@webiny/api-form-builder-so-ddb-es 5.25.0 → 5.26.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/configurations.d.ts +3 -2
  2. package/configurations.js +31 -9
  3. package/configurations.js.map +1 -1
  4. package/{operations/system → elasticsearch}/createElasticsearchIndex.d.ts +3 -0
  5. package/elasticsearch/createElasticsearchIndex.js +63 -0
  6. package/elasticsearch/createElasticsearchIndex.js.map +1 -0
  7. package/elasticsearch/indices/base.d.ts +2 -0
  8. package/elasticsearch/indices/base.js +23 -0
  9. package/elasticsearch/indices/base.js.map +1 -0
  10. package/elasticsearch/indices/index.d.ts +1 -0
  11. package/elasticsearch/indices/index.js +16 -0
  12. package/elasticsearch/indices/index.js.map +1 -0
  13. package/elasticsearch/indices/japanese.d.ts +2 -0
  14. package/elasticsearch/indices/japanese.js +24 -0
  15. package/elasticsearch/indices/japanese.js.map +1 -0
  16. package/index.js +26 -19
  17. package/index.js.map +1 -1
  18. package/operations/form/elasticsearchBody.js +3 -6
  19. package/operations/form/elasticsearchBody.js.map +1 -1
  20. package/operations/form/index.js +22 -15
  21. package/operations/form/index.js.map +1 -1
  22. package/operations/submission/elasticsearchBody.js +4 -0
  23. package/operations/submission/elasticsearchBody.js.map +1 -1
  24. package/operations/submission/index.js +7 -5
  25. package/operations/submission/index.js.map +1 -1
  26. package/package.json +15 -19
  27. package/plugins/FormElasticsearchIndexPlugin.d.ts +4 -0
  28. package/plugins/FormElasticsearchIndexPlugin.js +17 -0
  29. package/plugins/FormElasticsearchIndexPlugin.js.map +1 -0
  30. package/types.d.ts +2 -2
  31. package/types.js.map +1 -1
  32. package/operations/system/createElasticsearchIndex.js +0 -70
  33. package/operations/system/createElasticsearchIndex.js.map +0 -1
  34. package/upgrades/5.16.0/index.d.ts +0 -11
  35. package/upgrades/5.16.0/index.js +0 -142
  36. package/upgrades/5.16.0/index.js.map +0 -1
@@ -1,10 +1,11 @@
1
1
  export interface ElasticsearchConfigParams {
2
2
  tenant: string;
3
+ locale: string;
3
4
  }
4
5
  interface ElasticsearchConfig {
5
6
  index: string;
6
7
  }
7
- declare const _default: {
8
+ export declare const configurations: {
8
9
  es(params: ElasticsearchConfigParams): ElasticsearchConfig;
9
10
  };
10
- export default _default;
11
+ export {};
package/configurations.js CHANGED
@@ -1,28 +1,50 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
- exports.default = void 0;
7
- var _default = {
8
+ exports.configurations = void 0;
9
+
10
+ var _error = _interopRequireDefault(require("@webiny/error"));
11
+
12
+ const configurations = {
8
13
  es(params) {
9
14
  const {
10
- tenant
15
+ tenant,
16
+ locale
11
17
  } = params;
18
+
19
+ if (!tenant) {
20
+ throw new _error.default(`Missing "tenant" parameter when trying to create Elasticsearch index name.`, "TENANT_ERROR");
21
+ }
22
+
12
23
  const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === "true";
13
- const index = `${sharedIndex ? "root" : tenant}-form-builder`;
14
- const prefix = process.env.ELASTIC_SEARCH_INDEX_PREFIX;
24
+ const tenantId = sharedIndex ? "root" : tenant;
25
+ let localeCode = null;
26
+
27
+ if (process.env.WEBINY_ELASTICSEARCH_INDEX_LOCALE === "true") {
28
+ if (!locale) {
29
+ throw new _error.default(`Missing "locale" parameter when trying to create Elasticsearch index name.`, "LOCALE_ERROR");
30
+ }
31
+
32
+ localeCode = locale;
33
+ }
34
+
35
+ const index = [tenantId, localeCode, "form-builder"].filter(Boolean).join("-").toLowerCase();
36
+ const prefix = process.env.ELASTIC_SEARCH_INDEX_PREFIX || "";
15
37
 
16
- if (prefix) {
38
+ if (!prefix) {
17
39
  return {
18
- index: prefix + index
40
+ index
19
41
  };
20
42
  }
21
43
 
22
44
  return {
23
- index
45
+ index: prefix + index
24
46
  };
25
47
  }
26
48
 
27
49
  };
28
- exports.default = _default;
50
+ exports.configurations = configurations;
@@ -1 +1 @@
1
- {"version":3,"sources":["configurations.ts"],"names":["es","params","tenant","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","index","prefix","ELASTIC_SEARCH_INDEX_PREFIX"],"mappings":";;;;;;eAQe;AACXA,EAAAA,EAAE,CAACC,MAAD,EAAyD;AACvD,UAAM;AAAEC,MAAAA;AAAF,QAAaD,MAAnB;AAEA,UAAME,WAAW,GAAGC,OAAO,CAACC,GAAR,CAAYC,4BAAZ,KAA6C,MAAjE;AACA,UAAMC,KAAK,GAAI,GAAEJ,WAAW,GAAG,MAAH,GAAYD,MAAO,eAA/C;AAEA,UAAMM,MAAM,GAAGJ,OAAO,CAACC,GAAR,CAAYI,2BAA3B;;AACA,QAAID,MAAJ,EAAY;AACR,aAAO;AAAED,QAAAA,KAAK,EAAEC,MAAM,GAAGD;AAAlB,OAAP;AACH;;AACD,WAAO;AAAEA,MAAAA;AAAF,KAAP;AACH;;AAZU,C","sourcesContent":["export interface ElasticsearchConfigParams {\n tenant: string;\n}\n\ninterface ElasticsearchConfig {\n index: string;\n}\n\nexport default {\n es(params: ElasticsearchConfigParams): ElasticsearchConfig {\n const { tenant } = params;\n\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n const index = `${sharedIndex ? \"root\" : tenant}-form-builder`;\n\n const prefix = process.env.ELASTIC_SEARCH_INDEX_PREFIX;\n if (prefix) {\n return { index: prefix + index };\n }\n return { index };\n }\n};\n"]}
1
+ {"version":3,"sources":["configurations.ts"],"names":["configurations","es","params","tenant","locale","WebinyError","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenantId","localeCode","WEBINY_ELASTICSEARCH_INDEX_LOCALE","index","filter","Boolean","join","toLowerCase","prefix","ELASTIC_SEARCH_INDEX_PREFIX"],"mappings":";;;;;;;;;AAAA;;AAWO,MAAMA,cAAc,GAAG;AAC1BC,EAAAA,EAAE,CAACC,MAAD,EAAyD;AACvD,UAAM;AAAEC,MAAAA,MAAF;AAAUC,MAAAA;AAAV,QAAqBF,MAA3B;;AACA,QAAI,CAACC,MAAL,EAAa;AACT,YAAM,IAAIE,cAAJ,CACD,4EADC,EAEF,cAFE,CAAN;AAIH;;AAED,UAAMC,WAAW,GAAGC,OAAO,CAACC,GAAR,CAAYC,4BAAZ,KAA6C,MAAjE;AAEA,UAAMC,QAAQ,GAAGJ,WAAW,GAAG,MAAH,GAAYH,MAAxC;AACA,QAAIQ,UAAyB,GAAG,IAAhC;;AACA,QAAIJ,OAAO,CAACC,GAAR,CAAYI,iCAAZ,KAAkD,MAAtD,EAA8D;AAC1D,UAAI,CAACR,MAAL,EAAa;AACT,cAAM,IAAIC,cAAJ,CACD,4EADC,EAEF,cAFE,CAAN;AAIH;;AACDM,MAAAA,UAAU,GAAGP,MAAb;AACH;;AAED,UAAMS,KAAK,GAAG,CAACH,QAAD,EAAWC,UAAX,EAAuB,cAAvB,EACTG,MADS,CACFC,OADE,EAETC,IAFS,CAEJ,GAFI,EAGTC,WAHS,EAAd;AAKA,UAAMC,MAAM,GAAGX,OAAO,CAACC,GAAR,CAAYW,2BAAZ,IAA2C,EAA1D;;AACA,QAAI,CAACD,MAAL,EAAa;AACT,aAAO;AACHL,QAAAA;AADG,OAAP;AAGH;;AACD,WAAO;AACHA,MAAAA,KAAK,EAAEK,MAAM,GAAGL;AADb,KAAP;AAGH;;AAtCyB,CAAvB","sourcesContent":["import WebinyError from \"@webiny/error\";\n\nexport interface ElasticsearchConfigParams {\n tenant: string;\n locale: string;\n}\n\ninterface ElasticsearchConfig {\n index: string;\n}\n\nexport const configurations = {\n es(params: ElasticsearchConfigParams): ElasticsearchConfig {\n const { tenant, locale } = params;\n if (!tenant) {\n throw new WebinyError(\n `Missing \"tenant\" parameter when trying to create Elasticsearch index name.`,\n \"TENANT_ERROR\"\n );\n }\n\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n\n const tenantId = sharedIndex ? \"root\" : tenant;\n let localeCode: string | null = null;\n if (process.env.WEBINY_ELASTICSEARCH_INDEX_LOCALE === \"true\") {\n if (!locale) {\n throw new WebinyError(\n `Missing \"locale\" parameter when trying to create Elasticsearch index name.`,\n \"LOCALE_ERROR\"\n );\n }\n localeCode = locale;\n }\n\n const index = [tenantId, localeCode, \"form-builder\"]\n .filter(Boolean)\n .join(\"-\")\n .toLowerCase();\n\n const prefix = process.env.ELASTIC_SEARCH_INDEX_PREFIX || \"\";\n if (!prefix) {\n return {\n index\n };\n }\n return {\n index: prefix + index\n };\n }\n};\n"]}
@@ -1,7 +1,10 @@
1
1
  import { Client } from "@elastic/elasticsearch";
2
+ import { PluginsContainer } from "@webiny/plugins";
2
3
  interface CreateElasticsearchIndexParams {
3
4
  elasticsearch: Client;
5
+ plugins: PluginsContainer;
4
6
  tenant: string;
7
+ locale: string;
5
8
  }
6
9
  export declare const createElasticsearchIndex: (params: CreateElasticsearchIndexParams) => Promise<void>;
7
10
  export {};
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createElasticsearchIndex = void 0;
9
+
10
+ var _indices = require("@webiny/api-elasticsearch/indices");
11
+
12
+ var _FormElasticsearchIndexPlugin = require("../plugins/FormElasticsearchIndexPlugin");
13
+
14
+ var _error = _interopRequireDefault(require("@webiny/error"));
15
+
16
+ var _configurations = require("../configurations");
17
+
18
+ const createElasticsearchIndex = async params => {
19
+ const {
20
+ elasticsearch,
21
+ plugins: container,
22
+ locale,
23
+ tenant
24
+ } = params;
25
+ const plugin = (0, _indices.getLastAddedIndexPlugin)({
26
+ container,
27
+ type: _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin.type,
28
+ locale
29
+ });
30
+
31
+ const {
32
+ index
33
+ } = _configurations.configurations.es({
34
+ locale,
35
+ tenant
36
+ });
37
+
38
+ try {
39
+ const response = await elasticsearch.indices.exists({
40
+ index
41
+ });
42
+
43
+ if (response.body) {
44
+ return;
45
+ }
46
+
47
+ await elasticsearch.indices.create({
48
+ index,
49
+ body: plugin.body
50
+ });
51
+ } catch (ex) {
52
+ throw new _error.default(ex.message || "Could not create Elasticsearch index for the Form Builder.", ex.code || "FB_ELASTICSEARCH_INDEX_ERROR", {
53
+ error: ex,
54
+ type: _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin.type,
55
+ locale,
56
+ tenant,
57
+ index,
58
+ body: plugin.body
59
+ });
60
+ }
61
+ };
62
+
63
+ exports.createElasticsearchIndex = createElasticsearchIndex;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["createElasticsearchIndex.ts"],"names":["createElasticsearchIndex","params","elasticsearch","plugins","container","locale","tenant","plugin","type","FormElasticsearchIndexPlugin","index","configurations","es","response","indices","exists","body","create","ex","WebinyError","message","code","error"],"mappings":";;;;;;;;;AACA;;AACA;;AAEA;;AACA;;AASO,MAAMA,wBAAwB,GAAG,MAAOC,MAAP,IAAkD;AACtF,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA,OAAO,EAAEC,SAA1B;AAAqCC,IAAAA,MAArC;AAA6CC,IAAAA;AAA7C,MAAwDL,MAA9D;AAEA,QAAMM,MAAM,GAAG,sCAAsD;AACjEH,IAAAA,SADiE;AAEjEI,IAAAA,IAAI,EAAEC,2DAA6BD,IAF8B;AAGjEH,IAAAA;AAHiE,GAAtD,CAAf;;AAMA,QAAM;AAAEK,IAAAA;AAAF,MAAYC,+BAAeC,EAAf,CAAkB;AAChCP,IAAAA,MADgC;AAEhCC,IAAAA;AAFgC,GAAlB,CAAlB;;AAKA,MAAI;AACA,UAAMO,QAAQ,GAAG,MAAMX,aAAa,CAACY,OAAd,CAAsBC,MAAtB,CAA6B;AAChDL,MAAAA;AADgD,KAA7B,CAAvB;;AAGA,QAAIG,QAAQ,CAACG,IAAb,EAAmB;AACf;AACH;;AAED,UAAMd,aAAa,CAACY,OAAd,CAAsBG,MAAtB,CAA6B;AAC/BP,MAAAA,KAD+B;AAE/BM,MAAAA,IAAI,EAAET,MAAM,CAACS;AAFkB,KAA7B,CAAN;AAIH,GAZD,CAYE,OAAOE,EAAP,EAAW;AACT,UAAM,IAAIC,cAAJ,CACFD,EAAE,CAACE,OAAH,IAAc,4DADZ,EAEFF,EAAE,CAACG,IAAH,IAAW,8BAFT,EAGF;AACIC,MAAAA,KAAK,EAAEJ,EADX;AAEIV,MAAAA,IAAI,EAAEC,2DAA6BD,IAFvC;AAGIH,MAAAA,MAHJ;AAIIC,MAAAA,MAJJ;AAKII,MAAAA,KALJ;AAMIM,MAAAA,IAAI,EAAET,MAAM,CAACS;AANjB,KAHE,CAAN;AAYH;AACJ,CAxCM","sourcesContent":["import { Client } from \"@elastic/elasticsearch\";\nimport { getLastAddedIndexPlugin } from \"@webiny/api-elasticsearch/indices\";\nimport { FormElasticsearchIndexPlugin } from \"~/plugins/FormElasticsearchIndexPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\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: container, locale, tenant } = params;\n\n const plugin = getLastAddedIndexPlugin<FormElasticsearchIndexPlugin>({\n container,\n type: FormElasticsearchIndexPlugin.type,\n locale\n });\n\n const { index } = configurations.es({\n locale,\n tenant\n });\n\n try {\n const response = await elasticsearch.indices.exists({\n index\n });\n if (response.body) {\n return;\n }\n\n await elasticsearch.indices.create({\n index,\n body: plugin.body\n });\n } catch (ex) {\n throw new WebinyError(\n ex.message || \"Could not create Elasticsearch index for the Form Builder.\",\n ex.code || \"FB_ELASTICSEARCH_INDEX_ERROR\",\n {\n error: ex,\n type: FormElasticsearchIndexPlugin.type,\n locale,\n tenant,\n index,\n body: plugin.body\n }\n );\n }\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import { FormElasticsearchIndexPlugin } from "../../plugins/FormElasticsearchIndexPlugin";
2
+ export declare const base: FormElasticsearchIndexPlugin;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.base = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _FormElasticsearchIndexPlugin = require("../../plugins/FormElasticsearchIndexPlugin");
13
+
14
+ var _base = require("@webiny/api-elasticsearch/indexConfiguration/base");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
+
20
+ const base = new _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin({
21
+ body: _objectSpread({}, _base.base)
22
+ });
23
+ exports.base = base;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["base.ts"],"names":["base","FormElasticsearchIndexPlugin","body","baseConfiguration"],"mappings":";;;;;;;;;;;AAAA;;AACA;;;;;;AAEO,MAAMA,IAAI,GAAG,IAAIC,0DAAJ,CAAiC;AACjDC,EAAAA,IAAI,oBACGC,UADH;AAD6C,CAAjC,CAAb","sourcesContent":["import { FormElasticsearchIndexPlugin } from \"~/plugins/FormElasticsearchIndexPlugin\";\nimport { base as baseConfiguration } from \"@webiny/api-elasticsearch/indexConfiguration/base\";\n\nexport const base = new FormElasticsearchIndexPlugin({\n body: {\n ...baseConfiguration\n }\n});\n"]}
@@ -0,0 +1 @@
1
+ export declare const elasticsearchIndexPlugins: () => import("../../plugins/FormElasticsearchIndexPlugin").FormElasticsearchIndexPlugin[];
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.elasticsearchIndexPlugins = void 0;
7
+
8
+ var _base = require("./base");
9
+
10
+ var _japanese = require("./japanese");
11
+
12
+ const elasticsearchIndexPlugins = () => {
13
+ return [_base.base, _japanese.japanese];
14
+ };
15
+
16
+ exports.elasticsearchIndexPlugins = elasticsearchIndexPlugins;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.ts"],"names":["elasticsearchIndexPlugins","base","japanese"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,MAAMA,yBAAyB,GAAG,MAAM;AAC3C,SAAO,CAACC,UAAD,EAAOC,kBAAP,CAAP;AACH,CAFM","sourcesContent":["import { base } from \"./base\";\nimport { japanese } from \"./japanese\";\n\nexport const elasticsearchIndexPlugins = () => {\n return [base, japanese];\n};\n"]}
@@ -0,0 +1,2 @@
1
+ import { FormElasticsearchIndexPlugin } from "../../plugins/FormElasticsearchIndexPlugin";
2
+ export declare const japanese: FormElasticsearchIndexPlugin;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.japanese = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _japanese = require("@webiny/api-elasticsearch/indexConfiguration/japanese");
13
+
14
+ var _FormElasticsearchIndexPlugin = require("../../plugins/FormElasticsearchIndexPlugin");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
+
20
+ const japanese = new _FormElasticsearchIndexPlugin.FormElasticsearchIndexPlugin({
21
+ body: _objectSpread({}, _japanese.japanese),
22
+ locales: ["ja", "ja-jp"]
23
+ });
24
+ exports.japanese = japanese;
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["japanese.ts"],"names":["japanese","FormElasticsearchIndexPlugin","body","japaneseConfiguration","locales"],"mappings":";;;;;;;;;;;AAAA;;AACA;;;;;;AAEO,MAAMA,QAAQ,GAAG,IAAIC,0DAAJ,CAAiC;AACrDC,EAAAA,IAAI,oBACGC,kBADH,CADiD;AAIrDC,EAAAA,OAAO,EAAE,CAAC,IAAD,EAAO,OAAP;AAJ4C,CAAjC,CAAjB","sourcesContent":["import { japanese as japaneseConfiguration } from \"@webiny/api-elasticsearch/indexConfiguration/japanese\";\nimport { FormElasticsearchIndexPlugin } from \"~/plugins/FormElasticsearchIndexPlugin\";\n\nexport const japanese = new FormElasticsearchIndexPlugin({\n body: {\n ...japaneseConfiguration\n },\n locales: [\"ja\", \"ja-jp\"]\n});\n"]}
package/index.js CHANGED
@@ -9,10 +9,16 @@ exports.createFormBuilderStorageOperations = void 0;
9
9
 
10
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
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,23 +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"));
48
+ var _indices = require("./elasticsearch/indices");
49
+
50
+ var _createElasticsearchIndex = require("./elasticsearch/createElasticsearchIndex");
51
51
 
52
52
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
53
53
 
@@ -72,7 +72,7 @@ const createFormBuilderStorageOperations = params => {
72
72
  esTable: esTableName,
73
73
  documentClient,
74
74
  elasticsearch,
75
- plugins: pluginsInput
75
+ plugins: userPlugins
76
76
  } = params;
77
77
 
78
78
  if (attributes) {
@@ -85,15 +85,15 @@ const createFormBuilderStorageOperations = params => {
85
85
  /**
86
86
  * User defined plugins.
87
87
  */
88
- pluginsInput || [],
88
+ userPlugins || [],
89
89
  /**
90
90
  * Elasticsearch field definitions for the submission record.
91
91
  */
92
- (0, _elasticsearchFields.default)(),
92
+ (0, _elasticsearchFields2.default)(),
93
93
  /**
94
94
  * Elasticsearch field definitions for the form record.
95
95
  */
96
- (0, _elasticsearchFields2.default)(),
96
+ (0, _elasticsearchFields.default)(),
97
97
  /**
98
98
  * DynamoDB filter plugins for the where conditions.
99
99
  */
@@ -101,7 +101,11 @@ const createFormBuilderStorageOperations = params => {
101
101
  /**
102
102
  * Elasticsearch operators.
103
103
  */
104
- (0, _operators.getElasticsearchOperators)()]);
104
+ (0, _operators.getElasticsearchOperators)(),
105
+ /**
106
+ * Built-in Elasticsearch index plugins
107
+ */
108
+ (0, _indices.elasticsearchIndexPlugins)()]);
105
109
  const table = (0, _table.createTable)({
106
110
  tableName,
107
111
  documentClient
@@ -150,17 +154,20 @@ const createFormBuilderStorageOperations = params => {
150
154
  })
151
155
  };
152
156
  return _objectSpread(_objectSpread(_objectSpread(_objectSpread({
153
- init: async formBuilder => {
154
- formBuilder.onAfterInstall.subscribe(async ({
157
+ init: async context => {
158
+ context.i18n.locales.onBeforeCreate.subscribe(async ({
159
+ locale,
155
160
  tenant
156
161
  }) => {
157
162
  await (0, _createElasticsearchIndex.createElasticsearchIndex)({
158
163
  elasticsearch,
159
- tenant
164
+ plugins,
165
+ tenant,
166
+ locale: locale.code
160
167
  });
161
168
  });
162
169
  },
163
- upgrade: (0, _.default)(),
170
+ upgrade: null,
164
171
  getTable: () => table,
165
172
  getEsTable: () => esTable,
166
173
  getEntities: () => entities
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["reservedFields","isReserved","name","includes","WebinyError","createFormBuilderStorageOperations","params","attributes","table","tableName","esTable","esTableName","documentClient","elasticsearch","plugins","pluginsInput","Object","values","forEach","attrs","keys","PluginsContainer","entities","form","entityName","ENTITIES","FORM","submission","SUBMISSION","system","SYSTEM","settings","SETTINGS","esForm","ES_FORM","esSubmission","ES_SUBMISSION","init","formBuilder","onAfterInstall","subscribe","tenant","upgrade","getTable","getEsTable","getEntities","entity","esEntity"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;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;AACvC,MAAIF,cAAc,CAACG,QAAf,CAAwBD,IAAxB,MAAkC,KAAtC,EAA6C;AACzC;AACH;;AACD,QAAM,IAAIE,cAAJ,CAAiB,mBAAkBF,IAAK,mBAAxC,EAA4D,uBAA5D,EAAqF;AACvFA,IAAAA;AADuF,GAArF,CAAN;AAGH,CAPD;;AASO,MAAMG,kCAAuE,GAAGC,MAAM,IAAI;AAC7F,QAAM;AACFC,IAAAA,UADE;AAEFC,IAAAA,KAAK,EAAEC,SAFL;AAGFC,IAAAA,OAAO,EAAEC,WAHP;AAIFC,IAAAA,cAJE;AAKFC,IAAAA,aALE;AAMFC,IAAAA,OAAO,EAAEC;AANP,MAOFT,MAPJ;;AASA,MAAIC,UAAJ,EAAgB;AACZS,IAAAA,MAAM,CAACC,MAAP,CAAcV,UAAd,EAA0BW,OAA1B,CAAkCC,KAAK,IAAI;AACvCH,MAAAA,MAAM,CAACI,IAAP,CAAYD,KAAZ,EAAmBD,OAAnB,CAA2B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AExB,QAAQ,CAACC,IAHU;AAI3BwB,IAAAA,QAAQ,EAAEzB,QAAQ,CAACW,MAJQ;AAK3BnB,IAAAA;AAL2B,GAA5B,CArBP,GA4BO,oDAAkC;AACjCD,IAAAA,aADiC;AAEjCL,IAAAA,KAFiC;AAGjCsC,IAAAA,MAAM,EAAExB,QAAQ,CAACK,UAHgB;AAIjCoB,IAAAA,QAAQ,EAAEzB,QAAQ,CAACa,YAJc;AAKjCrB,IAAAA;AALiC,GAAlC,CA5BP;AAoCH,CA5HM","sourcesContent":["import { FormBuilderStorageOperationsFactory, ENTITIES } from \"~/types\";\nimport WebinyError from \"@webiny/error\";\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 { createElasticsearchIndex } from \"~/operations/system/createElasticsearchIndex\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createElasticsearchEntity } from \"~/definitions/elasticsearch\";\nimport submissionElasticsearchFields from \"./operations/submission/elasticsearchFields\";\nimport formElasticsearchFields from \"./operations/form/elasticsearchFields\";\nimport dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport { getElasticsearchOperators } from \"@webiny/api-elasticsearch/operators\";\n\nimport upgrade5160 from \"./upgrades/5.16.0\";\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: pluginsInput\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 pluginsInput || [],\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\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 formBuilder => {\n formBuilder.onAfterInstall.subscribe(async ({ tenant }) => {\n await createElasticsearchIndex({\n elasticsearch,\n tenant\n });\n });\n },\n upgrade: upgrade5160(),\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"]}
1
+ {"version":3,"sources":["index.ts"],"names":["reservedFields","isReserved","name","includes","WebinyError","createFormBuilderStorageOperations","params","attributes","table","tableName","esTable","esTableName","documentClient","elasticsearch","plugins","userPlugins","Object","values","forEach","attrs","keys","PluginsContainer","entities","form","entityName","ENTITIES","FORM","submission","SUBMISSION","system","SYSTEM","settings","SETTINGS","esForm","ES_FORM","esSubmission","ES_SUBMISSION","init","context","i18n","locales","onBeforeCreate","subscribe","locale","tenant","code","upgrade","getTable","getEsTable","getEntities","entity","esEntity"],"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;AACvC,MAAIF,cAAc,CAACG,QAAf,CAAwBD,IAAxB,MAAkC,KAAtC,EAA6C;AACzC;AACH;;AACD,QAAM,IAAIE,cAAJ,CAAiB,mBAAkBF,IAAK,mBAAxC,EAA4D,uBAA5D,EAAqF;AACvFA,IAAAA;AADuF,GAArF,CAAN;AAGH,CAPD;;AASO,MAAMG,kCAAuE,GAA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,UAAAA,MAAM,EAAEA,MAAM,CAACE;AAJY,SAAzB,CAAN;AAMH,OAPD;AAQH,KAVL;AAWIC,IAAAA,OAAO,EAAE,IAXb;AAYIC,IAAAA,QAAQ,EAAE,MAAMvC,KAZpB;AAaIwC,IAAAA,UAAU,EAAE,MAAMtC,OAbtB;AAcIuC,IAAAA,WAAW,EAAE,MAAM3B;AAdvB,KAeO,4CAA8B;AAC7Bd,IAAAA,KAD6B;AAE7B0C,IAAAA,MAAM,EAAE5B,QAAQ,CAACO;AAFY,GAA9B,CAfP,GAmBO,gDAAgC;AAC/BrB,IAAAA,KAD+B;AAE/B0C,IAAAA,MAAM,EAAE5B,QAAQ,CAACS;AAFc,GAAhC,CAnBP,GAuBO,wCAA4B;AAC3BlB,IAAAA,aAD2B;AAE3BL,IAAAA,KAF2B;AAG3B0C,IAAAA,MAAM,EAAE5B,QAAQ,CAACC,IAHU;AAI3B4B,IAAAA,QAAQ,EAAE7B,QAAQ,CAACW,MAJQ;AAK3BnB,IAAAA;AAL2B,GAA5B,CAvBP,GA8BO,oDAAkC;AACjCD,IAAAA,aADiC;AAEjCL,IAAAA,KAFiC;AAGjC0C,IAAAA,MAAM,EAAE5B,QAAQ,CAACK,UAHgB;AAIjCwB,IAAAA,QAAQ,EAAE7B,QAAQ,CAACa,YAJc;AAKjCrB,IAAAA;AALiC,GAAlC,CA9BP;AAsCH,CAlIM","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.onBeforeCreate.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"]}
@@ -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,6 +25,8 @@ var _FormElasticsearchQueryModifierPlugin = require("../../plugins/FormElasticse
27
25
 
28
26
  var _where = require("@webiny/api-elasticsearch/where");
29
27
 
28
+ var _operators = require("@webiny/api-elasticsearch/operators");
29
+
30
30
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
31
31
 
32
32
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -65,10 +65,7 @@ const createElasticsearchQuery = params => {
65
65
  * Be aware that, if having more registered operator plugins of same type, the last one will be used.
66
66
  */
67
67
 
68
- const operatorPlugins = plugins.byType(_ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((acc, plugin) => {
69
- acc[plugin.getOperator()] = plugin;
70
- return acc;
71
- }, {});
68
+ const operatorPlugins = (0, _operators.getElasticsearchOperatorPluginsByLocale)(plugins, initialWhere.locale);
72
69
 
73
70
  const where = _objectSpread({}, initialWhere);
74
71
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["elasticsearchBody.ts"],"names":["createFormElasticType","createInitialQueryValue","must","term","must_not","should","filter","createElasticsearchQuery","params","plugins","where","initialWhere","fieldPlugins","query","operatorPlugins","byType","ElasticsearchQueryBuilderOperatorPlugin","type","reduce","acc","plugin","getOperator","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","locale","fields","operators","createElasticsearchBody","limit","initialLimit","sort","initialSort","after","FormElasticsearchFieldPlugin","field","queryModifiers","FormElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","FormElasticsearchSortModifierPlugin","modifySort","body","constant_score","bool","size","search_after","bodyModifiers","FormElasticsearchBodyModifierPlugin","modifyBody"],"mappings":";;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;;;;;AAEO,MAAMA,qBAAqB,GAAG,MAAc;AAC/C,SAAO,SAAP;AACH,CAFM;;;;AAIP,MAAMC,uBAAuB,GAAG,MAAoC;AAChE,SAAO;AACHC,IAAAA,IAAI,EAAE;AACF;AACZ;AACA;AACY;AACIC,MAAAA,IAAI,EAAE;AACF,0BAAkBH,qBAAqB;AADrC;AADV,KAJE,CADH;AAWHI,IAAAA,QAAQ,EAAE,EAXP;AAYHC,IAAAA,MAAM,EAAE,EAZL;AAaHC,IAAAA,MAAM,EAAE;AAbL,GAAP;AAeH,CAhBD;;AAsBA,MAAMC,wBAAwB,GAAIC,MAAD,IAA4C;AACzE,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA,KAAK,EAAEC,YAAlB;AAAgCC,IAAAA;AAAhC,MAAiDJ,MAAvD;AACA,QAAMK,KAAK,GAAGZ,uBAAuB,EAArC;AACA;AACJ;AACA;;AACI,QAAMa,eAAe,GAAGL,OAAO,CAC1BM,MADmB,CAEhBC,iFAAwCC,IAFxB,EAInBC,MAJmB,CAIZ,CAACC,GAAD,EAAMC,MAAN,KAAiB;AACrBD,IAAAA,GAAG,CAACC,MAAM,CAACC,WAAP,EAAD,CAAH,GAA4BD,MAA5B;AACA,WAAOD,GAAP;AACH,GAPmB,EAOjB,EAPiB,CAAxB;;AASA,QAAMT,KAAoE,qBACnEC,YADmE,CAA1E;AAGA;AACJ;AACA;AACA;AACA;AACA;;;AACI,QAAMW,WAAW,GAAGC,OAAO,CAAC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AAKA,QAAMsB,IAAI,GAAG,sBAAW;AACpBA,IAAAA,IAAI,EAAEC,WADc;AAEpBvB,IAAAA;AAFoB,GAAX,CAAb;AAKA,QAAM2B,cAAc,GAAG9B,OAAO,CAACM,MAAR,CACnByB,2EAAqCvB,IADlB,CAAvB;;AAIA,OAAK,MAAMG,MAAX,IAAqBmB,cAArB,EAAqC;AACjCnB,IAAAA,MAAM,CAACqB,WAAP,CAAmB;AACf5B,MAAAA,KADe;AAEfH,MAAAA;AAFe,KAAnB;AAIH;;AAED,QAAMgC,aAAa,GAAGjC,OAAO,CAACM,MAAR,CAClB4B,yEAAoC1B,IADlB,CAAtB;;AAIA,OAAK,MAAMG,MAAX,IAAqBsB,aAArB,EAAoC;AAChCtB,IAAAA,MAAM,CAACwB,UAAP,CAAkB;AACdV,MAAAA;AADc,KAAlB;AAGH;;AAED,QAAMW,IAAI,GAAG;AACThC,IAAAA,KAAK,EAAE;AACHiC,MAAAA,cAAc,EAAE;AACZxC,QAAAA,MAAM,EAAE;AACJyC,UAAAA,IAAI,oBACGlC,KADH;AADA;AADI;AADb,KADE;AAUTmC,IAAAA,IAAI,EAAEhB,KAAK,GAAG,CAVL;;AAWT;AACR;AACA;AACA;AACA;AACQiB,IAAAA,YAAY,EAAE,2BAAab,KAAb,CAhBL;AAiBTF,IAAAA;AAjBS,GAAb;AAoBA,QAAMgB,aAAa,GAAGzC,OAAO,CAACM,MAAR,CAClBoC,yEAAoClC,IADlB,CAAtB;;AAIA,OAAK,MAAMG,MAAX,IAAqB8B,aAArB,EAAoC;AAChC9B,IAAAA,MAAM,CAACgC,UAAP,CAAkB;AACdP,MAAAA;AADc,KAAlB;AAGH;;AAED,SAAOA,IAAP;AACH,CA1EM","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 { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\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\";\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 = plugins\n .byType<ElasticsearchQueryBuilderOperatorPlugin>(\n ElasticsearchQueryBuilderOperatorPlugin.type\n )\n .reduce((acc, plugin) => {\n acc[plugin.getOperator()] = plugin;\n return acc;\n }, {} as Record<string, ElasticsearchQueryBuilderOperatorPlugin>);\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"]}
1
+ {"version":3,"sources":["elasticsearchBody.ts"],"names":["createFormElasticType","createInitialQueryValue","must","term","must_not","should","filter","createElasticsearchQuery","params","plugins","where","initialWhere","fieldPlugins","query","operatorPlugins","locale","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","tenant","push","fields","operators","createElasticsearchBody","limit","initialLimit","sort","initialSort","after","byType","FormElasticsearchFieldPlugin","type","reduce","acc","plugin","field","queryModifiers","FormElasticsearchQueryModifierPlugin","modifyQuery","sortModifiers","FormElasticsearchSortModifierPlugin","modifySort","body","constant_score","bool","size","search_after","bodyModifiers","FormElasticsearchBodyModifierPlugin","modifyBody"],"mappings":";;;;;;;;;;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;;;;;AAEO,MAAMA,qBAAqB,GAAG,MAAc;AAC/C,SAAO,SAAP;AACH,CAFM;;;;AAIP,MAAMC,uBAAuB,GAAG,MAAoC;AAChE,SAAO;AACHC,IAAAA,IAAI,EAAE;AACF;AACZ;AACA;AACY;AACIC,MAAAA,IAAI,EAAE;AACF,0BAAkBH,qBAAqB;AADrC;AADV,KAJE,CADH;AAWHI,IAAAA,QAAQ,EAAE,EAXP;AAYHC,IAAAA,MAAM,EAAE,EAZL;AAaHC,IAAAA,MAAM,EAAE;AAbL,GAAP;AAeH,CAhBD;;AAsBA,MAAMC,wBAAwB,GAAIC,MAAD,IAA4C;AACzE,QAAM;AAAEC,IAAAA,OAAF;AAAWC,IAAAA,KAAK,EAAEC,YAAlB;AAAgCC,IAAAA;AA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AAkB;AACdP,MAAAA;AADc,KAAlB;AAGH;;AAED,SAAOA,IAAP;AACH,CA1EM","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"]}
@@ -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
 
@@ -136,8 +136,9 @@ const createFormStorageOperations = params => {
136
136
  try {
137
137
  const {
138
138
  index
139
- } = _configurations.default.es({
140
- tenant: form.tenant
139
+ } = _configurations.configurations.es({
140
+ tenant: form.tenant,
141
+ locale: form.locale
141
142
  });
142
143
 
143
144
  await esEntity.put(_objectSpread({
@@ -193,8 +194,9 @@ const createFormStorageOperations = params => {
193
194
  try {
194
195
  const {
195
196
  index
196
- } = _configurations.default.es({
197
- tenant: form.tenant
197
+ } = _configurations.configurations.es({
198
+ tenant: form.tenant,
199
+ locale: form.locale
198
200
  });
199
201
 
200
202
  await esEntity.put(_objectSpread({
@@ -277,8 +279,9 @@ const createFormStorageOperations = params => {
277
279
  try {
278
280
  const {
279
281
  index
280
- } = _configurations.default.es({
281
- tenant: form.tenant
282
+ } = _configurations.configurations.es({
283
+ tenant: form.tenant,
284
+ locale: form.locale
282
285
  });
283
286
 
284
287
  await esEntity.put(_objectSpread({
@@ -372,8 +375,9 @@ const createFormStorageOperations = params => {
372
375
  after: (0, _cursors.decodeCursor)(after)
373
376
  });
374
377
 
375
- const esConfig = _configurations.default.es({
376
- tenant: where.tenant
378
+ const esConfig = _configurations.configurations.es({
379
+ tenant: where.tenant,
380
+ locale: where.locale
377
381
  });
378
382
 
379
383
  const query = _objectSpread(_objectSpread({}, esConfig), {}, {
@@ -597,8 +601,9 @@ const createFormStorageOperations = params => {
597
601
 
598
602
  const {
599
603
  index
600
- } = _configurations.default.es({
601
- tenant: previous.tenant
604
+ } = _configurations.configurations.es({
605
+ tenant: previous.tenant,
606
+ locale: previous.locale
602
607
  });
603
608
 
604
609
  esDataItem = _objectSpread(_objectSpread({
@@ -728,8 +733,9 @@ const createFormStorageOperations = params => {
728
733
 
729
734
  const {
730
735
  index
731
- } = _configurations.default.es({
732
- tenant: form.tenant
736
+ } = _configurations.configurations.es({
737
+ tenant: form.tenant,
738
+ locale: form.locale
733
739
  });
734
740
 
735
741
  const esData = getESDataForLatestRevision(form);
@@ -862,8 +868,9 @@ const createFormStorageOperations = params => {
862
868
 
863
869
  const {
864
870
  index
865
- } = _configurations.default.es({
866
- tenant: form.tenant
871
+ } = _configurations.configurations.es({
872
+ tenant: form.tenant,
873
+ locale: form.locale
867
874
  });
868
875
 
869
876
  try {