@webiny/api-form-builder-so-ddb-es 5.34.8 → 5.35.0-beta.0

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.
Files changed (72) hide show
  1. package/configurations.js +0 -11
  2. package/configurations.js.map +1 -1
  3. package/definitions/elasticsearch.js +0 -5
  4. package/definitions/elasticsearch.js.map +1 -1
  5. package/definitions/form.js +0 -5
  6. package/definitions/form.js.map +1 -1
  7. package/definitions/settings.js +0 -5
  8. package/definitions/settings.js.map +1 -1
  9. package/definitions/submission.js +0 -5
  10. package/definitions/submission.js.map +1 -1
  11. package/definitions/system.js +0 -5
  12. package/definitions/system.js.map +1 -1
  13. package/definitions/table.js +0 -3
  14. package/definitions/table.js.map +1 -1
  15. package/definitions/tableElasticsearch.js +0 -3
  16. package/definitions/tableElasticsearch.js.map +1 -1
  17. package/elasticsearch/createElasticsearchIndex.js +0 -11
  18. package/elasticsearch/createElasticsearchIndex.js.map +1 -1
  19. package/elasticsearch/indices/base.js +0 -3
  20. package/elasticsearch/indices/base.js.map +1 -1
  21. package/elasticsearch/indices/index.d.ts +1 -1
  22. package/elasticsearch/indices/index.js +0 -4
  23. package/elasticsearch/indices/index.js.map +1 -1
  24. package/elasticsearch/indices/japanese.js +0 -3
  25. package/elasticsearch/indices/japanese.js.map +1 -1
  26. package/index.d.ts +1 -0
  27. package/index.js +25 -35
  28. package/index.js.map +1 -1
  29. package/operations/form/elasticsearchBody.js +0 -27
  30. package/operations/form/elasticsearchBody.js.map +1 -1
  31. package/operations/form/elasticsearchFields.js +0 -3
  32. package/operations/form/elasticsearchFields.js.map +1 -1
  33. package/operations/form/fields.js +0 -3
  34. package/operations/form/fields.js.map +1 -1
  35. package/operations/form/index.js +2 -103
  36. package/operations/form/index.js.map +1 -1
  37. package/operations/settings/index.js +0 -20
  38. package/operations/settings/index.js.map +1 -1
  39. package/operations/submission/elasticsearchBody.js +0 -29
  40. package/operations/submission/elasticsearchBody.js.map +1 -1
  41. package/operations/submission/elasticsearchFields.js +0 -3
  42. package/operations/submission/elasticsearchFields.js.map +1 -1
  43. package/operations/submission/index.js +1 -49
  44. package/operations/submission/index.js.map +1 -1
  45. package/operations/system/index.js +0 -18
  46. package/operations/system/index.js.map +1 -1
  47. package/package.json +15 -15
  48. package/plugins/FormDynamoDbFieldPlugin.js +0 -5
  49. package/plugins/FormDynamoDbFieldPlugin.js.map +1 -1
  50. package/plugins/FormElasticsearchBodyModifierPlugin.js +0 -5
  51. package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -1
  52. package/plugins/FormElasticsearchFieldPlugin.js +0 -5
  53. package/plugins/FormElasticsearchFieldPlugin.js.map +1 -1
  54. package/plugins/FormElasticsearchIndexPlugin.js +0 -5
  55. package/plugins/FormElasticsearchIndexPlugin.js.map +1 -1
  56. package/plugins/FormElasticsearchQueryModifierPlugin.js +0 -5
  57. package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -1
  58. package/plugins/FormElasticsearchSortModifierPlugin.js +0 -5
  59. package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -1
  60. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +0 -5
  61. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -1
  62. package/plugins/SubmissionElasticsearchFieldPlugin.js +0 -5
  63. package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -1
  64. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +0 -5
  65. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -1
  66. package/plugins/SubmissionElasticsearchSortModifierPlugin.js +0 -5
  67. package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -1
  68. package/plugins/index.d.ts +10 -0
  69. package/plugins/index.js +115 -0
  70. package/plugins/index.js.map +1 -0
  71. package/types.js +0 -1
  72. package/types.js.map +1 -1
@@ -1,30 +1,19 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createSubmissionStorageOperations = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _error = _interopRequireDefault(require("@webiny/error"));
13
-
14
10
  var _batchRead = require("@webiny/db-dynamodb/utils/batchRead");
15
-
16
11
  var _sort = require("@webiny/db-dynamodb/utils/sort");
17
-
18
12
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
19
-
20
13
  var _elasticsearchBody = require("./elasticsearchBody");
21
-
22
14
  var _configurations = require("../../configurations");
23
-
24
15
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
25
-
26
16
  var _utils = require("@webiny/utils");
27
-
28
17
  const createSubmissionStorageOperations = params => {
29
18
  const {
30
19
  entity,
@@ -33,7 +22,6 @@ const createSubmissionStorageOperations = params => {
33
22
  elasticsearch,
34
23
  plugins
35
24
  } = params;
36
-
37
25
  const createSubmissionPartitionKey = params => {
38
26
  const {
39
27
  tenant,
@@ -45,15 +33,12 @@ const createSubmissionStorageOperations = params => {
45
33
  } = (0, _utils.parseIdentifier)(formId);
46
34
  return `T#${tenant}#L#${locale}#FB#F#${id}`;
47
35
  };
48
-
49
36
  const createSubmissionSortKey = id => {
50
37
  return `FS#${id}`;
51
38
  };
52
-
53
39
  const createSubmissionType = () => {
54
40
  return "fb.formSubmission";
55
41
  };
56
-
57
42
  const createSubmission = async params => {
58
43
  const {
59
44
  submission,
@@ -63,7 +48,6 @@ const createSubmissionStorageOperations = params => {
63
48
  PK: createSubmissionPartitionKey(form),
64
49
  SK: createSubmissionSortKey(submission.id)
65
50
  };
66
-
67
51
  try {
68
52
  await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), keys), {}, {
69
53
  TYPE: createSubmissionType()
@@ -75,7 +59,6 @@ const createSubmissionStorageOperations = params => {
75
59
  keys
76
60
  });
77
61
  }
78
-
79
62
  try {
80
63
  const {
81
64
  index
@@ -83,7 +66,6 @@ const createSubmissionStorageOperations = params => {
83
66
  tenant: form.tenant,
84
67
  locale: form.locale
85
68
  });
86
-
87
69
  await esEntity.put((0, _objectSpread2.default)({
88
70
  index,
89
71
  data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), {}, {
@@ -98,14 +80,11 @@ const createSubmissionStorageOperations = params => {
98
80
  keys
99
81
  });
100
82
  }
101
-
102
83
  return submission;
103
84
  };
104
85
  /**
105
86
  * We do not save the data in the Elasticsearch because there is no need for that.
106
87
  */
107
-
108
-
109
88
  const updateSubmission = async params => {
110
89
  const {
111
90
  submission,
@@ -116,7 +95,6 @@ const createSubmissionStorageOperations = params => {
116
95
  PK: createSubmissionPartitionKey(form),
117
96
  SK: createSubmissionSortKey(submission.id)
118
97
  };
119
-
120
98
  try {
121
99
  await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), keys), {}, {
122
100
  TYPE: createSubmissionType()
@@ -131,7 +109,6 @@ const createSubmissionStorageOperations = params => {
131
109
  });
132
110
  }
133
111
  };
134
-
135
112
  const deleteSubmission = async params => {
136
113
  const {
137
114
  submission,
@@ -141,7 +118,6 @@ const createSubmissionStorageOperations = params => {
141
118
  PK: createSubmissionPartitionKey(form),
142
119
  SK: createSubmissionSortKey(submission.id)
143
120
  };
144
-
145
121
  try {
146
122
  await entity.delete(keys);
147
123
  } catch (ex) {
@@ -151,7 +127,6 @@ const createSubmissionStorageOperations = params => {
151
127
  keys
152
128
  });
153
129
  }
154
-
155
130
  try {
156
131
  await esEntity.delete(keys);
157
132
  } catch (ex) {
@@ -161,17 +136,15 @@ const createSubmissionStorageOperations = params => {
161
136
  keys
162
137
  });
163
138
  }
164
-
165
139
  return submission;
166
140
  };
141
+
167
142
  /**
168
143
  *
169
144
  * We are using this method because it is faster to fetch the exact data from the DynamoDB than Elasticsearch.
170
145
  *
171
146
  * @internal
172
147
  */
173
-
174
-
175
148
  const listSubmissionsByIds = async params => {
176
149
  const {
177
150
  where,
@@ -184,7 +157,6 @@ const createSubmissionStorageOperations = params => {
184
157
  });
185
158
  });
186
159
  let results = [];
187
-
188
160
  try {
189
161
  results = await (0, _batchRead.batchReadAll)({
190
162
  table,
@@ -199,23 +171,18 @@ const createSubmissionStorageOperations = params => {
199
171
  /**
200
172
  * We need to remove empty results because it is a possibility that batch read returned null for non-existing record.
201
173
  */
202
-
203
-
204
174
  const submissions = results.filter(Boolean).map(submission => {
205
175
  return (0, _cleanup.cleanupItem)(entity, submission);
206
176
  });
207
-
208
177
  if (!sort) {
209
178
  return submissions;
210
179
  }
211
-
212
180
  return (0, _sort.sortItems)({
213
181
  items: submissions,
214
182
  sort,
215
183
  fields: []
216
184
  });
217
185
  };
218
-
219
186
  const listSubmissions = async params => {
220
187
  const {
221
188
  where,
@@ -223,7 +190,6 @@ const createSubmissionStorageOperations = params => {
223
190
  limit: initialLimit,
224
191
  after
225
192
  } = params;
226
-
227
193
  if (where.id_in) {
228
194
  const items = await listSubmissionsByIds(params);
229
195
  return {
@@ -235,7 +201,6 @@ const createSubmissionStorageOperations = params => {
235
201
  }
236
202
  };
237
203
  }
238
-
239
204
  const limit = (0, _apiElasticsearch.createLimit)(initialLimit);
240
205
  const body = (0, _elasticsearchBody.createElasticsearchBody)({
241
206
  plugins,
@@ -244,17 +209,14 @@ const createSubmissionStorageOperations = params => {
244
209
  where,
245
210
  after: (0, _apiElasticsearch.decodeCursor)(after)
246
211
  });
247
-
248
212
  const esConfig = _configurations.configurations.es({
249
213
  tenant: where.tenant,
250
214
  locale: where.locale
251
215
  });
252
-
253
216
  const query = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, esConfig), {}, {
254
217
  body
255
218
  });
256
219
  let response;
257
-
258
220
  try {
259
221
  response = await elasticsearch.search(query);
260
222
  } catch (ex) {
@@ -263,14 +225,12 @@ const createSubmissionStorageOperations = params => {
263
225
  query
264
226
  });
265
227
  }
266
-
267
228
  const {
268
229
  hits,
269
230
  total
270
231
  } = response.body.hits;
271
232
  const items = hits.map(item => item._source);
272
233
  const hasMoreItems = items.length > limit;
273
-
274
234
  if (hasMoreItems) {
275
235
  /**
276
236
  * Remove the last item from results, we don't want to include it.
@@ -281,8 +241,6 @@ const createSubmissionStorageOperations = params => {
281
241
  * Cursor is the `sort` value of the last item in the array.
282
242
  * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
283
243
  */
284
-
285
-
286
244
  const meta = {
287
245
  hasMoreItems,
288
246
  totalCount: total.value,
@@ -293,7 +251,6 @@ const createSubmissionStorageOperations = params => {
293
251
  meta
294
252
  };
295
253
  };
296
-
297
254
  const getSubmission = async params => {
298
255
  const {
299
256
  where
@@ -304,14 +261,11 @@ const createSubmissionStorageOperations = params => {
304
261
  })),
305
262
  SK: createSubmissionSortKey(where.id)
306
263
  };
307
-
308
264
  try {
309
265
  const result = await entity.get(keys);
310
-
311
266
  if (!result || !result.Item) {
312
267
  return null;
313
268
  }
314
-
315
269
  return (0, _cleanup.cleanupItem)(entity, result.Item);
316
270
  } catch (ex) {
317
271
  throw new _error.default(ex.message || "Could not oad submission.", ex.code || "GET_SUBMISSION_ERROR", {
@@ -320,7 +274,6 @@ const createSubmissionStorageOperations = params => {
320
274
  });
321
275
  }
322
276
  };
323
-
324
277
  return {
325
278
  createSubmission,
326
279
  deleteSubmission,
@@ -331,5 +284,4 @@ const createSubmissionStorageOperations = params => {
331
284
  createSubmissionSortKey
332
285
  };
333
286
  };
334
-
335
287
  exports.createSubmissionStorageOperations = createSubmissionStorageOperations;
@@ -1 +1 @@
1
- {"version":3,"names":["createSubmissionStorageOperations","params","entity","esEntity","table","elasticsearch","plugins","createSubmissionPartitionKey","tenant","locale","formId","id","parseIdentifier","createSubmissionSortKey","createSubmissionType","createSubmission","submission","form","keys","PK","SK","put","TYPE","ex","WebinyError","message","code","index","configurations","es","data","__type","createSubmissionElasticType","updateSubmission","original","deleteSubmission","delete","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","item","_source","pop","value","encodeCursor","getSubmission","result","get","Item"],"sources":["index.ts"],"sourcesContent":["import {\n FbSubmission,\n FormBuilderStorageOperationsCreateSubmissionParams,\n FormBuilderStorageOperationsDeleteSubmissionParams,\n FormBuilderStorageOperationsGetSubmissionParams,\n FormBuilderStorageOperationsListSubmissionsParams,\n FormBuilderStorageOperationsListSubmissionsResponse,\n FormBuilderStorageOperationsUpdateSubmissionParams\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport WebinyError from \"@webiny/error\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { createLimit, encodeCursor, decodeCursor } from \"@webiny/api-elasticsearch\";\nimport {\n createElasticsearchBody,\n createSubmissionElasticType\n} from \"~/operations/submission/elasticsearchBody\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\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 { ElasticsearchSearchResponse } from \"@webiny/api-elasticsearch/types\";\n\nexport interface CreateSubmissionStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n table: Table;\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 entity.put({\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\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 esEntity.put({\n index,\n data: {\n ...submission,\n __type: createSubmissionElasticType()\n },\n TYPE: createSubmissionType(),\n ...keys\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 entity.put({\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\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 entity.delete(keys);\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 esEntity.delete(keys);\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) as any\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 const result = await entity.get(keys);\n\n if (!result || !result.Item) {\n return null;\n }\n\n return cleanupItem(entity, result.Item);\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;;AACA;;AACA;;AACA;;AACA;;AASA;;AACA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YrC,MAAlB;IAEA,MAAMiB,IAAI,GAAG;MACTC,EAAE,EAAEZ,4BAA4B,6DACzB+B,KADyB;QAE5B5B,MAAM,EAAE4B,KAAK,CAAC5B;MAFc,GADvB;MAKTU,EAAE,EAAEP,uBAAuB,CAACyB,KAAK,CAAC3B,EAAP;IALlB,CAAb;;IAQA,IAAI;MACA,MAAMkE,MAAM,GAAG,MAAM3E,MAAM,CAAC4E,GAAP,CAAW5D,IAAX,CAArB;;MAEA,IAAI,CAAC2D,MAAD,IAAW,CAACA,MAAM,CAACE,IAAvB,EAA6B;QACzB,OAAO,IAAP;MACH;;MAED,OAAO,IAAA9B,oBAAA,EAAY/C,MAAZ,EAAoB2E,MAAM,CAACE,IAA3B,CAAP;IACH,CARD,CAQE,OAAOxD,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,2BADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,sBAFT,EAGF;QACIY,KADJ;QAEIpB;MAFJ,CAHE,CAAN;IAQH;EACJ,CA/BD;;EAiCA,OAAO;IACHH,gBADG;IAEHoB,gBAFG;IAGHF,gBAHG;IAIHmB,eAJG;IAKHwB,aALG;IAMHrE,4BANG;IAOHM;EAPG,CAAP;AASH,CAnUM"}
1
+ {"version":3,"names":["createSubmissionStorageOperations","params","entity","esEntity","table","elasticsearch","plugins","createSubmissionPartitionKey","tenant","locale","formId","id","parseIdentifier","createSubmissionSortKey","createSubmissionType","createSubmission","submission","form","keys","PK","SK","put","TYPE","ex","WebinyError","message","code","index","configurations","es","data","__type","createSubmissionElasticType","updateSubmission","original","deleteSubmission","delete","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","item","_source","pop","value","encodeCursor","getSubmission","result","get","Item"],"sources":["index.ts"],"sourcesContent":["import {\n FbSubmission,\n FormBuilderStorageOperationsCreateSubmissionParams,\n FormBuilderStorageOperationsDeleteSubmissionParams,\n FormBuilderStorageOperationsGetSubmissionParams,\n FormBuilderStorageOperationsListSubmissionsParams,\n FormBuilderStorageOperationsListSubmissionsResponse,\n FormBuilderStorageOperationsUpdateSubmissionParams\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { Client } from \"@elastic/elasticsearch\";\nimport WebinyError from \"@webiny/error\";\nimport { batchReadAll } from \"@webiny/db-dynamodb/utils/batchRead\";\nimport { sortItems } from \"@webiny/db-dynamodb/utils/sort\";\nimport { createLimit, encodeCursor, decodeCursor } from \"@webiny/api-elasticsearch\";\nimport {\n createElasticsearchBody,\n createSubmissionElasticType\n} from \"~/operations/submission/elasticsearchBody\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\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 { ElasticsearchSearchResponse } from \"@webiny/api-elasticsearch/types\";\n\nexport interface CreateSubmissionStorageOperationsParams {\n entity: Entity<any>;\n esEntity: Entity<any>;\n table: Table;\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 entity.put({\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\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 esEntity.put({\n index,\n data: {\n ...submission,\n __type: createSubmissionElasticType()\n },\n TYPE: createSubmissionType(),\n ...keys\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 entity.put({\n ...submission,\n ...keys,\n TYPE: createSubmissionType()\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 entity.delete(keys);\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 esEntity.delete(keys);\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) as any\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 const result = await entity.get(keys);\n\n if (!result || !result.Item) {\n return null;\n }\n\n return cleanupItem(entity, result.Item);\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;AACA;AACA;AACA;AACA;AASA;AACA;AACA;AAWO,MAAMA,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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MAAM,IAAI,CAACA,MAAM,CAACE,IAAI,EAAE;QACzB,OAAO,IAAI;MACf;MAEA,OAAO,IAAA9B,oBAAW,EAAC/C,MAAM,EAAE2E,MAAM,CAACE,IAAI,CAAC;IAC3C,CAAC,CAAC,OAAOxD,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,2BAA2B,EACzCF,EAAE,CAACG,IAAI,IAAI,sBAAsB,EACjC;QACIY,KAAK;QACLpB;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACHH,gBAAgB;IAChBoB,gBAAgB;IAChBF,gBAAgB;IAChBmB,eAAe;IACfwB,aAAa;IACbrE,4BAA4B;IAC5BM;EACJ,CAAC;AACL,CAAC;AAAC"}
@@ -1,46 +1,36 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.createSystemStorageOperations = void 0;
9
-
10
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
-
12
9
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
11
  const createSystemStorageOperations = params => {
17
12
  const {
18
13
  entity
19
14
  } = params;
20
-
21
15
  const createSystemPartitionKey = ({
22
16
  tenant
23
17
  }) => {
24
18
  return `T#${tenant}#SYSTEM`;
25
19
  };
26
-
27
20
  const createSystemSortKey = () => {
28
21
  return "FB";
29
22
  };
30
-
31
23
  const createKeys = params => {
32
24
  return {
33
25
  PK: createSystemPartitionKey(params),
34
26
  SK: createSystemSortKey()
35
27
  };
36
28
  };
37
-
38
29
  const createSystem = async params => {
39
30
  const {
40
31
  system
41
32
  } = params;
42
33
  const keys = createKeys(system);
43
-
44
34
  try {
45
35
  await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
46
36
  return system;
@@ -51,17 +41,13 @@ const createSystemStorageOperations = params => {
51
41
  });
52
42
  }
53
43
  };
54
-
55
44
  const getSystem = async params => {
56
45
  const keys = createKeys(params);
57
-
58
46
  try {
59
47
  const result = await entity.get(keys);
60
-
61
48
  if (!result || !result.Item) {
62
49
  return null;
63
50
  }
64
-
65
51
  return (0, _cleanup.cleanupItem)(entity, result.Item);
66
52
  } catch (ex) {
67
53
  throw new _error.default(ex.message || "Could not get the system record by given keys.", ex.code || "LOAD_SYSTEM_ERROR", {
@@ -69,14 +55,12 @@ const createSystemStorageOperations = params => {
69
55
  });
70
56
  }
71
57
  };
72
-
73
58
  const updateSystem = async params => {
74
59
  const {
75
60
  system,
76
61
  original
77
62
  } = params;
78
63
  const keys = createKeys(system);
79
-
80
64
  try {
81
65
  await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
82
66
  return system;
@@ -88,7 +72,6 @@ const createSystemStorageOperations = params => {
88
72
  });
89
73
  }
90
74
  };
91
-
92
75
  return {
93
76
  createSystem,
94
77
  getSystem,
@@ -97,5 +80,4 @@ const createSystemStorageOperations = params => {
97
80
  createSystemSortKey
98
81
  };
99
82
  };
100
-
101
83
  exports.createSystemStorageOperations = createSystemStorageOperations;
@@ -1 +1 @@
1
- {"version":3,"names":["createSystemStorageOperations","params","entity","createSystemPartitionKey","tenant","createSystemSortKey","createKeys","PK","SK","createSystem","system","keys","put","ex","WebinyError","message","code","getSystem","result","get","Item","cleanupItem","updateSystem","original"],"sources":["index.ts"],"sourcesContent":["import {\n FormBuilderStorageOperationsCreateSystemParams,\n FormBuilderStorageOperationsGetSystemParams,\n FormBuilderStorageOperationsUpdateSystemParams,\n System\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { FormBuilderSystemCreateKeysParams, FormBuilderSystemStorageOperations } from \"~/types\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport WebinyError from \"@webiny/error\";\n\nexport interface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\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 entity.put({\n ...system,\n ...keys\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 const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\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 entity.put({\n ...system,\n ...keys\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":";;;;;;;;;;;AAQA;;AACA;;AAOO,MAAMA,6BA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E,OAAH,IAAc,gDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,mBAFT,EAGF;QACIL;MADJ,CAHE,CAAN;IAOH;EACJ,CApBD;;EAsBA,MAAMW,YAAY,GAAG,MACjBrB,MADiB,IAEC;IAClB,MAAM;MAAES,MAAF;MAAUa;IAAV,IAAuBtB,MAA7B;IACA,MAAMU,IAAI,GAAGL,UAAU,CAACI,MAAD,CAAvB;;IAEA,IAAI;MACA,MAAMR,MAAM,CAACU,GAAP,6DACCF,MADD,GAECC,IAFD,EAAN;MAIA,OAAOD,MAAP;IACH,CAND,CAME,OAAOG,EAAP,EAAW;MACT,MAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,mDADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,qBAFT,EAGF;QACIL,IADJ;QAEIY,QAFJ;QAGIb;MAHJ,CAHE,CAAN;IASH;EACJ,CAvBD;;EAyBA,OAAO;IACHD,YADG;IAEHQ,SAFG;IAGHK,YAHG;IAIHnB,wBAJG;IAKHE;EALG,CAAP;AAOH,CAlGM"}
1
+ {"version":3,"names":["createSystemStorageOperations","params","entity","createSystemPartitionKey","tenant","createSystemSortKey","createKeys","PK","SK","createSystem","system","keys","put","ex","WebinyError","message","code","getSystem","result","get","Item","cleanupItem","updateSystem","original"],"sources":["index.ts"],"sourcesContent":["import {\n FormBuilderStorageOperationsCreateSystemParams,\n FormBuilderStorageOperationsGetSystemParams,\n FormBuilderStorageOperationsUpdateSystemParams,\n System\n} from \"@webiny/api-form-builder/types\";\nimport { Entity, Table } from \"dynamodb-toolbox\";\nimport { FormBuilderSystemCreateKeysParams, FormBuilderSystemStorageOperations } from \"~/types\";\nimport { cleanupItem } from \"@webiny/db-dynamodb/utils/cleanup\";\nimport WebinyError from \"@webiny/error\";\n\nexport interface CreateSystemStorageOperationsParams {\n entity: Entity<any>;\n table: Table;\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 entity.put({\n ...system,\n ...keys\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 const result = await entity.get(keys);\n if (!result || !result.Item) {\n return null;\n }\n return cleanupItem(entity, result.Item);\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 entity.put({\n ...system,\n ...keys\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":";;;;;;;;AAQA;AACA;AAOO,MAAMA,6BAA6B,GACtCC,MAA2C,IACN;EACrC,MAAM;IAAEC;EAAO,CAAC,GAAGD,MAAM;EAEzB,MAAME,wBAAwB,GAAG,CAAC;IAAEC;EAA0C,CAAC,KAAa;IACxF,OAAQ,KAA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AAsD,IACpC;IAClB,MAAM;MAAES,MAAM;MAAEa;IAAS,CAAC,GAAGtB,MAAM;IACnC,MAAMU,IAAI,GAAGL,UAAU,CAACI,MAAM,CAAC;IAE/B,IAAI;MACA,MAAMR,MAAM,CAACU,GAAG,6DACTF,MAAM,GACNC,IAAI,EACT;MACF,OAAOD,MAAM;IACjB,CAAC,CAAC,OAAOG,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,mDAAmD,EACjEF,EAAE,CAACG,IAAI,IAAI,qBAAqB,EAChC;QACIL,IAAI;QACJY,QAAQ;QACRb;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,OAAO;IACHD,YAAY;IACZQ,SAAS;IACTK,YAAY;IACZnB,wBAAwB;IACxBE;EACJ,CAAC;AACL,CAAC;AAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-form-builder-so-ddb-es",
3
- "version": "5.34.8",
3
+ "version": "5.35.0-beta.0",
4
4
  "main": "index.js",
5
5
  "keywords": [
6
6
  "@webiny/api-form-builder",
@@ -21,15 +21,15 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@babel/runtime": "7.19.0",
24
+ "@babel/runtime": "7.20.13",
25
25
  "@elastic/elasticsearch": "7.12.0",
26
- "@webiny/api": "5.34.8",
27
- "@webiny/api-elasticsearch": "5.34.8",
28
- "@webiny/api-form-builder": "5.34.8",
29
- "@webiny/db-dynamodb": "5.34.8",
30
- "@webiny/error": "5.34.8",
31
- "@webiny/plugins": "5.34.8",
32
- "@webiny/utils": "5.34.8",
26
+ "@webiny/api": "5.35.0-beta.0",
27
+ "@webiny/api-elasticsearch": "5.35.0-beta.0",
28
+ "@webiny/api-form-builder": "5.35.0-beta.0",
29
+ "@webiny/db-dynamodb": "5.35.0-beta.0",
30
+ "@webiny/error": "5.35.0-beta.0",
31
+ "@webiny/plugins": "5.35.0-beta.0",
32
+ "@webiny/utils": "5.35.0-beta.0",
33
33
  "dynamodb-toolbox": "0.3.5",
34
34
  "elastic-ts": "0.8.0"
35
35
  },
@@ -38,11 +38,11 @@
38
38
  "@babel/core": "^7.19.3",
39
39
  "@babel/preset-env": "^7.19.4",
40
40
  "@babel/preset-typescript": "^7.18.6",
41
- "@webiny/api-dynamodb-to-elasticsearch": "^5.34.8",
42
- "@webiny/cli": "^5.34.8",
43
- "@webiny/handler-aws": "^5.34.8",
44
- "@webiny/handler-db": "^5.34.8",
45
- "@webiny/project-utils": "^5.34.8",
41
+ "@webiny/api-dynamodb-to-elasticsearch": "^5.35.0-beta.0",
42
+ "@webiny/cli": "^5.35.0-beta.0",
43
+ "@webiny/handler-aws": "^5.35.0-beta.0",
44
+ "@webiny/handler-db": "^5.35.0-beta.0",
45
+ "@webiny/project-utils": "^5.35.0-beta.0",
46
46
  "csvtojson": "^2.0.10",
47
47
  "jest": "^28.1.0",
48
48
  "jest-dynalite": "^3.2.0",
@@ -59,5 +59,5 @@
59
59
  "build": "yarn webiny run build",
60
60
  "watch": "yarn webiny run watch"
61
61
  },
62
- "gitHead": "6e77eebaac687279fe82ea04f667b7e84214b96a"
62
+ "gitHead": "8acc9e8892842cabb3980ce0b6432fde55968d5b"
63
63
  }
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.FormDynamoDbFieldPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _FieldPlugin = require("@webiny/db-dynamodb/plugins/definitions/FieldPlugin");
13
-
14
10
  class FormDynamoDbFieldPlugin extends _FieldPlugin.FieldPlugin {}
15
-
16
11
  exports.FormDynamoDbFieldPlugin = FormDynamoDbFieldPlugin;
17
12
  (0, _defineProperty2.default)(FormDynamoDbFieldPlugin, "type", "formBuilder.dynamodb.field.form");
@@ -1 +1 @@
1
- {"version":3,"names":["FormDynamoDbFieldPlugin","FieldPlugin"],"sources":["FormDynamoDbFieldPlugin.ts"],"sourcesContent":["import { FieldPlugin } from \"@webiny/db-dynamodb/plugins/definitions/FieldPlugin\";\n\nexport class FormDynamoDbFieldPlugin extends FieldPlugin {\n public static override readonly type: string = \"formBuilder.dynamodb.field.form\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,uBAAN,SAAsCC,wBAAtC,CAAkD;;;8BAA5CD,uB,UACsC,iC"}
1
+ {"version":3,"names":["FormDynamoDbFieldPlugin","FieldPlugin"],"sources":["FormDynamoDbFieldPlugin.ts"],"sourcesContent":["import { FieldPlugin } from \"@webiny/db-dynamodb/plugins/definitions/FieldPlugin\";\n\nexport class FormDynamoDbFieldPlugin extends FieldPlugin {\n public static override readonly type: string = \"formBuilder.dynamodb.field.form\";\n}\n"],"mappings":";;;;;;;;AAAA;AAEO,MAAMA,uBAAuB,SAASC,wBAAW,CAAC;AAExD;AAAA,8BAFYD,uBAAuB,UACe,iCAAiC"}
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.FormElasticsearchBodyModifierPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
13
-
14
10
  class FormElasticsearchBodyModifierPlugin extends _apiElasticsearch.ElasticsearchBodyModifierPlugin {}
15
-
16
11
  exports.FormElasticsearchBodyModifierPlugin = FormElasticsearchBodyModifierPlugin;
17
12
  (0, _defineProperty2.default)(FormElasticsearchBodyModifierPlugin, "type", "formBuilder.elasticsearch.modifier.body.form");
@@ -1 +1 @@
1
- {"version":3,"names":["FormElasticsearchBodyModifierPlugin","ElasticsearchBodyModifierPlugin"],"sources":["FormElasticsearchBodyModifierPlugin.ts"],"sourcesContent":["import { ElasticsearchBodyModifierPlugin } from \"@webiny/api-elasticsearch\";\n\nexport class FormElasticsearchBodyModifierPlugin extends ElasticsearchBodyModifierPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.modifier.body.form\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,mCAAN,SAAkDC,iDAAlD,CAAkF;;;8BAA5ED,mC,UACsC,8C"}
1
+ {"version":3,"names":["FormElasticsearchBodyModifierPlugin","ElasticsearchBodyModifierPlugin"],"sources":["FormElasticsearchBodyModifierPlugin.ts"],"sourcesContent":["import { ElasticsearchBodyModifierPlugin } from \"@webiny/api-elasticsearch\";\n\nexport class FormElasticsearchBodyModifierPlugin extends ElasticsearchBodyModifierPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.modifier.body.form\";\n}\n"],"mappings":";;;;;;;;AAAA;AAEO,MAAMA,mCAAmC,SAASC,iDAA+B,CAAC;AAExF;AAAA,8BAFYD,mCAAmC,UACG,8CAA8C"}
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.FormElasticsearchFieldPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
13
-
14
10
  class FormElasticsearchFieldPlugin extends _apiElasticsearch.ElasticsearchFieldPlugin {}
15
-
16
11
  exports.FormElasticsearchFieldPlugin = FormElasticsearchFieldPlugin;
17
12
  (0, _defineProperty2.default)(FormElasticsearchFieldPlugin, "type", "formBuilder.elasticsearch.fieldDefinition.form");
@@ -1 +1 @@
1
- {"version":3,"names":["FormElasticsearchFieldPlugin","ElasticsearchFieldPlugin"],"sources":["FormElasticsearchFieldPlugin.ts"],"sourcesContent":["import { ElasticsearchFieldPlugin } from \"@webiny/api-elasticsearch\";\n\nexport class FormElasticsearchFieldPlugin extends ElasticsearchFieldPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.fieldDefinition.form\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,4BAAN,SAA2CC,0CAA3C,CAAoE;;;8BAA9DD,4B,UACsC,gD"}
1
+ {"version":3,"names":["FormElasticsearchFieldPlugin","ElasticsearchFieldPlugin"],"sources":["FormElasticsearchFieldPlugin.ts"],"sourcesContent":["import { ElasticsearchFieldPlugin } from \"@webiny/api-elasticsearch\";\n\nexport class FormElasticsearchFieldPlugin extends ElasticsearchFieldPlugin {\n public static override readonly type: string = \"formBuilder.elasticsearch.fieldDefinition.form\";\n}\n"],"mappings":";;;;;;;;AAAA;AAEO,MAAMA,4BAA4B,SAASC,0CAAwB,CAAC;AAE1E;AAAA,8BAFYD,4BAA4B,UACU,gDAAgD"}
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.FormElasticsearchIndexPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
9
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
13
-
14
10
  class FormElasticsearchIndexPlugin extends _apiElasticsearch.ElasticsearchIndexPlugin {}
15
-
16
11
  exports.FormElasticsearchIndexPlugin = FormElasticsearchIndexPlugin;
17
12
  (0, _defineProperty2.default)(FormElasticsearchIndexPlugin, "type", "formBuilder.form.elasticsearch.index");
@@ -1 +1 @@
1
- {"version":3,"names":["FormElasticsearchIndexPlugin","ElasticsearchIndexPlugin"],"sources":["FormElasticsearchIndexPlugin.ts"],"sourcesContent":["import { ElasticsearchIndexPlugin } from \"@webiny/api-elasticsearch\";\n\nexport class FormElasticsearchIndexPlugin extends ElasticsearchIndexPlugin {\n public static override readonly type: string = \"formBuilder.form.elasticsearch.index\";\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAMA,4BAAN,SAA2CC,0CAA3C,CAAoE;;;8BAA9DD,4B,UACsC,sC"}
1
+ {"version":3,"names":["FormElasticsearchIndexPlugin","ElasticsearchIndexPlugin"],"sources":["FormElasticsearchIndexPlugin.ts"],"sourcesContent":["import { ElasticsearchIndexPlugin } from \"@webiny/api-elasticsearch\";\n\nexport class FormElasticsearchIndexPlugin extends ElasticsearchIndexPlugin {\n public static override readonly type: string = \"formBuilder.form.elasticsearch.index\";\n}\n"],"mappings":";;;;;;;;AAAA;AAEO,MAAMA,4BAA4B,SAASC,0CAAwB,CAAC;AAE1E;AAAA,8BAFYD,4BAA4B,UACU,sCAAsC"}