@webiny/api-headless-cms-ddb-es 0.0.0-unstable.496cf268ac → 0.0.0-unstable.606fc9c866

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 (35) hide show
  1. package/configurations.d.ts +1 -1
  2. package/configurations.js.map +1 -1
  3. package/elasticsearch/indexing/longTextIndexing.js +2 -8
  4. package/elasticsearch/indexing/longTextIndexing.js.map +1 -1
  5. package/index.js +2 -1
  6. package/index.js.map +1 -1
  7. package/operations/entry/elasticsearch/body.js +1 -1
  8. package/operations/entry/elasticsearch/body.js.map +1 -1
  9. package/operations/entry/elasticsearch/fields.d.ts +5 -4
  10. package/operations/entry/elasticsearch/fields.js +73 -41
  11. package/operations/entry/elasticsearch/fields.js.map +1 -1
  12. package/operations/entry/elasticsearch/filtering/exec.js +1 -1
  13. package/operations/entry/elasticsearch/filtering/exec.js.map +1 -1
  14. package/operations/entry/elasticsearch/filtering/path.js +1 -1
  15. package/operations/entry/elasticsearch/filtering/path.js.map +1 -1
  16. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js +1 -1
  17. package/operations/entry/elasticsearch/filtering/plugins/defaultFilterPlugin.js.map +1 -1
  18. package/operations/entry/elasticsearch/sort.js +5 -6
  19. package/operations/entry/elasticsearch/sort.js.map +1 -1
  20. package/operations/entry/elasticsearch/types.d.ts +3 -3
  21. package/operations/entry/elasticsearch/types.js.map +1 -1
  22. package/operations/entry/index.js +119 -18
  23. package/operations/entry/index.js.map +1 -1
  24. package/package.json +21 -14
  25. package/plugins/CmsElasticsearchModelFieldPlugin.d.ts +69 -0
  26. package/plugins/CmsElasticsearchModelFieldPlugin.js +48 -0
  27. package/plugins/CmsElasticsearchModelFieldPlugin.js.map +1 -0
  28. package/plugins/index.d.ts +1 -1
  29. package/plugins/index.js +11 -11
  30. package/plugins/index.js.map +1 -1
  31. package/types.d.ts +1 -1
  32. package/types.js.map +1 -1
  33. package/plugins/CmsEntryElasticsearchFieldPlugin.d.ts +0 -12
  34. package/plugins/CmsEntryElasticsearchFieldPlugin.js +0 -18
  35. package/plugins/CmsEntryElasticsearchFieldPlugin.js.map +0 -1
@@ -3,7 +3,7 @@ interface ElasticsearchConfig {
3
3
  index: string;
4
4
  }
5
5
  interface CmsElasticsearchParams {
6
- model: CmsModel;
6
+ model: Pick<CmsModel, "tenant" | "locale" | "modelId">;
7
7
  }
8
8
  interface Configurations {
9
9
  es: (params: CmsElasticsearchParams) => ElasticsearchConfig;
@@ -1 +1 @@
1
- {"version":3,"names":["configurations","es","model","tenant","locale","WebinyError","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","index","modelId","join","toLowerCase","prefix","ELASTIC_SEARCH_INDEX_PREFIX"],"sources":["configurations.ts"],"sourcesContent":["import { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\n\ninterface ElasticsearchConfig {\n index: string;\n}\n\ninterface CmsElasticsearchParams {\n model: CmsModel;\n}\ninterface Configurations {\n es: (params: CmsElasticsearchParams) => ElasticsearchConfig;\n}\n\nexport const configurations: Configurations = {\n es({ model }) {\n const { tenant, locale } = model;\n\n if (!tenant) {\n throw new WebinyError(\n `Missing \"tenant\" parameter when trying to create Elasticsearch index name.`,\n \"TENANT_ERROR\"\n );\n } else if (!locale) {\n throw new WebinyError(\n `Missing \"locale\" parameter when trying to create Elasticsearch index name.`,\n \"LOCALE_ERROR\"\n );\n }\n\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n const index = [sharedIndex ? \"root\" : tenant, \"headless-cms\", locale, model.modelId]\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"],"mappings":";;;;;;;AACA;AAaO,MAAMA,cAA8B,GAAG;EAC1CC,EAAE,CAAC;IAAEC;EAAM,CAAC,EAAE;IACV,MAAM;MAAEC,MAAM;MAAEC;IAAO,CAAC,GAAGF,KAAK;IAEhC,IAAI,CAACC,MAAM,EAAE;MACT,MAAM,IAAIE,cAAW,CAChB,4EAA2E,EAC5E,cAAc,CACjB;IACL,CAAC,MAAM,IAAI,CAACD,MAAM,EAAE;MAChB,MAAM,IAAIC,cAAW,CAChB,4EAA2E,EAC5E,cAAc,CACjB;IACL;IAEA,MAAMC,WAAW,GAAGC,OAAO,CAACC,GAAG,CAACC,4BAA4B,KAAK,MAAM;IACvE,MAAMC,KAAK,GAAG,CAACJ,WAAW,GAAG,MAAM,GAAGH,MAAM,EAAE,cAAc,EAAEC,MAAM,EAAEF,KAAK,CAACS,OAAO,CAAC,CAC/EC,IAAI,CAAC,GAAG,CAAC,CACTC,WAAW,EAAE;IAElB,MAAMC,MAAM,GAAGP,OAAO,CAACC,GAAG,CAACO,2BAA2B,IAAI,EAAE;IAC5D,IAAI,CAACD,MAAM,EAAE;MACT,OAAO;QACHJ;MACJ,CAAC;IACL;IACA,OAAO;MACHA,KAAK,EAAEI,MAAM,GAAGJ;IACpB,CAAC;EACL;AACJ,CAAC;AAAC"}
1
+ {"version":3,"names":["configurations","es","model","tenant","locale","WebinyError","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","index","modelId","join","toLowerCase","prefix","ELASTIC_SEARCH_INDEX_PREFIX"],"sources":["configurations.ts"],"sourcesContent":["import { CmsModel } from \"@webiny/api-headless-cms/types\";\nimport WebinyError from \"@webiny/error\";\n\ninterface ElasticsearchConfig {\n index: string;\n}\n\ninterface CmsElasticsearchParams {\n model: Pick<CmsModel, \"tenant\" | \"locale\" | \"modelId\">;\n}\n\ninterface Configurations {\n es: (params: CmsElasticsearchParams) => ElasticsearchConfig;\n}\n\nexport const configurations: Configurations = {\n es({ model }) {\n const { tenant, locale } = model;\n\n if (!tenant) {\n throw new WebinyError(\n `Missing \"tenant\" parameter when trying to create Elasticsearch index name.`,\n \"TENANT_ERROR\"\n );\n } else if (!locale) {\n throw new WebinyError(\n `Missing \"locale\" parameter when trying to create Elasticsearch index name.`,\n \"LOCALE_ERROR\"\n );\n }\n\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n const index = [sharedIndex ? \"root\" : tenant, \"headless-cms\", locale, model.modelId]\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"],"mappings":";;;;;;;AACA;AAcO,MAAMA,cAA8B,GAAG;EAC1CC,EAAE,CAAC;IAAEC;EAAM,CAAC,EAAE;IACV,MAAM;MAAEC,MAAM;MAAEC;IAAO,CAAC,GAAGF,KAAK;IAEhC,IAAI,CAACC,MAAM,EAAE;MACT,MAAM,IAAIE,cAAW,CAChB,4EAA2E,EAC5E,cAAc,CACjB;IACL,CAAC,MAAM,IAAI,CAACD,MAAM,EAAE;MAChB,MAAM,IAAIC,cAAW,CAChB,4EAA2E,EAC5E,cAAc,CACjB;IACL;IAEA,MAAMC,WAAW,GAAGC,OAAO,CAACC,GAAG,CAACC,4BAA4B,KAAK,MAAM;IACvE,MAAMC,KAAK,GAAG,CAACJ,WAAW,GAAG,MAAM,GAAGH,MAAM,EAAE,cAAc,EAAEC,MAAM,EAAEF,KAAK,CAACS,OAAO,CAAC,CAC/EC,IAAI,CAAC,GAAG,CAAC,CACTC,WAAW,EAAE;IAElB,MAAMC,MAAM,GAAGP,OAAO,CAACC,GAAG,CAACO,2BAA2B,IAAI,EAAE;IAC5D,IAAI,CAACD,MAAM,EAAE;MACT,OAAO;QACHJ;MACJ,CAAC;IACL;IACA,OAAO;MACHA,KAAK,EAAEI,MAAM,GAAGJ;IACpB,CAAC;EACL;AACJ,CAAC;AAAC"}
@@ -19,12 +19,6 @@ var _default = () => ({
19
19
  * We take the raw value, before it was prepared via `transformToStorage` for storage (there might be some transform due to DynamoDB) and store it in the Elasticsearch to be indexed.
20
20
  */
21
21
  return {
22
- /**
23
- * // TODO @Bruno validate and test
24
- * I have no idea why we encoded the raw value. We will see in testing and when upgrading our test projects.
25
- * // TODO remove comments when tested and verified.
26
- */
27
- // value: rawValue ? encodeURIComponent(rawValue) : "",
28
22
  value: Array.isArray(rawValue) ? rawValue : rawValue || ""
29
23
  };
30
24
  },
@@ -38,9 +32,9 @@ var _default = () => ({
38
32
  value
39
33
  }) {
40
34
  if (Array.isArray(value)) {
41
- return value.map(decodeURIComponent);
35
+ return value;
42
36
  }
43
- return value ? decodeURIComponent(value) : "";
37
+ return value || "";
44
38
  }
45
39
  });
46
40
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"names":["type","name","fieldType","toIndex","rawValue","value","Array","isArray","fromIndex","map","decodeURIComponent"],"sources":["longTextIndexing.ts"],"sourcesContent":["import { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\n\n/**\n * The long-text indexing plugin must take in consideration that users might have list of long-text fields.\n * Also, we used to encode values, and we do not do that anymore - but we need to have backward compatibility.\n */\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-long-text\",\n fieldType: \"long-text\",\n toIndex({ rawValue }) {\n /**\n * We take the raw value, before it was prepared via `transformToStorage` for storage (there might be some transform due to DynamoDB) and store it in the Elasticsearch to be indexed.\n */\n return {\n /**\n * // TODO @Bruno validate and test\n * I have no idea why we encoded the raw value. We will see in testing and when upgrading our test projects.\n * // TODO remove comments when tested and verified.\n */\n // value: rawValue ? encodeURIComponent(rawValue) : \"\",\n value: Array.isArray(rawValue) ? rawValue : rawValue || \"\"\n };\n },\n /**\n * When taking value from the index, we can return the original value.\n * At that point the `transformFromStorage` does not need to do anything.\n *\n * We need to decode to support older systems.\n */\n fromIndex({ value }) {\n if (Array.isArray(value)) {\n return value.map(decodeURIComponent);\n }\n return value ? decodeURIComponent(value) : \"\";\n }\n});\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AAHA,eAIe,OAA2C;EACtDA,IAAI,EAAE,mCAAmC;EACzCC,IAAI,EAAE,6CAA6C;EACnDC,SAAS,EAAE,WAAW;EACtBC,OAAO,CAAC;IAAEC;EAAS,CAAC,EAAE;IAClB;AACR;AACA;IACQ,OAAO;MACH;AACZ;AACA;AACA;AACA;MACY;MACAC,KAAK,EAAEC,KAAK,CAACC,OAAO,CAACH,QAAQ,CAAC,GAAGA,QAAQ,GAAGA,QAAQ,IAAI;IAC5D,CAAC;EACL,CAAC;EACD;AACJ;AACA;AACA;AACA;AACA;EACII,SAAS,CAAC;IAAEH;EAAM,CAAC,EAAE;IACjB,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACtB,OAAOA,KAAK,CAACI,GAAG,CAACC,kBAAkB,CAAC;IACxC;IACA,OAAOL,KAAK,GAAGK,kBAAkB,CAACL,KAAK,CAAC,GAAG,EAAE;EACjD;AACJ,CAAC,CAAC;AAAA"}
1
+ {"version":3,"names":["type","name","fieldType","toIndex","rawValue","value","Array","isArray","fromIndex"],"sources":["longTextIndexing.ts"],"sourcesContent":["import { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\n\n/**\n * The long-text indexing plugin must take in consideration that users might have list of long-text fields.\n * Also, we used to encode values, and we do not do that anymore - but we need to have backward compatibility.\n */\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-long-text\",\n fieldType: \"long-text\",\n toIndex({ rawValue }) {\n /**\n * We take the raw value, before it was prepared via `transformToStorage` for storage (there might be some transform due to DynamoDB) and store it in the Elasticsearch to be indexed.\n */\n return {\n value: Array.isArray(rawValue) ? rawValue : rawValue || \"\"\n };\n },\n /**\n * When taking value from the index, we can return the original value.\n * At that point the `transformFromStorage` does not need to do anything.\n *\n * We need to decode to support older systems.\n */\n fromIndex({ value }) {\n if (Array.isArray(value)) {\n return value;\n }\n return value || \"\";\n }\n});\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AAHA,eAIe,OAA2C;EACtDA,IAAI,EAAE,mCAAmC;EACzCC,IAAI,EAAE,6CAA6C;EACnDC,SAAS,EAAE,WAAW;EACtBC,OAAO,CAAC;IAAEC;EAAS,CAAC,EAAE;IAClB;AACR;AACA;IACQ,OAAO;MACHC,KAAK,EAAEC,KAAK,CAACC,OAAO,CAACH,QAAQ,CAAC,GAAGA,QAAQ,GAAGA,QAAQ,IAAI;IAC5D,CAAC;EACL,CAAC;EACD;AACJ;AACA;AACA;AACA;AACA;EACII,SAAS,CAAC;IAAEH;EAAM,CAAC,EAAE;IACjB,IAAIC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,EAAE;MACtB,OAAOA,KAAK;IAChB;IACA,OAAOA,KAAK,IAAI,EAAE;EACtB;AACJ,CAAC,CAAC;AAAA"}
package/index.js CHANGED
@@ -44,6 +44,7 @@ Object.keys(_plugins2).forEach(function (key) {
44
44
  });
45
45
  var _plugins3 = require("./operations/entry/elasticsearch/filtering/plugins");
46
46
  var _CmsEntryFilterPlugin = require("./plugins/CmsEntryFilterPlugin");
47
+ var _apiHeadlessCms = require("@webiny/api-headless-cms");
47
48
  const createStorageOperations = params => {
48
49
  const {
49
50
  attributes,
@@ -140,7 +141,7 @@ const createStorageOperations = params => {
140
141
  // Elasticsearch
141
142
  _apiElasticsearch.CompressionPlugin.type, _apiElasticsearch.ElasticsearchQueryBuilderOperatorPlugin.type,
142
143
  // Headless CMS
143
- "cms-model-field-to-graphql", _CmsEntryFilterPlugin.CmsEntryFilterPlugin.type, _plugins2.CmsEntryElasticsearchBodyModifierPlugin.type, _plugins2.CmsEntryElasticsearchFullTextSearchPlugin.type, _plugins2.CmsEntryElasticsearchIndexPlugin.type, _plugins2.CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type, _plugins2.CmsEntryElasticsearchQueryModifierPlugin.type, _plugins2.CmsEntryElasticsearchSortModifierPlugin.type, _plugins2.CmsEntryElasticsearchFieldPlugin.type];
144
+ "cms-model-field-to-graphql", _CmsEntryFilterPlugin.CmsEntryFilterPlugin.type, _plugins2.CmsEntryElasticsearchBodyModifierPlugin.type, _plugins2.CmsEntryElasticsearchFullTextSearchPlugin.type, _plugins2.CmsEntryElasticsearchIndexPlugin.type, _plugins2.CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type, _plugins2.CmsEntryElasticsearchQueryModifierPlugin.type, _plugins2.CmsEntryElasticsearchSortModifierPlugin.type, _plugins2.CmsElasticsearchModelFieldPlugin.type, _apiHeadlessCms.StorageOperationsCmsModelPlugin.type];
144
145
  for (const type of types) {
145
146
  plugins.mergeByType(context.plugins, type);
146
147
  }
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","tableInstance","createTable","tableElasticsearchInstance","createElasticsearchTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","entriesEs","createEntryElasticsearchEntity","ENTRIES_ES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","createFilterPlugins","name","beforeInit","context","register","types","CompressionPlugin","type","ElasticsearchQueryBuilderOperatorPlugin","CmsEntryFilterPlugin","CmsEntryElasticsearchBodyModifierPlugin","CmsEntryElasticsearchFullTextSearchPlugin","CmsEntryElasticsearchIndexPlugin","CmsEntryElasticsearchQueryBuilderValueSearchPlugin","CmsEntryElasticsearchQueryModifierPlugin","CmsEntryElasticsearchSortModifierPlugin","CmsEntryElasticsearchFieldPlugin","mergeByType","init","cms","onModelBeforeCreate","subscribe","model","createElasticsearchIndex","onModelBeforeCreateFrom","onModelAfterDelete","deleteElasticsearchIndex","onModelInitialize","getEntities","getTable","getEsTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations","esEntity"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport {\n CompressionPlugin,\n ElasticsearchQueryBuilderOperatorPlugin\n} from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\nimport {\n CmsEntryElasticsearchBodyModifierPlugin,\n CmsEntryElasticsearchFullTextSearchPlugin,\n CmsEntryElasticsearchIndexPlugin,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CmsEntryElasticsearchQueryModifierPlugin,\n CmsEntryElasticsearchSortModifierPlugin,\n CmsEntryElasticsearchFieldPlugin\n} from \"~/plugins\";\nimport { createFilterPlugins } from \"~/operations/entry/elasticsearch/filtering/plugins\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n }),\n entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins(),\n /**\n * Filter plugins used to apply filtering from where conditions to Elasticsearch query.\n */\n createFilterPlugins(),\n /**\n * User defined custom plugins.\n * They are at the end because we can then override existing plugins.\n */\n ...(userPlugins || [])\n ]);\n\n return {\n name: \"dynamodb:elasticsearch\",\n beforeInit: async context => {\n /**\n * Attach the elasticsearch into context if it is not already attached.\n */\n if (!context.elasticsearch) {\n context.elasticsearch = elasticsearch;\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n /**\n * We need to fetch all the plugin types in the list from the main container.\n * This way we do not need to register plugins in the storage plugins contains.\n */\n const types: string[] = [\n // Elasticsearch\n CompressionPlugin.type,\n ElasticsearchQueryBuilderOperatorPlugin.type,\n // Headless CMS\n \"cms-model-field-to-graphql\",\n CmsEntryFilterPlugin.type,\n CmsEntryElasticsearchBodyModifierPlugin.type,\n CmsEntryElasticsearchFullTextSearchPlugin.type,\n CmsEntryElasticsearchIndexPlugin.type,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type,\n CmsEntryElasticsearchQueryModifierPlugin.type,\n CmsEntryElasticsearchSortModifierPlugin.type,\n CmsEntryElasticsearchFieldPlugin.type\n ];\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n },\n init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onModelBeforeCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelBeforeCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelAfterDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n\n context.cms.onModelInitialize.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models,\n elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\n"],"mappings":";;;;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zD,MAAM,IAAAC,kDAAwB,EAAC;UAC3BxD,aAAa;UACbuD,KAAK;UACLtD;QACJ,CAAC,CAAC;MACN,CAAC,CAAC;IACN,CAAC;IACD4D,WAAW,EAAE,MAAMtD,QAAQ;IAC3BuD,QAAQ,EAAE,MAAM3D,aAAa;IAC7B4D,UAAU,EAAE,MAAM1D,0BAA0B;IAC5CQ,MAAM,EAAE,IAAAmD,qCAA6B,EAAC;MAClCC,MAAM,EAAE1D,QAAQ,CAACM;IACrB,CAAC,CAAC;IACFL,QAAQ,EAAE,IAAA0D,yCAA+B,EAAC;MACtCD,MAAM,EAAE1D,QAAQ,CAACC;IACrB,CAAC,CAAC;IACFQ,MAAM,EAAE,IAAAmD,qCAA6B,EAAC;MAClCF,MAAM,EAAE1D,QAAQ,CAACS,MAAM;MACvBf;IACJ,CAAC,CAAC;IACFkB,MAAM,EAAE,IAAAiD,oCAA6B,EAAC;MAClCH,MAAM,EAAE1D,QAAQ,CAACY,MAAM;MACvBnB;IACJ,CAAC,CAAC;IACFsB,OAAO,EAAE,IAAA+C,qCAA8B,EAAC;MACpCJ,MAAM,EAAE1D,QAAQ,CAACe,OAAO;MACxBgD,QAAQ,EAAE/D,QAAQ,CAACkB,SAAS;MAC5BxB,OAAO;MACPD;IACJ,CAAC;EACL,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["createStorageOperations","params","attributes","table","esTable","documentClient","elasticsearch","plugins","userPlugins","tableInstance","createTable","tableElasticsearchInstance","createElasticsearchTable","entities","settings","createSettingsEntity","entityName","ENTITIES","SETTINGS","system","createSystemEntity","SYSTEM","groups","createGroupEntity","GROUPS","models","createModelEntity","MODELS","entries","createEntryEntity","ENTRIES","entriesEs","createEntryElasticsearchEntity","ENTRIES_ES","PluginsContainer","dynamoDbValueFilters","dynamoDbPlugins","elasticsearchPlugins","elasticsearchIndexPlugins","createFilterPlugins","name","beforeInit","context","register","types","CompressionPlugin","type","ElasticsearchQueryBuilderOperatorPlugin","CmsEntryFilterPlugin","CmsEntryElasticsearchBodyModifierPlugin","CmsEntryElasticsearchFullTextSearchPlugin","CmsEntryElasticsearchIndexPlugin","CmsEntryElasticsearchQueryBuilderValueSearchPlugin","CmsEntryElasticsearchQueryModifierPlugin","CmsEntryElasticsearchSortModifierPlugin","CmsElasticsearchModelFieldPlugin","StorageOperationsCmsModelPlugin","mergeByType","init","cms","onModelBeforeCreate","subscribe","model","createElasticsearchIndex","onModelBeforeCreateFrom","onModelAfterDelete","deleteElasticsearchIndex","onModelInitialize","getEntities","getTable","getEsTable","createSystemStorageOperations","entity","createSettingsStorageOperations","createGroupsStorageOperations","createModelsStorageOperations","createEntriesStorageOperations","esEntity"],"sources":["index.ts"],"sourcesContent":["import dynamoDbValueFilters from \"@webiny/db-dynamodb/plugins/filters\";\nimport elasticsearchPlugins from \"./elasticsearch\";\nimport dynamoDbPlugins from \"./dynamoDb\";\nimport { createSettingsStorageOperations } from \"./operations/settings\";\nimport { createSystemStorageOperations } from \"./operations/system\";\nimport { createModelsStorageOperations } from \"./operations/model\";\nimport { createEntriesStorageOperations } from \"./operations/entry\";\nimport { ENTITIES, StorageOperationsFactory } from \"~/types\";\nimport { createTable } from \"~/definitions/table\";\nimport { createElasticsearchTable } from \"~/definitions/tableElasticsearch\";\nimport { createGroupEntity } from \"~/definitions/group\";\nimport { createModelEntity } from \"~/definitions/model\";\nimport { createEntryEntity } from \"~/definitions/entry\";\nimport { createEntryElasticsearchEntity } from \"~/definitions/entryElasticsearch\";\nimport { createSystemEntity } from \"~/definitions/system\";\nimport { createSettingsEntity } from \"~/definitions/settings\";\nimport { createElasticsearchIndex } from \"~/elasticsearch/createElasticsearchIndex\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createGroupsStorageOperations } from \"~/operations/group\";\nimport {\n CompressionPlugin,\n ElasticsearchQueryBuilderOperatorPlugin\n} from \"@webiny/api-elasticsearch\";\nimport { elasticsearchIndexPlugins } from \"./elasticsearch/indices\";\nimport { deleteElasticsearchIndex } from \"./elasticsearch/deleteElasticsearchIndex\";\nimport {\n CmsElasticsearchModelFieldPlugin,\n CmsEntryElasticsearchBodyModifierPlugin,\n CmsEntryElasticsearchFullTextSearchPlugin,\n CmsEntryElasticsearchIndexPlugin,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CmsEntryElasticsearchQueryModifierPlugin,\n CmsEntryElasticsearchSortModifierPlugin\n} from \"~/plugins\";\nimport { createFilterPlugins } from \"~/operations/entry/elasticsearch/filtering/plugins\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { StorageOperationsCmsModelPlugin } from \"@webiny/api-headless-cms\";\n\nexport * from \"./plugins\";\n\nexport const createStorageOperations: StorageOperationsFactory = params => {\n const {\n attributes,\n table,\n esTable,\n documentClient,\n elasticsearch,\n plugins: userPlugins\n } = params;\n\n const tableInstance = createTable({\n table,\n documentClient\n });\n const tableElasticsearchInstance = createElasticsearchTable({\n table: esTable,\n documentClient\n });\n\n const entities = {\n settings: createSettingsEntity({\n entityName: ENTITIES.SETTINGS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SETTINGS] : {}\n }),\n system: createSystemEntity({\n entityName: ENTITIES.SYSTEM,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.SYSTEM] : {}\n }),\n groups: createGroupEntity({\n entityName: ENTITIES.GROUPS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.GROUPS] : {}\n }),\n models: createModelEntity({\n entityName: ENTITIES.MODELS,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.MODELS] : {}\n }),\n entries: createEntryEntity({\n entityName: ENTITIES.ENTRIES,\n table: tableInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES] : {}\n }),\n entriesEs: createEntryElasticsearchEntity({\n entityName: ENTITIES.ENTRIES_ES,\n table: tableElasticsearchInstance,\n attributes: attributes ? attributes[ENTITIES.ENTRIES_ES] : {}\n })\n };\n\n const plugins = new PluginsContainer([\n /**\n * DynamoDB filter plugins for the where conditions.\n */\n dynamoDbValueFilters(),\n /**\n * Field plugins for DynamoDB.\n */\n dynamoDbPlugins(),\n /**\n * Field plugins for Elasticsearch.\n */\n elasticsearchPlugins(),\n /**\n * Built-in Elasticsearch index templates.\n */\n elasticsearchIndexPlugins(),\n /**\n * Filter plugins used to apply filtering from where conditions to Elasticsearch query.\n */\n createFilterPlugins(),\n /**\n * User defined custom plugins.\n * They are at the end because we can then override existing plugins.\n */\n ...(userPlugins || [])\n ]);\n\n return {\n name: \"dynamodb:elasticsearch\",\n beforeInit: async context => {\n /**\n * Attach the elasticsearch into context if it is not already attached.\n */\n if (!context.elasticsearch) {\n context.elasticsearch = elasticsearch;\n }\n /**\n * Pass the plugins to the parent context.\n */\n context.plugins.register([dynamoDbPlugins()]);\n /**\n * We need to fetch all the plugin types in the list from the main container.\n * This way we do not need to register plugins in the storage plugins contains.\n */\n const types: string[] = [\n // Elasticsearch\n CompressionPlugin.type,\n ElasticsearchQueryBuilderOperatorPlugin.type,\n // Headless CMS\n \"cms-model-field-to-graphql\",\n CmsEntryFilterPlugin.type,\n CmsEntryElasticsearchBodyModifierPlugin.type,\n CmsEntryElasticsearchFullTextSearchPlugin.type,\n CmsEntryElasticsearchIndexPlugin.type,\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin.type,\n CmsEntryElasticsearchQueryModifierPlugin.type,\n CmsEntryElasticsearchSortModifierPlugin.type,\n CmsElasticsearchModelFieldPlugin.type,\n StorageOperationsCmsModelPlugin.type\n ];\n for (const type of types) {\n plugins.mergeByType(context.plugins, type);\n }\n },\n init: async context => {\n /**\n * We need to create indexes on before model create and on clone (create from).\n * Other apps create indexes on locale creation.\n */\n context.cms.onModelBeforeCreate.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelBeforeCreateFrom.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n context.cms.onModelAfterDelete.subscribe(async ({ model }) => {\n await deleteElasticsearchIndex({\n elasticsearch,\n model\n });\n });\n\n context.cms.onModelInitialize.subscribe(async ({ model }) => {\n await createElasticsearchIndex({\n elasticsearch,\n model,\n plugins\n });\n });\n },\n getEntities: () => entities,\n getTable: () => tableInstance,\n getEsTable: () => tableElasticsearchInstance,\n system: createSystemStorageOperations({\n entity: entities.system\n }),\n settings: createSettingsStorageOperations({\n entity: entities.settings\n }),\n groups: createGroupsStorageOperations({\n entity: entities.groups,\n plugins\n }),\n models: createModelsStorageOperations({\n entity: entities.models,\n elasticsearch\n }),\n entries: createEntriesStorageOperations({\n entity: entities.entries,\n esEntity: entities.entriesEs,\n plugins,\n elasticsearch\n })\n };\n};\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AAaA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AAJA;AACA;AACA;AAIO,MAAMA,uBAAiD,GAAGC,MAAM,IAAI;EACvE,MAAM;IACFC,UAAU;IACVC,KAAK;IACLC,OAAO;IACPC,cAAc;IACdC,aAAa;IACbC,OAAO,EAAEC;EACb,CAAC,GAAGP,MAAM;EAEV,MAAMQ,aAAa,GAAG,IAAAC,kBAAW,EAAC;IAC9BP,KAAK;IACLE;EACJ,CAAC,CAAC;EACF,MAAMM,0BAA0B,GAAG,IAAAC,4CAAwB,EAAC;IACxDT,KAAK,EAAEC,OAAO;IACdC;EACJ,CAAC,CAAC;EAEF,MAAMQ,QAAQ,GAAG;IACbC,QAAQ,EAAE,IAAAC,+BAAoB,EAAC;MAC3BC,UAAU,EAAEC,eAAQ,CAACC,QAAQ;MAC7Bf,KAAK,EAAEM,aAAa;MACpBP,UAAU,EAAEA,UAAU,GAAGA,UAAU,CAACe,eAAQ,CAACC,QAAQ,CAAC,GAA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D,QAAQ,EAAEhE,QAAQ,CAACkB,SAAS;MAC5BxB,OAAO;MACPD;IACJ,CAAC;EACL,CAAC;AACL,CAAC;AAAC"}
@@ -32,7 +32,7 @@ const createElasticsearchBody = ({
32
32
  */
33
33
  const modelFields = (0, _fields.createModelFields)({
34
34
  plugins,
35
- fields: model.fields
35
+ model
36
36
  });
37
37
 
38
38
  /**
@@ -1 +1 @@
1
- {"version":3,"names":["createElasticsearchBody","plugins","model","params","fields","search","term","where","sort","initialSort","after","limit","modelFields","createModelFields","queryModifierPlugins","createQueryModifierPluginList","sortModifierPlugins","createSortModifierPluginList","bodyModifierPlugins","createBodyModifierPluginList","fullTextSearchFields","createFullTextSearchFields","query","createInitialQuery","applyFullTextSearch","execFiltering","createExecFiltering","pl","modifyQuery","createElasticsearchSort","modifySort","boolQuery","must","length","undefined","must_not","should","filter","assignMinimumShouldMatchToQuery","body","bool","size","search_after","track_total_hits","modifyBody"],"sources":["body.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryListParams, CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { createModelFields } from \"./fields\";\nimport { createFullTextSearchFields } from \"./fullTextSearchFields\";\nimport { createInitialQuery } from \"./initialQuery\";\nimport { applyFullTextSearch } from \"./fullTextSearch\";\nimport { createQueryModifierPluginList } from \"./plugins/queryModifier\";\nimport { createSortModifierPluginList } from \"./plugins/sortModifier\";\nimport { createBodyModifierPluginList } from \"./plugins/bodyModifier\";\nimport { createElasticsearchSort } from \"./sort\";\nimport { PrimitiveValue, SearchBody, BoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createExecFiltering } from \"./filtering\";\nimport { assignMinimumShouldMatchToQuery } from \"./assignMinimumShouldMatchToQuery\";\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n params: Omit<CmsEntryListParams, \"where\" | \"after\"> & {\n where: CmsEntryListWhere;\n after?: PrimitiveValue[];\n };\n}\nexport const createElasticsearchBody = ({ plugins, model, params }: Params): SearchBody => {\n const { fields, search: term, where, sort: initialSort, after, limit } = params;\n /**\n * We need the model fields constructed as a key -> field value, so we do not need to iterate through array when we require some field.\n */\n const modelFields = createModelFields({\n plugins,\n fields: model.fields\n });\n\n /**\n * We need the query modifier plugins.\n */\n const queryModifierPlugins = createQueryModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the sort modifier plugins.\n */\n const sortModifierPlugins = createSortModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the body modifier plugins.\n */\n const bodyModifierPlugins = createBodyModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the fields which we can search through via the full text search.\n *\n */\n const fullTextSearchFields = createFullTextSearchFields({\n model,\n term,\n fields\n });\n /**\n * The initial elasticsearch query where we attach some default conditions we always need.\n */\n const query = createInitialQuery({\n where,\n model\n });\n /**\n * Apply the full text search, if term is set.\n */\n applyFullTextSearch({\n model,\n plugins,\n query,\n term,\n fields: fullTextSearchFields\n });\n\n const execFiltering = createExecFiltering({\n model,\n fields: modelFields,\n plugins\n });\n\n execFiltering({\n where,\n query\n });\n\n for (const pl of queryModifierPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSort({\n plugins,\n sort: initialSort,\n modelFields,\n model\n });\n\n for (const pl of sortModifierPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const boolQuery: BoolQueryConfig = {\n must: query.must.length > 0 ? query.must : undefined,\n must_not: query.must_not.length > 0 ? query.must_not : undefined,\n should: query.should.length > 0 ? query.should : undefined,\n filter: query.filter.length > 0 ? query.filter : undefined\n };\n\n assignMinimumShouldMatchToQuery({\n query: boolQuery\n });\n\n const body: SearchBody = {\n query: {\n bool: boolQuery\n },\n sort,\n size: (limit || 0) + 1,\n search_after: after,\n track_total_hits: true\n };\n\n for (const pl of bodyModifierPlugins) {\n pl.modifyBody({\n body,\n model,\n where\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;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A,OAAOgC,IAAI;AACf,CAAC;AAAC"}
1
+ {"version":3,"names":["createElasticsearchBody","plugins","model","params","fields","search","term","where","sort","initialSort","after","limit","modelFields","createModelFields","queryModifierPlugins","createQueryModifierPluginList","sortModifierPlugins","createSortModifierPluginList","bodyModifierPlugins","createBodyModifierPluginList","fullTextSearchFields","createFullTextSearchFields","query","createInitialQuery","applyFullTextSearch","execFiltering","createExecFiltering","pl","modifyQuery","createElasticsearchSort","modifySort","boolQuery","must","length","undefined","must_not","should","filter","assignMinimumShouldMatchToQuery","body","bool","size","search_after","track_total_hits","modifyBody"],"sources":["body.ts"],"sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsEntryListParams, CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { createModelFields } from \"./fields\";\nimport { createFullTextSearchFields } from \"./fullTextSearchFields\";\nimport { createInitialQuery } from \"./initialQuery\";\nimport { applyFullTextSearch } from \"./fullTextSearch\";\nimport { createQueryModifierPluginList } from \"./plugins/queryModifier\";\nimport { createSortModifierPluginList } from \"./plugins/sortModifier\";\nimport { createBodyModifierPluginList } from \"./plugins/bodyModifier\";\nimport { createElasticsearchSort } from \"./sort\";\nimport { PrimitiveValue, SearchBody, BoolQueryConfig } from \"@webiny/api-elasticsearch/types\";\nimport { createExecFiltering } from \"./filtering\";\nimport { assignMinimumShouldMatchToQuery } from \"./assignMinimumShouldMatchToQuery\";\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n params: Omit<CmsEntryListParams, \"where\" | \"after\"> & {\n where: CmsEntryListWhere;\n after?: PrimitiveValue[];\n };\n}\nexport const createElasticsearchBody = ({ plugins, model, params }: Params): SearchBody => {\n const { fields, search: term, where, sort: initialSort, after, limit } = params;\n /**\n * We need the model fields constructed as a key -> field value, so we do not need to iterate through array when we require some field.\n */\n const modelFields = createModelFields({\n plugins,\n model\n });\n\n /**\n * We need the query modifier plugins.\n */\n const queryModifierPlugins = createQueryModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the sort modifier plugins.\n */\n const sortModifierPlugins = createSortModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the body modifier plugins.\n */\n const bodyModifierPlugins = createBodyModifierPluginList({\n plugins,\n model\n });\n /**\n * We need the fields which we can search through via the full text search.\n *\n */\n const fullTextSearchFields = createFullTextSearchFields({\n model,\n term,\n fields\n });\n /**\n * The initial elasticsearch query where we attach some default conditions we always need.\n */\n const query = createInitialQuery({\n where,\n model\n });\n /**\n * Apply the full text search, if term is set.\n */\n applyFullTextSearch({\n model,\n plugins,\n query,\n term,\n fields: fullTextSearchFields\n });\n\n const execFiltering = createExecFiltering({\n model,\n fields: modelFields,\n plugins\n });\n\n execFiltering({\n where,\n query\n });\n\n for (const pl of queryModifierPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSort({\n plugins,\n sort: initialSort,\n modelFields,\n model\n });\n\n for (const pl of sortModifierPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const boolQuery: BoolQueryConfig = {\n must: query.must.length > 0 ? query.must : undefined,\n must_not: query.must_not.length > 0 ? query.must_not : undefined,\n should: query.should.length > 0 ? query.should : undefined,\n filter: query.filter.length > 0 ? query.filter : undefined\n };\n\n assignMinimumShouldMatchToQuery({\n query: boolQuery\n });\n\n const body: SearchBody = {\n query: {\n bool: boolQuery\n },\n sort,\n size: (limit || 0) + 1,\n search_after: after,\n track_total_hits: true\n };\n\n for (const pl of bodyModifierPlugins) {\n pl.modifyBody({\n body,\n model,\n where\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAUO,MAAMA,uBAAuB,GAAG,CAAC;EAAEC,OAAO;EAAEC,KAAK;EAAEC;AAAe,CAAC,KAAiB;EACvF,MAAM;IAAEC,MAAM;IAAEC,MAAM,EAAEC,IAAI;IAAEC,KAAK;IAAEC,IAAI,EAAEC,WAAW;IAAEC,KAAK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AAC;EAEF,KAAK,MAAMyB,EAAE,IAAIX,mBAAmB,EAAE;IAClCW,EAAE,CAACG,UAAU,CAAC;MACVtB,IAAI;MACJN;IACJ,CAAC,CAAC;EACN;EAEA,MAAM6B,SAA0B,GAAG;IAC/BC,IAAI,EAAEV,KAAK,CAACU,IAAI,CAACC,MAAM,GAAG,CAAC,GAAGX,KAAK,CAACU,IAAI,GAAGE,SAAS;IACpDC,QAAQ,EAAEb,KAAK,CAACa,QAAQ,CAACF,MAAM,GAAG,CAAC,GAAGX,KAAK,CAACa,QAAQ,GAAGD,SAAS;IAChEE,MAAM,EAAEd,KAAK,CAACc,MAAM,CAACH,MAAM,GAAG,CAAC,GAAGX,KAAK,CAACc,MAAM,GAAGF,SAAS;IAC1DG,MAAM,EAAEf,KAAK,CAACe,MAAM,CAACJ,MAAM,GAAG,CAAC,GAAGX,KAAK,CAACe,MAAM,GAAGH;EACrD,CAAC;EAED,IAAAI,gEAA+B,EAAC;IAC5BhB,KAAK,EAAES;EACX,CAAC,CAAC;EAEF,MAAMQ,IAAgB,GAAG;IACrBjB,KAAK,EAAE;MACHkB,IAAI,EAAET;IACV,CAAC;IACDvB,IAAI;IACJiC,IAAI,EAAE,CAAC9B,KAAK,IAAI,CAAC,IAAI,CAAC;IACtB+B,YAAY,EAAEhC,KAAK;IACnBiC,gBAAgB,EAAE;EACtB,CAAC;EAED,KAAK,MAAMhB,EAAE,IAAIT,mBAAmB,EAAE;IAClCS,EAAE,CAACiB,UAAU,CAAC;MACVL,IAAI;MACJrC,KAAK;MACLK;IACJ,CAAC,CAAC;EACN;EAEA,OAAOgC,IAAI;AACf,CAAC;AAAC"}
@@ -1,9 +1,10 @@
1
1
  import { PluginsContainer } from "@webiny/plugins";
2
- import { CmsModelField } from "@webiny/api-headless-cms/types";
3
- import { ModelFields } from "./types";
2
+ import { CmsModel } from "@webiny/api-headless-cms/types";
4
3
  interface Params {
5
4
  plugins: PluginsContainer;
6
- fields?: CmsModelField[];
5
+ model: CmsModel;
7
6
  }
8
- export declare const createModelFields: ({ plugins, fields }: Params) => ModelFields;
7
+ export declare const createModelFields: ({ plugins, model }: Params) => {
8
+ [x: string]: import("./types").ModelField;
9
+ };
9
10
  export {};
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.createModelFields = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
9
  var _error = _interopRequireDefault(require("@webiny/error"));
10
+ var _plugins = require("../../../plugins");
10
11
  const createSystemField = field => {
11
12
  return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, field), {}, {
12
13
  id: field.fieldId,
@@ -17,9 +18,9 @@ const createSystemFields = () => {
17
18
  return {
18
19
  id: {
19
20
  type: "text",
20
- isSystemField: true,
21
- isSearchable: true,
22
- isSortable: true,
21
+ systemField: true,
22
+ searchable: true,
23
+ sortable: true,
23
24
  field: createSystemField({
24
25
  storageId: "id",
25
26
  fieldId: "id",
@@ -29,9 +30,9 @@ const createSystemFields = () => {
29
30
  },
30
31
  entryId: {
31
32
  type: "text",
32
- isSystemField: true,
33
- isSearchable: true,
34
- isSortable: true,
33
+ systemField: true,
34
+ searchable: true,
35
+ sortable: true,
35
36
  field: createSystemField({
36
37
  storageId: "entryId",
37
38
  fieldId: "entryId",
@@ -43,9 +44,9 @@ const createSystemFields = () => {
43
44
  type: "date",
44
45
  unmappedType: "date",
45
46
  keyword: false,
46
- isSystemField: true,
47
- isSearchable: true,
48
- isSortable: true,
47
+ systemField: true,
48
+ searchable: true,
49
+ sortable: true,
49
50
  field: createSystemField({
50
51
  storageId: "savedOn",
51
52
  fieldId: "savedOn",
@@ -60,9 +61,9 @@ const createSystemFields = () => {
60
61
  type: "date",
61
62
  unmappedType: "date",
62
63
  keyword: false,
63
- isSystemField: true,
64
- isSearchable: true,
65
- isSortable: true,
64
+ systemField: true,
65
+ searchable: true,
66
+ sortable: true,
66
67
  field: createSystemField({
67
68
  storageId: "createdOn",
68
69
  fieldId: "createdOn",
@@ -76,9 +77,9 @@ const createSystemFields = () => {
76
77
  createdBy: {
77
78
  type: "text",
78
79
  unmappedType: undefined,
79
- isSystemField: true,
80
- isSearchable: true,
81
- isSortable: false,
80
+ systemField: true,
81
+ searchable: true,
82
+ sortable: false,
82
83
  path: "createdBy.id",
83
84
  field: createSystemField({
84
85
  storageId: "createdBy",
@@ -90,9 +91,9 @@ const createSystemFields = () => {
90
91
  ownedBy: {
91
92
  type: "text",
92
93
  unmappedType: undefined,
93
- isSystemField: true,
94
- isSearchable: true,
95
- isSortable: false,
94
+ systemField: true,
95
+ searchable: true,
96
+ sortable: false,
96
97
  path: "ownedBy.id",
97
98
  field: createSystemField({
98
99
  storageId: "ownedBy",
@@ -105,9 +106,9 @@ const createSystemFields = () => {
105
106
  type: "number",
106
107
  unmappedType: undefined,
107
108
  keyword: false,
108
- isSystemField: true,
109
- isSearchable: true,
110
- isSortable: true,
109
+ systemField: true,
110
+ searchable: true,
111
+ sortable: true,
111
112
  field: createSystemField({
112
113
  storageId: "version",
113
114
  fieldId: "version",
@@ -119,9 +120,9 @@ const createSystemFields = () => {
119
120
  type: "string",
120
121
  unmappedType: undefined,
121
122
  keyword: false,
122
- isSystemField: true,
123
- isSearchable: true,
124
- isSortable: false,
123
+ systemField: true,
124
+ searchable: true,
125
+ sortable: false,
125
126
  field: createSystemField({
126
127
  storageId: "status",
127
128
  fieldId: "status",
@@ -131,6 +132,38 @@ const createSystemFields = () => {
131
132
  }
132
133
  };
133
134
  };
135
+ const buildCustomFields = params => {
136
+ const {
137
+ fields,
138
+ fieldTypePlugins
139
+ } = params;
140
+ return fields.reduce((collection, field) => {
141
+ const typePlugin = fieldTypePlugins[field.fieldType];
142
+ if (!typePlugin) {
143
+ return collection;
144
+ }
145
+ let unmappedType = undefined;
146
+ if (typePlugin.unmappedType) {
147
+ unmappedType = typePlugin.unmappedType(field);
148
+ }
149
+ collection[field.fieldId] = {
150
+ type: field.fieldType,
151
+ field: createSystemField({
152
+ storageId: field.fieldId,
153
+ fieldId: field.fieldId,
154
+ type: field.fieldType
155
+ }),
156
+ unmappedType,
157
+ fullTextSearch: field.searchable ? typePlugin.fullTextSearch : false,
158
+ searchable: field.searchable || typePlugin.searchable,
159
+ sortable: field.sortable || typePlugin.sortable,
160
+ systemField: false,
161
+ path: field.path,
162
+ parents: []
163
+ };
164
+ return collection;
165
+ }, {});
166
+ };
134
167
  const buildFieldsList = params => {
135
168
  const {
136
169
  plugins,
@@ -144,8 +177,8 @@ const buildFieldsList = params => {
144
177
  throw new _error.default(`There is no plugin for field type "${field.type}".`);
145
178
  }
146
179
  const {
147
- isSearchable,
148
- isSortable,
180
+ searchable,
181
+ sortable,
149
182
  unmappedType,
150
183
  fullTextSearch
151
184
  } = plugin;
@@ -166,20 +199,17 @@ const buildFieldsList = params => {
166
199
  type: field.type
167
200
  }]
168
201
  });
169
- /**
170
- *
171
- */
172
202
  Object.assign(result, childResult);
173
203
  }
174
204
  const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(".");
175
205
  result[identifier] = {
176
206
  type: field.type,
177
207
  parents,
178
- isSearchable,
179
- isSortable,
208
+ searchable,
209
+ sortable,
180
210
  fullTextSearch,
181
211
  unmappedType: typeof unmappedType === "function" ? unmappedType(field) : undefined,
182
- isSystemField: false,
212
+ systemField: false,
183
213
  field
184
214
  };
185
215
  return result;
@@ -187,11 +217,12 @@ const buildFieldsList = params => {
187
217
  };
188
218
  const createModelFields = ({
189
219
  plugins,
190
- fields
220
+ model
191
221
  }) => {
192
- if (!fields || fields.length === 0) {
193
- return createSystemFields();
194
- }
222
+ const fields = model.fields;
223
+ const fieldDefinitionPlugins = plugins.byType(_plugins.CmsElasticsearchModelFieldPlugin.type).filter(plugin => {
224
+ return plugin.canBeApplied(model.modelId);
225
+ });
195
226
  /**
196
227
  * Collect all unmappedType from elastic plugins.
197
228
  */
@@ -208,19 +239,20 @@ const createModelFields = ({
208
239
  const fieldTypePlugins = plugins.byType("cms-model-field-to-graphql").reduce((types, plugin) => {
209
240
  const {
210
241
  fieldType,
211
- isSearchable,
212
- isSortable,
213
242
  fullTextSearch
214
243
  } = plugin;
215
244
  types[fieldType] = {
216
245
  unmappedType: unmappedTypes[fieldType],
217
- isSearchable,
218
- isSortable,
246
+ searchable: plugin.isSearchable,
247
+ sortable: plugin.isSortable,
219
248
  fullTextSearch
220
249
  };
221
250
  return types;
222
251
  }, {});
223
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, createSystemFields()), buildFieldsList({
252
+ return (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, createSystemFields()), buildCustomFields({
253
+ fields: fieldDefinitionPlugins,
254
+ fieldTypePlugins
255
+ })), buildFieldsList({
224
256
  fields,
225
257
  plugins: fieldTypePlugins,
226
258
  parents: []
@@ -1 +1 @@
1
- {"version":3,"names":["createSystemField","field","id","fieldId","label","createSystemFields","type","isSystemField","isSearchable","isSortable","storageId","parents","entryId","savedOn","unmappedType","keyword","settings","createdOn","createdBy","undefined","path","ownedBy","version","status","buildFieldsList","params","plugins","fields","reduce","result","plugin","WebinyError","fullTextSearch","childFields","length","childResult","Object","assign","identifier","map","p","join","createModelFields","unmappedTypes","byType","acc","fieldType","fieldTypePlugins","types"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { CmsModelField, CmsModelFieldToGraphQLPlugin } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { ModelFieldParent, ModelFields } from \"./types\";\n\ntype PartialCmsModelField = Partial<CmsModelField> &\n Pick<CmsModelField, \"storageId\" | \"fieldId\" | \"type\">;\nconst createSystemField = (field: PartialCmsModelField): CmsModelField => {\n return {\n ...field,\n id: field.fieldId,\n label: field.fieldId\n };\n};\n\nconst createSystemFields = (): ModelFields => {\n return {\n id: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n savedOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n type: \"datetime\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"createdBy.id\",\n field: createSystemField({\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n type: \"text\"\n }),\n parents: []\n },\n ownedBy: {\n type: \"text\",\n unmappedType: undefined,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n path: \"ownedBy.id\",\n field: createSystemField({\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n type: \"text\"\n }),\n parents: []\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n isSystemField: true,\n isSearchable: true,\n isSortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: CmsModelField) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: CmsModelField) => string | undefined;\n isSearchable: boolean;\n isSortable: boolean;\n fullTextSearch?: boolean;\n}\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const plugin = plugins[field.type];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { isSearchable, isSortable, unmappedType, fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: field.type\n }\n ]\n });\n /**\n *\n */\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: field.type,\n parents,\n isSearchable,\n isSortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n isSystemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface Params {\n plugins: PluginsContainer;\n fields?: CmsModelField[];\n}\nexport const createModelFields = ({ plugins, fields }: Params) => {\n if (!fields || fields.length === 0) {\n return createSystemFields();\n }\n /**\n * Collect all unmappedType from elastic plugins.\n */\n const unmappedTypes = plugins\n .byType<CmsModelFieldToElasticsearchPlugin>(\"cms-model-field-to-elastic-search\")\n .reduce<UnmappedFieldTypes>((acc, plugin) => {\n if (!plugin.unmappedType) {\n return acc;\n }\n acc[plugin.fieldType] = plugin.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce<FieldTypePlugins>((types, plugin) => {\n const { fieldType, isSearchable, isSortable, fullTextSearch } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n isSearchable,\n isSortable,\n fullTextSearch\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildFieldsList({\n fields,\n plugins: fieldTypePlugins,\n parents: []\n })\n };\n};\n"],"mappings":";;;;;;;;AAAA;AAQA,MAAMA,iBAAiB,GAAIC,KAA2B,IAAoB;EACtE,mEACOA,KAAK;IACRC,EAAE,EAAED,KAAK,CAACE,OAAO;IACjBC,KAAK,EAAEH,KAAK,CAACE;EAAO;AAE5B,CAAC;AAED,MAAME,kBAAkB,GAAG,MAAmB;EAC1C,OAAO;IACHH,EAAE,EAAE;MACAI,IAAI,EAAE,MAAM;MACZC,aAAa,EAAE,IAAI;MACnBC,YAAY,EAAE,IAAI;MAClBC,UAAU,EAAE,IAAI;MAChBR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAAE,IAAI;QACfP,OAAO,EAAE,IAAI;QACbG,IAAI,EAAE;MACV,CAAC,CAAC;MACFK,OAAO,EAAE;IACb,CAAC;IACDC,OAAO,EAAE;MACLN,IAAI,EAAE,MAAM;MACZC,aAAa,EAAE,IAAI;MACnBC,YAAY,EAAE,IAAI;MAClBC,UAAU,EAAE,IAAI;MAChBR,KAAK,EAAED,iBAAiB,CAAC;QACrBU,SAAS,EAAE,SAAS;QACpBP,OAAO,EAAE,SAAS;QAClBG,IAAI,EAAE;MACV,CAAC,CAAC;MACFK,OAAO,EAAE;IACb,CAAC;IACDE,OAAO,EAAE;MACLP,IAAI,EAAE,MAAM;MACZQ,YAAY,EAAE,MAAM;MACpBC,OAAO,EAAE,KAAK;MACdR,aAAa,EAAE,IAAI;MACnBC,YAAY,EAAE,IAAI;MAClBC,UAAU,EAAE,IAAI;MAChBR,KAAK,EAAED,iBAAiB,CAAC;QACr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f,MAAM,CAACgB,SAAS,CAAC,GAAGhB,MAAM,CAAChB,YAAY;IAC3C,OAAO+B,GAAG;EACd,CAAC,EAAE,CAAC,CAAC,CAAC;EACV;AACJ;AACA;EACI,MAAME,gBAAgB,GAAGrB,OAAO,CAC3BkB,MAAM,CAA+B,4BAA4B,CAAC,CAClEhB,MAAM,CAAmB,CAACoB,KAAK,EAAElB,MAAM,KAAK;IACzC,MAAM;MAAEgB,SAAS;MAAEtC,YAAY;MAAEC,UAAU;MAAEuB;IAAe,CAAC,GAAGF,MAAM;IACtEkB,KAAK,CAACF,SAAS,CAAC,GAAG;MACfhC,YAAY,EAAE6B,aAAa,CAACG,SAAS,CAAC;MACtCtC,YAAY;MACZC,UAAU;MACVuB;IACJ,CAAC;IACD,OAAOgB,KAAK;EAChB,CAAC,EAAE,CAAC,CAAC,CAAC;EAEV,mEACO3C,kBAAkB,EAAE,GACpBmB,eAAe,CAAC;IACfG,MAAM;IACND,OAAO,EAAEqB,gBAAgB;IACzBpC,OAAO,EAAE;EACb,CAAC,CAAC;AAEV,CAAC;AAAC"}
1
+ {"version":3,"names":["createSystemField","field","id","fieldId","label","createSystemFields","type","systemField","searchable","sortable","storageId","parents","entryId","savedOn","unmappedType","keyword","settings","createdOn","createdBy","undefined","path","ownedBy","version","status","buildCustomFields","params","fields","fieldTypePlugins","reduce","collection","typePlugin","fieldType","fullTextSearch","buildFieldsList","plugins","result","plugin","WebinyError","childFields","length","childResult","Object","assign","identifier","map","p","join","createModelFields","model","fieldDefinitionPlugins","byType","CmsElasticsearchModelFieldPlugin","filter","canBeApplied","modelId","unmappedTypes","acc","types","isSearchable","isSortable"],"sources":["fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin\n} from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport { ModelFieldParent, ModelFields } from \"./types\";\nimport { CmsElasticsearchModelFieldPlugin } from \"~/plugins\";\n\ntype PartialCmsModelField = Partial<CmsModelField> &\n Pick<CmsModelField, \"storageId\" | \"fieldId\" | \"type\">;\nconst createSystemField = (field: PartialCmsModelField): CmsModelField => {\n return {\n ...field,\n id: field.fieldId,\n label: field.fieldId\n };\n};\n\nconst createSystemFields = (): ModelFields => {\n return {\n id: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n savedOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"savedOn\",\n fieldId: \"savedOn\",\n type: \"datetime\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdOn: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"createdOn\",\n fieldId: \"createdOn\",\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n },\n createdBy: {\n type: \"text\",\n unmappedType: undefined,\n systemField: true,\n searchable: true,\n sortable: false,\n path: \"createdBy.id\",\n field: createSystemField({\n storageId: \"createdBy\",\n fieldId: \"createdBy\",\n type: \"text\"\n }),\n parents: []\n },\n ownedBy: {\n type: \"text\",\n unmappedType: undefined,\n systemField: true,\n searchable: true,\n sortable: false,\n path: \"ownedBy.id\",\n field: createSystemField({\n storageId: \"ownedBy\",\n fieldId: \"ownedBy\",\n type: \"text\"\n }),\n parents: []\n },\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n }\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n searchable: boolean;\n sortable: boolean;\n fullTextSearch?: boolean;\n}\n\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildCustomFieldsParams {\n fields: CmsElasticsearchModelFieldPlugin[];\n fieldTypePlugins: FieldTypePlugins;\n}\n\nconst buildCustomFields = (params: BuildCustomFieldsParams) => {\n const { fields, fieldTypePlugins } = params;\n\n return fields.reduce<ModelFields>((collection, field) => {\n const typePlugin = fieldTypePlugins[field.fieldType];\n if (!typePlugin) {\n return collection;\n }\n let unmappedType: string | undefined = undefined;\n if (typePlugin.unmappedType) {\n unmappedType = typePlugin.unmappedType(field);\n }\n\n collection[field.fieldId] = {\n type: field.fieldType,\n field: createSystemField({\n storageId: field.fieldId,\n fieldId: field.fieldId,\n type: field.fieldType\n }),\n unmappedType,\n fullTextSearch: field.searchable ? typePlugin.fullTextSearch : false,\n searchable: field.searchable || typePlugin.searchable,\n sortable: field.sortable || typePlugin.sortable,\n systemField: false,\n path: field.path,\n parents: []\n };\n\n return collection;\n }, {});\n};\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\n\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const plugin = plugins[field.type];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { searchable, sortable, unmappedType, fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: field.type\n }\n ]\n });\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: field.type,\n parents,\n searchable,\n sortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n systemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface Params {\n plugins: PluginsContainer;\n model: CmsModel;\n}\n\nexport const createModelFields = ({ plugins, model }: Params) => {\n const fields = model.fields;\n const fieldDefinitionPlugins = plugins\n .byType<CmsElasticsearchModelFieldPlugin>(CmsElasticsearchModelFieldPlugin.type)\n .filter(plugin => {\n return plugin.canBeApplied(model.modelId);\n });\n /**\n * Collect all unmappedType from elastic plugins.\n */\n const unmappedTypes = plugins\n .byType<CmsModelFieldToElasticsearchPlugin>(\"cms-model-field-to-elastic-search\")\n .reduce<UnmappedFieldTypes>((acc, plugin) => {\n if (!plugin.unmappedType) {\n return acc;\n }\n acc[plugin.fieldType] = plugin.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = plugins\n .byType<CmsModelFieldToGraphQLPlugin>(\"cms-model-field-to-graphql\")\n .reduce<FieldTypePlugins>((types, plugin) => {\n const { fieldType, fullTextSearch } = plugin;\n types[fieldType] = {\n unmappedType: unmappedTypes[fieldType],\n searchable: plugin.isSearchable,\n sortable: plugin.isSortable,\n fullTextSearch\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildCustomFields({\n fields: fieldDefinitionPlugins,\n fieldTypePlugins\n }),\n ...buildFieldsList({\n fields,\n pl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IACzC,MAAM;MAAEL,SAAS;MAAEC;IAAe,CAAC,GAAGI,MAAM;IAC5CqB,KAAK,CAAC1B,SAAS,CAAC,GAAG;MACfjB,YAAY,EAAEyC,aAAa,CAACxB,SAAS,CAAC;MACtCvB,UAAU,EAAE4B,MAAM,CAACsB,YAAY;MAC/BjD,QAAQ,EAAE2B,MAAM,CAACuB,UAAU;MAC3B3B;IACJ,CAAC;IACD,OAAOyB,KAAK;EAChB,CAAC,EAAE,CAAC,CAAC,CAAC;EAEV,+FACOpD,kBAAkB,EAAE,GACpBmB,iBAAiB,CAAC;IACjBE,MAAM,EAAEuB,sBAAsB;IAC9BtB;EACJ,CAAC,CAAC,GACCM,eAAe,CAAC;IACfP,MAAM;IACNQ,OAAO,EAAEP,gBAAgB;IACzBhB,OAAO,EAAE;EACb,CAAC,CAAC;AAEV,CAAC;AAAC"}
@@ -146,7 +146,7 @@ const createExecFiltering = params => {
146
146
  */
147
147
  const cmsModelField = model.fields.find(f => f.fieldId === fieldId);
148
148
  if (!cmsModelField && !fields[fieldId]) {
149
- throw new _error.default(`There is no CMS Model Field field "${fieldId}".`);
149
+ throw new _error.default(`There is no CMS Model Field "${fieldId}".`);
150
150
  } else if (cmsModelField) {
151
151
  fieldId = cmsModelField.fieldId;
152
152
  }
@@ -1 +1 @@
1
- {"version":3,"names":["createExecFiltering","params","fields","plugins","model","searchPlugins","createSearchPluginList","operatorPlugins","createOperatorPluginList","locale","applyFiltering","createApplyFiltering","filteringPlugins","byType","CmsEntryFilterPlugin","type","reduce","collection","plugin","fieldType","getFilterPlugin","WebinyError","execFiltering","where","initialWhere","query","keys","Object","length","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","filter","push","bool","should","assignMinimumShouldMatchToQuery","field","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","find","f","filterPlugin","exec"],"sources":["exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { ModelFields } from \"~/operations/entry/elasticsearch/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ElasticsearchBoolQueryConfig, Query } from \"@webiny/api-elasticsearch/types\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\nimport { getWhereValues } from \"./values\";\nimport { getPopulated } from \"./populated\";\nimport { createApplyFiltering } from \"./applyFiltering\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n}\nexport interface ExecParams {\n where: CmsEntryListWhere;\n query: ElasticsearchBoolQueryConfig;\n}\nexport interface CreateExecFilteringResponse {\n (params: ExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model } = params;\n\n /**\n * We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.\n */\n const searchPlugins = createSearchPluginList({\n plugins\n });\n /**\n * We need the operator plugins, which we execute on our where conditions.\n */\n const operatorPlugins = createOperatorPluginList({\n plugins,\n locale: model.locale\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n searchPlugins\n });\n\n const filteringPlugins = plugins\n .byType<CmsEntryFilterPlugin>(CmsEntryFilterPlugin.type)\n .reduce<Record<string, CmsEntryFilterPlugin>>((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {});\n\n const getFilterPlugin = (type: string) => {\n const plugin = filteringPlugins[type] || filteringPlugins[\"*\"];\n if (plugin) {\n return plugin;\n }\n throw new WebinyError(\n `There is no filtering plugin for the given field type \"${type}\".`,\n \"FILTERING_PLUGIN_ERROR\",\n {\n type\n }\n );\n };\n\n const execFiltering = (params: ExecParams) => {\n const { where: initialWhere, query } = params;\n /**\n * No point in continuing if no \"where\" conditions exist.\n */\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n for (const key in where) {\n const value = where[key] as unknown as any;\n /**\n * We always skip if no value is defined.\n * Only skip undefined value, null is valid.\n */\n if (value === undefined) {\n continue;\n }\n //\n /**\n * When we are running with AND, the \"value\" MUST be an array.\n */\n else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n\n const childQuery = createBaseQuery();\n\n for (const childWhere of childWhereList) {\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({\n bool: childQueryBool\n });\n\n continue;\n }\n //\n /**\n * When we are running with OR, the \"value\" must be an array.\n */\n else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n /**\n * Each of the conditions MUST produce it's own should section.\n */\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({\n bool: childQueryBool\n });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n /**\n * If there are any should, minimum to have is 1.\n * Of course, do not override if it's already set.\n */\n assignMinimumShouldMatchToQuery({\n query\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n\n let fieldId: string = whereFieldId;\n\n /**\n * TODO This will be required until the storage operations receive the fieldId instead of field storageId.\n * TODO For this to work without field searching, we need to refactor how the query looks like.\n *\n * Storage operations should NEVER receive an field storageId, only alias - fieldId.\n */\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(`There is no field \"${fieldId}\".`);\n }\n const filterPlugin = getFilterPlugin(field.type);\n\n filterPlugin.exec({\n applyFiltering,\n getFilterPlugin,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n return execFiltering;\n};\n"],"mappings":";;;;;;;;AAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAcO,MAAMA,mBAAmB,GAAIC,MAAwB,IAAkC;EAC1F,MAAM;IAAEC,MAAM;IAAEC,OAAO;IAAEC;EAAM,CAAC,GAAGH,MAAM;;EAEzC;AACJ;AACA;EACI,MAAMI,aAAa,GAAG,IAAAC,8BAAsB,EAAC;IACzCH;EACJ,CAAC,CAAC;EACF;AACJ;AACA;EACI,MAAMI,eAAe,GAAG,IAAAC,kCAAwB,EAAC;IAC7CL,OAAO;IACPM,MAAM,EAAEL,KAAK,CAACK;EAClB,CAAC,CAAC;EAEF,MAAMC,cAAc,GAAG,IAAAC,oCAAoB,EAAC;IACxCJ,eAAe;IACfF;EACJ,CAAC,CAAC;EAEF,MAAMO,gBAAgB,GAAGT,OAAO,CAC3BU,MAAM,CAAuBC,0CAAoB,CAACC,IAAI,CAAC,CACvDC,MAAM,CAAuC,CAACC,UAAU,EAAEC,MAAM,KAAK;IAClED,UAAU,CAACC,MAAM,CAACC,SAAS,CAAC,GAAGD,MAAM;IAErC,OAAOD,UAAU;EACrB,CAAC,EAAE,CAAC,CAAC,CAAC;EAEV,MAAMG,eAAe,GAAIL,IAAY,IAAK;IACtC,MAAMG,MAAM,GAAGN,gBAAgB,CAACG,IAAI,CAAC,IAAIH,gBAAgB,CAAC,GAAG,CAAC;IAC9D,IAAIM,MAAM,EAAE;MACR,OAAOA,MAAM;IACjB;IAC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C7B,IAAI,CAACJ,KAAK,EAAE;QACR,MAAM,IAAIvB,cAAW,CAAE,sBAAqB2B,OAAQ,IAAG,CAAC;MAC5D;MACA,MAAMI,YAAY,GAAGhC,eAAe,CAACwB,KAAK,CAAC7B,IAAI,CAAC;MAEhDqC,YAAY,CAACC,IAAI,CAAC;QACd3C,cAAc;QACdU,eAAe;QACfS,GAAG;QACHC,KAAK;QACLgB,QAAQ;QACRF,KAAK;QACL1C,MAAM;QACNuB;MACJ,CAAC,CAAC;IACN;EACJ,CAAC;EAED,OAAOH,aAAa;AACxB,CAAC;AAAC"}
1
+ {"version":3,"names":["createExecFiltering","params","fields","plugins","model","searchPlugins","createSearchPluginList","operatorPlugins","createOperatorPluginList","locale","applyFiltering","createApplyFiltering","filteringPlugins","byType","CmsEntryFilterPlugin","type","reduce","collection","plugin","fieldType","getFilterPlugin","WebinyError","execFiltering","where","initialWhere","query","keys","Object","length","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","filter","push","bool","should","assignMinimumShouldMatchToQuery","field","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","find","f","filterPlugin","exec"],"sources":["exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types\";\nimport { ModelFields } from \"~/operations/entry/elasticsearch/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ElasticsearchBoolQueryConfig, Query } from \"@webiny/api-elasticsearch/types\";\nimport { createSearchPluginList } from \"~/operations/entry/elasticsearch/plugins/search\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch\";\nimport { getWhereValues } from \"./values\";\nimport { getPopulated } from \"./populated\";\nimport { createApplyFiltering } from \"./applyFiltering\";\nimport { CmsEntryFilterPlugin } from \"~/plugins/CmsEntryFilterPlugin\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n plugins: PluginsContainer;\n}\nexport interface ExecParams {\n where: CmsEntryListWhere;\n query: ElasticsearchBoolQueryConfig;\n}\nexport interface CreateExecFilteringResponse {\n (params: ExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, plugins, model } = params;\n\n /**\n * We need the search plugins as key -> plugin value, so it is easy to find plugin we need, without iterating through array.\n */\n const searchPlugins = createSearchPluginList({\n plugins\n });\n /**\n * We need the operator plugins, which we execute on our where conditions.\n */\n const operatorPlugins = createOperatorPluginList({\n plugins,\n locale: model.locale\n });\n\n const applyFiltering = createApplyFiltering({\n operatorPlugins,\n searchPlugins\n });\n\n const filteringPlugins = plugins\n .byType<CmsEntryFilterPlugin>(CmsEntryFilterPlugin.type)\n .reduce<Record<string, CmsEntryFilterPlugin>>((collection, plugin) => {\n collection[plugin.fieldType] = plugin;\n\n return collection;\n }, {});\n\n const getFilterPlugin = (type: string) => {\n const plugin = filteringPlugins[type] || filteringPlugins[\"*\"];\n if (plugin) {\n return plugin;\n }\n throw new WebinyError(\n `There is no filtering plugin for the given field type \"${type}\".`,\n \"FILTERING_PLUGIN_ERROR\",\n {\n type\n }\n );\n };\n\n const execFiltering = (params: ExecParams) => {\n const { where: initialWhere, query } = params;\n /**\n * No point in continuing if no \"where\" conditions exist.\n */\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n for (const key in where) {\n const value = where[key] as unknown as any;\n /**\n * We always skip if no value is defined.\n * Only skip undefined value, null is valid.\n */\n if (value === undefined) {\n continue;\n }\n //\n /**\n * When we are running with AND, the \"value\" MUST be an array.\n */\n else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n\n const childQuery = createBaseQuery();\n\n for (const childWhere of childWhereList) {\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({\n bool: childQueryBool\n });\n\n continue;\n }\n //\n /**\n * When we are running with OR, the \"value\" must be an array.\n */\n else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n /**\n * Each of the conditions MUST produce it's own should section.\n */\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({\n query: childQuery,\n where: childWhere\n });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({\n bool: childQueryBool\n });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n /**\n * If there are any should, minimum to have is 1.\n * Of course, do not override if it's already set.\n */\n assignMinimumShouldMatchToQuery({\n query\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n\n let fieldId: string = whereFieldId;\n\n /**\n * TODO This will be required until the storage operations receive the fieldId instead of field storageId.\n * TODO For this to work without field searching, we need to refactor how the query looks like.\n *\n * Storage operations should NEVER receive an field storageId, only alias - fieldId.\n */\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(`There is no field \"${fieldId}\".`);\n }\n const filterPlugin = getFilterPlugin(field.type);\n\n filterPlugin.exec({\n applyFiltering,\n getFilterPlugin,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n return execFiltering;\n};\n"],"mappings":";;;;;;;;AAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAcO,MAAMA,mBAAmB,GAAIC,MAAwB,IAAkC;EAC1F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field.isSystemField) {
33
+ if (!field.systemField) {
34
34
  result.push("values");
35
35
  }
36
36
  result.push(...field.parents.map(p => p.storageId));
@@ -1 +1 @@
1
- {"version":3,"names":["createFieldPathFactory","plugins","params","field","key","value","keyword","plugin","type","fieldPath","createPath","storageId","path","result","isSystemField","push","parents","map","p","basePath","join","concat"],"sources":["path.ts"],"sourcesContent":["import {\n ElasticsearchQuerySearchValuePlugins,\n ModelField\n} from \"~/operations/entry/elasticsearch/types\";\n\ninterface FieldPathFactoryParams {\n plugins: ElasticsearchQuerySearchValuePlugins;\n}\ninterface FieldPathParams {\n field: ModelField;\n key: string;\n value: any;\n keyword: boolean;\n}\n\nexport const createFieldPathFactory = ({ plugins }: FieldPathFactoryParams) => {\n return (params: FieldPathParams) => {\n const { field, key, value, keyword } = params;\n const plugin = plugins[field.type];\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field: field.field, value, key });\n }\n if (!fieldPath) {\n fieldPath = field.field.storageId;\n if (field.path) {\n fieldPath = typeof field.path === \"function\" ? field.path(value) : field.path;\n }\n }\n\n const result: string[] = [];\n if (!field.isSystemField) {\n result.push(\"values\");\n }\n result.push(...field.parents.map(p => p.storageId));\n result.push(fieldPath);\n\n return {\n basePath: result.join(\".\"),\n path: result.concat(keyword ? [\"keyword\"] : []).join(\".\")\n };\n };\n};\n"],"mappings":";;;;;;AAeO,MAAMA,sBAAsB,GAAG,CAAC;EAAEC;AAAgC,CAAC,KAAK;EAC3E,OAAQC,MAAuB,IAAK;IAChC,MAAM;MAAEC,KAAK;MAAEC,GAAG;MAAEC,KAAK;MAAEC;IAAQ,CAAC,GAAGJ,MAAM;IAC7C,MAAMK,MAAM,GAAGN,OAAO,CAACE,KAAK,CAACK,IAAI,CAAC;IAElC,IAAIC,SAAwB,GAAG,IAAI;IACnC,IAAIF,MAAM,EAAE;MACRE,SAAS,GAAGF,MAAM,CAACG,UAAU,CAAC;QAAEP,KAAK,EAAEA,KAAK,CAACA,KAAK;QAAEE,KAAK;QAAED;MAAI,CAAC,CAAC;IACrE;IACA,IAAI,CAACK,SAAS,EAAE;MACZA,SAAS,GAAGN,KAAK,CAACA,KAAK,CAACQ,SAAS;MACjC,IAAIR,KAAK,CAACS,IAAI,EAAE;QACZH,SAAS,GAAG,OAAON,KAAK,CAACS,IAAI,KAAK,UAAU,GAAGT,KAAK,CAACS,IAAI,CAACP,KAAK,CAAC,GAAGF,KAAK,CAACS,IAAI;MACjF;IACJ;IAEA,MAAMC,MAAgB,GAAG,EAAE;IAC3B,IAAI,CAACV,KAAK,CAACW,aAAa,EAAE;MACtBD,MAAM,CAACE,IAAI,CAAC,QAAQ,CAAC;IACzB;IACAF,MAAM,CAACE,IAAI,CAAC,GAAGZ,KAAK,CAACa,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACP,SAAS,CAAC,CAAC;IACnDE,MAAM,CAACE,IAAI,CAACN,SAAS,CAAC;IAEtB,OAAO;MACHU,QAAQ,EAAEN,MAAM,CAACO,IAAI,CAAC,GAAG,CAAC;MAC1BR,IAAI,EAAEC,MAAM,CAACQ,MAAM,CAACf,OAAO,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,CAACc,IAAI,CAAC,GAAG;IAC5D,CAAC;EACL,CAAC;AACL,CAAC;AAAC"}
1
+ {"version":3,"names":["createFieldPathFactory","plugins","params","field","key","value","keyword","plugin","type","fieldPath","createPath","storageId","path","result","systemField","push","parents","map","p","basePath","join","concat"],"sources":["path.ts"],"sourcesContent":["import {\n ElasticsearchQuerySearchValuePlugins,\n ModelField\n} from \"~/operations/entry/elasticsearch/types\";\n\ninterface FieldPathFactoryParams {\n plugins: ElasticsearchQuerySearchValuePlugins;\n}\ninterface FieldPathParams {\n field: ModelField;\n key: string;\n value: any;\n keyword: boolean;\n}\n\nexport const createFieldPathFactory = ({ plugins }: FieldPathFactoryParams) => {\n return (params: FieldPathParams) => {\n const { field, key, value, keyword } = params;\n const plugin = plugins[field.type];\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field: field.field, value, key });\n }\n if (!fieldPath) {\n fieldPath = field.field.storageId;\n if (field.path) {\n fieldPath = typeof field.path === \"function\" ? field.path(value) : field.path;\n }\n }\n\n const result: string[] = [];\n if (!field.systemField) {\n result.push(\"values\");\n }\n result.push(...field.parents.map(p => p.storageId));\n result.push(fieldPath);\n\n return {\n basePath: result.join(\".\"),\n path: result.concat(keyword ? [\"keyword\"] : []).join(\".\")\n };\n };\n};\n"],"mappings":";;;;;;AAeO,MAAMA,sBAAsB,GAAG,CAAC;EAAEC;AAAgC,CAAC,KAAK;EAC3E,OAAQC,MAAuB,IAAK;IAChC,MAAM;MAAEC,KAAK;MAAEC,GAAG;MAAEC,KAAK;MAAEC;IAAQ,CAAC,GAAGJ,MAAM;IAC7C,MAAMK,MAAM,GAAGN,OAAO,CAACE,KAAK,CAACK,IAAI,CAAC;IAElC,IAAIC,SAAwB,GAAG,IAAI;IACnC,IAAIF,MAAM,EAAE;MACRE,SAAS,GAAGF,MAAM,CAACG,UAAU,CAAC;QAAEP,KAAK,EAAEA,KAAK,CAACA,KAAK;QAAEE,KAAK;QAAED;MAAI,CAAC,CAAC;IACrE;IACA,IAAI,CAACK,SAAS,EAAE;MACZA,SAAS,GAAGN,KAAK,CAACA,KAAK,CAACQ,SAAS;MACjC,IAAIR,KAAK,CAACS,IAAI,EAAE;QACZH,SAAS,GAAG,OAAON,KAAK,CAACS,IAAI,KAAK,UAAU,GAAGT,KAAK,CAACS,IAAI,CAACP,KAAK,CAAC,GAAGF,KAAK,CAACS,IAAI;MACjF;IACJ;IAEA,MAAMC,MAAgB,GAAG,EAAE;IAC3B,IAAI,CAACV,KAAK,CAACW,WAAW,EAAE;MACpBD,MAAM,CAACE,IAAI,CAAC,QAAQ,CAAC;IACzB;IACAF,MAAM,CAACE,IAAI,CAAC,GAAGZ,KAAK,CAACa,OAAO,CAACC,GAAG,CAACC,CAAC,IAAIA,CAAC,CAACP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