UNPKG

@becomes/cms

Version:

Simple CMS for building APIs.

975 lines (974 loc) 56.4 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PropUtil = void 0; var prop_interface_1 = require("./interfaces/prop.interface"); var purple_cheetah_1 = require("purple-cheetah"); var cache_control_1 = require("../cache-control"); var Turndown = require("turndown"); var PropUtil = (function () { function PropUtil() { } Object.defineProperty(PropUtil, "changesSchema", { get: function () { return { name: { __type: 'object', __required: true, __child: { old: { __type: 'string', __required: true, }, new: { __type: 'string', __required: true, }, }, }, required: { __type: 'boolean', __required: true, }, remove: { __type: 'boolean', __required: false, }, add: { __type: 'object', __required: false, __child: {}, }, }; }, enumerable: false, configurable: true }); PropUtil.getPropsFromUntrustedObject = function (object, groupService) { return __awaiter(this, void 0, void 0, function () { var returnProps, props, _a, _b, _i, i, prop, p, _c, verifiedProp, j, item, temp, j, content, errorMsg, j, j, j, verifiedProp; return __generator(this, function (_d) { switch (_d.label) { case 0: returnProps = []; props = object; if (typeof props !== 'object' || !(props instanceof Array)) { throw new Error("'body.props' is not an array."); } _a = []; for (_b in props) _a.push(_b); _i = 0; _d.label = 1; case 1: if (!(_i < _a.length)) return [3, 21]; i = _a[_i]; prop = props[i]; p = { name: '', required: false, type: undefined, value: undefined, }; if (typeof prop.type === 'undefined') { throw new Error("'body.prop[" + i + "].type' is undefined."); } p.type = prop.type; if (typeof prop.name === 'undefined') { throw new Error("'body.prop[" + i + "].name' is undefined."); } p.name = prop.name; if (typeof prop.required === 'undefined') { throw new Error("'body.prop[" + i + "].required' is undefined."); } p.required = prop.required; _c = prop.type; switch (_c) { case prop_interface_1.PropType.BOOLEAN: return [3, 2]; case prop_interface_1.PropType.DATE: return [3, 3]; case prop_interface_1.PropType.NUMBER: return [3, 4]; case prop_interface_1.PropType.STRING: return [3, 5]; case prop_interface_1.PropType.MEDIA: return [3, 6]; case prop_interface_1.PropType.GROUP_POINTER: return [3, 7]; case prop_interface_1.PropType.ENUMERATION: return [3, 9]; case prop_interface_1.PropType.ENTRY_POINTER: return [3, 10]; case prop_interface_1.PropType.QUILL: return [3, 11]; case prop_interface_1.PropType.STRING_ARRAY: return [3, 12]; case prop_interface_1.PropType.NUMBER_ARRAY: return [3, 13]; case prop_interface_1.PropType.BOOLEAN_ARRAY: return [3, 14]; case prop_interface_1.PropType.GROUP_POINTER_ARRAY: return [3, 15]; case prop_interface_1.PropType.ENTRY_POINTER_ARRAY: return [3, 17]; } return [3, 18]; case 2: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'boolean') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'boolean' but got '" + typeof prop.value + "'.")); } p.value = prop.value; } return [3, 19]; case 3: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'number') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'number' but got '" + typeof prop.value + "'.")); } p.value = prop.value; } return [3, 19]; case 4: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'number') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'number' but got '" + typeof prop.value + "'.")); } p.value = prop.value; } return [3, 19]; case 5: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'string' but got '" + typeof prop.value + "'.")); } p.value = prop.value; } return [3, 19]; case 6: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'string' but got '" + typeof prop.value + "'.")); } p.value = prop.value; } return [3, 19]; case 7: return [4, this.untrustedGroupPointerObjectToProp(prop, groupService, "props[" + i + "]")]; case 8: verifiedProp = _d.sent(); p.type = prop_interface_1.PropType[verifiedProp.type]; p.value = verifiedProp.value; return [3, 19]; case 9: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value === 'undefined') { throw new Error("'value' is undefined for prop type '" + prop.type + "' " + ("in 'props[" + i + "]'.")); } if (typeof prop.value !== 'object') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'object' but got '" + typeof prop.value + "'.")); } if (typeof prop.value.items === 'undefined') { throw new Error("'items' is undefined for prop type '" + prop.type + "' " + ("in 'props[" + i + "].value'.")); } if (!(prop.value.items instanceof Array)) { throw new Error("Invalid type of 'props[" + i + "].value.items'. " + ("Expected 'array' but got '" + typeof prop.value + "'.")); } if (prop.value.items.length === 0) { throw new Error("Empty array was provided in 'props[" + i + "].value.items' " + ("for type '" + prop.type + "'.")); } for (j in prop.value.items) { item = prop.value.items[j]; if (typeof item !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.items[" + j + "]'. " + ("Expected 'string' but got '" + typeof item + "'.")); } } temp = { items: prop.value.items, selected: prop.value.selected, }; p.value = temp; } return [3, 19]; case 10: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'object') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'object' but got '" + typeof prop.value + "'.")); } if (typeof prop.value.templateId !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.templateId'. " + ("Expected 'string' but got '" + typeof prop.value .templateId + "'.")); } if (typeof prop.value.entryId !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.entryId'. " + ("Expected 'string' but got '" + typeof prop.value.entryId + "'.")); } if (typeof prop.value.displayProp !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.displayProp'. " + ("Expected 'string' but got '" + typeof prop.value .displayProp + "'.")); } p.value = prop.value; } return [3, 19]; case 11: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'object') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'object' but got '" + typeof prop.value + "'.")); } { if (typeof prop.value.heading !== 'object') { throw new Error("Invalid type of 'props[" + i + "].value.heading'. " + ("Expected 'object' but got '" + typeof prop.value.heading + "'.")); } if (typeof prop.value.heading.title !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.heading.title'. " + ("Expected 'string' but got '" + typeof prop.value.heading .title + "'.")); } if (typeof prop.value.heading.title !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.heading.slug'. " + ("Expected 'string' but got '" + typeof prop.value.heading .slug + "'.")); } if (typeof prop.value.heading.desc !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.heading.desc'. " + ("Expected 'string' but got '" + typeof prop.value.heading .desc + "'.")); } if (typeof prop.value.heading.coverImageUri !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.heading.coverImageUri'. " + ("Expected 'string' but got '" + typeof prop.value.heading .coverImageUri + "'.")); } } { if (typeof prop.value.content !== 'object') { throw new Error("Error in Content. Invalid type of 'props[" + i + "].value.content'. " + ("Expected 'object' but got '" + typeof prop.value.content + "'.")); } if (!(prop.value.content instanceof Array)) { throw new Error("Error in Content. Expected an array for 'props[" + i + "].value.content'"); } for (j in prop.value.content) { content = prop.value.content[j]; errorMsg = "Error in content at section " + content.type + ". "; if (typeof content.id !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.content[" + j + "].id'. " + ("Expected 'string' but got '" + typeof content.id + "'.")); } if (typeof content.type !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.content[" + j + "].type'. " + ("Expected 'string' but got '" + typeof content.type + "'.")); } if (typeof content.valueAsText !== 'string') { throw new Error(errorMsg + ("Invalid type of 'props[" + i + "].value.content[" + j + "].valueAsText'. ") + ("Expected 'string' but got '" + typeof content.valueAsText + "'.")); } if (content.type === 'MEDIA') { if (typeof content.value !== 'string') { throw new Error(errorMsg + ("Invalid type of 'props[" + i + "].value.content[" + j + "].value'. ") + ("Expected 'string' but got '" + typeof content.value + "'.")); } } else { if (typeof content.value !== 'object') { throw new Error(errorMsg + ("Invalid type of 'props[" + i + "].value.content[" + j + "].value'. ") + ("Expected 'object' but got '" + typeof content.value + "'.")); } } if (content.type !== 'MEDIA' && content.type !== 'WIDGET') { if (!(content.value.ops instanceof Array)) { throw new Error(errorMsg + "Section is probably empty. " + ("Expected an array for 'props[" + i + "].value.content[" + j + "].value.ops'")); } } } } p.value = prop.value; } return [3, 19]; case 12: { p.type = prop_interface_1.PropType[prop.type]; if (!(prop.value instanceof Array)) { throw new Error("Invalid type of 'props[" + i + "].value'. " + "Expected 'array'."); } if (prop.value.length > 0) { for (j in prop.value) { if (typeof prop.value[j] !== 'string') { throw new Error("Invalid type found in 'props[" + i + "].value[" + j + "]'. " + ("Expected 'string' but got '" + typeof prop.value[j] + "'.")); } } } p.value = prop.value; } return [3, 19]; case 13: { p.type = prop_interface_1.PropType[prop.type]; if (!(prop.value instanceof Array)) { throw new Error("Invalid type of 'props[" + i + "].value'. " + "Expected 'array'."); } if (prop.value.length > 0) { for (j in prop.value) { if (typeof prop.value[j] !== 'number') { throw new Error("Invalid type found in 'props[" + i + "].value[" + j + "]'. " + ("Expected 'number' but got '" + typeof prop.value[j] + "'.")); } } } p.value = prop.value; } return [3, 19]; case 14: { p.type = prop_interface_1.PropType[prop.type]; if (!(prop.value instanceof Array)) { throw new Error("Invalid type of 'props[" + i + "].value'. " + "Expected 'array'."); } if (prop.value.length > 0) { for (j in prop.value) { if (typeof prop.value[j] !== 'boolean') { throw new Error("Invalid type found in 'props[" + i + "].value[" + j + "]'. " + ("Expected 'boolean' but got '" + typeof prop.value[j] + "'.")); } } } p.value = prop.value; } return [3, 19]; case 15: p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'object') { throw new Error("Invalid type found in 'props[" + i + "].value'. " + ("Expected 'object' but got '" + typeof prop.value + "'.")); } if (typeof prop.value._id !== 'string') { throw new Error("Invalid type found in 'props[" + i + "].value._id'. " + ("Expected 'string' but got '" + typeof prop.value + "'.")); } if (!(prop.value.array instanceof Array)) { throw new Error("Invalid type of 'props[" + i + "].value.array'. " + "Expected 'array'."); } return [4, this.untrustedGroupPointerObjectToProp(prop, groupService, "props[" + i + "].value")]; case 16: verifiedProp = _d.sent(); verifiedProp.value = verifiedProp.value; p.value = { _id: verifiedProp.value._id, props: verifiedProp.value.props, array: prop.value.array, }; return [3, 19]; case 17: { p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value !== 'object') { throw new Error("Invalid type of 'props[" + i + "].value'. " + ("Expected 'object' but got '" + typeof prop.value + "'.")); } if (typeof prop.value.templateId !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.templateId'. " + ("Expected 'string' but got '" + typeof prop.value .templateId + "'.")); } if (typeof prop.value.entryIds !== 'object') { throw new Error("Invalid type of 'props[" + i + "].value.entryIds'. " + ("Expected 'object' but got '" + typeof prop.value.entryIds + "'.")); } if (!(prop.value.entryIds instanceof Array)) { throw new Error("Invalid type of 'props[" + i + "].value.entryIds'. " + "Expected an 'array'."); } if (typeof prop.value.displayProp !== 'string') { throw new Error("Invalid type of 'props[" + i + "].value.displayProp'. " + ("Expected 'string' but got '" + typeof prop.value .displayProp + "'.")); } p.value = prop.value; } return [3, 19]; case 18: { throw new Error("Unsupported value '" + prop.type + "' for 'body.prop[" + i + "].type'."); } _d.label = 19; case 19: returnProps.push(p); _d.label = 20; case 20: _i++; return [3, 1]; case 21: return [2, returnProps]; } }); }); }; PropUtil.untrustedGroupPointerObjectToProp = function (prop, groupService, messagePrefix) { return __awaiter(this, void 0, void 0, function () { var p, g, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: p = { name: '', required: false, type: undefined, value: undefined, }; p.type = prop_interface_1.PropType[prop.type]; if (typeof prop.value === 'undefined') { throw new Error("'value' is undefined for prop type '" + prop.type + "' " + ("in '" + messagePrefix + "'.")); } if (typeof prop.value !== 'object') { throw new Error("Invalid type of '" + messagePrefix + ".value'. " + ("Expected 'object' but got '" + typeof prop.value + "'.")); } if (typeof prop.value._id === 'undefined') { throw new Error("'_id' is undefined for prop type '" + prop.type + "' " + ("in '" + messagePrefix + ".value'.")); } if (typeof prop.value._id !== 'string') { throw new Error("Invalid type of '" + messagePrefix + ".value._id'. " + ("Expected 'string' but got '" + typeof prop.value._id + "'.")); } if (typeof prop.value.props === 'undefined') { throw new Error("'props' is undefined for prop type '" + prop.type + "' " + ("in '" + messagePrefix + ".value'.")); } if (!(prop.value.props instanceof Array)) { throw new Error("Invalid type of '" + messagePrefix + ".value.props'. " + "Expected 'array'."); } if (purple_cheetah_1.StringUtility.isIdValid(prop.value._id) === false) { throw new Error("Invalid ID '" + prop.value._id + "' value was provided for " + ("type '" + prop.type + "' in '" + messagePrefix + ".value._id'.")); } return [4, groupService.findById(prop.value)]; case 1: g = _c.sent(); if (g === null) { throw new Error("Group with ID '" + prop.value + "' does not exist but was " + ("provided in '" + messagePrefix + ".value'.")); } p.value = p.value; _a = p; _b = { _id: prop.value._id }; return [4, PropUtil.getPropsFromUntrustedObject(prop.value.props, groupService)]; case 2: _a.value = (_b.props = _c.sent(), _b); return [2, p]; } }); }); }; PropUtil.compareWithTemplate = function (propsToCheck, propsTemplate, level) { if (level) { level = 'root'; } var _loop_1 = function (i) { var propTemplate = propsTemplate[i]; var propToCheck = propsToCheck.find(function (e) { return e.name === propTemplate.name; }); if (!propToCheck) { if (propTemplate.required === true) { throw new Error("Missing property '" + level + "." + propTemplate.name + "'."); } } if (propToCheck.type !== propTemplate.type) { throw new Error("Type mismatch for '" + level + "." + propTemplate.name + "'. " + ("Expected '" + propTemplate.type + "' but got '" + propToCheck.type + "'.")); } if (propTemplate.type === prop_interface_1.PropType.GROUP_POINTER) { propToCheck.value = propToCheck.value; propTemplate.value = propTemplate.value; PropUtil.compareWithTemplate(propToCheck.value.props, propTemplate.value.props, level + "." + propTemplate.name); } }; for (var i in propsTemplate) { _loop_1(i); } }; PropUtil.propsToJSONObject = function (props, init, lng) { return __awaiter(this, void 0, void 0, function () { var object, _a, _b, _i, i, prop, _c, _d, _e, _f, _g, _h, j, arr, _j, _k, entry, entryContent, _l, _m, _o, _p, _q, j, eid, entry, entryContent, _r, _s; return __generator(this, function (_t) { switch (_t.label) { case 0: object = {}; if (init) { object = init; } _a = []; for (_b in props) _a.push(_b); _i = 0; _t.label = 1; case 1: if (!(_i < _a.length)) return [3, 26]; i = _a[_i]; prop = props[i]; _c = prop.type; switch (_c) { case prop_interface_1.PropType.GROUP_POINTER: return [3, 2]; case prop_interface_1.PropType.GROUP_POINTER_ARRAY: return [3, 4]; case prop_interface_1.PropType.QUILL: return [3, 9]; case prop_interface_1.PropType.ENTRY_POINTER: return [3, 10]; case prop_interface_1.PropType.ENTRY_POINTER_ARRAY: return [3, 16]; } return [3, 24]; case 2: prop.value = prop.value; _d = object; _e = prop.name; return [4, PropUtil.propsToJSONObject(prop.value.props, undefined, lng)]; case 3: _d[_e] = _t.sent(); return [3, 25]; case 4: prop.value = prop.value; object[prop.name] = []; _f = []; for (_g in prop.value.array) _f.push(_g); _h = 0; _t.label = 5; case 5: if (!(_h < _f.length)) return [3, 8]; j = _f[_h]; arr = prop.value.array[j]; _k = (_j = object[prop.name]).push; return [4, PropUtil.propsToJSONObject(arr.value, undefined, lng)]; case 6: _k.apply(_j, [_t.sent()]); _t.label = 7; case 7: _h++; return [3, 5]; case 8: return [3, 25]; case 9: { prop.value = prop.value; object.title = prop.value.heading.title; object.slug = prop.value.heading.slug; object.description = prop.value.heading.desc; object.coverImageUri = prop.value.heading.coverImageUri; } return [3, 25]; case 10: prop.value = prop.value; return [4, cache_control_1.CacheControl.Entry.findById(prop.value.entryId)]; case 11: entry = _t.sent(); if (!(!entry || entry === null)) return [3, 12]; object[prop.name] = prop.value; return [3, 15]; case 12: entryContent = entry.content.find(function (e) { return e.lng === lng; }); if (!entryContent) return [3, 14]; _l = object; _m = prop.name; return [4, PropUtil.propsToMarkdown(entryContent.props, undefined, lng)]; case 13: _l[_m] = _t.sent(); return [3, 15]; case 14: object[prop.name] = prop.value; _t.label = 15; case 15: return [3, 25]; case 16: prop.value = prop.value; object[prop.name] = []; _o = []; for (_p in prop.value.entryIds) _o.push(_p); _q = 0; _t.label = 17; case 17: if (!(_q < _o.length)) return [3, 23]; j = _o[_q]; eid = prop.value.entryIds[j]; return [4, cache_control_1.CacheControl.Entry.findById(eid)]; case 18: entry = _t.sent(); if (!(!entry || entry === null)) return [3, 19]; object[prop.name].push(prop.value); return [3, 22]; case 19: entryContent = entry.content.find(function (e) { return e.lng === lng; }); if (!entryContent) return [3, 21]; _s = (_r = object[prop.name]).push; return [4, PropUtil.propsToMarkdown(entryContent.props, undefined, lng)]; case 20: _s.apply(_r, [_t.sent()]); return [3, 22]; case 21: object[prop.name].push(prop.value); _t.label = 22; case 22: _q++; return [3, 17]; case 23: return [3, 25]; case 24: { object[prop.name] = prop.value; } _t.label = 25; case 25: _i++; return [3, 1]; case 26: return [2, object]; } }); }); }; PropUtil.propsToMarkdown = function (props, init, lng) { return __awaiter(this, void 0, void 0, function () { var meta, content, quillProp; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4, PropUtil.propsToJSONObject(props, init, lng)]; case 1: meta = _a.sent(); content = []; quillProp = props.find(function (e) { return e.type === prop_interface_1.PropType.QUILL; }); if (!quillProp) return [3, 3]; quillProp.value = quillProp.value; return [4, this.contentCompiler(quillProp.value.content, lng)]; case 2: content = _a.sent(); _a.label = 3; case 3: return [2, { meta: meta, content: content, }]; } }); }); }; PropUtil.formatMarkdownInsert = function (insert) { var checks = { end: [ { from: ' **', to: '** ', }, { from: ' *', to: '* ', }, { from: ' ~~', to: '~~ ', }, { from: ' **', to: '** ', }, { from: ' *', to: '* ', }, { from: ' ~~', to: '~~ ', }, ], start: [ { from: '** ', to: ' **', }, { from: '* ', to: ' *', }, { from: '~~ ', to: ' ~~', }, { from: '** ', to: ' **', }, { from: '* ', to: ' *', }, { from: '~~ ', to: ' ~~', }, ], }; for (var k in checks.end) { if (insert.endsWith(checks.end[k].from) === true) { insert = insert.replace(checks.end[k].from, checks.end[k].to); } } for (var k in checks.start) { if (insert.startsWith(checks.start[k].from) === true) { insert = insert.replace(checks.start[k].from, checks.start[k].to); } } return insert; }; PropUtil.contentToMarkdown = function (entryContent, init) { return __awaiter(this, void 0, void 0, function () { var data, _a, _b, _i, i, lngData; return __generator(this, function (_c) { switch (_c.label) { case 0: data = {}; _a = []; for (_b in entryContent) _a.push(_b); _i = 0; _c.label = 1; case 1: if (!(_i < _a.length)) return [3, 4]; i = _a[_i]; return [4, PropUtil.propsToMarkdown(entryContent[i].props, init, entryContent[i].lng)]; case 2: lngData = _c.sent(); data[entryContent[i].lng] = { meta: lngData.meta, content: lngData.content, }; _c.label = 3; case 3: _i++; return [3, 1]; case 4: return [2, data]; } }); }); }; PropUtil.contentToPrettyJSON = function (entryContent, init) { return __awaiter(this, void 0, void 0, function () { var data, _a, _b, _i, i, _c, _d, _e, _f, _g, _h; return __generator(this, function (_j) { switch (_j.label) { case 0: data = {}; _a = []; for (_b in entryContent) _a.push(_b); _i = 0; _j.label = 1; case 1: if (!(_i < _a.length)) return [3, 4]; i = _a[_i]; _c = data; _d = entryContent[i].lng; _f = (_e = JSON).parse; _h = (_g = JSON).stringify; return [4, PropUtil.propsToMarkdown(entryContent[i].props, init, entryContent[i].lng)]; case 2: _c[_d] = _f.apply(_e, [_h.apply(_g, [_j.sent()])]); _j.label = 3; case 3: _i++; return [3, 1]; case 4: return [2, data]; } }); }); }; PropUtil.updateGroupName = function (entries, oldName, newName) { var recursive = function (props, on, nn) { props.forEach(function (prop) { if (prop.type === prop_interface_1.PropType.GROUP_POINTER) { prop.value = prop.value; if (prop.name === on) { prop.name = nn; } else { prop.value.props = recursive(prop.value.props, on, nn); } } }); return props; }; entries.forEach(function (entry) { entry.content.forEach(function (content) { content.props = recursive(content.props, oldName, newName); }); }); }; PropUtil.contentCompiler = function (props, lng, toMarkdown) { return __awaiter(this, void 0, void 0, function () { var content, _a, _b, _i, i, prop, value, name_1, _c; return __generator(this, function (_d) { switch (_d.label) { case 0: content = []; _a = []; for (_b in props) _a.push(_b); _i = 0; _d.label = 1; case 1: if (!(_i < _a.length)) return [3, 15]; i = _a[_i]; prop = props[i]; value = ''; name_1 = void 0; _c = prop.type; switch (_c) { case prop_interface_1.PropQuillContentType.HEADING_1: return [3, 2]; case prop_interface_1.PropQuillContentType.HEADING_2: return [3, 3]; case prop_interface_1.PropQuillContentType.HEADING_3: return [3, 4]; case prop_interface_1.PropQuillContentType.HEADING_4: return [3, 5]; case prop_interface_1.PropQuillContentType.HEADING_5: return [3, 6]; case prop_interface_1.PropQuillContentType.CODE: return [3, 7]; case prop_interface_1.PropQuillContentType.PARAGRAPH: return [3, 8]; case prop_interface_1.PropQuillContentType.LIST: return [3, 9]; case prop_interface_1.PropQuillContentType.WIDGET: return [3, 10]; case prop_interface_1.PropQuillContentType.MEDIA: return [3, 12]; } return [3, 13]; case 2: { value += "<h2>" + (prop.valueAsText.endsWith('\n') ? prop.valueAsText.substring(0, prop.valueAsText.length - 1) : prop.valueAsText) + "</h2>"; } return [3, 13]; case 3: { value += "<h3>" + (prop.valueAsText.endsWith('\n') ? prop.valueAsText.substring(0, prop.valueAsText.length - 1) : prop.valueAsText) + "</h3>"; } return [3, 13]; case 4: { value += "<h4>" + (prop.valueAsText.endsWith('\n') ? prop.valueAsText.substring(0, prop.valueAsText.length - 1) : prop.valueAsText) + "</h4>"; } return [3, 13]; case 5: { value += "<h5>" + (prop.valueAsText.endsWith('\n') ? prop.valueAsText.substring(0, prop.valueAsText.length - 1) : prop.valueAsText) + "</h5>"; } return [3, 13]; case 6: { value += "<h6>" + (prop.valueAsText.endsWith('\n') ? prop.valueAsText.substring(0, prop.valueAsText.length - 1) : prop.valueAsText) + "</h6>"; } return [3, 13]; case 7: { value += "<pre><code>" + (prop.valueAsText.endsWith('\n') ? prop.valueAsText.substring(0, prop.valueAsText.length - 1) : prop.valueAsText) + "</code></pre>"; } return [3, 13]; case 8: { value += "<p>" + this.opsToValue(prop.value.ops) + "</p>"; } return [3, 13]; case 9: { value += "<ul>" + this.opsListToValue(prop.value.ops, true) + "</ul>"; } return [3, 13]; case 10: prop.value = prop.value; name_1 = prop.value.name; return [4, PropUtil.propsToJSONObject(prop.value.props, undefined, lng)]; case 11: value = _d.sent(); return [3, 13]; case 12: { value = prop.value; } return [3, 13]; case 13: content.push({ type: prop.type, name: name_1, value: toMarkdown === true ? this.td.turndown(value) : value, }); _d.label = 14; case 14: _i++; return [3, 1]; case 15: return [2, content]; } }); }); }; PropUtil.opsToValue = function (ops, isList) { var checker = { link: false, bold: false, italic: false, underline: false, list: { in: false, level: 0, }, }; var value = '';