var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promise, generator) {
    return new Promise(function (resolve, reject) {
        generator = generator.call(thisArg, _arguments);
        function cast(value) { return value instanceof Promise && value.constructor === Promise ? value : new Promise(function (resolve) { resolve(value); }); }
        function onfulfill(value) { try { step("next", value); } catch (e) { reject(e); } }
        function onreject(value) { try { step("throw", value); } catch (e) { reject(e); } }
        function step(verb, value) {
            var result = generator[verb](value);
            result.done ? resolve(result.value) : cast(result.value).then(onfulfill, onreject);
        }
        step("next", void 0);
    });
};
import { Util } from '../../../util/util';
export class Node {
    constructor() {
        this.dataRelationships = {};
        this._headers = {
            'Accept': 'application/vnd.api+json',
            'Content-Type': 'application/vnd.api+json'
        };
        this._nodeTemplate = {
            data: {
                type: "node--page",
                attributes: {
                    "title": "new: node--page",
                    // "langcode": "en",
                    // "status": true,
                    // "promote": false,
                    // "sticky": false,
                    // "default_langcode": true,
                    "body": {
                        "value": "new: node--page: body",
                    }
                }
            }
        };
    }
    _createNode(nodeObject = this._nodeTemplate) {
        let node = Util.copy(this._nodeTemplate);
        node = Util.deepAssign(node, nodeObject);
        console.log(node);
        return node;
    }
    _json() {
        return JSON.stringify(this.data);
    }
    _fetchResource(url, params = undefined) {
        return __awaiter(this, void 0, Promise, function* () {
            if (params) {
                url += '?';
                Object.keys(params).forEach(key => url += key + '=' + params[key] + '&');
            }
            let resource = yield fetch(url, { headers: this._headers })
                .then((response) => {
                if (response.status >= 400) {
                    throw new Error('Bad response from server');
                }
                return response.json();
            })
                .then((data) => {
                return data;
            });
            return resource;
        });
    }
}
//# sourceMappingURL=node.js.map