@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.1e66d121db

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