UNPKG

contentful-migration

Version:
114 lines 3.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Entry = exports.default = void 0; const lodash_1 = require("lodash"); const is_defined_1 = __importDefault(require("../utils/is-defined")); class Entry { constructor(entry) { var _a; this._id = entry.sys.id; this._fields = entry.fields; this._version = entry.sys.version; this._contentTypeId = entry.sys.contentType.sys.id; this._publishedVersion = entry.sys.publishedVersion; this._tags = (_a = entry.metadata) === null || _a === void 0 ? void 0 : _a.tags; this._fieldStatus = entry.sys.fieldStatus; } get id() { return this._id; } get contentTypeId() { return this._contentTypeId; } get fields() { return this._fields; } set fields(fields) { this._fields = fields; } setField(id, value) { this._fields[id] = value; } setFieldForLocale(id, locale, value) { const field = this._fields[id] || {}; field[locale] = value; this._fields[id] = field; } replaceArrayLinkForLocale(id, locale, index, linkId) { const link = { sys: { id: linkId, type: 'Link', linkType: 'Entry' } }; const field = this._fields[id] || {}; const fieldArray = field[locale]; if (fieldArray.length < index + 1) { fieldArray.push(link); } else { fieldArray[index] = link; } } get version() { return this._version; } set version(version) { this._version = version; } get isPublished() { return (0, is_defined_1.default)(this._publishedVersion); } get publishedVersion() { return this._publishedVersion; } set publishedVersion(version) { this._publishedVersion = version; } get tags() { return this._tags; } set tags(tags) { this._tags = tags; } get fieldStatus() { return this._fieldStatus; } set fieldStatus(fieldStatus) { this._fieldStatus = fieldStatus; } toApiEntry() { const sys = { id: this.id, version: this.version, publishedVersion: this.publishedVersion, contentType: { sys: { type: 'Link', linkType: 'ContentType', id: this.contentTypeId } }, fieldStatus: (0, lodash_1.cloneDeep)(this.fieldStatus) }; let payload; if (this.tags !== undefined) { payload = { sys, fields: (0, lodash_1.cloneDeep)(this.fields), metadata: { tags: (0, lodash_1.cloneDeep)(this.tags) } }; } else { payload = { sys, fields: (0, lodash_1.cloneDeep)(this.fields) }; } return payload; } clone() { return new Entry(this.toApiEntry()); } } exports.default = Entry; exports.Entry = Entry; //# sourceMappingURL=entry.js.map