@webiny/api-form-builder-so-ddb 0.0.0-unstable.fcdad0bc61 → 0.0.0-unstable.fdd9228b5d

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 (45) hide show
  1. package/definitions/form.d.ts +4 -3
  2. package/definitions/form.js +9 -13
  3. package/definitions/form.js.map +1 -1
  4. package/definitions/settings.d.ts +4 -3
  5. package/definitions/settings.js +8 -12
  6. package/definitions/settings.js.map +1 -1
  7. package/definitions/submission.d.ts +4 -3
  8. package/definitions/submission.js +8 -12
  9. package/definitions/submission.js.map +1 -1
  10. package/definitions/system.d.ts +4 -3
  11. package/definitions/system.js +8 -12
  12. package/definitions/system.js.map +1 -1
  13. package/definitions/table.d.ts +4 -4
  14. package/definitions/table.js +7 -6
  15. package/definitions/table.js.map +1 -1
  16. package/index.d.ts +2 -1
  17. package/index.js +49 -47
  18. package/index.js.map +1 -1
  19. package/operations/form/fields.js +2 -3
  20. package/operations/form/fields.js.map +1 -1
  21. package/operations/form/index.d.ts +4 -4
  22. package/operations/form/index.js +119 -166
  23. package/operations/form/index.js.map +1 -1
  24. package/operations/settings/index.d.ts +3 -3
  25. package/operations/settings/index.js +22 -26
  26. package/operations/settings/index.js.map +1 -1
  27. package/operations/submission/fields.js +2 -3
  28. package/operations/submission/fields.js.map +1 -1
  29. package/operations/submission/index.d.ts +4 -4
  30. package/operations/submission/index.js +27 -44
  31. package/operations/submission/index.js.map +1 -1
  32. package/operations/system/index.d.ts +3 -3
  33. package/operations/system/index.js +18 -23
  34. package/operations/system/index.js.map +1 -1
  35. package/package.json +19 -25
  36. package/plugins/FormDynamoDbFieldPlugin.js +5 -9
  37. package/plugins/FormDynamoDbFieldPlugin.js.map +1 -1
  38. package/plugins/FormSubmissionDynamoDbFieldPlugin.js +5 -9
  39. package/plugins/FormSubmissionDynamoDbFieldPlugin.js.map +1 -1
  40. package/plugins/index.d.ts +2 -0
  41. package/plugins/index.js +29 -0
  42. package/plugins/index.js.map +1 -0
  43. package/types.d.ts +9 -11
  44. package/types.js +5 -5
  45. package/types.js.map +1 -1
@@ -1,9 +1,9 @@
1
- import { Entity, Table } from "dynamodb-toolbox";
2
- import { PluginsContainer } from "@webiny/plugins";
3
- import { FormBuilderFormStorageOperations } from "../../types";
1
+ import type { Entity, Table } from "@webiny/db-dynamodb/toolbox";
2
+ import type { PluginsContainer } from "@webiny/plugins";
3
+ import type { FormBuilderFormStorageOperations } from "../../types";
4
4
  export interface CreateFormStorageOperationsParams {
5
5
  entity: Entity<any>;
6
- table: Table;
6
+ table: Table<string, string, string>;
7
7
  plugins: PluginsContainer;
8
8
  }
9
9
  export declare const createFormStorageOperations: (params: CreateFormStorageOperationsParams) => FormBuilderFormStorageOperations;
@@ -1,42 +1,25 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createFormStorageOperations = void 0;
9
-
10
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
8
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
9
  var _query = require("@webiny/db-dynamodb/utils/query");
15
-
16
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
-
18
- var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
19
-
10
+ var _dbDynamodb = require("@webiny/db-dynamodb");
20
11
  var _filter = require("@webiny/db-dynamodb/utils/filter");
21
-
22
12
  var _sort = require("@webiny/db-dynamodb/utils/sort");
23
-
24
13
  var _utils = require("@webiny/utils");
25
-
26
14
  var _FormDynamoDbFieldPlugin = require("../../plugins/FormDynamoDbFieldPlugin");
27
-
28
15
  var _cursor = require("@webiny/db-dynamodb/utils/cursor");
29
-
30
16
  var _get = require("@webiny/db-dynamodb/utils/get");
31
-
32
17
  const createFormStorageOperations = params => {
33
18
  const {
34
19
  entity,
35
- table,
36
20
  plugins
37
21
  } = params;
38
22
  const formDynamoDbFields = plugins.byType(_FormDynamoDbFieldPlugin.FormDynamoDbFieldPlugin.type);
39
-
40
23
  const createFormPartitionKey = params => {
41
24
  const {
42
25
  tenant,
@@ -44,15 +27,12 @@ const createFormStorageOperations = params => {
44
27
  } = params;
45
28
  return `T#${tenant}#L#${locale}#FB#F`;
46
29
  };
47
-
48
30
  const createFormLatestPartitionKey = params => {
49
31
  return `${createFormPartitionKey(params)}#L`;
50
32
  };
51
-
52
33
  const createFormLatestPublishedPartitionKey = params => {
53
34
  return `${createFormPartitionKey(params)}#LP`;
54
35
  };
55
-
56
36
  const createFormGSIPartitionKey = params => {
57
37
  const {
58
38
  tenant,
@@ -64,13 +44,11 @@ const createFormStorageOperations = params => {
64
44
  } = (0, _utils.parseIdentifier)(targetId);
65
45
  return `T#${tenant}#L#${locale}#FB#F#${id}`;
66
46
  };
67
-
68
47
  const createRevisionSortKey = ({
69
48
  id
70
49
  }) => {
71
50
  return `${id}`;
72
51
  };
73
-
74
52
  const createFormLatestSortKey = ({
75
53
  id,
76
54
  formId
@@ -78,7 +56,6 @@ const createFormStorageOperations = params => {
78
56
  const value = (0, _utils.parseIdentifier)(id || formId);
79
57
  return value.id;
80
58
  };
81
-
82
59
  const createLatestPublishedSortKey = ({
83
60
  id,
84
61
  formId
@@ -86,51 +63,42 @@ const createFormStorageOperations = params => {
86
63
  const value = (0, _utils.parseIdentifier)(id || formId);
87
64
  return value.id;
88
65
  };
89
-
90
66
  const createGSISortKey = version => {
91
67
  return `${version}`;
92
68
  };
93
-
94
69
  const createFormType = () => {
95
70
  return "fb.form";
96
71
  };
97
-
98
72
  const createFormLatestType = () => {
99
73
  return "fb.form.latest";
100
74
  };
101
-
102
75
  const createFormLatestPublishedType = () => {
103
76
  return "fb.form.latestPublished";
104
77
  };
105
-
106
78
  const createRevisionKeys = form => {
107
79
  return {
108
80
  PK: createFormPartitionKey(form),
109
81
  SK: createRevisionSortKey(form)
110
82
  };
111
83
  };
112
-
113
84
  const createLatestKeys = form => {
114
85
  return {
115
86
  PK: createFormLatestPartitionKey(form),
116
87
  SK: createFormLatestSortKey(form)
117
88
  };
118
89
  };
119
-
120
90
  const createLatestPublishedKeys = form => {
121
91
  return {
122
92
  PK: createFormLatestPublishedPartitionKey(form),
123
93
  SK: createLatestPublishedSortKey(form)
124
94
  };
125
95
  };
126
-
127
96
  const createGSIKeys = form => {
128
97
  return {
129
98
  GSI1_PK: createFormGSIPartitionKey(form),
130
99
  GSI1_SK: createGSISortKey(form.version)
131
100
  };
132
101
  };
133
-
134
102
  const createForm = async params => {
135
103
  const {
136
104
  form
@@ -138,17 +106,21 @@ const createFormStorageOperations = params => {
138
106
  const revisionKeys = createRevisionKeys(form);
139
107
  const latestKeys = createLatestKeys(form);
140
108
  const gsiKeys = createGSIKeys(form);
141
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
142
- TYPE: createFormType()
143
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
144
- TYPE: createFormLatestType()
145
- }))];
146
-
109
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
110
+ entity,
111
+ put: [{
112
+ ...form,
113
+ ...revisionKeys,
114
+ ...gsiKeys,
115
+ TYPE: createFormType()
116
+ }, {
117
+ ...form,
118
+ ...latestKeys,
119
+ TYPE: createFormLatestType()
120
+ }]
121
+ });
147
122
  try {
148
- await (0, _batchWrite.batchWriteAll)({
149
- table,
150
- items
151
- });
123
+ await entityBatch.execute();
152
124
  } catch (ex) {
153
125
  throw new _error.default(ex.message || "Could not insert form data into table.", ex.code || "CREATE_FORM_ERROR", {
154
126
  revisionKeys,
@@ -156,10 +128,8 @@ const createFormStorageOperations = params => {
156
128
  form
157
129
  });
158
130
  }
159
-
160
131
  return form;
161
132
  };
162
-
163
133
  const createFormFrom = async params => {
164
134
  const {
165
135
  form,
@@ -169,17 +139,21 @@ const createFormStorageOperations = params => {
169
139
  const revisionKeys = createRevisionKeys(form);
170
140
  const latestKeys = createLatestKeys(form);
171
141
  const gsiKeys = createGSIKeys(form);
172
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
173
- TYPE: createFormType()
174
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
175
- TYPE: createFormLatestType()
176
- }))];
177
-
142
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
143
+ entity,
144
+ put: [{
145
+ ...form,
146
+ ...revisionKeys,
147
+ ...gsiKeys,
148
+ TYPE: createFormType()
149
+ }, {
150
+ ...form,
151
+ ...latestKeys,
152
+ TYPE: createFormLatestType()
153
+ }]
154
+ });
178
155
  try {
179
- await (0, _batchWrite.batchWriteAll)({
180
- table,
181
- items
182
- });
156
+ await entityBatch.execute();
183
157
  } catch (ex) {
184
158
  throw new _error.default(ex.message || "Could not create form data in the table, from existing form.", ex.code || "CREATE_FORM_FROM_ERROR", {
185
159
  revisionKeys,
@@ -189,10 +163,8 @@ const createFormStorageOperations = params => {
189
163
  latest
190
164
  });
191
165
  }
192
-
193
166
  return form;
194
167
  };
195
-
196
168
  const updateForm = async params => {
197
169
  const {
198
170
  form,
@@ -215,21 +187,24 @@ const createFormStorageOperations = params => {
215
187
  }
216
188
  });
217
189
  const isLatestForm = latestForm ? latestForm.id === form.id : false;
218
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
219
- TYPE: createFormType()
220
- }))];
221
-
190
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
191
+ entity,
192
+ put: [{
193
+ ...form,
194
+ ...revisionKeys,
195
+ ...gsiKeys,
196
+ TYPE: createFormType()
197
+ }]
198
+ });
222
199
  if (isLatestForm) {
223
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
200
+ entityBatch.put({
201
+ ...form,
202
+ ...latestKeys,
224
203
  TYPE: createFormLatestType()
225
- })));
204
+ });
226
205
  }
227
-
228
206
  try {
229
- await (0, _batchWrite.batchWriteAll)({
230
- table,
231
- items
232
- });
207
+ await entityBatch.execute();
233
208
  } catch (ex) {
234
209
  throw new _error.default(ex.message || "Could not update form data in the table.", ex.code || "UPDATE_FORM_ERROR", {
235
210
  revisionKeys,
@@ -239,10 +214,8 @@ const createFormStorageOperations = params => {
239
214
  latestForm
240
215
  });
241
216
  }
242
-
243
217
  return form;
244
218
  };
245
-
246
219
  const getForm = async params => {
247
220
  const {
248
221
  where
@@ -254,14 +227,11 @@ const createFormStorageOperations = params => {
254
227
  published,
255
228
  version
256
229
  } = where;
257
-
258
230
  if (latest && published) {
259
231
  throw new _error.default("Cannot have both latest and published params.");
260
232
  }
261
-
262
233
  let partitionKey;
263
234
  let sortKey;
264
-
265
235
  if (latest) {
266
236
  partitionKey = createFormLatestPartitionKey(where);
267
237
  sortKey = createFormLatestSortKey(where);
@@ -284,25 +254,21 @@ const createFormStorageOperations = params => {
284
254
  where
285
255
  });
286
256
  }
287
-
288
257
  const keys = {
289
258
  PK: partitionKey,
290
259
  SK: sortKey
291
260
  };
292
-
293
261
  try {
294
- const item = await (0, _get.get)({
262
+ return await (0, _get.getClean)({
295
263
  entity,
296
264
  keys
297
265
  });
298
- return (0, _cleanup.cleanupItem)(entity, item);
299
266
  } catch (ex) {
300
267
  throw new _error.default(ex.message || "Could not get form by keys.", ex.code || "GET_FORM_ERROR", {
301
268
  keys
302
269
  });
303
270
  }
304
271
  };
305
-
306
272
  const listForms = async params => {
307
273
  const {
308
274
  sort,
@@ -318,7 +284,6 @@ const createFormStorageOperations = params => {
318
284
  }
319
285
  };
320
286
  let results;
321
-
322
287
  try {
323
288
  results = await (0, _query.queryAll)(queryAllParams);
324
289
  } catch (ex) {
@@ -327,13 +292,13 @@ const createFormStorageOperations = params => {
327
292
  partitionKey: queryAllParams.partitionKey
328
293
  });
329
294
  }
330
-
331
295
  const totalCount = results.length;
332
- const where = (0, _objectSpread2.default)({}, initialWhere);
296
+ const where = {
297
+ ...initialWhere
298
+ };
333
299
  /**
334
300
  * We need to remove conditions so we do not filter by them again.
335
301
  */
336
-
337
302
  delete where.tenant;
338
303
  delete where.locale;
339
304
  const filteredItems = (0, _filter.filterItems)({
@@ -355,7 +320,6 @@ const createFormStorageOperations = params => {
355
320
  * Although we do not need a cursor here, we will use it as such to keep it standardized.
356
321
  * Number is simply encoded.
357
322
  */
358
-
359
323
  const cursor = items.length > 0 ? (0, _cursor.encodeCursor)(start + limit) : null;
360
324
  const meta = {
361
325
  hasMoreItems,
@@ -367,7 +331,6 @@ const createFormStorageOperations = params => {
367
331
  meta
368
332
  };
369
333
  };
370
-
371
334
  const listFormRevisions = async params => {
372
335
  const {
373
336
  where: initialWhere,
@@ -392,7 +355,6 @@ const createFormStorageOperations = params => {
392
355
  }
393
356
  };
394
357
  let items = [];
395
-
396
358
  try {
397
359
  items = await (0, _query.queryAll)(queryAllParams);
398
360
  } catch (ex) {
@@ -401,12 +363,12 @@ const createFormStorageOperations = params => {
401
363
  options: queryAllParams.options
402
364
  });
403
365
  }
404
-
405
- const where = (0, _objectSpread2.default)({}, initialWhere);
366
+ const where = {
367
+ ...initialWhere
368
+ };
406
369
  /**
407
370
  * We need to remove conditions so we do not filter by them again.
408
371
  */
409
-
410
372
  delete where.id;
411
373
  delete where.formId;
412
374
  delete where.tenant;
@@ -423,7 +385,6 @@ const createFormStorageOperations = params => {
423
385
  fields: formDynamoDbFields
424
386
  });
425
387
  };
426
-
427
388
  const deleteForm = async params => {
428
389
  const {
429
390
  form
@@ -432,15 +393,13 @@ const createFormStorageOperations = params => {
432
393
  /**
433
394
  * This will find all form records.
434
395
  */
435
-
436
396
  const queryAllParams = {
437
397
  entity,
438
398
  partitionKey: createFormPartitionKey(form),
439
399
  options: {
440
- beginsWith: form.formId
400
+ beginsWith: form.formId || undefined
441
401
  }
442
402
  };
443
-
444
403
  try {
445
404
  items = await (0, _query.queryAll)(queryAllParams);
446
405
  } catch (ex) {
@@ -449,34 +408,28 @@ const createFormStorageOperations = params => {
449
408
  options: queryAllParams.options
450
409
  });
451
410
  }
452
-
453
- let hasLatestPublishedRecord = false;
454
- const deleteItems = items.map(item => {
455
- if (!hasLatestPublishedRecord && item.published) {
456
- hasLatestPublishedRecord = true;
411
+ let latestPublishedKeys;
412
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
413
+ entity,
414
+ delete: [createLatestKeys(form)]
415
+ });
416
+ for (const item of items) {
417
+ if (!latestPublishedKeys && item.published) {
418
+ latestPublishedKeys = createLatestPublishedKeys(item);
457
419
  }
458
-
459
- return entity.deleteBatch({
420
+ entityBatch.delete({
460
421
  PK: item.PK,
461
422
  SK: item.SK
462
423
  });
463
- });
464
-
465
- if (hasLatestPublishedRecord) {
466
- deleteItems.push(entity.deleteBatch(createLatestPublishedKeys(items[0])));
467
424
  }
468
-
469
- deleteItems.push(entity.deleteBatch(createLatestKeys(items[0])));
470
-
425
+ if (latestPublishedKeys) {
426
+ entityBatch.delete(latestPublishedKeys);
427
+ }
471
428
  try {
472
- await (0, _batchWrite.batchWriteAll)({
473
- table,
474
- items: deleteItems
475
- });
429
+ await entityBatch.execute();
476
430
  } catch (ex) {
477
431
  throw new _error.default(ex.message || "Could not delete form and it's submissions.", ex.code || "DELETE_FORM_AND_SUBMISSIONS_ERROR");
478
432
  }
479
-
480
433
  return form;
481
434
  };
482
435
  /**
@@ -485,8 +438,6 @@ const createFormStorageOperations = params => {
485
438
  * - get previously published revision and update the record if it exists or delete if it does not
486
439
  * - update latest record if current one is the latest
487
440
  */
488
-
489
-
490
441
  const deleteFormRevision = async params => {
491
442
  const {
492
443
  form,
@@ -499,8 +450,10 @@ const createFormStorageOperations = params => {
499
450
  const latestPublishedForm = revisions.find(rev => rev.published === true);
500
451
  const isLatest = latestForm ? latestForm.id === form.id : false;
501
452
  const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;
502
- const items = [entity.deleteBatch(revisionKeys)];
503
-
453
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
454
+ entity,
455
+ delete: [revisionKeys]
456
+ });
504
457
  if (isLatest || isLatestPublished) {
505
458
  /**
506
459
  * Sort out the latest published record.
@@ -509,40 +462,36 @@ const createFormStorageOperations = params => {
509
462
  const previouslyPublishedForm = revisions.filter(f => !!f.publishedOn && f.version !== form.version).sort((a, b) => {
510
463
  return new Date(b.publishedOn).getTime() - new Date(a.publishedOn).getTime();
511
464
  }).shift();
512
-
513
465
  if (previouslyPublishedForm) {
514
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedForm), createLatestPublishedKeys(previouslyPublishedForm)), {}, {
466
+ entityBatch.put({
467
+ ...previouslyPublishedForm,
468
+ ...createLatestPublishedKeys(previouslyPublishedForm),
515
469
  GSI1_PK: null,
516
470
  GSI1_SK: null,
517
471
  TYPE: createFormLatestPublishedType()
518
- })));
472
+ });
519
473
  } else {
520
- items.push(entity.deleteBatch(createLatestPublishedKeys(form)));
474
+ entityBatch.delete(createLatestPublishedKeys(form));
521
475
  }
522
476
  }
523
477
  /**
524
478
  * Sort out the latest record.
525
479
  */
526
-
527
-
528
480
  if (isLatest) {
529
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previous), latestKeys), {}, {
481
+ entityBatch.put({
482
+ ...previous,
483
+ ...latestKeys,
530
484
  GSI1_PK: null,
531
485
  GSI1_SK: null,
532
486
  TYPE: createFormLatestType()
533
- })));
487
+ });
534
488
  }
535
489
  }
536
490
  /**
537
491
  * Now save the batch data.
538
492
  */
539
-
540
-
541
493
  try {
542
- await (0, _batchWrite.batchWriteAll)({
543
- table,
544
- items
545
- });
494
+ await entityBatch.execute();
546
495
  return form;
547
496
  } catch (ex) {
548
497
  throw new _error.default(ex.message || "Could not delete form revision from table.", ex.code || "DELETE_FORM_REVISION_ERROR", {
@@ -553,6 +502,7 @@ const createFormStorageOperations = params => {
553
502
  });
554
503
  }
555
504
  };
505
+
556
506
  /**
557
507
  * We need to save form in:
558
508
  * - regular form record
@@ -560,8 +510,6 @@ const createFormStorageOperations = params => {
560
510
  * - latest form record - if form is latest one
561
511
  * - elasticsearch latest form record
562
512
  */
563
-
564
-
565
513
  const publishForm = async params => {
566
514
  const {
567
515
  form,
@@ -591,27 +539,32 @@ const createFormStorageOperations = params => {
591
539
  /**
592
540
  * Update revision and latest published records
593
541
  */
542
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
543
+ entity,
544
+ put: [{
545
+ ...form,
546
+ ...revisionKeys,
547
+ ...gsiKeys,
548
+ TYPE: createFormType()
549
+ }, {
550
+ ...form,
551
+ ...latestPublishedKeys,
552
+ TYPE: createFormLatestPublishedType()
553
+ }]
554
+ });
594
555
 
595
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
596
- TYPE: createFormType()
597
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestPublishedKeys), {}, {
598
- TYPE: createFormLatestPublishedType()
599
- }))];
600
556
  /**
601
557
  * Update the latest form as well
602
558
  */
603
-
604
559
  if (isLatestForm) {
605
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
560
+ entityBatch.put({
561
+ ...form,
562
+ ...latestKeys,
606
563
  TYPE: createFormLatestType()
607
- })));
564
+ });
608
565
  }
609
-
610
566
  try {
611
- await (0, _batchWrite.batchWriteAll)({
612
- table,
613
- items
614
- });
567
+ await entityBatch.execute();
615
568
  } catch (ex) {
616
569
  throw new _error.default(ex.message || "Could not publish form.", ex.code || "PUBLISH_FORM_ERROR", {
617
570
  form,
@@ -622,17 +575,15 @@ const createFormStorageOperations = params => {
622
575
  latestPublishedKeys
623
576
  });
624
577
  }
625
-
626
578
  return form;
627
579
  };
580
+
628
581
  /**
629
582
  * We need to:
630
583
  * - update form revision record
631
584
  * - if latest published (LP) is current form, find the previously published record and update LP if there is some previously published, delete otherwise
632
585
  * - if is latest update the Elasticsearch record
633
586
  */
634
-
635
-
636
587
  const unpublishForm = async params => {
637
588
  const {
638
589
  form,
@@ -665,21 +616,26 @@ const createFormStorageOperations = params => {
665
616
  });
666
617
  const isLatest = latestForm ? latestForm.id === form.id : false;
667
618
  const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;
668
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), gsiKeys), {}, {
669
- TYPE: createFormType()
670
- }))];
671
-
619
+ const entityBatch = (0, _dbDynamodb.createEntityWriteBatch)({
620
+ entity,
621
+ put: [{
622
+ ...form,
623
+ ...revisionKeys,
624
+ ...gsiKeys,
625
+ TYPE: createFormType()
626
+ }]
627
+ });
672
628
  if (isLatest) {
673
- entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
629
+ entityBatch.put({
630
+ ...form,
631
+ ...latestKeys,
674
632
  TYPE: createFormLatestType()
675
- }));
633
+ });
676
634
  }
677
635
  /**
678
636
  * In case previously published revision exists, replace current one with that one.
679
637
  * And if it does not, delete the record.
680
638
  */
681
-
682
-
683
639
  if (isLatestPublished) {
684
640
  const revisions = await listFormRevisions({
685
641
  where: {
@@ -692,21 +648,18 @@ const createFormStorageOperations = params => {
692
648
  sort: ["savedOn_DESC"]
693
649
  });
694
650
  const previouslyPublishedRevision = revisions.shift();
695
-
696
651
  if (previouslyPublishedRevision) {
697
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedRevision), latestPublishedKeys), {}, {
652
+ entityBatch.put({
653
+ ...previouslyPublishedRevision,
654
+ ...latestPublishedKeys,
698
655
  TYPE: createFormLatestPublishedType()
699
- })));
656
+ });
700
657
  } else {
701
- items.push(entity.deleteBatch(latestPublishedKeys));
658
+ entityBatch.delete(latestPublishedKeys);
702
659
  }
703
660
  }
704
-
705
661
  try {
706
- await (0, _batchWrite.batchWriteAll)({
707
- table,
708
- items
709
- });
662
+ await entityBatch.execute();
710
663
  return form;
711
664
  } catch (ex) {
712
665
  throw new _error.default(ex.message || "Could not unpublish form.", ex.code || "UNPUBLISH_FORM_ERROR", {
@@ -719,7 +672,6 @@ const createFormStorageOperations = params => {
719
672
  });
720
673
  }
721
674
  };
722
-
723
675
  return {
724
676
  createForm,
725
677
  createFormFrom,
@@ -734,5 +686,6 @@ const createFormStorageOperations = params => {
734
686
  createFormPartitionKey
735
687
  };
736
688
  };
689
+ exports.createFormStorageOperations = createFormStorageOperations;
737
690
 
738
- exports.createFormStorageOperations = createFormStorageOperations;
691
+ //# sourceMappingURL=index.js.map