@webiny/api-form-builder-so-ddb-es 0.0.0-mt-3 → 0.0.0-unstable.1e66d121db

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 (83) hide show
  1. package/configurations.d.ts +7 -5
  2. package/configurations.js +31 -9
  3. package/configurations.js.map +1 -0
  4. package/definitions/elasticsearch.d.ts +2 -1
  5. package/definitions/elasticsearch.js +3 -7
  6. package/definitions/elasticsearch.js.map +1 -0
  7. package/definitions/form.d.ts +2 -1
  8. package/definitions/form.js +3 -7
  9. package/definitions/form.js.map +1 -0
  10. package/definitions/settings.d.ts +2 -1
  11. package/definitions/settings.js +3 -7
  12. package/definitions/settings.js.map +1 -0
  13. package/definitions/submission.d.ts +2 -1
  14. package/definitions/submission.js +3 -7
  15. package/definitions/submission.js.map +1 -0
  16. package/definitions/system.d.ts +2 -1
  17. package/definitions/system.js +3 -7
  18. package/definitions/system.js.map +1 -0
  19. package/definitions/table.d.ts +3 -2
  20. package/definitions/table.js.map +1 -0
  21. package/definitions/tableElasticsearch.d.ts +2 -1
  22. package/definitions/tableElasticsearch.js.map +1 -0
  23. package/elasticsearch/createElasticsearchIndex.d.ts +10 -0
  24. package/elasticsearch/createElasticsearchIndex.js +63 -0
  25. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  26. package/elasticsearch/indices/base.d.ts +2 -0
  27. package/elasticsearch/indices/base.js +19 -0
  28. package/elasticsearch/indices/base.js.map +1 -0
  29. package/elasticsearch/indices/index.d.ts +1 -0
  30. package/elasticsearch/indices/index.js +16 -0
  31. package/elasticsearch/indices/index.js.map +1 -0
  32. package/elasticsearch/indices/japanese.d.ts +2 -0
  33. package/elasticsearch/indices/japanese.js +20 -0
  34. package/elasticsearch/indices/japanese.js.map +1 -0
  35. package/index.js +35 -32
  36. package/index.js.map +1 -0
  37. package/operations/form/elasticsearchBody.js +8 -17
  38. package/operations/form/elasticsearchBody.js.map +1 -0
  39. package/operations/form/elasticsearchFields.js.map +1 -0
  40. package/operations/form/fields.js.map +1 -0
  41. package/operations/form/index.d.ts +2 -2
  42. package/operations/form/index.js +49 -48
  43. package/operations/form/index.js.map +1 -0
  44. package/operations/settings/index.d.ts +2 -2
  45. package/operations/settings/index.js +4 -8
  46. package/operations/settings/index.js.map +1 -0
  47. package/operations/submission/elasticsearchBody.js +10 -12
  48. package/operations/submission/elasticsearchBody.js.map +1 -0
  49. package/operations/submission/elasticsearchFields.js.map +1 -0
  50. package/operations/submission/index.d.ts +2 -2
  51. package/operations/submission/index.js +19 -22
  52. package/operations/submission/index.js.map +1 -0
  53. package/operations/system/index.d.ts +2 -2
  54. package/operations/system/index.js +4 -8
  55. package/operations/system/index.js.map +1 -0
  56. package/package.json +23 -27
  57. package/plugins/FormDynamoDbFieldPlugin.js +1 -1
  58. package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
  59. package/plugins/FormElasticsearchBodyModifierPlugin.js +1 -1
  60. package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -0
  61. package/plugins/FormElasticsearchFieldPlugin.js +1 -1
  62. package/plugins/FormElasticsearchFieldPlugin.js.map +1 -0
  63. package/plugins/FormElasticsearchIndexPlugin.d.ts +4 -0
  64. package/plugins/FormElasticsearchIndexPlugin.js +17 -0
  65. package/plugins/FormElasticsearchIndexPlugin.js.map +1 -0
  66. package/plugins/FormElasticsearchQueryModifierPlugin.js +1 -1
  67. package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -0
  68. package/plugins/FormElasticsearchSortModifierPlugin.js +1 -1
  69. package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -0
  70. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +1 -1
  71. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -0
  72. package/plugins/SubmissionElasticsearchFieldPlugin.js +1 -1
  73. package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -0
  74. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +1 -1
  75. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -0
  76. package/plugins/SubmissionElasticsearchSortModifierPlugin.js +1 -1
  77. package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -0
  78. package/types.d.ts +2 -2
  79. package/types.js.map +1 -0
  80. package/operations/system/createElasticsearchIndex.d.ts +0 -6
  81. package/operations/system/createElasticsearchIndex.js +0 -70
  82. package/upgrades/5.16.0/index.d.ts +0 -8
  83. package/upgrades/5.16.0/index.js +0 -141
package/index.js CHANGED
@@ -1,18 +1,24 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.createFormBuilderStorageOperations = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
12
- var _types = require("./types");
12
+ var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
13
+
14
+ var _elasticsearchFields = _interopRequireDefault(require("./operations/form/elasticsearchFields"));
15
+
16
+ var _elasticsearchFields2 = _interopRequireDefault(require("./operations/submission/elasticsearchFields"));
13
17
 
14
18
  var _error = _interopRequireDefault(require("@webiny/error"));
15
19
 
20
+ var _types = require("./types");
21
+
16
22
  var _table = require("./definitions/table");
17
23
 
18
24
  var _form = require("./definitions/form");
@@ -31,27 +37,17 @@ var _settings2 = require("./operations/settings");
31
37
 
32
38
  var _form2 = require("./operations/form");
33
39
 
34
- var _createElasticsearchIndex = require("./operations/system/createElasticsearchIndex");
35
-
36
40
  var _tableElasticsearch = require("./definitions/tableElasticsearch");
37
41
 
38
42
  var _plugins = require("@webiny/plugins");
39
43
 
40
44
  var _elasticsearch = require("./definitions/elasticsearch");
41
45
 
42
- var _elasticsearchFields = _interopRequireDefault(require("./operations/submission/elasticsearchFields"));
43
-
44
- var _elasticsearchFields2 = _interopRequireDefault(require("./operations/form/elasticsearchFields"));
45
-
46
- var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
47
-
48
46
  var _operators = require("@webiny/api-elasticsearch/operators");
49
47
 
50
- var _ = _interopRequireDefault(require("./upgrades/5.16.0"));
51
-
52
- 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; }
48
+ var _indices = require("./elasticsearch/indices");
53
49
 
54
- 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; }
50
+ var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
55
51
 
56
52
  const reservedFields = ["PK", "SK", "index", "data", "TYPE", "__type", "GSI1_PK", "GSI1_SK"];
57
53
 
@@ -67,12 +63,12 @@ const isReserved = name => {
67
63
 
68
64
  const createFormBuilderStorageOperations = params => {
69
65
  const {
70
- attributes = {},
66
+ attributes,
71
67
  table: tableName,
72
68
  esTable: esTableName,
73
69
  documentClient,
74
70
  elasticsearch,
75
- plugins: pluginsInput
71
+ plugins: userPlugins
76
72
  } = params;
77
73
 
78
74
  if (attributes) {
@@ -85,15 +81,15 @@ const createFormBuilderStorageOperations = params => {
85
81
  /**
86
82
  * User defined plugins.
87
83
  */
88
- pluginsInput || [],
84
+ userPlugins || [],
89
85
  /**
90
86
  * Elasticsearch field definitions for the submission record.
91
87
  */
92
- (0, _elasticsearchFields.default)(),
88
+ (0, _elasticsearchFields2.default)(),
93
89
  /**
94
90
  * Elasticsearch field definitions for the form record.
95
91
  */
96
- (0, _elasticsearchFields2.default)(),
92
+ (0, _elasticsearchFields.default)(),
97
93
  /**
98
94
  * DynamoDB filter plugins for the where conditions.
99
95
  */
@@ -101,7 +97,11 @@ const createFormBuilderStorageOperations = params => {
101
97
  /**
102
98
  * Elasticsearch operators.
103
99
  */
104
- (0, _operators.getElasticsearchOperators)()]);
100
+ (0, _operators.getElasticsearchOperators)(),
101
+ /**
102
+ * Built-in Elasticsearch index plugins
103
+ */
104
+ (0, _indices.elasticsearchIndexPlugins)()]);
105
105
  const table = (0, _table.createTable)({
106
106
  tableName,
107
107
  documentClient
@@ -117,22 +117,22 @@ const createFormBuilderStorageOperations = params => {
117
117
  form: (0, _form.createFormEntity)({
118
118
  entityName: _types.ENTITIES.FORM,
119
119
  table,
120
- attributes: attributes[_types.ENTITIES.FORM]
120
+ attributes: attributes ? attributes[_types.ENTITIES.FORM] : {}
121
121
  }),
122
122
  submission: (0, _submission.createSubmissionEntity)({
123
123
  entityName: _types.ENTITIES.SUBMISSION,
124
124
  table,
125
- attributes: attributes[_types.ENTITIES.SUBMISSION]
125
+ attributes: attributes ? attributes[_types.ENTITIES.SUBMISSION] : {}
126
126
  }),
127
127
  system: (0, _system.createSystemEntity)({
128
128
  entityName: _types.ENTITIES.SYSTEM,
129
129
  table,
130
- attributes: attributes[_types.ENTITIES.SYSTEM]
130
+ attributes: attributes ? attributes[_types.ENTITIES.SYSTEM] : {}
131
131
  }),
132
132
  settings: (0, _settings.createSettingsEntity)({
133
133
  entityName: _types.ENTITIES.SETTINGS,
134
134
  table,
135
- attributes: attributes[_types.ENTITIES.SETTINGS]
135
+ attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
136
136
  }),
137
137
 
138
138
  /**
@@ -141,26 +141,29 @@ const createFormBuilderStorageOperations = params => {
141
141
  esForm: (0, _elasticsearch.createElasticsearchEntity)({
142
142
  entityName: _types.ENTITIES.ES_FORM,
143
143
  table: esTable,
144
- attributes: attributes[_types.ENTITIES.ES_FORM]
144
+ attributes: attributes ? attributes[_types.ENTITIES.ES_FORM] : {}
145
145
  }),
146
146
  esSubmission: (0, _elasticsearch.createElasticsearchEntity)({
147
147
  entityName: _types.ENTITIES.ES_SUBMISSION,
148
148
  table: esTable,
149
- attributes: attributes[_types.ENTITIES.ES_SUBMISSION]
149
+ attributes: attributes ? attributes[_types.ENTITIES.ES_SUBMISSION] : {}
150
150
  })
151
151
  };
152
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread({
153
- init: async formBuilder => {
154
- formBuilder.onAfterInstall.subscribe(async ({
152
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({
153
+ init: async context => {
154
+ context.i18n.locales.onLocaleBeforeCreate.subscribe(async ({
155
+ locale,
155
156
  tenant
156
157
  }) => {
157
158
  await (0, _createElasticsearchIndex.createElasticsearchIndex)({
158
159
  elasticsearch,
159
- tenant
160
+ plugins,
161
+ tenant,
162
+ locale: locale.code
160
163
  });
161
164
  });
162
165
  },
163
- upgrade: (0, _.default)(),
166
+ upgrade: null,
164
167
  getTable: () => table,
165
168
  getEsTable: () => esTable,
166
169
  getEntities: () => entities
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["reservedFields","isReserved","name","includes","WebinyError","createFormBuilderStorageOperations","params","attributes","table","tableName","esTable","esTableName","documentClient","elasticsearch","plugins","userPlugins","Object","values","forEach","attrs","keys","PluginsContainer","submissionElasticsearchFields","formElasticsearchFields","dynamoDbValueFilters","getElasticsearchOperators","elasticsearchIndexPlugins","createTable","createElasticsearchTable","entities","form","createFormEntity","entityName","ENTITIES","FORM","submission","createSubmissionEntity","SUBMISSION","system","createSystemEntity","SYSTEM","settings","createSettingsEntity","SETTINGS","esForm","createElasticsearchEntity","ES_FORM","esSubmission","ES_SUBMISSION","init","context","i18n","locales","onLocaleBeforeCreate","subscribe","locale","tenant","createElasticsearchIndex","code","upgrade","getTable","getEsTable","getEntities","createSystemStorageOperations","entity","createSettingsStorageOperations","createFormStorageOperations","esEntity","createSubmissionStorageOperations"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport formElasticsearchFields from \"./operations/form/elasticsearchFields\";\nimport submissionElasticsearchFields from \"./operations/submission/elasticsearchFields\";\nimport WebinyError from \"@webiny/error\";\nimport { FormBuilderStorageOperationsFactory, ENTITIES } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createFormEntity } from \"~/definitions/form\";\nimport { createSubmissionEntity } from \"~/definitions/submission\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createSystemStorageOperations } from \"~/operations/system\";\nimport { createSubmissionStorageOperations } from \"~/operations/submission\";\nimport { createSettingsStorageOperations } from \"~/operations/settings\";\nimport { createFormStorageOperations } from \"~/operations/form\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createElasticsearchEntity } from \"~/definitions/elasticsearch\";\nimport { getElasticsearchOperators } from \"@webiny/api-elasticsearch/operators\";\nimport { elasticsearchIndexPlugins } from \"~/elasticsearch/indices\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\n\nconst reservedFields = [\"PK\", \"SK\", \"index\", \"data\", \"TYPE\", \"__type\", \"GSI1_PK\", \"GSI1_SK\"];\n\nconst isReserved = (name: string): void => {\n if (reservedFields.includes(name) === false) {\n return;\n }\n throw new WebinyError(`Attribute name \"${name}\" is not allowed.`, \"ATTRIBUTE_NOT_ALLOWED\", {\n name\n });\n};\n\nexport const createFormBuilderStorageOperations: FormBuilderStorageOperationsFactory = params => {\n const {\n attributes,\n table: tableName,\n esTable: esTableName,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = params;\n\n if (attributes) {\n Object.values(attributes).forEach(attrs => {\n Object.keys(attrs).forEach(isReserved);\n });\n }\n\n const plugins = new PluginsContainer([\n /**\n * User defined plugins.\n */\n userPlugins || [],\n /**\n * Elasticsearch field definitions for the submission record.\n */\n submissionElasticsearchFields(),\n /**\n * Elasticsearch field definitions for the form record.\n */\n formElasticsearchFields(),\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Elasticsearch operators.\n */\n getElasticsearchOperators(),\n /**\n * Built-in Elasticsearch index plugins\n */\n elasticsearchIndexPlugins()\n ]);\n\n const table = createTable({\n tableName,\n documentClient\n });\n\n const esTable = createElasticsearchTable({\n tableName: esTableName,\n documentClient\n });\n\n const entities = {\n /**\n * Regular entities.\n */\n form: createFormEntity({\n entityName: ENTITIES.FORM,\n table,\n attributes: attributes ? attributes[ENTITIES.FORM] : {}\n }),\n submission: createSubmissionEntity({\n entityName: ENTITIES.SUBMISSION,\n table,\n attributes: attributes ? attributes[ENTITIES.SUBMISSION] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n /**\n * Elasticsearch entities.\n */\n esForm: createElasticsearchEntity({\n entityName: ENTITIES.ES_FORM,\n table: esTable,\n attributes: attributes ? attributes[ENTITIES.ES_FORM] : {}\n }),\n esSubmission: createElasticsearchEntity({\n entityName: ENTITIES.ES_SUBMISSION,\n table: esTable,\n attributes: attributes ? attributes[ENTITIES.ES_SUBMISSION] : {}\n })\n };\n\n return {\n init: async context => {\n context.i18n.locales.onLocaleBeforeCreate.subscribe(async ({ locale, tenant }) => {\n await createElasticsearchIndex({\n elasticsearch,\n plugins,\n tenant,\n locale: locale.code\n });\n });\n },\n upgrade: null,\n getTable: () => table,\n getEsTable: () => esTable,\n getEntities: () => entities,\n ...createSystemStorageOperations({\n table,\n entity: entities.system\n }),\n ...createSettingsStorageOperations({\n table,\n entity: entities.settings\n }),\n ...createFormStorageOperations({\n elasticsearch,\n table,\n entity: entities.form,\n esEntity: entities.esForm,\n plugins\n }),\n ...createSubmissionStorageOperations({\n elasticsearch,\n table,\n entity: entities.submission,\n esEntity: entities.esSubmission,\n plugins\n })\n };\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA,MAAMA,cAAc,GAAG,CAAC,IAAD,EAAO,IAAP,EAAa,OAAb,EAAsB,MAAtB,EAA8B,MAA9B,EAAsC,QAAtC,EAAgD,SAAhD,EAA2D,SAA3D,CAAvB;;AAEA,MAAMC,UAAU,GAAIC,IAAD,IAAwB;EACvC,IAAIF,cAAc,CAACG,QAAf,CAAwBD,IAAxB,MAAkC,KAAtC,EAA6C;IACzC;EACH;;EACD,MAAM,IAAIE,cAAJ,CAAiB,mBAAkBF,IAAK,mBAAxC,EAA4D,uBAA5D,EAAqF;IACvFA;EADuF,CAArF,CAAN;AAGH,CAPD;;AASO,MAAMG,kCAAuE,GAAGC,MAAM,IAAI;EAC7F,MAAM;IACFC,UADE;IAEFC,KAAK,EAAEC,SAFL;IAGFC,OAAO,EAAEC,WAHP;IAIFC,cAJE;IAKFC,aALE;IAMFC,OAAO,EAAEC;EANP,IAOFT,MAPJ;;EASA,IAAIC,UAAJ,EAAgB;IACZS,MAAM,CAACC,MAAP,CAAcV,UAAd,EAA0BW,OAA1B,CAAkCC,KAAK,IAAI;MACvCH,MAAM,CAACI,IAAP,CAAYD,KAAZ,EAAmBD,OAAnB,CAA2BjB,UAA3B;IACH,CAFD;EAGH;;EAED,MAAMa,OAAO,GAAG,IAAIO,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AA4B;IAC3BrD,aAD2B;IAE3BL,KAF2B;IAG3BwD,MAAM,EAAEnC,QAAQ,CAACC,IAHU;IAI3BqC,QAAQ,EAAEtC,QAAQ,CAACe,MAJQ;IAK3B9B;EAL2B,CAA5B,CAvBP,GA8BO,IAAAsD,8CAAA,EAAkC;IACjCvD,aADiC;IAEjCL,KAFiC;IAGjCwD,MAAM,EAAEnC,QAAQ,CAACM,UAHgB;IAIjCgC,QAAQ,EAAEtC,QAAQ,CAACkB,YAJc;IAKjCjC;EALiC,CAAlC,CA9BP;AAsCH,CAlIM"}
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.createFormElasticType = exports.createElasticsearchBody = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
12
12
  var _cursors = require("@webiny/api-elasticsearch/cursors");
13
13
 
@@ -15,8 +15,6 @@ var _sort = require("@webiny/api-elasticsearch/sort");
15
15
 
16
16
  var _limit = require("@webiny/api-elasticsearch/limit");
17
17
 
18
- var _ElasticsearchQueryBuilderOperatorPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin");
19
-
20
18
  var _FormElasticsearchFieldPlugin = require("../../plugins/FormElasticsearchFieldPlugin");
21
19
 
22
20
  var _FormElasticsearchSortModifierPlugin = require("../../plugins/FormElasticsearchSortModifierPlugin");
@@ -27,9 +25,7 @@ var _FormElasticsearchQueryModifierPlugin = require("../../plugins/FormElasticse
27
25
 
28
26
  var _where = require("@webiny/api-elasticsearch/where");
29
27
 
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; }
28
+ var _operators = require("@webiny/api-elasticsearch/operators");
33
29
 
34
30
  const createFormElasticType = () => {
35
31
  return "fb.form";
@@ -65,12 +61,8 @@ const createElasticsearchQuery = params => {
65
61
  * Be aware that, if having more registered operator plugins of same type, the last one will be used.
66
62
  */
67
63
 
68
- const operatorPlugins = plugins.byType(_ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((acc, plugin) => {
69
- acc[plugin.getOperator()] = plugin;
70
- return acc;
71
- }, {});
72
-
73
- const where = _objectSpread({}, initialWhere);
64
+ const operatorPlugins = (0, _operators.getElasticsearchOperatorPluginsByLocale)(plugins, initialWhere.locale);
65
+ const where = (0, _objectSpread2.default)({}, initialWhere);
74
66
  /**
75
67
  * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.
76
68
  *
@@ -78,10 +70,9 @@ const createElasticsearchQuery = params => {
78
70
  * No need for the tenant filtering otherwise as each index is for single tenant.
79
71
  */
80
72
 
81
-
82
73
  const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
83
74
 
84
- if (sharedIndex) {
75
+ if (sharedIndex && where.tenant) {
85
76
  query.must.push({
86
77
  term: {
87
78
  "tenant.keyword": where.tenant
@@ -131,7 +122,7 @@ const createElasticsearchBody = params => {
131
122
  return acc;
132
123
  }, {});
133
124
  const limit = (0, _limit.createLimit)(initialLimit, 100);
134
- const query = createElasticsearchQuery(_objectSpread(_objectSpread({}, params), {}, {
125
+ const query = createElasticsearchQuery((0, _objectSpread2.default)((0, _objectSpread2.default)({}, params), {}, {
135
126
  fieldPlugins
136
127
  }));
137
128
  const sort = (0, _sort.createSort)({
@@ -159,7 +150,7 @@ const createElasticsearchBody = params => {
159
150
  query: {
160
151
  constant_score: {
161
152
  filter: {
162
- bool: _objectSpread({}, query)
153
+ bool: (0, _objectSpread2.default)({}, query)
163
154
  }
164
155
  }
165
156
  },
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createFormElasticType","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","decodeCursor","bodyModifiers","FormElasticsearchBodyModifierPlugin","modifyBody"],"sources":["elasticsearchBody.ts"],"sourcesContent":["import { SearchBody as esSearchBody } from \"elastic-ts\";\nimport { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { ElasticsearchBoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createLimit } from \"@webiny/api-elasticsearch/limit\";\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\";\nimport { applyWhere } from \"@webiny/api-elasticsearch/where\";\nimport { getElasticsearchOperatorPluginsByLocale } from \"@webiny/api-elasticsearch/operators\";\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;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AAEO,MAAMA,qBAAqB,GAAG,MAAc;EAC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;IAWT;AACR;AACA;AACA;AACA;IACQwB,YAAY,EAAE,IAAAC,qBAAA,EAAarB,KAAb,CAhBL;IAiBTF;EAjBS,CAAb;EAoBA,MAAMwB,aAAa,GAAG5C,OAAO,CAACuB,MAAR,CAClBsB,wEAAA,CAAoCpB,IADlB,CAAtB;;EAIA,KAAK,MAAMG,MAAX,IAAqBgB,aAArB,EAAoC;IAChChB,MAAM,CAACkB,UAAP,CAAkB;MACdR;IADc,CAAlB;EAGH;;EAED,OAAOA,IAAP;AACH,CA1EM"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FormElasticsearchFieldPlugin","field","unmappedType","path","ALL"],"sources":["elasticsearchFields.ts"],"sourcesContent":["import { FormElasticsearchFieldPlugin } from \"~/plugins/FormElasticsearchFieldPlugin\";\n\nexport default () => [\n new FormElasticsearchFieldPlugin({\n field: \"createdOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"savedOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"publishedOn\",\n unmappedType: \"date\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"ownedBy\",\n path: \"ownedBy.id\"\n }),\n new FormElasticsearchFieldPlugin({\n field: \"createdBy\",\n path: \"createdBy.id\"\n }),\n /**\n * Always add the ALL fields plugin because of the keyword/path build.\n */\n new FormElasticsearchFieldPlugin({\n field: FormElasticsearchFieldPlugin.ALL\n })\n];\n"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,WADsB;EAE7BC,YAAY,EAAE;AAFe,CAAjC,CADiB,EAKjB,IAAIF,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,SADsB;EAE7BC,YAAY,EAAE;AAFe,CAAjC,CALiB,EASjB,IAAIF,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,aADsB;EAE7BC,YAAY,EAAE;AAFe,CAAjC,CATiB,EAajB,IAAIF,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,SADsB;EAE7BE,IAAI,EAAE;AAFuB,CAAjC,CAbiB,EAiBjB,IAAIH,0DAAJ,CAAiC;EAC7BC,KAAK,EAAE,WADsB;EAE7BE,IAAI,EAAE;AAFuB,CAAjC,CAjBiB;AAqBjB;AACJ;AACA;AACI,IAAIH,0DAAJ,CAAiC;EAC7BC,KAAK,EAAED,0DAAA,CAA6BI;AADP,CAAjC,CAxBiB,C"}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FormDynamoDbFieldPlugin","field","type"],"sources":["fields.ts"],"sourcesContent":["import { FormDynamoDbFieldPlugin } from \"~/plugins/FormDynamoDbFieldPlugin\";\n\nexport default () => [\n new FormDynamoDbFieldPlugin({\n field: \"publishedOn\",\n type: \"date\"\n })\n];\n"],"mappings":";;;;;;;AAAA;;eAEe,MAAM,CACjB,IAAIA,gDAAJ,CAA4B;EACxBC,KAAK,EAAE,aADiB;EAExBC,IAAI,EAAE;AAFkB,CAA5B,CADiB,C"}
@@ -7,11 +7,11 @@ export declare type DbRecord<T = any> = T & {
7
7
  SK: string;
8
8
  TYPE: string;
9
9
  };
10
- export interface Params {
10
+ export interface CreateFormStorageOperationsParams {
11
11
  entity: Entity<any>;
12
12
  esEntity: Entity<any>;
13
13
  table: Table;
14
14
  elasticsearch: Client;
15
15
  plugins: PluginsContainer;
16
16
  }
17
- export declare const createFormStorageOperations: (params: Params) => FormBuilderFormStorageOperations;
17
+ export declare const createFormStorageOperations: (params: CreateFormStorageOperationsParams) => FormBuilderFormStorageOperations;
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.createFormStorageOperations = void 0;
9
9
 
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
11
11
 
12
12
  var _query = require("@webiny/db-dynamodb/utils/query");
13
13
 
@@ -17,7 +17,7 @@ var _cleanup = require("@webiny/db-dynamodb/utils/cleanup");
17
17
 
18
18
  var _batchWrite = require("@webiny/db-dynamodb/utils/batchWrite");
19
19
 
20
- var _configurations = _interopRequireDefault(require("../../configurations"));
20
+ var _configurations = require("../../configurations");
21
21
 
22
22
  var _filter = require("@webiny/db-dynamodb/utils/filter");
23
23
 
@@ -31,10 +31,6 @@ var _elasticsearchBody = require("./elasticsearchBody");
31
31
 
32
32
  var _cursors = require("@webiny/api-elasticsearch/cursors");
33
33
 
34
- 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; }
35
-
36
- 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; }
37
-
38
34
  const getESDataForLatestRevision = form => ({
39
35
  __type: (0, _elasticsearchBody.createFormElasticType)(),
40
36
  id: form.id,
@@ -114,9 +110,9 @@ const createFormStorageOperations = params => {
114
110
  PK: createFormPartitionKey(form),
115
111
  SK: createLatestSortKey()
116
112
  };
117
- const items = [entity.putBatch(_objectSpread(_objectSpread({}, form), {}, {
113
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
118
114
  TYPE: createFormType()
119
- }, revisionKeys)), entity.putBatch(_objectSpread(_objectSpread({}, form), {}, {
115
+ }, revisionKeys)), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
120
116
  TYPE: createFormLatestType()
121
117
  }, latestKeys))];
122
118
 
@@ -136,11 +132,12 @@ const createFormStorageOperations = params => {
136
132
  try {
137
133
  const {
138
134
  index
139
- } = _configurations.default.es({
140
- tenant: form.tenant
135
+ } = _configurations.configurations.es({
136
+ tenant: form.tenant,
137
+ locale: form.locale
141
138
  });
142
139
 
143
- await esEntity.put(_objectSpread({
140
+ await esEntity.put((0, _objectSpread2.default)({
144
141
  index,
145
142
  data: getESDataForLatestRevision(form),
146
143
  TYPE: createFormType()
@@ -169,9 +166,9 @@ const createFormStorageOperations = params => {
169
166
  PK: createFormPartitionKey(form),
170
167
  SK: createLatestSortKey()
171
168
  };
172
- const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, form), revisionKeys), {}, {
169
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
173
170
  TYPE: createFormType()
174
- })), entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, form), latestKeys), {}, {
171
+ })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
175
172
  TYPE: createFormLatestType()
176
173
  }))];
177
174
 
@@ -193,11 +190,12 @@ const createFormStorageOperations = params => {
193
190
  try {
194
191
  const {
195
192
  index
196
- } = _configurations.default.es({
197
- tenant: form.tenant
193
+ } = _configurations.configurations.es({
194
+ tenant: form.tenant,
195
+ locale: form.locale
198
196
  });
199
197
 
200
- await esEntity.put(_objectSpread({
198
+ await esEntity.put((0, _objectSpread2.default)({
201
199
  index,
202
200
  data: getESDataForLatestRevision(form),
203
201
  TYPE: createFormLatestType()
@@ -241,12 +239,12 @@ const createFormStorageOperations = params => {
241
239
  }
242
240
  });
243
241
  const isLatestForm = latestForm ? latestForm.id === form.id : false;
244
- const items = [entity.putBatch(_objectSpread(_objectSpread({}, form), {}, {
242
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
245
243
  TYPE: createFormType()
246
244
  }, revisionKeys))];
247
245
 
248
246
  if (isLatestForm) {
249
- items.push(entity.putBatch(_objectSpread(_objectSpread({}, form), {}, {
247
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), {}, {
250
248
  TYPE: createFormLatestType()
251
249
  }, latestKeys)));
252
250
  }
@@ -277,11 +275,12 @@ const createFormStorageOperations = params => {
277
275
  try {
278
276
  const {
279
277
  index
280
- } = _configurations.default.es({
281
- tenant: form.tenant
278
+ } = _configurations.configurations.es({
279
+ tenant: form.tenant,
280
+ locale: form.locale
282
281
  });
283
282
 
284
- await esEntity.put(_objectSpread({
283
+ await esEntity.put((0, _objectSpread2.default)({
285
284
  index,
286
285
  data: getESDataForLatestRevision(form),
287
286
  TYPE: createFormLatestType()
@@ -372,14 +371,14 @@ const createFormStorageOperations = params => {
372
371
  after: (0, _cursors.decodeCursor)(after)
373
372
  });
374
373
 
375
- const esConfig = _configurations.default.es({
376
- tenant: where.tenant
374
+ const esConfig = _configurations.configurations.es({
375
+ tenant: where.tenant,
376
+ locale: where.locale
377
377
  });
378
378
 
379
- const query = _objectSpread(_objectSpread({}, esConfig), {}, {
379
+ const query = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, esConfig), {}, {
380
380
  body
381
381
  });
382
-
383
382
  let response;
384
383
 
385
384
  try {
@@ -413,7 +412,7 @@ const createFormStorageOperations = params => {
413
412
  const meta = {
414
413
  hasMoreItems,
415
414
  totalCount: total.value,
416
- cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) : null
415
+ cursor: items.length > 0 ? (0, _cursors.encodeCursor)(hits[items.length - 1].sort) || null : null
417
416
  };
418
417
  return {
419
418
  items,
@@ -454,11 +453,10 @@ const createFormStorageOperations = params => {
454
453
  });
455
454
  }
456
455
 
457
- const where = _objectSpread(_objectSpread({}, initialWhere), {}, {
456
+ const where = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, initialWhere), {}, {
458
457
  id: undefined,
459
458
  formId: undefined
460
459
  });
461
-
462
460
  const filteredItems = (0, _filter.filterItems)({
463
461
  plugins,
464
462
  items,
@@ -466,7 +464,7 @@ const createFormStorageOperations = params => {
466
464
  fields: formDynamoDbFields
467
465
  });
468
466
 
469
- if (Array.isArray(sort) === false || sort.length === 0) {
467
+ if (!sort || sort.length === 0) {
470
468
  return filteredItems;
471
469
  }
472
470
 
@@ -573,14 +571,14 @@ const createFormStorageOperations = params => {
573
571
  }).shift();
574
572
 
575
573
  if (previouslyPublishedForm) {
576
- items.push(entity.putBatch(_objectSpread(_objectSpread({}, previouslyPublishedForm), {}, {
574
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedForm), {}, {
577
575
  PK: createFormPartitionKey(previouslyPublishedForm),
578
576
  SK: createLatestPublishedSortKey(),
579
577
  TYPE: createFormLatestPublishedType()
580
578
  })));
581
579
  } else {
582
580
  items.push(entity.deleteBatch({
583
- PK: createFormPartitionKey(previouslyPublishedForm),
581
+ PK: createFormPartitionKey(form),
584
582
  SK: createLatestPublishedSortKey()
585
583
  }));
586
584
  }
@@ -590,18 +588,19 @@ const createFormStorageOperations = params => {
590
588
  */
591
589
 
592
590
 
593
- if (isLatest) {
594
- items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, previous), latestKeys), {}, {
591
+ if (isLatest && previous) {
592
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previous), latestKeys), {}, {
595
593
  TYPE: createFormLatestType()
596
594
  })));
597
595
 
598
596
  const {
599
597
  index
600
- } = _configurations.default.es({
601
- tenant: previous.tenant
598
+ } = _configurations.configurations.es({
599
+ tenant: previous.tenant,
600
+ locale: previous.locale
602
601
  });
603
602
 
604
- esDataItem = _objectSpread(_objectSpread({
603
+ esDataItem = (0, _objectSpread2.default)((0, _objectSpread2.default)({
605
604
  index
606
605
  }, latestKeys), {}, {
607
606
  data: getESDataForLatestRevision(previous)
@@ -691,9 +690,9 @@ const createFormStorageOperations = params => {
691
690
  * Update revision and latest published records
692
691
  */
693
692
 
694
- const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, form), revisionKeys), {}, {
693
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
695
694
  TYPE: createFormType()
696
- })), entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, form), latestPublishedKeys), {}, {
695
+ })), entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestPublishedKeys), {}, {
697
696
  TYPE: createFormLatestPublishedType()
698
697
  }))];
699
698
  /**
@@ -701,7 +700,7 @@ const createFormStorageOperations = params => {
701
700
  */
702
701
 
703
702
  if (isLatestForm) {
704
- items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, form), latestKeys), {}, {
703
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), latestKeys), {}, {
705
704
  TYPE: createFormLatestType()
706
705
  })));
707
706
  }
@@ -728,14 +727,15 @@ const createFormStorageOperations = params => {
728
727
 
729
728
  const {
730
729
  index
731
- } = _configurations.default.es({
732
- tenant: form.tenant
730
+ } = _configurations.configurations.es({
731
+ tenant: form.tenant,
732
+ locale: form.locale
733
733
  });
734
734
 
735
735
  const esData = getESDataForLatestRevision(form);
736
736
 
737
737
  try {
738
- await esEntity.put(_objectSpread(_objectSpread({}, latestKeys), {}, {
738
+ await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
739
739
  index,
740
740
  TYPE: createFormLatestType(),
741
741
  data: esData
@@ -800,7 +800,7 @@ const createFormStorageOperations = params => {
800
800
  });
801
801
  const isLatest = latestForm ? latestForm.id === form.id : false;
802
802
  const isLatestPublished = latestPublishedForm ? latestPublishedForm.id === form.id : false;
803
- const items = [entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, form), revisionKeys), {}, {
803
+ const items = [entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, form), revisionKeys), {}, {
804
804
  TYPE: createFormType()
805
805
  }))];
806
806
  let esData = undefined;
@@ -828,7 +828,7 @@ const createFormStorageOperations = params => {
828
828
  const previouslyPublishedRevision = revisions.shift();
829
829
 
830
830
  if (previouslyPublishedRevision) {
831
- items.push(entity.putBatch(_objectSpread(_objectSpread(_objectSpread({}, previouslyPublishedRevision), latestPublishedKeys), {}, {
831
+ items.push(entity.putBatch((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, previouslyPublishedRevision), latestPublishedKeys), {}, {
832
832
  TYPE: createFormLatestPublishedType()
833
833
  })));
834
834
  } else {
@@ -862,12 +862,13 @@ const createFormStorageOperations = params => {
862
862
 
863
863
  const {
864
864
  index
865
- } = _configurations.default.es({
866
- tenant: form.tenant
865
+ } = _configurations.configurations.es({
866
+ tenant: form.tenant,
867
+ locale: form.locale
867
868
  });
868
869
 
869
870
  try {
870
- await esEntity.put(_objectSpread(_objectSpread({}, latestKeys), {}, {
871
+ await esEntity.put((0, _objectSpread2.default)((0, _objectSpread2.default)({}, latestKeys), {}, {
871
872
  index,
872
873
  TYPE: createFormLatestType(),
873
874
  data: esData