@webiny/api-headless-cms-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.5e7233243f

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 (152) 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 +5 -2
  6. package/definitions/entry.js.map +1 -0
  7. package/definitions/entryElasticsearch.d.ts +2 -2
  8. package/definitions/entryElasticsearch.js +2 -2
  9. package/definitions/entryElasticsearch.js.map +1 -0
  10. package/definitions/group.d.ts +2 -2
  11. package/definitions/group.js +2 -2
  12. package/definitions/group.js.map +1 -0
  13. package/definitions/model.d.ts +2 -2
  14. package/definitions/model.js +2 -2
  15. package/definitions/model.js.map +1 -0
  16. package/definitions/settings.d.ts +2 -2
  17. package/definitions/settings.js +2 -2
  18. package/definitions/settings.js.map +1 -0
  19. package/definitions/system.d.ts +2 -2
  20. package/definitions/system.js +2 -2
  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 +79 -45
  31. package/dynamoDb/storage/date.js.map +1 -0
  32. package/dynamoDb/storage/longText.d.ts +7 -4
  33. package/dynamoDb/storage/longText.js +71 -53
  34. package/dynamoDb/storage/longText.js.map +1 -0
  35. package/dynamoDb/storage/richText.d.ts +2 -3
  36. package/dynamoDb/storage/richText.js +84 -66
  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.map +1 -0
  46. package/elasticsearch/indexing/dateTimeIndexing.js +15 -1
  47. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -0
  48. package/elasticsearch/indexing/defaultFieldIndexing.js.map +1 -0
  49. package/elasticsearch/indexing/index.js.map +1 -0
  50. package/elasticsearch/indexing/longTextIndexing.js.map +1 -0
  51. package/elasticsearch/indexing/numberIndexing.js.map +1 -0
  52. package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
  53. package/elasticsearch/indexing/objectIndexing.js +32 -9
  54. package/elasticsearch/indexing/objectIndexing.js.map +1 -0
  55. package/elasticsearch/indexing/richTextIndexing.js.map +1 -0
  56. package/elasticsearch/indices/base.d.ts +2 -0
  57. package/elasticsearch/indices/base.js +23 -0
  58. package/elasticsearch/indices/base.js.map +1 -0
  59. package/elasticsearch/indices/index.d.ts +1 -0
  60. package/elasticsearch/indices/index.js +16 -0
  61. package/elasticsearch/indices/index.js.map +1 -0
  62. package/elasticsearch/indices/japanese.d.ts +2 -0
  63. package/elasticsearch/indices/japanese.js +24 -0
  64. package/elasticsearch/indices/japanese.js.map +1 -0
  65. package/elasticsearch/search/index.d.ts +2 -2
  66. package/elasticsearch/search/index.js +3 -5
  67. package/elasticsearch/search/index.js.map +1 -0
  68. package/elasticsearch/search/refSearch.d.ts +2 -3
  69. package/elasticsearch/search/refSearch.js +25 -16
  70. package/elasticsearch/search/refSearch.js.map +1 -0
  71. package/elasticsearch/search/timeSearch.d.ts +2 -3
  72. package/elasticsearch/search/timeSearch.js +22 -14
  73. package/elasticsearch/search/timeSearch.js.map +1 -0
  74. package/helpers/createElasticsearchQueryBody.js +312 -67
  75. package/helpers/createElasticsearchQueryBody.js.map +1 -0
  76. package/helpers/entryIndexHelpers.js +32 -12
  77. package/helpers/entryIndexHelpers.js.map +1 -0
  78. package/helpers/fields.d.ts +4 -62
  79. package/helpers/fields.js +27 -5
  80. package/helpers/fields.js.map +1 -0
  81. package/helpers/index.js.map +1 -0
  82. package/helpers/searchPluginsList.d.ts +2 -2
  83. package/helpers/searchPluginsList.js.map +1 -0
  84. package/helpers/transformValueForSearch.d.ts +5 -2
  85. package/helpers/transformValueForSearch.js +3 -0
  86. package/helpers/transformValueForSearch.js.map +1 -0
  87. package/index.js +61 -23
  88. package/index.js.map +1 -0
  89. package/operations/entry/dataLoaders.d.ts +6 -2
  90. package/operations/entry/dataLoaders.js +26 -6
  91. package/operations/entry/dataLoaders.js.map +1 -0
  92. package/operations/entry/elasticsearchFields.js +3 -0
  93. package/operations/entry/elasticsearchFields.js.map +1 -0
  94. package/operations/entry/index.d.ts +2 -2
  95. package/operations/entry/index.js +475 -162
  96. package/operations/entry/index.js.map +1 -0
  97. package/operations/entry/keys.js.map +1 -0
  98. package/operations/group/index.d.ts +2 -2
  99. package/operations/group/index.js +3 -5
  100. package/operations/group/index.js.map +1 -0
  101. package/operations/model/index.d.ts +2 -2
  102. package/operations/model/index.js +38 -35
  103. package/operations/model/index.js.map +1 -0
  104. package/operations/settings/index.d.ts +2 -2
  105. package/operations/settings/index.js +3 -5
  106. package/operations/settings/index.js.map +1 -0
  107. package/operations/system/index.d.ts +2 -2
  108. package/operations/system/index.js +3 -5
  109. package/operations/system/index.js.map +1 -0
  110. package/package.json +25 -29
  111. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.d.ts +2 -2
  112. package/plugins/CmsEntryElasticsearchBodyModifierPlugin.js.map +1 -0
  113. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +3 -3
  114. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +1 -0
  115. package/plugins/CmsEntryElasticsearchIndexPlugin.d.ts +4 -0
  116. package/plugins/CmsEntryElasticsearchIndexPlugin.js +17 -0
  117. package/plugins/CmsEntryElasticsearchIndexPlugin.js.map +1 -0
  118. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.d.ts +30 -0
  119. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js +43 -0
  120. package/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin.js.map +1 -0
  121. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.d.ts +2 -2
  122. package/plugins/CmsEntryElasticsearchQueryModifierPlugin.js.map +1 -0
  123. package/plugins/CmsEntryElasticsearchSortModifierPlugin.d.ts +2 -2
  124. package/plugins/CmsEntryElasticsearchSortModifierPlugin.js.map +1 -0
  125. package/types.d.ts +2 -32
  126. package/types.js +0 -13
  127. package/types.js.map +1 -0
  128. package/upgrades/index.d.ts +1 -1
  129. package/upgrades/index.js +1 -7
  130. package/upgrades/index.js.map +1 -0
  131. package/helpers/operatorPluginsList.d.ts +0 -7
  132. package/helpers/operatorPluginsList.js +0 -30
  133. package/operations/entry/fields.d.ts +0 -3
  134. package/operations/entry/fields.js +0 -60
  135. package/operations/system/createElasticsearchTemplate.d.ts +0 -5
  136. package/operations/system/createElasticsearchTemplate.js +0 -62
  137. package/upgrades/utils.d.ts +0 -1
  138. package/upgrades/utils.js +0 -16
  139. package/upgrades/v5.0.0/cleanDatabaseRecord.d.ts +0 -6
  140. package/upgrades/v5.0.0/cleanDatabaseRecord.js +0 -16
  141. package/upgrades/v5.0.0/createOldVersionIndiceName.d.ts +0 -2
  142. package/upgrades/v5.0.0/createOldVersionIndiceName.js +0 -12
  143. package/upgrades/v5.0.0/entryValueFixer.d.ts +0 -4
  144. package/upgrades/v5.0.0/entryValueFixer.js +0 -124
  145. package/upgrades/v5.0.0/fieldFinder.d.ts +0 -6
  146. package/upgrades/v5.0.0/fieldFinder.js +0 -42
  147. package/upgrades/v5.0.0/helpers.d.ts +0 -4
  148. package/upgrades/v5.0.0/helpers.js +0 -57
  149. package/upgrades/v5.0.0/index.d.ts +0 -4
  150. package/upgrades/v5.0.0/index.js +0 -232
  151. package/upgrades/v5.8.0/index.d.ts +0 -4
  152. package/upgrades/v5.8.0/index.js +0 -426
@@ -13,13 +13,13 @@ 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,9 +41,9 @@ 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; }
44
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
45
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; }
46
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
47
47
 
48
48
  const createType = () => {
49
49
  return "cms.entry";
@@ -62,7 +62,7 @@ const createPublishedType = () => {
62
62
  exports.createPublishedType = createPublishedType;
63
63
 
64
64
  const getEntryData = entry => {
65
- return _objectSpread(_objectSpread({}, (0, _lodash2.default)(entry, ["PK", "SK", "published", "latest"])), {}, {
65
+ return _objectSpread(_objectSpread({}, (0, _omit.default)(entry, ["PK", "SK", "published", "latest"])), {}, {
66
66
  TYPE: createType(),
67
67
  __type: createType()
68
68
  });
@@ -84,6 +84,34 @@ const getESPublishedEntryData = async (plugins, entry) => {
84
84
  }));
85
85
  };
86
86
 
87
+ const convertToStorageEntry = params => {
88
+ const {
89
+ model,
90
+ entry
91
+ } = params;
92
+ const values = model.convertValueKeyToStorage({
93
+ fields: model.fields,
94
+ values: entry.values
95
+ });
96
+ return _objectSpread(_objectSpread({}, entry), {}, {
97
+ values
98
+ });
99
+ };
100
+
101
+ const convertFromStorageEntry = params => {
102
+ const {
103
+ model,
104
+ entry
105
+ } = params;
106
+ const values = model.convertValueKeyFromStorage({
107
+ fields: model.fields,
108
+ values: entry.values
109
+ });
110
+ return _objectSpread(_objectSpread({}, entry), {}, {
111
+ values
112
+ });
113
+ };
114
+
87
115
  const createEntriesStorageOperations = params => {
88
116
  const {
89
117
  entity,
@@ -97,37 +125,80 @@ const createEntriesStorageOperations = params => {
97
125
 
98
126
  const create = async (model, params) => {
99
127
  const {
100
- entry,
101
- storageEntry
128
+ entry: initialEntry,
129
+ storageEntry: initialStorageEntry
102
130
  } = params;
131
+ const isPublished = initialEntry.status === "published";
132
+ const locked = isPublished ? true : initialEntry.locked;
133
+ const entry = convertToStorageEntry({
134
+ model,
135
+ entry: initialEntry
136
+ });
137
+ const storageEntry = convertToStorageEntry({
138
+ model,
139
+ entry: initialStorageEntry
140
+ });
103
141
  const esEntry = (0, _helpers.prepareEntryToIndex)({
104
142
  plugins,
105
143
  model,
106
- entry: (0, _lodash.default)(entry),
107
- storageEntry: (0, _lodash.default)(storageEntry)
144
+ entry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, entry), {}, {
145
+ locked
146
+ })),
147
+ storageEntry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, storageEntry), {}, {
148
+ locked
149
+ }))
108
150
  });
109
151
 
110
152
  const {
111
153
  index: esIndex
112
- } = _configurations.default.es({
154
+ } = _configurations.configurations.es({
113
155
  model
114
156
  });
115
157
 
116
158
  const esLatestData = await getESLatestEntryData(plugins, esEntry);
159
+ const esPublishedData = await getESPublishedEntryData(plugins, esEntry);
117
160
  const revisionKeys = {
118
- PK: (0, _keys.createPartitionKey)(entry),
161
+ PK: (0, _keys.createPartitionKey)({
162
+ id: entry.id,
163
+ locale: model.locale,
164
+ tenant: model.tenant
165
+ }),
119
166
  SK: (0, _keys.createRevisionSortKey)(entry)
120
167
  };
121
168
  const latestKeys = {
122
- PK: (0, _keys.createPartitionKey)(entry),
169
+ PK: (0, _keys.createPartitionKey)({
170
+ id: entry.id,
171
+ locale: model.locale,
172
+ tenant: model.tenant
173
+ }),
123
174
  SK: (0, _keys.createLatestSortKey)()
124
175
  };
125
- const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), revisionKeys), {}, {
176
+ const publishedKeys = {
177
+ PK: (0, _keys.createPartitionKey)({
178
+ id: entry.id,
179
+ locale: model.locale,
180
+ tenant: model.tenant
181
+ }),
182
+ SK: (0, _keys.createPublishedSortKey)()
183
+ };
184
+ const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), {}, {
185
+ locked
186
+ }, revisionKeys), {}, {
126
187
  TYPE: createType()
127
- })), entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), latestKeys), {}, {
188
+ })), entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), {}, {
189
+ locked
190
+ }, latestKeys), {}, {
128
191
  TYPE: createLatestType()
129
192
  }))];
130
193
 
194
+ if (isPublished) {
195
+ items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), {}, {
196
+ locked
197
+ }, publishedKeys), {}, {
198
+ TYPE: createPublishedType()
199
+ })));
200
+ }
201
+
131
202
  try {
132
203
  await (0, _batchWrite.batchWriteAll)({
133
204
  table: entity.table,
@@ -144,11 +215,23 @@ const createEntriesStorageOperations = params => {
144
215
  });
145
216
  }
146
217
 
147
- try {
148
- await esEntity.put(_objectSpread(_objectSpread({}, latestKeys), {}, {
218
+ const esItems = [esEntity.putBatch(_objectSpread(_objectSpread({}, latestKeys), {}, {
219
+ index: esIndex,
220
+ data: esLatestData
221
+ }))];
222
+
223
+ if (isPublished) {
224
+ esItems.push(esEntity.putBatch(_objectSpread(_objectSpread({}, publishedKeys), {}, {
149
225
  index: esIndex,
150
- data: esLatestData
151
- }));
226
+ data: esPublishedData
227
+ })));
228
+ }
229
+
230
+ try {
231
+ await (0, _batchWrite.batchWriteAll)({
232
+ table: esEntity.table,
233
+ items: esItems
234
+ });
152
235
  } catch (ex) {
153
236
  throw new _error.default(ex.message || "Could not insert entry data into the Elasticsearch DynamoDB table.", ex.code || "CREATE_ES_ENTRY_ERROR", {
154
237
  error: ex,
@@ -157,28 +240,43 @@ const createEntriesStorageOperations = params => {
157
240
  });
158
241
  }
159
242
 
160
- return storageEntry;
243
+ return initialStorageEntry;
161
244
  };
162
245
 
163
246
  const createRevisionFrom = async (model, params) => {
164
247
  const {
165
- originalEntry,
166
- entry,
167
- storageEntry
248
+ entry: initialEntry,
249
+ storageEntry: initialStorageEntry
168
250
  } = params;
251
+ const entry = convertToStorageEntry({
252
+ model,
253
+ entry: initialEntry
254
+ });
255
+ const storageEntry = convertToStorageEntry({
256
+ model,
257
+ entry: initialStorageEntry
258
+ });
169
259
  const revisionKeys = {
170
- PK: (0, _keys.createPartitionKey)(entry),
260
+ PK: (0, _keys.createPartitionKey)({
261
+ id: entry.id,
262
+ locale: model.locale,
263
+ tenant: model.tenant
264
+ }),
171
265
  SK: (0, _keys.createRevisionSortKey)(entry)
172
266
  };
173
267
  const latestKeys = {
174
- PK: (0, _keys.createPartitionKey)(entry),
268
+ PK: (0, _keys.createPartitionKey)({
269
+ id: entry.id,
270
+ locale: model.locale,
271
+ tenant: model.tenant
272
+ }),
175
273
  SK: (0, _keys.createLatestSortKey)()
176
274
  };
177
275
  const esEntry = (0, _helpers.prepareEntryToIndex)({
178
276
  plugins,
179
277
  model,
180
- entry: (0, _lodash.default)(entry),
181
- storageEntry: (0, _lodash.default)(storageEntry)
278
+ entry: (0, _cloneDeep.default)(entry),
279
+ storageEntry: (0, _cloneDeep.default)(storageEntry)
182
280
  });
183
281
  const esLatestData = await getESLatestEntryData(plugins, esEntry);
184
282
  const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
@@ -189,7 +287,7 @@ const createEntriesStorageOperations = params => {
189
287
 
190
288
  const {
191
289
  index
192
- } = _configurations.default.es({
290
+ } = _configurations.configurations.es({
193
291
  model
194
292
  });
195
293
 
@@ -204,7 +302,6 @@ const createEntriesStorageOperations = params => {
204
302
  } catch (ex) {
205
303
  throw new _error.default(ex.message || "Could not create revision from given entry in the DynamoDB table.", ex.code || "CREATE_REVISION_ERROR", {
206
304
  error: ex,
207
- originalEntry,
208
305
  entry,
209
306
  storageEntry
210
307
  });
@@ -222,7 +319,6 @@ const createEntriesStorageOperations = params => {
222
319
  } catch (ex) {
223
320
  throw new _error.default(ex.message || "Could not update latest entry in the DynamoDB Elasticsearch table.", ex.code || "CREATE_REVISION_ERROR", {
224
321
  error: ex,
225
- originalEntry,
226
322
  entry
227
323
  });
228
324
  }
@@ -231,41 +327,94 @@ const createEntriesStorageOperations = params => {
231
327
  */
232
328
 
233
329
 
234
- return storageEntry;
330
+ return initialStorageEntry;
235
331
  };
236
332
 
237
333
  const update = async (model, params) => {
238
334
  const {
239
- originalEntry,
240
- entry,
241
- storageEntry
335
+ entry: initialEntry,
336
+ storageEntry: initialStorageEntry
242
337
  } = params;
338
+ const entry = convertToStorageEntry({
339
+ model,
340
+ entry: initialEntry
341
+ });
342
+ const storageEntry = convertToStorageEntry({
343
+ model,
344
+ entry: initialStorageEntry
345
+ });
346
+ const isPublished = entry.status === "published";
347
+ const locked = isPublished ? true : entry.locked;
243
348
  const revisionKeys = {
244
- PK: (0, _keys.createPartitionKey)(entry),
349
+ PK: (0, _keys.createPartitionKey)({
350
+ id: entry.id,
351
+ locale: model.locale,
352
+ tenant: model.tenant
353
+ }),
245
354
  SK: (0, _keys.createRevisionSortKey)(entry)
246
355
  };
247
356
  const latestKeys = {
248
- PK: (0, _keys.createPartitionKey)(entry),
357
+ PK: (0, _keys.createPartitionKey)({
358
+ id: entry.id,
359
+ locale: model.locale,
360
+ tenant: model.tenant
361
+ }),
249
362
  SK: (0, _keys.createLatestSortKey)()
250
363
  };
364
+ const publishedKeys = {
365
+ PK: (0, _keys.createPartitionKey)({
366
+ id: entry.id,
367
+ locale: model.locale,
368
+ tenant: model.tenant
369
+ }),
370
+ SK: (0, _keys.createPublishedSortKey)()
371
+ };
251
372
  /**
252
373
  * We need the latest entry to check if it needs to be updated.
253
374
  */
254
375
 
255
376
  const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
256
377
  model,
257
- ids: [originalEntry.id]
378
+ ids: [entry.id]
379
+ });
380
+ const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
381
+ model,
382
+ ids: [entry.id]
258
383
  });
259
- const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), revisionKeys), {}, {
384
+ const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), {}, {
385
+ locked
386
+ }, revisionKeys), {}, {
260
387
  TYPE: createType()
261
388
  }))];
389
+
390
+ if (isPublished) {
391
+ items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, storageEntry), {}, {
392
+ locked
393
+ }, publishedKeys), {}, {
394
+ TYPE: createPublishedType()
395
+ })));
396
+ }
397
+
398
+ const esItems = [];
399
+
400
+ const {
401
+ index: esIndex
402
+ } = _configurations.configurations.es({
403
+ model
404
+ });
405
+ /**
406
+ * Variable for the elasticsearch entry so we do not convert it more than once
407
+ */
408
+
409
+
410
+ let esEntry = undefined;
262
411
  /**
263
412
  * If the latest entry is the one being updated, we need to create a new latest entry records.
264
413
  */
265
414
 
266
415
  let elasticsearchLatestData = null;
267
416
 
268
- if (latestStorageEntry.id === originalEntry.id) {
417
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
269
418
  /**
270
419
  * First we update the regular DynamoDB table
271
420
  */
@@ -276,13 +425,57 @@ const createEntriesStorageOperations = params => {
276
425
  * And then update the Elasticsearch table to propagate changes to the Elasticsearch
277
426
  */
278
427
 
279
- const esEntry = (0, _helpers.prepareEntryToIndex)({
428
+ esEntry = (0, _helpers.prepareEntryToIndex)({
280
429
  plugins,
281
430
  model,
282
- entry: (0, _lodash.default)(entry),
283
- storageEntry: (0, _lodash.default)(storageEntry)
431
+ entry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, entry), {}, {
432
+ locked
433
+ })),
434
+ storageEntry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, storageEntry), {}, {
435
+ locked
436
+ }))
284
437
  });
285
438
  elasticsearchLatestData = await getESLatestEntryData(plugins, esEntry);
439
+ esItems.push(esEntity.putBatch(_objectSpread(_objectSpread({}, latestKeys), {}, {
440
+ index: esIndex,
441
+ data: elasticsearchLatestData
442
+ })));
443
+ }
444
+
445
+ let elasticsearchPublishedData = null;
446
+
447
+ if (isPublished && (publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
448
+ if (!elasticsearchLatestData) {
449
+ /**
450
+ * And then update the Elasticsearch table to propagate changes to the Elasticsearch
451
+ */
452
+ if (!esEntry) {
453
+ esEntry = (0, _helpers.prepareEntryToIndex)({
454
+ plugins,
455
+ model,
456
+ entry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, entry), {}, {
457
+ locked
458
+ })),
459
+ storageEntry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, storageEntry), {}, {
460
+ locked
461
+ }))
462
+ });
463
+ }
464
+
465
+ elasticsearchPublishedData = await getESPublishedEntryData(plugins, esEntry);
466
+ } else {
467
+ elasticsearchPublishedData = _objectSpread(_objectSpread({}, elasticsearchLatestData), {}, {
468
+ published: true,
469
+ TYPE: createPublishedType(),
470
+ __type: createPublishedType()
471
+ });
472
+ delete elasticsearchPublishedData.latest;
473
+ }
474
+
475
+ esItems.push(esEntity.putBatch(_objectSpread(_objectSpread({}, publishedKeys), {}, {
476
+ index: esIndex,
477
+ data: elasticsearchPublishedData
478
+ })));
286
479
  }
287
480
 
288
481
  try {
@@ -296,43 +489,39 @@ const createEntriesStorageOperations = params => {
296
489
  } catch (ex) {
297
490
  throw new _error.default(ex.message || "Could not update entry DynamoDB records.", ex.code || "UPDATE_ENTRY_ERROR", {
298
491
  error: ex,
299
- originalEntry,
300
492
  entry,
301
493
  storageEntry
302
494
  });
303
495
  }
304
496
 
305
- if (!elasticsearchLatestData) {
306
- return storageEntry;
497
+ if (esItems.length === 0) {
498
+ return initialStorageEntry;
307
499
  }
308
500
 
309
- const {
310
- index: esIndex
311
- } = _configurations.default.es({
312
- model
313
- });
314
-
315
501
  try {
316
- await esEntity.put(_objectSpread(_objectSpread({}, latestKeys), {}, {
317
- index: esIndex,
318
- data: elasticsearchLatestData
319
- }));
502
+ await (0, _batchWrite.batchWriteAll)({
503
+ table: esEntity.table,
504
+ items: esItems
505
+ });
320
506
  } catch (ex) {
321
- throw new _error.default(ex.message || "Could not update entry DynamoDB Elasticsearch record.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
507
+ throw new _error.default(ex.message || "Could not update entry DynamoDB Elasticsearch records.", ex.code || "UPDATE_ES_ENTRY_ERROR", {
322
508
  error: ex,
323
- originalEntry,
324
509
  entry
325
510
  });
326
511
  }
327
512
 
328
- return storageEntry;
513
+ return initialStorageEntry;
329
514
  };
330
515
 
331
516
  const deleteEntry = async (model, params) => {
332
517
  const {
333
518
  entry
334
519
  } = params;
335
- const partitionKey = (0, _keys.createPartitionKey)(entry);
520
+ const partitionKey = (0, _keys.createPartitionKey)({
521
+ id: entry.id,
522
+ locale: model.locale,
523
+ tenant: model.tenant
524
+ });
336
525
  const items = await (0, _query.queryAll)({
337
526
  entity,
338
527
  partitionKey,
@@ -390,15 +579,19 @@ const createEntriesStorageOperations = params => {
390
579
 
391
580
  const deleteRevision = async (model, params) => {
392
581
  const {
393
- entryToDelete,
394
- entryToSetAsLatest,
395
- storageEntryToSetAsLatest
582
+ entry,
583
+ latestEntry,
584
+ latestStorageEntry
396
585
  } = params;
397
- const partitionKey = (0, _keys.createPartitionKey)(entryToDelete);
586
+ const partitionKey = (0, _keys.createPartitionKey)({
587
+ id: entry.id,
588
+ locale: model.locale,
589
+ tenant: model.tenant
590
+ });
398
591
 
399
592
  const {
400
593
  index
401
- } = _configurations.default.es({
594
+ } = _configurations.configurations.es({
402
595
  model
403
596
  });
404
597
  /**
@@ -408,7 +601,7 @@ const createEntriesStorageOperations = params => {
408
601
 
409
602
  const [publishedStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
410
603
  model,
411
- ids: [entryToDelete.id]
604
+ ids: [entry.id]
412
605
  });
413
606
  /**
414
607
  * We need to delete all existing records of the given entry revision.
@@ -420,14 +613,14 @@ const createEntriesStorageOperations = params => {
420
613
  */
421
614
  entity.deleteBatch({
422
615
  PK: partitionKey,
423
- SK: (0, _keys.createRevisionSortKey)(entryToDelete)
616
+ SK: (0, _keys.createRevisionSortKey)(entry)
424
617
  })];
425
618
  const esItems = [];
426
619
  /**
427
620
  * If revision we are deleting is the published one as well, we need to delete those records as well.
428
621
  */
429
622
 
430
- if (publishedStorageEntry && entryToDelete.id === publishedStorageEntry.id) {
623
+ if ((publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
431
624
  items.push(entity.deleteBatch({
432
625
  PK: partitionKey,
433
626
  SK: (0, _keys.createPublishedSortKey)()
@@ -438,19 +631,19 @@ const createEntriesStorageOperations = params => {
438
631
  }));
439
632
  }
440
633
 
441
- if (entryToSetAsLatest) {
634
+ if (latestEntry && latestStorageEntry) {
442
635
  const esEntry = (0, _helpers.prepareEntryToIndex)({
443
636
  plugins,
444
637
  model,
445
- entry: (0, _lodash.default)(entryToSetAsLatest),
446
- storageEntry: (0, _lodash.default)(storageEntryToSetAsLatest)
638
+ entry: (0, _cloneDeep.default)(latestEntry),
639
+ storageEntry: (0, _cloneDeep.default)(latestStorageEntry)
447
640
  });
448
641
  const esLatestData = await getESLatestEntryData(plugins, esEntry);
449
642
  /**
450
643
  * In the end we need to set the new latest entry
451
644
  */
452
645
 
453
- items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntryToSetAsLatest), {}, {
646
+ items.push(entity.putBatch(_objectSpread(_objectSpread({}, latestStorageEntry), {}, {
454
647
  PK: partitionKey,
455
648
  SK: (0, _keys.createLatestSortKey)(),
456
649
  TYPE: createLatestType()
@@ -474,9 +667,9 @@ const createEntriesStorageOperations = params => {
474
667
  } catch (ex) {
475
668
  throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB table.", ex.code || "DELETE_REVISION_ERROR", {
476
669
  error: ex,
477
- entryToDelete,
478
- entryToSetAsLatest,
479
- storageEntryToSetAsLatest
670
+ entry,
671
+ latestEntry,
672
+ latestStorageEntry
480
673
  });
481
674
  }
482
675
 
@@ -492,15 +685,42 @@ const createEntriesStorageOperations = params => {
492
685
  } catch (ex) {
493
686
  throw new _error.default(ex.message || "Could not batch write entry records to DynamoDB Elasticsearch table.", ex.code || "DELETE_REVISION_ERROR", {
494
687
  error: ex,
495
- entryToDelete,
496
- entryToSetAsLatest,
497
- storageEntryToSetAsLatest
688
+ entry,
689
+ latestEntry,
690
+ latestStorageEntry
498
691
  });
499
692
  }
500
693
  };
501
694
 
502
695
  const list = async (model, params) => {
503
696
  const limit = (0, _limit.createLimit)(params.limit, 50);
697
+
698
+ const {
699
+ index
700
+ } = _configurations.configurations.es({
701
+ model
702
+ });
703
+
704
+ try {
705
+ const result = await elasticsearch.indices.exists({
706
+ index
707
+ });
708
+
709
+ if (!result || !result.body) {
710
+ return {
711
+ hasMoreItems: false,
712
+ totalCount: 0,
713
+ cursor: null,
714
+ items: []
715
+ };
716
+ }
717
+ } catch (ex) {
718
+ throw new _error.default("Could not determine if Elasticsearch index exists.", "ELASTICSEARCH_INDEX_CHECK_ERROR", {
719
+ error: ex,
720
+ index
721
+ });
722
+ }
723
+
504
724
  const body = (0, _helpers.createElasticsearchQueryBody)({
505
725
  model,
506
726
  args: _objectSpread(_objectSpread({}, params), {}, {
@@ -511,12 +731,6 @@ const createEntriesStorageOperations = params => {
511
731
  });
512
732
  let response;
513
733
 
514
- const {
515
- index
516
- } = _configurations.default.es({
517
- model
518
- });
519
-
520
734
  try {
521
735
  response = await elasticsearch.search({
522
736
  index,
@@ -526,7 +740,8 @@ const createEntriesStorageOperations = params => {
526
740
  throw new _error.default(ex.message, ex.code || "ELASTICSEARCH_ERROR", {
527
741
  error: ex,
528
742
  index,
529
- body
743
+ body,
744
+ model
530
745
  });
531
746
  }
532
747
 
@@ -538,6 +753,11 @@ const createEntriesStorageOperations = params => {
538
753
  plugins,
539
754
  model,
540
755
  entries: hits.map(item => item._source)
756
+ }).map(item => {
757
+ return convertFromStorageEntry({
758
+ model,
759
+ entry: item
760
+ });
541
761
  });
542
762
  const hasMoreItems = items.length > limit;
543
763
 
@@ -553,7 +773,7 @@ const createEntriesStorageOperations = params => {
553
773
  */
554
774
 
555
775
 
556
- const cursor = items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) : null;
776
+ const cursor = items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) || null : null;
557
777
  return {
558
778
  hasMoreItems,
559
779
  totalCount: total.value,
@@ -568,19 +788,22 @@ const createEntriesStorageOperations = params => {
568
788
  } = await list(model, _objectSpread(_objectSpread({}, params), {}, {
569
789
  limit: 1
570
790
  }));
571
-
572
- if (items.length === 0) {
573
- return null;
574
- }
575
-
576
- return items.shift();
791
+ return items.shift() || null;
577
792
  };
578
793
 
579
794
  const publish = async (model, params) => {
580
795
  const {
581
- entry,
582
- storageEntry
796
+ entry: initialEntry,
797
+ storageEntry: initialStorageEntry
583
798
  } = params;
799
+ const entry = convertToStorageEntry({
800
+ model,
801
+ entry: initialEntry
802
+ });
803
+ const storageEntry = convertToStorageEntry({
804
+ model,
805
+ entry: initialStorageEntry
806
+ });
584
807
  /**
585
808
  * We need currently published entry to check if need to remove it.
586
809
  */
@@ -590,15 +813,27 @@ const createEntriesStorageOperations = params => {
590
813
  ids: [entry.id]
591
814
  });
592
815
  const revisionKeys = {
593
- PK: (0, _keys.createPartitionKey)(entry),
816
+ PK: (0, _keys.createPartitionKey)({
817
+ id: entry.id,
818
+ locale: model.locale,
819
+ tenant: model.tenant
820
+ }),
594
821
  SK: (0, _keys.createRevisionSortKey)(entry)
595
822
  };
596
823
  const latestKeys = {
597
- PK: (0, _keys.createPartitionKey)(entry),
824
+ PK: (0, _keys.createPartitionKey)({
825
+ id: entry.id,
826
+ locale: model.locale,
827
+ tenant: model.tenant
828
+ }),
598
829
  SK: (0, _keys.createLatestSortKey)()
599
830
  };
600
831
  const publishedKeys = {
601
- PK: (0, _keys.createPartitionKey)(entry),
832
+ PK: (0, _keys.createPartitionKey)({
833
+ id: entry.id,
834
+ locale: model.locale,
835
+ tenant: model.tenant
836
+ }),
602
837
  SK: (0, _keys.createPublishedSortKey)()
603
838
  };
604
839
  let latestEsEntry = null;
@@ -623,11 +858,11 @@ const createEntriesStorageOperations = params => {
623
858
 
624
859
  const {
625
860
  index
626
- } = _configurations.default.es({
861
+ } = _configurations.configurations.es({
627
862
  model
628
863
  });
629
864
 
630
- if (publishedStorageEntry) {
865
+ if (publishedStorageEntry && publishedStorageEntry.id !== entry.id) {
631
866
  /**
632
867
  * If there is a `published` entry already, we need to set it to `unpublished`. We need to
633
868
  * execute two updates: update the previously published entry's status and the published entry record.
@@ -638,7 +873,12 @@ const createEntriesStorageOperations = params => {
638
873
  const [previouslyPublishedEntry] = await dataLoaders.getRevisionById({
639
874
  model,
640
875
  ids: [publishedStorageEntry.id]
641
- });
876
+ }); //
877
+ // const previouslyPublishedEntry = convertToStorageEntry({
878
+ // model,
879
+ // entry: initialPreviouslyPublishedEntry
880
+ // });
881
+
642
882
  items.push(
643
883
  /**
644
884
  * Update currently published entry (unpublish it)
@@ -660,20 +900,27 @@ const createEntriesStorageOperations = params => {
660
900
  TYPE: createPublishedType()
661
901
  })));
662
902
  /**
663
- * We need the latest entry to check if it neds to be updated as well in the Elasticsearch.
903
+ * We need the latest entry to check if it needs to be updated as well in the Elasticsearch.
664
904
  */
665
905
 
666
906
  const [latestStorageEntry] = await dataLoaders.getLatestRevisionByEntryId({
667
907
  model,
668
908
  ids: [entry.id]
669
909
  });
910
+
911
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
912
+ items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), latestKeys)));
913
+ }
670
914
  /**
671
915
  * If we are publishing the latest revision, let's also update the latest revision's status in ES.
672
916
  */
673
917
 
674
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
918
+
919
+ if (latestEsEntry && (latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
675
920
  /**
676
921
  * Need to decompress the data from Elasticsearch DynamoDB table.
922
+ *
923
+ * No need to transform it for the storage because it was fetched directly from the Elasticsearch table, where it sits transformed.
677
924
  */
678
925
  const latestEsEntryDataDecompressed = await (0, _compression.decompress)(plugins, latestEsEntry.data);
679
926
  esItems.push(esEntity.putBatch({
@@ -692,8 +939,8 @@ const createEntriesStorageOperations = params => {
692
939
  const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
693
940
  plugins,
694
941
  model,
695
- entry: (0, _lodash.default)(entry),
696
- storageEntry: (0, _lodash.default)(storageEntry)
942
+ entry: (0, _cloneDeep.default)(entry),
943
+ storageEntry: (0, _cloneDeep.default)(storageEntry)
697
944
  });
698
945
  /**
699
946
  * Update the published revision entry in ES.
@@ -743,14 +990,22 @@ const createEntriesStorageOperations = params => {
743
990
  });
744
991
  }
745
992
 
746
- return storageEntry;
993
+ return initialStorageEntry;
747
994
  };
748
995
 
749
996
  const unpublish = async (model, params) => {
750
997
  const {
751
- entry,
752
- storageEntry
998
+ entry: initialEntry,
999
+ storageEntry: initialStorageEntry
753
1000
  } = params;
1001
+ const entry = convertToStorageEntry({
1002
+ model,
1003
+ entry: initialEntry
1004
+ });
1005
+ const storageEntry = convertToStorageEntry({
1006
+ model,
1007
+ entry: initialStorageEntry
1008
+ });
754
1009
  /**
755
1010
  * We need the latest entry to check if it needs to be updated.
756
1011
  */
@@ -759,7 +1014,11 @@ const createEntriesStorageOperations = params => {
759
1014
  model,
760
1015
  ids: [entry.id]
761
1016
  });
762
- const partitionKey = (0, _keys.createPartitionKey)(entry);
1017
+ const partitionKey = (0, _keys.createPartitionKey)({
1018
+ id: entry.id,
1019
+ locale: model.locale,
1020
+ tenant: model.tenant
1021
+ });
763
1022
  const items = [entity.deleteBatch({
764
1023
  PK: partitionKey,
765
1024
  SK: (0, _keys.createPublishedSortKey)()
@@ -776,18 +1035,18 @@ const createEntriesStorageOperations = params => {
776
1035
  * If we are unpublishing the latest revision, let's also update the latest revision entry's status in ES.
777
1036
  */
778
1037
 
779
- if (latestStorageEntry.id === entry.id) {
1038
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
780
1039
  const {
781
1040
  index
782
- } = _configurations.default.es({
1041
+ } = _configurations.configurations.es({
783
1042
  model
784
1043
  });
785
1044
 
786
1045
  const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
787
1046
  plugins,
788
1047
  model,
789
- entry: (0, _lodash.default)(entry),
790
- storageEntry: (0, _lodash.default)(storageEntry)
1048
+ entry: (0, _cloneDeep.default)(entry),
1049
+ storageEntry: (0, _cloneDeep.default)(storageEntry)
791
1050
  });
792
1051
  const esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
793
1052
  esItems.push(esEntity.putBatch({
@@ -833,15 +1092,22 @@ const createEntriesStorageOperations = params => {
833
1092
  });
834
1093
  }
835
1094
 
836
- return storageEntry;
1095
+ return initialStorageEntry;
837
1096
  };
838
1097
 
839
1098
  const requestReview = async (model, params) => {
840
1099
  const {
841
- entry,
842
- storageEntry,
843
- originalEntry
1100
+ entry: initialEntry,
1101
+ storageEntry: initialStorageEntry
844
1102
  } = params;
1103
+ const entry = convertToStorageEntry({
1104
+ model,
1105
+ entry: initialEntry
1106
+ });
1107
+ const storageEntry = convertToStorageEntry({
1108
+ model,
1109
+ entry: initialStorageEntry
1110
+ });
845
1111
  /**
846
1112
  * We need the latest entry to check if it needs to be updated.
847
1113
  */
@@ -850,7 +1116,11 @@ const createEntriesStorageOperations = params => {
850
1116
  model,
851
1117
  ids: [entry.id]
852
1118
  });
853
- const partitionKey = (0, _keys.createPartitionKey)(entry);
1119
+ const partitionKey = (0, _keys.createPartitionKey)({
1120
+ id: entry.id,
1121
+ locale: model.locale,
1122
+ tenant: model.tenant
1123
+ });
854
1124
  /**
855
1125
  * If we updated the latest version, then make sure the changes are propagated to ES too.
856
1126
  */
@@ -859,16 +1129,16 @@ const createEntriesStorageOperations = params => {
859
1129
 
860
1130
  const {
861
1131
  index
862
- } = _configurations.default.es({
1132
+ } = _configurations.configurations.es({
863
1133
  model
864
1134
  });
865
1135
 
866
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
1136
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
867
1137
  const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
868
1138
  plugins,
869
1139
  model,
870
- entry: (0, _lodash.default)(entry),
871
- storageEntry: (0, _lodash.default)(storageEntry)
1140
+ entry: (0, _cloneDeep.default)(entry),
1141
+ storageEntry: (0, _cloneDeep.default)(storageEntry)
872
1142
  });
873
1143
  esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
874
1144
  }
@@ -885,8 +1155,8 @@ const createEntriesStorageOperations = params => {
885
1155
  } catch (ex) {
886
1156
  throw new _error.default(ex.message || "Could not store request review entry record into DynamoDB table.", ex.code || "REQUEST_REVIEW_ERROR", {
887
1157
  entry,
888
- latestStorageEntry,
889
- originalEntry
1158
+ storageEntry,
1159
+ latestStorageEntry
890
1160
  });
891
1161
  }
892
1162
  /**
@@ -895,7 +1165,7 @@ const createEntriesStorageOperations = params => {
895
1165
 
896
1166
 
897
1167
  if (!esLatestData) {
898
- return storageEntry;
1168
+ return initialStorageEntry;
899
1169
  }
900
1170
 
901
1171
  try {
@@ -908,20 +1178,27 @@ const createEntriesStorageOperations = params => {
908
1178
  } catch (ex) {
909
1179
  throw new _error.default(ex.message || "Could not store request review entry record into DynamoDB Elasticsearch table.", ex.code || "REQUEST_REVIEW_ERROR", {
910
1180
  entry,
911
- latestStorageEntry,
912
- originalEntry
1181
+ storageEntry,
1182
+ latestStorageEntry
913
1183
  });
914
1184
  }
915
1185
 
916
- return storageEntry;
1186
+ return initialStorageEntry;
917
1187
  };
918
1188
 
919
1189
  const requestChanges = async (model, params) => {
920
1190
  const {
921
- entry,
922
- storageEntry,
923
- originalEntry
1191
+ entry: initialEntry,
1192
+ storageEntry: initialStorageEntry
924
1193
  } = params;
1194
+ const entry = convertToStorageEntry({
1195
+ model,
1196
+ entry: initialEntry
1197
+ });
1198
+ const storageEntry = convertToStorageEntry({
1199
+ model,
1200
+ entry: initialStorageEntry
1201
+ });
925
1202
  /**
926
1203
  * We need the latest entry to check if it needs to be updated.
927
1204
  */
@@ -930,7 +1207,11 @@ const createEntriesStorageOperations = params => {
930
1207
  model,
931
1208
  ids: [entry.id]
932
1209
  });
933
- const partitionKey = (0, _keys.createPartitionKey)(entry);
1210
+ const partitionKey = (0, _keys.createPartitionKey)({
1211
+ id: entry.id,
1212
+ locale: model.locale,
1213
+ tenant: model.tenant
1214
+ });
934
1215
  const items = [entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
935
1216
  PK: partitionKey,
936
1217
  SK: (0, _keys.createRevisionSortKey)(entry),
@@ -942,13 +1223,13 @@ const createEntriesStorageOperations = params => {
942
1223
 
943
1224
  const {
944
1225
  index
945
- } = _configurations.default.es({
1226
+ } = _configurations.configurations.es({
946
1227
  model
947
1228
  });
948
1229
 
949
1230
  let esLatestData = null;
950
1231
 
951
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
1232
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
952
1233
  items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
953
1234
  PK: partitionKey,
954
1235
  SK: (0, _keys.createLatestSortKey)(),
@@ -957,8 +1238,8 @@ const createEntriesStorageOperations = params => {
957
1238
  const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
958
1239
  plugins,
959
1240
  model,
960
- entry: (0, _lodash.default)(entry),
961
- storageEntry: (0, _lodash.default)(storageEntry)
1241
+ entry: (0, _cloneDeep.default)(entry),
1242
+ storageEntry: (0, _cloneDeep.default)(storageEntry)
962
1243
  });
963
1244
  esLatestData = await getESLatestEntryData(plugins, preparedEntryData);
964
1245
  }
@@ -974,8 +1255,7 @@ const createEntriesStorageOperations = params => {
974
1255
  } catch (ex) {
975
1256
  throw new _error.default(ex.message || "Could not store request changes entry record into DynamoDB table.", ex.code || "REQUEST_CHANGES_ERROR", {
976
1257
  entry,
977
- latestStorageEntry,
978
- originalEntry
1258
+ latestStorageEntry
979
1259
  });
980
1260
  }
981
1261
  /**
@@ -984,7 +1264,7 @@ const createEntriesStorageOperations = params => {
984
1264
 
985
1265
 
986
1266
  if (!esLatestData) {
987
- return storageEntry;
1267
+ return initialStorageEntry;
988
1268
  }
989
1269
 
990
1270
  try {
@@ -997,86 +1277,111 @@ const createEntriesStorageOperations = params => {
997
1277
  } catch (ex) {
998
1278
  throw new _error.default(ex.message || "Could not store request changes entry record into DynamoDB Elasticsearch table.", ex.code || "REQUEST_CHANGES_ERROR", {
999
1279
  entry,
1000
- latestStorageEntry,
1001
- originalEntry
1280
+ latestStorageEntry
1002
1281
  });
1003
1282
  }
1004
1283
 
1005
- return storageEntry;
1006
- };
1007
-
1008
- const getAllRevisionsByIds = async (model, params) => {
1009
- return await dataLoaders.getAllEntryRevisions({
1010
- model,
1011
- ids: params.ids
1012
- });
1284
+ return initialStorageEntry;
1013
1285
  };
1014
1286
 
1015
1287
  const getLatestRevisionByEntryId = async (model, params) => {
1016
- const result = await dataLoaders.getLatestRevisionByEntryId({
1288
+ const [entry] = await dataLoaders.getLatestRevisionByEntryId({
1017
1289
  model,
1018
1290
  ids: [params.id]
1019
1291
  });
1020
1292
 
1021
- if (result.length === 0) {
1293
+ if (!entry) {
1022
1294
  return null;
1023
1295
  }
1024
1296
 
1025
- return result.shift();
1297
+ return convertFromStorageEntry({
1298
+ model,
1299
+ entry
1300
+ });
1026
1301
  };
1027
1302
 
1028
1303
  const getPublishedRevisionByEntryId = async (model, params) => {
1029
- const result = await dataLoaders.getPublishedRevisionByEntryId({
1304
+ const [entry] = await dataLoaders.getPublishedRevisionByEntryId({
1030
1305
  model,
1031
1306
  ids: [params.id]
1032
1307
  });
1033
1308
 
1034
- if (result.length === 0) {
1309
+ if (!entry) {
1035
1310
  return null;
1036
1311
  }
1037
1312
 
1038
- return result.shift();
1313
+ return convertFromStorageEntry({
1314
+ model,
1315
+ entry
1316
+ });
1039
1317
  };
1040
1318
 
1041
1319
  const getRevisionById = async (model, params) => {
1042
- const result = await dataLoaders.getRevisionById({
1320
+ const [entry] = await dataLoaders.getRevisionById({
1043
1321
  model,
1044
1322
  ids: [params.id]
1045
1323
  });
1046
1324
 
1047
- if (result.length === 0) {
1325
+ if (!entry) {
1048
1326
  return null;
1049
1327
  }
1050
1328
 
1051
- return result.shift();
1329
+ return convertFromStorageEntry({
1330
+ model,
1331
+ entry
1332
+ });
1052
1333
  };
1053
1334
 
1054
1335
  const getRevisions = async (model, params) => {
1055
- return await dataLoaders.getAllEntryRevisions({
1336
+ const entries = await dataLoaders.getAllEntryRevisions({
1056
1337
  model,
1057
1338
  ids: [params.id]
1058
1339
  });
1340
+ return entries.map(entry => {
1341
+ return convertFromStorageEntry({
1342
+ model,
1343
+ entry
1344
+ });
1345
+ });
1059
1346
  };
1060
1347
 
1061
1348
  const getByIds = async (model, params) => {
1062
- return dataLoaders.getRevisionById({
1349
+ const entries = await dataLoaders.getRevisionById({
1063
1350
  model,
1064
1351
  ids: params.ids
1065
1352
  });
1353
+ return entries.map(entry => {
1354
+ return convertFromStorageEntry({
1355
+ model,
1356
+ entry
1357
+ });
1358
+ });
1066
1359
  };
1067
1360
 
1068
1361
  const getLatestByIds = async (model, params) => {
1069
- return dataLoaders.getLatestRevisionByEntryId({
1362
+ const entries = await dataLoaders.getLatestRevisionByEntryId({
1070
1363
  model,
1071
1364
  ids: params.ids
1072
1365
  });
1366
+ return entries.map(entry => {
1367
+ return convertFromStorageEntry({
1368
+ model,
1369
+ entry
1370
+ });
1371
+ });
1073
1372
  };
1074
1373
 
1075
1374
  const getPublishedByIds = async (model, params) => {
1076
- return dataLoaders.getPublishedRevisionByEntryId({
1375
+ const entries = await dataLoaders.getPublishedRevisionByEntryId({
1077
1376
  model,
1078
1377
  ids: params.ids
1079
1378
  });
1379
+ return entries.map(entry => {
1380
+ return convertFromStorageEntry({
1381
+ model,
1382
+ entry
1383
+ });
1384
+ });
1080
1385
  };
1081
1386
 
1082
1387
  const getPreviousRevision = async (model, params) => {
@@ -1114,7 +1419,16 @@ const createEntriesStorageOperations = params => {
1114
1419
 
1115
1420
  try {
1116
1421
  const result = await (0, _query.queryOne)(queryParams);
1117
- return (0, _cleanup.cleanupItem)(entity, result);
1422
+ const entry = (0, _cleanup.cleanupItem)(entity, result);
1423
+
1424
+ if (!entry) {
1425
+ return null;
1426
+ }
1427
+
1428
+ return convertFromStorageEntry({
1429
+ entry,
1430
+ model
1431
+ });
1118
1432
  } catch (ex) {
1119
1433
  throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", _objectSpread(_objectSpread({}, params), {}, {
1120
1434
  error: ex,
@@ -1137,7 +1451,6 @@ const createEntriesStorageOperations = params => {
1137
1451
  requestReview,
1138
1452
  requestChanges,
1139
1453
  list,
1140
- getAllRevisionsByIds,
1141
1454
  getLatestRevisionByEntryId,
1142
1455
  getPublishedRevisionByEntryId,
1143
1456
  getRevisionById,