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