@webiny/api-form-builder-so-ddb-es 0.0.0-mt-2 → 0.0.0-unstable.085ff6572f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/configurations.d.ts +7 -5
  2. package/configurations.js +23 -12
  3. package/configurations.js.map +1 -0
  4. package/definitions/elasticsearch.d.ts +2 -1
  5. package/definitions/elasticsearch.js +3 -12
  6. package/definitions/elasticsearch.js.map +1 -0
  7. package/definitions/form.d.ts +2 -1
  8. package/definitions/form.js +3 -12
  9. package/definitions/form.js.map +1 -0
  10. package/definitions/settings.d.ts +2 -1
  11. package/definitions/settings.js +3 -12
  12. package/definitions/settings.js.map +1 -0
  13. package/definitions/submission.d.ts +2 -1
  14. package/definitions/submission.js +3 -12
  15. package/definitions/submission.js.map +1 -0
  16. package/definitions/system.d.ts +2 -1
  17. package/definitions/system.js +3 -12
  18. package/definitions/system.js.map +1 -0
  19. package/definitions/table.d.ts +3 -2
  20. package/definitions/table.js +0 -3
  21. package/definitions/table.js.map +1 -0
  22. package/definitions/tableElasticsearch.d.ts +2 -1
  23. package/definitions/tableElasticsearch.js +0 -3
  24. package/definitions/tableElasticsearch.js.map +1 -0
  25. package/elasticsearch/createElasticsearchIndex.d.ts +10 -0
  26. package/elasticsearch/createElasticsearchIndex.js +52 -0
  27. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  28. package/elasticsearch/indices/base.d.ts +2 -0
  29. package/elasticsearch/indices/base.js +12 -0
  30. package/elasticsearch/indices/base.js.map +1 -0
  31. package/elasticsearch/indices/index.d.ts +1 -0
  32. package/elasticsearch/indices/index.js +12 -0
  33. package/elasticsearch/indices/index.js.map +1 -0
  34. package/elasticsearch/indices/japanese.d.ts +2 -0
  35. package/elasticsearch/indices/japanese.js +13 -0
  36. package/elasticsearch/indices/japanese.js.map +1 -0
  37. package/index.d.ts +1 -0
  38. package/index.js +54 -61
  39. package/index.js.map +1 -0
  40. package/operations/form/elasticsearchBody.js +12 -56
  41. package/operations/form/elasticsearchBody.js.map +1 -0
  42. package/operations/form/elasticsearchFields.js +0 -3
  43. package/operations/form/elasticsearchFields.js.map +1 -0
  44. package/operations/form/fields.js +0 -3
  45. package/operations/form/fields.js.map +1 -0
  46. package/operations/form/index.d.ts +2 -2
  47. package/operations/form/index.js +53 -153
  48. package/operations/form/index.js.map +1 -0
  49. package/operations/settings/index.d.ts +2 -2
  50. package/operations/settings/index.js +5 -29
  51. package/operations/settings/index.js.map +1 -0
  52. package/operations/submission/elasticsearchBody.js +15 -54
  53. package/operations/submission/elasticsearchBody.js.map +1 -0
  54. package/operations/submission/elasticsearchFields.js +0 -3
  55. package/operations/submission/elasticsearchFields.js.map +1 -0
  56. package/operations/submission/index.d.ts +2 -2
  57. package/operations/submission/index.js +23 -76
  58. package/operations/submission/index.js.map +1 -0
  59. package/operations/system/index.d.ts +2 -2
  60. package/operations/system/index.js +4 -26
  61. package/operations/system/index.js.map +1 -0
  62. package/package.json +27 -32
  63. package/plugins/FormDynamoDbFieldPlugin.js +1 -6
  64. package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
  65. package/plugins/FormElasticsearchBodyModifierPlugin.d.ts +1 -1
  66. package/plugins/FormElasticsearchBodyModifierPlugin.js +3 -8
  67. package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -0
  68. package/plugins/FormElasticsearchFieldPlugin.d.ts +1 -1
  69. package/plugins/FormElasticsearchFieldPlugin.js +3 -8
  70. package/plugins/FormElasticsearchFieldPlugin.js.map +1 -0
  71. package/plugins/FormElasticsearchIndexPlugin.d.ts +4 -0
  72. package/plugins/FormElasticsearchIndexPlugin.js +12 -0
  73. package/plugins/FormElasticsearchIndexPlugin.js.map +1 -0
  74. package/plugins/FormElasticsearchQueryModifierPlugin.d.ts +1 -1
  75. package/plugins/FormElasticsearchQueryModifierPlugin.js +3 -8
  76. package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -0
  77. package/plugins/FormElasticsearchSortModifierPlugin.d.ts +1 -1
  78. package/plugins/FormElasticsearchSortModifierPlugin.js +3 -8
  79. package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -0
  80. package/plugins/SubmissionElasticsearchBodyModifierPlugin.d.ts +1 -1
  81. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +3 -8
  82. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -0
  83. package/plugins/SubmissionElasticsearchFieldPlugin.d.ts +1 -1
  84. package/plugins/SubmissionElasticsearchFieldPlugin.js +3 -8
  85. package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -0
  86. package/plugins/SubmissionElasticsearchQueryModifierPlugin.d.ts +1 -1
  87. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +3 -8
  88. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -0
  89. package/plugins/SubmissionElasticsearchSortModifierPlugin.d.ts +1 -1
  90. package/plugins/SubmissionElasticsearchSortModifierPlugin.js +3 -8
  91. package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -0
  92. package/plugins/index.d.ts +10 -0
  93. package/plugins/index.js +115 -0
  94. package/plugins/index.js.map +1 -0
  95. package/types.d.ts +2 -2
  96. package/types.js +0 -1
  97. package/types.js.map +1 -0
  98. package/operations/system/createElasticsearchIndex.d.ts +0 -6
  99. package/operations/system/createElasticsearchIndex.js +0 -70
  100. package/upgrades/5.16.0/index.d.ts +0 -8
  101. package/upgrades/5.16.0/index.js +0 -141
@@ -1,36 +1,19 @@
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
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
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
- var _limit = require("@webiny/api-elasticsearch/limit");
19
-
12
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
20
13
  var _elasticsearchBody = require("./elasticsearchBody");
21
-
22
- var _configurations = _interopRequireDefault(require("../../configurations"));
23
-
14
+ var _configurations = require("../../configurations");
24
15
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
25
-
26
16
  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
17
  const createSubmissionStorageOperations = params => {
35
18
  const {
36
19
  entity,
@@ -39,7 +22,6 @@ const createSubmissionStorageOperations = params => {
39
22
  elasticsearch,
40
23
  plugins
41
24
  } = params;
42
-
43
25
  const createSubmissionPartitionKey = params => {
44
26
  const {
45
27
  tenant,
@@ -51,15 +33,12 @@ const createSubmissionStorageOperations = params => {
51
33
  } = (0, _utils.parseIdentifier)(formId);
52
34
  return `T#${tenant}#L#${locale}#FB#F#${id}`;
53
35
  };
54
-
55
36
  const createSubmissionSortKey = id => {
56
37
  return `FS#${id}`;
57
38
  };
58
-
59
39
  const createSubmissionType = () => {
60
40
  return "fb.formSubmission";
61
41
  };
62
-
63
42
  const createSubmission = async params => {
64
43
  const {
65
44
  submission,
@@ -69,9 +48,8 @@ const createSubmissionStorageOperations = params => {
69
48
  PK: createSubmissionPartitionKey(form),
70
49
  SK: createSubmissionSortKey(submission.id)
71
50
  };
72
-
73
51
  try {
74
- await entity.put(_objectSpread(_objectSpread(_objectSpread({}, submission), keys), {}, {
52
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), keys), {}, {
75
53
  TYPE: createSubmissionType()
76
54
  }));
77
55
  } catch (ex) {
@@ -81,17 +59,16 @@ const createSubmissionStorageOperations = params => {
81
59
  keys
82
60
  });
83
61
  }
84
-
85
62
  try {
86
63
  const {
87
64
  index
88
- } = _configurations.default.es({
89
- tenant: form.tenant
65
+ } = _configurations.configurations.es({
66
+ tenant: form.tenant,
67
+ locale: form.locale
90
68
  });
91
-
92
- await esEntity.put(_objectSpread({
69
+ await esEntity.put((0, _objectSpread2.default)({
93
70
  index,
94
- data: _objectSpread(_objectSpread({}, submission), {}, {
71
+ data: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), {}, {
95
72
  __type: (0, _elasticsearchBody.createSubmissionElasticType)()
96
73
  }),
97
74
  TYPE: createSubmissionType()
@@ -103,14 +80,11 @@ const createSubmissionStorageOperations = params => {
103
80
  keys
104
81
  });
105
82
  }
106
-
107
83
  return submission;
108
84
  };
109
85
  /**
110
86
  * We do not save the data in the Elasticsearch because there is no need for that.
111
87
  */
112
-
113
-
114
88
  const updateSubmission = async params => {
115
89
  const {
116
90
  submission,
@@ -121,9 +95,8 @@ const createSubmissionStorageOperations = params => {
121
95
  PK: createSubmissionPartitionKey(form),
122
96
  SK: createSubmissionSortKey(submission.id)
123
97
  };
124
-
125
98
  try {
126
- await entity.put(_objectSpread(_objectSpread(_objectSpread({}, submission), keys), {}, {
99
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, submission), keys), {}, {
127
100
  TYPE: createSubmissionType()
128
101
  }));
129
102
  return submission;
@@ -136,7 +109,6 @@ const createSubmissionStorageOperations = params => {
136
109
  });
137
110
  }
138
111
  };
139
-
140
112
  const deleteSubmission = async params => {
141
113
  const {
142
114
  submission,
@@ -146,7 +118,6 @@ const createSubmissionStorageOperations = params => {
146
118
  PK: createSubmissionPartitionKey(form),
147
119
  SK: createSubmissionSortKey(submission.id)
148
120
  };
149
-
150
121
  try {
151
122
  await entity.delete(keys);
152
123
  } catch (ex) {
@@ -156,7 +127,6 @@ const createSubmissionStorageOperations = params => {
156
127
  keys
157
128
  });
158
129
  }
159
-
160
130
  try {
161
131
  await esEntity.delete(keys);
162
132
  } catch (ex) {
@@ -166,30 +136,27 @@ const createSubmissionStorageOperations = params => {
166
136
  keys
167
137
  });
168
138
  }
169
-
170
139
  return submission;
171
140
  };
141
+
172
142
  /**
173
143
  *
174
144
  * We are using this method because it is faster to fetch the exact data from the DynamoDB than Elasticsearch.
175
145
  *
176
146
  * @internal
177
147
  */
178
-
179
-
180
148
  const listSubmissionsByIds = async params => {
181
149
  const {
182
150
  where,
183
151
  sort
184
152
  } = params;
185
- const items = where.id_in.map(id => {
153
+ const items = (where.id_in || []).map(id => {
186
154
  return entity.getBatch({
187
- PK: createSubmissionPartitionKey(_objectSpread({}, where)),
155
+ PK: createSubmissionPartitionKey((0, _objectSpread2.default)({}, where)),
188
156
  SK: createSubmissionSortKey(id)
189
157
  });
190
158
  });
191
159
  let results = [];
192
-
193
160
  try {
194
161
  results = await (0, _batchRead.batchReadAll)({
195
162
  table,
@@ -204,31 +171,25 @@ const createSubmissionStorageOperations = params => {
204
171
  /**
205
172
  * We need to remove empty results because it is a possibility that batch read returned null for non-existing record.
206
173
  */
207
-
208
-
209
174
  const submissions = results.filter(Boolean).map(submission => {
210
175
  return (0, _cleanup.cleanupItem)(entity, submission);
211
176
  });
212
-
213
177
  if (!sort) {
214
178
  return submissions;
215
179
  }
216
-
217
180
  return (0, _sort.sortItems)({
218
181
  items: submissions,
219
182
  sort,
220
183
  fields: []
221
184
  });
222
185
  };
223
-
224
186
  const listSubmissions = async params => {
225
187
  const {
226
188
  where,
227
- sort,
189
+ sort = [],
228
190
  limit: initialLimit,
229
191
  after
230
192
  } = params;
231
-
232
193
  if (where.id_in) {
233
194
  const items = await listSubmissionsByIds(params);
234
195
  return {
@@ -240,26 +201,22 @@ const createSubmissionStorageOperations = params => {
240
201
  }
241
202
  };
242
203
  }
243
-
244
- const limit = (0, _limit.createLimit)(initialLimit);
204
+ const limit = (0, _apiElasticsearch.createLimit)(initialLimit);
245
205
  const body = (0, _elasticsearchBody.createElasticsearchBody)({
246
206
  plugins,
247
207
  sort,
248
208
  limit: limit + 1,
249
209
  where,
250
- after: (0, _cursors.decodeCursor)(after)
210
+ after: (0, _apiElasticsearch.decodeCursor)(after)
251
211
  });
252
-
253
- const esConfig = _configurations.default.es({
254
- tenant: where.tenant
212
+ const esConfig = _configurations.configurations.es({
213
+ tenant: where.tenant,
214
+ locale: where.locale
255
215
  });
256
-
257
- const query = _objectSpread(_objectSpread({}, esConfig), {}, {
216
+ const query = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, esConfig), {}, {
258
217
  body
259
218
  });
260
-
261
219
  let response;
262
-
263
220
  try {
264
221
  response = await elasticsearch.search(query);
265
222
  } catch (ex) {
@@ -268,14 +225,12 @@ const createSubmissionStorageOperations = params => {
268
225
  query
269
226
  });
270
227
  }
271
-
272
228
  const {
273
229
  hits,
274
230
  total
275
231
  } = response.body.hits;
276
232
  const items = hits.map(item => item._source);
277
233
  const hasMoreItems = items.length > limit;
278
-
279
234
  if (hasMoreItems) {
280
235
  /**
281
236
  * Remove the last item from results, we don't want to include it.
@@ -286,37 +241,31 @@ const createSubmissionStorageOperations = params => {
286
241
  * Cursor is the `sort` value of the last item in the array.
287
242
  * https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html#search-after
288
243
  */
289
-
290
-
291
244
  const meta = {
292
245
  hasMoreItems,
293
246
  totalCount: total.value,
294
- cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) : null
247
+ cursor: items.length > 0 ? (0, _apiElasticsearch.encodeCursor)(hits[items.length - 1].sort) || null : null
295
248
  };
296
249
  return {
297
250
  items,
298
251
  meta
299
252
  };
300
253
  };
301
-
302
254
  const getSubmission = async params => {
303
255
  const {
304
256
  where
305
257
  } = params;
306
258
  const keys = {
307
- PK: createSubmissionPartitionKey(_objectSpread(_objectSpread({}, where), {}, {
259
+ PK: createSubmissionPartitionKey((0, _objectSpread2.default)((0, _objectSpread2.default)({}, where), {}, {
308
260
  formId: where.formId
309
261
  })),
310
262
  SK: createSubmissionSortKey(where.id)
311
263
  };
312
-
313
264
  try {
314
265
  const result = await entity.get(keys);
315
-
316
266
  if (!result || !result.Item) {
317
267
  return null;
318
268
  }
319
-
320
269
  return (0, _cleanup.cleanupItem)(entity, result.Item);
321
270
  } catch (ex) {
322
271
  throw new _error.default(ex.message || "Could not oad submission.", ex.code || "GET_SUBMISSION_ERROR", {
@@ -325,7 +274,6 @@ const createSubmissionStorageOperations = params => {
325
274
  });
326
275
  }
327
276
  };
328
-
329
277
  return {
330
278
  createSubmission,
331
279
  deleteSubmission,
@@ -336,5 +284,4 @@ const createSubmissionStorageOperations = params => {
336
284
  createSubmissionSortKey
337
285
  };
338
286
  };
339
-
340
287
  exports.createSubmissionStorageOperations = createSubmissionStorageOperations;
@@ -0,0 +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;A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,KAAK;QACR5B,MAAM,EAAE4B,KAAK,CAAC5B;MAAgB,GAChC;MACFU,EAAE,EAAEP,uBAAuB,CAACyB,KAAK,CAAC3B,EAAE;IACxC,CAAC;IAED,IAAI;MACA,MAAMkE,MAAM,GAAG,MAAM3E,MAAM,CAAC4E,GAAG,CAAC5D,IAAI,CAAC;MAErC,IAAI,CAAC2D,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,7 +1,7 @@
1
1
  import { Entity, Table } from "dynamodb-toolbox";
2
2
  import { FormBuilderSystemStorageOperations } from "../../types";
3
- export interface Params {
3
+ export interface CreateSystemStorageOperationsParams {
4
4
  entity: Entity<any>;
5
5
  table: Table;
6
6
  }
7
- export declare const createSystemStorageOperations: (params: Params) => FormBuilderSystemStorageOperations;
7
+ export declare const createSystemStorageOperations: (params: CreateSystemStorageOperationsParams) => FormBuilderSystemStorageOperations;
@@ -1,52 +1,38 @@
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
-
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
12
9
  var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
13
-
14
10
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
-
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
-
20
11
  const createSystemStorageOperations = params => {
21
12
  const {
22
13
  entity
23
14
  } = params;
24
-
25
15
  const createSystemPartitionKey = ({
26
16
  tenant
27
17
  }) => {
28
18
  return `T#${tenant}#SYSTEM`;
29
19
  };
30
-
31
20
  const createSystemSortKey = () => {
32
21
  return "FB";
33
22
  };
34
-
35
23
  const createKeys = params => {
36
24
  return {
37
25
  PK: createSystemPartitionKey(params),
38
26
  SK: createSystemSortKey()
39
27
  };
40
28
  };
41
-
42
29
  const createSystem = async params => {
43
30
  const {
44
31
  system
45
32
  } = params;
46
33
  const keys = createKeys(system);
47
-
48
34
  try {
49
- await entity.put(_objectSpread(_objectSpread({}, system), keys));
35
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
50
36
  return system;
51
37
  } catch (ex) {
52
38
  throw new _error.default(ex.message || "Could not create the system record by given keys.", ex.code || "CREATE_SYSTEM_ERROR", {
@@ -55,17 +41,13 @@ const createSystemStorageOperations = params => {
55
41
  });
56
42
  }
57
43
  };
58
-
59
44
  const getSystem = async params => {
60
45
  const keys = createKeys(params);
61
-
62
46
  try {
63
47
  const result = await entity.get(keys);
64
-
65
48
  if (!result || !result.Item) {
66
49
  return null;
67
50
  }
68
-
69
51
  return (0, _cleanup.cleanupItem)(entity, result.Item);
70
52
  } catch (ex) {
71
53
  throw new _error.default(ex.message || "Could not get the system record by given keys.", ex.code || "LOAD_SYSTEM_ERROR", {
@@ -73,16 +55,14 @@ const createSystemStorageOperations = params => {
73
55
  });
74
56
  }
75
57
  };
76
-
77
58
  const updateSystem = async params => {
78
59
  const {
79
60
  system,
80
61
  original
81
62
  } = params;
82
63
  const keys = createKeys(system);
83
-
84
64
  try {
85
- await entity.put(_objectSpread(_objectSpread({}, system), keys));
65
+ await entity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, system), keys));
86
66
  return system;
87
67
  } catch (ex) {
88
68
  throw new _error.default(ex.message || "Could not update the system record by given keys.", ex.code || "UPDATE_SYSTEM_ERROR", {
@@ -92,7 +72,6 @@ const createSystemStorageOperations = params => {
92
72
  });
93
73
  }
94
74
  };
95
-
96
75
  return {
97
76
  createSystem,
98
77
  getSystem,
@@ -101,5 +80,4 @@ const createSystemStorageOperations = params => {
101
80
  createSystemSortKey
102
81
  };
103
82
  };
104
-
105
83
  exports.createSystemStorageOperations = createSystemStorageOperations;
@@ -0,0 +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,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AM,CAACE,IAAI,CAAC;IAC3C,CAAC,CAAC,OAAOP,EAAE,EAAE;MACT,MAAM,IAAIC,cAAW,CACjBD,EAAE,CAACE,OAAO,IAAI,gDAAgD,EAC9DF,EAAE,CAACG,IAAI,IAAI,mBAAmB,EAC9B;QACIL;MACJ,CAAC,CACJ;IACL;EACJ,CAAC;EAED,MAAMW,YAAY,GAAG,MACjBrB,MAAsD,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,12 +1,13 @@
1
1
  {
2
2
  "name": "@webiny/api-form-builder-so-ddb-es",
3
- "version": "0.0.0-mt-2",
3
+ "version": "0.0.0-unstable.085ff6572f",
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
+ "ddb-es",
10
11
  "fb:ddb-es"
11
12
  ],
12
13
  "repository": {
@@ -21,39 +22,33 @@
21
22
  ],
22
23
  "license": "MIT",
23
24
  "dependencies": {
24
- "@babel/runtime": "7.15.4",
25
+ "@babel/runtime": "7.20.13",
25
26
  "@elastic/elasticsearch": "7.12.0",
26
- "@webiny/api-elasticsearch": "0.0.0-mt-2",
27
- "@webiny/api-form-builder": "0.0.0-mt-2",
28
- "@webiny/api-i18n": "0.0.0-mt-2",
29
- "@webiny/api-tenancy": "0.0.0-mt-2",
30
- "@webiny/api-upgrade": "0.0.0-mt-2",
31
- "@webiny/db-dynamodb": "0.0.0-mt-2",
32
- "@webiny/error": "0.0.0-mt-2",
33
- "@webiny/handler": "0.0.0-mt-2",
34
- "@webiny/handler-aws": "0.0.0-mt-2",
35
- "@webiny/plugins": "0.0.0-mt-2",
36
- "@webiny/utils": "0.0.0-mt-2",
37
- "dynamodb-toolbox": "0.3.4",
38
- "elastic-ts": "0.7.0"
27
+ "@webiny/api-elasticsearch": "0.0.0-unstable.085ff6572f",
28
+ "@webiny/api-form-builder": "0.0.0-unstable.085ff6572f",
29
+ "@webiny/db-dynamodb": "0.0.0-unstable.085ff6572f",
30
+ "@webiny/error": "0.0.0-unstable.085ff6572f",
31
+ "@webiny/plugins": "0.0.0-unstable.085ff6572f",
32
+ "@webiny/utils": "0.0.0-unstable.085ff6572f",
33
+ "dynamodb-toolbox": "0.3.5",
34
+ "elastic-ts": "0.8.0"
39
35
  },
40
36
  "devDependencies": {
41
- "@babel/cli": "^7.5.5",
42
- "@babel/core": "^7.5.5",
43
- "@babel/preset-env": "^7.5.5",
44
- "@babel/preset-typescript": "^7.8.3",
45
- "@shelf/jest-elasticsearch": "^1.0.0",
46
- "@webiny/api-dynamodb-to-elasticsearch": "^0.0.0-mt-2",
47
- "@webiny/cli": "^0.0.0-mt-2",
48
- "@webiny/handler-db": "^0.0.0-mt-2",
49
- "@webiny/project-utils": "^0.0.0-mt-2",
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"
37
+ "@babel/cli": "7.20.7",
38
+ "@babel/core": "7.20.12",
39
+ "@babel/preset-env": "7.20.2",
40
+ "@babel/preset-typescript": "7.18.6",
41
+ "@webiny/api-dynamodb-to-elasticsearch": "0.0.0-unstable.085ff6572f",
42
+ "@webiny/cli": "0.0.0-unstable.085ff6572f",
43
+ "@webiny/handler-aws": "0.0.0-unstable.085ff6572f",
44
+ "@webiny/handler-db": "0.0.0-unstable.085ff6572f",
45
+ "@webiny/project-utils": "0.0.0-unstable.085ff6572f",
46
+ "csvtojson": "2.0.10",
47
+ "jest": "29.5.0",
48
+ "jest-dynalite": "3.6.1",
49
+ "rimraf": "3.0.2",
50
+ "ttypescript": "1.5.15",
51
+ "typescript": "4.7.4"
57
52
  },
58
53
  "publishConfig": {
59
54
  "access": "public",
@@ -63,5 +58,5 @@
63
58
  "build": "yarn webiny run build",
64
59
  "watch": "yarn webiny run watch"
65
60
  },
66
- "gitHead": "3c0dcfb3c22c9f83107fdb97b25014cd03d9db7d"
61
+ "gitHead": "085ff6572f6bb6a76d218088b06d9f4ef92bbea7"
67
62
  }
@@ -1,17 +1,12 @@
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.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");
@@ -0,0 +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,uBAAuB,SAASC,wBAAW,CAAC;AAExD;AAAA,8BAFYD,uBAAuB,UACe,iCAAiC"}
@@ -1,4 +1,4 @@
1
- import { ElasticsearchBodyModifierPlugin } from "@webiny/api-elasticsearch/plugins/definition/ElasticsearchBodyModifierPlugin";
1
+ import { ElasticsearchBodyModifierPlugin } from "@webiny/api-elasticsearch";
2
2
  export declare class FormElasticsearchBodyModifierPlugin extends ElasticsearchBodyModifierPlugin {
3
3
  static readonly type: string;
4
4
  }
@@ -1,17 +1,12 @@
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.FormElasticsearchBodyModifierPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _ElasticsearchBodyModifierPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchBodyModifierPlugin");
13
-
14
- class FormElasticsearchBodyModifierPlugin extends _ElasticsearchBodyModifierPlugin.ElasticsearchBodyModifierPlugin {}
15
-
9
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
10
+ class FormElasticsearchBodyModifierPlugin extends _apiElasticsearch.ElasticsearchBodyModifierPlugin {}
16
11
  exports.FormElasticsearchBodyModifierPlugin = FormElasticsearchBodyModifierPlugin;
17
12
  (0, _defineProperty2.default)(FormElasticsearchBodyModifierPlugin, "type", "formBuilder.elasticsearch.modifier.body.form");
@@ -0,0 +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,mCAAmC,SAASC,iDAA+B,CAAC;AAExF;AAAA,8BAFYD,mCAAmC,UACG,8CAA8C"}
@@ -1,4 +1,4 @@
1
- import { ElasticsearchFieldPlugin } from "@webiny/api-elasticsearch/plugins/definition/ElasticsearchFieldPlugin";
1
+ import { ElasticsearchFieldPlugin } from "@webiny/api-elasticsearch";
2
2
  export declare class FormElasticsearchFieldPlugin extends ElasticsearchFieldPlugin {
3
3
  static readonly type: string;
4
4
  }
@@ -1,17 +1,12 @@
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.FormElasticsearchFieldPlugin = void 0;
9
-
10
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _ElasticsearchFieldPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchFieldPlugin");
13
-
14
- class FormElasticsearchFieldPlugin extends _ElasticsearchFieldPlugin.ElasticsearchFieldPlugin {}
15
-
9
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
10
+ class FormElasticsearchFieldPlugin extends _apiElasticsearch.ElasticsearchFieldPlugin {}
16
11
  exports.FormElasticsearchFieldPlugin = FormElasticsearchFieldPlugin;
17
12
  (0, _defineProperty2.default)(FormElasticsearchFieldPlugin, "type", "formBuilder.elasticsearch.fieldDefinition.form");