@webiny/api-headless-cms-ddb-es 5.32.0 → 5.33.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dynamoDb/index.js +4 -6
  2. package/dynamoDb/index.js.map +1 -1
  3. package/dynamoDb/storage/date.d.ts +1 -2
  4. package/dynamoDb/storage/date.js +78 -44
  5. package/dynamoDb/storage/date.js.map +1 -1
  6. package/dynamoDb/storage/longText.d.ts +6 -3
  7. package/dynamoDb/storage/longText.js +68 -55
  8. package/dynamoDb/storage/longText.js.map +1 -1
  9. package/dynamoDb/storage/richText.d.ts +1 -2
  10. package/dynamoDb/storage/richText.js +70 -72
  11. package/dynamoDb/storage/richText.js.map +1 -1
  12. package/elasticsearch/indexing/dateTimeIndexing.js +14 -0
  13. package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
  14. package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
  15. package/elasticsearch/indexing/objectIndexing.js +16 -7
  16. package/elasticsearch/indexing/objectIndexing.js.map +1 -1
  17. package/elasticsearch/search/refSearch.js +2 -2
  18. package/elasticsearch/search/refSearch.js.map +1 -1
  19. package/helpers/createElasticsearchQueryBody.js +74 -15
  20. package/helpers/createElasticsearchQueryBody.js.map +1 -1
  21. package/helpers/entryIndexHelpers.js +8 -8
  22. package/helpers/entryIndexHelpers.js.map +1 -1
  23. package/helpers/fields.d.ts +3 -1
  24. package/helpers/fields.js +27 -5
  25. package/helpers/fields.js.map +1 -1
  26. package/operations/entry/index.js +221 -59
  27. package/operations/entry/index.js.map +1 -1
  28. package/operations/model/index.js +2 -2
  29. package/operations/model/index.js.map +1 -1
  30. package/package.json +14 -14
  31. package/operations/entry/fields.d.ts +0 -3
  32. package/operations/entry/fields.js +0 -69
  33. package/operations/entry/fields.js.map +0 -1
@@ -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,11 +125,19 @@ 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;
103
- const isPublished = entry.status === "published";
104
- const locked = isPublished ? true : entry.locked;
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
+ });
105
141
  const esEntry = (0, _helpers.prepareEntryToIndex)({
106
142
  plugins,
107
143
  model,
@@ -204,14 +240,22 @@ const createEntriesStorageOperations = params => {
204
240
  });
205
241
  }
206
242
 
207
- return storageEntry;
243
+ return initialStorageEntry;
208
244
  };
209
245
 
210
246
  const createRevisionFrom = async (model, params) => {
211
247
  const {
212
- entry,
213
- storageEntry
248
+ entry: initialEntry,
249
+ storageEntry: initialStorageEntry
214
250
  } = params;
251
+ const entry = convertToStorageEntry({
252
+ model,
253
+ entry: initialEntry
254
+ });
255
+ const storageEntry = convertToStorageEntry({
256
+ model,
257
+ entry: initialStorageEntry
258
+ });
215
259
  const revisionKeys = {
216
260
  PK: (0, _keys.createPartitionKey)({
217
261
  id: entry.id,
@@ -283,14 +327,22 @@ const createEntriesStorageOperations = params => {
283
327
  */
284
328
 
285
329
 
286
- return storageEntry;
330
+ return initialStorageEntry;
287
331
  };
288
332
 
289
333
  const update = async (model, params) => {
290
334
  const {
291
- entry,
292
- storageEntry
335
+ entry: initialEntry,
336
+ storageEntry: initialStorageEntry
293
337
  } = params;
338
+ const entry = convertToStorageEntry({
339
+ model,
340
+ entry: initialEntry
341
+ });
342
+ const storageEntry = convertToStorageEntry({
343
+ model,
344
+ entry: initialStorageEntry
345
+ });
294
346
  const isPublished = entry.status === "published";
295
347
  const locked = isPublished ? true : entry.locked;
296
348
  const revisionKeys = {
@@ -351,13 +403,18 @@ const createEntriesStorageOperations = params => {
351
403
  model
352
404
  });
353
405
  /**
354
- * If the latest entry is the one being updated, we need to create a new latest entry records.
406
+ * Variable for the elasticsearch entry so we do not convert it more than once
355
407
  */
356
408
 
357
409
 
410
+ let esEntry = undefined;
411
+ /**
412
+ * If the latest entry is the one being updated, we need to create a new latest entry records.
413
+ */
414
+
358
415
  let elasticsearchLatestData = null;
359
416
 
360
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
417
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
361
418
  /**
362
419
  * First we update the regular DynamoDB table
363
420
  */
@@ -368,7 +425,7 @@ const createEntriesStorageOperations = params => {
368
425
  * And then update the Elasticsearch table to propagate changes to the Elasticsearch
369
426
  */
370
427
 
371
- const esEntry = (0, _helpers.prepareEntryToIndex)({
428
+ esEntry = (0, _helpers.prepareEntryToIndex)({
372
429
  plugins,
373
430
  model,
374
431
  entry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, entry), {}, {
@@ -387,21 +444,24 @@ const createEntriesStorageOperations = params => {
387
444
 
388
445
  let elasticsearchPublishedData = null;
389
446
 
390
- if (isPublished && publishedStorageEntry && publishedStorageEntry.id === entry.id) {
447
+ if (isPublished && (publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
391
448
  if (!elasticsearchLatestData) {
392
449
  /**
393
450
  * And then update the Elasticsearch table to propagate changes to the Elasticsearch
394
451
  */
395
- const esEntry = (0, _helpers.prepareEntryToIndex)({
396
- plugins,
397
- model,
398
- entry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, entry), {}, {
399
- locked
400
- })),
401
- storageEntry: (0, _cloneDeep.default)(_objectSpread(_objectSpread({}, storageEntry), {}, {
402
- locked
403
- }))
404
- });
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
+
405
465
  elasticsearchPublishedData = await getESPublishedEntryData(plugins, esEntry);
406
466
  } else {
407
467
  elasticsearchPublishedData = _objectSpread(_objectSpread({}, elasticsearchLatestData), {}, {
@@ -435,7 +495,7 @@ const createEntriesStorageOperations = params => {
435
495
  }
436
496
 
437
497
  if (esItems.length === 0) {
438
- return storageEntry;
498
+ return initialStorageEntry;
439
499
  }
440
500
 
441
501
  try {
@@ -450,7 +510,7 @@ const createEntriesStorageOperations = params => {
450
510
  });
451
511
  }
452
512
 
453
- return storageEntry;
513
+ return initialStorageEntry;
454
514
  };
455
515
 
456
516
  const deleteEntry = async (model, params) => {
@@ -560,7 +620,7 @@ const createEntriesStorageOperations = params => {
560
620
  * If revision we are deleting is the published one as well, we need to delete those records as well.
561
621
  */
562
622
 
563
- if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
623
+ if ((publishedStorageEntry === null || publishedStorageEntry === void 0 ? void 0 : publishedStorageEntry.id) === entry.id) {
564
624
  items.push(entity.deleteBatch({
565
625
  PK: partitionKey,
566
626
  SK: (0, _keys.createPublishedSortKey)()
@@ -680,7 +740,8 @@ const createEntriesStorageOperations = params => {
680
740
  throw new _error.default(ex.message, ex.code || "ELASTICSEARCH_ERROR", {
681
741
  error: ex,
682
742
  index,
683
- body
743
+ body,
744
+ model
684
745
  });
685
746
  }
686
747
 
@@ -692,6 +753,11 @@ const createEntriesStorageOperations = params => {
692
753
  plugins,
693
754
  model,
694
755
  entries: hits.map(item => item._source)
756
+ }).map(item => {
757
+ return convertFromStorageEntry({
758
+ model,
759
+ entry: item
760
+ });
695
761
  });
696
762
  const hasMoreItems = items.length > limit;
697
763
 
@@ -727,9 +793,17 @@ const createEntriesStorageOperations = params => {
727
793
 
728
794
  const publish = async (model, params) => {
729
795
  const {
730
- entry,
731
- storageEntry
796
+ entry: initialEntry,
797
+ storageEntry: initialStorageEntry
732
798
  } = params;
799
+ const entry = convertToStorageEntry({
800
+ model,
801
+ entry: initialEntry
802
+ });
803
+ const storageEntry = convertToStorageEntry({
804
+ model,
805
+ entry: initialStorageEntry
806
+ });
733
807
  /**
734
808
  * We need currently published entry to check if need to remove it.
735
809
  */
@@ -799,7 +873,12 @@ const createEntriesStorageOperations = params => {
799
873
  const [previouslyPublishedEntry] = await dataLoaders.getRevisionById({
800
874
  model,
801
875
  ids: [publishedStorageEntry.id]
802
- });
876
+ }); //
877
+ // const previouslyPublishedEntry = convertToStorageEntry({
878
+ // model,
879
+ // entry: initialPreviouslyPublishedEntry
880
+ // });
881
+
803
882
  items.push(
804
883
  /**
805
884
  * Update currently published entry (unpublish it)
@@ -829,7 +908,7 @@ const createEntriesStorageOperations = params => {
829
908
  ids: [entry.id]
830
909
  });
831
910
 
832
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
911
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
833
912
  items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), latestKeys)));
834
913
  }
835
914
  /**
@@ -837,9 +916,11 @@ const createEntriesStorageOperations = params => {
837
916
  */
838
917
 
839
918
 
840
- if (latestEsEntry && latestStorageEntry && latestStorageEntry.id === entry.id) {
919
+ if (latestEsEntry && (latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
841
920
  /**
842
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.
843
924
  */
844
925
  const latestEsEntryDataDecompressed = await (0, _compression.decompress)(plugins, latestEsEntry.data);
845
926
  esItems.push(esEntity.putBatch({
@@ -909,14 +990,22 @@ const createEntriesStorageOperations = params => {
909
990
  });
910
991
  }
911
992
 
912
- return storageEntry;
993
+ return initialStorageEntry;
913
994
  };
914
995
 
915
996
  const unpublish = async (model, params) => {
916
997
  const {
917
- entry,
918
- storageEntry
998
+ entry: initialEntry,
999
+ storageEntry: initialStorageEntry
919
1000
  } = params;
1001
+ const entry = convertToStorageEntry({
1002
+ model,
1003
+ entry: initialEntry
1004
+ });
1005
+ const storageEntry = convertToStorageEntry({
1006
+ model,
1007
+ entry: initialStorageEntry
1008
+ });
920
1009
  /**
921
1010
  * We need the latest entry to check if it needs to be updated.
922
1011
  */
@@ -946,7 +1035,7 @@ const createEntriesStorageOperations = params => {
946
1035
  * If we are unpublishing the latest revision, let's also update the latest revision entry's status in ES.
947
1036
  */
948
1037
 
949
- if (latestStorageEntry.id === entry.id) {
1038
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
950
1039
  const {
951
1040
  index
952
1041
  } = _configurations.configurations.es({
@@ -1003,14 +1092,22 @@ const createEntriesStorageOperations = params => {
1003
1092
  });
1004
1093
  }
1005
1094
 
1006
- return storageEntry;
1095
+ return initialStorageEntry;
1007
1096
  };
1008
1097
 
1009
1098
  const requestReview = async (model, params) => {
1010
1099
  const {
1011
- entry,
1012
- storageEntry
1100
+ entry: initialEntry,
1101
+ storageEntry: initialStorageEntry
1013
1102
  } = params;
1103
+ const entry = convertToStorageEntry({
1104
+ model,
1105
+ entry: initialEntry
1106
+ });
1107
+ const storageEntry = convertToStorageEntry({
1108
+ model,
1109
+ entry: initialStorageEntry
1110
+ });
1014
1111
  /**
1015
1112
  * We need the latest entry to check if it needs to be updated.
1016
1113
  */
@@ -1036,7 +1133,7 @@ const createEntriesStorageOperations = params => {
1036
1133
  model
1037
1134
  });
1038
1135
 
1039
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
1136
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
1040
1137
  const preparedEntryData = (0, _helpers.prepareEntryToIndex)({
1041
1138
  plugins,
1042
1139
  model,
@@ -1068,7 +1165,7 @@ const createEntriesStorageOperations = params => {
1068
1165
 
1069
1166
 
1070
1167
  if (!esLatestData) {
1071
- return storageEntry;
1168
+ return initialStorageEntry;
1072
1169
  }
1073
1170
 
1074
1171
  try {
@@ -1086,14 +1183,22 @@ const createEntriesStorageOperations = params => {
1086
1183
  });
1087
1184
  }
1088
1185
 
1089
- return storageEntry;
1186
+ return initialStorageEntry;
1090
1187
  };
1091
1188
 
1092
1189
  const requestChanges = async (model, params) => {
1093
1190
  const {
1094
- entry,
1095
- storageEntry
1191
+ entry: initialEntry,
1192
+ storageEntry: initialStorageEntry
1096
1193
  } = params;
1194
+ const entry = convertToStorageEntry({
1195
+ model,
1196
+ entry: initialEntry
1197
+ });
1198
+ const storageEntry = convertToStorageEntry({
1199
+ model,
1200
+ entry: initialStorageEntry
1201
+ });
1097
1202
  /**
1098
1203
  * We need the latest entry to check if it needs to be updated.
1099
1204
  */
@@ -1124,7 +1229,7 @@ const createEntriesStorageOperations = params => {
1124
1229
 
1125
1230
  let esLatestData = null;
1126
1231
 
1127
- if (latestStorageEntry && latestStorageEntry.id === entry.id) {
1232
+ if ((latestStorageEntry === null || latestStorageEntry === void 0 ? void 0 : latestStorageEntry.id) === entry.id) {
1128
1233
  items.push(entity.putBatch(_objectSpread(_objectSpread({}, storageEntry), {}, {
1129
1234
  PK: partitionKey,
1130
1235
  SK: (0, _keys.createLatestSortKey)(),
@@ -1159,7 +1264,7 @@ const createEntriesStorageOperations = params => {
1159
1264
 
1160
1265
 
1161
1266
  if (!esLatestData) {
1162
- return storageEntry;
1267
+ return initialStorageEntry;
1163
1268
  }
1164
1269
 
1165
1270
  try {
@@ -1176,59 +1281,107 @@ const createEntriesStorageOperations = params => {
1176
1281
  });
1177
1282
  }
1178
1283
 
1179
- return storageEntry;
1284
+ return initialStorageEntry;
1180
1285
  };
1181
1286
 
1182
1287
  const getLatestRevisionByEntryId = async (model, params) => {
1183
- const result = await dataLoaders.getLatestRevisionByEntryId({
1288
+ const [entry] = await dataLoaders.getLatestRevisionByEntryId({
1184
1289
  model,
1185
1290
  ids: [params.id]
1186
1291
  });
1187
- return result.shift() || null;
1292
+
1293
+ if (!entry) {
1294
+ return null;
1295
+ }
1296
+
1297
+ return convertFromStorageEntry({
1298
+ model,
1299
+ entry
1300
+ });
1188
1301
  };
1189
1302
 
1190
1303
  const getPublishedRevisionByEntryId = async (model, params) => {
1191
- const result = await dataLoaders.getPublishedRevisionByEntryId({
1304
+ const [entry] = await dataLoaders.getPublishedRevisionByEntryId({
1192
1305
  model,
1193
1306
  ids: [params.id]
1194
1307
  });
1195
- return result.shift() || null;
1308
+
1309
+ if (!entry) {
1310
+ return null;
1311
+ }
1312
+
1313
+ return convertFromStorageEntry({
1314
+ model,
1315
+ entry
1316
+ });
1196
1317
  };
1197
1318
 
1198
1319
  const getRevisionById = async (model, params) => {
1199
- const result = await dataLoaders.getRevisionById({
1320
+ const [entry] = await dataLoaders.getRevisionById({
1200
1321
  model,
1201
1322
  ids: [params.id]
1202
1323
  });
1203
- return result.shift() || null;
1324
+
1325
+ if (!entry) {
1326
+ return null;
1327
+ }
1328
+
1329
+ return convertFromStorageEntry({
1330
+ model,
1331
+ entry
1332
+ });
1204
1333
  };
1205
1334
 
1206
1335
  const getRevisions = async (model, params) => {
1207
- return await dataLoaders.getAllEntryRevisions({
1336
+ const entries = await dataLoaders.getAllEntryRevisions({
1208
1337
  model,
1209
1338
  ids: [params.id]
1210
1339
  });
1340
+ return entries.map(entry => {
1341
+ return convertFromStorageEntry({
1342
+ model,
1343
+ entry
1344
+ });
1345
+ });
1211
1346
  };
1212
1347
 
1213
1348
  const getByIds = async (model, params) => {
1214
- return dataLoaders.getRevisionById({
1349
+ const entries = await dataLoaders.getRevisionById({
1215
1350
  model,
1216
1351
  ids: params.ids
1217
1352
  });
1353
+ return entries.map(entry => {
1354
+ return convertFromStorageEntry({
1355
+ model,
1356
+ entry
1357
+ });
1358
+ });
1218
1359
  };
1219
1360
 
1220
1361
  const getLatestByIds = async (model, params) => {
1221
- return dataLoaders.getLatestRevisionByEntryId({
1362
+ const entries = await dataLoaders.getLatestRevisionByEntryId({
1222
1363
  model,
1223
1364
  ids: params.ids
1224
1365
  });
1366
+ return entries.map(entry => {
1367
+ return convertFromStorageEntry({
1368
+ model,
1369
+ entry
1370
+ });
1371
+ });
1225
1372
  };
1226
1373
 
1227
1374
  const getPublishedByIds = async (model, params) => {
1228
- return dataLoaders.getPublishedRevisionByEntryId({
1375
+ const entries = await dataLoaders.getPublishedRevisionByEntryId({
1229
1376
  model,
1230
1377
  ids: params.ids
1231
1378
  });
1379
+ return entries.map(entry => {
1380
+ return convertFromStorageEntry({
1381
+ model,
1382
+ entry
1383
+ });
1384
+ });
1232
1385
  };
1233
1386
 
1234
1387
  const getPreviousRevision = async (model, params) => {
@@ -1266,7 +1419,16 @@ const createEntriesStorageOperations = params => {
1266
1419
 
1267
1420
  try {
1268
1421
  const result = await (0, _query.queryOne)(queryParams);
1269
- 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
+ });
1270
1432
  } catch (ex) {
1271
1433
  throw new _error.default(ex.message || "Could not get previous version of given entry.", ex.code || "GET_PREVIOUS_VERSION_ERROR", _objectSpread(_objectSpread({}, params), {}, {
1272
1434
  error: ex,