UNPKG

@webiny/api-page-builder-so-ddb-es

Version:

The DynamoDB + Elasticsearch storage operations Webiny Page Builder API.

90 lines (88 loc) 2.35 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.getESPublishedPageData = exports.getESPageData = exports.getESLatestPageData = void 0; var _get = _interopRequireDefault(require("lodash/get")); var _IndexPageDataPlugin = require("../../plugins/definitions/IndexPageDataPlugin"); /** * Map our system fields to the Elasticsearch data. * We need to add new fields if we add them into our system. */ const getESPageData = page => { return { __type: "page", tenant: page.tenant, webinyVersion: page.webinyVersion, id: page.id, pid: page.pid, editor: page.editor, locale: page.locale, createdOn: page.createdOn, savedOn: page.savedOn, createdBy: page.createdBy, ownedBy: page.ownedBy, category: page.category, version: page.version, title: page.title, titleLC: page.title.toLowerCase(), path: page.path, status: page.status, locked: page.locked, publishedOn: page.publishedOn, // Pull tags & snippet from settings.general. tags: (0, _get.default)(page, "settings.general.tags") || [], snippet: (0, _get.default)(page, "settings.general.snippet") || null, // Save some images that could maybe be used on listing pages. images: { general: (0, _get.default)(page, "settings.general.image") } }; }; exports.getESPageData = getESPageData; const getESLatestPageData = (plugins, page, input = {}) => { const data = { ...getESPageData(page), latest: true }; return modifyData({ data, page, plugins, input }); }; exports.getESLatestPageData = getESLatestPageData; const getESPublishedPageData = (plugins, page, input = {}) => { const data = { ...getESPageData(page), published: true }; return modifyData({ data, page, plugins, input }); }; exports.getESPublishedPageData = getESPublishedPageData; const modifyData = params => { const { data, page, plugins, input } = params; const pagePlugins = plugins.byType(_IndexPageDataPlugin.IndexPageDataPlugin.type); for (const plugin of pagePlugins) { plugin.apply({ page, data, plugins, input }); } return data; }; //# sourceMappingURL=helpers.js.map