@webiny/api-form-builder-so-ddb-es 5.39.0-beta.0 → 5.39.0-beta.2

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 (64) hide show
  1. package/definitions/elasticsearch.d.ts +43 -3
  2. package/definitions/elasticsearch.js +6 -7
  3. package/definitions/elasticsearch.js.map +1 -1
  4. package/definitions/form.d.ts +2 -2
  5. package/definitions/form.js +6 -7
  6. package/definitions/form.js.map +1 -1
  7. package/definitions/settings.d.ts +2 -2
  8. package/definitions/settings.js +6 -7
  9. package/definitions/settings.js.map +1 -1
  10. package/definitions/submission.d.ts +2 -2
  11. package/definitions/submission.js +6 -7
  12. package/definitions/submission.js.map +1 -1
  13. package/definitions/system.d.ts +2 -2
  14. package/definitions/system.js +6 -7
  15. package/definitions/system.js.map +1 -1
  16. package/definitions/table.d.ts +4 -4
  17. package/definitions/table.js +5 -3
  18. package/definitions/table.js.map +1 -1
  19. package/definitions/tableElasticsearch.d.ts +4 -4
  20. package/definitions/tableElasticsearch.js +5 -3
  21. package/definitions/tableElasticsearch.js.map +1 -1
  22. package/index.js +25 -22
  23. package/index.js.map +1 -1
  24. package/operations/form/elasticsearchBody.d.ts +2 -2
  25. package/operations/form/elasticsearchBody.js +10 -12
  26. package/operations/form/elasticsearchBody.js.map +1 -1
  27. package/operations/form/index.d.ts +2 -2
  28. package/operations/form/index.js +120 -69
  29. package/operations/form/index.js.map +1 -1
  30. package/operations/settings/index.d.ts +2 -2
  31. package/operations/settings/index.js +23 -10
  32. package/operations/settings/index.js.map +1 -1
  33. package/operations/submission/elasticsearchBody.d.ts +2 -2
  34. package/operations/submission/elasticsearchBody.js +10 -12
  35. package/operations/submission/elasticsearchBody.js.map +1 -1
  36. package/operations/submission/index.d.ts +2 -2
  37. package/operations/submission/index.js +50 -26
  38. package/operations/submission/index.js.map +1 -1
  39. package/operations/system/index.d.ts +2 -2
  40. package/operations/system/index.js +19 -9
  41. package/operations/system/index.js.map +1 -1
  42. package/package.json +18 -15
  43. package/plugins/FormDynamoDbFieldPlugin.js +3 -4
  44. package/plugins/FormDynamoDbFieldPlugin.js.map +1 -1
  45. package/plugins/FormElasticsearchBodyModifierPlugin.js +3 -4
  46. package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -1
  47. package/plugins/FormElasticsearchFieldPlugin.js +3 -4
  48. package/plugins/FormElasticsearchFieldPlugin.js.map +1 -1
  49. package/plugins/FormElasticsearchIndexPlugin.js +3 -4
  50. package/plugins/FormElasticsearchIndexPlugin.js.map +1 -1
  51. package/plugins/FormElasticsearchQueryModifierPlugin.js +3 -4
  52. package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -1
  53. package/plugins/FormElasticsearchSortModifierPlugin.js +3 -4
  54. package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -1
  55. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +3 -4
  56. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -1
  57. package/plugins/SubmissionElasticsearchFieldPlugin.js +3 -4
  58. package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -1
  59. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +3 -4
  60. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -1
  61. package/plugins/SubmissionElasticsearchSortModifierPlugin.js +3 -4
  62. package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -1
  63. package/types.d.ts +6 -8
  64. package/types.js.map +1 -1
@@ -1,11 +1,9 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.createFormElasticType = exports.createElasticsearchBody = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
7
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
10
8
  var _FormElasticsearchFieldPlugin = require("../../plugins/FormElasticsearchFieldPlugin");
11
9
  var _FormElasticsearchSortModifierPlugin = require("../../plugins/FormElasticsearchSortModifierPlugin");
@@ -42,7 +40,9 @@ const createElasticsearchQuery = params => {
42
40
  * Be aware that, if having more registered operator plugins of same type, the last one will be used.
43
41
  */
44
42
  const operatorPlugins = (0, _apiElasticsearch.getElasticsearchOperatorPluginsByLocale)(plugins, initialWhere.locale);
45
- const where = (0, _objectSpread2.default)({}, initialWhere);
43
+ const where = {
44
+ ...initialWhere
45
+ };
46
46
  /**
47
47
  * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.
48
48
  *
@@ -95,9 +95,10 @@ const createElasticsearchBody = params => {
95
95
  return acc;
96
96
  }, {});
97
97
  const limit = (0, _apiElasticsearch.createLimit)(initialLimit, 100);
98
- const query = createElasticsearchQuery((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
98
+ const query = createElasticsearchQuery({
99
+ ...params,
99
100
  fieldPlugins
100
- }));
101
+ });
101
102
  const sort = (0, _apiElasticsearch.createSort)({
102
103
  sort: initialSort,
103
104
  fieldPlugins
@@ -119,17 +120,14 @@ const createElasticsearchBody = params => {
119
120
  query: {
120
121
  constant_score: {
121
122
  filter: {
122
- bool: (0, _objectSpread2.default)({}, query)
123
+ bool: {
124
+ ...query
125
+ }
123
126
  }
124
127
  }
125
128
  },
126
129
  size: limit + 1,
127
- /**
128
- * Casting as any is required due to search_after is accepting an array of values.
129
- * Which is correct in some cases. In our case, it is not.
130
- * https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html
131
- */
132
- search_after: (0, _apiElasticsearch.decodeCursor)(after),
130
+ search_after: after,
133
131
  sort
134
132
  };
135
133
  const bodyModifiers = plugins.byType(_FormElasticsearchBodyModifierPlugin.FormElasticsearchBodyModifierPlugin.type);
@@ -1 +1 @@
1
- {"version":3,"names":["_apiElasticsearch","require","_FormElasticsearchFieldPlugin","_FormElasticsearchSortModifierPlugin","_FormElasticsearchBodyModifierPlugin","_FormElasticsearchQueryModifierPlugin","createFormElasticType","exports","createInitialQueryValue","must","term","must_not","should","filter","createElasticsearchQuery","params","plugins","where","initialWhere","fieldPlugins","query","operatorPlugins","getElasticsearchOperatorPluginsByLocale","locale","_objectSpread2","default","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","applyWhere","fields","operators","createElasticsearchBody","limit","initialLimit","sort","initialSort","after","byType","FormElasticsearchFieldPlugin","type","reduce","acc","plugin","field","createLimit","createSort","queryModifiers","FormElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","FormElasticsearchSortModifierPlugin","modifySort","body","constant_score","bool","size","search_after","decodeCursor","bodyModifiers","FormElasticsearchBodyModifierPlugin","modifyBody"],"sources":["elasticsearchBody.ts"],"sourcesContent":["import { SearchBody as esSearchBody } from \"elastic-ts\";\nimport {\n decodeCursor,\n getElasticsearchOperatorPluginsByLocale,\n applyWhere,\n createLimit,\n createSort\n} from \"@webiny/api-elasticsearch\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { FormElasticsearchFieldPlugin } from \"~/plugins/FormElasticsearchFieldPlugin\";\nimport { FormElasticsearchSortModifierPlugin } from \"~/plugins/FormElasticsearchSortModifierPlugin\";\nimport { FormElasticsearchBodyModifierPlugin } from \"~/plugins/FormElasticsearchBodyModifierPlugin\";\nimport { FormBuilderStorageOperationsListFormsParams } from \"@webiny/api-form-builder/types\";\nimport { FormElasticsearchQueryModifierPlugin } from \"~/plugins/FormElasticsearchQueryModifierPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\nexport const createFormElasticType = (): string => {\n return \"fb.form\";\n};\n\nconst createInitialQueryValue = (): ElasticsearchBoolQueryConfig => {\n return {\n must: [\n /**\n * We add the __type filtering in the initial query because it must be applied.\n */\n {\n term: {\n \"__type.keyword\": createFormElasticType()\n }\n }\n ],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\ninterface CreateElasticsearchQueryParams extends CreateElasticsearchBodyParams {\n fieldPlugins: Record<string, FormElasticsearchFieldPlugin>;\n}\n\nconst createElasticsearchQuery = (params: CreateElasticsearchQueryParams) => {\n const { plugins, where: initialWhere, fieldPlugins } = params;\n const query = createInitialQueryValue();\n /**\n * Be aware that, if having more registered operator plugins of same type, the last one will be used.\n */\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, initialWhere.locale);\n\n const where: Partial<FormBuilderStorageOperationsListFormsParams[\"where\"]> = {\n ...initialWhere\n };\n /**\n * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.\n *\n * When ES index is shared between tenants, we need to filter records by tenant ID.\n * No need for the tenant filtering otherwise as each index is for single tenant.\n */\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex && where.tenant) {\n query.must.push({\n term: {\n \"tenant.keyword\": where.tenant\n }\n });\n }\n /**\n * Remove tenant so it is not applied again later.\n * Possibly tenant is not defined, but just in case, remove it.\n */\n delete where.tenant;\n /**\n * Add the locale to filtering.\n */\n query.must.push({\n term: {\n \"locale.keyword\": where.locale as string\n }\n });\n delete where.locale;\n /**\n * We apply other conditions as they are passed via the where value.\n */\n applyWhere({\n query,\n where,\n fields: fieldPlugins,\n operators: operatorPlugins\n });\n\n return query;\n};\n\ninterface CreateElasticsearchBodyParams {\n plugins: PluginsContainer;\n where: FormBuilderStorageOperationsListFormsParams[\"where\"];\n limit: number;\n after?: string;\n sort: string[];\n}\n\nexport const createElasticsearchBody = (params: CreateElasticsearchBodyParams): esSearchBody => {\n const { plugins, where, limit: initialLimit, sort: initialSort, after } = params;\n\n const fieldPlugins = plugins\n .byType<FormElasticsearchFieldPlugin>(FormElasticsearchFieldPlugin.type)\n .reduce((acc, plugin) => {\n acc[plugin.field] = plugin;\n return acc;\n }, {} as Record<string, FormElasticsearchFieldPlugin>);\n\n const limit = createLimit(initialLimit, 100);\n\n const query = createElasticsearchQuery({\n ...params,\n fieldPlugins\n });\n\n const sort = createSort({\n sort: initialSort,\n fieldPlugins\n });\n\n const queryModifiers = plugins.byType<FormElasticsearchQueryModifierPlugin>(\n FormElasticsearchQueryModifierPlugin.type\n );\n\n for (const plugin of queryModifiers) {\n plugin.modifyQuery({\n query,\n where\n });\n }\n\n const sortModifiers = plugins.byType<FormElasticsearchSortModifierPlugin>(\n FormElasticsearchSortModifierPlugin.type\n );\n\n for (const plugin of sortModifiers) {\n plugin.modifySort({\n sort\n });\n }\n\n const body = {\n query: {\n constant_score: {\n filter: {\n bool: {\n ...query\n }\n }\n }\n },\n size: limit + 1,\n /**\n * Casting as any is required due to search_after is accepting an array of values.\n * Which is correct in some cases. In our case, it is not.\n * https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html\n */\n search_after: decodeCursor(after) as any,\n sort\n };\n\n const bodyModifiers = plugins.byType<FormElasticsearchBodyModifierPlugin>(\n FormElasticsearchBodyModifierPlugin.type\n );\n\n for (const plugin of bodyModifiers) {\n plugin.modifyBody({\n body\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAQA,IAAAC,6BAAA,GAAAD,OAAA;AACA,IAAAE,oCAAA,GAAAF,OAAA;AACA,IAAAG,oCAAA,GAAAH,OAAA;AAEA,IAAAI,qCAAA,GAAAJ,OAAA;AAGO,MAAMK,qBAAqB,GAAGA,CAAA,KAAc;EAC/C,OAAO,SAAS;AACpB,CAAC;AAACC,OAAA,CAAAD,qBAAA,GAAAA,qBAAA;AAEF,MAAME,uBAAuB,GAAGA,CAAA,KAAoC;EAChE,OAAO;IACHC,IAAI,EAAE;IACF;AACZ;AACA;IACY;MACIC,IAAI,EAAE;QACF,gBAAgB,EAAEJ,qBAAqB,CAAC;MAC5C;IACJ,CAAC,CACJ;IACDK,QAAQ,EAAE,EAAE;IACZC,MAAM,EAAE,EAAE;IACVC,MAAM,EAAE;EACZ,CAAC;AACL,CAAC;AAMD,MAAMC,wBAAwB,GAAIC,MAAsC,IAA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G,MAAM,IAAIgB,aAAa,EAAE;IAChChB,MAAM,CAACkB,UAAU,CAAC;MACdR;IACJ,CAAC,CAAC;EACN;EAEA,OAAOA,IAAI;AACf,CAAC;AAACjD,OAAA,CAAA4B,uBAAA,GAAAA,uBAAA"}
1
+ {"version":3,"names":["_apiElasticsearch","require","_FormElasticsearchFieldPlugin","_FormElasticsearchSortModifierPlugin","_FormElasticsearchBodyModifierPlugin","_FormElasticsearchQueryModifierPlugin","createFormElasticType","exports","createInitialQueryValue","must","term","must_not","should","filter","createElasticsearchQuery","params","plugins","where","initialWhere","fieldPlugins","query","operatorPlugins","getElasticsearchOperatorPluginsByLocale","locale","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","applyWhere","fields","operators","createElasticsearchBody","limit","initialLimit","sort","initialSort","after","byType","FormElasticsearchFieldPlugin","type","reduce","acc","plugin","field","createLimit","createSort","queryModifiers","FormElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","FormElasticsearchSortModifierPlugin","modifySort","body","constant_score","bool","size","search_after","bodyModifiers","FormElasticsearchBodyModifierPlugin","modifyBody"],"sources":["elasticsearchBody.ts"],"sourcesContent":["import { PrimitiveValue, SearchBody as esSearchBody } from \"elastic-ts\";\nimport {\n applyWhere,\n createLimit,\n createSort,\n getElasticsearchOperatorPluginsByLocale\n} from \"@webiny/api-elasticsearch\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { FormElasticsearchFieldPlugin } from \"~/plugins/FormElasticsearchFieldPlugin\";\nimport { FormElasticsearchSortModifierPlugin } from \"~/plugins/FormElasticsearchSortModifierPlugin\";\nimport { FormElasticsearchBodyModifierPlugin } from \"~/plugins/FormElasticsearchBodyModifierPlugin\";\nimport { FormBuilderStorageOperationsListFormsParams } from \"@webiny/api-form-builder/types\";\nimport { FormElasticsearchQueryModifierPlugin } from \"~/plugins/FormElasticsearchQueryModifierPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\nexport const createFormElasticType = (): string => {\n return \"fb.form\";\n};\n\nconst createInitialQueryValue = (): ElasticsearchBoolQueryConfig => {\n return {\n must: [\n /**\n * We add the __type filtering in the initial query because it must be applied.\n */\n {\n term: {\n \"__type.keyword\": createFormElasticType()\n }\n }\n ],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\ninterface CreateElasticsearchQueryParams extends CreateElasticsearchBodyParams {\n fieldPlugins: Record<string, FormElasticsearchFieldPlugin>;\n}\n\nconst createElasticsearchQuery = (params: CreateElasticsearchQueryParams) => {\n const { plugins, where: initialWhere, fieldPlugins } = params;\n const query = createInitialQueryValue();\n /**\n * Be aware that, if having more registered operator plugins of same type, the last one will be used.\n */\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, initialWhere.locale);\n\n const where: Partial<FormBuilderStorageOperationsListFormsParams[\"where\"]> = {\n ...initialWhere\n };\n /**\n * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.\n *\n * When ES index is shared between tenants, we need to filter records by tenant ID.\n * No need for the tenant filtering otherwise as each index is for single tenant.\n */\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex && where.tenant) {\n query.must.push({\n term: {\n \"tenant.keyword\": where.tenant\n }\n });\n }\n /**\n * Remove tenant so it is not applied again later.\n * Possibly tenant is not defined, but just in case, remove it.\n */\n delete where.tenant;\n /**\n * Add the locale to filtering.\n */\n query.must.push({\n term: {\n \"locale.keyword\": where.locale as string\n }\n });\n delete where.locale;\n /**\n * We apply other conditions as they are passed via the where value.\n */\n applyWhere({\n query,\n where,\n fields: fieldPlugins,\n operators: operatorPlugins\n });\n\n return query;\n};\n\ninterface CreateElasticsearchBodyParams {\n plugins: PluginsContainer;\n where: FormBuilderStorageOperationsListFormsParams[\"where\"];\n limit: number;\n after?: PrimitiveValue[];\n sort: string[];\n}\n\nexport const createElasticsearchBody = (params: CreateElasticsearchBodyParams): esSearchBody => {\n const { plugins, where, limit: initialLimit, sort: initialSort, after } = params;\n\n const fieldPlugins = plugins\n .byType<FormElasticsearchFieldPlugin>(FormElasticsearchFieldPlugin.type)\n .reduce((acc, plugin) => {\n acc[plugin.field] = plugin;\n return acc;\n }, {} as Record<string, FormElasticsearchFieldPlugin>);\n\n const limit = createLimit(initialLimit, 100);\n\n const query = createElasticsearchQuery({\n ...params,\n fieldPlugins\n });\n\n const sort = createSort({\n sort: initialSort,\n fieldPlugins\n });\n\n const queryModifiers = plugins.byType<FormElasticsearchQueryModifierPlugin>(\n FormElasticsearchQueryModifierPlugin.type\n );\n\n for (const plugin of queryModifiers) {\n plugin.modifyQuery({\n query,\n where\n });\n }\n\n const sortModifiers = plugins.byType<FormElasticsearchSortModifierPlugin>(\n FormElasticsearchSortModifierPlugin.type\n );\n\n for (const plugin of sortModifiers) {\n plugin.modifySort({\n sort\n });\n }\n\n const body = {\n query: {\n constant_score: {\n filter: {\n bool: {\n ...query\n }\n }\n }\n },\n size: limit + 1,\n search_after: after,\n sort\n };\n\n const bodyModifiers = plugins.byType<FormElasticsearchBodyModifierPlugin>(\n FormElasticsearchBodyModifierPlugin.type\n );\n\n for (const plugin of bodyModifiers) {\n plugin.modifyBody({\n body\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AAOA,IAAAC,6BAAA,GAAAD,OAAA;AACA,IAAAE,oCAAA,GAAAF,OAAA;AACA,IAAAG,oCAAA,GAAAH,OAAA;AAEA,IAAAI,qCAAA,GAAAJ,OAAA;AAGO,MAAMK,qBAAqB,GAAGA,CAAA,KAAc;EAC/C,OAAO,SAAS;AACpB,CAAC;AAACC,OAAA,CAAAD,qBAAA,GAAAA,qBAAA;AAEF,MAAME,uBAAuB,GAAGA,CAAA,KAAoC;EAChE,OAAO;IACHC,IAAI,EAAE;IACF;AACZ;AACA;IACY;MACIC,IAAI,EAAE;QACF,gBAAgB,EAAEJ,qBAAqB,CAAC;MAC5C;IACJ,CAAC,CACJ;IACDK,QA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AM,IAAIe,aAAa,EAAE;IAChCf,MAAM,CAACiB,UAAU,CAAC;MACdP;IACJ,CAAC,CAAC;EACN;EAEA,OAAOA,IAAI;AACf,CAAC;AAAC/C,OAAA,CAAA0B,uBAAA,GAAAA,uBAAA"}
@@ -1,4 +1,4 @@
1
- import { Entity, Table } from "dynamodb-toolbox";
1
+ import { Entity, Table } from "@webiny/db-dynamodb/toolbox";
2
2
  import { Client } from "@elastic/elasticsearch";
3
3
  import { PluginsContainer } from "@webiny/plugins";
4
4
  import { FormBuilderFormStorageOperations } from "../../types";
@@ -10,7 +10,7 @@ export declare type DbRecord<T = any> = T & {
10
10
  export interface CreateFormStorageOperationsParams {
11
11
  entity: Entity<any>;
12
12
  esEntity: Entity<any>;
13
- table: Table;
13
+ table: Table<string, string, string>;
14
14
  elasticsearch: Client;
15
15
  plugins: PluginsContainer;
16
16
  }
@@ -5,10 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createFormStorageOperations = void 0;
8
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
8
  var _query = require("@webiny/db-dynamodb/utils/query");
10
9
  var _error = _interopRequireDefault(require("@webiny/error"));
11
- var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
12
10
  var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
13
11
  var _configurations = require("../../configurations");
14
12
  var _filter = require("@webiny/db-dynamodb/utils/filter");
@@ -17,6 +15,7 @@ var _sort = require("@webiny/db-dynamodb/utils/sort");
17
15
  var _utils = require("@webiny/utils");
18
16
  var _elasticsearchBody = require("./elasticsearchBody");
19
17
  var _apiElasticsearch = require("@webiny/api-elasticsearch");
18
+ var _dbDynamodb = require("@webiny/db-dynamodb");
20
19
  const getESDataForLatestRevision = form => ({
21
20
  __type: (0, _elasticsearchBody.createFormElasticType)(),
22
21
  id: form.id,
@@ -87,11 +86,15 @@ const createFormStorageOperations = params => {
87
86
  PK: createFormPartitionKey(form),
88
87
  SK: createLatestSortKey()
89
88
  };
90
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
91
- TYPE: createFormType()
92
- }, revisionKeys)), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
93
- TYPE: createFormLatestType()
94
- }, latestKeys))];
89
+ const items = [entity.putBatch({
90
+ ...form,
91
+ TYPE: createFormType(),
92
+ ...revisionKeys
93
+ }), entity.putBatch({
94
+ ...form,
95
+ TYPE: createFormLatestType(),
96
+ ...latestKeys
97
+ })];
95
98
  try {
96
99
  await (0, _batchWrite.batchWriteAll)({
97
100
  table,
@@ -111,11 +114,15 @@ const createFormStorageOperations = params => {
111
114
  tenant: form.tenant,
112
115
  locale: form.locale
113
116
  });
114
- await esEntity.put((0, _objectSpread2.default)({
115
- index,
116
- data: getESDataForLatestRevision(form),
117
- TYPE: createFormType()
118
- }, latestKeys));
117
+ await (0, _dbDynamodb.put)({
118
+ entity: esEntity,
119
+ item: {
120
+ index,
121
+ data: getESDataForLatestRevision(form),
122
+ TYPE: createFormType(),
123
+ ...latestKeys
124
+ }
125
+ });
119
126
  } catch (ex) {
120
127
  throw new _error.default(ex.message || "Could not insert form data into Elasticsearch table.", ex.code || "CREATE_FORM_ERROR", {
121
128
  latestKeys,
@@ -138,11 +145,15 @@ const createFormStorageOperations = params => {
138
145
  PK: createFormPartitionKey(form),
139
146
  SK: createLatestSortKey()
140
147
  };
141
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
148
+ const items = [entity.putBatch({
149
+ ...form,
150
+ ...revisionKeys,
142
151
  TYPE: createFormType()
143
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
152
+ }), entity.putBatch({
153
+ ...form,
154
+ ...latestKeys,
144
155
  TYPE: createFormLatestType()
145
- }))];
156
+ })];
146
157
  try {
147
158
  await (0, _batchWrite.batchWriteAll)({
148
159
  table,
@@ -164,11 +175,15 @@ const createFormStorageOperations = params => {
164
175
  tenant: form.tenant,
165
176
  locale: form.locale
166
177
  });
167
- await esEntity.put((0, _objectSpread2.default)({
168
- index,
169
- data: getESDataForLatestRevision(form),
170
- TYPE: createFormLatestType()
171
- }, latestKeys));
178
+ await (0, _dbDynamodb.put)({
179
+ entity: esEntity,
180
+ item: {
181
+ index,
182
+ data: getESDataForLatestRevision(form),
183
+ TYPE: createFormLatestType(),
184
+ ...latestKeys
185
+ }
186
+ });
172
187
  } catch (ex) {
173
188
  throw new _error.default(ex.message || "Could not create form in the Elasticsearch table, from existing form.", ex.code || "CREATE_FORM_FROM_ERROR", {
174
189
  latestKeys,
@@ -206,13 +221,17 @@ const createFormStorageOperations = params => {
206
221
  }
207
222
  });
208
223
  const isLatestForm = latestForm ? latestForm.id === form.id : false;
209
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
210
- TYPE: createFormType()
211
- }, revisionKeys))];
224
+ const items = [entity.putBatch({
225
+ ...form,
226
+ TYPE: createFormType(),
227
+ ...revisionKeys
228
+ })];
212
229
  if (isLatestForm) {
213
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
214
- TYPE: createFormLatestType()
215
- }, latestKeys)));
230
+ items.push(entity.putBatch({
231
+ ...form,
232
+ TYPE: createFormLatestType(),
233
+ ...latestKeys
234
+ }));
216
235
  }
217
236
  try {
218
237
  await (0, _batchWrite.batchWriteAll)({
@@ -241,11 +260,15 @@ const createFormStorageOperations = params => {
241
260
  tenant: form.tenant,
242
261
  locale: form.locale
243
262
  });
244
- await esEntity.put((0, _objectSpread2.default)({
245
- index,
246
- data: getESDataForLatestRevision(form),
247
- TYPE: createFormLatestType()
248
- }, latestKeys));
263
+ await (0, _dbDynamodb.put)({
264
+ entity: esEntity,
265
+ item: {
266
+ index,
267
+ data: getESDataForLatestRevision(form),
268
+ TYPE: createFormLatestType(),
269
+ ...latestKeys
270
+ }
271
+ });
249
272
  } catch (ex) {
250
273
  throw new _error.default(ex.message || "Could not update form data in the Elasticsearch table.", ex.code || "UPDATE_FORM_ERROR", {
251
274
  latestKeys,
@@ -296,11 +319,10 @@ const createFormStorageOperations = params => {
296
319
  SK: sortKey
297
320
  };
298
321
  try {
299
- const result = await entity.get(keys);
300
- if (!result || !result.Item) {
301
- return null;
302
- }
303
- return (0, _cleanup.cleanupItem)(entity, result.Item);
322
+ return await (0, _dbDynamodb.getClean)({
323
+ entity,
324
+ keys
325
+ });
304
326
  } catch (ex) {
305
327
  throw new _error.default(ex.message || "Could not get form by keys.", ex.code || "GET_FORM_ERROR", {
306
328
  keys
@@ -325,9 +347,10 @@ const createFormStorageOperations = params => {
325
347
  tenant: where.tenant,
326
348
  locale: where.locale
327
349
  });
328
- const query = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, esConfig), {}, {
350
+ const query = {
351
+ ...esConfig,
329
352
  body
330
- });
353
+ };
331
354
  let response;
332
355
  try {
333
356
  response = await elasticsearch.search(query);
@@ -395,10 +418,11 @@ const createFormStorageOperations = params => {
395
418
  options: queryAllParams.options
396
419
  });
397
420
  }
398
- const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
421
+ const where = {
422
+ ...initialWhere,
399
423
  id: undefined,
400
424
  formId: undefined
401
- });
425
+ };
402
426
  const filteredItems = (0, _filter.filterItems)({
403
427
  plugins,
404
428
  items,
@@ -456,7 +480,10 @@ const createFormStorageOperations = params => {
456
480
  SK: createLatestSortKey()
457
481
  };
458
482
  try {
459
- await esEntity.delete(latestKeys);
483
+ await (0, _dbDynamodb.deleteItem)({
484
+ entity: esEntity,
485
+ keys: latestKeys
486
+ });
460
487
  } catch (ex) {
461
488
  throw new _error.default(ex.message || "Could not delete latest form record from Elasticsearch.", ex.code || "DELETE_FORM_ERROR", {
462
489
  latestKeys
@@ -499,11 +526,12 @@ const createFormStorageOperations = params => {
499
526
  return new Date(b.publishedOn).getTime() - new Date(a.publishedOn).getTime();
500
527
  }).shift();
501
528
  if (previouslyPublishedForm) {
502
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedForm), {}, {
529
+ items.push(entity.putBatch({
530
+ ...previouslyPublishedForm,
503
531
  PK: createFormPartitionKey(previouslyPublishedForm),
504
532
  SK: createLatestPublishedSortKey(),
505
533
  TYPE: createFormLatestPublishedType()
506
- })));
534
+ }));
507
535
  } else {
508
536
  items.push(entity.deleteBatch({
509
537
  PK: createFormPartitionKey(form),
@@ -515,20 +543,22 @@ const createFormStorageOperations = params => {
515
543
  * Sort out the latest record.
516
544
  */
517
545
  if (isLatest && previous) {
518
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previous), latestKeys), {}, {
546
+ items.push(entity.putBatch({
547
+ ...previous,
548
+ ...latestKeys,
519
549
  TYPE: createFormLatestType()
520
- })));
550
+ }));
521
551
  const {
522
552
  index
523
553
  } = _configurations.configurations.es({
524
554
  tenant: previous.tenant,
525
555
  locale: previous.locale
526
556
  });
527
- esDataItem = (0, _objectSpread2.default)((0, _objectSpread2.default)({
528
- index
529
- }, latestKeys), {}, {
557
+ esDataItem = {
558
+ index,
559
+ ...latestKeys,
530
560
  data: getESDataForLatestRevision(previous)
531
- });
561
+ };
532
562
  }
533
563
  }
534
564
  /**
@@ -554,7 +584,10 @@ const createFormStorageOperations = params => {
554
584
  return form;
555
585
  }
556
586
  try {
557
- await esEntity.put(esDataItem);
587
+ await (0, _dbDynamodb.put)({
588
+ entity: esEntity,
589
+ item: esDataItem
590
+ });
558
591
  return form;
559
592
  } catch (ex) {
560
593
  throw new _error.default(ex.message || "Could not delete form from to the Elasticsearch table.", ex.code || "DELETE_FORM_REVISION_ERROR", {
@@ -607,18 +640,24 @@ const createFormStorageOperations = params => {
607
640
  /**
608
641
  * Update revision and latest published records
609
642
  */
610
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
643
+ const items = [entity.putBatch({
644
+ ...form,
645
+ ...revisionKeys,
611
646
  TYPE: createFormType()
612
- })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestPublishedKeys), {}, {
647
+ }), entity.putBatch({
648
+ ...form,
649
+ ...latestPublishedKeys,
613
650
  TYPE: createFormLatestPublishedType()
614
- }))];
651
+ })];
615
652
  /**
616
653
  * Update the latest form as well
617
654
  */
618
655
  if (isLatestForm) {
619
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
656
+ items.push(entity.putBatch({
657
+ ...form,
658
+ ...latestKeys,
620
659
  TYPE: createFormLatestType()
621
- })));
660
+ }));
622
661
  }
623
662
  try {
624
663
  await (0, _batchWrite.batchWriteAll)({
@@ -646,11 +685,15 @@ const createFormStorageOperations = params => {
646
685
  });
647
686
  const esData = getESDataForLatestRevision(form);
648
687
  try {
649
- await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
650
- index,
651
- TYPE: createFormLatestType(),
652
- data: esData
653
- }));
688
+ await (0, _dbDynamodb.put)({
689
+ entity: esEntity,
690
+ item: {
691
+ ...latestKeys,
692
+ index,
693
+ TYPE: createFormLatestType(),
694
+ data: esData
695
+ }
696
+ });
654
697
  return form;
655
698
  } catch (ex) {
656
699
  throw new _error.default(ex.message || "Could not publish form to the Elasticsearch.", ex.code || "PUBLISH_FORM_ERROR", {
@@ -710,9 +753,11 @@ const createFormStorageOperations = params => {
710
753
  });
711
754
  const isLatest = latestForm ? latestForm.id === form.id : false;
712
755
  const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;
713
- const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
756
+ const items = [entity.putBatch({
757
+ ...form,
758
+ ...revisionKeys,
714
759
  TYPE: createFormType()
715
- }))];
760
+ })];
716
761
  let esData = undefined;
717
762
  if (isLatest) {
718
763
  esData = getESDataForLatestRevision(form);
@@ -734,9 +779,11 @@ const createFormStorageOperations = params => {
734
779
  });
735
780
  const previouslyPublishedRevision = revisions.shift();
736
781
  if (previouslyPublishedRevision) {
737
- items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedRevision), latestPublishedKeys), {}, {
782
+ items.push(entity.putBatch({
783
+ ...previouslyPublishedRevision,
784
+ ...latestPublishedKeys,
738
785
  TYPE: createFormLatestPublishedType()
739
- })));
786
+ }));
740
787
  } else {
741
788
  items.push(entity.deleteBatch(latestPublishedKeys));
742
789
  }
@@ -769,11 +816,15 @@ const createFormStorageOperations = params => {
769
816
  locale: form.locale
770
817
  });
771
818
  try {
772
- await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
773
- index,
774
- TYPE: createFormLatestType(),
775
- data: esData
776
- }));
819
+ await (0, _dbDynamodb.put)({
820
+ entity: esEntity,
821
+ item: {
822
+ ...latestKeys,
823
+ index,
824
+ TYPE: createFormLatestType(),
825
+ data: esData
826
+ }
827
+ });
777
828
  return form;
778
829
  } catch (ex) {
779
830
  throw new _error.default(ex.message || "Could not unpublish form from the Elasticsearch.", ex.code || "UNPUBLISH_FORM_ERROR", {