@webiny/api-headless-cms-ddb 5.41.4-beta.4 → 5.41.4-beta.6

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.
@@ -9,9 +9,7 @@ var _error = _interopRequireDefault(require("@webiny/error"));
9
9
  var _dataLoaders = require("./dataLoaders");
10
10
  var _types = require("@webiny/api-headless-cms/types");
11
11
  var _keys = require("./keys");
12
- var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
13
- var _query = require("@webiny/db-dynamodb/utils/query");
14
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
12
+ var _dbDynamodb = require("@webiny/db-dynamodb");
15
13
  var _cursor = require("@webiny/utils/cursor");
16
14
  var _zeroPad = require("@webiny/utils/zeroPad");
17
15
  var _apiHeadlessCms = require("@webiny/api-headless-cms");
@@ -120,29 +118,32 @@ const createEntriesStorageOperations = params => {
120
118
  * - create new main entry item
121
119
  * - create new or update the latest entry item
122
120
  */
123
- const items = [entity.putBatch({
124
- ...storageEntry,
125
- locked,
126
- PK: partitionKey,
127
- SK: (0, _keys.createRevisionSortKey)(entry),
128
- TYPE: createType(),
129
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
130
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
131
- }), entity.putBatch({
132
- ...storageEntry,
133
- locked,
134
- PK: partitionKey,
135
- SK: (0, _keys.createLatestSortKey)(),
136
- TYPE: createLatestType(),
137
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
138
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
139
- })];
121
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
122
+ entity,
123
+ put: [{
124
+ ...storageEntry,
125
+ locked,
126
+ PK: partitionKey,
127
+ SK: (0, _keys.createRevisionSortKey)(entry),
128
+ TYPE: createType(),
129
+ GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
130
+ GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
131
+ }, {
132
+ ...storageEntry,
133
+ locked,
134
+ PK: partitionKey,
135
+ SK: (0, _keys.createLatestSortKey)(),
136
+ TYPE: createLatestType(),
137
+ GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
138
+ GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
139
+ }]
140
+ });
140
141
 
141
142
  /**
142
143
  * We need to create published entry if
143
144
  */
144
145
  if (isPublished) {
145
- items.push(entity.putBatch({
146
+ entityBatch.put({
146
147
  ...storageEntry,
147
148
  locked,
148
149
  PK: partitionKey,
@@ -150,13 +151,10 @@ const createEntriesStorageOperations = params => {
150
151
  TYPE: createLatestType(),
151
152
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
152
153
  GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
153
- }));
154
+ });
154
155
  }
155
156
  try {
156
- await (0, _batchWrite.batchWriteAll)({
157
- table: entity.table,
158
- items
159
- });
157
+ await entityBatch.execute();
160
158
  dataLoaders.clearAll({
161
159
  model
162
160
  });
@@ -192,31 +190,34 @@ const createEntriesStorageOperations = params => {
192
190
  * - update the published entry item to the current one
193
191
  * - unpublish previously published revision (if any)
194
192
  */
195
- const items = [entity.putBatch({
196
- ...storageEntry,
197
- PK: partitionKey,
198
- SK: (0, _keys.createRevisionSortKey)(storageEntry),
199
- TYPE: createType(),
200
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
201
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
202
- }), entity.putBatch({
203
- ...storageEntry,
204
- PK: partitionKey,
205
- SK: (0, _keys.createLatestSortKey)(),
206
- TYPE: createLatestType(),
207
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
208
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
209
- })];
193
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
194
+ entity,
195
+ put: [{
196
+ ...storageEntry,
197
+ PK: partitionKey,
198
+ SK: (0, _keys.createRevisionSortKey)(storageEntry),
199
+ TYPE: createType(),
200
+ GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
201
+ GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
202
+ }, {
203
+ ...storageEntry,
204
+ PK: partitionKey,
205
+ SK: (0, _keys.createLatestSortKey)(),
206
+ TYPE: createLatestType(),
207
+ GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
208
+ GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
209
+ }]
210
+ });
210
211
  const isPublished = entry.status === "published";
211
212
  if (isPublished) {
212
- items.push(entity.putBatch({
213
+ entityBatch.put({
213
214
  ...storageEntry,
214
215
  PK: partitionKey,
215
216
  SK: (0, _keys.createPublishedSortKey)(),
216
217
  TYPE: createPublishedType(),
217
218
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
218
219
  GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
219
- }));
220
+ });
220
221
 
221
222
  // Unpublish previously published revision (if any).
222
223
  const [publishedRevisionStorageEntry] = await dataLoaders.getPublishedRevisionByEntryId({
@@ -224,7 +225,7 @@ const createEntriesStorageOperations = params => {
224
225
  ids: [entry.id]
225
226
  });
226
227
  if (publishedRevisionStorageEntry) {
227
- items.push(entity.putBatch({
228
+ entityBatch.put({
228
229
  ...publishedRevisionStorageEntry,
229
230
  PK: partitionKey,
230
231
  SK: (0, _keys.createRevisionSortKey)(publishedRevisionStorageEntry),
@@ -232,14 +233,11 @@ const createEntriesStorageOperations = params => {
232
233
  status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
233
234
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
234
235
  GSI1_SK: (0, _keys.createGSISortKey)(publishedRevisionStorageEntry)
235
- }));
236
+ });
236
237
  }
237
238
  }
238
239
  try {
239
- await (0, _batchWrite.batchWriteAll)({
240
- table: entity.table,
241
- items
242
- });
240
+ await entityBatch.execute();
243
241
  dataLoaders.clearAll({
244
242
  model
245
243
  });
@@ -268,7 +266,6 @@ const createEntriesStorageOperations = params => {
268
266
  });
269
267
  const isPublished = entry.status === "published";
270
268
  const locked = isPublished ? true : entry.locked;
271
- const items = [];
272
269
  const storageEntry = convertToStorageEntry({
273
270
  model,
274
271
  storageEntry: initialStorageEntry
@@ -278,17 +275,21 @@ const createEntriesStorageOperations = params => {
278
275
  * - update the current entry
279
276
  * - update the latest entry if the current entry is the latest one
280
277
  */
281
- items.push(entity.putBatch({
282
- ...storageEntry,
283
- locked,
284
- PK: partitionKey,
285
- SK: (0, _keys.createRevisionSortKey)(storageEntry),
286
- TYPE: createType(),
287
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
288
- GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
289
- }));
278
+
279
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
280
+ entity,
281
+ put: [{
282
+ ...storageEntry,
283
+ locked,
284
+ PK: partitionKey,
285
+ SK: (0, _keys.createRevisionSortKey)(storageEntry),
286
+ TYPE: createType(),
287
+ GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
288
+ GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
289
+ }]
290
+ });
290
291
  if (isPublished) {
291
- items.push(entity.putBatch({
292
+ entityBatch.put({
292
293
  ...storageEntry,
293
294
  locked,
294
295
  PK: partitionKey,
@@ -296,7 +297,7 @@ const createEntriesStorageOperations = params => {
296
297
  TYPE: createPublishedType(),
297
298
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
298
299
  GSI1_SK: (0, _keys.createGSISortKey)(storageEntry)
299
- }));
300
+ });
300
301
  }
301
302
 
302
303
  /**
@@ -306,7 +307,7 @@ const createEntriesStorageOperations = params => {
306
307
  if (latestStorageEntry) {
307
308
  const updatingLatestRevision = latestStorageEntry.id === entry.id;
308
309
  if (updatingLatestRevision) {
309
- items.push(entity.putBatch({
310
+ entityBatch.put({
310
311
  ...storageEntry,
311
312
  locked,
312
313
  PK: partitionKey,
@@ -314,7 +315,7 @@ const createEntriesStorageOperations = params => {
314
315
  TYPE: createLatestType(),
315
316
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
316
317
  GSI1_SK: (0, _keys.createGSISortKey)(entry)
317
- }));
318
+ });
318
319
  } else {
319
320
  /**
320
321
  * If not updating latest revision, we still want to update the latest revision's
@@ -327,7 +328,7 @@ const createEntriesStorageOperations = params => {
327
328
  * - one for the actual revision record
328
329
  * - one for the latest record
329
330
  */
330
- items.push(entity.putBatch({
331
+ entityBatch.put({
331
332
  ...latestStorageEntry,
332
333
  ...updatedEntryLevelMetaFields,
333
334
  PK: partitionKey,
@@ -335,8 +336,8 @@ const createEntriesStorageOperations = params => {
335
336
  TYPE: createType(),
336
337
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
337
338
  GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
338
- }));
339
- items.push(entity.putBatch({
339
+ });
340
+ entityBatch.put({
340
341
  ...latestStorageEntry,
341
342
  ...updatedEntryLevelMetaFields,
342
343
  PK: partitionKey,
@@ -344,14 +345,11 @@ const createEntriesStorageOperations = params => {
344
345
  TYPE: createLatestType(),
345
346
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
346
347
  GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
347
- }));
348
+ });
348
349
  }
349
350
  }
350
351
  try {
351
- await (0, _batchWrite.batchWriteAll)({
352
- table: entity.table,
353
- items
354
- });
352
+ await entityBatch.execute();
355
353
  dataLoaders.clearAll({
356
354
  model
357
355
  });
@@ -385,27 +383,28 @@ const createEntriesStorageOperations = params => {
385
383
  gte: " "
386
384
  }
387
385
  };
388
- const records = await (0, _query.queryAll)(queryAllParams);
386
+ const records = await (0, _dbDynamodb.queryAll)(queryAllParams);
389
387
  /**
390
388
  * Then create the batch writes for the DynamoDB, with the updated folderId.
391
389
  */
392
- const items = records.map(item => {
393
- return entity.putBatch({
394
- ...item,
395
- location: {
396
- ...item.location,
397
- folderId
398
- }
399
- });
390
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
391
+ entity,
392
+ put: records.map(item => {
393
+ return {
394
+ ...item,
395
+ location: {
396
+ ...item.location,
397
+ folderId
398
+ }
399
+ };
400
+ })
400
401
  });
402
+
401
403
  /**
402
404
  * And finally write it...
403
405
  */
404
406
  try {
405
- await (0, _batchWrite.batchWriteAll)({
406
- table: entity.table,
407
- items
408
- });
407
+ await entityBatch.execute();
409
408
  } catch (ex) {
410
409
  throw _error.default.from(ex, {
411
410
  message: "Could not move records to a new folder.",
@@ -439,13 +438,16 @@ const createEntriesStorageOperations = params => {
439
438
  };
440
439
  let records = [];
441
440
  try {
442
- records = await (0, _query.queryAll)(queryAllParams);
441
+ records = await (0, _dbDynamodb.queryAll)(queryAllParams);
443
442
  } catch (ex) {
444
443
  throw new _error.default(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
445
444
  error: ex,
446
445
  id: entry.id
447
446
  });
448
447
  }
448
+ if (records.length === 0) {
449
+ return;
450
+ }
449
451
  const storageEntry = convertToStorageEntry({
450
452
  model,
451
453
  storageEntry: initialStorageEntry
@@ -459,23 +461,23 @@ const createEntriesStorageOperations = params => {
459
461
  /**
460
462
  * Then create the batch writes for the DynamoDB, with the updated data.
461
463
  */
462
- const items = records.map(record => {
463
- return entity.putBatch({
464
- ...record,
465
- ...updatedDeletedMetaFields,
466
- wbyDeleted: storageEntry.wbyDeleted,
467
- location: storageEntry.location,
468
- binOriginalFolderId: storageEntry.binOriginalFolderId
469
- });
464
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
465
+ entity,
466
+ put: records.map(record => {
467
+ return {
468
+ ...record,
469
+ ...updatedDeletedMetaFields,
470
+ wbyDeleted: storageEntry.wbyDeleted,
471
+ location: storageEntry.location,
472
+ binOriginalFolderId: storageEntry.binOriginalFolderId
473
+ };
474
+ })
470
475
  });
471
476
  /**
472
477
  * And finally write it...
473
478
  */
474
479
  try {
475
- await (0, _batchWrite.batchWriteAll)({
476
- table: entity.table,
477
- items
478
- });
480
+ await entityBatch.execute();
479
481
  } catch (ex) {
480
482
  throw new _error.default(ex.message || "Could not move the entry to the bin.", ex.code || "MOVE_ENTRY_TO_BIN_ERROR", {
481
483
  error: ex,
@@ -503,24 +505,24 @@ const createEntriesStorageOperations = params => {
503
505
  };
504
506
  let records = [];
505
507
  try {
506
- records = await (0, _query.queryAll)(queryAllParams);
508
+ records = await (0, _dbDynamodb.queryAll)(queryAllParams);
507
509
  } catch (ex) {
508
510
  throw new _error.default(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
509
511
  error: ex,
510
512
  id
511
513
  });
512
514
  }
513
- const items = records.map(item => {
514
- return entity.deleteBatch({
515
- PK: item.PK,
516
- SK: item.SK
517
- });
515
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
516
+ entity,
517
+ delete: records.map(item => {
518
+ return {
519
+ PK: item.PK,
520
+ SK: item.SK
521
+ };
522
+ })
518
523
  });
519
524
  try {
520
- await (0, _batchWrite.batchWriteAll)({
521
- table: entity.table,
522
- items
523
- });
525
+ await entityBatch.execute();
524
526
  dataLoaders.clearAll({
525
527
  model
526
528
  });
@@ -555,13 +557,16 @@ const createEntriesStorageOperations = params => {
555
557
  };
556
558
  let records = [];
557
559
  try {
558
- records = await (0, _query.queryAll)(queryAllParams);
560
+ records = await (0, _dbDynamodb.queryAll)(queryAllParams);
559
561
  } catch (ex) {
560
562
  throw new _error.default(ex.message || "Could not load all records.", ex.code || "LOAD_ALL_RECORDS_ERROR", {
561
563
  error: ex,
562
564
  id: entry.id
563
565
  });
564
566
  }
567
+ if (records.length === 0) {
568
+ return initialStorageEntry;
569
+ }
565
570
  const storageEntry = convertToStorageEntry({
566
571
  model,
567
572
  storageEntry: initialStorageEntry
@@ -571,23 +576,24 @@ const createEntriesStorageOperations = params => {
571
576
  * Let's pick the `restored` meta fields from the storage entry.
572
577
  */
573
578
  const updatedRestoredMetaFields = (0, _constants.pickEntryMetaFields)(storageEntry, _constants.isRestoredEntryMetaField);
574
- const items = records.map(record => {
575
- return entity.putBatch({
576
- ...record,
577
- ...updatedRestoredMetaFields,
578
- wbyDeleted: storageEntry.wbyDeleted,
579
- location: storageEntry.location,
580
- binOriginalFolderId: storageEntry.binOriginalFolderId
581
- });
579
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
580
+ entity,
581
+ put: records.map(record => {
582
+ return {
583
+ ...record,
584
+ ...updatedRestoredMetaFields,
585
+ wbyDeleted: storageEntry.wbyDeleted,
586
+ location: storageEntry.location,
587
+ binOriginalFolderId: storageEntry.binOriginalFolderId
588
+ };
589
+ })
582
590
  });
591
+
583
592
  /**
584
593
  * And finally write it...
585
594
  */
586
595
  try {
587
- await (0, _batchWrite.batchWriteAll)({
588
- table: entity.table,
589
- items
590
- });
596
+ await entityBatch.execute();
591
597
  dataLoaders.clearAll({
592
598
  model
593
599
  });
@@ -612,51 +618,51 @@ const createEntriesStorageOperations = params => {
612
618
  locale: model.locale,
613
619
  tenant: model.tenant
614
620
  });
615
- const items = [entity.deleteBatch({
616
- PK: partitionKey,
617
- SK: (0, _keys.createRevisionSortKey)(entry)
618
- })];
621
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
622
+ entity,
623
+ delete: [{
624
+ PK: partitionKey,
625
+ SK: (0, _keys.createRevisionSortKey)(entry)
626
+ }]
627
+ });
619
628
  const publishedStorageEntry = await getPublishedRevisionByEntryId(model, entry);
620
629
 
621
630
  /**
622
631
  * If revision we are deleting is the published one as well, we need to delete those records as well.
623
632
  */
624
633
  if (publishedStorageEntry && entry.id === publishedStorageEntry.id) {
625
- items.push(entity.deleteBatch({
634
+ entityBatch.delete({
626
635
  PK: partitionKey,
627
636
  SK: (0, _keys.createPublishedSortKey)()
628
- }));
637
+ });
629
638
  }
630
639
  if (initialLatestStorageEntry) {
631
640
  const latestStorageEntry = convertToStorageEntry({
632
641
  storageEntry: initialLatestStorageEntry,
633
642
  model
634
643
  });
635
- items.push(entity.putBatch({
644
+ entityBatch.put({
636
645
  ...latestStorageEntry,
637
646
  PK: partitionKey,
638
647
  SK: (0, _keys.createLatestSortKey)(),
639
648
  TYPE: createLatestType(),
640
649
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
641
650
  GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
642
- }));
651
+ });
643
652
 
644
653
  // Do an update on the latest revision. We need to update the latest revision's
645
654
  // entry-level meta fields to match the previous revision's entry-level meta fields.
646
- items.push(entity.putBatch({
655
+ entityBatch.put({
647
656
  ...latestStorageEntry,
648
657
  PK: partitionKey,
649
658
  SK: (0, _keys.createRevisionSortKey)(initialLatestStorageEntry),
650
659
  TYPE: createType(),
651
660
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
652
661
  GSI1_SK: (0, _keys.createGSISortKey)(initialLatestStorageEntry)
653
- }));
662
+ });
654
663
  }
655
664
  try {
656
- await (0, _batchWrite.batchWriteAll)({
657
- table: entity.table,
658
- items
659
- });
665
+ entityBatch.execute();
660
666
  dataLoaders.clearAll({
661
667
  model
662
668
  });
@@ -683,36 +689,30 @@ const createEntriesStorageOperations = params => {
683
689
  /**
684
690
  * Then we need to construct the queries for all the revisions and entries.
685
691
  */
686
- const items = [];
692
+
693
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
694
+ entity
695
+ });
687
696
  for (const id of entries) {
688
- /**
689
- * Latest item.
690
- */
691
- items.push(entity.deleteBatch({
692
- PK: (0, _keys.createPartitionKey)({
693
- id,
694
- locale: model.locale,
695
- tenant: model.tenant
696
- }),
697
+ const partitionKey = (0, _keys.createPartitionKey)({
698
+ id,
699
+ locale: model.locale,
700
+ tenant: model.tenant
701
+ });
702
+ entityBatch.delete({
703
+ PK: partitionKey,
697
704
  SK: "L"
698
- }));
699
- /**
700
- * Published item.
701
- */
702
- items.push(entity.deleteBatch({
703
- PK: (0, _keys.createPartitionKey)({
704
- id,
705
- locale: model.locale,
706
- tenant: model.tenant
707
- }),
705
+ });
706
+ entityBatch.delete({
707
+ PK: partitionKey,
708
708
  SK: "P"
709
- }));
709
+ });
710
710
  }
711
711
  /**
712
712
  * Exact revisions of all the entries
713
713
  */
714
714
  for (const revision of revisions) {
715
- items.push(entity.deleteBatch({
715
+ entityBatch.delete({
716
716
  PK: (0, _keys.createPartitionKey)({
717
717
  id: revision.id,
718
718
  locale: model.locale,
@@ -721,12 +721,9 @@ const createEntriesStorageOperations = params => {
721
721
  SK: (0, _keys.createRevisionSortKey)({
722
722
  version: revision.version
723
723
  })
724
- }));
724
+ });
725
725
  }
726
- await (0, _batchWrite.batchWriteAll)({
727
- table: entity.table,
728
- items
729
- });
726
+ await entityBatch.execute();
730
727
  };
731
728
  const getLatestRevisionByEntryId = async (initialModel, params) => {
732
729
  const model = getStorageOperationsModel(initialModel);
@@ -854,8 +851,8 @@ const createEntriesStorageOperations = params => {
854
851
  }
855
852
  };
856
853
  try {
857
- const result = await (0, _query.queryOne)(queryParams);
858
- const storageEntry = (0, _cleanup.cleanupItem)(entity, result);
854
+ const result = await (0, _dbDynamodb.queryOne)(queryParams);
855
+ const storageEntry = (0, _dbDynamodb.cleanupItem)(entity, result);
859
856
  if (!storageEntry) {
860
857
  return null;
861
858
  }
@@ -895,7 +892,7 @@ const createEntriesStorageOperations = params => {
895
892
  };
896
893
  let storageEntries = [];
897
894
  try {
898
- storageEntries = await (0, _query.queryAll)(queryAllParams);
895
+ storageEntries = await (0, _dbDynamodb.queryAll)(queryAllParams);
899
896
  } catch (ex) {
900
897
  throw new _error.default(ex.message, "QUERY_ENTRIES_ERROR", {
901
898
  error: ex,
@@ -980,7 +977,7 @@ const createEntriesStorageOperations = params => {
980
977
  hasMoreItems,
981
978
  totalCount,
982
979
  cursor,
983
- items: (0, _cleanup.cleanupItems)(entity, slicedItems)
980
+ items: (0, _dbDynamodb.cleanupItems)(entity, slicedItems)
984
981
  };
985
982
  };
986
983
  const get = async (initialModel, params) => {
@@ -1021,21 +1018,24 @@ const createEntriesStorageOperations = params => {
1021
1018
  });
1022
1019
 
1023
1020
  // 1. Update REV# and P records with new data.
1024
- const items = [entity.putBatch({
1025
- ...storageEntry,
1026
- PK: partitionKey,
1027
- SK: (0, _keys.createRevisionSortKey)(entry),
1028
- TYPE: createType(),
1029
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
1030
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
1031
- }), entity.putBatch({
1032
- ...storageEntry,
1033
- PK: partitionKey,
1034
- SK: (0, _keys.createPublishedSortKey)(),
1035
- TYPE: createPublishedType(),
1036
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
1037
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
1038
- })];
1021
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
1022
+ entity,
1023
+ put: [{
1024
+ ...storageEntry,
1025
+ PK: partitionKey,
1026
+ SK: (0, _keys.createRevisionSortKey)(entry),
1027
+ TYPE: createType(),
1028
+ GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
1029
+ GSI1_SK: (0, _keys.createGSISortKey)(entry)
1030
+ }, {
1031
+ ...storageEntry,
1032
+ PK: partitionKey,
1033
+ SK: (0, _keys.createPublishedSortKey)(),
1034
+ TYPE: createPublishedType(),
1035
+ GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "P"),
1036
+ GSI1_SK: (0, _keys.createGSISortKey)(entry)
1037
+ }]
1038
+ });
1039
1039
 
1040
1040
  // 2. When it comes to the latest record, we need to perform a couple of different
1041
1041
  // updates, based on whether the entry being published is the latest revision or not.
@@ -1043,14 +1043,14 @@ const createEntriesStorageOperations = params => {
1043
1043
  const publishingLatestRevision = entry.id === initialLatestStorageEntry.id;
1044
1044
  if (publishingLatestRevision) {
1045
1045
  // 2.1 If we're publishing the latest revision, we first need to update the L record.
1046
- items.push(entity.putBatch({
1046
+ entityBatch.put({
1047
1047
  ...storageEntry,
1048
1048
  PK: partitionKey,
1049
1049
  SK: (0, _keys.createLatestSortKey)(),
1050
1050
  TYPE: createLatestType(),
1051
1051
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
1052
1052
  GSI1_SK: (0, _keys.createGSISortKey)(entry)
1053
- }));
1053
+ });
1054
1054
 
1055
1055
  // 2.2 Additionally, if we have a previously published entry, we need to mark it as unpublished.
1056
1056
  if (publishedRevisionId && publishedRevisionId !== entry.id) {
@@ -1058,7 +1058,7 @@ const createEntriesStorageOperations = params => {
1058
1058
  storageEntry: initialPublishedStorageEntry,
1059
1059
  model
1060
1060
  });
1061
- items.push(entity.putBatch({
1061
+ entityBatch.put({
1062
1062
  ...publishedStorageEntry,
1063
1063
  PK: partitionKey,
1064
1064
  SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry),
@@ -1066,7 +1066,7 @@ const createEntriesStorageOperations = params => {
1066
1066
  status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
1067
1067
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
1068
1068
  GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
1069
- }));
1069
+ });
1070
1070
  }
1071
1071
  } else {
1072
1072
  // 2.3 If the published revision is not the latest one, the situation is a bit
@@ -1089,24 +1089,24 @@ const createEntriesStorageOperations = params => {
1089
1089
  ...updatedEntryLevelMetaFields,
1090
1090
  status: latestRevisionStatus
1091
1091
  };
1092
- items.push(entity.putBatch({
1092
+ entityBatch.put({
1093
1093
  ...latestStorageEntryFields,
1094
1094
  PK: partitionKey,
1095
1095
  SK: (0, _keys.createLatestSortKey)(),
1096
1096
  TYPE: createLatestType(),
1097
1097
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
1098
1098
  GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
1099
- }));
1099
+ });
1100
1100
 
1101
1101
  // 2.3.2 Update REV# record.
1102
- items.push(entity.putBatch({
1102
+ entityBatch.put({
1103
1103
  ...latestStorageEntryFields,
1104
1104
  PK: partitionKey,
1105
1105
  SK: (0, _keys.createRevisionSortKey)(latestStorageEntry),
1106
1106
  TYPE: createType(),
1107
1107
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
1108
1108
  GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
1109
- }));
1109
+ });
1110
1110
 
1111
1111
  // 2.3.3 Finally, if we got a published entry, but it wasn't the latest one, we need to take
1112
1112
  // an extra step and mark it as unpublished.
@@ -1116,7 +1116,7 @@ const createEntriesStorageOperations = params => {
1116
1116
  storageEntry: initialPublishedStorageEntry,
1117
1117
  model
1118
1118
  });
1119
- items.push(entity.putBatch({
1119
+ entityBatch.put({
1120
1120
  ...publishedStorageEntry,
1121
1121
  PK: partitionKey,
1122
1122
  SK: (0, _keys.createRevisionSortKey)(publishedStorageEntry),
@@ -1124,14 +1124,11 @@ const createEntriesStorageOperations = params => {
1124
1124
  status: _types.CONTENT_ENTRY_STATUS.UNPUBLISHED,
1125
1125
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
1126
1126
  GSI1_SK: (0, _keys.createGSISortKey)(publishedStorageEntry)
1127
- }));
1127
+ });
1128
1128
  }
1129
1129
  }
1130
1130
  try {
1131
- await (0, _batchWrite.batchWriteAll)({
1132
- table: entity.table,
1133
- items
1134
- });
1131
+ await entityBatch.execute();
1135
1132
  dataLoaders.clearAll({
1136
1133
  model
1137
1134
  });
@@ -1165,17 +1162,21 @@ const createEntriesStorageOperations = params => {
1165
1162
  * - update current entry revision with new data
1166
1163
  * - update the latest entry status - if entry being unpublished is latest
1167
1164
  */
1168
- const items = [entity.deleteBatch({
1169
- PK: partitionKey,
1170
- SK: (0, _keys.createPublishedSortKey)()
1171
- }), entity.putBatch({
1172
- ...storageEntry,
1173
- PK: partitionKey,
1174
- SK: (0, _keys.createRevisionSortKey)(entry),
1175
- TYPE: createType(),
1176
- GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
1177
- GSI1_SK: (0, _keys.createGSISortKey)(entry)
1178
- })];
1165
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
1166
+ entity,
1167
+ delete: [{
1168
+ PK: partitionKey,
1169
+ SK: (0, _keys.createPublishedSortKey)()
1170
+ }],
1171
+ put: [{
1172
+ ...storageEntry,
1173
+ PK: partitionKey,
1174
+ SK: (0, _keys.createRevisionSortKey)(entry),
1175
+ TYPE: createType(),
1176
+ GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
1177
+ GSI1_SK: (0, _keys.createGSISortKey)(entry)
1178
+ }]
1179
+ });
1179
1180
 
1180
1181
  /**
1181
1182
  * We need the latest entry to see if something needs to be updated alongside the unpublishing one.
@@ -1184,14 +1185,14 @@ const createEntriesStorageOperations = params => {
1184
1185
  if (initialLatestStorageEntry) {
1185
1186
  const unpublishingLatestRevision = entry.id === initialLatestStorageEntry.id;
1186
1187
  if (unpublishingLatestRevision) {
1187
- items.push(entity.putBatch({
1188
+ entityBatch.put({
1188
1189
  ...storageEntry,
1189
1190
  PK: partitionKey,
1190
1191
  SK: (0, _keys.createLatestSortKey)(),
1191
1192
  TYPE: createLatestType(),
1192
1193
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
1193
1194
  GSI1_SK: (0, _keys.createGSISortKey)(entry)
1194
- }));
1195
+ });
1195
1196
  } else {
1196
1197
  const latestStorageEntry = convertToStorageEntry({
1197
1198
  storageEntry: initialLatestStorageEntry,
@@ -1203,7 +1204,7 @@ const createEntriesStorageOperations = params => {
1203
1204
  const updatedEntryLevelMetaFields = (0, _constants.pickEntryMetaFields)(entry, _constants.isEntryLevelEntryMetaField);
1204
1205
 
1205
1206
  // 1. Update actual revision record.
1206
- items.push(entity.putBatch({
1207
+ entityBatch.put({
1207
1208
  ...latestStorageEntry,
1208
1209
  ...updatedEntryLevelMetaFields,
1209
1210
  PK: partitionKey,
@@ -1211,10 +1212,10 @@ const createEntriesStorageOperations = params => {
1211
1212
  TYPE: createType(),
1212
1213
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "A"),
1213
1214
  GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
1214
- }));
1215
+ });
1215
1216
 
1216
1217
  // 2. Update latest record.
1217
- items.push(entity.putBatch({
1218
+ entityBatch.put({
1218
1219
  ...latestStorageEntry,
1219
1220
  ...updatedEntryLevelMetaFields,
1220
1221
  PK: partitionKey,
@@ -1222,14 +1223,11 @@ const createEntriesStorageOperations = params => {
1222
1223
  TYPE: createLatestType(),
1223
1224
  GSI1_PK: (0, _keys.createGSIPartitionKey)(model, "L"),
1224
1225
  GSI1_SK: (0, _keys.createGSISortKey)(latestStorageEntry)
1225
- }));
1226
+ });
1226
1227
  }
1227
1228
  }
1228
1229
  try {
1229
- await (0, _batchWrite.batchWriteAll)({
1230
- table: entity.table,
1231
- items
1232
- });
1230
+ await entityBatch.execute();
1233
1231
  dataLoaders.clearAll({
1234
1232
  model
1235
1233
  });