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