@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.3386f66516
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/configurations.d.ts +2 -2
- package/configurations.js +18 -7
- package/configurations.js.map +1 -0
- package/definitions/entry.d.ts +2 -2
- package/definitions/entry.js +6 -7
- package/definitions/entry.js.map +1 -0
- package/definitions/entryElasticsearch.d.ts +2 -2
- package/definitions/entryElasticsearch.js +3 -7
- package/definitions/entryElasticsearch.js.map +1 -0
- package/definitions/group.d.ts +2 -2
- package/definitions/group.js +3 -7
- package/definitions/group.js.map +1 -0
- package/definitions/model.d.ts +2 -2
- package/definitions/model.js +8 -7
- package/definitions/model.js.map +1 -0
- package/definitions/settings.d.ts +2 -2
- package/definitions/settings.js +3 -7
- package/definitions/settings.js.map +1 -0
- package/definitions/system.d.ts +2 -2
- package/definitions/system.js +3 -7
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +2 -2
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.d.ts +2 -2
- package/definitions/tableElasticsearch.js.map +1 -0
- package/dynamoDb/index.d.ts +1 -1
- package/dynamoDb/index.js +4 -6
- package/dynamoDb/index.js.map +1 -0
- package/dynamoDb/storage/date.d.ts +3 -3
- package/dynamoDb/storage/date.js +80 -46
- package/dynamoDb/storage/date.js.map +1 -0
- package/dynamoDb/storage/longText.d.ts +7 -4
- package/dynamoDb/storage/longText.js +79 -54
- package/dynamoDb/storage/longText.js.map +1 -0
- package/dynamoDb/storage/richText.d.ts +2 -3
- package/dynamoDb/storage/richText.js +85 -67
- package/dynamoDb/storage/richText.js.map +1 -0
- package/elasticsearch/createElasticsearchIndex.d.ts +9 -0
- package/elasticsearch/createElasticsearchIndex.js +60 -0
- package/elasticsearch/createElasticsearchIndex.js.map +1 -0
- package/elasticsearch/deleteElasticsearchIndex.d.ts +8 -0
- package/elasticsearch/deleteElasticsearchIndex.js +43 -0
- package/elasticsearch/deleteElasticsearchIndex.js.map +1 -0
- package/elasticsearch/index.d.ts +1 -1
- package/elasticsearch/index.js +1 -1
- package/elasticsearch/index.js.map +1 -0
- package/elasticsearch/indexing/dateTimeIndexing.js +15 -1
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
- package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
- package/elasticsearch/indexing/index.js +1 -1
- package/elasticsearch/indexing/index.js.map +1 -0
- package/elasticsearch/indexing/longTextIndexing.d.ts +4 -0
- package/elasticsearch/indexing/longTextIndexing.js +20 -4
- package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
- package/elasticsearch/indexing/numberIndexing.js.map +1 -0
- package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
- package/elasticsearch/indexing/objectIndexing.js +32 -9
- package/elasticsearch/indexing/objectIndexing.js.map +1 -0
- package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
- package/elasticsearch/indices/base.d.ts +2 -0
- package/elasticsearch/indices/base.js +15 -0
- package/elasticsearch/indices/base.js.map +1 -0
- package/elasticsearch/indices/index.d.ts +1 -0
- package/elasticsearch/indices/index.js +16 -0
- package/elasticsearch/indices/index.js.map +1 -0
- package/elasticsearch/indices/japanese.d.ts +2 -0
- package/elasticsearch/indices/japanese.js +16 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/elasticsearch/search/index.d.ts +2 -2
- package/elasticsearch/search/index.js +3 -5
- package/elasticsearch/search/index.js.map +1 -0
- package/elasticsearch/search/refSearch.d.ts +2 -3
- package/elasticsearch/search/refSearch.js +27 -16
- package/elasticsearch/search/refSearch.js.map +1 -0
- package/elasticsearch/search/timeSearch.d.ts +2 -3
- package/elasticsearch/search/timeSearch.js +22 -14
- package/elasticsearch/search/timeSearch.js.map +1 -0
- package/helpers/entryIndexHelpers.js +33 -18
- package/helpers/entryIndexHelpers.js.map +1 -0
- package/helpers/index.d.ts +0 -1
- package/helpers/index.js +0 -13
- package/helpers/index.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +132 -34
- package/index.js.map +1 -0
- package/operations/entry/dataLoaders.d.ts +6 -2
- package/operations/entry/dataLoaders.js +31 -13
- package/operations/entry/dataLoaders.js.map +1 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.d.ts +18 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +34 -0
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -0
- package/operations/entry/elasticsearch/body.d.ts +13 -0
- package/operations/entry/elasticsearch/body.js +162 -0
- package/operations/entry/elasticsearch/body.js.map +1 -0
- package/operations/entry/elasticsearch/fields.d.ts +9 -0
- package/operations/entry/elasticsearch/fields.js +248 -0
- package/operations/entry/elasticsearch/fields.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +8 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +66 -0
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/exec.d.ts +17 -0
- package/operations/entry/elasticsearch/filtering/exec.js +215 -0
- package/operations/entry/elasticsearch/filtering/exec.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/index.d.ts +1 -0
- package/operations/entry/elasticsearch/filtering/index.js +18 -0
- package/operations/entry/elasticsearch/filtering/index.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/path.d.ts +15 -0
- package/operations/entry/elasticsearch/filtering/path.js +52 -0
- package/operations/entry/elasticsearch/filtering/path.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +35 -0
- package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.d.ts +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.js +18 -0
- package/operations/entry/elasticsearch/filtering/plugins/index.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js +78 -0
- package/operations/entry/elasticsearch/filtering/plugins/objectFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js +58 -0
- package/operations/entry/elasticsearch/filtering/plugins/refFilterPlugin.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/populated.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/populated.js +30 -0
- package/operations/entry/elasticsearch/filtering/populated.js.map +1 -0
- package/operations/entry/elasticsearch/filtering/values.d.ts +2 -0
- package/operations/entry/elasticsearch/filtering/values.js +28 -0
- package/operations/entry/elasticsearch/filtering/values.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearch.d.ts +9 -0
- package/operations/entry/elasticsearch/fullTextSearch.js +34 -0
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.d.ts +8 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.js +52 -0
- package/operations/entry/elasticsearch/fullTextSearchFields.js.map +1 -0
- package/operations/entry/elasticsearch/initialQuery.d.ts +17 -0
- package/operations/entry/elasticsearch/initialQuery.js +117 -0
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -0
- package/operations/entry/elasticsearch/keyword.d.ts +2 -0
- package/operations/entry/elasticsearch/keyword.js +38 -0
- package/operations/entry/elasticsearch/keyword.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/bodyModifier.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/operator.d.ts +8 -0
- package/operations/entry/elasticsearch/plugins/operator.js +45 -0
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/queryModifier.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/search.d.ts +7 -0
- package/{helpers/searchPluginsList.js → operations/entry/elasticsearch/plugins/search.js} +9 -5
- package/operations/entry/elasticsearch/plugins/search.js.map +1 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.d.ts +9 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js +19 -0
- package/operations/entry/elasticsearch/plugins/sortModifier.js.map +1 -0
- package/operations/entry/elasticsearch/sort.d.ts +12 -0
- package/operations/entry/elasticsearch/sort.js +97 -0
- package/operations/entry/elasticsearch/sort.js.map +1 -0
- package/operations/entry/elasticsearch/transformValueForSearch.d.ts +16 -0
- package/operations/entry/elasticsearch/transformValueForSearch.js +34 -0
- package/operations/entry/elasticsearch/transformValueForSearch.js.map +1 -0
- package/operations/entry/elasticsearch/types.d.ts +41 -0
- package/operations/entry/elasticsearch/types.js +5 -0
- package/operations/entry/elasticsearch/types.js.map +1 -0
- package/operations/entry/index.d.ts +2 -4
- package/operations/entry/index.js +473 -374
- package/operations/entry/index.js.map +1 -0
- package/operations/entry/keys.js.map +1 -0
- package/operations/entry/recordType.d.ts +3 -0
- package/operations/entry/recordType.js +24 -0
- package/operations/entry/recordType.js.map +1 -0
- package/operations/group/index.d.ts +2 -2
- package/operations/group/index.js +8 -15
- package/operations/group/index.js.map +1 -0
- package/operations/model/index.d.ts +2 -2
- package/operations/model/index.js +38 -39
- package/operations/model/index.js.map +1 -0
- package/operations/settings/index.d.ts +2 -2
- package/operations/settings/index.js +7 -13
- package/operations/settings/index.js.map +1 -0
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js +5 -11
- package/operations/system/index.js.map +1 -0
- package/package.json +24 -29
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +7 -3
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js +11 -5
- package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +3 -3
- package/plugins/CmsEntryElasticsearchFieldPlugin.js +3 -3
- package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js +17 -0
- package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +30 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +43 -0
- package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +4 -3
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js +11 -5
- package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +4 -3
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js +11 -5
- package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/CmsEntryFilterPlugin.d.ts +49 -0
- package/plugins/CmsEntryFilterPlugin.js +31 -0
- package/plugins/CmsEntryFilterPlugin.js.map +1 -0
- package/plugins/index.d.ts +6 -0
- package/plugins/index.js +83 -0
- package/plugins/index.js.map +1 -0
- package/types.d.ts +7 -34
- package/types.js +0 -13
- package/types.js.map +1 -0
- package/helpers/createElasticsearchQueryBody.d.ts +0 -11
- package/helpers/createElasticsearchQueryBody.js +0 -375
- package/helpers/fields.d.ts +0 -77
- package/helpers/fields.js +0 -174
- package/helpers/operatorPluginsList.d.ts +0 -7
- package/helpers/operatorPluginsList.js +0 -30
- package/helpers/searchPluginsList.d.ts +0 -6
- package/helpers/transformValueForSearch.d.ts +0 -9
- package/helpers/transformValueForSearch.js +0 -26
- package/operations/entry/elasticsearchFields.d.ts +0 -2
- package/operations/entry/elasticsearchFields.js +0 -32
- package/operations/entry/fields.d.ts +0 -3
- package/operations/entry/fields.js +0 -60
- package/operations/system/createElasticsearchTemplate.d.ts +0 -5
- package/operations/system/createElasticsearchTemplate.js +0 -62
- package/upgrades/index.d.ts +0 -2
- package/upgrades/index.js +0 -16
- package/upgrades/utils.d.ts +0 -1
- package/upgrades/utils.js +0 -16
- package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
- package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
- package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
- package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
- package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
- package/upgrades/v5.0.0/entryValueFixer.js +0 -124
- package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
- package/upgrades/v5.0.0/fieldFinder.js +0 -42
- package/upgrades/v5.0.0/helpers.d.ts +0 -4
- package/upgrades/v5.0.0/helpers.js +0 -57
- package/upgrades/v5.0.0/index.d.ts +0 -4
- package/upgrades/v5.0.0/index.js +0 -232
- package/upgrades/v5.8.0/index.d.ts +0 -4
- package/upgrades/v5.8.0/index.js +0 -426
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.createEntriesStorageOperations = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _helpers = require("../../helpers");
|
|
15
|
-
|
|
16
|
-
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
12
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
17
13
|
|
|
18
14
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
19
15
|
|
|
20
|
-
var
|
|
16
|
+
var _types = require("@webiny/api-headless-cms/types");
|
|
21
17
|
|
|
22
|
-
var
|
|
18
|
+
var _helpers = require("../../helpers");
|
|
23
19
|
|
|
24
|
-
var
|
|
20
|
+
var _configurations = require("../../configurations");
|
|
25
21
|
|
|
26
22
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
27
23
|
|
|
@@ -31,9 +27,7 @@ var _keys = require("./keys");
|
|
|
31
27
|
|
|
32
28
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
33
29
|
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
var _cursors = require("@webiny/api-elasticsearch/cursors");
|
|
30
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
37
31
|
|
|
38
32
|
var _get = require("@webiny/db-dynamodb/utils/get");
|
|
39
33
|
|
|
@@ -41,49 +35,63 @@ var _utils = require("@webiny/utils");
|
|
|
41
35
|
|
|
42
36
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
38
|
+
var _body = require("./elasticsearch/body");
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
return "cms.entry";
|
|
50
|
-
};
|
|
40
|
+
var _recordType = require("./recordType");
|
|
51
41
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return `${createType()}.p`;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
exports.createPublishedType = createPublishedType;
|
|
63
|
-
|
|
64
|
-
const getEntryData = entry => {
|
|
65
|
-
return _objectSpread(_objectSpread({}, (0, _lodash2.default)(entry, ["PK", "SK", "published", "latest"])), {}, {
|
|
66
|
-
TYPE: createType(),
|
|
67
|
-
__type: createType()
|
|
68
|
-
});
|
|
42
|
+
const getEntryData = input => {
|
|
43
|
+
const output = (0, _objectSpread2.default)({}, input);
|
|
44
|
+
delete output["PK"];
|
|
45
|
+
delete output["SK"];
|
|
46
|
+
delete output["published"];
|
|
47
|
+
delete output["latest"];
|
|
48
|
+
return output;
|
|
69
49
|
};
|
|
70
50
|
|
|
71
51
|
const getESLatestEntryData = async (plugins, entry) => {
|
|
72
|
-
return (0,
|
|
52
|
+
return (0, _apiElasticsearch.compress)(plugins, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getEntryData(entry)), {}, {
|
|
73
53
|
latest: true,
|
|
74
|
-
TYPE:
|
|
75
|
-
__type:
|
|
54
|
+
TYPE: (0, _recordType.createLatestRecordType)(),
|
|
55
|
+
__type: (0, _recordType.createLatestRecordType)()
|
|
76
56
|
}));
|
|
77
57
|
};
|
|
78
58
|
|
|
79
59
|
const getESPublishedEntryData = async (plugins, entry) => {
|
|
80
|
-
return (0,
|
|
60
|
+
return (0, _apiElasticsearch.compress)(plugins, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, getEntryData(entry)), {}, {
|
|
81
61
|
published: true,
|
|
82
|
-
TYPE:
|
|
83
|
-
__type:
|
|
62
|
+
TYPE: (0, _recordType.createPublishedRecordType)(),
|
|
63
|
+
__type: (0, _recordType.createPublishedRecordType)()
|
|
84
64
|
}));
|
|
85
65
|
};
|
|
86
66
|
|
|
67
|
+
const convertEntryKeysToStorage = params => {
|
|
68
|
+
const {
|
|
69
|
+
model,
|
|
70
|
+
entry
|
|
71
|
+
} = params;
|
|
72
|
+
const values = model.convertValueKeyToStorage({
|
|
73
|
+
fields: model.fields,
|
|
74
|
+
values: entry.values
|
|
75
|
+
});
|
|
76
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
|
|
77
|
+
values
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const convertEntryKeysFromStorage = params => {
|
|
82
|
+
const {
|
|
83
|
+
model,
|
|
84
|
+
entry
|
|
85
|
+
} = params;
|
|
86
|
+
const values = model.convertValueKeyFromStorage({
|
|
87
|
+
fields: model.fields,
|
|
88
|
+
values: entry.values
|
|
89
|
+
});
|
|
90
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
|
|
91
|
+
values
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
87
95
|
const createEntriesStorageOperations = params => {
|
|
88
96
|
const {
|
|
89
97
|
entity,
|
|
@@ -97,37 +105,80 @@ const createEntriesStorageOperations = params => {
|
|
|
97
105
|
|
|
98
106
|
const create = async (model, params) => {
|
|
99
107
|
const {
|
|
100
|
-
entry,
|
|
101
|
-
storageEntry
|
|
108
|
+
entry: initialEntry,
|
|
109
|
+
storageEntry: initialStorageEntry
|
|
102
110
|
} = params;
|
|
111
|
+
const isPublished = initialEntry.status === "published";
|
|
112
|
+
const locked = isPublished ? true : initialEntry.locked;
|
|
113
|
+
const entry = convertEntryKeysToStorage({
|
|
114
|
+
model,
|
|
115
|
+
entry: initialEntry
|
|
116
|
+
});
|
|
117
|
+
const storageEntry = convertEntryKeysToStorage({
|
|
118
|
+
model,
|
|
119
|
+
entry: initialStorageEntry
|
|
120
|
+
});
|
|
103
121
|
const esEntry = (0, _helpers.prepareEntryToIndex)({
|
|
104
122
|
plugins,
|
|
105
123
|
model,
|
|
106
|
-
entry: (0,
|
|
107
|
-
|
|
124
|
+
entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
|
|
125
|
+
locked
|
|
126
|
+
})),
|
|
127
|
+
storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
128
|
+
locked
|
|
129
|
+
}))
|
|
108
130
|
});
|
|
109
131
|
|
|
110
132
|
const {
|
|
111
133
|
index: esIndex
|
|
112
|
-
} = _configurations.
|
|
134
|
+
} = _configurations.configurations.es({
|
|
113
135
|
model
|
|
114
136
|
});
|
|
115
137
|
|
|
116
138
|
const esLatestData = await getESLatestEntryData(plugins, esEntry);
|
|
139
|
+
const esPublishedData = await getESPublishedEntryData(plugins, esEntry);
|
|
117
140
|
const revisionKeys = {
|
|
118
|
-
PK: (0, _keys.createPartitionKey)(
|
|
141
|
+
PK: (0, _keys.createPartitionKey)({
|
|
142
|
+
id: entry.id,
|
|
143
|
+
locale: model.locale,
|
|
144
|
+
tenant: model.tenant
|
|
145
|
+
}),
|
|
119
146
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
120
147
|
};
|
|
121
148
|
const latestKeys = {
|
|
122
|
-
PK: (0, _keys.createPartitionKey)(
|
|
149
|
+
PK: (0, _keys.createPartitionKey)({
|
|
150
|
+
id: entry.id,
|
|
151
|
+
locale: model.locale,
|
|
152
|
+
tenant: model.tenant
|
|
153
|
+
}),
|
|
123
154
|
SK: (0, _keys.createLatestSortKey)()
|
|
124
155
|
};
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
156
|
+
const publishedKeys = {
|
|
157
|
+
PK: (0, _keys.createPartitionKey)({
|
|
158
|
+
id: entry.id,
|
|
159
|
+
locale: model.locale,
|
|
160
|
+
tenant: model.tenant
|
|
161
|
+
}),
|
|
162
|
+
SK: (0, _keys.createPublishedSortKey)()
|
|
163
|
+
};
|
|
164
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
165
|
+
locked
|
|
166
|
+
}, revisionKeys), {}, {
|
|
167
|
+
TYPE: (0, _recordType.createRecordType)()
|
|
168
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
169
|
+
locked
|
|
170
|
+
}, latestKeys), {}, {
|
|
171
|
+
TYPE: (0, _recordType.createLatestRecordType)()
|
|
129
172
|
}))];
|
|
130
173
|
|
|
174
|
+
if (isPublished) {
|
|
175
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
176
|
+
locked
|
|
177
|
+
}, publishedKeys), {}, {
|
|
178
|
+
TYPE: (0, _recordType.createPublishedRecordType)()
|
|
179
|
+
})));
|
|
180
|
+
}
|
|
181
|
+
|
|
131
182
|
try {
|
|
132
183
|
await (0, _batchWrite.batchWriteAll)({
|
|
133
184
|
table: entity.table,
|
|
@@ -144,11 +195,23 @@ const createEntriesStorageOperations = params => {
|
|
|
144
195
|
});
|
|
145
196
|
}
|
|
146
197
|
|
|
147
|
-
|
|
148
|
-
|
|
198
|
+
const esItems = [esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
|
|
199
|
+
index: esIndex,
|
|
200
|
+
data: esLatestData
|
|
201
|
+
}))];
|
|
202
|
+
|
|
203
|
+
if (isPublished) {
|
|
204
|
+
esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
|
|
149
205
|
index: esIndex,
|
|
150
|
-
data:
|
|
151
|
-
}));
|
|
206
|
+
data: esPublishedData
|
|
207
|
+
})));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
try {
|
|
211
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
212
|
+
table: esEntity.table,
|
|
213
|
+
items: esItems
|
|
214
|
+
});
|
|
152
215
|
} catch (ex) {
|
|
153
216
|
throw new _error.default(ex.message || "Could not insert entry data into the Elasticsearch DynamoDB table.", ex.code || "CREATE_ES_ENTRY_ERROR", {
|
|
154
217
|
error: ex,
|
|
@@ -157,39 +220,54 @@ const createEntriesStorageOperations = params => {
|
|
|
157
220
|
});
|
|
158
221
|
}
|
|
159
222
|
|
|
160
|
-
return
|
|
223
|
+
return initialStorageEntry;
|
|
161
224
|
};
|
|
162
225
|
|
|
163
226
|
const createRevisionFrom = async (model, params) => {
|
|
164
227
|
const {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
storageEntry
|
|
228
|
+
entry: initialEntry,
|
|
229
|
+
storageEntry: initialStorageEntry
|
|
168
230
|
} = params;
|
|
231
|
+
const entry = convertEntryKeysToStorage({
|
|
232
|
+
model,
|
|
233
|
+
entry: initialEntry
|
|
234
|
+
});
|
|
235
|
+
const storageEntry = convertEntryKeysToStorage({
|
|
236
|
+
model,
|
|
237
|
+
entry: initialStorageEntry
|
|
238
|
+
});
|
|
169
239
|
const revisionKeys = {
|
|
170
|
-
PK: (0, _keys.createPartitionKey)(
|
|
240
|
+
PK: (0, _keys.createPartitionKey)({
|
|
241
|
+
id: entry.id,
|
|
242
|
+
locale: model.locale,
|
|
243
|
+
tenant: model.tenant
|
|
244
|
+
}),
|
|
171
245
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
172
246
|
};
|
|
173
247
|
const latestKeys = {
|
|
174
|
-
PK: (0, _keys.createPartitionKey)(
|
|
248
|
+
PK: (0, _keys.createPartitionKey)({
|
|
249
|
+
id: entry.id,
|
|
250
|
+
locale: model.locale,
|
|
251
|
+
tenant: model.tenant
|
|
252
|
+
}),
|
|
175
253
|
SK: (0, _keys.createLatestSortKey)()
|
|
176
254
|
};
|
|
177
255
|
const esEntry = (0, _helpers.prepareEntryToIndex)({
|
|
178
256
|
plugins,
|
|
179
257
|
model,
|
|
180
|
-
entry: (0,
|
|
181
|
-
storageEntry: (0,
|
|
258
|
+
entry: (0, _cloneDeep.default)(entry),
|
|
259
|
+
storageEntry: (0, _cloneDeep.default)(storageEntry)
|
|
182
260
|
});
|
|
183
261
|
const esLatestData = await getESLatestEntryData(plugins, esEntry);
|
|
184
|
-
const items = [entity.putBatch(
|
|
185
|
-
TYPE:
|
|
186
|
-
}, revisionKeys)), entity.putBatch(
|
|
187
|
-
TYPE:
|
|
262
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
263
|
+
TYPE: (0, _recordType.createRecordType)()
|
|
264
|
+
}, revisionKeys)), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
265
|
+
TYPE: (0, _recordType.createLatestRecordType)()
|
|
188
266
|
}, latestKeys))];
|
|
189
267
|
|
|
190
268
|
const {
|
|
191
269
|
index
|
|
192
|
-
} = _configurations.
|
|
270
|
+
} = _configurations.configurations.es({
|
|
193
271
|
model
|
|
194
272
|
});
|
|
195
273
|
|
|
@@ -204,7 +282,6 @@ const createEntriesStorageOperations = params => {
|
|
|
204
282
|
} catch (ex) {
|
|
205
283
|
throw new _error.default(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
|
|
206
284
|
error: ex,
|
|
207
|
-
originalEntry,
|
|
208
285
|
entry,
|
|
209
286
|
storageEntry
|
|
210
287
|
});
|
|
@@ -215,14 +292,13 @@ const createEntriesStorageOperations = params => {
|
|
|
215
292
|
|
|
216
293
|
|
|
217
294
|
try {
|
|
218
|
-
await esEntity.put(
|
|
295
|
+
await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
|
|
219
296
|
index,
|
|
220
297
|
data: esLatestData
|
|
221
298
|
}));
|
|
222
299
|
} catch (ex) {
|
|
223
300
|
throw new _error.default(ex.message || "Could not update latest entry in the DynamoDB Elasticsearch table.", ex.code || "CREATE_REVISION_ERROR", {
|
|
224
301
|
error: ex,
|
|
225
|
-
originalEntry,
|
|
226
302
|
entry
|
|
227
303
|
});
|
|
228
304
|
}
|
|
@@ -231,58 +307,155 @@ const createEntriesStorageOperations = params => {
|
|
|
231
307
|
*/
|
|
232
308
|
|
|
233
309
|
|
|
234
|
-
return
|
|
310
|
+
return initialStorageEntry;
|
|
235
311
|
};
|
|
236
312
|
|
|
237
313
|
const update = async (model, params) => {
|
|
238
314
|
const {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
storageEntry
|
|
315
|
+
entry: initialEntry,
|
|
316
|
+
storageEntry: initialStorageEntry
|
|
242
317
|
} = params;
|
|
318
|
+
const entry = convertEntryKeysToStorage({
|
|
319
|
+
model,
|
|
320
|
+
entry: initialEntry
|
|
321
|
+
});
|
|
322
|
+
const storageEntry = convertEntryKeysToStorage({
|
|
323
|
+
model,
|
|
324
|
+
entry: initialStorageEntry
|
|
325
|
+
});
|
|
326
|
+
const isPublished = entry.status === "published";
|
|
327
|
+
const locked = isPublished ? true : entry.locked;
|
|
243
328
|
const revisionKeys = {
|
|
244
|
-
PK: (0, _keys.createPartitionKey)(
|
|
329
|
+
PK: (0, _keys.createPartitionKey)({
|
|
330
|
+
id: entry.id,
|
|
331
|
+
locale: model.locale,
|
|
332
|
+
tenant: model.tenant
|
|
333
|
+
}),
|
|
245
334
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
246
335
|
};
|
|
247
336
|
const latestKeys = {
|
|
248
|
-
PK: (0, _keys.createPartitionKey)(
|
|
337
|
+
PK: (0, _keys.createPartitionKey)({
|
|
338
|
+
id: entry.id,
|
|
339
|
+
locale: model.locale,
|
|
340
|
+
tenant: model.tenant
|
|
341
|
+
}),
|
|
249
342
|
SK: (0, _keys.createLatestSortKey)()
|
|
250
343
|
};
|
|
344
|
+
const publishedKeys = {
|
|
345
|
+
PK: (0, _keys.createPartitionKey)({
|
|
346
|
+
id: entry.id,
|
|
347
|
+
locale: model.locale,
|
|
348
|
+
tenant: model.tenant
|
|
349
|
+
}),
|
|
350
|
+
SK: (0, _keys.createPublishedSortKey)()
|
|
351
|
+
};
|
|
251
352
|
/**
|
|
252
353
|
* We need the latest entry to check if it needs to be updated.
|
|
253
354
|
*/
|
|
254
355
|
|
|
255
356
|
const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
|
|
256
357
|
model,
|
|
257
|
-
ids: [
|
|
358
|
+
ids: [entry.id]
|
|
359
|
+
});
|
|
360
|
+
const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
|
|
361
|
+
model,
|
|
362
|
+
ids: [entry.id]
|
|
258
363
|
});
|
|
259
|
-
const items = [entity.putBatch(
|
|
260
|
-
|
|
364
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
365
|
+
locked
|
|
366
|
+
}, revisionKeys), {}, {
|
|
367
|
+
TYPE: (0, _recordType.createRecordType)()
|
|
261
368
|
}))];
|
|
369
|
+
|
|
370
|
+
if (isPublished) {
|
|
371
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
372
|
+
locked
|
|
373
|
+
}, publishedKeys), {}, {
|
|
374
|
+
TYPE: (0, _recordType.createPublishedRecordType)()
|
|
375
|
+
})));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const esItems = [];
|
|
379
|
+
|
|
380
|
+
const {
|
|
381
|
+
index: esIndex
|
|
382
|
+
} = _configurations.configurations.es({
|
|
383
|
+
model
|
|
384
|
+
});
|
|
385
|
+
/**
|
|
386
|
+
* Variable for the elasticsearch entry so we do not convert it more than once
|
|
387
|
+
*/
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
let esEntry = undefined;
|
|
262
391
|
/**
|
|
263
392
|
* If the latest entry is the one being updated, we need to create a new latest entry records.
|
|
264
393
|
*/
|
|
265
394
|
|
|
266
395
|
let elasticsearchLatestData = null;
|
|
267
396
|
|
|
268
|
-
if (latestStorageEntry.id ===
|
|
397
|
+
if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
|
|
269
398
|
/**
|
|
270
399
|
* First we update the regular DynamoDB table
|
|
271
400
|
*/
|
|
272
|
-
items.push(entity.putBatch(
|
|
401
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), latestKeys), {}, {
|
|
273
402
|
TYPE: (0, _keys.createLatestSortKey)()
|
|
274
403
|
})));
|
|
275
404
|
/**
|
|
276
405
|
* And then update the Elasticsearch table to propagate changes to the Elasticsearch
|
|
277
406
|
*/
|
|
278
407
|
|
|
279
|
-
|
|
408
|
+
esEntry = (0, _helpers.prepareEntryToIndex)({
|
|
280
409
|
plugins,
|
|
281
410
|
model,
|
|
282
|
-
entry: (0,
|
|
283
|
-
|
|
411
|
+
entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
|
|
412
|
+
locked
|
|
413
|
+
})),
|
|
414
|
+
storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
415
|
+
locked
|
|
416
|
+
}))
|
|
284
417
|
});
|
|
285
418
|
elasticsearchLatestData = await getESLatestEntryData(plugins, esEntry);
|
|
419
|
+
esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
|
|
420
|
+
index: esIndex,
|
|
421
|
+
data: elasticsearchLatestData
|
|
422
|
+
})));
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
let elasticsearchPublishedData = null;
|
|
426
|
+
|
|
427
|
+
if (isPublished && (publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
|
|
428
|
+
if (!elasticsearchLatestData) {
|
|
429
|
+
/**
|
|
430
|
+
* And then update the Elasticsearch table to propagate changes to the Elasticsearch
|
|
431
|
+
*/
|
|
432
|
+
if (!esEntry) {
|
|
433
|
+
esEntry = (0, _helpers.prepareEntryToIndex)({
|
|
434
|
+
plugins,
|
|
435
|
+
model,
|
|
436
|
+
entry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
|
|
437
|
+
locked
|
|
438
|
+
})),
|
|
439
|
+
storageEntry: (0, _cloneDeep.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
440
|
+
locked
|
|
441
|
+
}))
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
elasticsearchPublishedData = await getESPublishedEntryData(plugins, esEntry);
|
|
446
|
+
} else {
|
|
447
|
+
elasticsearchPublishedData = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, elasticsearchLatestData), {}, {
|
|
448
|
+
published: true,
|
|
449
|
+
TYPE: (0, _recordType.createPublishedRecordType)(),
|
|
450
|
+
__type: (0, _recordType.createPublishedRecordType)()
|
|
451
|
+
});
|
|
452
|
+
delete elasticsearchPublishedData.latest;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
|
|
456
|
+
index: esIndex,
|
|
457
|
+
data: elasticsearchPublishedData
|
|
458
|
+
})));
|
|
286
459
|
}
|
|
287
460
|
|
|
288
461
|
try {
|
|
@@ -296,43 +469,39 @@ const createEntriesStorageOperations = params => {
|
|
|
296
469
|
} catch (ex) {
|
|
297
470
|
throw new _error.default(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
|
|
298
471
|
error: ex,
|
|
299
|
-
originalEntry,
|
|
300
472
|
entry,
|
|
301
473
|
storageEntry
|
|
302
474
|
});
|
|
303
475
|
}
|
|
304
476
|
|
|
305
|
-
if (
|
|
306
|
-
return
|
|
477
|
+
if (esItems.length === 0) {
|
|
478
|
+
return initialStorageEntry;
|
|
307
479
|
}
|
|
308
480
|
|
|
309
|
-
const {
|
|
310
|
-
index: esIndex
|
|
311
|
-
} = _configurations.default.es({
|
|
312
|
-
model
|
|
313
|
-
});
|
|
314
|
-
|
|
315
481
|
try {
|
|
316
|
-
await
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
})
|
|
482
|
+
await (0, _batchWrite.batchWriteAll)({
|
|
483
|
+
table: esEntity.table,
|
|
484
|
+
items: esItems
|
|
485
|
+
});
|
|
320
486
|
} catch (ex) {
|
|
321
|
-
throw new _error.default(ex.message || "Could not update entry DynamoDB Elasticsearch
|
|
487
|
+
throw new _error.default(ex.message || "Could not update entry DynamoDB Elasticsearch records.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
|
|
322
488
|
error: ex,
|
|
323
|
-
originalEntry,
|
|
324
489
|
entry
|
|
325
490
|
});
|
|
326
491
|
}
|
|
327
492
|
|
|
328
|
-
return
|
|
493
|
+
return initialStorageEntry;
|
|
329
494
|
};
|
|
330
495
|
|
|
331
496
|
const deleteEntry = async (model, params) => {
|
|
332
497
|
const {
|
|
333
498
|
entry
|
|
334
499
|
} = params;
|
|
335
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
500
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
501
|
+
id: entry.id,
|
|
502
|
+
locale: model.locale,
|
|
503
|
+
tenant: model.tenant
|
|
504
|
+
});
|
|
336
505
|
const items = await (0, _query.queryAll)({
|
|
337
506
|
entity,
|
|
338
507
|
partitionKey,
|
|
@@ -390,15 +559,19 @@ const createEntriesStorageOperations = params => {
|
|
|
390
559
|
|
|
391
560
|
const deleteRevision = async (model, params) => {
|
|
392
561
|
const {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
562
|
+
entry,
|
|
563
|
+
latestEntry,
|
|
564
|
+
latestStorageEntry
|
|
396
565
|
} = params;
|
|
397
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
566
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
567
|
+
id: entry.id,
|
|
568
|
+
locale: model.locale,
|
|
569
|
+
tenant: model.tenant
|
|
570
|
+
});
|
|
398
571
|
|
|
399
572
|
const {
|
|
400
573
|
index
|
|
401
|
-
} = _configurations.
|
|
574
|
+
} = _configurations.configurations.es({
|
|
402
575
|
model
|
|
403
576
|
});
|
|
404
577
|
/**
|
|
@@ -408,7 +581,7 @@ const createEntriesStorageOperations = params => {
|
|
|
408
581
|
|
|
409
582
|
const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
|
|
410
583
|
model,
|
|
411
|
-
ids: [
|
|
584
|
+
ids: [entry.id]
|
|
412
585
|
});
|
|
413
586
|
/**
|
|
414
587
|
* We need to delete all existing records of the given entry revision.
|
|
@@ -420,14 +593,14 @@ const createEntriesStorageOperations = params => {
|
|
|
420
593
|
*/
|
|
421
594
|
entity.deleteBatch({
|
|
422
595
|
PK: partitionKey,
|
|
423
|
-
SK: (0, _keys.createRevisionSortKey)(
|
|
596
|
+
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
424
597
|
})];
|
|
425
598
|
const esItems = [];
|
|
426
599
|
/**
|
|
427
600
|
* If revision we are deleting is the published one as well, we need to delete those records as well.
|
|
428
601
|
*/
|
|
429
602
|
|
|
430
|
-
if (publishedStorageEntry
|
|
603
|
+
if ((publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
|
|
431
604
|
items.push(entity.deleteBatch({
|
|
432
605
|
PK: partitionKey,
|
|
433
606
|
SK: (0, _keys.createPublishedSortKey)()
|
|
@@ -438,22 +611,22 @@ const createEntriesStorageOperations = params => {
|
|
|
438
611
|
}));
|
|
439
612
|
}
|
|
440
613
|
|
|
441
|
-
if (
|
|
614
|
+
if (latestEntry && latestStorageEntry) {
|
|
442
615
|
const esEntry = (0, _helpers.prepareEntryToIndex)({
|
|
443
616
|
plugins,
|
|
444
617
|
model,
|
|
445
|
-
entry: (0,
|
|
446
|
-
storageEntry: (0,
|
|
618
|
+
entry: (0, _cloneDeep.default)(latestEntry),
|
|
619
|
+
storageEntry: (0, _cloneDeep.default)(latestStorageEntry)
|
|
447
620
|
});
|
|
448
621
|
const esLatestData = await getESLatestEntryData(plugins, esEntry);
|
|
449
622
|
/**
|
|
450
623
|
* In the end we need to set the new latest entry
|
|
451
624
|
*/
|
|
452
625
|
|
|
453
|
-
items.push(entity.putBatch(
|
|
626
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestStorageEntry), {}, {
|
|
454
627
|
PK: partitionKey,
|
|
455
628
|
SK: (0, _keys.createLatestSortKey)(),
|
|
456
|
-
TYPE:
|
|
629
|
+
TYPE: (0, _recordType.createLatestRecordType)()
|
|
457
630
|
})));
|
|
458
631
|
esItems.push(esEntity.putBatch({
|
|
459
632
|
PK: partitionKey,
|
|
@@ -474,9 +647,9 @@ const createEntriesStorageOperations = params => {
|
|
|
474
647
|
} catch (ex) {
|
|
475
648
|
throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB table.", ex.code || "DELETE_REVISION_ERROR", {
|
|
476
649
|
error: ex,
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
650
|
+
entry,
|
|
651
|
+
latestEntry,
|
|
652
|
+
latestStorageEntry
|
|
480
653
|
});
|
|
481
654
|
}
|
|
482
655
|
|
|
@@ -492,31 +665,54 @@ const createEntriesStorageOperations = params => {
|
|
|
492
665
|
} catch (ex) {
|
|
493
666
|
throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB Elasticsearch table.", ex.code || "DELETE_REVISION_ERROR", {
|
|
494
667
|
error: ex,
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
668
|
+
entry,
|
|
669
|
+
latestEntry,
|
|
670
|
+
latestStorageEntry
|
|
498
671
|
});
|
|
499
672
|
}
|
|
500
673
|
};
|
|
501
674
|
|
|
502
675
|
const list = async (model, params) => {
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
args: _objectSpread(_objectSpread({}, params), {}, {
|
|
507
|
-
limit
|
|
508
|
-
}),
|
|
509
|
-
plugins,
|
|
510
|
-
parentPath: "values"
|
|
511
|
-
});
|
|
512
|
-
let response;
|
|
676
|
+
var _response, _response$body;
|
|
677
|
+
|
|
678
|
+
const limit = (0, _apiElasticsearch.createLimit)(params.limit, 50);
|
|
513
679
|
|
|
514
680
|
const {
|
|
515
681
|
index
|
|
516
|
-
} = _configurations.
|
|
682
|
+
} = _configurations.configurations.es({
|
|
517
683
|
model
|
|
518
684
|
});
|
|
519
685
|
|
|
686
|
+
try {
|
|
687
|
+
const result = await elasticsearch.indices.exists({
|
|
688
|
+
index
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
if (!(result !== null && result !== void 0 && result.body)) {
|
|
692
|
+
return {
|
|
693
|
+
hasMoreItems: false,
|
|
694
|
+
totalCount: 0,
|
|
695
|
+
cursor: null,
|
|
696
|
+
items: []
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
} catch (ex) {
|
|
700
|
+
throw new _error.default("Could not determine if Elasticsearch index exists.", "ELASTICSEARCH_INDEX_CHECK_ERROR", {
|
|
701
|
+
error: ex,
|
|
702
|
+
index
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const body = (0, _body.createElasticsearchBody)({
|
|
707
|
+
model,
|
|
708
|
+
params: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
709
|
+
limit,
|
|
710
|
+
after: (0, _apiElasticsearch.decodeCursor)(params.after)
|
|
711
|
+
}),
|
|
712
|
+
plugins
|
|
713
|
+
});
|
|
714
|
+
let response;
|
|
715
|
+
|
|
520
716
|
try {
|
|
521
717
|
response = await elasticsearch.search({
|
|
522
718
|
index,
|
|
@@ -526,18 +722,24 @@ const createEntriesStorageOperations = params => {
|
|
|
526
722
|
throw new _error.default(ex.message, ex.code || "ELASTICSEARCH_ERROR", {
|
|
527
723
|
error: ex,
|
|
528
724
|
index,
|
|
529
|
-
body
|
|
725
|
+
body,
|
|
726
|
+
model
|
|
530
727
|
});
|
|
531
728
|
}
|
|
532
729
|
|
|
533
730
|
const {
|
|
534
731
|
hits,
|
|
535
732
|
total
|
|
536
|
-
} = response.body.hits;
|
|
733
|
+
} = ((_response = response) === null || _response === void 0 ? void 0 : (_response$body = _response.body) === null || _response$body === void 0 ? void 0 : _response$body.hits) || {};
|
|
537
734
|
const items = (0, _helpers.extractEntriesFromIndex)({
|
|
538
735
|
plugins,
|
|
539
736
|
model,
|
|
540
737
|
entries: hits.map(item => item._source)
|
|
738
|
+
}).map(item => {
|
|
739
|
+
return convertEntryKeysFromStorage({
|
|
740
|
+
model,
|
|
741
|
+
entry: item
|
|
742
|
+
});
|
|
541
743
|
});
|
|
542
744
|
const hasMoreItems = items.length > limit;
|
|
543
745
|
|
|
@@ -553,7 +755,7 @@ const createEntriesStorageOperations = params => {
|
|
|
553
755
|
*/
|
|
554
756
|
|
|
555
757
|
|
|
556
|
-
const cursor = items.length > 0 ? (0,
|
|
758
|
+
const cursor = items.length > 0 ? (0, _apiElasticsearch.encodeCursor)(hits[items.length - 1].sort) || null : null;
|
|
557
759
|
return {
|
|
558
760
|
hasMoreItems,
|
|
559
761
|
totalCount: total.value,
|
|
@@ -565,22 +767,25 @@ const createEntriesStorageOperations = params => {
|
|
|
565
767
|
const get = async (model, params) => {
|
|
566
768
|
const {
|
|
567
769
|
items
|
|
568
|
-
} = await list(model,
|
|
770
|
+
} = await list(model, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
569
771
|
limit: 1
|
|
570
772
|
}));
|
|
571
|
-
|
|
572
|
-
if (items.length === 0) {
|
|
573
|
-
return null;
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
return items.shift();
|
|
773
|
+
return items.shift() || null;
|
|
577
774
|
};
|
|
578
775
|
|
|
579
776
|
const publish = async (model, params) => {
|
|
580
777
|
const {
|
|
581
|
-
entry,
|
|
582
|
-
storageEntry
|
|
778
|
+
entry: initialEntry,
|
|
779
|
+
storageEntry: initialStorageEntry
|
|
583
780
|
} = params;
|
|
781
|
+
const entry = convertEntryKeysToStorage({
|
|
782
|
+
model,
|
|
783
|
+
entry: initialEntry
|
|
784
|
+
});
|
|
785
|
+
const storageEntry = convertEntryKeysToStorage({
|
|
786
|
+
model,
|
|
787
|
+
entry: initialStorageEntry
|
|
788
|
+
});
|
|
584
789
|
/**
|
|
585
790
|
* We need currently published entry to check if need to remove it.
|
|
586
791
|
*/
|
|
@@ -590,15 +795,27 @@ const createEntriesStorageOperations = params => {
|
|
|
590
795
|
ids: [entry.id]
|
|
591
796
|
});
|
|
592
797
|
const revisionKeys = {
|
|
593
|
-
PK: (0, _keys.createPartitionKey)(
|
|
798
|
+
PK: (0, _keys.createPartitionKey)({
|
|
799
|
+
id: entry.id,
|
|
800
|
+
locale: model.locale,
|
|
801
|
+
tenant: model.tenant
|
|
802
|
+
}),
|
|
594
803
|
SK: (0, _keys.createRevisionSortKey)(entry)
|
|
595
804
|
};
|
|
596
805
|
const latestKeys = {
|
|
597
|
-
PK: (0, _keys.createPartitionKey)(
|
|
806
|
+
PK: (0, _keys.createPartitionKey)({
|
|
807
|
+
id: entry.id,
|
|
808
|
+
locale: model.locale,
|
|
809
|
+
tenant: model.tenant
|
|
810
|
+
}),
|
|
598
811
|
SK: (0, _keys.createLatestSortKey)()
|
|
599
812
|
};
|
|
600
813
|
const publishedKeys = {
|
|
601
|
-
PK: (0, _keys.createPartitionKey)(
|
|
814
|
+
PK: (0, _keys.createPartitionKey)({
|
|
815
|
+
id: entry.id,
|
|
816
|
+
locale: model.locale,
|
|
817
|
+
tenant: model.tenant
|
|
818
|
+
}),
|
|
602
819
|
SK: (0, _keys.createPublishedSortKey)()
|
|
603
820
|
};
|
|
604
821
|
let latestEsEntry = null;
|
|
@@ -616,18 +833,18 @@ const createEntriesStorageOperations = params => {
|
|
|
616
833
|
});
|
|
617
834
|
}
|
|
618
835
|
|
|
619
|
-
const items = [entity.putBatch(
|
|
620
|
-
TYPE:
|
|
836
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), revisionKeys), {}, {
|
|
837
|
+
TYPE: (0, _recordType.createRecordType)()
|
|
621
838
|
}))];
|
|
622
839
|
const esItems = [];
|
|
623
840
|
|
|
624
841
|
const {
|
|
625
842
|
index
|
|
626
|
-
} = _configurations.
|
|
843
|
+
} = _configurations.configurations.es({
|
|
627
844
|
model
|
|
628
845
|
});
|
|
629
846
|
|
|
630
|
-
if (publishedStorageEntry) {
|
|
847
|
+
if (publishedStorageEntry && publishedStorageEntry.id !== entry.id) {
|
|
631
848
|
/**
|
|
632
849
|
* If there is a `published` entry already, we need to set it to `unpublished`. We need to
|
|
633
850
|
* execute two updates: update the previously published entry's status and the published entry record.
|
|
@@ -643,10 +860,10 @@ const createEntriesStorageOperations = params => {
|
|
|
643
860
|
/**
|
|
644
861
|
* Update currently published entry (unpublish it)
|
|
645
862
|
*/
|
|
646
|
-
entity.putBatch(
|
|
863
|
+
entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedEntry), {}, {
|
|
647
864
|
status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
|
|
648
865
|
savedOn: entry.savedOn,
|
|
649
|
-
TYPE:
|
|
866
|
+
TYPE: (0, _recordType.createRecordType)(),
|
|
650
867
|
PK: (0, _keys.createPartitionKey)(publishedStorageEntry),
|
|
651
868
|
SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry)
|
|
652
869
|
})));
|
|
@@ -656,53 +873,60 @@ const createEntriesStorageOperations = params => {
|
|
|
656
873
|
*/
|
|
657
874
|
|
|
658
875
|
|
|
659
|
-
items.push(entity.putBatch(
|
|
660
|
-
TYPE:
|
|
876
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), publishedKeys), {}, {
|
|
877
|
+
TYPE: (0, _recordType.createPublishedRecordType)()
|
|
661
878
|
})));
|
|
662
879
|
/**
|
|
663
|
-
* We need the latest entry to check if it
|
|
880
|
+
* We need the latest entry to check if it needs to be updated as well in the Elasticsearch.
|
|
664
881
|
*/
|
|
665
882
|
|
|
666
883
|
const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
|
|
667
884
|
model,
|
|
668
885
|
ids: [entry.id]
|
|
669
886
|
});
|
|
887
|
+
|
|
888
|
+
if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
|
|
889
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), latestKeys)));
|
|
890
|
+
}
|
|
670
891
|
/**
|
|
671
892
|
* If we are publishing the latest revision, let's also update the latest revision's status in ES.
|
|
672
893
|
*/
|
|
673
894
|
|
|
674
|
-
|
|
895
|
+
|
|
896
|
+
if (latestEsEntry && (latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
|
|
675
897
|
/**
|
|
676
898
|
* Need to decompress the data from Elasticsearch DynamoDB table.
|
|
899
|
+
*
|
|
900
|
+
* No need to transform it for the storage because it was fetched directly from the Elasticsearch table, where it sits transformed.
|
|
677
901
|
*/
|
|
678
|
-
const latestEsEntryDataDecompressed = await (0,
|
|
902
|
+
const latestEsEntryDataDecompressed = await (0, _apiElasticsearch.decompress)(plugins, latestEsEntry.data);
|
|
679
903
|
esItems.push(esEntity.putBatch({
|
|
680
904
|
index,
|
|
681
905
|
PK: (0, _keys.createPartitionKey)(latestEsEntryDataDecompressed),
|
|
682
906
|
SK: (0, _keys.createLatestSortKey)(),
|
|
683
|
-
data:
|
|
907
|
+
data: await getESLatestEntryData(plugins, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestEsEntryDataDecompressed), {}, {
|
|
684
908
|
status: _types.CONTENT_ENTRY_STATUS.PUBLISHED,
|
|
685
909
|
locked: true,
|
|
686
910
|
savedOn: entry.savedOn,
|
|
687
911
|
publishedOn: entry.publishedOn
|
|
688
|
-
})
|
|
912
|
+
}))
|
|
689
913
|
}));
|
|
690
914
|
}
|
|
691
915
|
|
|
692
916
|
const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
|
|
693
917
|
plugins,
|
|
694
918
|
model,
|
|
695
|
-
entry: (0,
|
|
696
|
-
storageEntry: (0,
|
|
919
|
+
entry: (0, _cloneDeep.default)(entry),
|
|
920
|
+
storageEntry: (0, _cloneDeep.default)(storageEntry)
|
|
697
921
|
});
|
|
698
922
|
/**
|
|
699
923
|
* Update the published revision entry in ES.
|
|
700
924
|
*/
|
|
701
925
|
|
|
702
|
-
const
|
|
703
|
-
esItems.push(esEntity.putBatch(
|
|
926
|
+
const esPublishedData = await getESPublishedEntryData(plugins, preparedEntryData);
|
|
927
|
+
esItems.push(esEntity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, publishedKeys), {}, {
|
|
704
928
|
index,
|
|
705
|
-
data:
|
|
929
|
+
data: esPublishedData
|
|
706
930
|
})));
|
|
707
931
|
/**
|
|
708
932
|
* Finally, execute regular table batch.
|
|
@@ -743,14 +967,22 @@ const createEntriesStorageOperations = params => {
|
|
|
743
967
|
});
|
|
744
968
|
}
|
|
745
969
|
|
|
746
|
-
return
|
|
970
|
+
return initialStorageEntry;
|
|
747
971
|
};
|
|
748
972
|
|
|
749
973
|
const unpublish = async (model, params) => {
|
|
750
974
|
const {
|
|
751
|
-
entry,
|
|
752
|
-
storageEntry
|
|
975
|
+
entry: initialEntry,
|
|
976
|
+
storageEntry: initialStorageEntry
|
|
753
977
|
} = params;
|
|
978
|
+
const entry = convertEntryKeysToStorage({
|
|
979
|
+
model,
|
|
980
|
+
entry: initialEntry
|
|
981
|
+
});
|
|
982
|
+
const storageEntry = convertEntryKeysToStorage({
|
|
983
|
+
model,
|
|
984
|
+
entry: initialStorageEntry
|
|
985
|
+
});
|
|
754
986
|
/**
|
|
755
987
|
* We need the latest entry to check if it needs to be updated.
|
|
756
988
|
*/
|
|
@@ -759,14 +991,18 @@ const createEntriesStorageOperations = params => {
|
|
|
759
991
|
model,
|
|
760
992
|
ids: [entry.id]
|
|
761
993
|
});
|
|
762
|
-
const partitionKey = (0, _keys.createPartitionKey)(
|
|
994
|
+
const partitionKey = (0, _keys.createPartitionKey)({
|
|
995
|
+
id: entry.id,
|
|
996
|
+
locale: model.locale,
|
|
997
|
+
tenant: model.tenant
|
|
998
|
+
});
|
|
763
999
|
const items = [entity.deleteBatch({
|
|
764
1000
|
PK: partitionKey,
|
|
765
1001
|
SK: (0, _keys.createPublishedSortKey)()
|
|
766
|
-
}), entity.putBatch(
|
|
1002
|
+
}), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, storageEntry), {}, {
|
|
767
1003
|
PK: partitionKey,
|
|
768
1004
|
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
769
|
-
TYPE:
|
|
1005
|
+
TYPE: (0, _recordType.createRecordType)()
|
|
770
1006
|
}))];
|
|
771
1007
|
const esItems = [esEntity.deleteBatch({
|
|
772
1008
|
PK: partitionKey,
|
|
@@ -776,18 +1012,18 @@ const createEntriesStorageOperations = params => {
|
|
|
776
1012
|
* If we are unpublishing the latest revision, let's also update the latest revision entry's status in ES.
|
|
777
1013
|
*/
|
|
778
1014
|
|
|
779
|
-
if (latestStorageEntry.id === entry.id) {
|
|
1015
|
+
if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
|
|
780
1016
|
const {
|
|
781
1017
|
index
|
|
782
|
-
} = _configurations.
|
|
1018
|
+
} = _configurations.configurations.es({
|
|
783
1019
|
model
|
|
784
1020
|
});
|
|
785
1021
|
|
|
786
1022
|
const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
|
|
787
1023
|
plugins,
|
|
788
1024
|
model,
|
|
789
|
-
entry: (0,
|
|
790
|
-
storageEntry: (0,
|
|
1025
|
+
entry: (0, _cloneDeep.default)(entry),
|
|
1026
|
+
storageEntry: (0, _cloneDeep.default)(storageEntry)
|
|
791
1027
|
});
|
|
792
1028
|
const esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
|
|
793
1029
|
esItems.push(esEntity.putBatch({
|
|
@@ -833,250 +1069,107 @@ const createEntriesStorageOperations = params => {
|
|
|
833
1069
|
});
|
|
834
1070
|
}
|
|
835
1071
|
|
|
836
|
-
return
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
const requestReview = async (model, params) => {
|
|
840
|
-
const {
|
|
841
|
-
entry,
|
|
842
|
-
storageEntry,
|
|
843
|
-
originalEntry
|
|
844
|
-
} = params;
|
|
845
|
-
/**
|
|
846
|
-
* We need the latest entry to check if it needs to be updated.
|
|
847
|
-
*/
|
|
848
|
-
|
|
849
|
-
const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
|
|
850
|
-
model,
|
|
851
|
-
ids: [entry.id]
|
|
852
|
-
});
|
|
853
|
-
const partitionKey = (0, _keys.createPartitionKey)(entry);
|
|
854
|
-
/**
|
|
855
|
-
* If we updated the latest version, then make sure the changes are propagated to ES too.
|
|
856
|
-
*/
|
|
857
|
-
|
|
858
|
-
let esLatestData = null;
|
|
859
|
-
|
|
860
|
-
const {
|
|
861
|
-
index
|
|
862
|
-
} = _configurations.default.es({
|
|
863
|
-
model
|
|
864
|
-
});
|
|
865
|
-
|
|
866
|
-
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
867
|
-
const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
|
|
868
|
-
plugins,
|
|
869
|
-
model,
|
|
870
|
-
entry: (0, _lodash.default)(entry),
|
|
871
|
-
storageEntry: (0, _lodash.default)(storageEntry)
|
|
872
|
-
});
|
|
873
|
-
esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
try {
|
|
877
|
-
await entity.put(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
878
|
-
PK: partitionKey,
|
|
879
|
-
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
880
|
-
TYPE: createType()
|
|
881
|
-
}));
|
|
882
|
-
dataLoaders.clearAll({
|
|
883
|
-
model
|
|
884
|
-
});
|
|
885
|
-
} catch (ex) {
|
|
886
|
-
throw new _error.default(ex.message || "Could not store request review entry record into DynamoDB table.", ex.code || "REQUEST_REVIEW_ERROR", {
|
|
887
|
-
entry,
|
|
888
|
-
latestStorageEntry,
|
|
889
|
-
originalEntry
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* No need to proceed further if nothing to put into Elasticsearch.
|
|
894
|
-
*/
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
if (!esLatestData) {
|
|
898
|
-
return storageEntry;
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
try {
|
|
902
|
-
await esEntity.put({
|
|
903
|
-
PK: partitionKey,
|
|
904
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
905
|
-
index,
|
|
906
|
-
data: esLatestData
|
|
907
|
-
});
|
|
908
|
-
} catch (ex) {
|
|
909
|
-
throw new _error.default(ex.message || "Could not store request review entry record into DynamoDB Elasticsearch table.", ex.code || "REQUEST_REVIEW_ERROR", {
|
|
910
|
-
entry,
|
|
911
|
-
latestStorageEntry,
|
|
912
|
-
originalEntry
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
return storageEntry;
|
|
917
|
-
};
|
|
918
|
-
|
|
919
|
-
const requestChanges = async (model, params) => {
|
|
920
|
-
const {
|
|
921
|
-
entry,
|
|
922
|
-
storageEntry,
|
|
923
|
-
originalEntry
|
|
924
|
-
} = params;
|
|
925
|
-
/**
|
|
926
|
-
* We need the latest entry to check if it needs to be updated.
|
|
927
|
-
*/
|
|
928
|
-
|
|
929
|
-
const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
|
|
930
|
-
model,
|
|
931
|
-
ids: [entry.id]
|
|
932
|
-
});
|
|
933
|
-
const partitionKey = (0, _keys.createPartitionKey)(entry);
|
|
934
|
-
const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
935
|
-
PK: partitionKey,
|
|
936
|
-
SK: (0, _keys.createRevisionSortKey)(entry),
|
|
937
|
-
TYPE: createType()
|
|
938
|
-
}))];
|
|
939
|
-
/**
|
|
940
|
-
* If we updated the latest version, then make sure the changes are propagated to ES too.
|
|
941
|
-
*/
|
|
942
|
-
|
|
943
|
-
const {
|
|
944
|
-
index
|
|
945
|
-
} = _configurations.default.es({
|
|
946
|
-
model
|
|
947
|
-
});
|
|
948
|
-
|
|
949
|
-
let esLatestData = null;
|
|
950
|
-
|
|
951
|
-
if (latestStorageEntry && latestStorageEntry.id === entry.id) {
|
|
952
|
-
items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
|
|
953
|
-
PK: partitionKey,
|
|
954
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
955
|
-
TYPE: createLatestType()
|
|
956
|
-
})));
|
|
957
|
-
const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
|
|
958
|
-
plugins,
|
|
959
|
-
model,
|
|
960
|
-
entry: (0, _lodash.default)(entry),
|
|
961
|
-
storageEntry: (0, _lodash.default)(storageEntry)
|
|
962
|
-
});
|
|
963
|
-
esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
try {
|
|
967
|
-
await (0, _batchWrite.batchWriteAll)({
|
|
968
|
-
table: entity.table,
|
|
969
|
-
items
|
|
970
|
-
});
|
|
971
|
-
dataLoaders.clearAll({
|
|
972
|
-
model
|
|
973
|
-
});
|
|
974
|
-
} catch (ex) {
|
|
975
|
-
throw new _error.default(ex.message || "Could not store request changes entry record into DynamoDB table.", ex.code || "REQUEST_CHANGES_ERROR", {
|
|
976
|
-
entry,
|
|
977
|
-
latestStorageEntry,
|
|
978
|
-
originalEntry
|
|
979
|
-
});
|
|
980
|
-
}
|
|
981
|
-
/**
|
|
982
|
-
* No need to proceed further if nothing to put into Elasticsearch.
|
|
983
|
-
*/
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
if (!esLatestData) {
|
|
987
|
-
return storageEntry;
|
|
988
|
-
}
|
|
989
|
-
|
|
990
|
-
try {
|
|
991
|
-
await esEntity.put({
|
|
992
|
-
PK: partitionKey,
|
|
993
|
-
SK: (0, _keys.createLatestSortKey)(),
|
|
994
|
-
index,
|
|
995
|
-
data: esLatestData
|
|
996
|
-
});
|
|
997
|
-
} catch (ex) {
|
|
998
|
-
throw new _error.default(ex.message || "Could not store request changes entry record into DynamoDB Elasticsearch table.", ex.code || "REQUEST_CHANGES_ERROR", {
|
|
999
|
-
entry,
|
|
1000
|
-
latestStorageEntry,
|
|
1001
|
-
originalEntry
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
return storageEntry;
|
|
1006
|
-
};
|
|
1007
|
-
|
|
1008
|
-
const getAllRevisionsByIds = async (model, params) => {
|
|
1009
|
-
return await dataLoaders.getAllEntryRevisions({
|
|
1010
|
-
model,
|
|
1011
|
-
ids: params.ids
|
|
1012
|
-
});
|
|
1072
|
+
return initialStorageEntry;
|
|
1013
1073
|
};
|
|
1014
1074
|
|
|
1015
1075
|
const getLatestRevisionByEntryId = async (model, params) => {
|
|
1016
|
-
const
|
|
1076
|
+
const [entry] = await dataLoaders.getLatestRevisionByEntryId({
|
|
1017
1077
|
model,
|
|
1018
1078
|
ids: [params.id]
|
|
1019
1079
|
});
|
|
1020
1080
|
|
|
1021
|
-
if (
|
|
1081
|
+
if (!entry) {
|
|
1022
1082
|
return null;
|
|
1023
1083
|
}
|
|
1024
1084
|
|
|
1025
|
-
return
|
|
1085
|
+
return convertEntryKeysFromStorage({
|
|
1086
|
+
model,
|
|
1087
|
+
entry
|
|
1088
|
+
});
|
|
1026
1089
|
};
|
|
1027
1090
|
|
|
1028
1091
|
const getPublishedRevisionByEntryId = async (model, params) => {
|
|
1029
|
-
const
|
|
1092
|
+
const [entry] = await dataLoaders.getPublishedRevisionByEntryId({
|
|
1030
1093
|
model,
|
|
1031
1094
|
ids: [params.id]
|
|
1032
1095
|
});
|
|
1033
1096
|
|
|
1034
|
-
if (
|
|
1097
|
+
if (!entry) {
|
|
1035
1098
|
return null;
|
|
1036
1099
|
}
|
|
1037
1100
|
|
|
1038
|
-
return
|
|
1101
|
+
return convertEntryKeysFromStorage({
|
|
1102
|
+
model,
|
|
1103
|
+
entry
|
|
1104
|
+
});
|
|
1039
1105
|
};
|
|
1040
1106
|
|
|
1041
1107
|
const getRevisionById = async (model, params) => {
|
|
1042
|
-
const
|
|
1108
|
+
const [entry] = await dataLoaders.getRevisionById({
|
|
1043
1109
|
model,
|
|
1044
1110
|
ids: [params.id]
|
|
1045
1111
|
});
|
|
1046
1112
|
|
|
1047
|
-
if (
|
|
1113
|
+
if (!entry) {
|
|
1048
1114
|
return null;
|
|
1049
1115
|
}
|
|
1050
1116
|
|
|
1051
|
-
return
|
|
1117
|
+
return convertEntryKeysFromStorage({
|
|
1118
|
+
model,
|
|
1119
|
+
entry
|
|
1120
|
+
});
|
|
1052
1121
|
};
|
|
1053
1122
|
|
|
1054
1123
|
const getRevisions = async (model, params) => {
|
|
1055
|
-
|
|
1124
|
+
const entries = await dataLoaders.getAllEntryRevisions({
|
|
1056
1125
|
model,
|
|
1057
1126
|
ids: [params.id]
|
|
1058
1127
|
});
|
|
1128
|
+
return entries.map(entry => {
|
|
1129
|
+
return convertEntryKeysFromStorage({
|
|
1130
|
+
model,
|
|
1131
|
+
entry
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
1059
1134
|
};
|
|
1060
1135
|
|
|
1061
1136
|
const getByIds = async (model, params) => {
|
|
1062
|
-
|
|
1137
|
+
const entries = await dataLoaders.getRevisionById({
|
|
1063
1138
|
model,
|
|
1064
1139
|
ids: params.ids
|
|
1065
1140
|
});
|
|
1141
|
+
return entries.map(entry => {
|
|
1142
|
+
return convertEntryKeysFromStorage({
|
|
1143
|
+
model,
|
|
1144
|
+
entry
|
|
1145
|
+
});
|
|
1146
|
+
});
|
|
1066
1147
|
};
|
|
1067
1148
|
|
|
1068
1149
|
const getLatestByIds = async (model, params) => {
|
|
1069
|
-
|
|
1150
|
+
const entries = await dataLoaders.getLatestRevisionByEntryId({
|
|
1070
1151
|
model,
|
|
1071
1152
|
ids: params.ids
|
|
1072
1153
|
});
|
|
1154
|
+
return entries.map(entry => {
|
|
1155
|
+
return convertEntryKeysFromStorage({
|
|
1156
|
+
model,
|
|
1157
|
+
entry
|
|
1158
|
+
});
|
|
1159
|
+
});
|
|
1073
1160
|
};
|
|
1074
1161
|
|
|
1075
1162
|
const getPublishedByIds = async (model, params) => {
|
|
1076
|
-
|
|
1163
|
+
const entries = await dataLoaders.getPublishedRevisionByEntryId({
|
|
1077
1164
|
model,
|
|
1078
1165
|
ids: params.ids
|
|
1079
1166
|
});
|
|
1167
|
+
return entries.map(entry => {
|
|
1168
|
+
return convertEntryKeysFromStorage({
|
|
1169
|
+
model,
|
|
1170
|
+
entry
|
|
1171
|
+
});
|
|
1172
|
+
});
|
|
1080
1173
|
};
|
|
1081
1174
|
|
|
1082
1175
|
const getPreviousRevision = async (model, params) => {
|
|
@@ -1103,7 +1196,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1103
1196
|
*/
|
|
1104
1197
|
filters: [{
|
|
1105
1198
|
attr: "TYPE",
|
|
1106
|
-
eq:
|
|
1199
|
+
eq: (0, _recordType.createRecordType)()
|
|
1107
1200
|
}, {
|
|
1108
1201
|
attr: "version",
|
|
1109
1202
|
lt: version
|
|
@@ -1114,9 +1207,18 @@ const createEntriesStorageOperations = params => {
|
|
|
1114
1207
|
|
|
1115
1208
|
try {
|
|
1116
1209
|
const result = await (0, _query.queryOne)(queryParams);
|
|
1117
|
-
|
|
1210
|
+
const entry = (0, _cleanup.cleanupItem)(entity, result);
|
|
1211
|
+
|
|
1212
|
+
if (!entry) {
|
|
1213
|
+
return null;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
return convertEntryKeysFromStorage({
|
|
1217
|
+
entry,
|
|
1218
|
+
model
|
|
1219
|
+
});
|
|
1118
1220
|
} catch (ex) {
|
|
1119
|
-
throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR",
|
|
1221
|
+
throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
|
|
1120
1222
|
error: ex,
|
|
1121
1223
|
partitionKey: queryParams.partitionKey,
|
|
1122
1224
|
options: queryParams.options,
|
|
@@ -1134,10 +1236,7 @@ const createEntriesStorageOperations = params => {
|
|
|
1134
1236
|
get,
|
|
1135
1237
|
publish,
|
|
1136
1238
|
unpublish,
|
|
1137
|
-
requestReview,
|
|
1138
|
-
requestChanges,
|
|
1139
1239
|
list,
|
|
1140
|
-
getAllRevisionsByIds,
|
|
1141
1240
|
getLatestRevisionByEntryId,
|
|
1142
1241
|
getPublishedRevisionByEntryId,
|
|
1143
1242
|
getRevisionById,
|