@webiny/api-form-builder-so-ddb-es 0.0.0-mt-1
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/LICENSE +21 -0
- package/README.md +12 -0
- package/configurations.d.ts +9 -0
- package/configurations.js +28 -0
- package/definitions/elasticsearch.d.ts +8 -0
- package/definitions/elasticsearch.js +47 -0
- package/definitions/form.d.ts +8 -0
- package/definitions/form.js +104 -0
- package/definitions/settings.d.ts +8 -0
- package/definitions/settings.js +53 -0
- package/definitions/submission.d.ts +8 -0
- package/definitions/submission.js +74 -0
- package/definitions/system.d.ts +8 -0
- package/definitions/system.js +44 -0
- package/definitions/table.d.ts +7 -0
- package/definitions/table.js +23 -0
- package/definitions/tableElasticsearch.d.ts +7 -0
- package/definitions/tableElasticsearch.js +23 -0
- package/index.d.ts +2 -0
- package/index.js +188 -0
- package/operations/form/elasticsearchBody.d.ts +13 -0
- package/operations/form/elasticsearchBody.js +187 -0
- package/operations/form/elasticsearchFields.d.ts +3 -0
- package/operations/form/elasticsearchFields.js +33 -0
- package/operations/form/fields.d.ts +3 -0
- package/operations/form/fields.js +15 -0
- package/operations/form/index.d.ts +17 -0
- package/operations/form/index.js +903 -0
- package/operations/settings/index.d.ts +7 -0
- package/operations/settings/index.js +122 -0
- package/operations/submission/elasticsearchBody.d.ts +13 -0
- package/operations/submission/elasticsearchBody.js +197 -0
- package/operations/submission/elasticsearchFields.d.ts +3 -0
- package/operations/submission/elasticsearchFields.js +30 -0
- package/operations/submission/index.d.ts +12 -0
- package/operations/submission/index.js +340 -0
- package/operations/system/createElasticsearchIndex.d.ts +6 -0
- package/operations/system/createElasticsearchIndex.js +70 -0
- package/operations/system/index.d.ts +7 -0
- package/operations/system/index.js +105 -0
- package/package.json +67 -0
- package/plugins/FormDynamoDbFieldPlugin.d.ts +4 -0
- package/plugins/FormDynamoDbFieldPlugin.js +17 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchBodyModifierPlugin.js +17 -0
- package/plugins/FormElasticsearchFieldPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchFieldPlugin.js +17 -0
- package/plugins/FormElasticsearchQueryModifierPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchQueryModifierPlugin.js +17 -0
- package/plugins/FormElasticsearchSortModifierPlugin.d.ts +4 -0
- package/plugins/FormElasticsearchSortModifierPlugin.js +17 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.d.ts +4 -0
- package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +17 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.d.ts +4 -0
- package/plugins/SubmissionElasticsearchFieldPlugin.js +17 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.d.ts +4 -0
- package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +17 -0
- package/plugins/SubmissionElasticsearchSortModifierPlugin.d.ts +4 -0
- package/plugins/SubmissionElasticsearchSortModifierPlugin.js +17 -0
- package/types.d.ts +66 -0
- package/types.js +17 -0
- package/upgrades/5.16.0/index.d.ts +8 -0
- package/upgrades/5.16.0/index.js +141 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createSubmissionStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
+
|
|
14
|
+
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
15
|
+
|
|
16
|
+
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
17
|
+
|
|
18
|
+
var _limit = require("@webiny/api-elasticsearch/limit");
|
|
19
|
+
|
|
20
|
+
var _elasticsearchBody = require("./elasticsearchBody");
|
|
21
|
+
|
|
22
|
+
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
23
|
+
|
|
24
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
25
|
+
|
|
26
|
+
var _utils = require("@webiny/utils");
|
|
27
|
+
|
|
28
|
+
var _cursors = require("@webiny/api-elasticsearch/cursors");
|
|
29
|
+
|
|
30
|
+
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; }
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
const createSubmissionStorageOperations = params => {
|
|
35
|
+
const {
|
|
36
|
+
entity,
|
|
37
|
+
esEntity,
|
|
38
|
+
table,
|
|
39
|
+
elasticsearch,
|
|
40
|
+
plugins
|
|
41
|
+
} = params;
|
|
42
|
+
|
|
43
|
+
const createSubmissionPartitionKey = params => {
|
|
44
|
+
const {
|
|
45
|
+
tenant,
|
|
46
|
+
locale,
|
|
47
|
+
formId
|
|
48
|
+
} = params;
|
|
49
|
+
const {
|
|
50
|
+
id
|
|
51
|
+
} = (0, _utils.parseIdentifier)(formId);
|
|
52
|
+
return `T#${tenant}#L#${locale}#FB#F#${id}`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const createSubmissionSortKey = id => {
|
|
56
|
+
return `FS#${id}`;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const createSubmissionType = () => {
|
|
60
|
+
return "fb.formSubmission";
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const createSubmission = async params => {
|
|
64
|
+
const {
|
|
65
|
+
submission,
|
|
66
|
+
form
|
|
67
|
+
} = params;
|
|
68
|
+
const keys = {
|
|
69
|
+
PK: createSubmissionPartitionKey(form),
|
|
70
|
+
SK: createSubmissionSortKey(submission.id)
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, submission), keys), {}, {
|
|
75
|
+
TYPE: createSubmissionType()
|
|
76
|
+
}));
|
|
77
|
+
} catch (ex) {
|
|
78
|
+
throw new _error.default(ex.message || "Could not create form submission in the DynamoDB.", ex.code || "UPDATE_FORM_SUBMISSION_ERROR", {
|
|
79
|
+
submission,
|
|
80
|
+
form,
|
|
81
|
+
keys
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const {
|
|
87
|
+
index
|
|
88
|
+
} = _configurations.default.es({
|
|
89
|
+
tenant: form.tenant
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
await esEntity.put(_objectSpread({
|
|
93
|
+
index,
|
|
94
|
+
data: _objectSpread(_objectSpread({}, submission), {}, {
|
|
95
|
+
__type: (0, _elasticsearchBody.createSubmissionElasticType)()
|
|
96
|
+
}),
|
|
97
|
+
TYPE: createSubmissionType()
|
|
98
|
+
}, keys));
|
|
99
|
+
} catch (ex) {
|
|
100
|
+
throw new _error.default(ex.message || "Could not create form submission in the Elasticsearch.", ex.code || "UPDATE_FORM_SUBMISSION_ERROR", {
|
|
101
|
+
submission,
|
|
102
|
+
form,
|
|
103
|
+
keys
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return submission;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* We do not save the data in the Elasticsearch because there is no need for that.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
const updateSubmission = async params => {
|
|
115
|
+
const {
|
|
116
|
+
submission,
|
|
117
|
+
form,
|
|
118
|
+
original
|
|
119
|
+
} = params;
|
|
120
|
+
const keys = {
|
|
121
|
+
PK: createSubmissionPartitionKey(form),
|
|
122
|
+
SK: createSubmissionSortKey(submission.id)
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
await entity.put(_objectSpread(_objectSpread(_objectSpread({}, submission), keys), {}, {
|
|
127
|
+
TYPE: createSubmissionType()
|
|
128
|
+
}));
|
|
129
|
+
return submission;
|
|
130
|
+
} catch (ex) {
|
|
131
|
+
throw new _error.default(ex.message || "Could not update form submission in the DynamoDB.", ex.code || "UPDATE_FORM_SUBMISSION_ERROR", {
|
|
132
|
+
submission,
|
|
133
|
+
original,
|
|
134
|
+
form,
|
|
135
|
+
keys
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const deleteSubmission = async params => {
|
|
141
|
+
const {
|
|
142
|
+
submission,
|
|
143
|
+
form
|
|
144
|
+
} = params;
|
|
145
|
+
const keys = {
|
|
146
|
+
PK: createSubmissionPartitionKey(form),
|
|
147
|
+
SK: createSubmissionSortKey(submission.id)
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
try {
|
|
151
|
+
await entity.delete(keys);
|
|
152
|
+
} catch (ex) {
|
|
153
|
+
throw new _error.default(ex.message || "Could not delete form submission from DynamoDB.", ex.code || "DELETE_FORM_SUBMISSION_ERROR", {
|
|
154
|
+
submission,
|
|
155
|
+
form,
|
|
156
|
+
keys
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
await esEntity.delete(keys);
|
|
162
|
+
} catch (ex) {
|
|
163
|
+
throw new _error.default(ex.message || "Could not delete form submission from Elasticsearch.", ex.code || "DELETE_FORM_SUBMISSION_ERROR", {
|
|
164
|
+
submission,
|
|
165
|
+
form,
|
|
166
|
+
keys
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return submission;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
*
|
|
174
|
+
* We are using this method because it is faster to fetch the exact data from the DynamoDB than Elasticsearch.
|
|
175
|
+
*
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
const listSubmissionsByIds = async params => {
|
|
181
|
+
const {
|
|
182
|
+
where,
|
|
183
|
+
sort
|
|
184
|
+
} = params;
|
|
185
|
+
const items = where.id_in.map(id => {
|
|
186
|
+
return entity.getBatch({
|
|
187
|
+
PK: createSubmissionPartitionKey(_objectSpread({}, where)),
|
|
188
|
+
SK: createSubmissionSortKey(id)
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
let results = [];
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
results = await (0, _batchRead.batchReadAll)({
|
|
195
|
+
table,
|
|
196
|
+
items
|
|
197
|
+
});
|
|
198
|
+
} catch (ex) {
|
|
199
|
+
throw new _error.default(ex.message || "Could not batch read form submissions.", ex.code || "BATCH_READ_SUBMISSIONS_ERROR", {
|
|
200
|
+
where,
|
|
201
|
+
sort
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* We need to remove empty results because it is a possibility that batch read returned null for non-existing record.
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
const submissions = results.filter(Boolean).map(submission => {
|
|
210
|
+
return (0, _cleanup.cleanupItem)(entity, submission);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
if (!sort) {
|
|
214
|
+
return submissions;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return (0, _sort.sortItems)({
|
|
218
|
+
items: submissions,
|
|
219
|
+
sort,
|
|
220
|
+
fields: []
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const listSubmissions = async params => {
|
|
225
|
+
const {
|
|
226
|
+
where,
|
|
227
|
+
sort,
|
|
228
|
+
limit: initialLimit,
|
|
229
|
+
after
|
|
230
|
+
} = params;
|
|
231
|
+
|
|
232
|
+
if (where.id_in) {
|
|
233
|
+
const items = await listSubmissionsByIds(params);
|
|
234
|
+
return {
|
|
235
|
+
items,
|
|
236
|
+
meta: {
|
|
237
|
+
hasMoreItems: false,
|
|
238
|
+
cursor: null,
|
|
239
|
+
totalCount: items.length
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const limit = (0, _limit.createLimit)(initialLimit);
|
|
245
|
+
const body = (0, _elasticsearchBody.createElasticsearchBody)({
|
|
246
|
+
plugins,
|
|
247
|
+
sort,
|
|
248
|
+
limit: limit + 1,
|
|
249
|
+
where,
|
|
250
|
+
after: (0, _cursors.decodeCursor)(after)
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const esConfig = _configurations.default.es({
|
|
254
|
+
tenant: where.tenant
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const query = _objectSpread(_objectSpread({}, esConfig), {}, {
|
|
258
|
+
body
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
let response;
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
response = await elasticsearch.search(query);
|
|
265
|
+
} catch (ex) {
|
|
266
|
+
throw new _error.default(ex.message || "Could list form submissions.", ex.code || "LIST_SUBMISSIONS_ERROR", {
|
|
267
|
+
where,
|
|
268
|
+
query
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const {
|
|
273
|
+
hits,
|
|
274
|
+
total
|
|
275
|
+
} = response.body.hits;
|
|
276
|
+
const items = hits.map(item => item._source);
|
|
277
|
+
const hasMoreItems = items.length > limit;
|
|
278
|
+
|
|
279
|
+
if (hasMoreItems) {
|
|
280
|
+
/**
|
|
281
|
+
* Remove the last item from results, we don't want to include it.
|
|
282
|
+
*/
|
|
283
|
+
items.pop();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Cursor is the `sort` value of the last item in the array.
|
|
287
|
+
* https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
|
|
288
|
+
*/
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
const meta = {
|
|
292
|
+
hasMoreItems,
|
|
293
|
+
totalCount: total.value,
|
|
294
|
+
cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) : null
|
|
295
|
+
};
|
|
296
|
+
return {
|
|
297
|
+
items,
|
|
298
|
+
meta
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const getSubmission = async params => {
|
|
303
|
+
const {
|
|
304
|
+
where
|
|
305
|
+
} = params;
|
|
306
|
+
const keys = {
|
|
307
|
+
PK: createSubmissionPartitionKey(_objectSpread(_objectSpread({}, where), {}, {
|
|
308
|
+
formId: where.formId
|
|
309
|
+
})),
|
|
310
|
+
SK: createSubmissionSortKey(where.id)
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
const result = await entity.get(keys);
|
|
315
|
+
|
|
316
|
+
if (!result || !result.Item) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
321
|
+
} catch (ex) {
|
|
322
|
+
throw new _error.default(ex.message || "Could not oad submission.", ex.code || "GET_SUBMISSION_ERROR", {
|
|
323
|
+
where,
|
|
324
|
+
keys
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
return {
|
|
330
|
+
createSubmission,
|
|
331
|
+
deleteSubmission,
|
|
332
|
+
updateSubmission,
|
|
333
|
+
listSubmissions,
|
|
334
|
+
getSubmission,
|
|
335
|
+
createSubmissionPartitionKey,
|
|
336
|
+
createSubmissionSortKey
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
exports.createSubmissionStorageOperations = createSubmissionStorageOperations;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createElasticsearchIndex = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
const createElasticsearchIndex = async params => {
|
|
19
|
+
const {
|
|
20
|
+
tenant,
|
|
21
|
+
elasticsearch
|
|
22
|
+
} = params;
|
|
23
|
+
|
|
24
|
+
const esIndex = _configurations.default.es({
|
|
25
|
+
tenant
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
body: exists
|
|
30
|
+
} = await elasticsearch.indices.exists(esIndex);
|
|
31
|
+
|
|
32
|
+
if (exists) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await elasticsearch.indices.create(_objectSpread(_objectSpread({}, esIndex), {}, {
|
|
37
|
+
body: {
|
|
38
|
+
/**
|
|
39
|
+
* need this part for sorting to work on text fields
|
|
40
|
+
*/
|
|
41
|
+
settings: {
|
|
42
|
+
analysis: {
|
|
43
|
+
analyzer: {
|
|
44
|
+
lowercase_analyzer: {
|
|
45
|
+
type: "custom",
|
|
46
|
+
filter: ["lowercase", "trim"],
|
|
47
|
+
tokenizer: "keyword"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
mappings: {
|
|
53
|
+
properties: {
|
|
54
|
+
property: {
|
|
55
|
+
type: "text",
|
|
56
|
+
fields: {
|
|
57
|
+
keyword: {
|
|
58
|
+
type: "keyword",
|
|
59
|
+
ignore_above: 256
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
analyzer: "lowercase_analyzer"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
exports.createElasticsearchIndex = createElasticsearchIndex;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Entity, Table } from "dynamodb-toolbox";
|
|
2
|
+
import { FormBuilderSystemStorageOperations } from "../../types";
|
|
3
|
+
export interface Params {
|
|
4
|
+
entity: Entity<any>;
|
|
5
|
+
table: Table;
|
|
6
|
+
}
|
|
7
|
+
export declare const createSystemStorageOperations: (params: Params) => FormBuilderSystemStorageOperations;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createSystemStorageOperations = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
const createSystemStorageOperations = params => {
|
|
21
|
+
const {
|
|
22
|
+
entity
|
|
23
|
+
} = params;
|
|
24
|
+
|
|
25
|
+
const createSystemPartitionKey = ({
|
|
26
|
+
tenant
|
|
27
|
+
}) => {
|
|
28
|
+
return `T#${tenant}#SYSTEM`;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const createSystemSortKey = () => {
|
|
32
|
+
return "FB";
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const createKeys = params => {
|
|
36
|
+
return {
|
|
37
|
+
PK: createSystemPartitionKey(params),
|
|
38
|
+
SK: createSystemSortKey()
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const createSystem = async params => {
|
|
43
|
+
const {
|
|
44
|
+
system
|
|
45
|
+
} = params;
|
|
46
|
+
const keys = createKeys(system);
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
await entity.put(_objectSpread(_objectSpread({}, system), keys));
|
|
50
|
+
return system;
|
|
51
|
+
} catch (ex) {
|
|
52
|
+
throw new _error.default(ex.message || "Could not create the system record by given keys.", ex.code || "CREATE_SYSTEM_ERROR", {
|
|
53
|
+
keys,
|
|
54
|
+
system
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const getSystem = async params => {
|
|
60
|
+
const keys = createKeys(params);
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
const result = await entity.get(keys);
|
|
64
|
+
|
|
65
|
+
if (!result || !result.Item) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
70
|
+
} catch (ex) {
|
|
71
|
+
throw new _error.default(ex.message || "Could not get the system record by given keys.", ex.code || "LOAD_SYSTEM_ERROR", {
|
|
72
|
+
keys
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const updateSystem = async params => {
|
|
78
|
+
const {
|
|
79
|
+
system,
|
|
80
|
+
original
|
|
81
|
+
} = params;
|
|
82
|
+
const keys = createKeys(system);
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
await entity.put(_objectSpread(_objectSpread({}, system), keys));
|
|
86
|
+
return system;
|
|
87
|
+
} catch (ex) {
|
|
88
|
+
throw new _error.default(ex.message || "Could not update the system record by given keys.", ex.code || "UPDATE_SYSTEM_ERROR", {
|
|
89
|
+
keys,
|
|
90
|
+
original,
|
|
91
|
+
system
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
createSystem,
|
|
98
|
+
getSystem,
|
|
99
|
+
updateSystem,
|
|
100
|
+
createSystemPartitionKey,
|
|
101
|
+
createSystemSortKey
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
exports.createSystemStorageOperations = createSystemStorageOperations;
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/api-form-builder-so-ddb-es",
|
|
3
|
+
"version": "0.0.0-mt-1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"@webiny/api-form-builder",
|
|
7
|
+
"storage-operations",
|
|
8
|
+
"dynamodb",
|
|
9
|
+
"elasticsearch",
|
|
10
|
+
"fb:ddb-es"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/webiny/webiny-js.git",
|
|
15
|
+
"directory": "packages/api-form-builder-so-ddb-es"
|
|
16
|
+
},
|
|
17
|
+
"contributors": [
|
|
18
|
+
"Pavel Denisjuk <pavel@webiny.com>",
|
|
19
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
20
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@babel/runtime": "7.15.4",
|
|
25
|
+
"@elastic/elasticsearch": "7.12.0",
|
|
26
|
+
"@webiny/api-elasticsearch": "0.0.0-mt-1",
|
|
27
|
+
"@webiny/api-form-builder": "0.0.0-mt-1",
|
|
28
|
+
"@webiny/api-i18n": "0.0.0-mt-1",
|
|
29
|
+
"@webiny/api-tenancy": "0.0.0-mt-1",
|
|
30
|
+
"@webiny/api-upgrade": "0.0.0-mt-1",
|
|
31
|
+
"@webiny/db-dynamodb": "0.0.0-mt-1",
|
|
32
|
+
"@webiny/error": "0.0.0-mt-1",
|
|
33
|
+
"@webiny/handler": "0.0.0-mt-1",
|
|
34
|
+
"@webiny/handler-aws": "0.0.0-mt-1",
|
|
35
|
+
"@webiny/plugins": "0.0.0-mt-1",
|
|
36
|
+
"@webiny/utils": "0.0.0-mt-1",
|
|
37
|
+
"dynamodb-toolbox": "0.3.4",
|
|
38
|
+
"elastic-ts": "0.7.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@babel/cli": "^7.5.5",
|
|
42
|
+
"@babel/core": "^7.5.5",
|
|
43
|
+
"@babel/preset-env": "^7.5.5",
|
|
44
|
+
"@babel/preset-typescript": "^7.8.3",
|
|
45
|
+
"@shelf/jest-elasticsearch": "^1.0.0",
|
|
46
|
+
"@webiny/api-dynamodb-to-elasticsearch": "^0.0.0-mt-1",
|
|
47
|
+
"@webiny/cli": "^0.0.0-mt-1",
|
|
48
|
+
"@webiny/handler-db": "^0.0.0-mt-1",
|
|
49
|
+
"@webiny/project-utils": "^0.0.0-mt-1",
|
|
50
|
+
"csvtojson": "^2.0.10",
|
|
51
|
+
"jest": "^26.6.3",
|
|
52
|
+
"jest-dynalite": "^3.2.0",
|
|
53
|
+
"jest-environment-node": "^27.2.4",
|
|
54
|
+
"rimraf": "^3.0.2",
|
|
55
|
+
"ttypescript": "^1.5.12",
|
|
56
|
+
"typescript": "^4.1.3"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public",
|
|
60
|
+
"directory": "dist"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "yarn webiny run build",
|
|
64
|
+
"watch": "yarn webiny run watch"
|
|
65
|
+
},
|
|
66
|
+
"gitHead": "37736d8456a6ecb342a6c3645060bd9a3f2d4bb0"
|
|
67
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FormDynamoDbFieldPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _FieldPlugin = require("@webiny/db-dynamodb/plugins/definitions/FieldPlugin");
|
|
13
|
+
|
|
14
|
+
class FormDynamoDbFieldPlugin extends _FieldPlugin.FieldPlugin {}
|
|
15
|
+
|
|
16
|
+
exports.FormDynamoDbFieldPlugin = FormDynamoDbFieldPlugin;
|
|
17
|
+
(0, _defineProperty2.default)(FormDynamoDbFieldPlugin, "type", "formBuilder.dynamodb.field.form");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FormElasticsearchBodyModifierPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchBodyModifierPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchBodyModifierPlugin");
|
|
13
|
+
|
|
14
|
+
class FormElasticsearchBodyModifierPlugin extends _ElasticsearchBodyModifierPlugin.ElasticsearchBodyModifierPlugin {}
|
|
15
|
+
|
|
16
|
+
exports.FormElasticsearchBodyModifierPlugin = FormElasticsearchBodyModifierPlugin;
|
|
17
|
+
(0, _defineProperty2.default)(FormElasticsearchBodyModifierPlugin, "type", "formBuilder.elasticsearch.modifier.body.form");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FormElasticsearchFieldPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchFieldPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchFieldPlugin");
|
|
13
|
+
|
|
14
|
+
class FormElasticsearchFieldPlugin extends _ElasticsearchFieldPlugin.ElasticsearchFieldPlugin {}
|
|
15
|
+
|
|
16
|
+
exports.FormElasticsearchFieldPlugin = FormElasticsearchFieldPlugin;
|
|
17
|
+
(0, _defineProperty2.default)(FormElasticsearchFieldPlugin, "type", "formBuilder.elasticsearch.fieldDefinition.form");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.FormElasticsearchQueryModifierPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryModifierPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryModifierPlugin");
|
|
13
|
+
|
|
14
|
+
class FormElasticsearchQueryModifierPlugin extends _ElasticsearchQueryModifierPlugin.ElasticsearchQueryModifierPlugin {}
|
|
15
|
+
|
|
16
|
+
exports.FormElasticsearchQueryModifierPlugin = FormElasticsearchQueryModifierPlugin;
|
|
17
|
+
(0, _defineProperty2.default)(FormElasticsearchQueryModifierPlugin, "type", "formBuilder.elasticsearch.modifier.query.form");
|