@webiny/api-form-builder-so-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.085ff6572f
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/configurations.d.ts +7 -5
- package/configurations.js +23 -12
- package/configurations.js.map +1 -0
- package/definitions/elasticsearch.d.ts +2 -1
- package/definitions/elasticsearch.js +3 -12
- package/definitions/elasticsearch.js.map +1 -0
- package/definitions/form.d.ts +2 -1
- package/definitions/form.js +3 -12
- package/definitions/form.js.map +1 -0
- package/definitions/settings.d.ts +2 -1
- package/definitions/settings.js +3 -12
- package/definitions/settings.js.map +1 -0
- package/definitions/submission.d.ts +2 -1
- package/definitions/submission.js +3 -12
- package/definitions/submission.js.map +1 -0
- package/definitions/system.d.ts +2 -1
- package/definitions/system.js +3 -12
- package/definitions/system.js.map +1 -0
- package/definitions/table.d.ts +3 -2
- package/definitions/table.js +0 -3
- package/definitions/table.js.map +1 -0
- package/definitions/tableElasticsearch.d.ts +2 -1
- package/definitions/tableElasticsearch.js +0 -3
- package/definitions/tableElasticsearch.js.map +1 -0
- package/elasticsearch/createElasticsearchIndex.d.ts +10 -0
- package/elasticsearch/createElasticsearchIndex.js +52 -0
- package/elasticsearch/createElasticsearchIndex.js.map +1 -0
- package/elasticsearch/indices/base.d.ts +2 -0
- package/elasticsearch/indices/base.js +12 -0
- package/elasticsearch/indices/base.js.map +1 -0
- package/elasticsearch/indices/index.d.ts +1 -0
- package/elasticsearch/indices/index.js +12 -0
- package/elasticsearch/indices/index.js.map +1 -0
- package/elasticsearch/indices/japanese.d.ts +2 -0
- package/elasticsearch/indices/japanese.js +13 -0
- package/elasticsearch/indices/japanese.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +54 -61
- package/index.js.map +1 -0
- package/operations/form/elasticsearchBody.js +12 -56
- package/operations/form/elasticsearchBody.js.map +1 -0
- package/operations/form/elasticsearchFields.js +0 -3
- package/operations/form/elasticsearchFields.js.map +1 -0
- package/operations/form/fields.js +0 -3
- package/operations/form/fields.js.map +1 -0
- package/operations/form/index.d.ts +2 -2
- package/operations/form/index.js +53 -153
- package/operations/form/index.js.map +1 -0
- package/operations/settings/index.d.ts +2 -2
- package/operations/settings/index.js +5 -29
- package/operations/settings/index.js.map +1 -0
- package/operations/submission/elasticsearchBody.js +15 -54
- package/operations/submission/elasticsearchBody.js.map +1 -0
- package/operations/submission/elasticsearchFields.js +0 -3
- package/operations/submission/elasticsearchFields.js.map +1 -0
- package/operations/submission/index.d.ts +2 -2
- package/operations/submission/index.js +23 -76
- package/operations/submission/index.js.map +1 -0
- package/operations/system/index.d.ts +2 -2
- package/operations/system/index.js +4 -26
- package/operations/system/index.js.map +1 -0
- package/package.json +27 -32
- package/plugins/FormDynamoDbFieldPlugin.js +1 -6
- package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.d.ts +1 -1
- package/plugins/FormElasticsearchBodyModifierPlugin.js +3 -8
- package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/FormElasticsearchFieldPlugin.d.ts +1 -1
- package/plugins/FormElasticsearchFieldPlugin.js +3 -8
- package/plugins/FormElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/FormElasticsearchIndexPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchIndexPlugin.js +12 -0
- package/plugins/FormElasticsearchIndexPlugin.js.map +1 -0
- package/plugins/FormElasticsearchQueryModifierPlugin.d.ts +1 -1
- package/plugins/FormElasticsearchQueryModifierPlugin.js +3 -8
- package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/FormElasticsearchSortModifierPlugin.d.ts +1 -1
- package/plugins/FormElasticsearchSortModifierPlugin.js +3 -8
- package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.d.ts +1 -1
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +3 -8
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.d.ts +1 -1
- package/plugins/SubmissionElasticsearchFieldPlugin.js +3 -8
- package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.d.ts +1 -1
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +3 -8
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/SubmissionElasticsearchSortModifierPlugin.d.ts +1 -1
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js +3 -8
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/index.d.ts +10 -0
- package/plugins/index.js +115 -0
- package/plugins/index.js.map +1 -0
- package/types.d.ts +2 -2
- package/types.js +0 -1
- package/types.js.map +1 -0
- package/operations/system/createElasticsearchIndex.d.ts +0 -6
- package/operations/system/createElasticsearchIndex.js +0 -70
- package/upgrades/5.16.0/index.d.ts +0 -8
- package/upgrades/5.16.0/index.js +0 -141
package/operations/form/index.js
CHANGED
|
@@ -1,40 +1,22 @@
|
|
|
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
|
-
|
|
8
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
12
9
|
var _query = require("@webiny/db-dynamodb/utils/query");
|
|
13
|
-
|
|
14
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
-
|
|
16
11
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
17
|
-
|
|
18
12
|
var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
|
|
19
|
-
|
|
20
|
-
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
21
|
-
|
|
13
|
+
var _configurations = require("../../configurations");
|
|
22
14
|
var _filter = require("@webiny/db-dynamodb/utils/filter");
|
|
23
|
-
|
|
24
15
|
var _fields = _interopRequireDefault(require("./fields"));
|
|
25
|
-
|
|
26
16
|
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
27
|
-
|
|
28
17
|
var _utils = require("@webiny/utils");
|
|
29
|
-
|
|
30
18
|
var _elasticsearchBody = require("./elasticsearchBody");
|
|
31
|
-
|
|
32
|
-
var _cursors = require("@webiny/api-elasticsearch/cursors");
|
|
33
|
-
|
|
34
|
-
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; }
|
|
35
|
-
|
|
36
|
-
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; }
|
|
37
|
-
|
|
19
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
38
20
|
const getESDataForLatestRevision = form => ({
|
|
39
21
|
__type: (0, _elasticsearchBody.createFormElasticType)(),
|
|
40
22
|
id: form.id,
|
|
@@ -54,7 +36,6 @@ const getESDataForLatestRevision = form => ({
|
|
|
54
36
|
webinyVersion: form.webinyVersion,
|
|
55
37
|
formId: form.formId
|
|
56
38
|
});
|
|
57
|
-
|
|
58
39
|
const createFormStorageOperations = params => {
|
|
59
40
|
const {
|
|
60
41
|
entity,
|
|
@@ -64,7 +45,6 @@ const createFormStorageOperations = params => {
|
|
|
64
45
|
elasticsearch
|
|
65
46
|
} = params;
|
|
66
47
|
const formDynamoDbFields = (0, _fields.default)();
|
|
67
|
-
|
|
68
48
|
const createFormPartitionKey = params => {
|
|
69
49
|
const {
|
|
70
50
|
tenant,
|
|
@@ -76,32 +56,25 @@ const createFormStorageOperations = params => {
|
|
|
76
56
|
} = (0, _utils.parseIdentifier)(targetId);
|
|
77
57
|
return `T#${tenant}#L#${locale}#FB#F#${id}`;
|
|
78
58
|
};
|
|
79
|
-
|
|
80
59
|
const createRevisionSortKey = value => {
|
|
81
60
|
const version = typeof value === "number" ? Number(value) : (0, _utils.parseIdentifier)(value).version;
|
|
82
61
|
return `REV#${(0, _utils.zeroPad)(version)}`;
|
|
83
62
|
};
|
|
84
|
-
|
|
85
63
|
const createLatestSortKey = () => {
|
|
86
64
|
return "L";
|
|
87
65
|
};
|
|
88
|
-
|
|
89
66
|
const createLatestPublishedSortKey = () => {
|
|
90
67
|
return "LP";
|
|
91
68
|
};
|
|
92
|
-
|
|
93
69
|
const createFormType = () => {
|
|
94
70
|
return "fb.form";
|
|
95
71
|
};
|
|
96
|
-
|
|
97
72
|
const createFormLatestType = () => {
|
|
98
73
|
return "fb.form.latest";
|
|
99
74
|
};
|
|
100
|
-
|
|
101
75
|
const createFormLatestPublishedType = () => {
|
|
102
76
|
return "fb.form.latestPublished";
|
|
103
77
|
};
|
|
104
|
-
|
|
105
78
|
const createForm = async params => {
|
|
106
79
|
const {
|
|
107
80
|
form
|
|
@@ -114,12 +87,11 @@ const createFormStorageOperations = params => {
|
|
|
114
87
|
PK: createFormPartitionKey(form),
|
|
115
88
|
SK: createLatestSortKey()
|
|
116
89
|
};
|
|
117
|
-
const items = [entity.putBatch(
|
|
90
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
|
|
118
91
|
TYPE: createFormType()
|
|
119
|
-
}, revisionKeys)), entity.putBatch(
|
|
92
|
+
}, revisionKeys)), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
|
|
120
93
|
TYPE: createFormLatestType()
|
|
121
94
|
}, latestKeys))];
|
|
122
|
-
|
|
123
95
|
try {
|
|
124
96
|
await (0, _batchWrite.batchWriteAll)({
|
|
125
97
|
table,
|
|
@@ -132,15 +104,14 @@ const createFormStorageOperations = params => {
|
|
|
132
104
|
form
|
|
133
105
|
});
|
|
134
106
|
}
|
|
135
|
-
|
|
136
107
|
try {
|
|
137
108
|
const {
|
|
138
109
|
index
|
|
139
|
-
} = _configurations.
|
|
140
|
-
tenant: form.tenant
|
|
110
|
+
} = _configurations.configurations.es({
|
|
111
|
+
tenant: form.tenant,
|
|
112
|
+
locale: form.locale
|
|
141
113
|
});
|
|
142
|
-
|
|
143
|
-
await esEntity.put(_objectSpread({
|
|
114
|
+
await esEntity.put((0, _objectSpread2.default)({
|
|
144
115
|
index,
|
|
145
116
|
data: getESDataForLatestRevision(form),
|
|
146
117
|
TYPE: createFormType()
|
|
@@ -151,10 +122,8 @@ const createFormStorageOperations = params => {
|
|
|
151
122
|
form
|
|
152
123
|
});
|
|
153
124
|
}
|
|
154
|
-
|
|
155
125
|
return form;
|
|
156
126
|
};
|
|
157
|
-
|
|
158
127
|
const createFormFrom = async params => {
|
|
159
128
|
const {
|
|
160
129
|
form,
|
|
@@ -169,12 +138,11 @@ const createFormStorageOperations = params => {
|
|
|
169
138
|
PK: createFormPartitionKey(form),
|
|
170
139
|
SK: createLatestSortKey()
|
|
171
140
|
};
|
|
172
|
-
const items = [entity.putBatch(
|
|
141
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
|
|
173
142
|
TYPE: createFormType()
|
|
174
|
-
})), entity.putBatch(
|
|
143
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
175
144
|
TYPE: createFormLatestType()
|
|
176
145
|
}))];
|
|
177
|
-
|
|
178
146
|
try {
|
|
179
147
|
await (0, _batchWrite.batchWriteAll)({
|
|
180
148
|
table,
|
|
@@ -189,15 +157,14 @@ const createFormStorageOperations = params => {
|
|
|
189
157
|
latest
|
|
190
158
|
});
|
|
191
159
|
}
|
|
192
|
-
|
|
193
160
|
try {
|
|
194
161
|
const {
|
|
195
162
|
index
|
|
196
|
-
} = _configurations.
|
|
197
|
-
tenant: form.tenant
|
|
163
|
+
} = _configurations.configurations.es({
|
|
164
|
+
tenant: form.tenant,
|
|
165
|
+
locale: form.locale
|
|
198
166
|
});
|
|
199
|
-
|
|
200
|
-
await esEntity.put(_objectSpread({
|
|
167
|
+
await esEntity.put((0, _objectSpread2.default)({
|
|
201
168
|
index,
|
|
202
169
|
data: getESDataForLatestRevision(form),
|
|
203
170
|
TYPE: createFormLatestType()
|
|
@@ -210,10 +177,8 @@ const createFormStorageOperations = params => {
|
|
|
210
177
|
original
|
|
211
178
|
});
|
|
212
179
|
}
|
|
213
|
-
|
|
214
180
|
return form;
|
|
215
181
|
};
|
|
216
|
-
|
|
217
182
|
const updateForm = async params => {
|
|
218
183
|
const {
|
|
219
184
|
form,
|
|
@@ -241,16 +206,14 @@ const createFormStorageOperations = params => {
|
|
|
241
206
|
}
|
|
242
207
|
});
|
|
243
208
|
const isLatestForm = latestForm ? latestForm.id === form.id : false;
|
|
244
|
-
const items = [entity.putBatch(
|
|
209
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
|
|
245
210
|
TYPE: createFormType()
|
|
246
211
|
}, revisionKeys))];
|
|
247
|
-
|
|
248
212
|
if (isLatestForm) {
|
|
249
|
-
items.push(entity.putBatch(
|
|
213
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
|
|
250
214
|
TYPE: createFormLatestType()
|
|
251
215
|
}, latestKeys)));
|
|
252
216
|
}
|
|
253
|
-
|
|
254
217
|
try {
|
|
255
218
|
await (0, _batchWrite.batchWriteAll)({
|
|
256
219
|
table,
|
|
@@ -268,20 +231,17 @@ const createFormStorageOperations = params => {
|
|
|
268
231
|
/**
|
|
269
232
|
* No need to go further if its not latest form.
|
|
270
233
|
*/
|
|
271
|
-
|
|
272
|
-
|
|
273
234
|
if (!isLatestForm) {
|
|
274
235
|
return form;
|
|
275
236
|
}
|
|
276
|
-
|
|
277
237
|
try {
|
|
278
238
|
const {
|
|
279
239
|
index
|
|
280
|
-
} = _configurations.
|
|
281
|
-
tenant: form.tenant
|
|
240
|
+
} = _configurations.configurations.es({
|
|
241
|
+
tenant: form.tenant,
|
|
242
|
+
locale: form.locale
|
|
282
243
|
});
|
|
283
|
-
|
|
284
|
-
await esEntity.put(_objectSpread({
|
|
244
|
+
await esEntity.put((0, _objectSpread2.default)({
|
|
285
245
|
index,
|
|
286
246
|
data: getESDataForLatestRevision(form),
|
|
287
247
|
TYPE: createFormLatestType()
|
|
@@ -294,10 +254,8 @@ const createFormStorageOperations = params => {
|
|
|
294
254
|
original
|
|
295
255
|
});
|
|
296
256
|
}
|
|
297
|
-
|
|
298
257
|
return form;
|
|
299
258
|
};
|
|
300
|
-
|
|
301
259
|
const getForm = async params => {
|
|
302
260
|
const {
|
|
303
261
|
where
|
|
@@ -311,13 +269,10 @@ const createFormStorageOperations = params => {
|
|
|
311
269
|
tenant,
|
|
312
270
|
locale
|
|
313
271
|
} = where;
|
|
314
|
-
|
|
315
272
|
if (latest && published) {
|
|
316
273
|
throw new _error.default("Cannot have both latest and published params.");
|
|
317
274
|
}
|
|
318
|
-
|
|
319
275
|
let sortKey;
|
|
320
|
-
|
|
321
276
|
if (latest) {
|
|
322
277
|
sortKey = createLatestSortKey();
|
|
323
278
|
} else if (published && !version) {
|
|
@@ -332,7 +287,6 @@ const createFormStorageOperations = params => {
|
|
|
332
287
|
where
|
|
333
288
|
});
|
|
334
289
|
}
|
|
335
|
-
|
|
336
290
|
const keys = {
|
|
337
291
|
PK: createFormPartitionKey({
|
|
338
292
|
tenant,
|
|
@@ -341,14 +295,11 @@ const createFormStorageOperations = params => {
|
|
|
341
295
|
}),
|
|
342
296
|
SK: sortKey
|
|
343
297
|
};
|
|
344
|
-
|
|
345
298
|
try {
|
|
346
299
|
const result = await entity.get(keys);
|
|
347
|
-
|
|
348
300
|
if (!result || !result.Item) {
|
|
349
301
|
return null;
|
|
350
302
|
}
|
|
351
|
-
|
|
352
303
|
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
353
304
|
} catch (ex) {
|
|
354
305
|
throw new _error.default(ex.message || "Could not get form by keys.", ex.code || "GET_FORM_ERROR", {
|
|
@@ -356,7 +307,6 @@ const createFormStorageOperations = params => {
|
|
|
356
307
|
});
|
|
357
308
|
}
|
|
358
309
|
};
|
|
359
|
-
|
|
360
310
|
const listForms = async params => {
|
|
361
311
|
const {
|
|
362
312
|
sort,
|
|
@@ -369,19 +319,16 @@ const createFormStorageOperations = params => {
|
|
|
369
319
|
sort,
|
|
370
320
|
limit: limit + 1,
|
|
371
321
|
where,
|
|
372
|
-
after: (0,
|
|
322
|
+
after: (0, _apiElasticsearch.decodeCursor)(after)
|
|
373
323
|
});
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
324
|
+
const esConfig = _configurations.configurations.es({
|
|
325
|
+
tenant: where.tenant,
|
|
326
|
+
locale: where.locale
|
|
377
327
|
});
|
|
378
|
-
|
|
379
|
-
const query = _objectSpread(_objectSpread({}, esConfig), {}, {
|
|
328
|
+
const query = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, esConfig), {}, {
|
|
380
329
|
body
|
|
381
330
|
});
|
|
382
|
-
|
|
383
331
|
let response;
|
|
384
|
-
|
|
385
332
|
try {
|
|
386
333
|
response = await elasticsearch.search(query);
|
|
387
334
|
} catch (ex) {
|
|
@@ -390,14 +337,12 @@ const createFormStorageOperations = params => {
|
|
|
390
337
|
query
|
|
391
338
|
});
|
|
392
339
|
}
|
|
393
|
-
|
|
394
340
|
const {
|
|
395
341
|
hits,
|
|
396
342
|
total
|
|
397
343
|
} = response.body.hits;
|
|
398
344
|
const items = hits.map(item => item._source);
|
|
399
345
|
const hasMoreItems = items.length > limit;
|
|
400
|
-
|
|
401
346
|
if (hasMoreItems) {
|
|
402
347
|
/**
|
|
403
348
|
* Remove the last item from results, we don't want to include it.
|
|
@@ -409,18 +354,16 @@ const createFormStorageOperations = params => {
|
|
|
409
354
|
* https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
|
|
410
355
|
*/
|
|
411
356
|
|
|
412
|
-
|
|
413
357
|
const meta = {
|
|
414
358
|
hasMoreItems,
|
|
415
359
|
totalCount: total.value,
|
|
416
|
-
cursor: items.length > 0 ? (0,
|
|
360
|
+
cursor: items.length > 0 ? (0, _apiElasticsearch.encodeCursor)(hits[items.length - 1].sort) || null : null
|
|
417
361
|
};
|
|
418
362
|
return {
|
|
419
363
|
items,
|
|
420
364
|
meta
|
|
421
365
|
};
|
|
422
366
|
};
|
|
423
|
-
|
|
424
367
|
const listFormRevisions = async params => {
|
|
425
368
|
const {
|
|
426
369
|
where: initialWhere,
|
|
@@ -444,7 +387,6 @@ const createFormStorageOperations = params => {
|
|
|
444
387
|
}
|
|
445
388
|
};
|
|
446
389
|
let items = [];
|
|
447
|
-
|
|
448
390
|
try {
|
|
449
391
|
items = await (0, _query.queryAll)(queryAllParams);
|
|
450
392
|
} catch (ex) {
|
|
@@ -453,30 +395,25 @@ const createFormStorageOperations = params => {
|
|
|
453
395
|
options: queryAllParams.options
|
|
454
396
|
});
|
|
455
397
|
}
|
|
456
|
-
|
|
457
|
-
const where = _objectSpread(_objectSpread({}, initialWhere), {}, {
|
|
398
|
+
const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
|
|
458
399
|
id: undefined,
|
|
459
400
|
formId: undefined
|
|
460
401
|
});
|
|
461
|
-
|
|
462
402
|
const filteredItems = (0, _filter.filterItems)({
|
|
463
403
|
plugins,
|
|
464
404
|
items,
|
|
465
405
|
where,
|
|
466
406
|
fields: formDynamoDbFields
|
|
467
407
|
});
|
|
468
|
-
|
|
469
|
-
if (Array.isArray(sort) === false || sort.length === 0) {
|
|
408
|
+
if (!sort || sort.length === 0) {
|
|
470
409
|
return filteredItems;
|
|
471
410
|
}
|
|
472
|
-
|
|
473
411
|
return (0, _sort.sortItems)({
|
|
474
412
|
items: filteredItems,
|
|
475
413
|
sort,
|
|
476
414
|
fields: formDynamoDbFields
|
|
477
415
|
});
|
|
478
416
|
};
|
|
479
|
-
|
|
480
417
|
const deleteForm = async params => {
|
|
481
418
|
const {
|
|
482
419
|
form
|
|
@@ -485,7 +422,6 @@ const createFormStorageOperations = params => {
|
|
|
485
422
|
/**
|
|
486
423
|
* This will find all form and submission records.
|
|
487
424
|
*/
|
|
488
|
-
|
|
489
425
|
const queryAllParams = {
|
|
490
426
|
entity,
|
|
491
427
|
partitionKey: createFormPartitionKey(form),
|
|
@@ -493,7 +429,6 @@ const createFormStorageOperations = params => {
|
|
|
493
429
|
gte: " "
|
|
494
430
|
}
|
|
495
431
|
};
|
|
496
|
-
|
|
497
432
|
try {
|
|
498
433
|
items = await (0, _query.queryAll)(queryAllParams);
|
|
499
434
|
} catch (ex) {
|
|
@@ -502,14 +437,12 @@ const createFormStorageOperations = params => {
|
|
|
502
437
|
options: queryAllParams.options
|
|
503
438
|
});
|
|
504
439
|
}
|
|
505
|
-
|
|
506
440
|
const deleteItems = items.map(item => {
|
|
507
441
|
return entity.deleteBatch({
|
|
508
442
|
PK: item.PK,
|
|
509
443
|
SK: item.SK
|
|
510
444
|
});
|
|
511
445
|
});
|
|
512
|
-
|
|
513
446
|
try {
|
|
514
447
|
await (0, _batchWrite.batchWriteAll)({
|
|
515
448
|
table,
|
|
@@ -518,12 +451,10 @@ const createFormStorageOperations = params => {
|
|
|
518
451
|
} catch (ex) {
|
|
519
452
|
throw new _error.default(ex.message || "Could not delete form and it's submissions.", ex.code || "DELETE_FORM_AND_SUBMISSIONS_ERROR");
|
|
520
453
|
}
|
|
521
|
-
|
|
522
454
|
const latestKeys = {
|
|
523
455
|
PK: createFormPartitionKey(form),
|
|
524
456
|
SK: createLatestSortKey()
|
|
525
457
|
};
|
|
526
|
-
|
|
527
458
|
try {
|
|
528
459
|
await esEntity.delete(latestKeys);
|
|
529
460
|
} catch (ex) {
|
|
@@ -531,7 +462,6 @@ const createFormStorageOperations = params => {
|
|
|
531
462
|
latestKeys
|
|
532
463
|
});
|
|
533
464
|
}
|
|
534
|
-
|
|
535
465
|
return form;
|
|
536
466
|
};
|
|
537
467
|
/**
|
|
@@ -540,8 +470,6 @@ const createFormStorageOperations = params => {
|
|
|
540
470
|
* - get previously published revision and update the record if it exists or delete if it does not
|
|
541
471
|
* - update latest record if current one is the latest
|
|
542
472
|
*/
|
|
543
|
-
|
|
544
|
-
|
|
545
473
|
const deleteFormRevision = async params => {
|
|
546
474
|
const {
|
|
547
475
|
form,
|
|
@@ -562,7 +490,6 @@ const createFormStorageOperations = params => {
|
|
|
562
490
|
const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;
|
|
563
491
|
const items = [entity.deleteBatch(revisionKeys)];
|
|
564
492
|
let esDataItem = undefined;
|
|
565
|
-
|
|
566
493
|
if (isLatest || isLatestPublished) {
|
|
567
494
|
/**
|
|
568
495
|
* Sort out the latest published record.
|
|
@@ -571,16 +498,15 @@ const createFormStorageOperations = params => {
|
|
|
571
498
|
const previouslyPublishedForm = revisions.filter(f => !!f.publishedOn && f.version !== form.version).sort((a, b) => {
|
|
572
499
|
return new Date(b.publishedOn).getTime() - new Date(a.publishedOn).getTime();
|
|
573
500
|
}).shift();
|
|
574
|
-
|
|
575
501
|
if (previouslyPublishedForm) {
|
|
576
|
-
items.push(entity.putBatch(
|
|
502
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedForm), {}, {
|
|
577
503
|
PK: createFormPartitionKey(previouslyPublishedForm),
|
|
578
504
|
SK: createLatestPublishedSortKey(),
|
|
579
505
|
TYPE: createFormLatestPublishedType()
|
|
580
506
|
})));
|
|
581
507
|
} else {
|
|
582
508
|
items.push(entity.deleteBatch({
|
|
583
|
-
PK: createFormPartitionKey(
|
|
509
|
+
PK: createFormPartitionKey(form),
|
|
584
510
|
SK: createLatestPublishedSortKey()
|
|
585
511
|
}));
|
|
586
512
|
}
|
|
@@ -588,20 +514,17 @@ const createFormStorageOperations = params => {
|
|
|
588
514
|
/**
|
|
589
515
|
* Sort out the latest record.
|
|
590
516
|
*/
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
if (isLatest) {
|
|
594
|
-
items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, previous), latestKeys), {}, {
|
|
517
|
+
if (isLatest && previous) {
|
|
518
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previous), latestKeys), {}, {
|
|
595
519
|
TYPE: createFormLatestType()
|
|
596
520
|
})));
|
|
597
|
-
|
|
598
521
|
const {
|
|
599
522
|
index
|
|
600
|
-
} = _configurations.
|
|
601
|
-
tenant: previous.tenant
|
|
523
|
+
} = _configurations.configurations.es({
|
|
524
|
+
tenant: previous.tenant,
|
|
525
|
+
locale: previous.locale
|
|
602
526
|
});
|
|
603
|
-
|
|
604
|
-
esDataItem = _objectSpread(_objectSpread({
|
|
527
|
+
esDataItem = (0, _objectSpread2.default)((0, _objectSpread2.default)({
|
|
605
528
|
index
|
|
606
529
|
}, latestKeys), {}, {
|
|
607
530
|
data: getESDataForLatestRevision(previous)
|
|
@@ -611,8 +534,6 @@ const createFormStorageOperations = params => {
|
|
|
611
534
|
/**
|
|
612
535
|
* Now save the batch data.
|
|
613
536
|
*/
|
|
614
|
-
|
|
615
|
-
|
|
616
537
|
try {
|
|
617
538
|
await (0, _batchWrite.batchWriteAll)({
|
|
618
539
|
table,
|
|
@@ -629,12 +550,9 @@ const createFormStorageOperations = params => {
|
|
|
629
550
|
/**
|
|
630
551
|
* And then the Elasticsearch data, if any.
|
|
631
552
|
*/
|
|
632
|
-
|
|
633
|
-
|
|
634
553
|
if (!esDataItem) {
|
|
635
554
|
return form;
|
|
636
555
|
}
|
|
637
|
-
|
|
638
556
|
try {
|
|
639
557
|
await esEntity.put(esDataItem);
|
|
640
558
|
return form;
|
|
@@ -647,6 +565,7 @@ const createFormStorageOperations = params => {
|
|
|
647
565
|
});
|
|
648
566
|
}
|
|
649
567
|
};
|
|
568
|
+
|
|
650
569
|
/**
|
|
651
570
|
* We need to save form in:
|
|
652
571
|
* - regular form record
|
|
@@ -654,8 +573,6 @@ const createFormStorageOperations = params => {
|
|
|
654
573
|
* - latest form record - if form is latest one
|
|
655
574
|
* - elasticsearch latest form record
|
|
656
575
|
*/
|
|
657
|
-
|
|
658
|
-
|
|
659
576
|
const publishForm = async params => {
|
|
660
577
|
const {
|
|
661
578
|
form,
|
|
@@ -690,22 +607,19 @@ const createFormStorageOperations = params => {
|
|
|
690
607
|
/**
|
|
691
608
|
* Update revision and latest published records
|
|
692
609
|
*/
|
|
693
|
-
|
|
694
|
-
const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, form), revisionKeys), {}, {
|
|
610
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
|
|
695
611
|
TYPE: createFormType()
|
|
696
|
-
})), entity.putBatch(
|
|
612
|
+
})), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestPublishedKeys), {}, {
|
|
697
613
|
TYPE: createFormLatestPublishedType()
|
|
698
614
|
}))];
|
|
699
615
|
/**
|
|
700
616
|
* Update the latest form as well
|
|
701
617
|
*/
|
|
702
|
-
|
|
703
618
|
if (isLatestForm) {
|
|
704
|
-
items.push(entity.putBatch(
|
|
619
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
|
|
705
620
|
TYPE: createFormLatestType()
|
|
706
621
|
})));
|
|
707
622
|
}
|
|
708
|
-
|
|
709
623
|
try {
|
|
710
624
|
await (0, _batchWrite.batchWriteAll)({
|
|
711
625
|
table,
|
|
@@ -721,21 +635,18 @@ const createFormStorageOperations = params => {
|
|
|
721
635
|
latestPublishedKeys
|
|
722
636
|
});
|
|
723
637
|
}
|
|
724
|
-
|
|
725
638
|
if (!isLatestForm) {
|
|
726
639
|
return form;
|
|
727
640
|
}
|
|
728
|
-
|
|
729
641
|
const {
|
|
730
642
|
index
|
|
731
|
-
} = _configurations.
|
|
732
|
-
tenant: form.tenant
|
|
643
|
+
} = _configurations.configurations.es({
|
|
644
|
+
tenant: form.tenant,
|
|
645
|
+
locale: form.locale
|
|
733
646
|
});
|
|
734
|
-
|
|
735
647
|
const esData = getESDataForLatestRevision(form);
|
|
736
|
-
|
|
737
648
|
try {
|
|
738
|
-
await esEntity.put(
|
|
649
|
+
await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
|
|
739
650
|
index,
|
|
740
651
|
TYPE: createFormLatestType(),
|
|
741
652
|
data: esData
|
|
@@ -752,14 +663,13 @@ const createFormStorageOperations = params => {
|
|
|
752
663
|
});
|
|
753
664
|
}
|
|
754
665
|
};
|
|
666
|
+
|
|
755
667
|
/**
|
|
756
668
|
* We need to:
|
|
757
669
|
* - update form revision record
|
|
758
670
|
* - if latest published (LP) is current form, find the previously published record and update LP if there is some previously published, delete otherwise
|
|
759
671
|
* - if is latest update the Elasticsearch record
|
|
760
672
|
*/
|
|
761
|
-
|
|
762
|
-
|
|
763
673
|
const unpublishForm = async params => {
|
|
764
674
|
const {
|
|
765
675
|
form,
|
|
@@ -800,11 +710,10 @@ const createFormStorageOperations = params => {
|
|
|
800
710
|
});
|
|
801
711
|
const isLatest = latestForm ? latestForm.id === form.id : false;
|
|
802
712
|
const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;
|
|
803
|
-
const items = [entity.putBatch(
|
|
713
|
+
const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
|
|
804
714
|
TYPE: createFormType()
|
|
805
715
|
}))];
|
|
806
716
|
let esData = undefined;
|
|
807
|
-
|
|
808
717
|
if (isLatest) {
|
|
809
718
|
esData = getESDataForLatestRevision(form);
|
|
810
719
|
}
|
|
@@ -812,8 +721,6 @@ const createFormStorageOperations = params => {
|
|
|
812
721
|
* In case previously published revision exists, replace current one with that one.
|
|
813
722
|
* And if it does not, delete the record.
|
|
814
723
|
*/
|
|
815
|
-
|
|
816
|
-
|
|
817
724
|
if (isLatestPublished) {
|
|
818
725
|
const revisions = await listFormRevisions({
|
|
819
726
|
where: {
|
|
@@ -826,16 +733,14 @@ const createFormStorageOperations = params => {
|
|
|
826
733
|
sort: ["savedOn_DESC"]
|
|
827
734
|
});
|
|
828
735
|
const previouslyPublishedRevision = revisions.shift();
|
|
829
|
-
|
|
830
736
|
if (previouslyPublishedRevision) {
|
|
831
|
-
items.push(entity.putBatch(
|
|
737
|
+
items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedRevision), latestPublishedKeys), {}, {
|
|
832
738
|
TYPE: createFormLatestPublishedType()
|
|
833
739
|
})));
|
|
834
740
|
} else {
|
|
835
741
|
items.push(entity.deleteBatch(latestPublishedKeys));
|
|
836
742
|
}
|
|
837
743
|
}
|
|
838
|
-
|
|
839
744
|
try {
|
|
840
745
|
await (0, _batchWrite.batchWriteAll)({
|
|
841
746
|
table,
|
|
@@ -854,20 +759,17 @@ const createFormStorageOperations = params => {
|
|
|
854
759
|
/**
|
|
855
760
|
* No need to go further in case of non-existing Elasticsearch data.
|
|
856
761
|
*/
|
|
857
|
-
|
|
858
|
-
|
|
859
762
|
if (!esData) {
|
|
860
763
|
return form;
|
|
861
764
|
}
|
|
862
|
-
|
|
863
765
|
const {
|
|
864
766
|
index
|
|
865
|
-
} = _configurations.
|
|
866
|
-
tenant: form.tenant
|
|
767
|
+
} = _configurations.configurations.es({
|
|
768
|
+
tenant: form.tenant,
|
|
769
|
+
locale: form.locale
|
|
867
770
|
});
|
|
868
|
-
|
|
869
771
|
try {
|
|
870
|
-
await esEntity.put(
|
|
772
|
+
await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
|
|
871
773
|
index,
|
|
872
774
|
TYPE: createFormLatestType(),
|
|
873
775
|
data: esData
|
|
@@ -884,7 +786,6 @@ const createFormStorageOperations = params => {
|
|
|
884
786
|
});
|
|
885
787
|
}
|
|
886
788
|
};
|
|
887
|
-
|
|
888
789
|
return {
|
|
889
790
|
createForm,
|
|
890
791
|
createFormFrom,
|
|
@@ -899,5 +800,4 @@ const createFormStorageOperations = params => {
|
|
|
899
800
|
createFormPartitionKey
|
|
900
801
|
};
|
|
901
802
|
};
|
|
902
|
-
|
|
903
803
|
exports.createFormStorageOperations = createFormStorageOperations;
|