@webiny/api-page-builder-so-ddb-es 0.0.0-unstable.496cf268ac → 0.0.0-unstable.606fc9c866
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/operations/pages/elasticsearchQueryBody.d.ts +3 -1
- package/operations/pages/elasticsearchQueryBody.js.map +1 -1
- package/operations/pages/helpers.d.ts +2 -2
- package/operations/pages/helpers.js +23 -6
- package/operations/pages/helpers.js.map +1 -1
- package/operations/pages/index.js +6 -4
- package/operations/pages/index.js.map +1 -1
- package/package.json +31 -17
- package/plugins/definitions/IndexPageDataPlugin.d.ts +1 -0
- package/plugins/definitions/IndexPageDataPlugin.js.map +1 -1
- package/upgrades/index.d.ts +0 -2
- package/upgrades/index.js +0 -14
- package/upgrades/index.js.map +0 -1
- package/upgrades/v5.15.0/category.d.ts +0 -2
- package/upgrades/v5.15.0/category.js +0 -73
- package/upgrades/v5.15.0/category.js.map +0 -1
- package/upgrades/v5.15.0/index.d.ts +0 -4
- package/upgrades/v5.15.0/index.js +0 -52
- package/upgrades/v5.15.0/index.js.map +0 -1
- package/upgrades/v5.15.0/menu.d.ts +0 -2
- package/upgrades/v5.15.0/menu.js +0 -73
- package/upgrades/v5.15.0/menu.js.map +0 -1
- package/upgrades/v5.15.0/pageElement.d.ts +0 -2
- package/upgrades/v5.15.0/pageElement.js +0 -73
- package/upgrades/v5.15.0/pageElement.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SearchBody as esSearchBody } from "elastic-ts";
|
|
2
2
|
import { PageStorageOperationsListWhere } from "@webiny/api-page-builder/types";
|
|
3
|
+
import { PageElasticsearchFieldPlugin } from "../../plugins/definitions/PageElasticsearchFieldPlugin";
|
|
3
4
|
import { PluginsContainer } from "@webiny/plugins";
|
|
4
5
|
interface CreateElasticsearchBodyParams {
|
|
5
6
|
plugins: PluginsContainer;
|
|
@@ -7,6 +8,7 @@ interface CreateElasticsearchBodyParams {
|
|
|
7
8
|
limit: number;
|
|
8
9
|
after: string | null;
|
|
9
10
|
sort: string[];
|
|
11
|
+
fieldPlugins: Record<string, PageElasticsearchFieldPlugin>;
|
|
10
12
|
}
|
|
11
|
-
export declare const createElasticsearchQueryBody: (params: CreateElasticsearchBodyParams) => esSearchBody & Pick<Required<esSearchBody>, "sort">;
|
|
13
|
+
export declare const createElasticsearchQueryBody: (params: Omit<CreateElasticsearchBodyParams, "fieldPlugins">) => esSearchBody & Pick<Required<esSearchBody>, "sort">;
|
|
12
14
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createInitialQueryValue","args","where","query","must","must_not","should","filter","published","push","term","latest","WebinyError","createElasticsearchQuery","params","plugins","initialWhere","fieldPlugins","operatorPlugins","getElasticsearchOperatorPluginsByLocale","locale","tags_in","tags","tags_rule","tagsRule","Array","isArray","length","terms","bool","map","tag","search","query_string","allow_leading_wildcard","fields","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","applyWhere","operators","createElasticsearchQueryBody","limit","initialLimit","sort","initialSort","after","byType","PageElasticsearchFieldPlugin","type","reduce","acc","plugin","field","createLimit","createSort","queryModifiers","PageElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","PageElasticsearchSortModifierPlugin","modifySort","body","constant_score","size","search_after","decodeCursor","bodyModifiers","PageElasticsearchBodyModifierPlugin","modifyBody"],"sources":["elasticsearchQueryBody.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { SearchBody as esSearchBody } from \"elastic-ts\";\nimport {\n applyWhere,\n createLimit,\n createSort,\n decodeCursor,\n ElasticsearchFieldPlugin,\n getElasticsearchOperatorPluginsByLocale\n} from \"@webiny/api-elasticsearch\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { PageStorageOperationsListWhere } from \"@webiny/api-page-builder/types\";\nimport { PageElasticsearchFieldPlugin } from \"~/plugins/definitions/PageElasticsearchFieldPlugin\";\nimport { PageElasticsearchSortModifierPlugin } from \"~/plugins/definitions/PageElasticsearchSortModifierPlugin\";\nimport { PageElasticsearchQueryModifierPlugin } from \"~/plugins/definitions/PageElasticsearchQueryModifierPlugin\";\nimport { PageElasticsearchBodyModifierPlugin } from \"~/plugins/definitions/PageElasticsearchBodyModifierPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface CreateElasticsearchQueryArgs {\n where: PageStorageOperationsListWhere;\n}\n\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the published or latest property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n */\nconst createInitialQueryValue = (\n args: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const { where } = args;\n\n const query: ElasticsearchBoolQueryConfig = {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.must.push({\n term: {\n published: true\n }\n });\n } else if (where.latest === true) {\n query.must.push({\n term: {\n latest: true\n }\n });\n }\n // we do not allow not published and not latest\n else if (where.published === false) {\n throw new WebinyError(\n `Cannot call Elasticsearch query with \"published\" set at false.`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n } else if (where.latest === false) {\n throw new WebinyError(\n `Cannot call Elasticsearch query with \"latest\" set at false.`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n delete where.published;\n delete where.latest;\n //\n return query;\n};\n\ninterface CreateElasticsearchBodyParams {\n plugins: PluginsContainer;\n where: PageStorageOperationsListWhere;\n limit: number;\n after: string | null;\n sort: string[];\n}\n\nconst createElasticsearchQuery = (\n params: CreateElasticsearchBodyParams & {\n fieldPlugins: Record<string, ElasticsearchFieldPlugin>;\n }\n) => {\n const { plugins, where: initialWhere, fieldPlugins } = params;\n const query = createInitialQueryValue({\n where: initialWhere\n });\n /**\n * Be aware that, if having more registered operator plugins of same type, the last one will be used.\n */\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, initialWhere.locale);\n\n const where: Partial<PageStorageOperationsListWhere> = {\n ...initialWhere\n };\n /**\n * Tags are specific so extract them and remove from where.\n */\n const { tags_in: tags, tags_rule: tagsRule } = initialWhere;\n delete where[\"tags_in\"];\n delete where[\"tags_rule\"];\n if (tags && Array.isArray(tags) === true && tags.length > 0) {\n if (tagsRule === \"any\") {\n query.filter.push({\n terms: {\n \"tags.keyword\": tags\n }\n });\n } else {\n query.filter.push({\n bool: {\n must: tags.map(tag => {\n return {\n term: {\n \"tags.keyword\": tag\n }\n };\n })\n }\n });\n }\n }\n /**\n * Specific search parameter\n */\n if (where.search) {\n query.must.push({\n query_string: {\n query: `*${where.search}*`,\n allow_leading_wildcard: true,\n fields: [\"titleLC\", \"snippet\"]\n }\n });\n }\n delete where.search;\n\n /**\n * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.\n *\n * When ES index is shared between tenants, we need to filter records by tenant ID.\n */\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex) {\n const tenant = initialWhere.tenant;\n query.must.push({ term: { \"tenant.keyword\": tenant } });\n /**\n * Remove so it is not applied again later.\n * Possibly tenant is not defined, but just in case, remove it.\n */\n delete where[\"tenant\"];\n }\n /**\n * We apply other conditions as they are passed via the where value.\n */\n applyWhere({\n query,\n where,\n fields: fieldPlugins,\n operators: operatorPlugins\n });\n\n return query;\n};\n\nexport const createElasticsearchQueryBody = (\n params: CreateElasticsearchBodyParams\n): esSearchBody & Pick<Required<esSearchBody>, \"sort\"> => {\n const { plugins, where, limit: initialLimit, sort: initialSort, after } = params;\n\n const fieldPlugins = plugins\n .byType<PageElasticsearchFieldPlugin>(PageElasticsearchFieldPlugin.type)\n .reduce((acc, plugin) => {\n acc[plugin.field] = plugin;\n return acc;\n }, {} as Record<string, PageElasticsearchFieldPlugin>);\n\n const limit = createLimit(initialLimit, 100);\n\n const query = createElasticsearchQuery({\n ...params,\n fieldPlugins\n });\n\n const sort = createSort({\n sort: initialSort,\n fieldPlugins\n });\n\n const queryModifiers = plugins.byType<PageElasticsearchQueryModifierPlugin>(\n PageElasticsearchQueryModifierPlugin.type\n );\n for (const plugin of queryModifiers) {\n plugin.modifyQuery({\n query,\n where,\n sort,\n limit\n });\n }\n\n const sortModifiers = plugins.byType<PageElasticsearchSortModifierPlugin>(\n PageElasticsearchSortModifierPlugin.type\n );\n for (const plugin of sortModifiers) {\n plugin.modifySort({\n sort,\n where\n });\n }\n\n const body = {\n query: {\n constant_score: {\n filter: {\n bool: {\n ...query\n }\n }\n }\n },\n size: limit + 1,\n /**\n * Casting as any is required due to search_after is accepting an array of values.\n * Which is correct in some cases. In our case, it is not.\n * https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html\n */\n search_after: decodeCursor(after),\n sort\n };\n\n const bodyModifiers = plugins.byType<PageElasticsearchBodyModifierPlugin>(\n PageElasticsearchBodyModifierPlugin.type\n );\n for (const plugin of bodyModifiers) {\n plugin.modifyBody({\n body,\n where\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AAUA;AACA;AACA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA,MAAMA,uBAAuB,GACzBC,IAAkC,IACH;EAC/B,MAAM;IAAEC;EAAM,CAAC,GAAGD,IAAI;EAEtB,MAAME,KAAmC,GAAG;IACxCC,IAAI,EAAE,EAAE;IACRC,QAAQ,EAAE,EAAE;IACZC,MAAM,EAAE,EAAE;IACVC,MAAM,EAAE;EACZ,CAAC;;EAED;AACJ;AACA;EACI,IAAIL,KAAK,CAACM,SAAS,KAAK,IAAI,EAAE;IAC1BL,KAAK,CAACC,IAAI,CAACK,IAAI,CAAC;MACZC,IAAI,EAAE;QACFF,SAAS,EAAE;MACf;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIN,KAAK,CAACS,MAAM,KAAK,IAAI,EAAE;IAC9BR,KAAK,CAACC,IAAI,C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MuB,aAAa,GAAGtD,OAAO,CAACkC,MAAM,CAChCqB,wEAAmC,CAACnB,IAAI,CAC3C;EACD,KAAK,MAAMG,MAAM,IAAIe,aAAa,EAAE;IAChCf,MAAM,CAACiB,UAAU,CAAC;MACdP,IAAI;MACJ9D;IACJ,CAAC,CAAC;EACN;EAEA,OAAO8D,IAAI;AACf,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["createInitialQueryValue","args","where","query","must","must_not","should","filter","published","push","term","latest","WebinyError","createElasticsearchQuery","params","plugins","initialWhere","fieldPlugins","operatorPlugins","getElasticsearchOperatorPluginsByLocale","locale","tags_in","tags","tags_rule","tagsRule","Array","isArray","length","terms","bool","map","tag","search","query_string","allow_leading_wildcard","fields","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","applyWhere","operators","createElasticsearchQueryBody","limit","initialLimit","sort","initialSort","after","byType","PageElasticsearchFieldPlugin","type","reduce","acc","plugin","field","createLimit","createSort","queryModifiers","PageElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","PageElasticsearchSortModifierPlugin","modifySort","body","constant_score","size","search_after","decodeCursor","bodyModifiers","PageElasticsearchBodyModifierPlugin","modifyBody"],"sources":["elasticsearchQueryBody.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { SearchBody as esSearchBody } from \"elastic-ts\";\nimport {\n applyWhere,\n createLimit,\n createSort,\n decodeCursor,\n getElasticsearchOperatorPluginsByLocale\n} from \"@webiny/api-elasticsearch\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { PageStorageOperationsListWhere } from \"@webiny/api-page-builder/types\";\nimport { PageElasticsearchFieldPlugin } from \"~/plugins/definitions/PageElasticsearchFieldPlugin\";\nimport { PageElasticsearchSortModifierPlugin } from \"~/plugins/definitions/PageElasticsearchSortModifierPlugin\";\nimport { PageElasticsearchQueryModifierPlugin } from \"~/plugins/definitions/PageElasticsearchQueryModifierPlugin\";\nimport { PageElasticsearchBodyModifierPlugin } from \"~/plugins/definitions/PageElasticsearchBodyModifierPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface CreateElasticsearchQueryArgs {\n where: PageStorageOperationsListWhere;\n}\n\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the published or latest property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n */\nconst createInitialQueryValue = (\n args: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const { where } = args;\n\n const query: ElasticsearchBoolQueryConfig = {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.must.push({\n term: {\n published: true\n }\n });\n } else if (where.latest === true) {\n query.must.push({\n term: {\n latest: true\n }\n });\n }\n // we do not allow not published and not latest\n else if (where.published === false) {\n throw new WebinyError(\n `Cannot call Elasticsearch query with \"published\" set at false.`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n } else if (where.latest === false) {\n throw new WebinyError(\n `Cannot call Elasticsearch query with \"latest\" set at false.`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n delete where.published;\n delete where.latest;\n //\n return query;\n};\n\ninterface CreateElasticsearchBodyParams {\n plugins: PluginsContainer;\n where: PageStorageOperationsListWhere;\n limit: number;\n after: string | null;\n sort: string[];\n fieldPlugins: Record<string, PageElasticsearchFieldPlugin>;\n}\n\nconst createElasticsearchQuery = (params: CreateElasticsearchBodyParams) => {\n const { plugins, where: initialWhere, fieldPlugins } = params;\n const query = createInitialQueryValue({\n where: initialWhere\n });\n /**\n * Be aware that, if having more registered operator plugins of same type, the last one will be used.\n */\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, initialWhere.locale);\n\n const where: Partial<PageStorageOperationsListWhere> = {\n ...initialWhere\n };\n /**\n * Tags are specific so extract them and remove from where.\n */\n const { tags_in: tags, tags_rule: tagsRule } = initialWhere;\n delete where[\"tags_in\"];\n delete where[\"tags_rule\"];\n if (tags && Array.isArray(tags) === true && tags.length > 0) {\n if (tagsRule === \"any\") {\n query.filter.push({\n terms: {\n \"tags.keyword\": tags\n }\n });\n } else {\n query.filter.push({\n bool: {\n must: tags.map(tag => {\n return {\n term: {\n \"tags.keyword\": tag\n }\n };\n })\n }\n });\n }\n }\n /**\n * Specific search parameter\n */\n if (where.search) {\n query.must.push({\n query_string: {\n query: `*${where.search}*`,\n allow_leading_wildcard: true,\n fields: [\"titleLC\", \"snippet\"]\n }\n });\n }\n delete where.search;\n\n /**\n * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.\n *\n * When ES index is shared between tenants, we need to filter records by tenant ID.\n */\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex) {\n const tenant = initialWhere.tenant;\n query.must.push({ term: { \"tenant.keyword\": tenant } });\n /**\n * Remove so it is not applied again later.\n * Possibly tenant is not defined, but just in case, remove it.\n */\n delete where[\"tenant\"];\n }\n /**\n * We apply other conditions as they are passed via the where value.\n */\n applyWhere({\n query,\n where,\n fields: fieldPlugins,\n operators: operatorPlugins\n });\n\n return query;\n};\n\nexport const createElasticsearchQueryBody = (\n params: Omit<CreateElasticsearchBodyParams, \"fieldPlugins\">\n): esSearchBody & Pick<Required<esSearchBody>, \"sort\"> => {\n const { plugins, where, limit: initialLimit, sort: initialSort, after } = params;\n\n const fieldPlugins = plugins\n .byType<PageElasticsearchFieldPlugin>(PageElasticsearchFieldPlugin.type)\n .reduce((acc, plugin) => {\n acc[plugin.field] = plugin;\n return acc;\n }, {} as Record<string, PageElasticsearchFieldPlugin>);\n\n const limit = createLimit(initialLimit, 100);\n\n const query = createElasticsearchQuery({\n ...params,\n fieldPlugins\n });\n\n const sort = createSort({\n sort: initialSort,\n fieldPlugins\n });\n\n const queryModifiers = plugins.byType<PageElasticsearchQueryModifierPlugin>(\n PageElasticsearchQueryModifierPlugin.type\n );\n for (const plugin of queryModifiers) {\n plugin.modifyQuery({\n query,\n where,\n sort,\n limit\n });\n }\n\n const sortModifiers = plugins.byType<PageElasticsearchSortModifierPlugin>(\n PageElasticsearchSortModifierPlugin.type\n );\n for (const plugin of sortModifiers) {\n plugin.modifySort({\n sort,\n where\n });\n }\n\n const body = {\n query: {\n constant_score: {\n filter: {\n bool: {\n ...query\n }\n }\n }\n },\n size: limit + 1,\n /**\n * Casting as any is required due to search_after is accepting an array of values.\n * Which is correct in some cases. In our case, it is not.\n * https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html\n */\n search_after: decodeCursor(after),\n sort\n };\n\n const bodyModifiers = plugins.byType<PageElasticsearchBodyModifierPlugin>(\n PageElasticsearchBodyModifierPlugin.type\n );\n for (const plugin of bodyModifiers) {\n plugin.modifyBody({\n body,\n where\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;AAAA;AAEA;AASA;AACA;AACA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA,MAAMA,uBAAuB,GACzBC,IAAkC,IACH;EAC/B,MAAM;IAAEC;EAAM,CAAC,GAAGD,IAAI;EAEtB,MAAME,KAAmC,GAAG;IACxCC,IAAI,EAAE,EAAE;IACRC,QAAQ,EAAE,EAAE;IACZC,MAAM,EAAE,EAAE;IACVC,MAAM,EAAE;EACZ,CAAC;;EAED;AACJ;AACA;EACI,IAAIL,KAAK,CAACM,SAAS,KAAK,IAAI,EAAE;IAC1BL,KAAK,CAACC,IAAI,CAACK,IAAI,CAAC;MACZC,IAAI,EAAE;QACFF,SAAS,EAAE;MACf;IACJ,CAAC,CAAC;EACN,CAAC,MAAM,IAAIN,KAAK,CAACS,MAAM,KAAK,IAAI,EAAE;IAC9BR,KAAK,CAACC,IAAI,CAACK,IAAI,CAAC;MACZC,IAAI,EAAE;QACFC,MAAM,EAAE;MACZ;IACJ,CAAC,CAAC;EACN;EACA;EAAA,KACK,IAAIT,KAAK,CAACM,SAAS,KAAK,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AAM,CAACiB,UAAU,CAAC;MACdP,IAAI;MACJ9D;IACJ,CAAC,CAAC;EACN;EAEA,OAAO8D,IAAI;AACf,CAAC;AAAC"}
|
|
@@ -31,5 +31,5 @@ export declare const getESPageData: (page: Page) => {
|
|
|
31
31
|
general: import("lodash").FieldWithPossiblyUndefined<import("@webiny/api-page-builder/types").PageSettings, "general.image">;
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
|
-
export declare const getESLatestPageData: (plugins: PluginsContainer, page: Page) => Record<string, any>;
|
|
35
|
-
export declare const getESPublishedPageData: (plugins: PluginsContainer, page: Page) => Record<string, any>;
|
|
34
|
+
export declare const getESLatestPageData: (plugins: PluginsContainer, page: Page, input?: Record<string, any>) => Record<string, any>;
|
|
35
|
+
export declare const getESPublishedPageData: (plugins: PluginsContainer, page: Page, input?: Record<string, any>) => Record<string, any>;
|
|
@@ -43,27 +43,44 @@ const getESPageData = page => {
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
exports.getESPageData = getESPageData;
|
|
46
|
-
const getESLatestPageData = (plugins, page) => {
|
|
46
|
+
const getESLatestPageData = (plugins, page, input = {}) => {
|
|
47
47
|
const data = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getESPageData(page)), {}, {
|
|
48
48
|
latest: true
|
|
49
49
|
});
|
|
50
|
-
return modifyData(
|
|
50
|
+
return modifyData({
|
|
51
|
+
data,
|
|
52
|
+
page,
|
|
53
|
+
plugins,
|
|
54
|
+
input
|
|
55
|
+
});
|
|
51
56
|
};
|
|
52
57
|
exports.getESLatestPageData = getESLatestPageData;
|
|
53
|
-
const getESPublishedPageData = (plugins, page) => {
|
|
58
|
+
const getESPublishedPageData = (plugins, page, input = {}) => {
|
|
54
59
|
const data = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getESPageData(page)), {}, {
|
|
55
60
|
published: true
|
|
56
61
|
});
|
|
57
|
-
return modifyData(
|
|
62
|
+
return modifyData({
|
|
63
|
+
data,
|
|
64
|
+
page,
|
|
65
|
+
plugins,
|
|
66
|
+
input
|
|
67
|
+
});
|
|
58
68
|
};
|
|
59
69
|
exports.getESPublishedPageData = getESPublishedPageData;
|
|
60
|
-
const modifyData =
|
|
70
|
+
const modifyData = params => {
|
|
71
|
+
const {
|
|
72
|
+
data,
|
|
73
|
+
page,
|
|
74
|
+
plugins,
|
|
75
|
+
input
|
|
76
|
+
} = params;
|
|
61
77
|
const pagePlugins = plugins.byType(_IndexPageDataPlugin.IndexPageDataPlugin.type);
|
|
62
78
|
for (const plugin of pagePlugins) {
|
|
63
79
|
plugin.apply({
|
|
64
80
|
page,
|
|
65
81
|
data,
|
|
66
|
-
plugins
|
|
82
|
+
plugins,
|
|
83
|
+
input
|
|
67
84
|
});
|
|
68
85
|
}
|
|
69
86
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getESPageData","page","__type","tenant","webinyVersion","id","pid","editor","locale","createdOn","savedOn","createdBy","ownedBy","category","version","title","titleLC","toLowerCase","path","status","locked","publishedOn","tags","lodashGet","snippet","images","general","getESLatestPageData","plugins","data","latest","modifyData","getESPublishedPageData","published","pagePlugins","byType","IndexPageDataPlugin","type","plugin","apply"],"sources":["helpers.ts"],"sourcesContent":["import lodashGet from \"lodash/get\";\nimport { IndexPageDataPlugin } from \"~/plugins/definitions/IndexPageDataPlugin\";\nimport { Page } from \"@webiny/api-page-builder/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * Map our system fields to the Elasticsearch data.\n * We need to add new fields if we add them into our system.\n */\nexport const getESPageData = (page: Page) => {\n return {\n __type: \"page\",\n tenant: page.tenant,\n webinyVersion: page.webinyVersion,\n id: page.id,\n pid: page.pid,\n editor: page.editor,\n locale: page.locale,\n createdOn: page.createdOn,\n savedOn: page.savedOn,\n createdBy: page.createdBy,\n ownedBy: page.ownedBy,\n category: page.category,\n version: page.version,\n title: page.title,\n titleLC: page.title.toLowerCase(),\n path: page.path,\n status: page.status,\n locked: page.locked,\n publishedOn: page.publishedOn,\n\n // Pull tags & snippet from settings.general.\n tags: lodashGet(page, \"settings.general.tags\") || [],\n snippet: lodashGet(page, \"settings.general.snippet\") || null,\n\n // Save some images that could maybe be used on listing pages.\n images: {\n general: lodashGet(page, \"settings.general.image\")\n }\n };\n};\n\nexport const getESLatestPageData = (plugins: PluginsContainer
|
|
1
|
+
{"version":3,"names":["getESPageData","page","__type","tenant","webinyVersion","id","pid","editor","locale","createdOn","savedOn","createdBy","ownedBy","category","version","title","titleLC","toLowerCase","path","status","locked","publishedOn","tags","lodashGet","snippet","images","general","getESLatestPageData","plugins","input","data","latest","modifyData","getESPublishedPageData","published","params","pagePlugins","byType","IndexPageDataPlugin","type","plugin","apply"],"sources":["helpers.ts"],"sourcesContent":["import lodashGet from \"lodash/get\";\nimport { IndexPageDataPlugin } from \"~/plugins/definitions/IndexPageDataPlugin\";\nimport { Page } from \"@webiny/api-page-builder/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\n/**\n * Map our system fields to the Elasticsearch data.\n * We need to add new fields if we add them into our system.\n */\nexport const getESPageData = (page: Page) => {\n return {\n __type: \"page\",\n tenant: page.tenant,\n webinyVersion: page.webinyVersion,\n id: page.id,\n pid: page.pid,\n editor: page.editor,\n locale: page.locale,\n createdOn: page.createdOn,\n savedOn: page.savedOn,\n createdBy: page.createdBy,\n ownedBy: page.ownedBy,\n category: page.category,\n version: page.version,\n title: page.title,\n titleLC: page.title.toLowerCase(),\n path: page.path,\n status: page.status,\n locked: page.locked,\n publishedOn: page.publishedOn,\n\n // Pull tags & snippet from settings.general.\n tags: lodashGet(page, \"settings.general.tags\") || [],\n snippet: lodashGet(page, \"settings.general.snippet\") || null,\n\n // Save some images that could maybe be used on listing pages.\n images: {\n general: lodashGet(page, \"settings.general.image\")\n }\n };\n};\n\nexport const getESLatestPageData = (\n plugins: PluginsContainer,\n page: Page,\n input: Record<string, any> = {}\n) => {\n const data = { ...getESPageData(page), latest: true };\n return modifyData({ data, page, plugins, input });\n};\n\nexport const getESPublishedPageData = (\n plugins: PluginsContainer,\n page: Page,\n input: Record<string, any> = {}\n) => {\n const data = { ...getESPageData(page), published: true };\n return modifyData({ data, page, plugins, input });\n};\n\ninterface ModifyDataParams {\n input: Record<string, any>;\n data: Record<string, any>;\n page: Page;\n plugins: PluginsContainer;\n}\n\nconst modifyData = (params: ModifyDataParams) => {\n const { data, page, plugins, input } = params;\n const pagePlugins = plugins.byType<IndexPageDataPlugin>(IndexPageDataPlugin.type);\n\n for (const plugin of pagePlugins) {\n plugin.apply({ page, data, plugins, input });\n }\n\n return data;\n};\n"],"mappings":";;;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACO,MAAMA,aAAa,GAAIC,IAAU,IAAK;EACzC,OAAO;IACHC,MAAM,EAAE,MAAM;IACdC,MAAM,EAAEF,IAAI,CAACE,MAAM;IACnBC,aAAa,EAAEH,IAAI,CAACG,aAAa;IACjCC,EAAE,EAAEJ,IAAI,CAACI,EAAE;IACXC,GAAG,EAAEL,IAAI,CAACK,GAAG;IACbC,MAAM,EAAEN,IAAI,CAACM,MAAM;IACnBC,MAAM,EAAEP,IAAI,CAACO,MAAM;IACnBC,SAAS,EAAER,IAAI,CAACQ,SAAS;IACzBC,OAAO,EAAET,IAAI,CAACS,OAAO;IACrBC,SAAS,EAAEV,IAAI,CAACU,SAAS;IACzBC,OAAO,EAAEX,IAAI,CAACW,OAAO;IACrBC,QAAQ,EAAEZ,IAAI,CAACY,QAAQ;IACvBC,OAAO,EAAEb,IAAI,CAACa,OAAO;IACrBC,KAAK,EAAEd,IAAI,CAACc,KAAK;IACjBC,OAAO,EAAEf,IAAI,CAACc,KAAK,CAACE,WAAW,EAAE;IACjCC,IAAI,EAAEjB,IAAI,CAACiB,IAAI;IACfC,MAAM,EAAElB,IAAI,CAACkB,MAAM;IACnBC,MAAM,EAAEnB,IAAI,CAACmB,MAAM;IACnBC,WAAW,EAAEpB,IAAI,CAACoB,WAAW;IAE7B;IACAC,IAAI,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f,CAAC"}
|
|
@@ -35,7 +35,8 @@ const createPageStorageOperations = params => {
|
|
|
35
35
|
} = params;
|
|
36
36
|
const create = async params => {
|
|
37
37
|
const {
|
|
38
|
-
page
|
|
38
|
+
page,
|
|
39
|
+
input
|
|
39
40
|
} = params;
|
|
40
41
|
const versionKeys = {
|
|
41
42
|
PK: (0, _keys.createPartitionKey)(page),
|
|
@@ -49,7 +50,7 @@ const createPageStorageOperations = params => {
|
|
|
49
50
|
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, page), latestKeys), {}, {
|
|
50
51
|
TYPE: (0, _keys.createLatestType)()
|
|
51
52
|
}))];
|
|
52
|
-
const esData = (0, _helpers.getESLatestPageData)(plugins, page);
|
|
53
|
+
const esData = (0, _helpers.getESLatestPageData)(plugins, page, input);
|
|
53
54
|
try {
|
|
54
55
|
await (0, _batchWrite.batchWriteAll)({
|
|
55
56
|
table: entity.table,
|
|
@@ -110,7 +111,8 @@ const createPageStorageOperations = params => {
|
|
|
110
111
|
const update = async params => {
|
|
111
112
|
const {
|
|
112
113
|
original,
|
|
113
|
-
page
|
|
114
|
+
page,
|
|
115
|
+
input
|
|
114
116
|
} = params;
|
|
115
117
|
const keys = {
|
|
116
118
|
PK: (0, _keys.createPartitionKey)(page),
|
|
@@ -124,7 +126,7 @@ const createPageStorageOperations = params => {
|
|
|
124
126
|
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, page), {}, {
|
|
125
127
|
TYPE: (0, _keys.createBasicType)()
|
|
126
128
|
}, keys))];
|
|
127
|
-
const esData = (0, _helpers.getESLatestPageData)(plugins, page);
|
|
129
|
+
const esData = (0, _helpers.getESLatestPageData)(plugins, page, input);
|
|
128
130
|
if (latestPage && latestPage.id === page.id) {
|
|
129
131
|
/**
|
|
130
132
|
* We also update the regular record.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["removePageAttributes","item","omit","createPageStorageOperations","params","entity","esEntity","elasticsearch","plugins","create","page","versionKeys","PK","createPartitionKey","SK","createSortKey","latestKeys","createLatestSortKey","items","putBatch","TYPE","createBasicType","createLatestType","esData","getESLatestPageData","batchWriteAll","table","put","index","configurations","es","data","ex","WebinyError","message","code","createFrom","latestPage","original","update","keys","latestPageResult","get","cleanupItem","Item","id","push","deleteOne","publishedPage","partitionKey","deleteBatch","esItems","createPublishedSortKey","createPathPartitionKey","createPathSortKey","previousLatestPage","previousLatestRecord","queryOne","options","lt","reverse","length","deleteAll","queryAllParams","gte","revisions","queryAll","publishedPathEntryDeleted","revision","status","path","publish","getESPublishedPageData","createPublishedPathType","createPublishedType","unpublish","where","pid","published","version","includes","Number","split","pop","sortKey","result","list","latest","after","previousCursor","limit","initialLimit","createLimit","body","createElasticsearchQueryBody","searchPlugins","byType","SearchPublishedPagesPlugin","type","SearchLatestPagesPlugin","plugin","modifyQuery","query","args","modifySort","sort","response","esConfig","search","meta","hasMoreItems","totalCount","cursor","hits","total","map","_source","encodeCursor","value","listTags","tenant","locale","undefined","size","aggs","tags","terms","field","include","aggregations","Array","isArray","buckets","key","listRevisions","beginsWith","fields","PageDynamoDbElasticsearchFieldPlugin","sortItems","delete"],"sources":["index.ts"],"sourcesContent":["import {\n Page,\n PageStorageOperations,\n PageStorageOperationsCreateFromParams,\n PageStorageOperationsCreateParams,\n PageStorageOperationsDeleteAllParams,\n PageStorageOperationsDeleteParams,\n PageStorageOperationsGetParams,\n PageStorageOperationsListParams,\n PageStorageOperationsListResponse,\n PageStorageOperationsListRevisionsParams,\n PageStorageOperationsListTagsParams,\n PageStorageOperationsPublishParams,\n PageStorageOperationsUnpublishParams,\n PageStorageOperationsUpdateParams\n} from \"@webiny/api-page-builder/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport omit from \"lodash/omit\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport {\n ElasticsearchBoolQueryConfig,\n ElasticsearchSearchResponse\n} from \"@webiny/api-elasticsearch/types\";\nimport { configurations } from \"~/configurations\";\nimport { encodeCursor, createLimit } from \"@webiny/api-elasticsearch\";\nimport { createElasticsearchQueryBody } from \"./elasticsearchQueryBody\";\nimport { SearchLatestPagesPlugin } from \"~/plugins/definitions/SearchLatestPagesPlugin\";\nimport { SearchPublishedPagesPlugin } from \"~/plugins/definitions/SearchPublishedPagesPlugin\";\nimport { DbItem, queryAll, QueryAllParams, queryOne } from \"@webiny/db-dynamodb/utils/query\";\nimport { SearchPagesPlugin } from \"~/plugins/definitions/SearchPagesPlugin\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport { getESLatestPageData, getESPublishedPageData } from \"./helpers\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n createBasicType,\n createLatestSortKey,\n createLatestType,\n createPartitionKey,\n createPathPartitionKey,\n createPathSortKey,\n createPublishedPathType,\n createPublishedSortKey,\n createPublishedType,\n createSortKey\n} from \"./keys\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { PageDynamoDbElasticsearchFieldPlugin } from \"~/plugins/definitions/PageDynamoDbElasticsearchFieldPlugin\";\n\n/**\n * This function removes attributes that were once present in the Page record, which we no longer need.\n */\nfunction removePageAttributes(item: Page): Page {\n return omit(item, [\"home\", \"notFound\", \"visibility\"]) as Page;\n}\n\nexport interface CreatePageStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n elasticsearch: Client;\n plugins: PluginsContainer;\n}\nexport const createPageStorageOperations = (\n params: CreatePageStorageOperationsParams\n): PageStorageOperations => {\n const { entity, esEntity, elasticsearch, plugins } = params;\n\n const create = async (params: PageStorageOperationsCreateParams): Promise<Page> => {\n const { page } = params;\n\n const versionKeys = {\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n };\n const latestKeys = {\n ...versionKeys,\n SK: createLatestSortKey()\n };\n\n const items = [\n entity.putBatch({\n ...page,\n ...versionKeys,\n TYPE: createBasicType()\n }),\n entity.putBatch({\n ...page,\n ...latestKeys,\n TYPE: createLatestType()\n })\n ];\n const esData = getESLatestPageData(plugins, page);\n try {\n await batchWriteAll({\n table: entity.table,\n items: items\n });\n await esEntity.put({\n index: configurations.es(page).index,\n data: esData,\n ...latestKeys\n });\n return page;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create new page.\",\n ex.code || \"CREATE_PAGE_ERROR\",\n {\n versionKeys,\n latestKeys,\n page\n }\n );\n }\n };\n\n const createFrom = async (params: PageStorageOperationsCreateFromParams): Promise<Page> => {\n const { page, latestPage, original } = params;\n\n const versionKeys = {\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n };\n const latestKeys = {\n ...versionKeys,\n SK: createLatestSortKey()\n };\n\n const items = [\n entity.putBatch({\n ...page,\n TYPE: createBasicType(),\n ...versionKeys\n }),\n entity.putBatch({\n ...page,\n TYPE: createLatestType(),\n ...latestKeys\n })\n ];\n\n const esData = getESLatestPageData(plugins, page);\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n\n await esEntity.put({\n index: configurations.es(page).index,\n data: esData,\n ...latestKeys\n });\n return page;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create new page from existing page.\",\n ex.code || \"CREATE_PAGE_FROM_ERROR\",\n {\n versionKeys,\n latestKeys,\n latestPage,\n original,\n page\n }\n );\n }\n };\n\n const update = async (params: PageStorageOperationsUpdateParams): Promise<Page> => {\n const { original, page } = params;\n\n const keys = {\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n };\n\n const latestKeys = {\n ...keys,\n SK: createLatestSortKey()\n };\n const latestPageResult = await entity.get(latestKeys);\n const latestPage = cleanupItem(entity, latestPageResult ? latestPageResult.Item : null);\n\n const items = [\n entity.putBatch({\n ...page,\n TYPE: createBasicType(),\n ...keys\n })\n ];\n\n const esData = getESLatestPageData(plugins, page);\n\n if (latestPage && latestPage.id === page.id) {\n /**\n * We also update the regular record.\n */\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createLatestType(),\n ...latestKeys\n })\n );\n }\n /**\n * Unfortunately we cannot push regular and es record in the batch write because they are two separate tables.\n */\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n\n await esEntity.put({\n index: configurations.es(page).index,\n data: esData,\n ...latestKeys\n });\n\n return page;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update existing page.\",\n ex.code || \"UPDATE_PAGE_ERROR\",\n {\n original,\n page,\n latestPage,\n latestKeys,\n keys\n }\n );\n }\n };\n\n /**\n * In case of delete, we must delete records:\n * - revision\n * - path if published\n * Update:\n * - latest\n */\n const deleteOne = async (\n params: PageStorageOperationsDeleteParams\n ): Promise<[Page, Page | null]> => {\n const { page, latestPage, publishedPage } = params;\n\n const partitionKey = createPartitionKey(page);\n\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createSortKey(page)\n })\n ];\n const esItems = [];\n if (publishedPage && publishedPage.id === page.id) {\n items.push(\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n items.push(\n entity.deleteBatch({\n PK: createPathPartitionKey(page),\n SK: createPathSortKey(page)\n })\n );\n esItems.push(\n esEntity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n let previousLatestPage: Page | null = null;\n if (latestPage && latestPage.id === page.id) {\n const previousLatestRecord = await queryOne<Page>({\n entity,\n partitionKey,\n options: {\n lt: createSortKey(latestPage),\n reverse: true\n }\n });\n if (previousLatestRecord) {\n items.push(\n entity.putBatch({\n ...previousLatestRecord,\n TYPE: createLatestType(),\n PK: partitionKey,\n SK: createLatestSortKey()\n })\n );\n esItems.push(\n esEntity.putBatch({\n PK: partitionKey,\n SK: createLatestSortKey(),\n index: configurations.es(page).index,\n data: getESLatestPageData(plugins, previousLatestRecord)\n })\n );\n previousLatestPage = cleanupItem(entity, previousLatestRecord);\n }\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch write all the page records.\",\n ex.code || \"BATCH_WRITE_RECORDS_ERROR\"\n );\n }\n if (esItems.length === 0) {\n return [page, previousLatestPage];\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items: esItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch write all the page Elasticsearch records.\",\n ex.code || \"BATCH_WRITE_ELASTICSEARCH_RECORDS_ERROR\"\n );\n }\n return [page, previousLatestPage];\n };\n\n /**\n * In case of deleteAll, we must delete records:\n * - latest\n * - published\n * - path if published\n * - revision\n * - es latest\n * - es published\n */\n const deleteAll = async (params: PageStorageOperationsDeleteAllParams): Promise<[Page]> => {\n const { page } = params;\n\n const partitionKey = createPartitionKey(page);\n const queryAllParams = {\n entity,\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n let revisions: DbItem<Page>[];\n try {\n revisions = await queryAll<Page>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query for all revisions of the page.\",\n ex.code || \"LIST_REVISIONS_ERROR\",\n {\n params: queryAllParams\n }\n );\n }\n\n /**\n * We need to go through all possible entries and delete them.\n * Also, delete the published entry path record.\n */\n const items = [];\n let publishedPathEntryDeleted = false;\n for (const revision of revisions) {\n if (revision.status === \"published\" && !publishedPathEntryDeleted) {\n publishedPathEntryDeleted = true;\n items.push(\n entity.deleteBatch({\n PK: createPathPartitionKey(page),\n SK: revision.path\n })\n );\n }\n items.push(\n entity.deleteBatch({\n PK: revision.PK,\n SK: revision.SK\n })\n );\n }\n const esItems = [\n esEntity.deleteBatch({\n PK: partitionKey,\n SK: createLatestSortKey()\n })\n ];\n /**\n * Delete published record if it is published.\n */\n if (publishedPathEntryDeleted) {\n esItems.push(\n esEntity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete all the page records.\",\n ex.code || \"DELETE_RECORDS_ERROR\"\n );\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items: esItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete all the page Elasticsearch records.\",\n ex.code || \"DELETE_ELASTICSEARCH_RECORDS_ERROR\"\n );\n }\n return [page];\n };\n\n const publish = async (params: PageStorageOperationsPublishParams): Promise<Page> => {\n const { page, latestPage, publishedPage } = params;\n\n /**\n * Update the given revision of the page.\n */\n const items = [\n entity.putBatch({\n ...page,\n TYPE: createBasicType(),\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n })\n ];\n const esItems = [];\n /**\n * If we are publishing the latest revision, let's also update the latest revision entry's\n * status in ES. Also, if we are publishing the latest revision, we need to update the latest\n * page revision entry in ES.\n */\n if (latestPage.id === page.id) {\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createLatestType(),\n PK: createPartitionKey(page),\n SK: createLatestSortKey()\n })\n );\n\n esItems.push(\n esEntity.putBatch({\n PK: createPartitionKey(page),\n SK: createLatestSortKey(),\n index: configurations.es(page).index,\n data: getESLatestPageData(plugins, page)\n })\n );\n }\n /**\n * If we have already published revision of this page:\n * - set existing published page revision to unpublished\n * - remove old published path if paths are different\n */\n if (publishedPage) {\n items.push(\n entity.putBatch({\n ...publishedPage,\n status: \"unpublished\",\n PK: createPartitionKey(publishedPage),\n SK: createSortKey(publishedPage)\n })\n );\n /**\n * Remove old published path if required.\n */\n if (publishedPage.path !== page.path) {\n items.push(\n entity.deleteBatch({\n PK: createPathPartitionKey(page),\n SK: publishedPage.path\n })\n );\n }\n }\n\n esItems.push(\n esEntity.putBatch({\n PK: createPartitionKey(page),\n SK: createPublishedSortKey(),\n index: configurations.es(page).index,\n data: getESPublishedPageData(plugins, page)\n })\n );\n\n /**\n * Update or insert published path.\n */\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createPublishedPathType(),\n PK: createPathPartitionKey(page),\n SK: createPathSortKey(page)\n })\n );\n /**\n * Update or insert published page.\n */\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createPublishedType(),\n PK: createPartitionKey(page),\n SK: createPublishedSortKey()\n })\n );\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update all the page records when publishing.\",\n ex.code || \"UPDATE_RECORDS_ERROR\"\n );\n }\n /**\n * No point in continuing if there are no items in Elasticsearch data\n */\n if (esItems.length === 0) {\n return page;\n }\n try {\n await batchWriteAll({\n table: esEntity.table,\n items: esItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not update all the page Elasticsearch records when publishing.\",\n ex.code || \"UPDATE_ELASTICSEARCH_RECORDS_ERROR\"\n );\n }\n return page;\n };\n\n const unpublish = async (params: PageStorageOperationsUnpublishParams): Promise<Page> => {\n const { page, latestPage } = params;\n\n const items = [\n entity.deleteBatch({\n PK: createPartitionKey(page),\n SK: createPublishedSortKey()\n }),\n entity.deleteBatch({\n PK: createPathPartitionKey(page),\n SK: createPathSortKey(page)\n }),\n entity.putBatch({\n ...page,\n TYPE: createBasicType(),\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n })\n ];\n const esItems = [];\n /*\n * If we are unpublishing the latest revision, let's also update the latest revision entry's status in ES.\n */\n if (latestPage.id === page.id) {\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createLatestType(),\n PK: createPartitionKey(page),\n SK: createLatestSortKey()\n })\n );\n esItems.push(\n esEntity.putBatch({\n PK: createPartitionKey(page),\n SK: createLatestSortKey(),\n index: configurations.es(page).index,\n data: getESLatestPageData(plugins, page)\n })\n );\n }\n\n esItems.push(\n esEntity.deleteBatch({\n PK: createPartitionKey(page),\n SK: createPublishedSortKey()\n })\n );\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update all the page records when unpublishing.\",\n ex.code || \"UPDATE_RECORDS_ERROR\"\n );\n }\n /**\n * No need to go further if no Elasticsearch items to be applied.\n */\n if (esItems.length === 0) {\n return page;\n }\n try {\n await batchWriteAll({\n table: esEntity.table,\n items: esItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not update all the page Elasticsearch records when unpublishing.\",\n ex.code || \"UPDATE_ELASTICSEARCH_RECORDS_ERROR\"\n );\n }\n return page;\n };\n\n const get = async (params: PageStorageOperationsGetParams): Promise<Page | null> => {\n const { where } = params;\n const { pid, id, path, published } = where;\n let { version } = where;\n /**\n * In case of having full ID and not having version we can take the version from the id.\n */\n if (id && id.includes(\"#\") && !version) {\n version = Number(id.split(\"#\").pop());\n }\n let partitionKey: string | null = null;\n let sortKey: string;\n if (path) {\n partitionKey = createPathPartitionKey(where);\n sortKey = path;\n } else if (published) {\n sortKey = createPublishedSortKey();\n } else if (version) {\n sortKey = createSortKey({\n version\n });\n } else {\n sortKey = createLatestSortKey();\n }\n /**\n * If partition key is still undefined, create one with id or pid\n */\n if (!partitionKey) {\n partitionKey = createPartitionKey({\n ...where,\n id: pid || (id as string)\n });\n }\n const keys = {\n PK: partitionKey,\n SK: sortKey\n };\n try {\n const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load page by given params.\",\n ex.code || \"GET_PAGE_ERROR\",\n {\n where,\n keys\n }\n );\n }\n };\n\n const list = async (\n params: PageStorageOperationsListParams\n ): Promise<PageStorageOperationsListResponse> => {\n /**\n * We do not allow loading both published and latest at the same time.\n * @see PageStorageOperationsListWhere\n */\n if (params.where.published && params.where.latest) {\n throw new WebinyError(\n \"Both published and latest cannot be defined at the same time.\",\n \"MALFORMED_WHERE_ERROR\",\n {\n where: params.where\n }\n );\n }\n\n const { after: previousCursor = null, limit: initialLimit } = params;\n\n const limit = createLimit(initialLimit, 50);\n const body = createElasticsearchQueryBody({\n ...params,\n where: {\n ...params.where\n },\n limit,\n after: previousCursor,\n plugins\n });\n\n let searchPlugins: SearchPagesPlugin[] = [];\n if (params.where.published) {\n searchPlugins = plugins.byType<SearchPublishedPagesPlugin>(\n SearchPublishedPagesPlugin.type\n );\n } else if (params.where.latest) {\n searchPlugins = plugins.byType<SearchLatestPagesPlugin>(SearchLatestPagesPlugin.type);\n } else {\n throw new WebinyError(\n \"Only published or latest can be listed. Missing where condition.\",\n \"MALFORMED_WHERE_ERROR\",\n {\n where: params.where\n }\n );\n }\n\n for (const plugin of searchPlugins) {\n /**\n * Apply query modifications\n */\n plugin.modifyQuery({\n query: body.query as unknown as ElasticsearchBoolQueryConfig,\n args: params,\n plugins\n });\n\n /**\n * Apply sort modifications\n */\n plugin.modifySort({\n sort: body.sort,\n args: params,\n plugins\n });\n }\n\n let response: ElasticsearchSearchResponse<Page>;\n const esConfig = configurations.es(params.where);\n try {\n response = await elasticsearch.search({\n ...esConfig,\n body\n });\n } catch (ex) {\n /**\n * Do not throw the error if Elasticsearch index does not exist.\n * In some CRUDs we try to get list of pages but index was not created yet.\n */\n if (ex.message === \"index_not_found_exception\") {\n return {\n items: [],\n meta: {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null\n }\n };\n }\n throw new WebinyError(\n ex.message || \"Could not load pages by given Elasticsearch body.\",\n ex.code || \"LIST_PAGES_ERROR\",\n {\n body\n }\n );\n }\n const { hits, total } = response.body.hits;\n const items = hits.map(item => item._source).map(item => removePageAttributes(item));\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n const cursor =\n items.length > 0 && hasMoreItems\n ? encodeCursor(hits[items.length - 1].sort) || null\n : null;\n return {\n items,\n meta: {\n hasMoreItems,\n totalCount: total.value,\n cursor\n }\n };\n };\n\n const listTags = async (params: PageStorageOperationsListTagsParams): Promise<string[]> => {\n const { where } = params;\n\n const tenant: string = where.tenant;\n const body = createElasticsearchQueryBody({\n ...params,\n where: {\n locale: where.locale,\n search: undefined,\n tenant\n },\n sort: [],\n after: null,\n limit: 100000,\n plugins\n });\n\n const esConfig = configurations.es(where);\n\n try {\n const response: ElasticsearchSearchResponse<string> = await elasticsearch.search({\n ...esConfig,\n body: {\n ...body,\n sort: undefined,\n limit: undefined,\n size: 0,\n aggs: {\n tags: {\n terms: {\n field: \"tags.keyword\",\n include: `.*${where.search}.*`,\n size: 10\n }\n }\n }\n }\n });\n\n const tags = response.body.aggregations[\"tags\"];\n if (!tags || Array.isArray(tags.buckets) === false) {\n return [];\n }\n return tags.buckets.map(item => item.key);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list tags by given parameters.\",\n ex.code || \"LIST_TAGS_ERROR\",\n {\n body,\n where\n }\n );\n }\n };\n\n const listRevisions = async (\n params: PageStorageOperationsListRevisionsParams\n ): Promise<Page[]> => {\n const { where, sort } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n ...where,\n id: where.pid\n }),\n options: {\n beginsWith: \"REV#\",\n reverse: false\n }\n };\n\n let items: Page[] = [];\n try {\n items = await queryAll<Page>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load all the revisions from requested page.\",\n ex.code || \"LOAD_PAGE_REVISIONS_ERROR\",\n {\n params\n }\n );\n }\n\n const fields = plugins.byType<PageDynamoDbElasticsearchFieldPlugin>(\n PageDynamoDbElasticsearchFieldPlugin.type\n );\n\n return sortItems({\n items: items.map(item => removePageAttributes(item)),\n fields,\n sort\n });\n };\n\n return {\n create,\n createFrom,\n update,\n delete: deleteOne,\n deleteAll: deleteAll,\n publish,\n unpublish,\n get,\n list,\n listRevisions,\n listTags\n };\n};\n"],"mappings":";;;;;;;;AAiBA;AACA;AACA;AAMA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AAYA;AACA;AAEA;AACA;AACA;AACA,SAASA,oBAAoB,CAACC,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AA,KAAK,GAAG,MAAM,IAAAgD,eAAQ,EAAOH,cAAc,CAAC;IAChD,CAAC,CAAC,OAAO/B,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,uDAAuD,EACrEF,EAAE,CAACG,IAAI,IAAI,2BAA2B,EACtC;QACI/B;MACJ,CAAC,CACJ;IACL;IAEA,MAAMoI,MAAM,GAAGhI,OAAO,CAACwF,MAAM,CACzByC,0EAAoC,CAACvC,IAAI,CAC5C;IAED,OAAO,IAAAwC,eAAS,EAAC;MACbxH,KAAK,EAAEA,KAAK,CAACiG,GAAG,CAAClH,IAAI,IAAID,oBAAoB,CAACC,IAAI,CAAC,CAAC;MACpDuI,MAAM;MACN/B;IACJ,CAAC,CAAC;EACN,CAAC;EAED,OAAO;IACHhG,MAAM;IACN2B,UAAU;IACVG,MAAM;IACNoG,MAAM,EAAE5F,SAAS;IACjBe,SAAS,EAAEA,SAAS;IACpBS,OAAO;IACPI,SAAS;IACTjC,GAAG;IACH4C,IAAI;IACJgD,aAAa;IACbf;EACJ,CAAC;AACL,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"names":["removePageAttributes","item","omit","createPageStorageOperations","params","entity","esEntity","elasticsearch","plugins","create","page","input","versionKeys","PK","createPartitionKey","SK","createSortKey","latestKeys","createLatestSortKey","items","putBatch","TYPE","createBasicType","createLatestType","esData","getESLatestPageData","batchWriteAll","table","put","index","configurations","es","data","ex","WebinyError","message","code","createFrom","latestPage","original","update","keys","latestPageResult","get","cleanupItem","Item","id","push","deleteOne","publishedPage","partitionKey","deleteBatch","esItems","createPublishedSortKey","createPathPartitionKey","createPathSortKey","previousLatestPage","previousLatestRecord","queryOne","options","lt","reverse","length","deleteAll","queryAllParams","gte","revisions","queryAll","publishedPathEntryDeleted","revision","status","path","publish","getESPublishedPageData","createPublishedPathType","createPublishedType","unpublish","where","pid","published","version","includes","Number","split","pop","sortKey","result","list","latest","after","previousCursor","limit","initialLimit","createLimit","body","createElasticsearchQueryBody","searchPlugins","byType","SearchPublishedPagesPlugin","type","SearchLatestPagesPlugin","plugin","modifyQuery","query","args","modifySort","sort","response","esConfig","search","meta","hasMoreItems","totalCount","cursor","hits","total","map","_source","encodeCursor","value","listTags","tenant","locale","undefined","size","aggs","tags","terms","field","include","aggregations","Array","isArray","buckets","key","listRevisions","beginsWith","fields","PageDynamoDbElasticsearchFieldPlugin","sortItems","delete"],"sources":["index.ts"],"sourcesContent":["import {\n Page,\n PageStorageOperations,\n PageStorageOperationsCreateFromParams,\n PageStorageOperationsCreateParams,\n PageStorageOperationsDeleteAllParams,\n PageStorageOperationsDeleteParams,\n PageStorageOperationsGetParams,\n PageStorageOperationsListParams,\n PageStorageOperationsListResponse,\n PageStorageOperationsListRevisionsParams,\n PageStorageOperationsListTagsParams,\n PageStorageOperationsPublishParams,\n PageStorageOperationsUnpublishParams,\n PageStorageOperationsUpdateParams\n} from \"@webiny/api-page-builder/types\";\nimport { Entity } from \"dynamodb-toolbox\";\nimport omit from \"lodash/omit\";\nimport WebinyError from \"@webiny/error\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport {\n ElasticsearchBoolQueryConfig,\n ElasticsearchSearchResponse\n} from \"@webiny/api-elasticsearch/types\";\nimport { configurations } from \"~/configurations\";\nimport { encodeCursor, createLimit } from \"@webiny/api-elasticsearch\";\nimport { createElasticsearchQueryBody } from \"./elasticsearchQueryBody\";\nimport { SearchLatestPagesPlugin } from \"~/plugins/definitions/SearchLatestPagesPlugin\";\nimport { SearchPublishedPagesPlugin } from \"~/plugins/definitions/SearchPublishedPagesPlugin\";\nimport { DbItem, queryAll, QueryAllParams, queryOne } from \"@webiny/db-dynamodb/utils/query\";\nimport { SearchPagesPlugin } from \"~/plugins/definitions/SearchPagesPlugin\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport { getESLatestPageData, getESPublishedPageData } from \"./helpers\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n createBasicType,\n createLatestSortKey,\n createLatestType,\n createPartitionKey,\n createPathPartitionKey,\n createPathSortKey,\n createPublishedPathType,\n createPublishedSortKey,\n createPublishedType,\n createSortKey\n} from \"./keys\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { PageDynamoDbElasticsearchFieldPlugin } from \"~/plugins/definitions/PageDynamoDbElasticsearchFieldPlugin\";\n\n/**\n * This function removes attributes that were once present in the Page record, which we no longer need.\n */\nfunction removePageAttributes(item: Page): Page {\n return omit(item, [\"home\", \"notFound\", \"visibility\"]) as Page;\n}\n\nexport interface CreatePageStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n elasticsearch: Client;\n plugins: PluginsContainer;\n}\nexport const createPageStorageOperations = (\n params: CreatePageStorageOperationsParams\n): PageStorageOperations => {\n const { entity, esEntity, elasticsearch, plugins } = params;\n\n const create = async (params: PageStorageOperationsCreateParams): Promise<Page> => {\n const { page, input } = params;\n\n const versionKeys = {\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n };\n const latestKeys = {\n ...versionKeys,\n SK: createLatestSortKey()\n };\n\n const items = [\n entity.putBatch({\n ...page,\n ...versionKeys,\n TYPE: createBasicType()\n }),\n entity.putBatch({\n ...page,\n ...latestKeys,\n TYPE: createLatestType()\n })\n ];\n const esData = getESLatestPageData(plugins, page, input);\n try {\n await batchWriteAll({\n table: entity.table,\n items: items\n });\n await esEntity.put({\n index: configurations.es(page).index,\n data: esData,\n ...latestKeys\n });\n return page;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create new page.\",\n ex.code || \"CREATE_PAGE_ERROR\",\n {\n versionKeys,\n latestKeys,\n page\n }\n );\n }\n };\n\n const createFrom = async (params: PageStorageOperationsCreateFromParams): Promise<Page> => {\n const { page, latestPage, original } = params;\n\n const versionKeys = {\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n };\n const latestKeys = {\n ...versionKeys,\n SK: createLatestSortKey()\n };\n\n const items = [\n entity.putBatch({\n ...page,\n TYPE: createBasicType(),\n ...versionKeys\n }),\n entity.putBatch({\n ...page,\n TYPE: createLatestType(),\n ...latestKeys\n })\n ];\n\n const esData = getESLatestPageData(plugins, page);\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n\n await esEntity.put({\n index: configurations.es(page).index,\n data: esData,\n ...latestKeys\n });\n return page;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create new page from existing page.\",\n ex.code || \"CREATE_PAGE_FROM_ERROR\",\n {\n versionKeys,\n latestKeys,\n latestPage,\n original,\n page\n }\n );\n }\n };\n\n const update = async (params: PageStorageOperationsUpdateParams): Promise<Page> => {\n const { original, page, input } = params;\n\n const keys = {\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n };\n\n const latestKeys = {\n ...keys,\n SK: createLatestSortKey()\n };\n const latestPageResult = await entity.get(latestKeys);\n const latestPage = cleanupItem(entity, latestPageResult ? latestPageResult.Item : null);\n\n const items = [\n entity.putBatch({\n ...page,\n TYPE: createBasicType(),\n ...keys\n })\n ];\n\n const esData = getESLatestPageData(plugins, page, input);\n\n if (latestPage && latestPage.id === page.id) {\n /**\n * We also update the regular record.\n */\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createLatestType(),\n ...latestKeys\n })\n );\n }\n /**\n * Unfortunately we cannot push regular and es record in the batch write because they are two separate tables.\n */\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n\n await esEntity.put({\n index: configurations.es(page).index,\n data: esData,\n ...latestKeys\n });\n\n return page;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update existing page.\",\n ex.code || \"UPDATE_PAGE_ERROR\",\n {\n original,\n page,\n latestPage,\n latestKeys,\n keys\n }\n );\n }\n };\n\n /**\n * In case of delete, we must delete records:\n * - revision\n * - path if published\n * Update:\n * - latest\n */\n const deleteOne = async (\n params: PageStorageOperationsDeleteParams\n ): Promise<[Page, Page | null]> => {\n const { page, latestPage, publishedPage } = params;\n\n const partitionKey = createPartitionKey(page);\n\n const items = [\n entity.deleteBatch({\n PK: partitionKey,\n SK: createSortKey(page)\n })\n ];\n const esItems = [];\n if (publishedPage && publishedPage.id === page.id) {\n items.push(\n entity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n items.push(\n entity.deleteBatch({\n PK: createPathPartitionKey(page),\n SK: createPathSortKey(page)\n })\n );\n esItems.push(\n esEntity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n let previousLatestPage: Page | null = null;\n if (latestPage && latestPage.id === page.id) {\n const previousLatestRecord = await queryOne<Page>({\n entity,\n partitionKey,\n options: {\n lt: createSortKey(latestPage),\n reverse: true\n }\n });\n if (previousLatestRecord) {\n items.push(\n entity.putBatch({\n ...previousLatestRecord,\n TYPE: createLatestType(),\n PK: partitionKey,\n SK: createLatestSortKey()\n })\n );\n esItems.push(\n esEntity.putBatch({\n PK: partitionKey,\n SK: createLatestSortKey(),\n index: configurations.es(page).index,\n data: getESLatestPageData(plugins, previousLatestRecord)\n })\n );\n previousLatestPage = cleanupItem(entity, previousLatestRecord);\n }\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch write all the page records.\",\n ex.code || \"BATCH_WRITE_RECORDS_ERROR\"\n );\n }\n if (esItems.length === 0) {\n return [page, previousLatestPage];\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items: esItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch write all the page Elasticsearch records.\",\n ex.code || \"BATCH_WRITE_ELASTICSEARCH_RECORDS_ERROR\"\n );\n }\n return [page, previousLatestPage];\n };\n\n /**\n * In case of deleteAll, we must delete records:\n * - latest\n * - published\n * - path if published\n * - revision\n * - es latest\n * - es published\n */\n const deleteAll = async (params: PageStorageOperationsDeleteAllParams): Promise<[Page]> => {\n const { page } = params;\n\n const partitionKey = createPartitionKey(page);\n const queryAllParams = {\n entity,\n partitionKey,\n options: {\n gte: \" \"\n }\n };\n let revisions: DbItem<Page>[];\n try {\n revisions = await queryAll<Page>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not query for all revisions of the page.\",\n ex.code || \"LIST_REVISIONS_ERROR\",\n {\n params: queryAllParams\n }\n );\n }\n\n /**\n * We need to go through all possible entries and delete them.\n * Also, delete the published entry path record.\n */\n const items = [];\n let publishedPathEntryDeleted = false;\n for (const revision of revisions) {\n if (revision.status === \"published\" && !publishedPathEntryDeleted) {\n publishedPathEntryDeleted = true;\n items.push(\n entity.deleteBatch({\n PK: createPathPartitionKey(page),\n SK: revision.path\n })\n );\n }\n items.push(\n entity.deleteBatch({\n PK: revision.PK,\n SK: revision.SK\n })\n );\n }\n const esItems = [\n esEntity.deleteBatch({\n PK: partitionKey,\n SK: createLatestSortKey()\n })\n ];\n /**\n * Delete published record if it is published.\n */\n if (publishedPathEntryDeleted) {\n esItems.push(\n esEntity.deleteBatch({\n PK: partitionKey,\n SK: createPublishedSortKey()\n })\n );\n }\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete all the page records.\",\n ex.code || \"DELETE_RECORDS_ERROR\"\n );\n }\n try {\n await batchWriteAll({\n table: entity.table,\n items: esItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete all the page Elasticsearch records.\",\n ex.code || \"DELETE_ELASTICSEARCH_RECORDS_ERROR\"\n );\n }\n return [page];\n };\n\n const publish = async (params: PageStorageOperationsPublishParams): Promise<Page> => {\n const { page, latestPage, publishedPage } = params;\n\n /**\n * Update the given revision of the page.\n */\n const items = [\n entity.putBatch({\n ...page,\n TYPE: createBasicType(),\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n })\n ];\n const esItems = [];\n /**\n * If we are publishing the latest revision, let's also update the latest revision entry's\n * status in ES. Also, if we are publishing the latest revision, we need to update the latest\n * page revision entry in ES.\n */\n if (latestPage.id === page.id) {\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createLatestType(),\n PK: createPartitionKey(page),\n SK: createLatestSortKey()\n })\n );\n\n esItems.push(\n esEntity.putBatch({\n PK: createPartitionKey(page),\n SK: createLatestSortKey(),\n index: configurations.es(page).index,\n data: getESLatestPageData(plugins, page)\n })\n );\n }\n /**\n * If we have already published revision of this page:\n * - set existing published page revision to unpublished\n * - remove old published path if paths are different\n */\n if (publishedPage) {\n items.push(\n entity.putBatch({\n ...publishedPage,\n status: \"unpublished\",\n PK: createPartitionKey(publishedPage),\n SK: createSortKey(publishedPage)\n })\n );\n /**\n * Remove old published path if required.\n */\n if (publishedPage.path !== page.path) {\n items.push(\n entity.deleteBatch({\n PK: createPathPartitionKey(page),\n SK: publishedPage.path\n })\n );\n }\n }\n\n esItems.push(\n esEntity.putBatch({\n PK: createPartitionKey(page),\n SK: createPublishedSortKey(),\n index: configurations.es(page).index,\n data: getESPublishedPageData(plugins, page)\n })\n );\n\n /**\n * Update or insert published path.\n */\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createPublishedPathType(),\n PK: createPathPartitionKey(page),\n SK: createPathSortKey(page)\n })\n );\n /**\n * Update or insert published page.\n */\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createPublishedType(),\n PK: createPartitionKey(page),\n SK: createPublishedSortKey()\n })\n );\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update all the page records when publishing.\",\n ex.code || \"UPDATE_RECORDS_ERROR\"\n );\n }\n /**\n * No point in continuing if there are no items in Elasticsearch data\n */\n if (esItems.length === 0) {\n return page;\n }\n try {\n await batchWriteAll({\n table: esEntity.table,\n items: esItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not update all the page Elasticsearch records when publishing.\",\n ex.code || \"UPDATE_ELASTICSEARCH_RECORDS_ERROR\"\n );\n }\n return page;\n };\n\n const unpublish = async (params: PageStorageOperationsUnpublishParams): Promise<Page> => {\n const { page, latestPage } = params;\n\n const items = [\n entity.deleteBatch({\n PK: createPartitionKey(page),\n SK: createPublishedSortKey()\n }),\n entity.deleteBatch({\n PK: createPathPartitionKey(page),\n SK: createPathSortKey(page)\n }),\n entity.putBatch({\n ...page,\n TYPE: createBasicType(),\n PK: createPartitionKey(page),\n SK: createSortKey(page)\n })\n ];\n const esItems = [];\n /*\n * If we are unpublishing the latest revision, let's also update the latest revision entry's status in ES.\n */\n if (latestPage.id === page.id) {\n items.push(\n entity.putBatch({\n ...page,\n TYPE: createLatestType(),\n PK: createPartitionKey(page),\n SK: createLatestSortKey()\n })\n );\n esItems.push(\n esEntity.putBatch({\n PK: createPartitionKey(page),\n SK: createLatestSortKey(),\n index: configurations.es(page).index,\n data: getESLatestPageData(plugins, page)\n })\n );\n }\n\n esItems.push(\n esEntity.deleteBatch({\n PK: createPartitionKey(page),\n SK: createPublishedSortKey()\n })\n );\n\n try {\n await batchWriteAll({\n table: entity.table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update all the page records when unpublishing.\",\n ex.code || \"UPDATE_RECORDS_ERROR\"\n );\n }\n /**\n * No need to go further if no Elasticsearch items to be applied.\n */\n if (esItems.length === 0) {\n return page;\n }\n try {\n await batchWriteAll({\n table: esEntity.table,\n items: esItems\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message ||\n \"Could not update all the page Elasticsearch records when unpublishing.\",\n ex.code || \"UPDATE_ELASTICSEARCH_RECORDS_ERROR\"\n );\n }\n return page;\n };\n\n const get = async (params: PageStorageOperationsGetParams): Promise<Page | null> => {\n const { where } = params;\n const { pid, id, path, published } = where;\n let { version } = where;\n /**\n * In case of having full ID and not having version we can take the version from the id.\n */\n if (id && id.includes(\"#\") && !version) {\n version = Number(id.split(\"#\").pop());\n }\n let partitionKey: string | null = null;\n let sortKey: string;\n if (path) {\n partitionKey = createPathPartitionKey(where);\n sortKey = path;\n } else if (published) {\n sortKey = createPublishedSortKey();\n } else if (version) {\n sortKey = createSortKey({\n version\n });\n } else {\n sortKey = createLatestSortKey();\n }\n /**\n * If partition key is still undefined, create one with id or pid\n */\n if (!partitionKey) {\n partitionKey = createPartitionKey({\n ...where,\n id: pid || (id as string)\n });\n }\n const keys = {\n PK: partitionKey,\n SK: sortKey\n };\n try {\n const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load page by given params.\",\n ex.code || \"GET_PAGE_ERROR\",\n {\n where,\n keys\n }\n );\n }\n };\n\n const list = async (\n params: PageStorageOperationsListParams\n ): Promise<PageStorageOperationsListResponse> => {\n /**\n * We do not allow loading both published and latest at the same time.\n * @see PageStorageOperationsListWhere\n */\n if (params.where.published && params.where.latest) {\n throw new WebinyError(\n \"Both published and latest cannot be defined at the same time.\",\n \"MALFORMED_WHERE_ERROR\",\n {\n where: params.where\n }\n );\n }\n\n const { after: previousCursor = null, limit: initialLimit } = params;\n\n const limit = createLimit(initialLimit, 50);\n const body = createElasticsearchQueryBody({\n ...params,\n where: {\n ...params.where\n },\n limit,\n after: previousCursor,\n plugins\n });\n\n let searchPlugins: SearchPagesPlugin[] = [];\n if (params.where.published) {\n searchPlugins = plugins.byType<SearchPublishedPagesPlugin>(\n SearchPublishedPagesPlugin.type\n );\n } else if (params.where.latest) {\n searchPlugins = plugins.byType<SearchLatestPagesPlugin>(SearchLatestPagesPlugin.type);\n } else {\n throw new WebinyError(\n \"Only published or latest can be listed. Missing where condition.\",\n \"MALFORMED_WHERE_ERROR\",\n {\n where: params.where\n }\n );\n }\n\n for (const plugin of searchPlugins) {\n /**\n * Apply query modifications\n */\n plugin.modifyQuery({\n query: body.query as unknown as ElasticsearchBoolQueryConfig,\n args: params,\n plugins\n });\n\n /**\n * Apply sort modifications\n */\n plugin.modifySort({\n sort: body.sort,\n args: params,\n plugins\n });\n }\n\n let response: ElasticsearchSearchResponse<Page>;\n const esConfig = configurations.es(params.where);\n try {\n response = await elasticsearch.search({\n ...esConfig,\n body\n });\n } catch (ex) {\n /**\n * Do not throw the error if Elasticsearch index does not exist.\n * In some CRUDs we try to get list of pages but index was not created yet.\n */\n if (ex.message === \"index_not_found_exception\") {\n return {\n items: [],\n meta: {\n hasMoreItems: false,\n totalCount: 0,\n cursor: null\n }\n };\n }\n throw new WebinyError(\n ex.message || \"Could not load pages by given Elasticsearch body.\",\n ex.code || \"LIST_PAGES_ERROR\",\n {\n body\n }\n );\n }\n const { hits, total } = response.body.hits;\n const items = hits.map(item => item._source).map(item => removePageAttributes(item));\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n const cursor =\n items.length > 0 && hasMoreItems\n ? encodeCursor(hits[items.length - 1].sort) || null\n : null;\n return {\n items,\n meta: {\n hasMoreItems,\n totalCount: total.value,\n cursor\n }\n };\n };\n\n const listTags = async (params: PageStorageOperationsListTagsParams): Promise<string[]> => {\n const { where } = params;\n\n const tenant: string = where.tenant;\n const body = createElasticsearchQueryBody({\n ...params,\n where: {\n locale: where.locale,\n search: undefined,\n tenant\n },\n sort: [],\n after: null,\n limit: 100000,\n plugins\n });\n\n const esConfig = configurations.es(where);\n\n try {\n const response: ElasticsearchSearchResponse<string> = await elasticsearch.search({\n ...esConfig,\n body: {\n ...body,\n sort: undefined,\n limit: undefined,\n size: 0,\n aggs: {\n tags: {\n terms: {\n field: \"tags.keyword\",\n include: `.*${where.search}.*`,\n size: 10\n }\n }\n }\n }\n });\n\n const tags = response.body.aggregations[\"tags\"];\n if (!tags || Array.isArray(tags.buckets) === false) {\n return [];\n }\n return tags.buckets.map(item => item.key);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not list tags by given parameters.\",\n ex.code || \"LIST_TAGS_ERROR\",\n {\n body,\n where\n }\n );\n }\n };\n\n const listRevisions = async (\n params: PageStorageOperationsListRevisionsParams\n ): Promise<Page[]> => {\n const { where, sort } = params;\n\n const queryAllParams: QueryAllParams = {\n entity,\n partitionKey: createPartitionKey({\n ...where,\n id: where.pid\n }),\n options: {\n beginsWith: \"REV#\",\n reverse: false\n }\n };\n\n let items: Page[] = [];\n try {\n items = await queryAll<Page>(queryAllParams);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not load all the revisions from requested page.\",\n ex.code || \"LOAD_PAGE_REVISIONS_ERROR\",\n {\n params\n }\n );\n }\n\n const fields = plugins.byType<PageDynamoDbElasticsearchFieldPlugin>(\n PageDynamoDbElasticsearchFieldPlugin.type\n );\n\n return sortItems({\n items: items.map(item => removePageAttributes(item)),\n fields,\n sort\n });\n };\n\n return {\n create,\n createFrom,\n update,\n delete: deleteOne,\n deleteAll: deleteAll,\n publish,\n unpublish,\n get,\n list,\n listRevisions,\n listTags\n };\n};\n"],"mappings":";;;;;;;;AAiBA;AACA;AACA;AAMA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA;AAYA;AACA;AAEA;AACA;AACA;AACA,SAASA,oBAAoB,CAACC,IAAU,EAAQ;EAC5C,OAAO,IAAAC,aAAI,EAACD,IAAI,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC;AACzD;AAQO,MAAME,2BAA2B,GACpCC,MAAyC,IACjB;EACxB,MAAM;IAAEC,MAAM;IAAEC,QAAQ;IAAEC,aAAa;IAAEC;EAAQ,CAAC,GAAGJ,MAAM;EAE3D,MAAMK,MAAM,GAAG,MAAOL,MAAyC,IAAoB;IAC/E,MAAM;MAAEM,IAAI;MAAEC;IAAM,CAAC,GAAGP,MAAM;IAE9B,MAAMQ,WAAW,GAAG;MAChBC,EAAE,EAAE,IAAAC,wBAAkB,EAACJ,IAAI,CAAC;MAC5BK,EAAE,EAAE,IAAAC,mBAAa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AACiG,GAAG,CAACnH,IAAI,IAAID,oBAAoB,CAACC,IAAI,CAAC,CAAC;MACpDwI,MAAM;MACN/B;IACJ,CAAC,CAAC;EACN,CAAC;EAED,OAAO;IACHjG,MAAM;IACN4B,UAAU;IACVG,MAAM;IACNoG,MAAM,EAAE5F,SAAS;IACjBe,SAAS,EAAEA,SAAS;IACpBS,OAAO;IACPI,SAAS;IACTjC,GAAG;IACH4C,IAAI;IACJgD,aAAa;IACbf;EACJ,CAAC;AACL,CAAC;AAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-page-builder-so-ddb-es",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.606fc9c866",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-page-builder",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "7.20.13",
|
|
21
|
-
"@webiny/api-elasticsearch": "0.0.0-unstable.
|
|
22
|
-
"@webiny/api-page-builder": "0.0.0-unstable.
|
|
23
|
-
"@webiny/db-dynamodb": "0.0.0-unstable.
|
|
24
|
-
"@webiny/error": "0.0.0-unstable.
|
|
25
|
-
"@webiny/handler-db": "0.0.0-unstable.
|
|
26
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
27
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
21
|
+
"@webiny/api-elasticsearch": "0.0.0-unstable.606fc9c866",
|
|
22
|
+
"@webiny/api-page-builder": "0.0.0-unstable.606fc9c866",
|
|
23
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.606fc9c866",
|
|
24
|
+
"@webiny/error": "0.0.0-unstable.606fc9c866",
|
|
25
|
+
"@webiny/handler-db": "0.0.0-unstable.606fc9c866",
|
|
26
|
+
"@webiny/plugins": "0.0.0-unstable.606fc9c866",
|
|
27
|
+
"@webiny/utils": "0.0.0-unstable.606fc9c866",
|
|
28
28
|
"dataloader": "2.2.1",
|
|
29
29
|
"dynamodb-toolbox": "0.3.5",
|
|
30
30
|
"elastic-ts": "0.8.0",
|
|
@@ -37,14 +37,28 @@
|
|
|
37
37
|
"@babel/preset-typescript": "^7.18.6",
|
|
38
38
|
"@elastic/elasticsearch": "7.12.0",
|
|
39
39
|
"@elastic/elasticsearch-mock": "0.3.0",
|
|
40
|
-
"@webiny/api": "^0.0.0-unstable.
|
|
41
|
-
"@webiny/api-
|
|
42
|
-
"@webiny/api-
|
|
43
|
-
"@webiny/api-
|
|
44
|
-
"@webiny/
|
|
45
|
-
"@webiny/
|
|
46
|
-
"@webiny/
|
|
47
|
-
"@webiny/
|
|
40
|
+
"@webiny/api": "^0.0.0-unstable.606fc9c866",
|
|
41
|
+
"@webiny/api-aco": "^0.0.0-unstable.606fc9c866",
|
|
42
|
+
"@webiny/api-dynamodb-to-elasticsearch": "^0.0.0-unstable.606fc9c866",
|
|
43
|
+
"@webiny/api-file-manager": "^0.0.0-unstable.606fc9c866",
|
|
44
|
+
"@webiny/api-file-manager-ddb": "^0.0.0-unstable.606fc9c866",
|
|
45
|
+
"@webiny/api-headless-cms": "^0.0.0-unstable.606fc9c866",
|
|
46
|
+
"@webiny/api-headless-cms-ddb-es": "^0.0.0-unstable.606fc9c866",
|
|
47
|
+
"@webiny/api-i18n": "^0.0.0-unstable.606fc9c866",
|
|
48
|
+
"@webiny/api-i18n-ddb": "^0.0.0-unstable.606fc9c866",
|
|
49
|
+
"@webiny/api-page-builder-aco": "^0.0.0-unstable.606fc9c866",
|
|
50
|
+
"@webiny/api-prerendering-service": "^0.0.0-unstable.606fc9c866",
|
|
51
|
+
"@webiny/api-security": "^0.0.0-unstable.606fc9c866",
|
|
52
|
+
"@webiny/api-security-so-ddb": "^0.0.0-unstable.606fc9c866",
|
|
53
|
+
"@webiny/api-tenancy": "^0.0.0-unstable.606fc9c866",
|
|
54
|
+
"@webiny/api-tenancy-so-ddb": "^0.0.0-unstable.606fc9c866",
|
|
55
|
+
"@webiny/api-wcp": "^0.0.0-unstable.606fc9c866",
|
|
56
|
+
"@webiny/cli": "^0.0.0-unstable.606fc9c866",
|
|
57
|
+
"@webiny/handler": "^0.0.0-unstable.606fc9c866",
|
|
58
|
+
"@webiny/handler-aws": "^0.0.0-unstable.606fc9c866",
|
|
59
|
+
"@webiny/handler-graphql": "^0.0.0-unstable.606fc9c866",
|
|
60
|
+
"@webiny/project-utils": "^0.0.0-unstable.606fc9c866",
|
|
61
|
+
"graphql": "^15.8.0",
|
|
48
62
|
"jest": "^28.1.0",
|
|
49
63
|
"jest-dynalite": "^3.2.0",
|
|
50
64
|
"jest-environment-node": "^27.0.6",
|
|
@@ -60,5 +74,5 @@
|
|
|
60
74
|
"build": "yarn webiny run build",
|
|
61
75
|
"watch": "yarn webiny run watch"
|
|
62
76
|
},
|
|
63
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "606fc9c866aec436f24983abc9bdaf02af2b8746"
|
|
64
78
|
}
|
|
@@ -2,6 +2,7 @@ import { Plugin, PluginsContainer } from "@webiny/plugins";
|
|
|
2
2
|
import { Page } from "@webiny/api-page-builder/types";
|
|
3
3
|
interface ApplyPageDataParams<TPage, TData = Record<string, any>> {
|
|
4
4
|
data: TData;
|
|
5
|
+
input: Record<string, any>;
|
|
5
6
|
page: TPage;
|
|
6
7
|
plugins: PluginsContainer;
|
|
7
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["IndexPageDataPlugin","Plugin","constructor","callable","apply","params"],"sources":["IndexPageDataPlugin.ts"],"sourcesContent":["import { Plugin, PluginsContainer } from \"@webiny/plugins\";\nimport { Page } from \"@webiny/api-page-builder/types\";\n\ninterface ApplyPageDataParams<TPage, TData = Record<string, any>> {\n data: TData;\n page: TPage;\n plugins: PluginsContainer;\n}\n\ninterface ApplyPageDataCallable<TPage, TData> {\n (params: ApplyPageDataParams<TPage, TData>): void;\n}\n\nexport class IndexPageDataPlugin<\n TPage extends Page = Page,\n TData = Record<string, any>\n> extends Plugin {\n public static override readonly type: string = \"pb.elasticsearch.index-page-data\";\n private readonly callable: ApplyPageDataCallable<TPage, TData>;\n\n public constructor(callable: ApplyPageDataCallable<TPage, TData>) {\n super();\n this.callable = callable;\n }\n\n public apply(params: ApplyPageDataParams<TPage, TData>): void {\n if (typeof this.callable !== \"function\") {\n return;\n }\n this.callable(params);\n }\n}\n"],"mappings":";;;;;;;;AAAA;
|
|
1
|
+
{"version":3,"names":["IndexPageDataPlugin","Plugin","constructor","callable","apply","params"],"sources":["IndexPageDataPlugin.ts"],"sourcesContent":["import { Plugin, PluginsContainer } from \"@webiny/plugins\";\nimport { Page } from \"@webiny/api-page-builder/types\";\n\ninterface ApplyPageDataParams<TPage, TData = Record<string, any>> {\n data: TData;\n input: Record<string, any>;\n page: TPage;\n plugins: PluginsContainer;\n}\n\ninterface ApplyPageDataCallable<TPage, TData> {\n (params: ApplyPageDataParams<TPage, TData>): void;\n}\n\nexport class IndexPageDataPlugin<\n TPage extends Page = Page,\n TData = Record<string, any>\n> extends Plugin {\n public static override readonly type: string = \"pb.elasticsearch.index-page-data\";\n private readonly callable: ApplyPageDataCallable<TPage, TData>;\n\n public constructor(callable: ApplyPageDataCallable<TPage, TData>) {\n super();\n this.callable = callable;\n }\n\n public apply(params: ApplyPageDataParams<TPage, TData>): void {\n if (typeof this.callable !== \"function\") {\n return;\n }\n this.callable(params);\n }\n}\n"],"mappings":";;;;;;;;AAAA;AAcO,MAAMA,mBAAmB,SAGtBC,eAAM,CAAC;EAINC,WAAW,CAACC,QAA6C,EAAE;IAC9D,KAAK,EAAE;IAAC;IACR,IAAI,CAACA,QAAQ,GAAGA,QAAQ;EAC5B;EAEOC,KAAK,CAACC,MAAyC,EAAQ;IAC1D,IAAI,OAAO,IAAI,CAACF,QAAQ,KAAK,UAAU,EAAE;MACrC;IACJ;IACA,IAAI,CAACA,QAAQ,CAACE,MAAM,CAAC;EACzB;AACJ;AAAC;AAAA,8BAlBYL,mBAAmB,UAImB,kCAAkC"}
|
package/upgrades/index.d.ts
DELETED
package/upgrades/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _v = _interopRequireDefault(require("./v5.15.0"));
|
|
11
|
-
|
|
12
|
-
var _default = () => [(0, _v.default)()];
|
|
13
|
-
|
|
14
|
-
exports.default = _default;
|
package/upgrades/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["upgrade5150"],"sources":["index.ts"],"sourcesContent":["import upgrade5150 from \"~/upgrades/v5.15.0\";\n\nexport default () => [upgrade5150()];\n"],"mappings":";;;;;;;;;AAAA;;eAEe,MAAM,CAAC,IAAAA,UAAA,GAAD,C"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.upgradeCategories = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _CategoryStorageOperations = require("../../operations/category/CategoryStorageOperations");
|
|
13
|
-
|
|
14
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
15
|
-
|
|
16
|
-
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
17
|
-
|
|
18
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
const upgradeCategories = async context => {
|
|
22
|
-
const tenant = context.tenancy.getCurrentTenant().id;
|
|
23
|
-
const localeCodes = await context.i18n.getLocales().map(locale => locale.code); // @ts-ignore
|
|
24
|
-
|
|
25
|
-
const categoryStorageOperations = context.pageBuilder.categories.storageOperations;
|
|
26
|
-
|
|
27
|
-
if (categoryStorageOperations instanceof _CategoryStorageOperations.CategoryStorageOperationsDdbEs === false) {
|
|
28
|
-
throw new _error.default("context.pageBuilder.categories.storageOperations must be instance of CategoryStorageOperationsDdbEs.");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* First we need all categories in all existing locales of the tenant.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const records = [];
|
|
36
|
-
|
|
37
|
-
for (const locale of localeCodes) {
|
|
38
|
-
const partitionKey = categoryStorageOperations.createPartitionKey({
|
|
39
|
-
tenant,
|
|
40
|
-
locale
|
|
41
|
-
});
|
|
42
|
-
const result = await (0, _query.queryAll)({
|
|
43
|
-
entity: categoryStorageOperations.entity,
|
|
44
|
-
partitionKey,
|
|
45
|
-
options: {
|
|
46
|
-
gt: " "
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
/**
|
|
50
|
-
* Need to update existing categories with tenant and locale information.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
records.push(...result.map(item => {
|
|
54
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
|
|
55
|
-
PK: partitionKey,
|
|
56
|
-
SK: categoryStorageOperations.createSortKey(item),
|
|
57
|
-
TYPE: categoryStorageOperations.createType(),
|
|
58
|
-
tenant,
|
|
59
|
-
locale
|
|
60
|
-
});
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const items = records.map(record => {
|
|
65
|
-
return categoryStorageOperations.entity.putBatch(record);
|
|
66
|
-
});
|
|
67
|
-
await (0, _batchWrite.batchWriteAll)({
|
|
68
|
-
table: categoryStorageOperations.table,
|
|
69
|
-
items
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
exports.upgradeCategories = upgradeCategories;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["upgradeCategories","context","tenant","tenancy","getCurrentTenant","id","localeCodes","i18n","getLocales","map","locale","code","categoryStorageOperations","pageBuilder","categories","storageOperations","CategoryStorageOperationsDdbEs","WebinyError","records","partitionKey","createPartitionKey","result","queryAll","entity","options","gt","push","item","PK","SK","createSortKey","TYPE","createType","items","record","putBatch","batchWriteAll","table"],"sources":["category.ts"],"sourcesContent":["import { PbContext } from \"@webiny/api-page-builder/graphql/types\";\n// @ts-ignore\nimport { CategoryStorageOperationsDdbEs } from \"~/operations/category/CategoryStorageOperations\";\nimport { Category } from \"@webiny/api-page-builder/types\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport WebinyError from \"@webiny/error\";\n\ntype DbRecord<T> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n};\n\nexport const upgradeCategories = async (context: PbContext) => {\n const tenant: string = context.tenancy.getCurrentTenant().id;\n const localeCodes: string[] = await context.i18n.getLocales().map(locale => locale.code);\n // @ts-ignore\n const categoryStorageOperations = context.pageBuilder.categories\n .storageOperations as CategoryStorageOperationsDdbEs;\n if (categoryStorageOperations instanceof CategoryStorageOperationsDdbEs === false) {\n throw new WebinyError(\n \"context.pageBuilder.categories.storageOperations must be instance of CategoryStorageOperationsDdbEs.\"\n );\n }\n /**\n * First we need all categories in all existing locales of the tenant.\n */\n const records: DbRecord<Category>[] = [];\n for (const locale of localeCodes) {\n const partitionKey = categoryStorageOperations.createPartitionKey({\n tenant,\n locale\n });\n const result = await queryAll<Category>({\n entity: categoryStorageOperations.entity,\n partitionKey,\n options: {\n gt: \" \"\n }\n });\n /**\n * Need to update existing categories with tenant and locale information.\n */\n records.push(\n ...result.map(item => {\n return {\n ...item,\n PK: partitionKey,\n SK: categoryStorageOperations.createSortKey(item),\n TYPE: categoryStorageOperations.createType(),\n tenant,\n locale\n };\n })\n );\n }\n const items = records.map(record => {\n return categoryStorageOperations.entity.putBatch(record);\n });\n\n await batchWriteAll({\n table: categoryStorageOperations.table,\n items\n });\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AAEA;;AACA;;AACA;;AALA;AAaO,MAAMA,iBAAiB,GAAG,MAAOC,OAAP,IAA8B;EAC3D,MAAMC,MAAc,GAAGD,OAAO,CAACE,OAAR,CAAgBC,gBAAhB,GAAmCC,EAA1D;EACA,MAAMC,WAAqB,GAAG,MAAML,OAAO,CAACM,IAAR,CAAaC,UAAb,GAA0BC,GAA1B,CAA8BC,MAAM,IAAIA,MAAM,CAACC,IAA/C,CAApC,CAF2D,CAG3D;;EACA,MAAMC,yBAAyB,GAAGX,OAAO,CAACY,WAAR,CAAoBC,UAApB,CAC7BC,iBADL;;EAEA,IAAIH,yBAAyB,YAAYI,yDAArC,KAAwE,KAA5E,EAAmF;IAC/E,MAAM,IAAIC,cAAJ,CACF,sGADE,CAAN;EAGH;EACD;AACJ;AACA;;;EACI,MAAMC,OAA6B,GAAG,EAAtC;;EACA,KAAK,MAAMR,MAAX,IAAqBJ,WAArB,EAAkC;IAC9B,MAAMa,YAAY,GAAGP,yBAAyB,CAACQ,kBAA1B,CAA6C;MAC9DlB,MAD8D;MAE9DQ;IAF8D,CAA7C,CAArB;IAIA,MAAMW,MAAM,GAAG,MAAM,IAAAC,eAAA,EAAmB;MACpCC,MAAM,EAAEX,yBAAyB,CAACW,MADE;MAEpCJ,YAFoC;MAGpCK,OAAO,EAAE;QACLC,EAAE,EAAE;MADC;IAH2B,CAAnB,CAArB;IAOA;AACR;AACA;;IACQP,OAAO,CAACQ,IAAR,CACI,GAAGL,MAAM,CAACZ,GAAP,CAAWkB,IAAI,IAAI;MAClB,mEACOA,IADP;QAEIC,EAAE,EAAET,YAFR;QAGIU,EAAE,EAAEjB,yBAAyB,CAACkB,aAA1B,CAAwCH,IAAxC,CAHR;QAIII,IAAI,EAAEnB,yBAAyB,CAACoB,UAA1B,EAJV;QAKI9B,MALJ;QAMIQ;MANJ;IAQH,CATE,CADP;EAYH;;EACD,MAAMuB,KAAK,GAAGf,OAAO,CAACT,GAAR,CAAYyB,MAAM,IAAI;IAChC,OAAOtB,yBAAyB,CAACW,MAA1B,CAAiCY,QAAjC,CAA0CD,MAA1C,CAAP;EACH,CAFa,CAAd;EAIA,MAAM,IAAAE,yBAAA,EAAc;IAChBC,KAAK,EAAEzB,yBAAyB,CAACyB,KADjB;IAEhBJ;EAFgB,CAAd,CAAN;AAIH,CAnDM"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _category = require("./category");
|
|
9
|
-
|
|
10
|
-
var _menu = require("./menu");
|
|
11
|
-
|
|
12
|
-
var _pageElement = require("./pageElement");
|
|
13
|
-
|
|
14
|
-
var _default = () => {
|
|
15
|
-
return {
|
|
16
|
-
type: "api-upgrade",
|
|
17
|
-
app: "page-builder",
|
|
18
|
-
version: "5.15.0",
|
|
19
|
-
apply: async context => {
|
|
20
|
-
/**
|
|
21
|
-
* Upgrade categories.
|
|
22
|
-
*/
|
|
23
|
-
try {
|
|
24
|
-
await (0, _category.upgradeCategories)(context);
|
|
25
|
-
} catch (ex) {
|
|
26
|
-
console.log(ex.message);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Upgrade menus.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
await (0, _menu.upgradeMenus)(context);
|
|
35
|
-
} catch (ex) {
|
|
36
|
-
console.log(ex.message);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Upgrade page elements.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
await (0, _pageElement.upgradePageElements)(context);
|
|
45
|
-
} catch (ex) {
|
|
46
|
-
console.log(ex.message);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
exports.default = _default;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["type","app","version","apply","context","upgradeCategories","ex","console","log","message","upgradeMenus","upgradePageElements"],"sources":["index.ts"],"sourcesContent":["import { UpgradePlugin } from \"@webiny/api-upgrade/types\";\nimport { PbContext } from \"@webiny/api-page-builder/graphql/types\";\nimport { upgradeCategories } from \"~/upgrades/v5.15.0/category\";\nimport { upgradeMenus } from \"~/upgrades/v5.15.0/menu\";\nimport { upgradePageElements } from \"~/upgrades/v5.15.0/pageElement\";\n\nexport default (): UpgradePlugin<PbContext> => {\n return {\n type: \"api-upgrade\",\n app: \"page-builder\",\n version: \"5.15.0\",\n apply: async context => {\n /**\n * Upgrade categories.\n */\n try {\n await upgradeCategories(context);\n } catch (ex) {\n console.log(ex.message);\n }\n /**\n * Upgrade menus.\n */\n try {\n await upgradeMenus(context);\n } catch (ex) {\n console.log(ex.message);\n }\n /**\n * Upgrade page elements.\n */\n try {\n await upgradePageElements(context);\n } catch (ex) {\n console.log(ex.message);\n }\n }\n };\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AACA;;eAEe,MAAgC;EAC3C,OAAO;IACHA,IAAI,EAAE,aADH;IAEHC,GAAG,EAAE,cAFF;IAGHC,OAAO,EAAE,QAHN;IAIHC,KAAK,EAAE,MAAMC,OAAN,IAAiB;MACpB;AACZ;AACA;MACY,IAAI;QACA,MAAM,IAAAC,2BAAA,EAAkBD,OAAlB,CAAN;MACH,CAFD,CAEE,OAAOE,EAAP,EAAW;QACTC,OAAO,CAACC,GAAR,CAAYF,EAAE,CAACG,OAAf;MACH;MACD;AACZ;AACA;;;MACY,IAAI;QACA,MAAM,IAAAC,kBAAA,EAAaN,OAAb,CAAN;MACH,CAFD,CAEE,OAAOE,EAAP,EAAW;QACTC,OAAO,CAACC,GAAR,CAAYF,EAAE,CAACG,OAAf;MACH;MACD;AACZ;AACA;;;MACY,IAAI;QACA,MAAM,IAAAE,gCAAA,EAAoBP,OAApB,CAAN;MACH,CAFD,CAEE,OAAOE,EAAP,EAAW;QACTC,OAAO,CAACC,GAAR,CAAYF,EAAE,CAACG,OAAf;MACH;IACJ;EA7BE,CAAP;AA+BH,C"}
|
package/upgrades/v5.15.0/menu.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.upgradeMenus = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _MenuStorageOperations = require("../../operations/menu/MenuStorageOperations");
|
|
13
|
-
|
|
14
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
15
|
-
|
|
16
|
-
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
17
|
-
|
|
18
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
const upgradeMenus = async context => {
|
|
22
|
-
const tenant = context.tenancy.getCurrentTenant().id;
|
|
23
|
-
const localeCodes = await context.i18n.getLocales().map(locale => locale.code); // @ts-ignore
|
|
24
|
-
|
|
25
|
-
const menuStorageOperations = context.pageBuilder.menus.storageOperations;
|
|
26
|
-
|
|
27
|
-
if (menuStorageOperations instanceof _MenuStorageOperations.MenuStorageOperationsDdbEs === false) {
|
|
28
|
-
throw new _error.default("context.pageBuilder.menus.storageOperations must be instance of MenuStorageOperationsDdbEs.");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* First we need all categories in all existing locales of the tenant.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const records = [];
|
|
36
|
-
|
|
37
|
-
for (const locale of localeCodes) {
|
|
38
|
-
const partitionKey = menuStorageOperations.createPartitionKey({
|
|
39
|
-
tenant,
|
|
40
|
-
locale
|
|
41
|
-
});
|
|
42
|
-
const result = await (0, _query.queryAll)({
|
|
43
|
-
entity: menuStorageOperations.entity,
|
|
44
|
-
partitionKey,
|
|
45
|
-
options: {
|
|
46
|
-
gt: " "
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
/**
|
|
50
|
-
* Need to update existing menus with tenant and locale information.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
records.push(...result.map(item => {
|
|
54
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
|
|
55
|
-
PK: partitionKey,
|
|
56
|
-
SK: menuStorageOperations.createSortKey(item),
|
|
57
|
-
TYPE: menuStorageOperations.createType(),
|
|
58
|
-
tenant,
|
|
59
|
-
locale
|
|
60
|
-
});
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const items = records.map(record => {
|
|
65
|
-
return menuStorageOperations.entity.putBatch(record);
|
|
66
|
-
});
|
|
67
|
-
await (0, _batchWrite.batchWriteAll)({
|
|
68
|
-
table: menuStorageOperations.table,
|
|
69
|
-
items
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
exports.upgradeMenus = upgradeMenus;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["upgradeMenus","context","tenant","tenancy","getCurrentTenant","id","localeCodes","i18n","getLocales","map","locale","code","menuStorageOperations","pageBuilder","menus","storageOperations","MenuStorageOperationsDdbEs","WebinyError","records","partitionKey","createPartitionKey","result","queryAll","entity","options","gt","push","item","PK","SK","createSortKey","TYPE","createType","items","record","putBatch","batchWriteAll","table"],"sources":["menu.ts"],"sourcesContent":["import { PbContext } from \"@webiny/api-page-builder/graphql/types\";\n// @ts-ignore\nimport { MenuStorageOperationsDdbEs } from \"~/operations/menu/MenuStorageOperations\";\nimport { Menu } from \"@webiny/api-page-builder/types\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport WebinyError from \"@webiny/error\";\n\ntype DbRecord<T> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n};\n\nexport const upgradeMenus = async (context: PbContext) => {\n const tenant: string = context.tenancy.getCurrentTenant().id;\n const localeCodes: string[] = await context.i18n.getLocales().map(locale => locale.code);\n // @ts-ignore\n const menuStorageOperations = context.pageBuilder.menus\n .storageOperations as MenuStorageOperationsDdbEs;\n if (menuStorageOperations instanceof MenuStorageOperationsDdbEs === false) {\n throw new WebinyError(\n \"context.pageBuilder.menus.storageOperations must be instance of MenuStorageOperationsDdbEs.\"\n );\n }\n /**\n * First we need all categories in all existing locales of the tenant.\n */\n const records: DbRecord<Menu>[] = [];\n for (const locale of localeCodes) {\n const partitionKey = menuStorageOperations.createPartitionKey({\n tenant,\n locale\n });\n const result = await queryAll<Menu>({\n entity: menuStorageOperations.entity,\n partitionKey,\n options: {\n gt: \" \"\n }\n });\n /**\n * Need to update existing menus with tenant and locale information.\n */\n records.push(\n ...result.map(item => {\n return {\n ...item,\n PK: partitionKey,\n SK: menuStorageOperations.createSortKey(item),\n TYPE: menuStorageOperations.createType(),\n tenant,\n locale\n };\n })\n );\n }\n const items = records.map(record => {\n return menuStorageOperations.entity.putBatch(record);\n });\n\n await batchWriteAll({\n table: menuStorageOperations.table,\n items\n });\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AAEA;;AACA;;AACA;;AALA;AAaO,MAAMA,YAAY,GA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,CAAP;EACH,CAFa,CAAd;EAIA,MAAM,IAAAE,yBAAA,EAAc;IAChBC,KAAK,EAAEzB,qBAAqB,CAACyB,KADb;IAEhBJ;EAFgB,CAAd,CAAN;AAIH,CAnDM"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.upgradePageElements = void 0;
|
|
9
|
-
|
|
10
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
-
|
|
12
|
-
var _PageElementStorageOperations = require("../../operations/pageElement/PageElementStorageOperations");
|
|
13
|
-
|
|
14
|
-
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
15
|
-
|
|
16
|
-
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
17
|
-
|
|
18
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
const upgradePageElements = async context => {
|
|
22
|
-
const tenant = context.tenancy.getCurrentTenant().id;
|
|
23
|
-
const localeCodes = await context.i18n.getLocales().map(locale => locale.code); // @ts-ignore
|
|
24
|
-
|
|
25
|
-
const pageElementsStorageOperations = context.pageBuilder.pageElements.storageOperations;
|
|
26
|
-
|
|
27
|
-
if (pageElementsStorageOperations instanceof _PageElementStorageOperations.PageElementStorageOperationsDdbEs === false) {
|
|
28
|
-
throw new _error.default("context.pageBuilder.pageElements.storageOperations must be instance of PageElementStorageOperationsDdbEs.");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* First we need all categories in all existing locales of the tenant.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const records = [];
|
|
36
|
-
|
|
37
|
-
for (const locale of localeCodes) {
|
|
38
|
-
const partitionKey = pageElementsStorageOperations.createPartitionKey({
|
|
39
|
-
tenant,
|
|
40
|
-
locale
|
|
41
|
-
});
|
|
42
|
-
const result = await (0, _query.queryAll)({
|
|
43
|
-
entity: pageElementsStorageOperations.entity,
|
|
44
|
-
partitionKey,
|
|
45
|
-
options: {
|
|
46
|
-
gt: " "
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
/**
|
|
50
|
-
* Need to update existing menus with tenant and locale information.
|
|
51
|
-
*/
|
|
52
|
-
|
|
53
|
-
records.push(...result.map(item => {
|
|
54
|
-
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
|
|
55
|
-
PK: partitionKey,
|
|
56
|
-
SK: pageElementsStorageOperations.createSortKey(item),
|
|
57
|
-
TYPE: pageElementsStorageOperations.createType(),
|
|
58
|
-
tenant,
|
|
59
|
-
locale
|
|
60
|
-
});
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const items = records.map(record => {
|
|
65
|
-
return pageElementsStorageOperations.entity.putBatch(record);
|
|
66
|
-
});
|
|
67
|
-
await (0, _batchWrite.batchWriteAll)({
|
|
68
|
-
table: pageElementsStorageOperations.table,
|
|
69
|
-
items
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
exports.upgradePageElements = upgradePageElements;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["upgradePageElements","context","tenant","tenancy","getCurrentTenant","id","localeCodes","i18n","getLocales","map","locale","code","pageElementsStorageOperations","pageBuilder","pageElements","storageOperations","PageElementStorageOperationsDdbEs","WebinyError","records","partitionKey","createPartitionKey","result","queryAll","entity","options","gt","push","item","PK","SK","createSortKey","TYPE","createType","items","record","putBatch","batchWriteAll","table"],"sources":["pageElement.ts"],"sourcesContent":["import { PbContext } from \"@webiny/api-page-builder/graphql/types\";\n// @ts-ignore\nimport { PageElementStorageOperationsDdbEs } from \"~/operations/pageElement/PageElementStorageOperations\";\nimport { PageElement } from \"@webiny/api-page-builder/types\";\nimport { queryAll } from \"@webiny/db-dynamodb/utils/query\";\nimport { batchWriteAll } from \"@webiny/db-dynamodb/utils/batchWrite\";\nimport WebinyError from \"@webiny/error\";\n\ntype DbRecord<T> = T & {\n PK: string;\n SK: string;\n TYPE: string;\n};\n\nexport const upgradePageElements = async (context: PbContext) => {\n const tenant: string = context.tenancy.getCurrentTenant().id;\n const localeCodes: string[] = await context.i18n.getLocales().map(locale => locale.code);\n // @ts-ignore\n const pageElementsStorageOperations = context.pageBuilder.pageElements\n .storageOperations as PageElementStorageOperationsDdbEs;\n if (pageElementsStorageOperations instanceof PageElementStorageOperationsDdbEs === false) {\n throw new WebinyError(\n \"context.pageBuilder.pageElements.storageOperations must be instance of PageElementStorageOperationsDdbEs.\"\n );\n }\n /**\n * First we need all categories in all existing locales of the tenant.\n */\n const records: DbRecord<PageElement>[] = [];\n for (const locale of localeCodes) {\n const partitionKey = pageElementsStorageOperations.createPartitionKey({\n tenant,\n locale\n });\n const result = await queryAll<PageElement>({\n entity: pageElementsStorageOperations.entity,\n partitionKey,\n options: {\n gt: \" \"\n }\n });\n /**\n * Need to update existing menus with tenant and locale information.\n */\n records.push(\n ...result.map(item => {\n return {\n ...item,\n PK: partitionKey,\n SK: pageElementsStorageOperations.createSortKey(item),\n TYPE: pageElementsStorageOperations.createType(),\n tenant,\n locale\n };\n })\n );\n }\n const items = records.map(record => {\n return pageElementsStorageOperations.entity.putBatch(record);\n });\n\n await batchWriteAll({\n table: pageElementsStorageOperations.table,\n items\n });\n};\n"],"mappings":";;;;;;;;;;;AAEA;;AAEA;;AACA;;AACA;;AALA;AAaO,MAAMA,mBAAmB,GAAG,MAAOC,OAAP,IAA8B;EAC7D,MAAMC,MAAc,GAAGD,OAAO,CAACE,OAAR,CAAgBC,gBAAhB,GAAmCC,EAA1D;EACA,MAAMC,WAAqB,GAAG,MAAML,OAAO,CAACM,IAAR,CAAaC,UAAb,GAA0BC,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