@webiny/api-headless-cms-ddb-es 6.0.0-alpha.5 → 6.0.0-rc.0
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/README.md +6 -30
- package/configurations.d.ts +4 -5
- package/configurations.js +12 -24
- package/configurations.js.map +1 -1
- package/definitions/entry.d.ts +4 -6
- package/definitions/entry.js +5 -174
- package/definitions/entry.js.map +1 -1
- package/definitions/group.d.ts +6 -7
- package/definitions/group.js +5 -58
- package/definitions/group.js.map +1 -1
- package/definitions/model.d.ts +6 -7
- package/definitions/model.js +5 -102
- package/definitions/model.js.map +1 -1
- package/definitions/types.d.ts +59 -0
- package/definitions/types.js +3 -0
- package/definitions/types.js.map +1 -0
- package/dynamoDb/index.d.ts +2 -2
- package/dynamoDb/index.js +5 -13
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/storage/longText.js +10 -18
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.js +10 -18
- package/dynamoDb/storage/richText.js.map +1 -1
- package/elasticsearch/createElasticsearchIndex.d.ts +1 -1
- package/elasticsearch/createElasticsearchIndex.js +7 -15
- package/elasticsearch/createElasticsearchIndex.js.map +1 -1
- package/elasticsearch/deleteElasticsearchIndex.d.ts +1 -1
- package/elasticsearch/deleteElasticsearchIndex.js +3 -10
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -1
- package/elasticsearch/index.d.ts +1 -1
- package/elasticsearch/index.js +3 -11
- package/elasticsearch/index.js.map +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.d.ts +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.js +1 -8
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
- package/elasticsearch/indexing/defaultFieldIndexing.d.ts +1 -1
- package/elasticsearch/indexing/defaultFieldIndexing.js +1 -8
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -1
- package/elasticsearch/indexing/index.d.ts +1 -1
- package/elasticsearch/indexing/index.js +8 -16
- package/elasticsearch/indexing/index.js.map +1 -1
- package/elasticsearch/indexing/jsonIndexing.d.ts +1 -1
- package/elasticsearch/indexing/jsonIndexing.js +1 -8
- package/elasticsearch/indexing/jsonIndexing.js.map +1 -1
- package/elasticsearch/indexing/longTextIndexing.d.ts +1 -1
- package/elasticsearch/indexing/longTextIndexing.js +1 -8
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
- package/elasticsearch/indexing/numberIndexing.d.ts +1 -1
- package/elasticsearch/indexing/numberIndexing.js +1 -8
- package/elasticsearch/indexing/numberIndexing.js.map +1 -1
- package/elasticsearch/indexing/objectIndexing.d.ts +1 -1
- package/elasticsearch/indexing/objectIndexing.js +6 -13
- package/elasticsearch/indexing/objectIndexing.js.map +1 -1
- package/elasticsearch/indexing/richTextIndexing.d.ts +1 -1
- package/elasticsearch/indexing/richTextIndexing.js +1 -8
- package/elasticsearch/indexing/richTextIndexing.js.map +1 -1
- package/elasticsearch/indices/base.d.ts +1 -1
- package/elasticsearch/indices/base.js +4 -10
- package/elasticsearch/indices/base.js.map +1 -1
- package/elasticsearch/indices/index.d.ts +1 -1
- package/elasticsearch/indices/index.js +3 -11
- package/elasticsearch/indices/index.js.map +1 -1
- package/elasticsearch/search/index.d.ts +1 -1
- package/elasticsearch/search/index.js +4 -11
- package/elasticsearch/search/index.js.map +1 -1
- package/elasticsearch/search/refSearch.d.ts +1 -1
- package/elasticsearch/search/refSearch.js +3 -10
- package/elasticsearch/search/refSearch.js.map +1 -1
- package/elasticsearch/search/searchableJson.d.ts +1 -1
- package/elasticsearch/search/searchableJson.js +9 -16
- package/elasticsearch/search/searchableJson.js.map +1 -1
- package/elasticsearch/search/timeSearch.d.ts +1 -1
- package/elasticsearch/search/timeSearch.js +3 -10
- package/elasticsearch/search/timeSearch.js.map +1 -1
- package/helpers/entryIndexHelpers.d.ts +9 -9
- package/helpers/entryIndexHelpers.js +32 -26
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/fieldIdentifier.d.ts +1 -1
- package/helpers/fieldIdentifier.js +2 -10
- package/helpers/fieldIdentifier.js.map +1 -1
- package/helpers/index.d.ts +2 -2
- package/helpers/index.js +2 -27
- package/helpers/index.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +98 -133
- package/index.js.map +1 -1
- package/operations/entry/dataLoader/DataLoaderCache.d.ts +0 -2
- package/operations/entry/dataLoader/DataLoaderCache.js +2 -9
- package/operations/entry/dataLoader/DataLoaderCache.js.map +1 -1
- package/operations/entry/dataLoader/constants.js +1 -7
- package/operations/entry/dataLoader/constants.js.map +1 -1
- package/operations/entry/dataLoader/createBatchScheduleFn.js +4 -10
- package/operations/entry/dataLoader/createBatchScheduleFn.js.map +1 -1
- package/operations/entry/dataLoader/getAllEntryRevisions.d.ts +3 -3
- package/operations/entry/dataLoader/getAllEntryRevisions.js +11 -24
- package/operations/entry/dataLoader/getAllEntryRevisions.js.map +1 -1
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js +18 -30
- package/operations/entry/dataLoader/getLatestRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.d.ts +3 -3
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js +18 -30
- package/operations/entry/dataLoader/getPublishedRevisionByEntryId.js.map +1 -1
- package/operations/entry/dataLoader/getRevisionById.d.ts +3 -3
- package/operations/entry/dataLoader/getRevisionById.js +23 -35
- package/operations/entry/dataLoader/getRevisionById.js.map +1 -1
- package/operations/entry/dataLoader/index.d.ts +3 -3
- package/operations/entry/dataLoader/index.js +10 -31
- package/operations/entry/dataLoader/index.js.map +1 -1
- package/operations/entry/dataLoader/types.d.ts +3 -4
- package/operations/entry/dataLoader/types.js +1 -5
- package/operations/entry/dataLoader/types.js.map +1 -1
- package/operations/entry/dataLoaders.d.ts +13 -13
- package/operations/entry/dataLoaders.js +15 -25
- package/operations/entry/dataLoaders.js.map +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +1 -8
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
- package/operations/entry/elasticsearch/body.d.ts +2 -2
- package/operations/entry/elasticsearch/body.js +21 -28
- package/operations/entry/elasticsearch/body.js.map +1 -1
- package/operations/entry/elasticsearch/fields.d.ts +2 -2
- package/operations/entry/elasticsearch/fields.js +110 -24
- package/operations/entry/elasticsearch/fields.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +2 -2
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +9 -17
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/exec.d.ts +6 -5
- package/operations/entry/elasticsearch/filtering/exec.js +48 -45
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/index.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/index.js +1 -16
- package/operations/entry/elasticsearch/filtering/index.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/path.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/path.js +5 -15
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +6 -14
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/index.js +5 -12
- package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +7 -15
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +7 -15
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/populated.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/populated.js +1 -8
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/values.d.ts +1 -1
- package/operations/entry/elasticsearch/filtering/values.js +4 -12
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearch.d.ts +2 -2
- package/operations/entry/elasticsearch/fullTextSearch.js +6 -12
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +1 -1
- package/operations/entry/elasticsearch/fullTextSearchFields.js +1 -8
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -1
- package/operations/entry/elasticsearch/initialQuery.d.ts +2 -2
- package/operations/entry/elasticsearch/initialQuery.js +9 -27
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
- package/operations/entry/elasticsearch/keyword.d.ts +1 -1
- package/operations/entry/elasticsearch/keyword.js +4 -9
- package/operations/entry/elasticsearch/keyword.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +2 -2
- package/operations/entry/elasticsearch/plugins/bodyModifier.js +3 -10
- package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/operator.d.ts +1 -2
- package/operations/entry/elasticsearch/plugins/operator.js +4 -19
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +2 -2
- package/operations/entry/elasticsearch/plugins/queryModifier.js +3 -10
- package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/search.d.ts +1 -1
- package/operations/entry/elasticsearch/plugins/search.js +5 -13
- package/operations/entry/elasticsearch/plugins/search.js.map +1 -1
- package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +2 -2
- package/operations/entry/elasticsearch/plugins/sortModifier.js +3 -10
- package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -1
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js +1 -8
- package/operations/entry/elasticsearch/shouldIgnoreEsResponseError.js.map +1 -1
- package/operations/entry/elasticsearch/sort.d.ts +3 -3
- package/operations/entry/elasticsearch/sort.js +51 -33
- package/operations/entry/elasticsearch/sort.js.map +1 -1
- package/operations/entry/elasticsearch/transformValueForSearch.d.ts +2 -2
- package/operations/entry/elasticsearch/transformValueForSearch.js +4 -9
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -1
- package/operations/entry/elasticsearch/types.d.ts +2 -2
- package/operations/entry/elasticsearch/types.js +1 -5
- package/operations/entry/elasticsearch/types.js.map +1 -1
- package/operations/entry/index.d.ts +5 -4
- package/operations/entry/index.js +333 -515
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/keys.d.ts +31 -1
- package/operations/entry/keys.js +56 -19
- package/operations/entry/keys.js.map +1 -1
- package/operations/entry/recordType.js +3 -12
- package/operations/entry/recordType.js.map +1 -1
- package/operations/entry/transformations/convertEntryKeys.d.ts +6 -6
- package/operations/entry/transformations/convertEntryKeys.js +2 -10
- package/operations/entry/transformations/convertEntryKeys.js.map +1 -1
- package/operations/entry/transformations/index.d.ts +16 -16
- package/operations/entry/transformations/index.js +22 -30
- package/operations/entry/transformations/index.js.map +1 -1
- package/operations/entry/transformations/modifyEntryValues.d.ts +27 -34
- package/operations/entry/transformations/modifyEntryValues.js +1 -8
- package/operations/entry/transformations/modifyEntryValues.js.map +1 -1
- package/operations/entry/transformations/transformEntryKeys.d.ts +8 -8
- package/operations/entry/transformations/transformEntryKeys.js +4 -11
- package/operations/entry/transformations/transformEntryKeys.js.map +1 -1
- package/operations/entry/transformations/transformEntryToIndex.d.ts +6 -6
- package/operations/entry/transformations/transformEntryToIndex.js +3 -10
- package/operations/entry/transformations/transformEntryToIndex.js.map +1 -1
- package/operations/group/index.d.ts +5 -4
- package/operations/group/index.js +39 -73
- package/operations/group/index.js.map +1 -1
- package/operations/model/index.d.ts +3 -3
- package/operations/model/index.js +38 -57
- package/operations/model/index.js.map +1 -1
- package/package.json +27 -32
- package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +1 -1
- package/plugins/CmsElasticsearchModelFieldPlugin.js +2 -8
- package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +1 -1
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +3 -11
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.d.ts +2 -2
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js +3 -11
- package/plugins/CmsEntryElasticsearchFullTextSearchPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +2 -9
- package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +2 -2
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +3 -11
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +1 -1
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +3 -11
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +1 -1
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +3 -11
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -1
- package/plugins/CmsEntryElasticsearchValuesModifier.d.ts +12 -12
- package/plugins/CmsEntryElasticsearchValuesModifier.js +4 -12
- package/plugins/CmsEntryElasticsearchValuesModifier.js.map +1 -1
- package/plugins/CmsEntryFilterPlugin.d.ts +3 -3
- package/plugins/CmsEntryFilterPlugin.js +2 -9
- package/plugins/CmsEntryFilterPlugin.js.map +1 -1
- package/plugins/index.d.ts +8 -8
- package/plugins/index.js +8 -93
- package/plugins/index.js.map +1 -1
- package/tasks/createIndexTaskPlugin.d.ts +2 -2
- package/tasks/createIndexTaskPlugin.js +36 -62
- package/tasks/createIndexTaskPlugin.js.map +1 -1
- package/types.d.ts +23 -26
- package/types.js +5 -8
- package/types.js.map +1 -1
- package/values/NoValueContainer.js +1 -8
- package/values/NoValueContainer.js.map +1 -1
- package/definitions/entryElasticsearch.d.ts +0 -9
- package/definitions/entryElasticsearch.js +0 -41
- package/definitions/entryElasticsearch.js.map +0 -1
- package/definitions/system.d.ts +0 -9
- package/definitions/system.js +0 -42
- package/definitions/system.js.map +0 -1
- package/definitions/table.d.ts +0 -8
- package/definitions/table.js +0 -25
- package/definitions/table.js.map +0 -1
- package/definitions/tableElasticsearch.d.ts +0 -8
- package/definitions/tableElasticsearch.js +0 -25
- package/definitions/tableElasticsearch.js.map +0 -1
- package/elasticsearch/indices/japanese.d.ts +0 -2
- package/elasticsearch/indices/japanese.js +0 -14
- package/elasticsearch/indices/japanese.js.map +0 -1
- package/operations/entry/elasticsearch/logIgnoredEsResponseError.d.ts +0 -9
- package/operations/entry/elasticsearch/logIgnoredEsResponseError.js +0 -26
- package/operations/entry/elasticsearch/logIgnoredEsResponseError.js.map +0 -1
- package/operations/system/index.d.ts +0 -6
- package/operations/system/index.js +0 -94
- package/operations/system/index.js.map +0 -1
- package/operations/system/indexes.d.ts +0 -10
- package/operations/system/indexes.js +0 -41
- package/operations/system/indexes.js.map +0 -1
|
@@ -1,27 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _keys = require("./keys");
|
|
15
|
-
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
16
|
-
var _utils = require("@webiny/utils");
|
|
17
|
-
var _body = require("./elasticsearch/body");
|
|
18
|
-
var _logIgnoredEsResponseError = require("./elasticsearch/logIgnoredEsResponseError");
|
|
19
|
-
var _shouldIgnoreEsResponseError = require("./elasticsearch/shouldIgnoreEsResponseError");
|
|
20
|
-
var _recordType = require("./recordType");
|
|
21
|
-
var _apiHeadlessCms = require("@webiny/api-headless-cms");
|
|
22
|
-
var _transformations = require("./transformations");
|
|
23
|
-
var _convertEntryKeys = require("./transformations/convertEntryKeys");
|
|
24
|
-
var _constants = require("@webiny/api-headless-cms/constants");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { CONTENT_ENTRY_STATUS } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
import { extractEntriesFromIndex } from "../../helpers/index.js";
|
|
4
|
+
import { configurations } from "../../configurations.js";
|
|
5
|
+
import { DataLoadersHandler } from "./dataLoaders.js";
|
|
6
|
+
import { createEntryLatestKeys, createEntryPublishedKeys, createEntryRevisionKeys, createLatestSortKey, createPartitionKey, createPublishedSortKey, createRevisionSortKey } from "./keys.js";
|
|
7
|
+
import { compress, createLimit, decodeCursor, decompress, encodeCursor } from "@webiny/api-elasticsearch";
|
|
8
|
+
import { createElasticsearchBody } from "./elasticsearch/body.js";
|
|
9
|
+
import { shouldIgnoreEsResponseError } from "./elasticsearch/shouldIgnoreEsResponseError.js";
|
|
10
|
+
import { StorageOperationsCmsModelPlugin } from "@webiny/api-headless-cms";
|
|
11
|
+
import { createTransformer } from "./transformations/index.js";
|
|
12
|
+
import { convertEntryKeysFromStorage } from "./transformations/convertEntryKeys.js";
|
|
13
|
+
import { isDeletedEntryMetaField, isEntryLevelEntryMetaField, isRestoredEntryMetaField, pickEntryMetaFields } from "@webiny/api-headless-cms/constants.js";
|
|
25
14
|
const convertToStorageEntry = params => {
|
|
26
15
|
const {
|
|
27
16
|
model,
|
|
@@ -36,7 +25,7 @@ const convertToStorageEntry = params => {
|
|
|
36
25
|
values
|
|
37
26
|
};
|
|
38
27
|
};
|
|
39
|
-
const createEntriesStorageOperations = params => {
|
|
28
|
+
export const createEntriesStorageOperations = params => {
|
|
40
29
|
const {
|
|
41
30
|
entity,
|
|
42
31
|
esEntity,
|
|
@@ -48,14 +37,14 @@ const createEntriesStorageOperations = params => {
|
|
|
48
37
|
if (storageOperationsCmsModelPlugin) {
|
|
49
38
|
return storageOperationsCmsModelPlugin;
|
|
50
39
|
}
|
|
51
|
-
storageOperationsCmsModelPlugin = plugins.oneByType(
|
|
40
|
+
storageOperationsCmsModelPlugin = plugins.oneByType(StorageOperationsCmsModelPlugin.type);
|
|
52
41
|
return storageOperationsCmsModelPlugin;
|
|
53
42
|
};
|
|
54
43
|
const getStorageOperationsModel = model => {
|
|
55
44
|
const plugin = getStorageOperationsCmsModelPlugin();
|
|
56
45
|
return plugin.getModel(model);
|
|
57
46
|
};
|
|
58
|
-
const dataLoaders = new
|
|
47
|
+
const dataLoaders = new DataLoadersHandler({
|
|
59
48
|
entity
|
|
60
49
|
});
|
|
61
50
|
const create = async (initialModel, params) => {
|
|
@@ -68,7 +57,7 @@ const createEntriesStorageOperations = params => {
|
|
|
68
57
|
const locked = isPublished ? true : initialEntry.locked;
|
|
69
58
|
initialEntry.locked = locked;
|
|
70
59
|
initialStorageEntry.locked = locked;
|
|
71
|
-
const transformer =
|
|
60
|
+
const transformer = createTransformer({
|
|
72
61
|
plugins,
|
|
73
62
|
model,
|
|
74
63
|
entry: initialEntry,
|
|
@@ -81,53 +70,34 @@ const createEntriesStorageOperations = params => {
|
|
|
81
70
|
const esEntry = transformer.transformToIndex();
|
|
82
71
|
const {
|
|
83
72
|
index: esIndex
|
|
84
|
-
} =
|
|
73
|
+
} = configurations.es({
|
|
85
74
|
model
|
|
86
75
|
});
|
|
87
|
-
const revisionKeys =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
tenant: model.tenant
|
|
92
|
-
}),
|
|
93
|
-
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
94
|
-
};
|
|
95
|
-
const latestKeys = {
|
|
96
|
-
PK: (0, _keys.createPartitionKey)({
|
|
97
|
-
id: entry.id,
|
|
98
|
-
locale: model.locale,
|
|
99
|
-
tenant: model.tenant
|
|
100
|
-
}),
|
|
101
|
-
SK: (0, _keys.createLatestSortKey)()
|
|
102
|
-
};
|
|
103
|
-
const publishedKeys = {
|
|
104
|
-
PK: (0, _keys.createPartitionKey)({
|
|
105
|
-
id: entry.id,
|
|
106
|
-
locale: model.locale,
|
|
107
|
-
tenant: model.tenant
|
|
108
|
-
}),
|
|
109
|
-
SK: (0, _keys.createPublishedSortKey)()
|
|
110
|
-
};
|
|
111
|
-
const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
112
|
-
entity,
|
|
76
|
+
const revisionKeys = createEntryRevisionKeys(entry);
|
|
77
|
+
const latestKeys = createEntryLatestKeys(entry);
|
|
78
|
+
const publishedKeys = createEntryPublishedKeys(entry);
|
|
79
|
+
const entityBatch = entity.createEntityWriter({
|
|
113
80
|
put: [{
|
|
114
|
-
...storageEntry,
|
|
115
|
-
locked,
|
|
116
81
|
...revisionKeys,
|
|
117
|
-
|
|
82
|
+
data: {
|
|
83
|
+
...storageEntry,
|
|
84
|
+
locked
|
|
85
|
+
}
|
|
118
86
|
}, {
|
|
119
|
-
...storageEntry,
|
|
120
|
-
locked,
|
|
121
87
|
...latestKeys,
|
|
122
|
-
|
|
88
|
+
data: {
|
|
89
|
+
...storageEntry,
|
|
90
|
+
locked
|
|
91
|
+
}
|
|
123
92
|
}]
|
|
124
93
|
});
|
|
125
94
|
if (isPublished) {
|
|
126
95
|
entityBatch.put({
|
|
127
|
-
...storageEntry,
|
|
128
|
-
locked,
|
|
129
96
|
...publishedKeys,
|
|
130
|
-
|
|
97
|
+
data: {
|
|
98
|
+
...storageEntry,
|
|
99
|
+
locked
|
|
100
|
+
}
|
|
131
101
|
});
|
|
132
102
|
}
|
|
133
103
|
try {
|
|
@@ -136,15 +106,14 @@ const createEntriesStorageOperations = params => {
|
|
|
136
106
|
model
|
|
137
107
|
});
|
|
138
108
|
} catch (ex) {
|
|
139
|
-
throw new
|
|
109
|
+
throw new WebinyError(ex.message || "Could not insert entry data into the DynamoDB table.", ex.code || "CREATE_ENTRY_ERROR", {
|
|
140
110
|
error: ex,
|
|
141
111
|
entry,
|
|
142
112
|
storageEntry
|
|
143
113
|
});
|
|
144
114
|
}
|
|
145
115
|
const esLatestData = await transformer.getElasticsearchLatestEntryData();
|
|
146
|
-
const elasticsearchEntityBatch =
|
|
147
|
-
entity: esEntity,
|
|
116
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter({
|
|
148
117
|
put: [{
|
|
149
118
|
...latestKeys,
|
|
150
119
|
index: esIndex,
|
|
@@ -162,7 +131,7 @@ const createEntriesStorageOperations = params => {
|
|
|
162
131
|
try {
|
|
163
132
|
await elasticsearchEntityBatch.execute();
|
|
164
133
|
} catch (ex) {
|
|
165
|
-
throw new
|
|
134
|
+
throw new WebinyError(ex.message || "Could not insert entry data into the Elasticsearch DynamoDB table.", ex.code || "CREATE_ES_ENTRY_ERROR", {
|
|
166
135
|
error: ex,
|
|
167
136
|
entry,
|
|
168
137
|
esEntry
|
|
@@ -176,7 +145,7 @@ const createEntriesStorageOperations = params => {
|
|
|
176
145
|
storageEntry: initialStorageEntry
|
|
177
146
|
} = params;
|
|
178
147
|
const model = getStorageOperationsModel(initialModel);
|
|
179
|
-
const transformer =
|
|
148
|
+
const transformer = createTransformer({
|
|
180
149
|
plugins,
|
|
181
150
|
model,
|
|
182
151
|
entry: initialEntry,
|
|
@@ -186,51 +155,26 @@ const createEntriesStorageOperations = params => {
|
|
|
186
155
|
entry,
|
|
187
156
|
storageEntry
|
|
188
157
|
} = transformer.transformEntryKeys();
|
|
189
|
-
const revisionKeys =
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
locale: model.locale,
|
|
193
|
-
tenant: model.tenant
|
|
194
|
-
}),
|
|
195
|
-
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
196
|
-
};
|
|
197
|
-
const latestKeys = {
|
|
198
|
-
PK: (0, _keys.createPartitionKey)({
|
|
199
|
-
id: entry.id,
|
|
200
|
-
locale: model.locale,
|
|
201
|
-
tenant: model.tenant
|
|
202
|
-
}),
|
|
203
|
-
SK: (0, _keys.createLatestSortKey)()
|
|
204
|
-
};
|
|
205
|
-
const publishedKeys = {
|
|
206
|
-
PK: (0, _keys.createPartitionKey)({
|
|
207
|
-
id: entry.id,
|
|
208
|
-
locale: model.locale,
|
|
209
|
-
tenant: model.tenant
|
|
210
|
-
}),
|
|
211
|
-
SK: (0, _keys.createPublishedSortKey)()
|
|
212
|
-
};
|
|
158
|
+
const revisionKeys = createEntryRevisionKeys(entry);
|
|
159
|
+
const latestKeys = createEntryLatestKeys(entry);
|
|
160
|
+
const publishedKeys = createEntryPublishedKeys(entry);
|
|
213
161
|
|
|
214
162
|
// We'll need this flag below.
|
|
215
163
|
const isPublished = entry.status === "published";
|
|
216
164
|
const esLatestData = await transformer.getElasticsearchLatestEntryData();
|
|
217
|
-
const entityBatch =
|
|
218
|
-
entity,
|
|
165
|
+
const entityBatch = entity.createEntityWriter({
|
|
219
166
|
put: [{
|
|
220
|
-
...
|
|
221
|
-
|
|
222
|
-
...revisionKeys
|
|
167
|
+
...revisionKeys,
|
|
168
|
+
data: storageEntry
|
|
223
169
|
}, {
|
|
224
|
-
...
|
|
225
|
-
|
|
226
|
-
...latestKeys
|
|
170
|
+
...latestKeys,
|
|
171
|
+
data: storageEntry
|
|
227
172
|
}]
|
|
228
173
|
});
|
|
229
174
|
if (isPublished) {
|
|
230
175
|
entityBatch.put({
|
|
231
|
-
...
|
|
232
|
-
|
|
233
|
-
...publishedKeys
|
|
176
|
+
...publishedKeys,
|
|
177
|
+
data: storageEntry
|
|
234
178
|
});
|
|
235
179
|
|
|
236
180
|
// Unpublish previously published revision (if any).
|
|
@@ -239,16 +183,13 @@ const createEntriesStorageOperations = params => {
|
|
|
239
183
|
ids: [entry.id]
|
|
240
184
|
});
|
|
241
185
|
if (publishedRevisionStorageEntry) {
|
|
186
|
+
const publishedRevisionKey = createEntryRevisionKeys(publishedRevisionStorageEntry);
|
|
242
187
|
entityBatch.put({
|
|
243
|
-
...
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}),
|
|
249
|
-
SK: (0, _keys.createRevisionSortKey)(publishedRevisionStorageEntry),
|
|
250
|
-
TYPE: (0, _recordType.createRecordType)(),
|
|
251
|
-
status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
188
|
+
...publishedRevisionKey,
|
|
189
|
+
data: {
|
|
190
|
+
...publishedRevisionStorageEntry,
|
|
191
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
192
|
+
}
|
|
252
193
|
});
|
|
253
194
|
}
|
|
254
195
|
}
|
|
@@ -258,7 +199,7 @@ const createEntriesStorageOperations = params => {
|
|
|
258
199
|
model
|
|
259
200
|
});
|
|
260
201
|
} catch (ex) {
|
|
261
|
-
throw new
|
|
202
|
+
throw new WebinyError(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
|
|
262
203
|
error: ex,
|
|
263
204
|
entry,
|
|
264
205
|
storageEntry
|
|
@@ -266,11 +207,10 @@ const createEntriesStorageOperations = params => {
|
|
|
266
207
|
}
|
|
267
208
|
const {
|
|
268
209
|
index: esIndex
|
|
269
|
-
} =
|
|
210
|
+
} = configurations.es({
|
|
270
211
|
model
|
|
271
212
|
});
|
|
272
|
-
const elasticsearchEntityBatch =
|
|
273
|
-
entity: esEntity,
|
|
213
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter({
|
|
274
214
|
put: [{
|
|
275
215
|
...latestKeys,
|
|
276
216
|
index: esIndex,
|
|
@@ -288,7 +228,7 @@ const createEntriesStorageOperations = params => {
|
|
|
288
228
|
try {
|
|
289
229
|
await elasticsearchEntityBatch.execute();
|
|
290
230
|
} catch (ex) {
|
|
291
|
-
throw new
|
|
231
|
+
throw new WebinyError(ex.message || "Could not update latest entry in the DynamoDB Elasticsearch table.", ex.code || "CREATE_REVISION_ERROR", {
|
|
292
232
|
error: ex,
|
|
293
233
|
entry
|
|
294
234
|
});
|
|
@@ -304,7 +244,7 @@ const createEntriesStorageOperations = params => {
|
|
|
304
244
|
storageEntry: initialStorageEntry
|
|
305
245
|
} = params;
|
|
306
246
|
const model = getStorageOperationsModel(initialModel);
|
|
307
|
-
const transformer =
|
|
247
|
+
const transformer = createTransformer({
|
|
308
248
|
plugins,
|
|
309
249
|
model,
|
|
310
250
|
entry: initialEntry,
|
|
@@ -316,30 +256,9 @@ const createEntriesStorageOperations = params => {
|
|
|
316
256
|
} = transformer.transformEntryKeys();
|
|
317
257
|
const isPublished = entry.status === "published";
|
|
318
258
|
const locked = isPublished ? true : entry.locked;
|
|
319
|
-
const revisionKeys =
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
locale: model.locale,
|
|
323
|
-
tenant: model.tenant
|
|
324
|
-
}),
|
|
325
|
-
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
326
|
-
};
|
|
327
|
-
const latestKeys = {
|
|
328
|
-
PK: (0, _keys.createPartitionKey)({
|
|
329
|
-
id: entry.id,
|
|
330
|
-
locale: model.locale,
|
|
331
|
-
tenant: model.tenant
|
|
332
|
-
}),
|
|
333
|
-
SK: (0, _keys.createLatestSortKey)()
|
|
334
|
-
};
|
|
335
|
-
const publishedKeys = {
|
|
336
|
-
PK: (0, _keys.createPartitionKey)({
|
|
337
|
-
id: entry.id,
|
|
338
|
-
locale: model.locale,
|
|
339
|
-
tenant: model.tenant
|
|
340
|
-
}),
|
|
341
|
-
SK: (0, _keys.createPublishedSortKey)()
|
|
342
|
-
};
|
|
259
|
+
const revisionKeys = createEntryRevisionKeys(entry);
|
|
260
|
+
const latestKeys = createEntryLatestKeys(entry);
|
|
261
|
+
const publishedKeys = createEntryPublishedKeys(entry);
|
|
343
262
|
|
|
344
263
|
/**
|
|
345
264
|
* We need the latest entry to check if it needs to be updated.
|
|
@@ -352,29 +271,28 @@ const createEntriesStorageOperations = params => {
|
|
|
352
271
|
model,
|
|
353
272
|
ids: [entry.id]
|
|
354
273
|
});
|
|
355
|
-
const entityBatch =
|
|
356
|
-
entity,
|
|
274
|
+
const entityBatch = entity.createEntityWriter({
|
|
357
275
|
put: [{
|
|
358
|
-
...storageEntry,
|
|
359
|
-
locked,
|
|
360
276
|
...revisionKeys,
|
|
361
|
-
|
|
277
|
+
data: {
|
|
278
|
+
...storageEntry,
|
|
279
|
+
locked
|
|
280
|
+
}
|
|
362
281
|
}]
|
|
363
282
|
});
|
|
364
283
|
if (isPublished) {
|
|
365
284
|
entityBatch.put({
|
|
366
|
-
...storageEntry,
|
|
367
|
-
locked,
|
|
368
285
|
...publishedKeys,
|
|
369
|
-
|
|
286
|
+
data: {
|
|
287
|
+
...storageEntry,
|
|
288
|
+
locked
|
|
289
|
+
}
|
|
370
290
|
});
|
|
371
291
|
}
|
|
372
|
-
const elasticsearchEntityBatch = (
|
|
373
|
-
entity: esEntity
|
|
374
|
-
});
|
|
292
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter();
|
|
375
293
|
const {
|
|
376
294
|
index: esIndex
|
|
377
|
-
} =
|
|
295
|
+
} = configurations.es({
|
|
378
296
|
model
|
|
379
297
|
});
|
|
380
298
|
|
|
@@ -388,9 +306,8 @@ const createEntriesStorageOperations = params => {
|
|
|
388
306
|
* First we update the regular DynamoDB table.
|
|
389
307
|
*/
|
|
390
308
|
entityBatch.put({
|
|
391
|
-
...storageEntry,
|
|
392
309
|
...latestKeys,
|
|
393
|
-
|
|
310
|
+
data: storageEntry
|
|
394
311
|
});
|
|
395
312
|
|
|
396
313
|
/**
|
|
@@ -407,11 +324,13 @@ const createEntriesStorageOperations = params => {
|
|
|
407
324
|
* If not updating latest revision, we still want to update the latest revision's
|
|
408
325
|
* entry-level meta fields to match the current revision's entry-level meta fields.
|
|
409
326
|
*/
|
|
410
|
-
const updatedEntryLevelMetaFields =
|
|
327
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
411
328
|
const updatedLatestStorageEntry = {
|
|
412
|
-
...latestStorageEntry,
|
|
413
329
|
...latestKeys,
|
|
414
|
-
|
|
330
|
+
data: {
|
|
331
|
+
...latestStorageEntry,
|
|
332
|
+
...updatedEntryLevelMetaFields
|
|
333
|
+
}
|
|
415
334
|
};
|
|
416
335
|
|
|
417
336
|
/**
|
|
@@ -421,29 +340,23 @@ const createEntriesStorageOperations = params => {
|
|
|
421
340
|
*/
|
|
422
341
|
entityBatch.put({
|
|
423
342
|
...updatedLatestStorageEntry,
|
|
424
|
-
PK:
|
|
343
|
+
PK: createPartitionKey({
|
|
425
344
|
id: latestStorageEntry.id,
|
|
426
|
-
locale: model.locale,
|
|
427
345
|
tenant: model.tenant
|
|
428
346
|
}),
|
|
429
|
-
SK:
|
|
430
|
-
TYPE: (0, _recordType.createRecordType)()
|
|
347
|
+
SK: createRevisionSortKey(latestStorageEntry)
|
|
431
348
|
});
|
|
432
349
|
entityBatch.put({
|
|
433
|
-
...updatedLatestStorageEntry
|
|
434
|
-
TYPE: (0, _recordType.createLatestRecordType)()
|
|
350
|
+
...updatedLatestStorageEntry
|
|
435
351
|
});
|
|
436
352
|
|
|
437
353
|
/**
|
|
438
354
|
* Update the Elasticsearch table to propagate changes to the Elasticsearch.
|
|
439
355
|
*/
|
|
440
|
-
const latestEsEntry = await
|
|
441
|
-
entity: esEntity,
|
|
442
|
-
keys: latestKeys
|
|
443
|
-
});
|
|
356
|
+
const latestEsEntry = await esEntity.getClean(latestKeys);
|
|
444
357
|
if (latestEsEntry) {
|
|
445
|
-
const latestEsEntryDataDecompressed = await
|
|
446
|
-
const updatedLatestEntry = await
|
|
358
|
+
const latestEsEntryDataDecompressed = await decompress(plugins, latestEsEntry.data);
|
|
359
|
+
const updatedLatestEntry = await compress(plugins, {
|
|
447
360
|
...latestEsEntryDataDecompressed,
|
|
448
361
|
...updatedEntryLevelMetaFields
|
|
449
362
|
});
|
|
@@ -469,7 +382,7 @@ const createEntriesStorageOperations = params => {
|
|
|
469
382
|
model
|
|
470
383
|
});
|
|
471
384
|
} catch (ex) {
|
|
472
|
-
throw new
|
|
385
|
+
throw new WebinyError(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
|
|
473
386
|
error: ex,
|
|
474
387
|
entry,
|
|
475
388
|
storageEntry
|
|
@@ -478,7 +391,7 @@ const createEntriesStorageOperations = params => {
|
|
|
478
391
|
try {
|
|
479
392
|
await elasticsearchEntityBatch.execute();
|
|
480
393
|
} catch (ex) {
|
|
481
|
-
throw new
|
|
394
|
+
throw new WebinyError(ex.message || "Could not update entry DynamoDB Elasticsearch records.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
|
|
482
395
|
error: ex,
|
|
483
396
|
entry
|
|
484
397
|
});
|
|
@@ -487,38 +400,37 @@ const createEntriesStorageOperations = params => {
|
|
|
487
400
|
};
|
|
488
401
|
const move = async (initialModel, id, folderId) => {
|
|
489
402
|
const model = getStorageOperationsModel(initialModel);
|
|
490
|
-
const partitionKey =
|
|
403
|
+
const partitionKey = createPartitionKey({
|
|
491
404
|
id,
|
|
492
|
-
locale: model.locale,
|
|
493
405
|
tenant: model.tenant
|
|
494
406
|
});
|
|
495
407
|
/**
|
|
496
408
|
* First we need to fetch all the records in the regular DynamoDB table.
|
|
497
409
|
*/
|
|
498
410
|
const queryAllParams = {
|
|
499
|
-
entity,
|
|
500
411
|
partitionKey,
|
|
501
412
|
options: {
|
|
502
413
|
gte: " "
|
|
503
414
|
}
|
|
504
415
|
};
|
|
505
|
-
const latestSortKey =
|
|
506
|
-
const publishedSortKey =
|
|
507
|
-
const records = await
|
|
416
|
+
const latestSortKey = createLatestSortKey();
|
|
417
|
+
const publishedSortKey = createPublishedSortKey();
|
|
418
|
+
const records = await entity.queryAll(queryAllParams);
|
|
508
419
|
/**
|
|
509
420
|
* Then update the folderId in each record and prepare it to be stored.
|
|
510
421
|
*/
|
|
511
422
|
let latestRecord = undefined;
|
|
512
423
|
let publishedRecord = undefined;
|
|
513
|
-
const entityBatch = (
|
|
514
|
-
entity
|
|
515
|
-
});
|
|
424
|
+
const entityBatch = entity.createEntityWriter();
|
|
516
425
|
for (const record of records) {
|
|
517
426
|
entityBatch.put({
|
|
518
427
|
...record,
|
|
519
|
-
|
|
520
|
-
...record
|
|
521
|
-
|
|
428
|
+
data: {
|
|
429
|
+
...record.data,
|
|
430
|
+
location: {
|
|
431
|
+
...record.data.location,
|
|
432
|
+
folderId
|
|
433
|
+
}
|
|
522
434
|
}
|
|
523
435
|
});
|
|
524
436
|
|
|
@@ -526,9 +438,9 @@ const createEntriesStorageOperations = params => {
|
|
|
526
438
|
* We need to get the published and latest records, so we can update the Elasticsearch.
|
|
527
439
|
*/
|
|
528
440
|
if (record.SK === publishedSortKey) {
|
|
529
|
-
publishedRecord = record;
|
|
441
|
+
publishedRecord = record.data;
|
|
530
442
|
} else if (record.SK === latestSortKey) {
|
|
531
|
-
latestRecord = record;
|
|
443
|
+
latestRecord = record.data;
|
|
532
444
|
}
|
|
533
445
|
}
|
|
534
446
|
try {
|
|
@@ -537,62 +449,58 @@ const createEntriesStorageOperations = params => {
|
|
|
537
449
|
model
|
|
538
450
|
});
|
|
539
451
|
} catch (ex) {
|
|
540
|
-
throw new
|
|
452
|
+
throw new WebinyError(ex.message || "Could not move all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_ERROR", {
|
|
541
453
|
error: ex,
|
|
542
454
|
id
|
|
543
455
|
});
|
|
544
456
|
}
|
|
545
|
-
const
|
|
457
|
+
const esEntityReader = esEntity.createEntityReader();
|
|
546
458
|
if (publishedRecord) {
|
|
547
|
-
|
|
459
|
+
esEntityReader.get({
|
|
548
460
|
PK: partitionKey,
|
|
549
461
|
SK: publishedSortKey
|
|
550
|
-
})
|
|
462
|
+
});
|
|
551
463
|
}
|
|
552
464
|
if (latestRecord) {
|
|
553
|
-
|
|
465
|
+
esEntityReader.get({
|
|
554
466
|
PK: partitionKey,
|
|
555
467
|
SK: latestSortKey
|
|
556
|
-
})
|
|
468
|
+
});
|
|
557
469
|
}
|
|
558
|
-
if (
|
|
470
|
+
if (esEntityReader.total === 0) {
|
|
559
471
|
return;
|
|
560
472
|
}
|
|
561
|
-
const esRecords = await (
|
|
562
|
-
table: esEntity.table,
|
|
563
|
-
items: esGetItems
|
|
564
|
-
});
|
|
473
|
+
const esRecords = await esEntityReader.execute();
|
|
565
474
|
const esItems = (await Promise.all(esRecords.map(async record => {
|
|
566
475
|
if (!record) {
|
|
567
476
|
return null;
|
|
568
477
|
}
|
|
569
478
|
return {
|
|
570
479
|
...record,
|
|
571
|
-
data: await
|
|
480
|
+
data: await decompress(plugins, record.data)
|
|
572
481
|
};
|
|
573
|
-
}))).filter(
|
|
482
|
+
}))).filter(item => !!item);
|
|
574
483
|
if (esItems.length === 0) {
|
|
575
484
|
return;
|
|
576
485
|
}
|
|
577
|
-
const elasticsearchEntityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
578
|
-
entity: esEntity,
|
|
579
|
-
put: await Promise.all(esItems.map(async item => {
|
|
580
|
-
return {
|
|
581
|
-
...item,
|
|
582
|
-
data: await (0, _apiElasticsearch.compress)(plugins, {
|
|
583
|
-
...item.data,
|
|
584
|
-
location: {
|
|
585
|
-
...item.data?.location,
|
|
586
|
-
folderId
|
|
587
|
-
}
|
|
588
|
-
})
|
|
589
|
-
};
|
|
590
|
-
}))
|
|
591
|
-
});
|
|
592
486
|
try {
|
|
487
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter({
|
|
488
|
+
put: await Promise.all(esItems.map(async item => {
|
|
489
|
+
return {
|
|
490
|
+
...item,
|
|
491
|
+
data: await compress(plugins, {
|
|
492
|
+
...item.data,
|
|
493
|
+
location: {
|
|
494
|
+
...item.data?.location,
|
|
495
|
+
folderId
|
|
496
|
+
}
|
|
497
|
+
})
|
|
498
|
+
};
|
|
499
|
+
}))
|
|
500
|
+
});
|
|
593
501
|
await elasticsearchEntityBatch.execute();
|
|
594
502
|
} catch (ex) {
|
|
595
|
-
throw new
|
|
503
|
+
throw new WebinyError(ex.message || "Could not move entry DynamoDB Elasticsearch records.", ex.code || "MOVE_ES_ENTRY_ERROR", {
|
|
596
504
|
error: ex,
|
|
597
505
|
partitionKey
|
|
598
506
|
});
|
|
@@ -604,7 +512,7 @@ const createEntriesStorageOperations = params => {
|
|
|
604
512
|
storageEntry: initialStorageEntry
|
|
605
513
|
} = params;
|
|
606
514
|
const model = getStorageOperationsModel(initialModel);
|
|
607
|
-
const transformer =
|
|
515
|
+
const transformer = createTransformer({
|
|
608
516
|
plugins,
|
|
609
517
|
model,
|
|
610
518
|
entry: initialEntry,
|
|
@@ -614,9 +522,8 @@ const createEntriesStorageOperations = params => {
|
|
|
614
522
|
entry,
|
|
615
523
|
storageEntry
|
|
616
524
|
} = transformer.transformEntryKeys();
|
|
617
|
-
const partitionKey =
|
|
525
|
+
const partitionKey = createPartitionKey({
|
|
618
526
|
id: entry.id,
|
|
619
|
-
locale: model.locale,
|
|
620
527
|
tenant: model.tenant
|
|
621
528
|
});
|
|
622
529
|
|
|
@@ -624,45 +531,45 @@ const createEntriesStorageOperations = params => {
|
|
|
624
531
|
* First we need to fetch all the records in the regular DynamoDB table.
|
|
625
532
|
*/
|
|
626
533
|
const queryAllParams = {
|
|
627
|
-
entity,
|
|
628
534
|
partitionKey,
|
|
629
535
|
options: {
|
|
630
536
|
gte: " "
|
|
631
537
|
}
|
|
632
538
|
};
|
|
633
|
-
const latestSortKey =
|
|
634
|
-
const publishedSortKey =
|
|
635
|
-
const records = await
|
|
539
|
+
const latestSortKey = createLatestSortKey();
|
|
540
|
+
const publishedSortKey = createPublishedSortKey();
|
|
541
|
+
const records = await entity.queryAll(queryAllParams);
|
|
636
542
|
|
|
637
543
|
/**
|
|
638
544
|
* Let's pick the `deleted` meta fields from the entry.
|
|
639
545
|
*/
|
|
640
|
-
const updatedEntryMetaFields =
|
|
546
|
+
const updatedEntryMetaFields = pickEntryMetaFields(entry, isDeletedEntryMetaField);
|
|
641
547
|
|
|
642
548
|
/**
|
|
643
549
|
* Then update all the records with data received.
|
|
644
550
|
*/
|
|
645
551
|
let latestRecord = undefined;
|
|
646
552
|
let publishedRecord = undefined;
|
|
647
|
-
const entityBatch = (
|
|
648
|
-
entity
|
|
649
|
-
});
|
|
553
|
+
const entityBatch = entity.createEntityWriter();
|
|
650
554
|
for (const record of records) {
|
|
651
555
|
entityBatch.put({
|
|
652
556
|
...record,
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
557
|
+
data: {
|
|
558
|
+
...record.data,
|
|
559
|
+
...updatedEntryMetaFields,
|
|
560
|
+
wbyDeleted: storageEntry.wbyDeleted,
|
|
561
|
+
location: storageEntry.location,
|
|
562
|
+
binOriginalFolderId: storageEntry.binOriginalFolderId
|
|
563
|
+
}
|
|
657
564
|
});
|
|
658
565
|
|
|
659
566
|
/**
|
|
660
567
|
* We need to get the published and latest records, so we can update the Elasticsearch.
|
|
661
568
|
*/
|
|
662
569
|
if (record.SK === publishedSortKey) {
|
|
663
|
-
publishedRecord = record;
|
|
570
|
+
publishedRecord = record.data;
|
|
664
571
|
} else if (record.SK === latestSortKey) {
|
|
665
|
-
latestRecord = record;
|
|
572
|
+
latestRecord = record.data;
|
|
666
573
|
}
|
|
667
574
|
}
|
|
668
575
|
|
|
@@ -675,7 +582,7 @@ const createEntriesStorageOperations = params => {
|
|
|
675
582
|
model
|
|
676
583
|
});
|
|
677
584
|
} catch (ex) {
|
|
678
|
-
throw new
|
|
585
|
+
throw new WebinyError(ex.message || "Could mark as deleted all entry records from in the DynamoDB table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
|
|
679
586
|
error: ex,
|
|
680
587
|
entry,
|
|
681
588
|
storageEntry
|
|
@@ -685,35 +592,32 @@ const createEntriesStorageOperations = params => {
|
|
|
685
592
|
/**
|
|
686
593
|
* We need to get the published and latest records from Elasticsearch.
|
|
687
594
|
*/
|
|
688
|
-
const
|
|
595
|
+
const esEntityReader = esEntity.createEntityReader();
|
|
689
596
|
if (publishedRecord) {
|
|
690
|
-
|
|
597
|
+
esEntityReader.get({
|
|
691
598
|
PK: partitionKey,
|
|
692
599
|
SK: publishedSortKey
|
|
693
|
-
})
|
|
600
|
+
});
|
|
694
601
|
}
|
|
695
602
|
if (latestRecord) {
|
|
696
|
-
|
|
603
|
+
esEntityReader.get({
|
|
697
604
|
PK: partitionKey,
|
|
698
605
|
SK: latestSortKey
|
|
699
|
-
})
|
|
606
|
+
});
|
|
700
607
|
}
|
|
701
|
-
if (
|
|
608
|
+
if (esEntityReader.total === 0) {
|
|
702
609
|
return;
|
|
703
610
|
}
|
|
704
|
-
const esRecords = await (
|
|
705
|
-
table: esEntity.table,
|
|
706
|
-
items: esGetItems
|
|
707
|
-
});
|
|
611
|
+
const esRecords = await esEntityReader.execute();
|
|
708
612
|
const esItems = (await Promise.all(esRecords.map(async record => {
|
|
709
613
|
if (!record) {
|
|
710
614
|
return null;
|
|
711
615
|
}
|
|
712
616
|
return {
|
|
713
617
|
...record,
|
|
714
|
-
data: await
|
|
618
|
+
data: await decompress(plugins, record.data)
|
|
715
619
|
};
|
|
716
|
-
}))).filter(
|
|
620
|
+
}))).filter(item => !!item);
|
|
717
621
|
if (esItems.length === 0) {
|
|
718
622
|
return;
|
|
719
623
|
}
|
|
@@ -721,13 +625,11 @@ const createEntriesStorageOperations = params => {
|
|
|
721
625
|
/**
|
|
722
626
|
* We update all ES records with data received.
|
|
723
627
|
*/
|
|
724
|
-
const elasticsearchEntityBatch = (
|
|
725
|
-
entity: esEntity
|
|
726
|
-
});
|
|
628
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter();
|
|
727
629
|
for (const item of esItems) {
|
|
728
630
|
elasticsearchEntityBatch.put({
|
|
729
631
|
...item,
|
|
730
|
-
data: await
|
|
632
|
+
data: await compress(plugins, {
|
|
731
633
|
...item.data,
|
|
732
634
|
...updatedEntryMetaFields,
|
|
733
635
|
wbyDeleted: entry.wbyDeleted,
|
|
@@ -743,7 +645,7 @@ const createEntriesStorageOperations = params => {
|
|
|
743
645
|
try {
|
|
744
646
|
await elasticsearchEntityBatch.execute();
|
|
745
647
|
} catch (ex) {
|
|
746
|
-
throw new
|
|
648
|
+
throw new WebinyError(ex.message || "Could not mark as deleted entry records from DynamoDB Elasticsearch table.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
|
|
747
649
|
error: ex,
|
|
748
650
|
entry,
|
|
749
651
|
storageEntry
|
|
@@ -756,7 +658,7 @@ const createEntriesStorageOperations = params => {
|
|
|
756
658
|
storageEntry: initialStorageEntry
|
|
757
659
|
} = params;
|
|
758
660
|
const model = getStorageOperationsModel(initialModel);
|
|
759
|
-
const transformer =
|
|
661
|
+
const transformer = createTransformer({
|
|
760
662
|
plugins,
|
|
761
663
|
model,
|
|
762
664
|
entry: initialEntry,
|
|
@@ -770,10 +672,9 @@ const createEntriesStorageOperations = params => {
|
|
|
770
672
|
/**
|
|
771
673
|
* Let's pick the `restored` meta fields from the storage entry.
|
|
772
674
|
*/
|
|
773
|
-
const updatedEntryMetaFields =
|
|
774
|
-
const partitionKey =
|
|
675
|
+
const updatedEntryMetaFields = pickEntryMetaFields(entry, isRestoredEntryMetaField);
|
|
676
|
+
const partitionKey = createPartitionKey({
|
|
775
677
|
id: entry.id,
|
|
776
|
-
locale: model.locale,
|
|
777
678
|
tenant: model.tenant
|
|
778
679
|
});
|
|
779
680
|
|
|
@@ -781,40 +682,40 @@ const createEntriesStorageOperations = params => {
|
|
|
781
682
|
* First we need to fetch all the records in the regular DynamoDB table.
|
|
782
683
|
*/
|
|
783
684
|
const queryAllParams = {
|
|
784
|
-
entity,
|
|
785
685
|
partitionKey,
|
|
786
686
|
options: {
|
|
787
687
|
gte: " "
|
|
788
688
|
}
|
|
789
689
|
};
|
|
790
|
-
const latestSortKey =
|
|
791
|
-
const publishedSortKey =
|
|
792
|
-
const records = await
|
|
690
|
+
const latestSortKey = createLatestSortKey();
|
|
691
|
+
const publishedSortKey = createPublishedSortKey();
|
|
692
|
+
const records = await entity.queryAll(queryAllParams);
|
|
793
693
|
|
|
794
694
|
/**
|
|
795
695
|
* Then update all the records with data received.
|
|
796
696
|
*/
|
|
797
697
|
let latestRecord = undefined;
|
|
798
698
|
let publishedRecord = undefined;
|
|
799
|
-
const entityBatch = (
|
|
800
|
-
entity
|
|
801
|
-
});
|
|
699
|
+
const entityBatch = entity.createEntityWriter();
|
|
802
700
|
for (const record of records) {
|
|
803
701
|
entityBatch.put({
|
|
804
702
|
...record,
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
703
|
+
data: {
|
|
704
|
+
...record.data,
|
|
705
|
+
...updatedEntryMetaFields,
|
|
706
|
+
wbyDeleted: storageEntry.wbyDeleted,
|
|
707
|
+
location: storageEntry.location,
|
|
708
|
+
binOriginalFolderId: storageEntry.binOriginalFolderId
|
|
709
|
+
}
|
|
809
710
|
});
|
|
810
711
|
|
|
811
712
|
/**
|
|
812
713
|
* We need to get the published and latest records, so we can update the Elasticsearch.
|
|
813
714
|
*/
|
|
814
715
|
if (record.SK === publishedSortKey) {
|
|
815
|
-
publishedRecord = record;
|
|
716
|
+
publishedRecord = record.data;
|
|
816
717
|
} else if (record.SK === latestSortKey) {
|
|
817
|
-
latestRecord = record;
|
|
718
|
+
latestRecord = record.data;
|
|
818
719
|
}
|
|
819
720
|
}
|
|
820
721
|
|
|
@@ -827,7 +728,7 @@ const createEntriesStorageOperations = params => {
|
|
|
827
728
|
model
|
|
828
729
|
});
|
|
829
730
|
} catch (ex) {
|
|
830
|
-
throw new
|
|
731
|
+
throw new WebinyError(ex.message || "Could not restore all entry records from in the DynamoDB table.", ex.code || "RESTORE_ENTRY_ERROR", {
|
|
831
732
|
error: ex,
|
|
832
733
|
entry,
|
|
833
734
|
storageEntry
|
|
@@ -837,32 +738,29 @@ const createEntriesStorageOperations = params => {
|
|
|
837
738
|
/**
|
|
838
739
|
* We need to get the published and latest records from Elasticsearch.
|
|
839
740
|
*/
|
|
840
|
-
const
|
|
741
|
+
const esEntityReader = esEntity.createEntityReader();
|
|
841
742
|
if (publishedRecord) {
|
|
842
|
-
|
|
743
|
+
esEntityReader.get({
|
|
843
744
|
PK: partitionKey,
|
|
844
745
|
SK: publishedSortKey
|
|
845
|
-
})
|
|
746
|
+
});
|
|
846
747
|
}
|
|
847
748
|
if (latestRecord) {
|
|
848
|
-
|
|
749
|
+
esEntityReader.get({
|
|
849
750
|
PK: partitionKey,
|
|
850
751
|
SK: latestSortKey
|
|
851
|
-
})
|
|
752
|
+
});
|
|
852
753
|
}
|
|
853
|
-
const esRecords = await (
|
|
854
|
-
table: esEntity.table,
|
|
855
|
-
items: esGetItems
|
|
856
|
-
});
|
|
754
|
+
const esRecords = await esEntityReader.execute();
|
|
857
755
|
const esItems = (await Promise.all(esRecords.map(async record => {
|
|
858
756
|
if (!record) {
|
|
859
757
|
return null;
|
|
860
758
|
}
|
|
861
759
|
return {
|
|
862
760
|
...record,
|
|
863
|
-
data: await
|
|
761
|
+
data: await decompress(plugins, record.data)
|
|
864
762
|
};
|
|
865
|
-
}))).filter(
|
|
763
|
+
}))).filter(item => !!item);
|
|
866
764
|
if (esItems.length === 0) {
|
|
867
765
|
return initialStorageEntry;
|
|
868
766
|
}
|
|
@@ -870,13 +768,11 @@ const createEntriesStorageOperations = params => {
|
|
|
870
768
|
/**
|
|
871
769
|
* We update all ES records with data received.
|
|
872
770
|
*/
|
|
873
|
-
const elasticsearchEntityBatch = (
|
|
874
|
-
entity: esEntity
|
|
875
|
-
});
|
|
771
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter();
|
|
876
772
|
for (const item of esItems) {
|
|
877
773
|
elasticsearchEntityBatch.put({
|
|
878
774
|
...item,
|
|
879
|
-
data: await
|
|
775
|
+
data: await compress(plugins, {
|
|
880
776
|
...item.data,
|
|
881
777
|
...updatedEntryMetaFields,
|
|
882
778
|
wbyDeleted: entry.wbyDeleted,
|
|
@@ -892,7 +788,7 @@ const createEntriesStorageOperations = params => {
|
|
|
892
788
|
try {
|
|
893
789
|
await elasticsearchEntityBatch.execute();
|
|
894
790
|
} catch (ex) {
|
|
895
|
-
throw new
|
|
791
|
+
throw new WebinyError(ex.message || "Could not restore entry records from DynamoDB Elasticsearch table.", ex.code || "RESTORE_ENTRY_ERROR", {
|
|
896
792
|
error: ex,
|
|
897
793
|
entry,
|
|
898
794
|
storageEntry
|
|
@@ -906,27 +802,23 @@ const createEntriesStorageOperations = params => {
|
|
|
906
802
|
} = params;
|
|
907
803
|
const id = entry.id || entry.entryId;
|
|
908
804
|
const model = getStorageOperationsModel(initialModel);
|
|
909
|
-
const partitionKey =
|
|
805
|
+
const partitionKey = createPartitionKey({
|
|
910
806
|
id,
|
|
911
|
-
locale: model.locale,
|
|
912
807
|
tenant: model.tenant
|
|
913
808
|
});
|
|
914
|
-
const items = await
|
|
915
|
-
entity,
|
|
809
|
+
const items = await entity.queryAll({
|
|
916
810
|
partitionKey,
|
|
917
811
|
options: {
|
|
918
812
|
gte: " "
|
|
919
813
|
}
|
|
920
814
|
});
|
|
921
|
-
const esItems = await
|
|
922
|
-
entity: esEntity,
|
|
815
|
+
const esItems = await esEntity.queryAll({
|
|
923
816
|
partitionKey,
|
|
924
817
|
options: {
|
|
925
818
|
gte: " "
|
|
926
819
|
}
|
|
927
820
|
});
|
|
928
|
-
const entityBatch =
|
|
929
|
-
entity,
|
|
821
|
+
const entityBatch = entity.createEntityWriter({
|
|
930
822
|
delete: items.map(item => {
|
|
931
823
|
return {
|
|
932
824
|
PK: item.PK,
|
|
@@ -934,8 +826,7 @@ const createEntriesStorageOperations = params => {
|
|
|
934
826
|
};
|
|
935
827
|
})
|
|
936
828
|
});
|
|
937
|
-
const elasticsearchEntityBatch =
|
|
938
|
-
entity: esEntity,
|
|
829
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter({
|
|
939
830
|
delete: esItems.map(item => {
|
|
940
831
|
return {
|
|
941
832
|
PK: item.PK,
|
|
@@ -949,7 +840,7 @@ const createEntriesStorageOperations = params => {
|
|
|
949
840
|
model
|
|
950
841
|
});
|
|
951
842
|
} catch (ex) {
|
|
952
|
-
throw new
|
|
843
|
+
throw new WebinyError(ex.message || "Could not destroy entry records from DynamoDB table.", ex.code || "DELETE_ENTRY_ERROR", {
|
|
953
844
|
error: ex,
|
|
954
845
|
id
|
|
955
846
|
});
|
|
@@ -957,7 +848,7 @@ const createEntriesStorageOperations = params => {
|
|
|
957
848
|
try {
|
|
958
849
|
await elasticsearchEntityBatch.execute();
|
|
959
850
|
} catch (ex) {
|
|
960
|
-
throw new
|
|
851
|
+
throw new WebinyError(ex.message || "Could not destroy entry records from DynamoDB Elasticsearch table.", ex.code || "DELETE_ENTRY_ERROR", {
|
|
961
852
|
error: ex,
|
|
962
853
|
id
|
|
963
854
|
});
|
|
@@ -970,14 +861,13 @@ const createEntriesStorageOperations = params => {
|
|
|
970
861
|
latestStorageEntry: initialLatestStorageEntry
|
|
971
862
|
} = params;
|
|
972
863
|
const model = getStorageOperationsModel(initialModel);
|
|
973
|
-
const partitionKey =
|
|
864
|
+
const partitionKey = createPartitionKey({
|
|
974
865
|
id: entry.id,
|
|
975
|
-
locale: model.locale,
|
|
976
866
|
tenant: model.tenant
|
|
977
867
|
});
|
|
978
868
|
const {
|
|
979
869
|
index
|
|
980
|
-
} =
|
|
870
|
+
} = configurations.es({
|
|
981
871
|
model
|
|
982
872
|
});
|
|
983
873
|
/**
|
|
@@ -990,16 +880,13 @@ const createEntriesStorageOperations = params => {
|
|
|
990
880
|
/**
|
|
991
881
|
* We need to delete all existing records of the given entry revision.
|
|
992
882
|
*/
|
|
993
|
-
const entityBatch =
|
|
994
|
-
entity,
|
|
883
|
+
const entityBatch = entity.createEntityWriter({
|
|
995
884
|
delete: [{
|
|
996
885
|
PK: partitionKey,
|
|
997
|
-
SK:
|
|
886
|
+
SK: createRevisionSortKey(entry)
|
|
998
887
|
}]
|
|
999
888
|
});
|
|
1000
|
-
const elasticsearchEntityBatch = (
|
|
1001
|
-
entity: esEntity
|
|
1002
|
-
});
|
|
889
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter();
|
|
1003
890
|
|
|
1004
891
|
/**
|
|
1005
892
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
@@ -1007,11 +894,11 @@ const createEntriesStorageOperations = params => {
|
|
|
1007
894
|
if (publishedStorageEntry?.id === entry.id) {
|
|
1008
895
|
entityBatch.delete({
|
|
1009
896
|
PK: partitionKey,
|
|
1010
|
-
SK:
|
|
897
|
+
SK: createPublishedSortKey()
|
|
1011
898
|
});
|
|
1012
899
|
elasticsearchEntityBatch.delete({
|
|
1013
900
|
PK: partitionKey,
|
|
1014
|
-
SK:
|
|
901
|
+
SK: createPublishedSortKey()
|
|
1015
902
|
});
|
|
1016
903
|
}
|
|
1017
904
|
if (latestEntry && initialLatestStorageEntry) {
|
|
@@ -1023,37 +910,31 @@ const createEntriesStorageOperations = params => {
|
|
|
1023
910
|
/**
|
|
1024
911
|
* In the end we need to set the new latest entry.
|
|
1025
912
|
*/
|
|
913
|
+
const latestStorageEntryLatestKey = createEntryLatestKeys(latestStorageEntry);
|
|
1026
914
|
entityBatch.put({
|
|
1027
|
-
...
|
|
1028
|
-
|
|
1029
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
1030
|
-
TYPE: (0, _recordType.createLatestRecordType)()
|
|
915
|
+
...latestStorageEntryLatestKey,
|
|
916
|
+
data: latestStorageEntry
|
|
1031
917
|
});
|
|
1032
918
|
|
|
1033
919
|
/**
|
|
1034
920
|
* Also perform an update on the actual revision. This is needed
|
|
1035
921
|
* because of updates on the entry-level meta fields.
|
|
1036
922
|
*/
|
|
923
|
+
const actualRevisionEntryKey = createEntryRevisionKeys(initialLatestStorageEntry);
|
|
1037
924
|
entityBatch.put({
|
|
1038
|
-
...
|
|
1039
|
-
|
|
1040
|
-
id: initialLatestStorageEntry.id,
|
|
1041
|
-
locale: model.locale,
|
|
1042
|
-
tenant: model.tenant
|
|
1043
|
-
}),
|
|
1044
|
-
SK: (0, _keys.createRevisionSortKey)(initialLatestStorageEntry),
|
|
1045
|
-
TYPE: (0, _recordType.createRecordType)()
|
|
925
|
+
...actualRevisionEntryKey,
|
|
926
|
+
data: latestStorageEntry
|
|
1046
927
|
});
|
|
1047
|
-
const latestTransformer =
|
|
928
|
+
const latestTransformer = createTransformer({
|
|
1048
929
|
plugins,
|
|
1049
930
|
model,
|
|
1050
931
|
entry: latestEntry,
|
|
1051
932
|
storageEntry: initialLatestStorageEntry
|
|
1052
933
|
});
|
|
1053
934
|
const esLatestData = await latestTransformer.getElasticsearchLatestEntryData();
|
|
935
|
+
const esLatestKeys = createEntryLatestKeys(latestEntry);
|
|
1054
936
|
elasticsearchEntityBatch.put({
|
|
1055
|
-
|
|
1056
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
937
|
+
...esLatestKeys,
|
|
1057
938
|
index,
|
|
1058
939
|
data: esLatestData
|
|
1059
940
|
});
|
|
@@ -1064,7 +945,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1064
945
|
model
|
|
1065
946
|
});
|
|
1066
947
|
} catch (ex) {
|
|
1067
|
-
throw new
|
|
948
|
+
throw new WebinyError(ex.message || "Could not batch write entry records to DynamoDB table.", ex.code || "DELETE_REVISION_ERROR", {
|
|
1068
949
|
error: ex,
|
|
1069
950
|
entry,
|
|
1070
951
|
latestEntry,
|
|
@@ -1074,7 +955,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1074
955
|
try {
|
|
1075
956
|
await elasticsearchEntityBatch.execute();
|
|
1076
957
|
} catch (ex) {
|
|
1077
|
-
throw new
|
|
958
|
+
throw new WebinyError(ex.message || "Could not batch write entry records to DynamoDB Elasticsearch table.", ex.code || "DELETE_REVISION_ERROR", {
|
|
1078
959
|
error: ex,
|
|
1079
960
|
entry,
|
|
1080
961
|
latestEntry,
|
|
@@ -1098,28 +979,22 @@ const createEntriesStorageOperations = params => {
|
|
|
1098
979
|
* Then we need to construct the queries for all the revisions and entries.
|
|
1099
980
|
*/
|
|
1100
981
|
|
|
1101
|
-
const entityBatch = (
|
|
1102
|
-
|
|
1103
|
-
});
|
|
1104
|
-
const elasticsearchEntityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
|
|
1105
|
-
entity: esEntity
|
|
1106
|
-
});
|
|
982
|
+
const entityBatch = entity.createEntityWriter();
|
|
983
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter();
|
|
1107
984
|
for (const id of entries) {
|
|
1108
985
|
/**
|
|
1109
986
|
* Latest item.
|
|
1110
987
|
*/
|
|
1111
988
|
entityBatch.delete({
|
|
1112
|
-
PK:
|
|
989
|
+
PK: createPartitionKey({
|
|
1113
990
|
id,
|
|
1114
|
-
locale: model.locale,
|
|
1115
991
|
tenant: model.tenant
|
|
1116
992
|
}),
|
|
1117
993
|
SK: "L"
|
|
1118
994
|
});
|
|
1119
995
|
elasticsearchEntityBatch.delete({
|
|
1120
|
-
PK:
|
|
996
|
+
PK: createPartitionKey({
|
|
1121
997
|
id,
|
|
1122
|
-
locale: model.locale,
|
|
1123
998
|
tenant: model.tenant
|
|
1124
999
|
}),
|
|
1125
1000
|
SK: "L"
|
|
@@ -1129,17 +1004,15 @@ const createEntriesStorageOperations = params => {
|
|
|
1129
1004
|
* Published item.
|
|
1130
1005
|
*/
|
|
1131
1006
|
entityBatch.delete({
|
|
1132
|
-
PK:
|
|
1007
|
+
PK: createPartitionKey({
|
|
1133
1008
|
id,
|
|
1134
|
-
locale: model.locale,
|
|
1135
1009
|
tenant: model.tenant
|
|
1136
1010
|
}),
|
|
1137
1011
|
SK: "P"
|
|
1138
1012
|
});
|
|
1139
1013
|
elasticsearchEntityBatch.delete({
|
|
1140
|
-
PK:
|
|
1014
|
+
PK: createPartitionKey({
|
|
1141
1015
|
id,
|
|
1142
|
-
locale: model.locale,
|
|
1143
1016
|
tenant: model.tenant
|
|
1144
1017
|
}),
|
|
1145
1018
|
SK: "P"
|
|
@@ -1150,12 +1023,11 @@ const createEntriesStorageOperations = params => {
|
|
|
1150
1023
|
*/
|
|
1151
1024
|
for (const revision of revisions) {
|
|
1152
1025
|
entityBatch.delete({
|
|
1153
|
-
PK:
|
|
1026
|
+
PK: createPartitionKey({
|
|
1154
1027
|
id: revision.id,
|
|
1155
|
-
locale: model.locale,
|
|
1156
1028
|
tenant: model.tenant
|
|
1157
1029
|
}),
|
|
1158
|
-
SK:
|
|
1030
|
+
SK: createRevisionSortKey({
|
|
1159
1031
|
version: revision.version
|
|
1160
1032
|
})
|
|
1161
1033
|
});
|
|
@@ -1165,18 +1037,18 @@ const createEntriesStorageOperations = params => {
|
|
|
1165
1037
|
};
|
|
1166
1038
|
const list = async (initialModel, params) => {
|
|
1167
1039
|
const model = getStorageOperationsModel(initialModel);
|
|
1168
|
-
const limit =
|
|
1040
|
+
const limit = createLimit(params.limit, 50);
|
|
1169
1041
|
const {
|
|
1170
1042
|
index
|
|
1171
|
-
} =
|
|
1043
|
+
} = configurations.es({
|
|
1172
1044
|
model
|
|
1173
1045
|
});
|
|
1174
|
-
const body =
|
|
1046
|
+
const body = createElasticsearchBody({
|
|
1175
1047
|
model,
|
|
1176
1048
|
params: {
|
|
1177
1049
|
...params,
|
|
1178
1050
|
limit,
|
|
1179
|
-
after:
|
|
1051
|
+
after: decodeCursor(params.after)
|
|
1180
1052
|
},
|
|
1181
1053
|
plugins
|
|
1182
1054
|
});
|
|
@@ -1191,12 +1063,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1191
1063
|
* We will silently ignore the `index_not_found_exception` error and return an empty result set.
|
|
1192
1064
|
* This is because the index might not exist yet, and we don't want to throw an error.
|
|
1193
1065
|
*/
|
|
1194
|
-
if (
|
|
1195
|
-
(0, _logIgnoredEsResponseError.logIgnoredEsResponseError)({
|
|
1196
|
-
error,
|
|
1197
|
-
model,
|
|
1198
|
-
indexName: index
|
|
1199
|
-
});
|
|
1066
|
+
if (shouldIgnoreEsResponseError(error)) {
|
|
1200
1067
|
return {
|
|
1201
1068
|
hasMoreItems: false,
|
|
1202
1069
|
totalCount: 0,
|
|
@@ -1204,7 +1071,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1204
1071
|
items: []
|
|
1205
1072
|
};
|
|
1206
1073
|
}
|
|
1207
|
-
throw new
|
|
1074
|
+
throw new WebinyError(error.message, error.code || "OPENSEARCH_ERROR", {
|
|
1208
1075
|
error,
|
|
1209
1076
|
index,
|
|
1210
1077
|
body,
|
|
@@ -1215,12 +1082,14 @@ const createEntriesStorageOperations = params => {
|
|
|
1215
1082
|
hits,
|
|
1216
1083
|
total
|
|
1217
1084
|
} = response?.body?.hits || {};
|
|
1218
|
-
const items =
|
|
1085
|
+
const items = extractEntriesFromIndex({
|
|
1219
1086
|
plugins,
|
|
1220
1087
|
model,
|
|
1221
|
-
entries: hits.map(item =>
|
|
1088
|
+
entries: hits.map(item => {
|
|
1089
|
+
return item._source;
|
|
1090
|
+
})
|
|
1222
1091
|
}).map(item => {
|
|
1223
|
-
return
|
|
1092
|
+
return convertEntryKeysFromStorage({
|
|
1224
1093
|
model,
|
|
1225
1094
|
entry: item
|
|
1226
1095
|
});
|
|
@@ -1236,7 +1105,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1236
1105
|
* Cursor is the `sort` value of the last item in the array.
|
|
1237
1106
|
* https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
|
|
1238
1107
|
*/
|
|
1239
|
-
const cursor = items.length > 0 ?
|
|
1108
|
+
const cursor = items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null;
|
|
1240
1109
|
return {
|
|
1241
1110
|
hasMoreItems,
|
|
1242
1111
|
totalCount: total.value,
|
|
@@ -1260,7 +1129,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1260
1129
|
storageEntry: initialStorageEntry
|
|
1261
1130
|
} = params;
|
|
1262
1131
|
const model = getStorageOperationsModel(initialModel);
|
|
1263
|
-
const transformer =
|
|
1132
|
+
const transformer = createTransformer({
|
|
1264
1133
|
plugins,
|
|
1265
1134
|
model,
|
|
1266
1135
|
entry: initialEntry,
|
|
@@ -1270,45 +1139,21 @@ const createEntriesStorageOperations = params => {
|
|
|
1270
1139
|
entry,
|
|
1271
1140
|
storageEntry
|
|
1272
1141
|
} = transformer.transformEntryKeys();
|
|
1273
|
-
const revisionKeys =
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
locale: model.locale,
|
|
1277
|
-
tenant: model.tenant
|
|
1278
|
-
}),
|
|
1279
|
-
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
1280
|
-
};
|
|
1281
|
-
const latestKeys = {
|
|
1282
|
-
PK: (0, _keys.createPartitionKey)({
|
|
1283
|
-
id: entry.id,
|
|
1284
|
-
locale: model.locale,
|
|
1285
|
-
tenant: model.tenant
|
|
1286
|
-
}),
|
|
1287
|
-
SK: (0, _keys.createLatestSortKey)()
|
|
1288
|
-
};
|
|
1289
|
-
const publishedKeys = {
|
|
1290
|
-
PK: (0, _keys.createPartitionKey)({
|
|
1291
|
-
id: entry.id,
|
|
1292
|
-
locale: model.locale,
|
|
1293
|
-
tenant: model.tenant
|
|
1294
|
-
}),
|
|
1295
|
-
SK: (0, _keys.createPublishedSortKey)()
|
|
1296
|
-
};
|
|
1142
|
+
const revisionKeys = createEntryRevisionKeys(entry);
|
|
1143
|
+
const latestKeys = createEntryLatestKeys(entry);
|
|
1144
|
+
const publishedKeys = createEntryPublishedKeys(entry);
|
|
1297
1145
|
let latestEsEntry = null;
|
|
1298
1146
|
try {
|
|
1299
|
-
latestEsEntry = await
|
|
1300
|
-
entity: esEntity,
|
|
1301
|
-
keys: latestKeys
|
|
1302
|
-
});
|
|
1147
|
+
latestEsEntry = await esEntity.getClean(latestKeys);
|
|
1303
1148
|
} catch (ex) {
|
|
1304
|
-
throw new
|
|
1149
|
+
throw new WebinyError(ex.message || "Could not read Elasticsearch latest data.", ex.code || "PUBLISH_LATEST_READ", {
|
|
1305
1150
|
error: ex,
|
|
1306
1151
|
latestKeys: latestKeys,
|
|
1307
1152
|
publishedKeys: publishedKeys
|
|
1308
1153
|
});
|
|
1309
1154
|
}
|
|
1310
1155
|
if (!latestEsEntry) {
|
|
1311
|
-
throw new
|
|
1156
|
+
throw new WebinyError(`Could not publish entry. Could not load latest ("L") record (ES table).`, "PUBLISH_ERROR", {
|
|
1312
1157
|
entry
|
|
1313
1158
|
});
|
|
1314
1159
|
}
|
|
@@ -1321,7 +1166,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1321
1166
|
ids: [entry.id]
|
|
1322
1167
|
});
|
|
1323
1168
|
if (!latestStorageEntry) {
|
|
1324
|
-
throw new
|
|
1169
|
+
throw new WebinyError(`Could not publish entry. Could not load latest ("L") record.`, "PUBLISH_ERROR", {
|
|
1325
1170
|
entry
|
|
1326
1171
|
});
|
|
1327
1172
|
}
|
|
@@ -1335,24 +1180,19 @@ const createEntriesStorageOperations = params => {
|
|
|
1335
1180
|
});
|
|
1336
1181
|
|
|
1337
1182
|
// 1. Update REV# and P records with new data.
|
|
1338
|
-
const entityBatch =
|
|
1339
|
-
entity,
|
|
1183
|
+
const entityBatch = entity.createEntityWriter({
|
|
1340
1184
|
put: [{
|
|
1341
|
-
...storageEntry,
|
|
1342
1185
|
...revisionKeys,
|
|
1343
|
-
|
|
1186
|
+
data: storageEntry
|
|
1344
1187
|
}, {
|
|
1345
|
-
...storageEntry,
|
|
1346
1188
|
...publishedKeys,
|
|
1347
|
-
|
|
1189
|
+
data: storageEntry
|
|
1348
1190
|
}]
|
|
1349
1191
|
});
|
|
1350
|
-
const
|
|
1351
|
-
entity: esEntity
|
|
1352
|
-
});
|
|
1192
|
+
const elasticsearchEntityWriter = esEntity.createEntityWriter();
|
|
1353
1193
|
const {
|
|
1354
1194
|
index: esIndex
|
|
1355
|
-
} =
|
|
1195
|
+
} = configurations.es({
|
|
1356
1196
|
model
|
|
1357
1197
|
});
|
|
1358
1198
|
|
|
@@ -1363,8 +1203,8 @@ const createEntriesStorageOperations = params => {
|
|
|
1363
1203
|
if (publishingLatestRevision) {
|
|
1364
1204
|
// 2.1 If we're publishing the latest revision, we first need to update the L record.
|
|
1365
1205
|
entityBatch.put({
|
|
1366
|
-
...
|
|
1367
|
-
|
|
1206
|
+
...latestKeys,
|
|
1207
|
+
data: storageEntry
|
|
1368
1208
|
});
|
|
1369
1209
|
|
|
1370
1210
|
// 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.
|
|
@@ -1377,12 +1217,13 @@ const createEntriesStorageOperations = params => {
|
|
|
1377
1217
|
/**
|
|
1378
1218
|
* Update currently published entry (unpublish it)
|
|
1379
1219
|
*/
|
|
1220
|
+
const publishedStorageEntryKeys = createEntryRevisionKeys(publishedStorageEntry);
|
|
1380
1221
|
entityBatch.put({
|
|
1381
|
-
...
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1222
|
+
...publishedStorageEntryKeys,
|
|
1223
|
+
data: {
|
|
1224
|
+
...publishedStorageEntry,
|
|
1225
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
1226
|
+
}
|
|
1386
1227
|
});
|
|
1387
1228
|
}
|
|
1388
1229
|
}
|
|
@@ -1390,32 +1231,30 @@ const createEntriesStorageOperations = params => {
|
|
|
1390
1231
|
// 2.3 If the published revision is not the latest one, the situation is a bit
|
|
1391
1232
|
// more complex. We first need to update the L and REV# records with the new
|
|
1392
1233
|
// values of *only entry-level* meta fields.
|
|
1393
|
-
const updatedEntryLevelMetaFields =
|
|
1234
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
1394
1235
|
|
|
1395
1236
|
// 2.4 Update L record. Apart from updating the entry-level meta fields, we also need
|
|
1396
1237
|
// to change the status from "published" to "unpublished" (if the status is set to "published").
|
|
1397
1238
|
let latestRevisionStatus = latestStorageEntry.status;
|
|
1398
|
-
if (latestRevisionStatus ===
|
|
1399
|
-
latestRevisionStatus =
|
|
1239
|
+
if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {
|
|
1240
|
+
latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
|
|
1400
1241
|
}
|
|
1401
1242
|
const latestStorageEntryFields = {
|
|
1402
1243
|
...latestStorageEntry,
|
|
1403
1244
|
...updatedEntryLevelMetaFields,
|
|
1404
1245
|
status: latestRevisionStatus
|
|
1405
1246
|
};
|
|
1247
|
+
const latestStorageEntryLatestKeys = createEntryLatestKeys(latestStorageEntry);
|
|
1406
1248
|
entityBatch.put({
|
|
1407
|
-
...
|
|
1408
|
-
|
|
1409
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
1410
|
-
TYPE: (0, _recordType.createLatestRecordType)()
|
|
1249
|
+
...latestStorageEntryLatestKeys,
|
|
1250
|
+
data: latestStorageEntryFields
|
|
1411
1251
|
});
|
|
1412
1252
|
|
|
1413
1253
|
// 2.5 Update REV# record.
|
|
1254
|
+
const latestStorageEntryRevisionKeys = createEntryRevisionKeys(latestStorageEntry);
|
|
1414
1255
|
entityBatch.put({
|
|
1415
|
-
...
|
|
1416
|
-
|
|
1417
|
-
SK: (0, _keys.createRevisionSortKey)(latestStorageEntry),
|
|
1418
|
-
TYPE: (0, _recordType.createRecordType)()
|
|
1256
|
+
...latestStorageEntryRevisionKeys,
|
|
1257
|
+
data: latestStorageEntryFields
|
|
1419
1258
|
});
|
|
1420
1259
|
|
|
1421
1260
|
// 2.6 Additionally, if we have a previously published entry, we need to mark it as unpublished.
|
|
@@ -1426,12 +1265,13 @@ const createEntriesStorageOperations = params => {
|
|
|
1426
1265
|
const isRepublishing = publishedStorageEntry.id === entry.id;
|
|
1427
1266
|
const publishedRevisionDifferentFromLatest = publishedRevisionId !== latestStorageEntry.id;
|
|
1428
1267
|
if (!isRepublishing && publishedRevisionDifferentFromLatest) {
|
|
1268
|
+
const publishedStorageEntryRevisionKeys = createEntryRevisionKeys(publishedStorageEntry);
|
|
1429
1269
|
entityBatch.put({
|
|
1430
|
-
...
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1270
|
+
...publishedStorageEntryRevisionKeys,
|
|
1271
|
+
data: {
|
|
1272
|
+
...publishedStorageEntry,
|
|
1273
|
+
status: CONTENT_ENTRY_STATUS.UNPUBLISHED
|
|
1274
|
+
}
|
|
1435
1275
|
});
|
|
1436
1276
|
}
|
|
1437
1277
|
}
|
|
@@ -1443,7 +1283,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1443
1283
|
* Update the published revision entry in ES.
|
|
1444
1284
|
*/
|
|
1445
1285
|
const esPublishedData = await transformer.getElasticsearchPublishedEntryData();
|
|
1446
|
-
|
|
1286
|
+
elasticsearchEntityWriter.put({
|
|
1447
1287
|
...publishedKeys,
|
|
1448
1288
|
index: esIndex,
|
|
1449
1289
|
data: esPublishedData
|
|
@@ -1455,47 +1295,44 @@ const createEntriesStorageOperations = params => {
|
|
|
1455
1295
|
* No need to transform it for the storage because it was fetched
|
|
1456
1296
|
* directly from the Elasticsearch table, where it sits transformed.
|
|
1457
1297
|
*/
|
|
1458
|
-
const latestEsEntryDataDecompressed = await
|
|
1298
|
+
const latestEsEntryDataDecompressed = await decompress(plugins, latestEsEntry.data);
|
|
1459
1299
|
if (publishingLatestRevision) {
|
|
1460
|
-
const updatedMetaFields =
|
|
1461
|
-
const latestTransformer =
|
|
1300
|
+
const updatedMetaFields = pickEntryMetaFields(entry);
|
|
1301
|
+
const latestTransformer = createTransformer({
|
|
1462
1302
|
plugins,
|
|
1463
1303
|
model,
|
|
1464
1304
|
transformedToIndex: {
|
|
1465
1305
|
...latestEsEntryDataDecompressed,
|
|
1466
|
-
status:
|
|
1306
|
+
status: CONTENT_ENTRY_STATUS.PUBLISHED,
|
|
1467
1307
|
locked: true,
|
|
1468
1308
|
...updatedMetaFields
|
|
1469
1309
|
}
|
|
1470
1310
|
});
|
|
1471
|
-
|
|
1311
|
+
const esEntryLatestKeys = createEntryLatestKeys(latestEsEntryDataDecompressed);
|
|
1312
|
+
elasticsearchEntityWriter.put({
|
|
1472
1313
|
index: esIndex,
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
data: await latestTransformer.getElasticsearchLatestEntryData()
|
|
1314
|
+
data: await latestTransformer.getElasticsearchLatestEntryData(),
|
|
1315
|
+
...esEntryLatestKeys
|
|
1476
1316
|
});
|
|
1477
1317
|
} else {
|
|
1478
|
-
const updatedEntryLevelMetaFields =
|
|
1318
|
+
const updatedEntryLevelMetaFields = pickEntryMetaFields(entry, isEntryLevelEntryMetaField);
|
|
1479
1319
|
|
|
1480
1320
|
/**
|
|
1481
1321
|
* Update the Elasticsearch table to propagate changes to the Elasticsearch.
|
|
1482
1322
|
*/
|
|
1483
|
-
const latestEsEntry = await
|
|
1484
|
-
entity: esEntity,
|
|
1485
|
-
keys: latestKeys
|
|
1486
|
-
});
|
|
1323
|
+
const latestEsEntry = await esEntity.getClean(latestKeys);
|
|
1487
1324
|
if (latestEsEntry) {
|
|
1488
|
-
const latestEsEntryDataDecompressed = await
|
|
1325
|
+
const latestEsEntryDataDecompressed = await decompress(plugins, latestEsEntry.data);
|
|
1489
1326
|
let latestRevisionStatus = latestEsEntryDataDecompressed.status;
|
|
1490
|
-
if (latestRevisionStatus ===
|
|
1491
|
-
latestRevisionStatus =
|
|
1327
|
+
if (latestRevisionStatus === CONTENT_ENTRY_STATUS.PUBLISHED) {
|
|
1328
|
+
latestRevisionStatus = CONTENT_ENTRY_STATUS.UNPUBLISHED;
|
|
1492
1329
|
}
|
|
1493
|
-
const updatedLatestEntry = await
|
|
1330
|
+
const updatedLatestEntry = await compress(plugins, {
|
|
1494
1331
|
...latestEsEntryDataDecompressed,
|
|
1495
1332
|
...updatedEntryLevelMetaFields,
|
|
1496
1333
|
status: latestRevisionStatus
|
|
1497
1334
|
});
|
|
1498
|
-
|
|
1335
|
+
elasticsearchEntityWriter.put({
|
|
1499
1336
|
...latestKeys,
|
|
1500
1337
|
index: esIndex,
|
|
1501
1338
|
data: updatedLatestEntry
|
|
@@ -1512,7 +1349,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1512
1349
|
model
|
|
1513
1350
|
});
|
|
1514
1351
|
} catch (ex) {
|
|
1515
|
-
throw new
|
|
1352
|
+
throw new WebinyError(ex.message || "Could not store publish entry records in DynamoDB table.", ex.code || "PUBLISH_ERROR", {
|
|
1516
1353
|
error: ex,
|
|
1517
1354
|
entry,
|
|
1518
1355
|
latestStorageEntry,
|
|
@@ -1523,9 +1360,9 @@ const createEntriesStorageOperations = params => {
|
|
|
1523
1360
|
* And Elasticsearch table batch.
|
|
1524
1361
|
*/
|
|
1525
1362
|
try {
|
|
1526
|
-
await
|
|
1363
|
+
await elasticsearchEntityWriter.execute();
|
|
1527
1364
|
} catch (ex) {
|
|
1528
|
-
throw new
|
|
1365
|
+
throw new WebinyError(ex.message || "Could not store publish entry records in DynamoDB Elasticsearch table.", ex.code || "PUBLISH_ES_ERROR", {
|
|
1529
1366
|
error: ex,
|
|
1530
1367
|
entry,
|
|
1531
1368
|
latestStorageEntry,
|
|
@@ -1540,7 +1377,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1540
1377
|
storageEntry: initialStorageEntry
|
|
1541
1378
|
} = params;
|
|
1542
1379
|
const model = getStorageOperationsModel(initialModel);
|
|
1543
|
-
const transformer =
|
|
1380
|
+
const transformer = createTransformer({
|
|
1544
1381
|
plugins,
|
|
1545
1382
|
model,
|
|
1546
1383
|
entry: initialEntry,
|
|
@@ -1558,29 +1395,25 @@ const createEntriesStorageOperations = params => {
|
|
|
1558
1395
|
model,
|
|
1559
1396
|
ids: [entry.id]
|
|
1560
1397
|
});
|
|
1561
|
-
const partitionKey =
|
|
1398
|
+
const partitionKey = createPartitionKey({
|
|
1562
1399
|
id: entry.id,
|
|
1563
|
-
locale: model.locale,
|
|
1564
1400
|
tenant: model.tenant
|
|
1565
1401
|
});
|
|
1566
|
-
const
|
|
1567
|
-
|
|
1402
|
+
const entryRevisionKeys = createEntryRevisionKeys(entry);
|
|
1403
|
+
const entityBatch = entity.createEntityWriter({
|
|
1568
1404
|
put: [{
|
|
1569
|
-
...
|
|
1570
|
-
|
|
1571
|
-
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
1572
|
-
TYPE: (0, _recordType.createRecordType)()
|
|
1405
|
+
...entryRevisionKeys,
|
|
1406
|
+
data: storageEntry
|
|
1573
1407
|
}],
|
|
1574
1408
|
delete: [{
|
|
1575
1409
|
PK: partitionKey,
|
|
1576
|
-
SK:
|
|
1410
|
+
SK: createPublishedSortKey()
|
|
1577
1411
|
}]
|
|
1578
1412
|
});
|
|
1579
|
-
const elasticsearchEntityBatch =
|
|
1580
|
-
entity: esEntity,
|
|
1413
|
+
const elasticsearchEntityBatch = esEntity.createEntityWriter({
|
|
1581
1414
|
delete: [{
|
|
1582
1415
|
PK: partitionKey,
|
|
1583
|
-
SK:
|
|
1416
|
+
SK: createPublishedSortKey()
|
|
1584
1417
|
}]
|
|
1585
1418
|
});
|
|
1586
1419
|
|
|
@@ -1590,21 +1423,19 @@ const createEntriesStorageOperations = params => {
|
|
|
1590
1423
|
if (latestStorageEntry?.id === entry.id) {
|
|
1591
1424
|
const {
|
|
1592
1425
|
index
|
|
1593
|
-
} =
|
|
1426
|
+
} = configurations.es({
|
|
1594
1427
|
model
|
|
1595
1428
|
});
|
|
1429
|
+
const entryLatestKeys = createEntryLatestKeys(storageEntry);
|
|
1596
1430
|
entityBatch.put({
|
|
1597
|
-
...
|
|
1598
|
-
|
|
1599
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
1600
|
-
TYPE: (0, _recordType.createLatestRecordType)()
|
|
1431
|
+
...entryLatestKeys,
|
|
1432
|
+
data: storageEntry
|
|
1601
1433
|
});
|
|
1602
1434
|
const esLatestData = await transformer.getElasticsearchLatestEntryData();
|
|
1603
1435
|
elasticsearchEntityBatch.put({
|
|
1604
|
-
PK: partitionKey,
|
|
1605
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
1606
1436
|
index,
|
|
1607
|
-
data: esLatestData
|
|
1437
|
+
data: esLatestData,
|
|
1438
|
+
...entryLatestKeys
|
|
1608
1439
|
});
|
|
1609
1440
|
}
|
|
1610
1441
|
|
|
@@ -1617,7 +1448,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1617
1448
|
model
|
|
1618
1449
|
});
|
|
1619
1450
|
} catch (ex) {
|
|
1620
|
-
throw new
|
|
1451
|
+
throw new WebinyError(ex.message || "Could not store unpublished entry records in DynamoDB table.", ex.code || "UNPUBLISH_ERROR", {
|
|
1621
1452
|
entry,
|
|
1622
1453
|
storageEntry
|
|
1623
1454
|
});
|
|
@@ -1628,7 +1459,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1628
1459
|
try {
|
|
1629
1460
|
await elasticsearchEntityBatch.execute();
|
|
1630
1461
|
} catch (ex) {
|
|
1631
|
-
throw new
|
|
1462
|
+
throw new WebinyError(ex.message || "Could not store unpublished entry records in DynamoDB Elasticsearch table.", ex.code || "UNPUBLISH_ERROR", {
|
|
1632
1463
|
entry,
|
|
1633
1464
|
storageEntry
|
|
1634
1465
|
});
|
|
@@ -1644,7 +1475,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1644
1475
|
if (!entry) {
|
|
1645
1476
|
return null;
|
|
1646
1477
|
}
|
|
1647
|
-
return
|
|
1478
|
+
return convertEntryKeysFromStorage({
|
|
1648
1479
|
model,
|
|
1649
1480
|
entry
|
|
1650
1481
|
});
|
|
@@ -1658,7 +1489,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1658
1489
|
if (!entry) {
|
|
1659
1490
|
return null;
|
|
1660
1491
|
}
|
|
1661
|
-
return
|
|
1492
|
+
return convertEntryKeysFromStorage({
|
|
1662
1493
|
model,
|
|
1663
1494
|
entry
|
|
1664
1495
|
});
|
|
@@ -1672,7 +1503,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1672
1503
|
if (!entry) {
|
|
1673
1504
|
return null;
|
|
1674
1505
|
}
|
|
1675
|
-
return
|
|
1506
|
+
return convertEntryKeysFromStorage({
|
|
1676
1507
|
model,
|
|
1677
1508
|
entry
|
|
1678
1509
|
});
|
|
@@ -1684,7 +1515,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1684
1515
|
ids: [params.id]
|
|
1685
1516
|
});
|
|
1686
1517
|
return entries.map(entry => {
|
|
1687
|
-
return
|
|
1518
|
+
return convertEntryKeysFromStorage({
|
|
1688
1519
|
model,
|
|
1689
1520
|
entry
|
|
1690
1521
|
});
|
|
@@ -1697,7 +1528,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1697
1528
|
ids: params.ids
|
|
1698
1529
|
});
|
|
1699
1530
|
return entries.map(entry => {
|
|
1700
|
-
return
|
|
1531
|
+
return convertEntryKeysFromStorage({
|
|
1701
1532
|
model,
|
|
1702
1533
|
entry
|
|
1703
1534
|
});
|
|
@@ -1710,7 +1541,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1710
1541
|
ids: params.ids
|
|
1711
1542
|
});
|
|
1712
1543
|
return entries.map(entry => {
|
|
1713
|
-
return
|
|
1544
|
+
return convertEntryKeysFromStorage({
|
|
1714
1545
|
model,
|
|
1715
1546
|
entry
|
|
1716
1547
|
});
|
|
@@ -1723,7 +1554,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1723
1554
|
ids: params.ids
|
|
1724
1555
|
});
|
|
1725
1556
|
return entries.map(entry => {
|
|
1726
|
-
return
|
|
1557
|
+
return convertEntryKeysFromStorage({
|
|
1727
1558
|
model,
|
|
1728
1559
|
entry
|
|
1729
1560
|
});
|
|
@@ -1732,51 +1563,44 @@ const createEntriesStorageOperations = params => {
|
|
|
1732
1563
|
const getPreviousRevision = async (initialModel, params) => {
|
|
1733
1564
|
const model = getStorageOperationsModel(initialModel);
|
|
1734
1565
|
const {
|
|
1735
|
-
tenant
|
|
1736
|
-
locale
|
|
1566
|
+
tenant
|
|
1737
1567
|
} = model;
|
|
1738
1568
|
const {
|
|
1739
1569
|
entryId,
|
|
1740
1570
|
version
|
|
1741
1571
|
} = params;
|
|
1742
|
-
const
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
options: {
|
|
1750
|
-
lt: `REV#${(0, _utils.zeroPad)(version)}`,
|
|
1751
|
-
/**
|
|
1752
|
-
* We need to have extra checks because DynamoDB will return published or latest record if there is no REV# record.
|
|
1753
|
-
*/
|
|
1754
|
-
filters: [{
|
|
1755
|
-
attr: "TYPE",
|
|
1756
|
-
eq: (0, _recordType.createRecordType)()
|
|
1757
|
-
}, {
|
|
1758
|
-
attr: "version",
|
|
1759
|
-
lt: version
|
|
1760
|
-
}],
|
|
1761
|
-
reverse: true
|
|
1762
|
-
}
|
|
1572
|
+
const partitionKey = createPartitionKey({
|
|
1573
|
+
tenant,
|
|
1574
|
+
id: entryId
|
|
1575
|
+
});
|
|
1576
|
+
const options = {
|
|
1577
|
+
beginsWith: `REV#`,
|
|
1578
|
+
reverse: true
|
|
1763
1579
|
};
|
|
1764
1580
|
try {
|
|
1765
|
-
const
|
|
1766
|
-
|
|
1581
|
+
const unfilteredEntries = (await entity.queryAll({
|
|
1582
|
+
partitionKey,
|
|
1583
|
+
options
|
|
1584
|
+
})).map(item => {
|
|
1585
|
+
return item.data;
|
|
1586
|
+
});
|
|
1587
|
+
const entries = unfilteredEntries.filter(item => {
|
|
1588
|
+
return item.version < version;
|
|
1589
|
+
});
|
|
1590
|
+
const entry = entries[0];
|
|
1767
1591
|
if (!entry) {
|
|
1768
1592
|
return null;
|
|
1769
1593
|
}
|
|
1770
|
-
return
|
|
1594
|
+
return convertEntryKeysFromStorage({
|
|
1771
1595
|
entry,
|
|
1772
1596
|
model
|
|
1773
1597
|
});
|
|
1774
1598
|
} catch (ex) {
|
|
1775
|
-
throw new
|
|
1599
|
+
throw new WebinyError(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", {
|
|
1776
1600
|
...params,
|
|
1777
1601
|
error: ex,
|
|
1778
|
-
partitionKey
|
|
1779
|
-
options
|
|
1602
|
+
partitionKey,
|
|
1603
|
+
options,
|
|
1780
1604
|
model
|
|
1781
1605
|
});
|
|
1782
1606
|
}
|
|
@@ -1788,10 +1612,10 @@ const createEntriesStorageOperations = params => {
|
|
|
1788
1612
|
} = params;
|
|
1789
1613
|
const {
|
|
1790
1614
|
index
|
|
1791
|
-
} =
|
|
1615
|
+
} = configurations.es({
|
|
1792
1616
|
model
|
|
1793
1617
|
});
|
|
1794
|
-
const initialBody =
|
|
1618
|
+
const initialBody = createElasticsearchBody({
|
|
1795
1619
|
model,
|
|
1796
1620
|
params: {
|
|
1797
1621
|
limit: 1,
|
|
@@ -1801,7 +1625,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1801
1625
|
});
|
|
1802
1626
|
const field = model.fields.find(f => f.fieldId === fieldId);
|
|
1803
1627
|
if (!field) {
|
|
1804
|
-
throw new
|
|
1628
|
+
throw new WebinyError(`Could not find field with given "fieldId" value.`, "FIELD_NOT_FOUND", {
|
|
1805
1629
|
fieldId
|
|
1806
1630
|
});
|
|
1807
1631
|
}
|
|
@@ -1827,15 +1651,10 @@ const createEntriesStorageOperations = params => {
|
|
|
1827
1651
|
body
|
|
1828
1652
|
});
|
|
1829
1653
|
} catch (error) {
|
|
1830
|
-
if (
|
|
1831
|
-
(0, _logIgnoredEsResponseError.logIgnoredEsResponseError)({
|
|
1832
|
-
error,
|
|
1833
|
-
model,
|
|
1834
|
-
indexName: index
|
|
1835
|
-
});
|
|
1654
|
+
if (shouldIgnoreEsResponseError(error)) {
|
|
1836
1655
|
return [];
|
|
1837
1656
|
}
|
|
1838
|
-
throw new
|
|
1657
|
+
throw new WebinyError(error.message || "Error in the Elasticsearch query.", error.code || "OPENSEARCH_ERROR", {
|
|
1839
1658
|
error,
|
|
1840
1659
|
index,
|
|
1841
1660
|
model,
|
|
@@ -1876,6 +1695,5 @@ const createEntriesStorageOperations = params => {
|
|
|
1876
1695
|
dataLoaders
|
|
1877
1696
|
};
|
|
1878
1697
|
};
|
|
1879
|
-
exports.createEntriesStorageOperations = createEntriesStorageOperations;
|
|
1880
1698
|
|
|
1881
1699
|
//# sourceMappingURL=index.js.map
|