@webiny/api-form-builder-so-ddb-es 0.0.0-mt-2 → 0.0.0-unstable.06b2ede40f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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
|
@@ -1,36 +1,18 @@
|
|
|
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.createSubmissionStorageOperations = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
8
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
13
|
-
|
|
14
|
-
var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
|
|
15
|
-
|
|
9
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
16
10
|
var _sort = require("@webiny/db-dynamodb/utils/sort");
|
|
17
|
-
|
|
18
|
-
var _limit = require("@webiny/api-elasticsearch/limit");
|
|
19
|
-
|
|
11
|
+
var _apiElasticsearch = require("@webiny/api-elasticsearch");
|
|
20
12
|
var _elasticsearchBody = require("./elasticsearchBody");
|
|
21
|
-
|
|
22
|
-
var _configurations = _interopRequireDefault(require("../../configurations"));
|
|
23
|
-
|
|
13
|
+
var _configurations = require("../../configurations");
|
|
24
14
|
var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
|
|
25
|
-
|
|
26
15
|
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
16
|
const createSubmissionStorageOperations = params => {
|
|
35
17
|
const {
|
|
36
18
|
entity,
|
|
@@ -39,7 +21,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
39
21
|
elasticsearch,
|
|
40
22
|
plugins
|
|
41
23
|
} = params;
|
|
42
|
-
|
|
43
24
|
const createSubmissionPartitionKey = params => {
|
|
44
25
|
const {
|
|
45
26
|
tenant,
|
|
@@ -51,15 +32,12 @@ const createSubmissionStorageOperations = params => {
|
|
|
51
32
|
} = (0, _utils.parseIdentifier)(formId);
|
|
52
33
|
return `T#${tenant}#L#${locale}#FB#F#${id}`;
|
|
53
34
|
};
|
|
54
|
-
|
|
55
35
|
const createSubmissionSortKey = id => {
|
|
56
36
|
return `FS#${id}`;
|
|
57
37
|
};
|
|
58
|
-
|
|
59
38
|
const createSubmissionType = () => {
|
|
60
39
|
return "fb.formSubmission";
|
|
61
40
|
};
|
|
62
|
-
|
|
63
41
|
const createSubmission = async params => {
|
|
64
42
|
const {
|
|
65
43
|
submission,
|
|
@@ -69,11 +47,15 @@ const createSubmissionStorageOperations = params => {
|
|
|
69
47
|
PK: createSubmissionPartitionKey(form),
|
|
70
48
|
SK: createSubmissionSortKey(submission.id)
|
|
71
49
|
};
|
|
72
|
-
|
|
73
50
|
try {
|
|
74
|
-
await
|
|
75
|
-
|
|
76
|
-
|
|
51
|
+
await (0, _dbDynamodb.put)({
|
|
52
|
+
entity,
|
|
53
|
+
item: {
|
|
54
|
+
...submission,
|
|
55
|
+
...keys,
|
|
56
|
+
TYPE: createSubmissionType()
|
|
57
|
+
}
|
|
58
|
+
});
|
|
77
59
|
} catch (ex) {
|
|
78
60
|
throw new _error.default(ex.message || "Could not create form submission in the DynamoDB.", ex.code || "UPDATE_FORM_SUBMISSION_ERROR", {
|
|
79
61
|
submission,
|
|
@@ -81,21 +63,25 @@ const createSubmissionStorageOperations = params => {
|
|
|
81
63
|
keys
|
|
82
64
|
});
|
|
83
65
|
}
|
|
84
|
-
|
|
85
66
|
try {
|
|
86
67
|
const {
|
|
87
68
|
index
|
|
88
|
-
} = _configurations.
|
|
89
|
-
tenant: form.tenant
|
|
69
|
+
} = _configurations.configurations.es({
|
|
70
|
+
tenant: form.tenant,
|
|
71
|
+
locale: form.locale
|
|
72
|
+
});
|
|
73
|
+
await (0, _dbDynamodb.put)({
|
|
74
|
+
entity: esEntity,
|
|
75
|
+
item: {
|
|
76
|
+
index,
|
|
77
|
+
data: {
|
|
78
|
+
...submission,
|
|
79
|
+
__type: (0, _elasticsearchBody.createSubmissionElasticType)()
|
|
80
|
+
},
|
|
81
|
+
TYPE: createSubmissionType(),
|
|
82
|
+
...keys
|
|
83
|
+
}
|
|
90
84
|
});
|
|
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
85
|
} catch (ex) {
|
|
100
86
|
throw new _error.default(ex.message || "Could not create form submission in the Elasticsearch.", ex.code || "UPDATE_FORM_SUBMISSION_ERROR", {
|
|
101
87
|
submission,
|
|
@@ -103,14 +89,11 @@ const createSubmissionStorageOperations = params => {
|
|
|
103
89
|
keys
|
|
104
90
|
});
|
|
105
91
|
}
|
|
106
|
-
|
|
107
92
|
return submission;
|
|
108
93
|
};
|
|
109
94
|
/**
|
|
110
95
|
* We do not save the data in the Elasticsearch because there is no need for that.
|
|
111
96
|
*/
|
|
112
|
-
|
|
113
|
-
|
|
114
97
|
const updateSubmission = async params => {
|
|
115
98
|
const {
|
|
116
99
|
submission,
|
|
@@ -121,11 +104,15 @@ const createSubmissionStorageOperations = params => {
|
|
|
121
104
|
PK: createSubmissionPartitionKey(form),
|
|
122
105
|
SK: createSubmissionSortKey(submission.id)
|
|
123
106
|
};
|
|
124
|
-
|
|
125
107
|
try {
|
|
126
|
-
await
|
|
127
|
-
|
|
128
|
-
|
|
108
|
+
await (0, _dbDynamodb.put)({
|
|
109
|
+
entity,
|
|
110
|
+
item: {
|
|
111
|
+
...submission,
|
|
112
|
+
...keys,
|
|
113
|
+
TYPE: createSubmissionType()
|
|
114
|
+
}
|
|
115
|
+
});
|
|
129
116
|
return submission;
|
|
130
117
|
} catch (ex) {
|
|
131
118
|
throw new _error.default(ex.message || "Could not update form submission in the DynamoDB.", ex.code || "UPDATE_FORM_SUBMISSION_ERROR", {
|
|
@@ -136,7 +123,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
136
123
|
});
|
|
137
124
|
}
|
|
138
125
|
};
|
|
139
|
-
|
|
140
126
|
const deleteSubmission = async params => {
|
|
141
127
|
const {
|
|
142
128
|
submission,
|
|
@@ -146,9 +132,11 @@ const createSubmissionStorageOperations = params => {
|
|
|
146
132
|
PK: createSubmissionPartitionKey(form),
|
|
147
133
|
SK: createSubmissionSortKey(submission.id)
|
|
148
134
|
};
|
|
149
|
-
|
|
150
135
|
try {
|
|
151
|
-
await
|
|
136
|
+
await (0, _dbDynamodb.deleteItem)({
|
|
137
|
+
entity,
|
|
138
|
+
keys
|
|
139
|
+
});
|
|
152
140
|
} catch (ex) {
|
|
153
141
|
throw new _error.default(ex.message || "Could not delete form submission from DynamoDB.", ex.code || "DELETE_FORM_SUBMISSION_ERROR", {
|
|
154
142
|
submission,
|
|
@@ -156,9 +144,11 @@ const createSubmissionStorageOperations = params => {
|
|
|
156
144
|
keys
|
|
157
145
|
});
|
|
158
146
|
}
|
|
159
|
-
|
|
160
147
|
try {
|
|
161
|
-
await
|
|
148
|
+
await (0, _dbDynamodb.deleteItem)({
|
|
149
|
+
entity: esEntity,
|
|
150
|
+
keys
|
|
151
|
+
});
|
|
162
152
|
} catch (ex) {
|
|
163
153
|
throw new _error.default(ex.message || "Could not delete form submission from Elasticsearch.", ex.code || "DELETE_FORM_SUBMISSION_ERROR", {
|
|
164
154
|
submission,
|
|
@@ -166,32 +156,31 @@ const createSubmissionStorageOperations = params => {
|
|
|
166
156
|
keys
|
|
167
157
|
});
|
|
168
158
|
}
|
|
169
|
-
|
|
170
159
|
return submission;
|
|
171
160
|
};
|
|
161
|
+
|
|
172
162
|
/**
|
|
173
163
|
*
|
|
174
164
|
* We are using this method because it is faster to fetch the exact data from the DynamoDB than Elasticsearch.
|
|
175
165
|
*
|
|
176
166
|
* @internal
|
|
177
167
|
*/
|
|
178
|
-
|
|
179
|
-
|
|
180
168
|
const listSubmissionsByIds = async params => {
|
|
181
169
|
const {
|
|
182
170
|
where,
|
|
183
171
|
sort
|
|
184
172
|
} = params;
|
|
185
|
-
const items = where.id_in.map(id => {
|
|
173
|
+
const items = (where.id_in || []).map(id => {
|
|
186
174
|
return entity.getBatch({
|
|
187
|
-
PK: createSubmissionPartitionKey(
|
|
175
|
+
PK: createSubmissionPartitionKey({
|
|
176
|
+
...where
|
|
177
|
+
}),
|
|
188
178
|
SK: createSubmissionSortKey(id)
|
|
189
179
|
});
|
|
190
180
|
});
|
|
191
181
|
let results = [];
|
|
192
|
-
|
|
193
182
|
try {
|
|
194
|
-
results = await (0,
|
|
183
|
+
results = await (0, _dbDynamodb.batchReadAll)({
|
|
195
184
|
table,
|
|
196
185
|
items
|
|
197
186
|
});
|
|
@@ -204,31 +193,25 @@ const createSubmissionStorageOperations = params => {
|
|
|
204
193
|
/**
|
|
205
194
|
* We need to remove empty results because it is a possibility that batch read returned null for non-existing record.
|
|
206
195
|
*/
|
|
207
|
-
|
|
208
|
-
|
|
209
196
|
const submissions = results.filter(Boolean).map(submission => {
|
|
210
197
|
return (0, _cleanup.cleanupItem)(entity, submission);
|
|
211
198
|
});
|
|
212
|
-
|
|
213
199
|
if (!sort) {
|
|
214
200
|
return submissions;
|
|
215
201
|
}
|
|
216
|
-
|
|
217
202
|
return (0, _sort.sortItems)({
|
|
218
203
|
items: submissions,
|
|
219
204
|
sort,
|
|
220
205
|
fields: []
|
|
221
206
|
});
|
|
222
207
|
};
|
|
223
|
-
|
|
224
208
|
const listSubmissions = async params => {
|
|
225
209
|
const {
|
|
226
210
|
where,
|
|
227
|
-
sort,
|
|
211
|
+
sort = [],
|
|
228
212
|
limit: initialLimit,
|
|
229
213
|
after
|
|
230
214
|
} = params;
|
|
231
|
-
|
|
232
215
|
if (where.id_in) {
|
|
233
216
|
const items = await listSubmissionsByIds(params);
|
|
234
217
|
return {
|
|
@@ -240,26 +223,23 @@ const createSubmissionStorageOperations = params => {
|
|
|
240
223
|
}
|
|
241
224
|
};
|
|
242
225
|
}
|
|
243
|
-
|
|
244
|
-
const limit = (0, _limit.createLimit)(initialLimit);
|
|
226
|
+
const limit = (0, _apiElasticsearch.createLimit)(initialLimit);
|
|
245
227
|
const body = (0, _elasticsearchBody.createElasticsearchBody)({
|
|
246
228
|
plugins,
|
|
247
229
|
sort,
|
|
248
230
|
limit: limit + 1,
|
|
249
231
|
where,
|
|
250
|
-
after: (0,
|
|
232
|
+
after: (0, _apiElasticsearch.decodeCursor)(after)
|
|
251
233
|
});
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
234
|
+
const esConfig = _configurations.configurations.es({
|
|
235
|
+
tenant: where.tenant,
|
|
236
|
+
locale: where.locale
|
|
255
237
|
});
|
|
256
|
-
|
|
257
|
-
|
|
238
|
+
const query = {
|
|
239
|
+
...esConfig,
|
|
258
240
|
body
|
|
259
|
-
}
|
|
260
|
-
|
|
241
|
+
};
|
|
261
242
|
let response;
|
|
262
|
-
|
|
263
243
|
try {
|
|
264
244
|
response = await elasticsearch.search(query);
|
|
265
245
|
} catch (ex) {
|
|
@@ -268,14 +248,12 @@ const createSubmissionStorageOperations = params => {
|
|
|
268
248
|
query
|
|
269
249
|
});
|
|
270
250
|
}
|
|
271
|
-
|
|
272
251
|
const {
|
|
273
252
|
hits,
|
|
274
253
|
total
|
|
275
254
|
} = response.body.hits;
|
|
276
255
|
const items = hits.map(item => item._source);
|
|
277
256
|
const hasMoreItems = items.length > limit;
|
|
278
|
-
|
|
279
257
|
if (hasMoreItems) {
|
|
280
258
|
/**
|
|
281
259
|
* Remove the last item from results, we don't want to include it.
|
|
@@ -286,38 +264,32 @@ const createSubmissionStorageOperations = params => {
|
|
|
286
264
|
* Cursor is the `sort` value of the last item in the array.
|
|
287
265
|
* https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
|
|
288
266
|
*/
|
|
289
|
-
|
|
290
|
-
|
|
291
267
|
const meta = {
|
|
292
268
|
hasMoreItems,
|
|
293
269
|
totalCount: total.value,
|
|
294
|
-
cursor: items.length > 0 ? (0,
|
|
270
|
+
cursor: items.length > 0 ? (0, _apiElasticsearch.encodeCursor)(hits[items.length - 1].sort) || null : null
|
|
295
271
|
};
|
|
296
272
|
return {
|
|
297
273
|
items,
|
|
298
274
|
meta
|
|
299
275
|
};
|
|
300
276
|
};
|
|
301
|
-
|
|
302
277
|
const getSubmission = async params => {
|
|
303
278
|
const {
|
|
304
279
|
where
|
|
305
280
|
} = params;
|
|
306
281
|
const keys = {
|
|
307
|
-
PK: createSubmissionPartitionKey(
|
|
282
|
+
PK: createSubmissionPartitionKey({
|
|
283
|
+
...where,
|
|
308
284
|
formId: where.formId
|
|
309
|
-
})
|
|
285
|
+
}),
|
|
310
286
|
SK: createSubmissionSortKey(where.id)
|
|
311
287
|
};
|
|
312
|
-
|
|
313
288
|
try {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
289
|
+
return await (0, _dbDynamodb.getClean)({
|
|
290
|
+
entity,
|
|
291
|
+
keys
|
|
292
|
+
});
|
|
321
293
|
} catch (ex) {
|
|
322
294
|
throw new _error.default(ex.message || "Could not oad submission.", ex.code || "GET_SUBMISSION_ERROR", {
|
|
323
295
|
where,
|
|
@@ -325,7 +297,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
325
297
|
});
|
|
326
298
|
}
|
|
327
299
|
};
|
|
328
|
-
|
|
329
300
|
return {
|
|
330
301
|
createSubmission,
|
|
331
302
|
deleteSubmission,
|
|
@@ -336,5 +307,6 @@ const createSubmissionStorageOperations = params => {
|
|
|
336
307
|
createSubmissionSortKey
|
|
337
308
|
};
|
|
338
309
|
};
|
|
310
|
+
exports.createSubmissionStorageOperations = createSubmissionStorageOperations;
|
|
339
311
|
|
|
340
|
-
|
|
312
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_dbDynamodb","_sort","_apiElasticsearch","_elasticsearchBody","_configurations","_cleanup","_utils","createSubmissionStorageOperations","params","entity","esEntity","table","elasticsearch","plugins","createSubmissionPartitionKey","tenant","locale","formId","id","parseIdentifier","createSubmissionSortKey","createSubmissionType","createSubmission","submission","form","keys","PK","SK","put","item","TYPE","ex","WebinyError","message","code","index","configurations","es","data","__type","createSubmissionElasticType","updateSubmission","original","deleteSubmission","deleteItem","listSubmissionsByIds","where","sort","items","id_in","map","getBatch","results","batchReadAll","submissions","filter","Boolean","cleanupItem","sortItems","fields","listSubmissions","limit","initialLimit","after","meta","hasMoreItems","cursor","totalCount","length","createLimit","body","createElasticsearchBody","decodeCursor","esConfig","query","response","search","hits","total","_source","pop","value","encodeCursor","getSubmission","getClean","exports"],"sources":["index.ts"],"sourcesContent":["import type {\n FbSubmission,\n FormBuilderStorageOperationsCreateSubmissionParams,\n FormBuilderStorageOperationsDeleteSubmissionParams,\n FormBuilderStorageOperationsGetSubmissionParams,\n FormBuilderStorageOperationsListSubmissionsParams,\n FormBuilderStorageOperationsListSubmissionsResponse,\n FormBuilderStorageOperationsUpdateSubmissionParams\n} from \"@webiny/api-form-builder/types\";\nimport type { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\nimport type { Client } from \"@elastic/elasticsearch\";\nimport WebinyError from \"@webiny/error\";\nimport { batchReadAll } from \"@webiny/db-dynamodb\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { createLimit, decodeCursor, encodeCursor } from \"@webiny/api-elasticsearch\";\nimport {\n createElasticsearchBody,\n createSubmissionElasticType\n} from \"~/operations/submission/elasticsearchBody\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport type {\n FormBuilderSubmissionStorageOperations,\n FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n} from \"~/types\";\nimport { configurations } from \"~/configurations\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport { parseIdentifier } from \"@webiny/utils\";\nimport type { ElasticsearchSearchResponse } from \"@webiny/api-elasticsearch/types\";\nimport { deleteItem, getClean, put } from \"@webiny/db-dynamodb\";\n\nexport interface CreateSubmissionStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n table: Table<string, string, string>;\n elasticsearch: Client;\n plugins: PluginsContainer;\n}\n\nexport const createSubmissionStorageOperations = (\n params: CreateSubmissionStorageOperationsParams\n): FormBuilderSubmissionStorageOperations => {\n const { entity, esEntity, table, elasticsearch, plugins } = params;\n\n const createSubmissionPartitionKey = (\n params: FormBuilderSubmissionStorageOperationsCreatePartitionKeyParams\n ) => {\n const { tenant, locale, formId } = params;\n\n const { id } = parseIdentifier(formId);\n\n return `T#${tenant}#L#${locale}#FB#F#${id}`;\n };\n const createSubmissionSortKey = (id: string) => {\n return `FS#${id}`;\n };\n\n const createSubmissionType = () => {\n return \"fb.formSubmission\";\n };\n\n const createSubmission = async (\n params: FormBuilderStorageOperationsCreateSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form } = params;\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await put({\n entity,\n item: {\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\n }\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create form submission in the DynamoDB.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n try {\n const { index } = configurations.es({\n tenant: form.tenant,\n locale: form.locale\n });\n await put({\n entity: esEntity,\n item: {\n index,\n data: {\n ...submission,\n __type: createSubmissionElasticType()\n },\n TYPE: createSubmissionType(),\n ...keys\n }\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create form submission in the Elasticsearch.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n return submission;\n };\n /**\n * We do not save the data in the Elasticsearch because there is no need for that.\n */\n const updateSubmission = async (\n params: FormBuilderStorageOperationsUpdateSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form, original } = params;\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await put({\n entity,\n item: {\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\n }\n });\n return submission;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update form submission in the DynamoDB.\",\n ex.code || \"UPDATE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n original,\n form,\n keys\n }\n );\n }\n };\n\n const deleteSubmission = async (\n params: FormBuilderStorageOperationsDeleteSubmissionParams\n ): Promise<FbSubmission> => {\n const { submission, form } = params;\n\n const keys = {\n PK: createSubmissionPartitionKey(form),\n SK: createSubmissionSortKey(submission.id)\n };\n\n try {\n await deleteItem({\n entity,\n keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form submission from DynamoDB.\",\n ex.code || \"DELETE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n try {\n await deleteItem({\n entity: esEntity,\n keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not delete form submission from Elasticsearch.\",\n ex.code || \"DELETE_FORM_SUBMISSION_ERROR\",\n {\n submission,\n form,\n keys\n }\n );\n }\n\n return submission;\n };\n\n /**\n *\n * We are using this method because it is faster to fetch the exact data from the DynamoDB than Elasticsearch.\n *\n * @internal\n */\n const listSubmissionsByIds = async (\n params: FormBuilderStorageOperationsListSubmissionsParams\n ): Promise<FbSubmission[]> => {\n const { where, sort } = params;\n const items = (where.id_in || []).map(id => {\n return entity.getBatch({\n PK: createSubmissionPartitionKey({\n ...where\n }),\n SK: createSubmissionSortKey(id)\n });\n });\n\n let results: FbSubmission[] = [];\n\n try {\n results = await batchReadAll<FbSubmission>({\n table,\n items\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not batch read form submissions.\",\n ex.code || \"BATCH_READ_SUBMISSIONS_ERROR\",\n {\n where,\n sort\n }\n );\n }\n /**\n * We need to remove empty results because it is a possibility that batch read returned null for non-existing record.\n */\n const submissions = results.filter(Boolean).map(submission => {\n return cleanupItem(entity, submission);\n }) as FbSubmission[];\n if (!sort) {\n return submissions;\n }\n return sortItems<FbSubmission>({\n items: submissions,\n sort,\n fields: []\n });\n };\n\n const listSubmissions = async (\n params: FormBuilderStorageOperationsListSubmissionsParams\n ): Promise<FormBuilderStorageOperationsListSubmissionsResponse> => {\n const { where, sort = [], limit: initialLimit, after } = params;\n\n if (where.id_in) {\n const items = await listSubmissionsByIds(params);\n\n return {\n items,\n meta: {\n hasMoreItems: false,\n cursor: null,\n totalCount: items.length\n }\n };\n }\n\n const limit = createLimit(initialLimit);\n\n const body = createElasticsearchBody({\n plugins,\n sort,\n limit: limit + 1,\n where,\n after: decodeCursor(after)\n });\n\n const esConfig = configurations.es({\n tenant: where.tenant,\n locale: where.locale\n });\n\n const query = {\n ...esConfig,\n body\n };\n\n let response: ElasticsearchSearchResponse<FbSubmission>;\n try {\n response = await elasticsearch.search(query);\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could list form submissions.\",\n ex.code || \"LIST_SUBMISSIONS_ERROR\",\n {\n where,\n query\n }\n );\n }\n\n const { hits, total } = response.body.hits;\n const items = hits.map(item => item._source);\n\n const hasMoreItems = items.length > limit;\n if (hasMoreItems) {\n /**\n * Remove the last item from results, we don't want to include it.\n */\n items.pop();\n }\n /**\n * Cursor is the `sort` value of the last item in the array.\n * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after\n */\n const meta = {\n hasMoreItems,\n totalCount: total.value,\n cursor: items.length > 0 ? encodeCursor(hits[items.length - 1].sort) || null : null\n };\n\n return {\n items,\n meta\n };\n };\n\n const getSubmission = async (\n params: FormBuilderStorageOperationsGetSubmissionParams\n ): Promise<FbSubmission | null> => {\n const { where } = params;\n\n const keys = {\n PK: createSubmissionPartitionKey({\n ...where,\n formId: where.formId as string\n }),\n SK: createSubmissionSortKey(where.id)\n };\n\n try {\n return await getClean<FbSubmission>({\n entity,\n keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not oad submission.\",\n ex.code || \"GET_SUBMISSION_ERROR\",\n {\n where,\n keys\n }\n );\n }\n };\n\n return {\n createSubmission,\n deleteSubmission,\n updateSubmission,\n listSubmissions,\n getSubmission,\n createSubmissionPartitionKey,\n createSubmissionSortKey\n };\n};\n"],"mappings":";;;;;;;AAWA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,kBAAA,GAAAJ,OAAA;AASA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAYO,MAAMQ,iCAAiC,GAC1CC,MAA+C,IACN;EACzC,MAAM;IAAEC,MAAM;IAAEC,QAAQ;IAAEC,KAAK;IAAEC,aAAa;IAAEC;EAAQ,CAAC,GAAGL,MAAM;EAElE,MAAMM,4BAA4B,GAC9BN,MAAsE,IACrE;IACD,MAAM;MAAEO,MAAM;MAAEC,MAAM;MAAEC;IAAO,CAAC,GAAGT,MAAM;IAEzC,MAAM;MAAEU;IAAG,CAAC,GAAG,IAAAC,sBAAe,EAACF,MAAM,CAAC;IAEtC,OAAO,KAAKF,MAAM,MAAMC,MAAM,SAASE,EAAE,EAAE;EAC/C,CAAC;EACD,MAAME,uBAAuB,GAAI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xC,CAAC;IAED,IAAI;MACA,OAAO,MAAM,IAAAkE,oBAAQ,EAAe;QAChC3E,MAAM;QACNgB;MACJ,CAAC,CAAC;IACN,CAAC,CAAC,OAAOM,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,2BAA2B,EACzCF,EAAE,CAACG,IAAI,IAAI,sBAAsB,EACjC;QACIY,KAAK;QACLrB;MACJ,CACJ,CAAC;IACL;EACJ,CAAC;EAED,OAAO;IACHH,gBAAgB;IAChBqB,gBAAgB;IAChBF,gBAAgB;IAChBmB,eAAe;IACfuB,aAAa;IACbrE,4BAA4B;IAC5BM;EACJ,CAAC;AACL,CAAC;AAACiE,OAAA,CAAA9E,iCAAA,GAAAA,iCAAA","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Entity, Table } from "dynamodb
|
|
2
|
-
import { FormBuilderSystemStorageOperations } from "../../types";
|
|
3
|
-
export interface
|
|
1
|
+
import type { Entity, Table } from "@webiny/db-dynamodb/toolbox";
|
|
2
|
+
import type { FormBuilderSystemStorageOperations } from "../../types";
|
|
3
|
+
export interface CreateSystemStorageOperationsParams {
|
|
4
4
|
entity: Entity<any>;
|
|
5
|
-
table: Table
|
|
5
|
+
table: Table<string, string, string>;
|
|
6
6
|
}
|
|
7
|
-
export declare const createSystemStorageOperations: (params:
|
|
7
|
+
export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => FormBuilderSystemStorageOperations;
|
|
@@ -1,52 +1,43 @@
|
|
|
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.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
8
|
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
|
-
|
|
9
|
+
var _dbDynamodb = require("@webiny/db-dynamodb");
|
|
20
10
|
const createSystemStorageOperations = params => {
|
|
21
11
|
const {
|
|
22
12
|
entity
|
|
23
13
|
} = params;
|
|
24
|
-
|
|
25
14
|
const createSystemPartitionKey = ({
|
|
26
15
|
tenant
|
|
27
16
|
}) => {
|
|
28
17
|
return `T#${tenant}#SYSTEM`;
|
|
29
18
|
};
|
|
30
|
-
|
|
31
19
|
const createSystemSortKey = () => {
|
|
32
20
|
return "FB";
|
|
33
21
|
};
|
|
34
|
-
|
|
35
22
|
const createKeys = params => {
|
|
36
23
|
return {
|
|
37
24
|
PK: createSystemPartitionKey(params),
|
|
38
25
|
SK: createSystemSortKey()
|
|
39
26
|
};
|
|
40
27
|
};
|
|
41
|
-
|
|
42
28
|
const createSystem = async params => {
|
|
43
29
|
const {
|
|
44
30
|
system
|
|
45
31
|
} = params;
|
|
46
32
|
const keys = createKeys(system);
|
|
47
|
-
|
|
48
33
|
try {
|
|
49
|
-
await
|
|
34
|
+
await (0, _dbDynamodb.put)({
|
|
35
|
+
entity,
|
|
36
|
+
item: {
|
|
37
|
+
...system,
|
|
38
|
+
...keys
|
|
39
|
+
}
|
|
40
|
+
});
|
|
50
41
|
return system;
|
|
51
42
|
} catch (ex) {
|
|
52
43
|
throw new _error.default(ex.message || "Could not create the system record by given keys.", ex.code || "CREATE_SYSTEM_ERROR", {
|
|
@@ -55,34 +46,33 @@ const createSystemStorageOperations = params => {
|
|
|
55
46
|
});
|
|
56
47
|
}
|
|
57
48
|
};
|
|
58
|
-
|
|
59
49
|
const getSystem = async params => {
|
|
60
50
|
const keys = createKeys(params);
|
|
61
|
-
|
|
62
51
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return (0, _cleanup.cleanupItem)(entity, result.Item);
|
|
52
|
+
return await (0, _dbDynamodb.getClean)({
|
|
53
|
+
entity,
|
|
54
|
+
keys
|
|
55
|
+
});
|
|
70
56
|
} catch (ex) {
|
|
71
57
|
throw new _error.default(ex.message || "Could not get the system record by given keys.", ex.code || "LOAD_SYSTEM_ERROR", {
|
|
72
58
|
keys
|
|
73
59
|
});
|
|
74
60
|
}
|
|
75
61
|
};
|
|
76
|
-
|
|
77
62
|
const updateSystem = async params => {
|
|
78
63
|
const {
|
|
79
64
|
system,
|
|
80
65
|
original
|
|
81
66
|
} = params;
|
|
82
67
|
const keys = createKeys(system);
|
|
83
|
-
|
|
84
68
|
try {
|
|
85
|
-
await
|
|
69
|
+
await (0, _dbDynamodb.put)({
|
|
70
|
+
entity,
|
|
71
|
+
item: {
|
|
72
|
+
...system,
|
|
73
|
+
...keys
|
|
74
|
+
}
|
|
75
|
+
});
|
|
86
76
|
return system;
|
|
87
77
|
} catch (ex) {
|
|
88
78
|
throw new _error.default(ex.message || "Could not update the system record by given keys.", ex.code || "UPDATE_SYSTEM_ERROR", {
|
|
@@ -92,7 +82,6 @@ const createSystemStorageOperations = params => {
|
|
|
92
82
|
});
|
|
93
83
|
}
|
|
94
84
|
};
|
|
95
|
-
|
|
96
85
|
return {
|
|
97
86
|
createSystem,
|
|
98
87
|
getSystem,
|
|
@@ -101,5 +90,6 @@ const createSystemStorageOperations = params => {
|
|
|
101
90
|
createSystemSortKey
|
|
102
91
|
};
|
|
103
92
|
};
|
|
93
|
+
exports.createSystemStorageOperations = createSystemStorageOperations;
|
|
104
94
|
|
|
105
|
-
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_error","_interopRequireDefault","require","_dbDynamodb","createSystemStorageOperations","params","entity","createSystemPartitionKey","tenant","createSystemSortKey","createKeys","PK","SK","createSystem","system","keys","put","item","ex","WebinyError","message","code","getSystem","getClean","updateSystem","original","exports"],"sources":["index.ts"],"sourcesContent":["import type {\n FormBuilderStorageOperationsCreateSystemParams,\n FormBuilderStorageOperationsGetSystemParams,\n FormBuilderStorageOperationsUpdateSystemParams,\n System\n} from \"@webiny/api-form-builder/types\";\nimport type { Entity, Table } from \"@webiny/db-dynamodb/toolbox\";\nimport type {\n FormBuilderSystemCreateKeysParams,\n FormBuilderSystemStorageOperations\n} from \"~/types\";\nimport WebinyError from \"@webiny/error\";\nimport { getClean, put } from \"@webiny/db-dynamodb\";\n\nexport interface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n table: Table<string, string, string>;\n}\n\nexport const createSystemStorageOperations = (\n params: CreateSystemStorageOperationsParams\n): FormBuilderSystemStorageOperations => {\n const { entity } = params;\n\n const createSystemPartitionKey = ({ tenant }: FormBuilderSystemCreateKeysParams): string => {\n return `T#${tenant}#SYSTEM`;\n };\n\n const createSystemSortKey = (): string => {\n return \"FB\";\n };\n\n const createKeys = (params: FormBuilderSystemCreateKeysParams) => {\n return {\n PK: createSystemPartitionKey(params),\n SK: createSystemSortKey()\n };\n };\n\n const createSystem = async (\n params: FormBuilderStorageOperationsCreateSystemParams\n ): Promise<System> => {\n const { system } = params;\n const keys = createKeys(system);\n\n try {\n await put({\n entity,\n item: {\n ...system,\n ...keys\n }\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create the system record by given keys.\",\n ex.code || \"CREATE_SYSTEM_ERROR\",\n {\n keys,\n system\n }\n );\n }\n };\n\n const getSystem = async (\n params: FormBuilderStorageOperationsGetSystemParams\n ): Promise<System | null> => {\n const keys = createKeys(params);\n\n try {\n return await getClean<System>({\n entity,\n keys\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not get the system record by given keys.\",\n ex.code || \"LOAD_SYSTEM_ERROR\",\n {\n keys\n }\n );\n }\n };\n\n const updateSystem = async (\n params: FormBuilderStorageOperationsUpdateSystemParams\n ): Promise<System> => {\n const { system, original } = params;\n const keys = createKeys(system);\n\n try {\n await put({\n entity,\n item: {\n ...system,\n ...keys\n }\n });\n return system;\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not update the system record by given keys.\",\n ex.code || \"UPDATE_SYSTEM_ERROR\",\n {\n keys,\n original,\n system\n }\n );\n }\n };\n\n return {\n createSystem,\n getSystem,\n updateSystem,\n createSystemPartitionKey,\n createSystemSortKey\n };\n};\n"],"mappings":";;;;;;;AAWA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAOO,MAAME,6BAA6B,GACtCC,MAA2C,IACN;EACrC,MAAM;IAAEC;EAAO,CAAC,GAAGD,MAAM;EAEzB,MAAME,wBAAwB,GAAGA,CAAC;IAAEC;EAA0C,CAAC,KAAa;IACxF,OAAO,KAAKA,MAAM,SAAS;EAC/B,CAAC;EAED,MAAMC,mBAAmB,GAAGA,CAAA,KAAc;IACtC,OAAO,IAAI;EACf,CAAC;EAED,MAAMC,UAAU,GAAIL,MAAyC,IAAK;IAC9D,OAAO;MAC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,CAAC,CAAC;MACF,OAAOD,MAAM;IACjB,CAAC,CAAC,OAAOI,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,mDAAmD,EACjEF,EAAE,CAACG,IAAI,IAAI,qBAAqB,EAChC;QACIN,IAAI;QACJU,QAAQ;QACRX;MACJ,CACJ,CAAC;IACL;EACJ,CAAC;EAED,OAAO;IACHD,YAAY;IACZS,SAAS;IACTE,YAAY;IACZjB,wBAAwB;IACxBE;EACJ,CAAC;AACL,CAAC;AAACiB,OAAA,CAAAtB,6BAAA,GAAAA,6BAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-form-builder-so-ddb-es",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.06b2ede40f",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"@webiny/api-form-builder",
|
|
7
7
|
"storage-operations",
|
|
8
8
|
"dynamodb",
|
|
9
9
|
"elasticsearch",
|
|
10
|
-
"
|
|
10
|
+
"ddb-es",
|
|
11
|
+
"fb:ddb-es",
|
|
12
|
+
"opensearch",
|
|
13
|
+
"ddb-os",
|
|
14
|
+
"fb:ddb-os"
|
|
11
15
|
],
|
|
12
16
|
"repository": {
|
|
13
17
|
"type": "git",
|
|
@@ -21,47 +25,36 @@
|
|
|
21
25
|
],
|
|
22
26
|
"license": "MIT",
|
|
23
27
|
"dependencies": {
|
|
24
|
-
"@babel/runtime": "7.15.4",
|
|
25
28
|
"@elastic/elasticsearch": "7.12.0",
|
|
26
|
-
"@webiny/api
|
|
27
|
-
"@webiny/api-
|
|
28
|
-
"@webiny/api-
|
|
29
|
-
"@webiny/api-
|
|
30
|
-
"@webiny/
|
|
31
|
-
"@webiny/db-dynamodb": "0.0.0-
|
|
32
|
-
"@webiny/error": "0.0.0-
|
|
33
|
-
"@webiny/
|
|
34
|
-
"@webiny/
|
|
35
|
-
"
|
|
36
|
-
"@webiny/utils": "0.0.0-mt-2",
|
|
37
|
-
"dynamodb-toolbox": "0.3.4",
|
|
38
|
-
"elastic-ts": "0.7.0"
|
|
29
|
+
"@webiny/api": "0.0.0-unstable.06b2ede40f",
|
|
30
|
+
"@webiny/api-elasticsearch": "0.0.0-unstable.06b2ede40f",
|
|
31
|
+
"@webiny/api-elasticsearch-tasks": "0.0.0-unstable.06b2ede40f",
|
|
32
|
+
"@webiny/api-form-builder": "0.0.0-unstable.06b2ede40f",
|
|
33
|
+
"@webiny/aws-sdk": "0.0.0-unstable.06b2ede40f",
|
|
34
|
+
"@webiny/db-dynamodb": "0.0.0-unstable.06b2ede40f",
|
|
35
|
+
"@webiny/error": "0.0.0-unstable.06b2ede40f",
|
|
36
|
+
"@webiny/plugins": "0.0.0-unstable.06b2ede40f",
|
|
37
|
+
"@webiny/utils": "0.0.0-unstable.06b2ede40f",
|
|
38
|
+
"elastic-ts": "0.12.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
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"
|
|
41
|
+
"@webiny/api-dynamodb-to-elasticsearch": "0.0.0-unstable.06b2ede40f",
|
|
42
|
+
"@webiny/handler-aws": "0.0.0-unstable.06b2ede40f",
|
|
43
|
+
"@webiny/handler-db": "0.0.0-unstable.06b2ede40f",
|
|
44
|
+
"@webiny/project-utils": "0.0.0-unstable.06b2ede40f",
|
|
45
|
+
"csvtojson": "2.0.10",
|
|
46
|
+
"jest": "29.7.0",
|
|
47
|
+
"jest-dynalite": "3.6.1",
|
|
48
|
+
"rimraf": "6.0.1",
|
|
49
|
+
"typescript": "5.3.3"
|
|
57
50
|
},
|
|
58
51
|
"publishConfig": {
|
|
59
52
|
"access": "public",
|
|
60
53
|
"directory": "dist"
|
|
61
54
|
},
|
|
62
55
|
"scripts": {
|
|
63
|
-
"build": "
|
|
64
|
-
"watch": "
|
|
56
|
+
"build": "node ../cli/bin.js run build",
|
|
57
|
+
"watch": "node ../cli/bin.js run watch"
|
|
65
58
|
},
|
|
66
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "06b2ede40fc2212a70eeafd74afd50b56fb0ce82"
|
|
67
60
|
}
|