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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/configurations.d.ts +16 -7
  2. package/configurations.js +38 -13
  3. package/configurations.js.map +1 -0
  4. package/definitions/elasticsearch.d.ts +47 -5
  5. package/definitions/elasticsearch.js +8 -16
  6. package/definitions/elasticsearch.js.map +1 -0
  7. package/definitions/form.d.ts +6 -4
  8. package/definitions/form.js +9 -17
  9. package/definitions/form.js.map +1 -0
  10. package/definitions/settings.d.ts +6 -4
  11. package/definitions/settings.js +8 -16
  12. package/definitions/settings.js.map +1 -0
  13. package/definitions/submission.d.ts +6 -4
  14. package/definitions/submission.js +8 -16
  15. package/definitions/submission.js.map +1 -0
  16. package/definitions/system.d.ts +6 -4
  17. package/definitions/system.js +8 -16
  18. package/definitions/system.js.map +1 -0
  19. package/definitions/table.d.ts +7 -6
  20. package/definitions/table.js +7 -6
  21. package/definitions/table.js.map +1 -0
  22. package/definitions/tableElasticsearch.d.ts +6 -5
  23. package/definitions/tableElasticsearch.js +7 -6
  24. package/definitions/tableElasticsearch.js.map +1 -0
  25. package/elasticsearch/createElasticsearchIndex.d.ts +10 -0
  26. package/elasticsearch/createElasticsearchIndex.js +41 -0
  27. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  28. package/elasticsearch/indices/base.d.ts +2 -0
  29. package/elasticsearch/indices/base.js +13 -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 +14 -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 +14 -0
  36. package/elasticsearch/indices/japanese.js.map +1 -0
  37. package/index.d.ts +2 -1
  38. package/index.js +100 -81
  39. package/index.js.map +1 -0
  40. package/operations/form/elasticsearchBody.d.ts +4 -4
  41. package/operations/form/elasticsearchBody.js +19 -63
  42. package/operations/form/elasticsearchBody.js.map +1 -0
  43. package/operations/form/elasticsearchFields.js +2 -3
  44. package/operations/form/elasticsearchFields.js.map +1 -0
  45. package/operations/form/fields.js +2 -3
  46. package/operations/form/fields.js.map +1 -0
  47. package/operations/form/index.d.ts +8 -8
  48. package/operations/form/index.js +196 -243
  49. package/operations/form/index.js.map +1 -0
  50. package/operations/settings/index.d.ts +5 -5
  51. package/operations/settings/index.js +26 -35
  52. package/operations/settings/index.js.map +1 -0
  53. package/operations/submission/elasticsearchBody.d.ts +4 -4
  54. package/operations/submission/elasticsearchBody.js +22 -61
  55. package/operations/submission/elasticsearchBody.js.map +1 -0
  56. package/operations/submission/elasticsearchFields.js +2 -3
  57. package/operations/submission/elasticsearchFields.js.map +1 -0
  58. package/operations/submission/index.d.ts +7 -7
  59. package/operations/submission/index.js +68 -96
  60. package/operations/submission/index.js.map +1 -0
  61. package/operations/system/index.d.ts +5 -5
  62. package/operations/system/index.js +22 -32
  63. package/operations/system/index.js.map +1 -0
  64. package/package.json +28 -35
  65. package/plugins/FormDynamoDbFieldPlugin.js +5 -9
  66. package/plugins/FormDynamoDbFieldPlugin.js.map +1 -0
  67. package/plugins/FormElasticsearchBodyModifierPlugin.d.ts +1 -1
  68. package/plugins/FormElasticsearchBodyModifierPlugin.js +6 -10
  69. package/plugins/FormElasticsearchBodyModifierPlugin.js.map +1 -0
  70. package/plugins/FormElasticsearchFieldPlugin.d.ts +1 -1
  71. package/plugins/FormElasticsearchFieldPlugin.js +6 -10
  72. package/plugins/FormElasticsearchFieldPlugin.js.map +1 -0
  73. package/plugins/FormElasticsearchIndexPlugin.d.ts +4 -0
  74. package/plugins/FormElasticsearchIndexPlugin.js +13 -0
  75. package/plugins/FormElasticsearchIndexPlugin.js.map +1 -0
  76. package/plugins/FormElasticsearchQueryModifierPlugin.d.ts +1 -1
  77. package/plugins/FormElasticsearchQueryModifierPlugin.js +6 -10
  78. package/plugins/FormElasticsearchQueryModifierPlugin.js.map +1 -0
  79. package/plugins/FormElasticsearchSortModifierPlugin.d.ts +1 -1
  80. package/plugins/FormElasticsearchSortModifierPlugin.js +6 -10
  81. package/plugins/FormElasticsearchSortModifierPlugin.js.map +1 -0
  82. package/plugins/SubmissionElasticsearchBodyModifierPlugin.d.ts +1 -1
  83. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js +6 -10
  84. package/plugins/SubmissionElasticsearchBodyModifierPlugin.js.map +1 -0
  85. package/plugins/SubmissionElasticsearchFieldPlugin.d.ts +1 -1
  86. package/plugins/SubmissionElasticsearchFieldPlugin.js +6 -10
  87. package/plugins/SubmissionElasticsearchFieldPlugin.js.map +1 -0
  88. package/plugins/SubmissionElasticsearchQueryModifierPlugin.d.ts +1 -1
  89. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js +6 -10
  90. package/plugins/SubmissionElasticsearchQueryModifierPlugin.js.map +1 -0
  91. package/plugins/SubmissionElasticsearchSortModifierPlugin.d.ts +1 -1
  92. package/plugins/SubmissionElasticsearchSortModifierPlugin.js +6 -10
  93. package/plugins/SubmissionElasticsearchSortModifierPlugin.js.map +1 -0
  94. package/plugins/index.d.ts +10 -0
  95. package/plugins/index.js +117 -0
  96. package/plugins/index.js.map +1 -0
  97. package/tasks/createIndexTaskPlugin.d.ts +2 -0
  98. package/tasks/createIndexTaskPlugin.js +36 -0
  99. package/tasks/createIndexTaskPlugin.js.map +1 -0
  100. package/types.d.ts +17 -15
  101. package/types.js +6 -6
  102. package/types.js.map +1 -0
  103. package/operations/system/createElasticsearchIndex.d.ts +0 -6
  104. package/operations/system/createElasticsearchIndex.js +0 -70
  105. package/upgrades/5.16.0/index.d.ts +0 -8
  106. package/upgrades/5.16.0/index.js +0 -141
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createElasticsearchIndex = void 0;
7
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
8
+ var _FormElasticsearchIndexPlugin = require("../plugins/FormElasticsearchIndexPlugin");
9
+ var _configurations = require("../configurations");
10
+ const createElasticsearchIndex = async params => {
11
+ const {
12
+ elasticsearch,
13
+ plugins,
14
+ locale,
15
+ tenant
16
+ } = params;
17
+ const {
18
+ index
19
+ } = _configurations.configurations.es({
20
+ locale,
21
+ tenant
22
+ });
23
+ await (0, _apiElasticsearch.createIndex)({
24
+ client: elasticsearch,
25
+ index,
26
+ type: _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin.type,
27
+ tenant,
28
+ locale,
29
+ plugins,
30
+ onExists: () => {
31
+ console.log(`Elasticsearch index "${index}" for the Form Builder already exists.`);
32
+ },
33
+ onError: ex => {
34
+ console.error(`Could not create the Form Builder Elasticsearch index "${index}".`, ex);
35
+ return ex;
36
+ }
37
+ });
38
+ };
39
+ exports.createElasticsearchIndex = createElasticsearchIndex;
40
+
41
+ //# sourceMappingURL=createElasticsearchIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_apiElasticsearch","require","_FormElasticsearchIndexPlugin","_configurations","createElasticsearchIndex","params","elasticsearch","plugins","locale","tenant","index","configurations","es","createIndex","client","type","FormElasticsearchIndexPlugin","onExists","console","log","onError","ex","error","exports"],"sources":["createElasticsearchIndex.ts"],"sourcesContent":["import type { Client } from \"@elastic/elasticsearch\";\nimport { createIndex } from \"@webiny/api-elasticsearch\";\nimport { FormElasticsearchIndexPlugin } from \"~/plugins/FormElasticsearchIndexPlugin\";\nimport type { PluginsContainer } from \"@webiny/plugins\";\nimport { configurations } from \"~/configurations\";\n\ninterface CreateElasticsearchIndexParams {\n elasticsearch: Client;\n plugins: PluginsContainer;\n tenant: string;\n locale: string;\n}\n\nexport const createElasticsearchIndex = async (params: CreateElasticsearchIndexParams) => {\n const { elasticsearch, plugins, locale, tenant } = params;\n\n const { index } = configurations.es({\n locale,\n tenant\n });\n\n await createIndex({\n client: elasticsearch,\n index,\n type: FormElasticsearchIndexPlugin.type,\n tenant,\n locale,\n plugins,\n onExists: () => {\n console.log(`Elasticsearch index \"${index}\" for the Form Builder already exists.`);\n },\n onError: (ex: Error) => {\n console.error(`Could not create the Form Builder Elasticsearch index \"${index}\".`, ex);\n return ex;\n }\n });\n};\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,6BAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AASO,MAAMG,wBAAwB,GAAG,MAAOC,MAAsC,IAAK;EACtF,MAAM;IAAEC,aAAa;IAAEC,OAAO;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGJ,MAAM;EAEzD,MAAM;IAAEK;EAAM,CAAC,GAAGC,8BAAc,CAACC,EAAE,CAAC;IAChCJ,MAAM;IACNC;EACJ,CAAC,CAAC;EAEF,MAAM,IAAAI,6BAAW,EAAC;IACdC,MAAM,EAAER,aAAa;IACrBI,KAAK;IACLK,IAAI,EAAEC,0DAA4B,CAACD,IAAI;IACvCN,MAAM;IACND,MAAM;IACND,OAAO;IACPU,QAAQ,EAAEA,CAAA,KAAM;MACZC,OAAO,CAACC,GAAG,CAAC,wBAAwBT,KAAK,wCAAwC,CAAC;IACtF,CAAC;IACDU,OAAO,EAAGC,EAAS,IAAK;MACpBH,OAAO,CAACI,KAAK,CAAC,0DAA0DZ,KAAK,IAAI,EAAEW,EAAE,CAAC;MACtF,OAAOA,EAAE;IACb;EACJ,CAAC,CAAC;AACN,CAAC;AAACE,OAAA,CAAAnB,wBAAA,GAAAA,wBAAA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import { FormElasticsearchIndexPlugin } from "../../plugins/FormElasticsearchIndexPlugin";
2
+ export declare const base: FormElasticsearchIndexPlugin;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.base = void 0;
7
+ var _FormElasticsearchIndexPlugin = require("../../plugins/FormElasticsearchIndexPlugin");
8
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
9
+ const base = exports.base = new _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin({
10
+ body: (0, _apiElasticsearch.getBaseConfiguration)()
11
+ });
12
+
13
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_FormElasticsearchIndexPlugin","require","_apiElasticsearch","base","exports","FormElasticsearchIndexPlugin","body","getBaseConfiguration"],"sources":["base.ts"],"sourcesContent":["import { FormElasticsearchIndexPlugin } from \"~/plugins/FormElasticsearchIndexPlugin\";\nimport { getBaseConfiguration } from \"@webiny/api-elasticsearch\";\n\nexport const base = new FormElasticsearchIndexPlugin({\n body: getBaseConfiguration()\n});\n"],"mappings":";;;;;;AAAA,IAAAA,6BAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAEO,MAAME,IAAI,GAAAC,OAAA,CAAAD,IAAA,GAAG,IAAIE,0DAA4B,CAAC;EACjDC,IAAI,EAAE,IAAAC,sCAAoB,EAAC;AAC/B,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export declare const elasticsearchIndexPlugins: () => import("../..").FormElasticsearchIndexPlugin[];
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.elasticsearchIndexPlugins = void 0;
7
+ var _base = require("./base");
8
+ var _japanese = require("./japanese");
9
+ const elasticsearchIndexPlugins = () => {
10
+ return [_base.base, _japanese.japanese];
11
+ };
12
+ exports.elasticsearchIndexPlugins = elasticsearchIndexPlugins;
13
+
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_base","require","_japanese","elasticsearchIndexPlugins","base","japanese","exports"],"sources":["index.ts"],"sourcesContent":["import { base } from \"./base\";\nimport { japanese } from \"./japanese\";\n\nexport const elasticsearchIndexPlugins = () => {\n return [base, japanese];\n};\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAEO,MAAME,yBAAyB,GAAGA,CAAA,KAAM;EAC3C,OAAO,CAACC,UAAI,EAAEC,kBAAQ,CAAC;AAC3B,CAAC;AAACC,OAAA,CAAAH,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import { FormElasticsearchIndexPlugin } from "../../plugins/FormElasticsearchIndexPlugin";
2
+ export declare const japanese: FormElasticsearchIndexPlugin;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.japanese = void 0;
7
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
8
+ var _FormElasticsearchIndexPlugin = require("../../plugins/FormElasticsearchIndexPlugin");
9
+ const japanese = exports.japanese = new _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin({
10
+ body: (0, _apiElasticsearch.getJapaneseConfiguration)(),
11
+ locales: ["ja", "ja-jp"]
12
+ });
13
+
14
+ //# sourceMappingURL=japanese.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_apiElasticsearch","require","_FormElasticsearchIndexPlugin","japanese","exports","FormElasticsearchIndexPlugin","body","getJapaneseConfiguration","locales"],"sources":["japanese.ts"],"sourcesContent":["import { getJapaneseConfiguration } from \"@webiny/api-elasticsearch\";\nimport { FormElasticsearchIndexPlugin } from \"~/plugins/FormElasticsearchIndexPlugin\";\n\nexport const japanese = new FormElasticsearchIndexPlugin({\n body: getJapaneseConfiguration(),\n locales: [\"ja\", \"ja-jp\"]\n});\n"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,6BAAA,GAAAD,OAAA;AAEO,MAAME,QAAQ,GAAAC,OAAA,CAAAD,QAAA,GAAG,IAAIE,0DAA4B,CAAC;EACrDC,IAAI,EAAE,IAAAC,0CAAwB,EAAC,CAAC;EAChCC,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO;AAC3B,CAAC,CAAC","ignoreList":[]}
package/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- import { FormBuilderStorageOperationsFactory } from "./types";
1
+ import type { FormBuilderStorageOperationsFactory } from "./types";
2
+ export * from "./plugins";
2
3
  export declare const createFormBuilderStorageOperations: FormBuilderStorageOperationsFactory;
package/index.js CHANGED
@@ -1,107 +1,91 @@
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
  });
7
+ var _exportNames = {
8
+ createFormBuilderStorageOperations: true
9
+ };
8
10
  exports.createFormBuilderStorageOperations = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _types = require("./types");
13
-
11
+ var _filters = _interopRequireDefault(require("@webiny/db-dynamodb/plugins/filters"));
12
+ var _elasticsearchFields = _interopRequireDefault(require("./operations/form/elasticsearchFields"));
13
+ var _elasticsearchFields2 = _interopRequireDefault(require("./operations/submission/elasticsearchFields"));
14
14
  var _error = _interopRequireDefault(require("@webiny/error"));
15
-
15
+ var _types = require("./types");
16
16
  var _table = require("./definitions/table");
17
-
18
17
  var _form = require("./definitions/form");
19
-
20
18
  var _submission = require("./definitions/submission");
21
-
22
19
  var _system = require("./definitions/system");
23
-
24
20
  var _settings = require("./definitions/settings");
25
-
26
21
  var _system2 = require("./operations/system");
27
-
28
22
  var _submission2 = require("./operations/submission");
29
-
30
23
  var _settings2 = require("./operations/settings");
31
-
32
24
  var _form2 = require("./operations/form");
33
-
34
- var _createElasticsearchIndex = require("./operations/system/createElasticsearchIndex");
35
-
36
25
  var _tableElasticsearch = require("./definitions/tableElasticsearch");
37
-
38
26
  var _plugins = require("@webiny/plugins");
39
-
40
27
  var _elasticsearch = require("./definitions/elasticsearch");
41
-
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
- var _operators = require("@webiny/api-elasticsearch/operators");
49
-
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; }
53
-
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; }
55
-
28
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
29
+ var _indices = require("./elasticsearch/indices");
30
+ var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
31
+ var _plugins2 = require("./plugins");
32
+ Object.keys(_plugins2).forEach(function (key) {
33
+ if (key === "default" || key === "__esModule") return;
34
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
35
+ if (key in exports && exports[key] === _plugins2[key]) return;
36
+ Object.defineProperty(exports, key, {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _plugins2[key];
40
+ }
41
+ });
42
+ });
43
+ var _createIndexTaskPlugin = require("./tasks/createIndexTaskPlugin");
44
+ var _api = require("@webiny/api");
56
45
  const reservedFields = ["PK", "SK", "index", "data", "TYPE", "__type", "GSI1_PK", "GSI1_SK"];
57
-
58
46
  const isReserved = name => {
59
47
  if (reservedFields.includes(name) === false) {
60
48
  return;
61
49
  }
62
-
63
50
  throw new _error.default(`Attribute name "${name}" is not allowed.`, "ATTRIBUTE_NOT_ALLOWED", {
64
51
  name
65
52
  });
66
53
  };
67
-
68
54
  const createFormBuilderStorageOperations = params => {
69
55
  const {
70
- attributes = {},
56
+ attributes,
71
57
  table: tableName,
72
58
  esTable: esTableName,
73
59
  documentClient,
74
60
  elasticsearch,
75
- plugins: pluginsInput
61
+ plugins: userPlugins
76
62
  } = params;
77
-
78
63
  if (attributes) {
79
64
  Object.values(attributes).forEach(attrs => {
80
65
  Object.keys(attrs).forEach(isReserved);
81
66
  });
82
67
  }
83
-
84
68
  const plugins = new _plugins.PluginsContainer([
85
69
  /**
86
70
  * User defined plugins.
87
71
  */
88
- pluginsInput || [],
72
+ userPlugins || [],
89
73
  /**
90
74
  * Elasticsearch field definitions for the submission record.
91
75
  */
92
- (0, _elasticsearchFields.default)(),
76
+ (0, _elasticsearchFields2.default)(),
93
77
  /**
94
78
  * Elasticsearch field definitions for the form record.
95
79
  */
96
- (0, _elasticsearchFields2.default)(),
80
+ (0, _elasticsearchFields.default)(),
97
81
  /**
98
82
  * DynamoDB filter plugins for the where conditions.
99
83
  */
100
84
  (0, _filters.default)(),
101
85
  /**
102
- * Elasticsearch operators.
86
+ * Built-in Elasticsearch index plugins
103
87
  */
104
- (0, _operators.getElasticsearchOperators)()]);
88
+ (0, _indices.elasticsearchIndexPlugins)()]);
105
89
  const table = (0, _table.createTable)({
106
90
  tableName,
107
91
  documentClient
@@ -117,72 +101,107 @@ const createFormBuilderStorageOperations = params => {
117
101
  form: (0, _form.createFormEntity)({
118
102
  entityName: _types.ENTITIES.FORM,
119
103
  table,
120
- attributes: attributes[_types.ENTITIES.FORM]
104
+ attributes: attributes ? attributes[_types.ENTITIES.FORM] : {}
121
105
  }),
122
106
  submission: (0, _submission.createSubmissionEntity)({
123
107
  entityName: _types.ENTITIES.SUBMISSION,
124
108
  table,
125
- attributes: attributes[_types.ENTITIES.SUBMISSION]
109
+ attributes: attributes ? attributes[_types.ENTITIES.SUBMISSION] : {}
126
110
  }),
127
111
  system: (0, _system.createSystemEntity)({
128
112
  entityName: _types.ENTITIES.SYSTEM,
129
113
  table,
130
- attributes: attributes[_types.ENTITIES.SYSTEM]
114
+ attributes: attributes ? attributes[_types.ENTITIES.SYSTEM] : {}
131
115
  }),
132
116
  settings: (0, _settings.createSettingsEntity)({
133
117
  entityName: _types.ENTITIES.SETTINGS,
134
118
  table,
135
- attributes: attributes[_types.ENTITIES.SETTINGS]
119
+ attributes: attributes ? attributes[_types.ENTITIES.SETTINGS] : {}
136
120
  }),
137
-
138
121
  /**
139
122
  * Elasticsearch entities.
140
123
  */
141
124
  esForm: (0, _elasticsearch.createElasticsearchEntity)({
142
125
  entityName: _types.ENTITIES.ES_FORM,
143
126
  table: esTable,
144
- attributes: attributes[_types.ENTITIES.ES_FORM]
127
+ attributes: attributes ? attributes[_types.ENTITIES.ES_FORM] : {}
145
128
  }),
146
129
  esSubmission: (0, _elasticsearch.createElasticsearchEntity)({
147
130
  entityName: _types.ENTITIES.ES_SUBMISSION,
148
131
  table: esTable,
149
- attributes: attributes[_types.ENTITIES.ES_SUBMISSION]
132
+ attributes: attributes ? attributes[_types.ENTITIES.ES_SUBMISSION] : {}
150
133
  })
151
134
  };
152
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread({
153
- init: async formBuilder => {
154
- formBuilder.onAfterInstall.subscribe(async ({
135
+ return {
136
+ beforeInit: async context => {
137
+ context.db.registry.register({
138
+ item: entities.form,
139
+ app: "fb",
140
+ tags: ["regular", "form", entities.form.name]
141
+ });
142
+ context.db.registry.register({
143
+ item: entities.esForm,
144
+ app: "fb",
145
+ tags: ["es", "form", entities.esForm.name]
146
+ });
147
+ context.db.registry.register({
148
+ item: entities.submission,
149
+ app: "fb",
150
+ tags: ["regular", "form-submission", entities.submission.name]
151
+ });
152
+ context.db.registry.register({
153
+ item: entities.esSubmission,
154
+ app: "fb",
155
+ tags: ["es", "form-submission", entities.esSubmission.name]
156
+ });
157
+ const types = [_apiElasticsearch.ElasticsearchQueryBuilderOperatorPlugin.type,
158
+ // Form Builder
159
+ _plugins2.FormDynamoDbFieldPlugin.type, _plugins2.FormElasticsearchBodyModifierPlugin.type, _plugins2.FormElasticsearchFieldPlugin.type, _plugins2.FormElasticsearchIndexPlugin.type, _plugins2.FormElasticsearchQueryModifierPlugin.type, _plugins2.FormElasticsearchSortModifierPlugin.type, _plugins2.SubmissionElasticsearchBodyModifierPlugin.type, _plugins2.SubmissionElasticsearchFieldPlugin.type, _plugins2.SubmissionElasticsearchQueryModifierPlugin.type, _plugins2.SubmissionElasticsearchSortModifierPlugin.type, _api.CompressorPlugin.type];
160
+ for (const type of types) {
161
+ plugins.mergeByType(context.plugins, type);
162
+ }
163
+ context.plugins.register([(0, _createIndexTaskPlugin.createIndexTaskPlugin)(), (0, _indices.elasticsearchIndexPlugins)()]);
164
+ },
165
+ init: async context => {
166
+ context.i18n.locales.onLocaleBeforeCreate.subscribe(async ({
167
+ locale,
155
168
  tenant
156
169
  }) => {
157
170
  await (0, _createElasticsearchIndex.createElasticsearchIndex)({
158
171
  elasticsearch,
159
- tenant
172
+ plugins,
173
+ tenant,
174
+ locale: locale.code
160
175
  });
161
176
  });
162
177
  },
163
- upgrade: (0, _.default)(),
164
178
  getTable: () => table,
165
179
  getEsTable: () => esTable,
166
- getEntities: () => entities
167
- }, (0, _system2.createSystemStorageOperations)({
168
- table,
169
- entity: entities.system
170
- })), (0, _settings2.createSettingsStorageOperations)({
171
- table,
172
- entity: entities.settings
173
- })), (0, _form2.createFormStorageOperations)({
174
- elasticsearch,
175
- table,
176
- entity: entities.form,
177
- esEntity: entities.esForm,
178
- plugins
179
- })), (0, _submission2.createSubmissionStorageOperations)({
180
- elasticsearch,
181
- table,
182
- entity: entities.submission,
183
- esEntity: entities.esSubmission,
184
- plugins
185
- }));
180
+ getEntities: () => entities,
181
+ ...(0, _system2.createSystemStorageOperations)({
182
+ table,
183
+ entity: entities.system
184
+ }),
185
+ ...(0, _settings2.createSettingsStorageOperations)({
186
+ table,
187
+ entity: entities.settings
188
+ }),
189
+ ...(0, _form2.createFormStorageOperations)({
190
+ elasticsearch,
191
+ table,
192
+ entity: entities.form,
193
+ esEntity: entities.esForm,
194
+ plugins
195
+ }),
196
+ ...(0, _submission2.createSubmissionStorageOperations)({
197
+ elasticsearch,
198
+ table,
199
+ entity: entities.submission,
200
+ esEntity: entities.esSubmission,
201
+ plugins
202
+ })
203
+ };
186
204
  };
205
+ exports.createFormBuilderStorageOperations = createFormBuilderStorageOperations;
187
206
 
188
- exports.createFormBuilderStorageOperations = createFormBuilderStorageOperations;
207
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_filters","_interopRequireDefault","require","_elasticsearchFields","_elasticsearchFields2","_error","_types","_table","_form","_submission","_system","_settings","_system2","_submission2","_settings2","_form2","_tableElasticsearch","_plugins","_elasticsearch","_apiElasticsearch","_indices","_createElasticsearchIndex","_plugins2","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_createIndexTaskPlugin","_api","reservedFields","isReserved","name","includes","WebinyError","createFormBuilderStorageOperations","params","attributes","table","tableName","esTable","esTableName","documentClient","elasticsearch","plugins","userPlugins","values","attrs","PluginsContainer","submissionElasticsearchFields","formElasticsearchFields","dynamoDbValueFilters","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","beforeInit","context","db","registry","register","item","app","tags","types","ElasticsearchQueryBuilderOperatorPlugin","type","FormDynamoDbFieldPlugin","FormElasticsearchBodyModifierPlugin","FormElasticsearchFieldPlugin","FormElasticsearchIndexPlugin","FormElasticsearchQueryModifierPlugin","FormElasticsearchSortModifierPlugin","SubmissionElasticsearchBodyModifierPlugin","SubmissionElasticsearchFieldPlugin","SubmissionElasticsearchQueryModifierPlugin","SubmissionElasticsearchSortModifierPlugin","CompressorPlugin","mergeByType","createIndexTaskPlugin","init","i18n","locales","onLocaleBeforeCreate","subscribe","locale","tenant","createElasticsearchIndex","code","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 type { FormBuilderStorageOperationsFactory } from \"~/types\";\nimport { 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 { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"~/elasticsearch/indices\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport type { FormBuilderContext } from \"@webiny/api-form-builder/types\";\nimport {\n FormDynamoDbFieldPlugin,\n FormElasticsearchBodyModifierPlugin,\n FormElasticsearchFieldPlugin,\n FormElasticsearchIndexPlugin,\n FormElasticsearchQueryModifierPlugin,\n FormElasticsearchSortModifierPlugin,\n SubmissionElasticsearchBodyModifierPlugin,\n SubmissionElasticsearchFieldPlugin,\n SubmissionElasticsearchQueryModifierPlugin,\n SubmissionElasticsearchSortModifierPlugin\n} from \"~/plugins\";\nimport { createIndexTaskPlugin } from \"~/tasks/createIndexTaskPlugin\";\nimport { CompressorPlugin } from \"@webiny/api\";\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 * from \"./plugins\";\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 * 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 beforeInit: async (context: FormBuilderContext) => {\n context.db.registry.register({\n item: entities.form,\n app: \"fb\",\n tags: [\"regular\", \"form\", entities.form.name]\n });\n context.db.registry.register({\n item: entities.esForm,\n app: \"fb\",\n tags: [\"es\", \"form\", entities.esForm.name]\n });\n context.db.registry.register({\n item: entities.submission,\n app: \"fb\",\n tags: [\"regular\", \"form-submission\", entities.submission.name]\n });\n context.db.registry.register({\n item: entities.esSubmission,\n app: \"fb\",\n tags: [\"es\", \"form-submission\", entities.esSubmission.name]\n });\n\n const types: string[] = [\n ElasticsearchQueryBuilderOperatorPlugin.type,\n // Form Builder\n FormDynamoDbFieldPlugin.type,\n FormElasticsearchBodyModifierPlugin.type,\n FormElasticsearchFieldPlugin.type,\n FormElasticsearchIndexPlugin.type,\n FormElasticsearchQueryModifierPlugin.type,\n FormElasticsearchSortModifierPlugin.type,\n SubmissionElasticsearchBodyModifierPlugin.type,\n SubmissionElasticsearchFieldPlugin.type,\n SubmissionElasticsearchQueryModifierPlugin.type,\n SubmissionElasticsearchSortModifierPlugin.type,\n CompressorPlugin.type\n ];\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n context.plugins.register([createIndexTaskPlugin(), elasticsearchIndexPlugins()]);\n },\n init: async (context: FormBuilderContext) => {\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 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,IAAAA,QAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,qBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAN,OAAA;AACA,IAAAO,WAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AACA,IAAAS,SAAA,GAAAT,OAAA;AACA,IAAAU,QAAA,GAAAV,OAAA;AACA,IAAAW,YAAA,GAAAX,OAAA;AACA,IAAAY,UAAA,GAAAZ,OAAA;AACA,IAAAa,MAAA,GAAAb,OAAA;AACA,IAAAc,mBAAA,GAAAd,OAAA;AACA,IAAAe,QAAA,GAAAf,OAAA;AACA,IAAAgB,cAAA,GAAAhB,OAAA;AACA,IAAAiB,iBAAA,GAAAjB,OAAA;AACA,IAAAkB,QAAA,GAAAlB,OAAA;AACA,IAAAmB,yBAAA,GAAAnB,OAAA;AAEA,IAAAoB,SAAA,GAAApB,OAAA;AA0BAqB,MAAA,CAAAC,IAAA,CAAAF,SAAA,EAAAG,OAAA,WAAAC,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OAAO;IACzBsE,WAAW,EAAEA,CAAA,KAAMvD,QAAQ;IAC3B,GAAG,IAAAwD,sCAA6B,EAAC;MAC7BzE,KAAK;MACL0E,MAAM,EAAEzD,QAAQ,CAACS;IACrB,CAAC,CAAC;IACF,GAAG,IAAAiD,0CAA+B,EAAC;MAC/B3E,KAAK;MACL0E,MAAM,EAAEzD,QAAQ,CAACY;IACrB,CAAC,CAAC;IACF,GAAG,IAAA+C,kCAA2B,EAAC;MAC3BvE,aAAa;MACbL,KAAK;MACL0E,MAAM,EAAEzD,QAAQ,CAACC,IAAI;MACrB2D,QAAQ,EAAE5D,QAAQ,CAACe,MAAM;MACzB1B;IACJ,CAAC,CAAC;IACF,GAAG,IAAAwE,8CAAiC,EAAC;MACjCzE,aAAa;MACbL,KAAK;MACL0E,MAAM,EAAEzD,QAAQ,CAACM,UAAU;MAC3BsD,QAAQ,EAAE5D,QAAQ,CAACkB,YAAY;MAC/B7B;IACJ,CAAC;EACL,CAAC;AACL,CAAC;AAACpB,OAAA,CAAAW,kCAAA,GAAAA,kCAAA","ignoreList":[]}
@@ -1,12 +1,12 @@
1
- import { SearchBody as esSearchBody } from "elastic-ts";
2
- import { FormBuilderStorageOperationsListFormsParams } from "@webiny/api-form-builder/types";
3
- import { PluginsContainer } from "@webiny/plugins";
1
+ import type { PrimitiveValue, SearchBody as esSearchBody } from "elastic-ts";
2
+ import type { FormBuilderStorageOperationsListFormsParams } from "@webiny/api-form-builder/types";
3
+ import type { PluginsContainer } from "@webiny/plugins";
4
4
  export declare const createFormElasticType: () => string;
5
5
  interface CreateElasticsearchBodyParams {
6
6
  plugins: PluginsContainer;
7
7
  where: FormBuilderStorageOperationsListFormsParams["where"];
8
8
  limit: number;
9
- after?: string;
9
+ after?: PrimitiveValue[];
10
10
  sort: string[];
11
11
  }
12
12
  export declare const createElasticsearchBody: (params: CreateElasticsearchBodyParams) => esSearchBody;
@@ -1,42 +1,18 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.createFormElasticType = exports.createElasticsearchBody = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _cursors = require("@webiny/api-elasticsearch/cursors");
13
-
14
- var _sort = require("@webiny/api-elasticsearch/sort");
15
-
16
- var _limit = require("@webiny/api-elasticsearch/limit");
17
-
18
- var _ElasticsearchQueryBuilderOperatorPlugin = require("@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin");
19
-
7
+ var _apiElasticsearch = require("@webiny/api-elasticsearch");
20
8
  var _FormElasticsearchFieldPlugin = require("../../plugins/FormElasticsearchFieldPlugin");
21
-
22
9
  var _FormElasticsearchSortModifierPlugin = require("../../plugins/FormElasticsearchSortModifierPlugin");
23
-
24
10
  var _FormElasticsearchBodyModifierPlugin = require("../../plugins/FormElasticsearchBodyModifierPlugin");
25
-
26
11
  var _FormElasticsearchQueryModifierPlugin = require("../../plugins/FormElasticsearchQueryModifierPlugin");
27
-
28
- var _where = require("@webiny/api-elasticsearch/where");
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
12
  const createFormElasticType = () => {
35
13
  return "fb.form";
36
14
  };
37
-
38
15
  exports.createFormElasticType = createFormElasticType;
39
-
40
16
  const createInitialQueryValue = () => {
41
17
  return {
42
18
  must: [
@@ -53,7 +29,6 @@ const createInitialQueryValue = () => {
53
29
  filter: []
54
30
  };
55
31
  };
56
-
57
32
  const createElasticsearchQuery = params => {
58
33
  const {
59
34
  plugins,
@@ -64,24 +39,18 @@ const createElasticsearchQuery = params => {
64
39
  /**
65
40
  * Be aware that, if having more registered operator plugins of same type, the last one will be used.
66
41
  */
67
-
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);
42
+ const operatorPlugins = (0, _apiElasticsearch.getElasticsearchOperatorPluginsByLocale)(plugins, initialWhere.locale);
43
+ const where = {
44
+ ...initialWhere
45
+ };
74
46
  /**
75
47
  * !!! IMPORTANT !!! There are few specific cases where we hardcode the query conditions.
76
48
  *
77
49
  * When ES index is shared between tenants, we need to filter records by tenant ID.
78
50
  * No need for the tenant filtering otherwise as each index is for single tenant.
79
51
  */
80
-
81
-
82
- const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
83
-
84
- if (sharedIndex) {
52
+ const sharedIndex = (0, _apiElasticsearch.isSharedElasticsearchIndex)();
53
+ if (sharedIndex && where.tenant) {
85
54
  query.must.push({
86
55
  term: {
87
56
  "tenant.keyword": where.tenant
@@ -92,13 +61,10 @@ const createElasticsearchQuery = params => {
92
61
  * Remove tenant so it is not applied again later.
93
62
  * Possibly tenant is not defined, but just in case, remove it.
94
63
  */
95
-
96
-
97
64
  delete where.tenant;
98
65
  /**
99
66
  * Add the locale to filtering.
100
67
  */
101
-
102
68
  query.must.push({
103
69
  term: {
104
70
  "locale.keyword": where.locale
@@ -108,8 +74,7 @@ const createElasticsearchQuery = params => {
108
74
  /**
109
75
  * We apply other conditions as they are passed via the where value.
110
76
  */
111
-
112
- (0, _where.applyWhere)({
77
+ (0, _apiElasticsearch.applyWhere)({
113
78
  query,
114
79
  where,
115
80
  fields: fieldPlugins,
@@ -117,7 +82,6 @@ const createElasticsearchQuery = params => {
117
82
  });
118
83
  return query;
119
84
  };
120
-
121
85
  const createElasticsearchBody = params => {
122
86
  const {
123
87
  plugins,
@@ -130,58 +94,50 @@ const createElasticsearchBody = params => {
130
94
  acc[plugin.field] = plugin;
131
95
  return acc;
132
96
  }, {});
133
- const limit = (0, _limit.createLimit)(initialLimit, 100);
134
- const query = createElasticsearchQuery(_objectSpread(_objectSpread({}, params), {}, {
97
+ const limit = (0, _apiElasticsearch.createLimit)(initialLimit, 100);
98
+ const query = createElasticsearchQuery({
99
+ ...params,
135
100
  fieldPlugins
136
- }));
137
- const sort = (0, _sort.createSort)({
101
+ });
102
+ const sort = (0, _apiElasticsearch.createSort)({
138
103
  sort: initialSort,
139
104
  fieldPlugins
140
105
  });
141
106
  const queryModifiers = plugins.byType(_FormElasticsearchQueryModifierPlugin.FormElasticsearchQueryModifierPlugin.type);
142
-
143
107
  for (const plugin of queryModifiers) {
144
108
  plugin.modifyQuery({
145
109
  query,
146
110
  where
147
111
  });
148
112
  }
149
-
150
113
  const sortModifiers = plugins.byType(_FormElasticsearchSortModifierPlugin.FormElasticsearchSortModifierPlugin.type);
151
-
152
114
  for (const plugin of sortModifiers) {
153
115
  plugin.modifySort({
154
116
  sort
155
117
  });
156
118
  }
157
-
158
119
  const body = {
159
120
  query: {
160
121
  constant_score: {
161
122
  filter: {
162
- bool: _objectSpread({}, query)
123
+ bool: {
124
+ ...query
125
+ }
163
126
  }
164
127
  }
165
128
  },
166
129
  size: limit + 1,
167
-
168
- /**
169
- * Casting as any is required due to search_after is accepting an array of values.
170
- * Which is correct in some cases. In our case, it is not.
171
- * https://www.elastic.co/guide/en/elasticsearch/reference/7.13/paginate-search-results.html
172
- */
173
- search_after: (0, _cursors.decodeCursor)(after),
130
+ search_after: after,
174
131
  sort
175
132
  };
176
133
  const bodyModifiers = plugins.byType(_FormElasticsearchBodyModifierPlugin.FormElasticsearchBodyModifierPlugin.type);
177
-
178
134
  for (const plugin of bodyModifiers) {
179
135
  plugin.modifyBody({
180
136
  body
181
137
  });
182
138
  }
183
-
184
139
  return body;
185
140
  };
141
+ exports.createElasticsearchBody = createElasticsearchBody;
186
142
 
187
- exports.createElasticsearchBody = createElasticsearchBody;
143
+ //# sourceMappingURL=elasticsearchBody.js.map