@webiny/api-headless-cms-utils-os 0.0.0-unstable.0d717d18dd → 0.0.0-unstable.7c2def32a7

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 (47) hide show
  1. package/configurations.d.ts +8 -9
  2. package/configurations.js +15 -22
  3. package/configurations.js.map +1 -1
  4. package/exports/api/cms/opensearch.d.ts +1 -0
  5. package/exports/api/cms/opensearch.js +1 -0
  6. package/features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.js +3 -2
  7. package/features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.js.map +1 -1
  8. package/features/CmsEntryOpenSearchBodyBuilder/abstractions.d.ts +4 -0
  9. package/features/CmsEntryOpenSearchBodyBuilder/abstractions.js.map +1 -1
  10. package/features/CmsEntryOpenSearchFieldIndex/feature.js +10 -10
  11. package/features/CmsEntryOpenSearchFieldIndex/feature.js.map +1 -1
  12. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js +11 -2
  13. package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js.map +1 -1
  14. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.d.ts +1 -1
  15. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js +1 -1
  16. package/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js.map +1 -1
  17. package/features/CmsEntryOpenSearchIndexCreate/CmsEntryOpenSearchIndexCreate.js +3 -4
  18. package/features/CmsEntryOpenSearchIndexCreate/CmsEntryOpenSearchIndexCreate.js.map +1 -1
  19. package/features/CmsEntryOpenSearchIndexDelete/CmsEntryOpenSearchIndexDelete.js +3 -4
  20. package/features/CmsEntryOpenSearchIndexDelete/CmsEntryOpenSearchIndexDelete.js.map +1 -1
  21. package/features/CmsEntryOpenSearchUtilsFeature.js +2 -0
  22. package/features/CmsEntryOpenSearchUtilsFeature.js.map +1 -1
  23. package/features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndex.d.ts +8 -0
  24. package/features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndex.js +17 -0
  25. package/features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndex.js.map +1 -0
  26. package/features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndexProvider.d.ts +12 -0
  27. package/features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndexProvider.js +35 -0
  28. package/features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndexProvider.js.map +1 -0
  29. package/features/CmsModelOpenSearchIndex/feature.d.ts +4 -0
  30. package/features/CmsModelOpenSearchIndex/feature.js +13 -0
  31. package/features/CmsModelOpenSearchIndex/feature.js.map +1 -0
  32. package/features/CmsModelOpenSearchIndex/index.d.ts +3 -0
  33. package/features/CmsModelOpenSearchIndex/index.js +3 -0
  34. package/operations/entry/elasticsearch/fullTextSearch.js +10 -1
  35. package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
  36. package/operations/entry/elasticsearch/initialQuery.d.ts +4 -0
  37. package/operations/entry/elasticsearch/initialQuery.js +2 -4
  38. package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
  39. package/operations/entry/elasticsearch/initialQuery.test.d.ts +1 -0
  40. package/operations/entry/elasticsearch/initialQuery.test.js +48 -0
  41. package/operations/entry/elasticsearch/initialQuery.test.js.map +1 -0
  42. package/package.json +8 -7
  43. package/testing/createTestModelIndexName.d.ts +3 -0
  44. package/testing/createTestModelIndexName.js +11 -0
  45. package/testing/createTestModelIndexName.js.map +1 -0
  46. package/testing/index.d.ts +1 -0
  47. package/testing/index.js +1 -0
@@ -1,10 +1,9 @@
1
1
  import type { StorageCmsModel } from "@webiny/api-headless-cms/types/index.js";
2
- export declare const configurations: {
3
- es(params: {
4
- model: Pick<StorageCmsModel, "tenant" | "modelId">;
5
- }): {
6
- index: string;
7
- settings: import("@opensearch-project/opensearch/api/index.js").Indices_Create_RequestBody;
8
- shared: boolean;
9
- };
10
- };
2
+ import type { CmsModelOpenSearchIndexProvider, ICmsModelOpenSearchIndexProviderResult } from "./features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js";
3
+ export interface CmsElasticsearchParams {
4
+ model: StorageCmsModel;
5
+ }
6
+ export interface Configurations {
7
+ es: (params: CmsElasticsearchParams) => Promise<ICmsModelOpenSearchIndexProviderResult>;
8
+ }
9
+ export declare const createConfigurations: (provider: CmsModelOpenSearchIndexProvider.Interface) => Configurations;
package/configurations.js CHANGED
@@ -1,24 +1,17 @@
1
- import error from "@webiny/error";
2
- import { getBaseConfiguration, getOpenSearchIndexPrefix, isSharedOpenSearchIndex } from "@webiny/api-opensearch";
3
- const configurations = {
4
- es (params) {
5
- const { model } = params;
6
- const { tenant } = model;
7
- if (!tenant) throw new error('Missing "tenant" parameter when trying to create Elasticsearch index name.', "TENANT_ERROR");
8
- const shared = isSharedOpenSearchIndex();
9
- const index = [
10
- shared ? "root" : tenant,
11
- "headless-cms",
12
- model.modelId
13
- ].join("-").toLowerCase();
14
- const prefix = getOpenSearchIndexPrefix();
15
- return {
16
- index: prefix ? prefix + index : index,
17
- settings: getBaseConfiguration(),
18
- shared
19
- };
20
- }
21
- };
22
- export { configurations };
1
+ import { getOpenSearchIndexPrefix } from "@webiny/api-opensearch";
2
+ const createConfigurations = (provider)=>({
3
+ async es ({ model }) {
4
+ const result = await provider.execute({
5
+ model
6
+ });
7
+ const prefix = getOpenSearchIndexPrefix();
8
+ if (!prefix) return result;
9
+ return {
10
+ ...result,
11
+ index: prefix + result.index
12
+ };
13
+ }
14
+ });
15
+ export { createConfigurations };
23
16
 
24
17
  //# sourceMappingURL=configurations.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"configurations.js","sources":["../src/configurations.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport {\n getBaseConfiguration,\n getOpenSearchIndexPrefix,\n isSharedOpenSearchIndex\n} from \"@webiny/api-opensearch\";\nimport type { StorageCmsModel } from \"@webiny/api-headless-cms/types/index.js\";\n\nexport const configurations = {\n es(params: { model: Pick<StorageCmsModel, \"tenant\" | \"modelId\"> }) {\n const { model } = params;\n const { tenant } = 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 }\n\n const shared = isSharedOpenSearchIndex();\n const index = [shared ? \"root\" : tenant, \"headless-cms\", model.modelId]\n .join(\"-\")\n .toLowerCase();\n\n const prefix = getOpenSearchIndexPrefix();\n\n return {\n index: prefix ? prefix + index : index,\n settings: getBaseConfiguration(),\n shared\n };\n }\n};\n"],"names":["configurations","params","model","tenant","WebinyError","shared","isSharedOpenSearchIndex","index","prefix","getOpenSearchIndexPrefix","getBaseConfiguration"],"mappings":";;AAQO,MAAMA,iBAAiB;IAC1B,IAAGC,MAA8D;QAC7D,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAM,EAAEE,MAAM,EAAE,GAAGD;QAEnB,IAAI,CAACC,QACD,MAAM,IAAIC,MACN,8EACA;QAIR,MAAMC,SAASC;QACf,MAAMC,QAAQ;YAACF,SAAS,SAASF;YAAQ;YAAgBD,MAAM,OAAO;SAAC,CAClE,IAAI,CAAC,KACL,WAAW;QAEhB,MAAMM,SAASC;QAEf,OAAO;YACH,OAAOD,SAASA,SAASD,QAAQA;YACjC,UAAUG;YACVL;QACJ;IACJ;AACJ"}
1
+ {"version":3,"file":"configurations.js","sources":["../src/configurations.ts"],"sourcesContent":["import { getOpenSearchIndexPrefix } from \"@webiny/api-opensearch\";\nimport type { StorageCmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type {\n CmsModelOpenSearchIndexProvider,\n ICmsModelOpenSearchIndexProviderResult\n} from \"./features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js\";\n\nexport interface CmsElasticsearchParams {\n model: StorageCmsModel;\n}\n\nexport interface Configurations {\n es: (params: CmsElasticsearchParams) => Promise<ICmsModelOpenSearchIndexProviderResult>;\n}\n\nexport const createConfigurations = (\n provider: CmsModelOpenSearchIndexProvider.Interface\n): Configurations => ({\n async es({ model }) {\n const result = await provider.execute({ model });\n\n const prefix = getOpenSearchIndexPrefix();\n\n if (!prefix) {\n return result;\n }\n return {\n ...result,\n index: prefix + result.index\n };\n }\n});\n"],"names":["createConfigurations","provider","model","result","prefix","getOpenSearchIndexPrefix"],"mappings":";AAeO,MAAMA,uBAAuB,CAChCC,WACkB;QAClB,MAAM,IAAG,EAAEC,KAAK,EAAE;YACd,MAAMC,SAAS,MAAMF,SAAS,OAAO,CAAC;gBAAEC;YAAM;YAE9C,MAAME,SAASC;YAEf,IAAI,CAACD,QACD,OAAOD;YAEX,OAAO;gBACH,GAAGA,MAAM;gBACT,OAAOC,SAASD,OAAO,KAAK;YAChC;QACJ;IACJ"}
@@ -1,3 +1,4 @@
1
+ export { CmsModelOpenSearchIndexProvider, CmsModelOpenSearchIndex } from "../../../features/CmsModelOpenSearchIndex/index.js";
1
2
  export { CmsEntryOpenSearchUtilsFeature } from "../../../features/CmsEntryOpenSearchUtilsFeature.js";
2
3
  export { CmsEntryOpenSearchFieldIndexRegistry, CmsEntryOpenSearchFieldIndex } from "../../../features/CmsEntryOpenSearchFieldIndex/index.js";
3
4
  export { CmsEntryOpenSearchFilterRegistry, CmsEntryOpenSearchFilter } from "../../../features/CmsEntryOpenSearchFilter/index.js";
@@ -1,3 +1,4 @@
1
+ export { CmsModelOpenSearchIndex, CmsModelOpenSearchIndexProvider } from "../../../features/CmsModelOpenSearchIndex/index.js";
1
2
  export { CmsEntryOpenSearchUtilsFeature } from "../../../features/CmsEntryOpenSearchUtilsFeature.js";
2
3
  export { CmsEntryOpenSearchFieldIndex, CmsEntryOpenSearchFieldIndexRegistry } from "../../../features/CmsEntryOpenSearchFieldIndex/index.js";
3
4
  export { CmsEntryOpenSearchFilter, CmsEntryOpenSearchFilterRegistry } from "../../../features/CmsEntryOpenSearchFilter/index.js";
@@ -29,7 +29,7 @@ class CmsEntryOpenSearchBodyBuilderImpl {
29
29
  this.fieldFactory = fieldFactory;
30
30
  }
31
31
  build(params) {
32
- const { model } = params;
32
+ const { model, shared } = params;
33
33
  const { fields, search: term, where, sort: initialSort, after, limit } = params.params;
34
34
  const modelFields = createModelFields({
35
35
  model,
@@ -46,7 +46,8 @@ class CmsEntryOpenSearchBodyBuilderImpl {
46
46
  });
47
47
  const query = createInitialQuery({
48
48
  where,
49
- model
49
+ model,
50
+ shared
50
51
  });
51
52
  applyFullTextSearch({
52
53
  model,
@@ -1 +1 @@
1
- {"version":3,"file":"features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.js","sources":["../../../src/features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.ts"],"sourcesContent":["import type {\n QueryDslBoolQuery as BoolQueryConfig,\n SearchBody\n} from \"@webiny/api-opensearch/types.js\";\nimport { OpenSearchFieldFactory } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { CmsEntryOpenSearchFieldIndexRegistry } from \"~/features/CmsEntryOpenSearchFieldIndex/index.js\";\nimport { CmsEntryOpenSearchBodyModifier } from \"~/features/CmsEntryOpenSearchBodyModifier/index.js\";\nimport { CmsEntryOpenSearchSortModifier } from \"~/features/CmsEntryOpenSearchSortModifier/index.js\";\nimport { CmsEntryOpenSearchQueryModifier } from \"~/features/CmsEntryOpenSearchQueryModifier/index.js\";\nimport { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\nimport { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport { CmsEntryOpenSearchExecFiltering } from \"~/features/CmsEntryOpenSearchExecFiltering/index.js\";\nimport { CmsEntryOpenSearchFieldPathFactory } from \"~/features/CmsEntryOpenSearchFieldPathFactory/index.js\";\nimport { createModelFields } from \"~/operations/entry/elasticsearch/fields.js\";\nimport { createFullTextSearchFields } from \"~/operations/entry/elasticsearch/fullTextSearchFields.js\";\nimport { createInitialQuery } from \"~/operations/entry/elasticsearch/initialQuery.js\";\nimport { applyFullTextSearch } from \"~/operations/entry/elasticsearch/fullTextSearch.js\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js\";\nimport { createElasticsearchSort } from \"./sort.js\";\nimport { CmsEntryOpenSearchBodyBuilder as CmsEntryOpenSearchBodyBuilderAbstraction } from \"./abstractions.js\";\n\nclass CmsEntryOpenSearchBodyBuilderImpl\n implements CmsEntryOpenSearchBodyBuilderAbstraction.Interface\n{\n public constructor(\n private readonly execFiltering: CmsEntryOpenSearchExecFiltering.Interface,\n private readonly fieldPathFactory: CmsEntryOpenSearchFieldPathFactory.Interface,\n private readonly fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface,\n private readonly fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private readonly bodyModifiers: CmsEntryOpenSearchBodyModifier.Interface[],\n private readonly sortModifiers: CmsEntryOpenSearchSortModifier.Interface[],\n private readonly queryModifiers: CmsEntryOpenSearchQueryModifier.Interface[],\n private readonly valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface,\n private readonly fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[],\n private readonly fieldFactory: OpenSearchFieldFactory.Interface\n ) {}\n\n public build(params: CmsEntryOpenSearchBodyBuilderAbstraction.Params): SearchBody {\n const { model } = params;\n const { fields, search: term, where, sort: initialSort, after, limit } = params.params;\n\n const modelFields = createModelFields({\n model,\n fieldRegistry: this.fieldRegistry,\n fieldIndexRegistry: this.fieldIndexRegistry\n });\n\n const applicableQueryModifiers = this.queryModifiers.filter(m => {\n return !m.modelId || m.modelId === model.modelId;\n });\n const applicableSortModifiers = this.sortModifiers.filter(\n m => !m.modelId || m.modelId === model.modelId\n );\n const applicableBodyModifiers = this.bodyModifiers.filter(m => {\n return !m.modelId || m.modelId === model.modelId;\n });\n\n const fullTextSearchFields = createFullTextSearchFields({\n fields: modelFields,\n term,\n targets: fields\n });\n\n const query = createInitialQuery({\n where,\n model\n });\n\n applyFullTextSearch({\n model,\n fullTextSearches: this.fullTextSearches,\n query,\n term,\n fields: fullTextSearchFields\n });\n\n this.execFiltering.execute({\n model,\n fields: modelFields,\n where,\n query\n });\n\n for (const modifier of applicableQueryModifiers) {\n modifier.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSort({\n sort: initialSort,\n modelFields,\n model,\n fieldPathFactory: this.fieldPathFactory,\n valueSearchRegistry: this.valueSearchRegistry,\n fieldFactory: this.fieldFactory\n });\n\n for (const modifier of applicableSortModifiers) {\n modifier.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 modifier of applicableBodyModifiers) {\n modifier.modifyBody({\n body,\n model,\n where\n });\n }\n\n return body;\n }\n}\n\nexport const CmsEntryOpenSearchBodyBuilder =\n CmsEntryOpenSearchBodyBuilderAbstraction.createImplementation({\n implementation: CmsEntryOpenSearchBodyBuilderImpl,\n dependencies: [\n CmsEntryOpenSearchExecFiltering,\n CmsEntryOpenSearchFieldPathFactory,\n CmsModelFieldToGraphQLRegistry,\n CmsEntryOpenSearchFieldIndexRegistry,\n [CmsEntryOpenSearchBodyModifier, { multiple: true }],\n [CmsEntryOpenSearchSortModifier, { multiple: true }],\n [CmsEntryOpenSearchQueryModifier, { multiple: true }],\n CmsEntryOpenSearchValueSearchRegistry,\n [CmsEntryOpenSearchFullTextSearch, { multiple: true }],\n OpenSearchFieldFactory\n ]\n });\n"],"names":["CmsEntryOpenSearchBodyBuilderImpl","execFiltering","fieldPathFactory","fieldRegistry","fieldIndexRegistry","bodyModifiers","sortModifiers","queryModifiers","valueSearchRegistry","fullTextSearches","fieldFactory","params","model","fields","term","where","initialSort","after","limit","modelFields","createModelFields","applicableQueryModifiers","m","applicableSortModifiers","applicableBodyModifiers","fullTextSearchFields","createFullTextSearchFields","query","createInitialQuery","applyFullTextSearch","modifier","sort","createElasticsearchSort","boolQuery","undefined","assignMinimumShouldMatchToQuery","body","CmsEntryOpenSearchBodyBuilder","CmsEntryOpenSearchBodyBuilderAbstraction","CmsEntryOpenSearchExecFiltering","CmsEntryOpenSearchFieldPathFactory","CmsModelFieldToGraphQLRegistry","CmsEntryOpenSearchFieldIndexRegistry","CmsEntryOpenSearchBodyModifier","CmsEntryOpenSearchSortModifier","CmsEntryOpenSearchQueryModifier","CmsEntryOpenSearchValueSearchRegistry","CmsEntryOpenSearchFullTextSearch","OpenSearchFieldFactory"],"mappings":"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"}
1
+ {"version":3,"file":"features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.js","sources":["../../../src/features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.ts"],"sourcesContent":["import type {\n QueryDslBoolQuery as BoolQueryConfig,\n SearchBody\n} from \"@webiny/api-opensearch/types.js\";\nimport { OpenSearchFieldFactory } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { CmsEntryOpenSearchFieldIndexRegistry } from \"~/features/CmsEntryOpenSearchFieldIndex/index.js\";\nimport { CmsEntryOpenSearchBodyModifier } from \"~/features/CmsEntryOpenSearchBodyModifier/index.js\";\nimport { CmsEntryOpenSearchSortModifier } from \"~/features/CmsEntryOpenSearchSortModifier/index.js\";\nimport { CmsEntryOpenSearchQueryModifier } from \"~/features/CmsEntryOpenSearchQueryModifier/index.js\";\nimport { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\nimport { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport { CmsEntryOpenSearchExecFiltering } from \"~/features/CmsEntryOpenSearchExecFiltering/index.js\";\nimport { CmsEntryOpenSearchFieldPathFactory } from \"~/features/CmsEntryOpenSearchFieldPathFactory/index.js\";\nimport { createModelFields } from \"~/operations/entry/elasticsearch/fields.js\";\nimport { createFullTextSearchFields } from \"~/operations/entry/elasticsearch/fullTextSearchFields.js\";\nimport { createInitialQuery } from \"~/operations/entry/elasticsearch/initialQuery.js\";\nimport { applyFullTextSearch } from \"~/operations/entry/elasticsearch/fullTextSearch.js\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js\";\nimport { createElasticsearchSort } from \"./sort.js\";\nimport { CmsEntryOpenSearchBodyBuilder as CmsEntryOpenSearchBodyBuilderAbstraction } from \"./abstractions.js\";\n\nclass CmsEntryOpenSearchBodyBuilderImpl\n implements CmsEntryOpenSearchBodyBuilderAbstraction.Interface\n{\n public constructor(\n private readonly execFiltering: CmsEntryOpenSearchExecFiltering.Interface,\n private readonly fieldPathFactory: CmsEntryOpenSearchFieldPathFactory.Interface,\n private readonly fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface,\n private readonly fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface,\n private readonly bodyModifiers: CmsEntryOpenSearchBodyModifier.Interface[],\n private readonly sortModifiers: CmsEntryOpenSearchSortModifier.Interface[],\n private readonly queryModifiers: CmsEntryOpenSearchQueryModifier.Interface[],\n private readonly valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface,\n private readonly fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[],\n private readonly fieldFactory: OpenSearchFieldFactory.Interface\n ) {}\n\n public build(params: CmsEntryOpenSearchBodyBuilderAbstraction.Params): SearchBody {\n const { model, shared } = params;\n const { fields, search: term, where, sort: initialSort, after, limit } = params.params;\n\n const modelFields = createModelFields({\n model,\n fieldRegistry: this.fieldRegistry,\n fieldIndexRegistry: this.fieldIndexRegistry\n });\n\n const applicableQueryModifiers = this.queryModifiers.filter(m => {\n return !m.modelId || m.modelId === model.modelId;\n });\n const applicableSortModifiers = this.sortModifiers.filter(\n m => !m.modelId || m.modelId === model.modelId\n );\n const applicableBodyModifiers = this.bodyModifiers.filter(m => {\n return !m.modelId || m.modelId === model.modelId;\n });\n\n const fullTextSearchFields = createFullTextSearchFields({\n fields: modelFields,\n term,\n targets: fields\n });\n\n const query = createInitialQuery({\n where,\n model,\n shared\n });\n\n applyFullTextSearch({\n model,\n fullTextSearches: this.fullTextSearches,\n query,\n term,\n fields: fullTextSearchFields\n });\n\n this.execFiltering.execute({\n model,\n fields: modelFields,\n where,\n query\n });\n\n for (const modifier of applicableQueryModifiers) {\n modifier.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSort({\n sort: initialSort,\n modelFields,\n model,\n fieldPathFactory: this.fieldPathFactory,\n valueSearchRegistry: this.valueSearchRegistry,\n fieldFactory: this.fieldFactory\n });\n\n for (const modifier of applicableSortModifiers) {\n modifier.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 modifier of applicableBodyModifiers) {\n modifier.modifyBody({\n body,\n model,\n where\n });\n }\n\n return body;\n }\n}\n\nexport const CmsEntryOpenSearchBodyBuilder =\n CmsEntryOpenSearchBodyBuilderAbstraction.createImplementation({\n implementation: CmsEntryOpenSearchBodyBuilderImpl,\n dependencies: [\n CmsEntryOpenSearchExecFiltering,\n CmsEntryOpenSearchFieldPathFactory,\n CmsModelFieldToGraphQLRegistry,\n CmsEntryOpenSearchFieldIndexRegistry,\n [CmsEntryOpenSearchBodyModifier, { multiple: true }],\n [CmsEntryOpenSearchSortModifier, { multiple: true }],\n [CmsEntryOpenSearchQueryModifier, { multiple: true }],\n CmsEntryOpenSearchValueSearchRegistry,\n [CmsEntryOpenSearchFullTextSearch, { multiple: true }],\n OpenSearchFieldFactory\n ]\n });\n"],"names":["CmsEntryOpenSearchBodyBuilderImpl","execFiltering","fieldPathFactory","fieldRegistry","fieldIndexRegistry","bodyModifiers","sortModifiers","queryModifiers","valueSearchRegistry","fullTextSearches","fieldFactory","params","model","shared","fields","term","where","initialSort","after","limit","modelFields","createModelFields","applicableQueryModifiers","m","applicableSortModifiers","applicableBodyModifiers","fullTextSearchFields","createFullTextSearchFields","query","createInitialQuery","applyFullTextSearch","modifier","sort","createElasticsearchSort","boolQuery","undefined","assignMinimumShouldMatchToQuery","body","CmsEntryOpenSearchBodyBuilder","CmsEntryOpenSearchBodyBuilderAbstraction","CmsEntryOpenSearchExecFiltering","CmsEntryOpenSearchFieldPathFactory","CmsModelFieldToGraphQLRegistry","CmsEntryOpenSearchFieldIndexRegistry","CmsEntryOpenSearchBodyModifier","CmsEntryOpenSearchSortModifier","CmsEntryOpenSearchQueryModifier","CmsEntryOpenSearchValueSearchRegistry","CmsEntryOpenSearchFullTextSearch","OpenSearchFieldFactory"],"mappings":"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"}
@@ -3,6 +3,10 @@ import type { CmsEntryListParams, CmsEntryListWhere } from "@webiny/api-headless
3
3
  import type { PrimitiveValue, SearchBody } from "@webiny/api-opensearch/types.js";
4
4
  export interface ICmsEntryOpenSearchBodyBuilderParams {
5
5
  model: CmsModel;
6
+ /**
7
+ * Whether the model's index is shared between tenants, from CmsModelOpenSearchIndexProvider.
8
+ */
9
+ shared: boolean;
6
10
  params: Omit<CmsEntryListParams, "where" | "after"> & {
7
11
  where: CmsEntryListWhere;
8
12
  after?: PrimitiveValue[];
@@ -1 +1 @@
1
- {"version":3,"file":"features/CmsEntryOpenSearchBodyBuilder/abstractions.js","sources":["../../../src/features/CmsEntryOpenSearchBodyBuilder/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type {\n CmsEntryListParams,\n CmsEntryListWhere\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { PrimitiveValue, SearchBody } from \"@webiny/api-opensearch/types.js\";\n\nexport interface ICmsEntryOpenSearchBodyBuilderParams {\n model: CmsModel;\n params: Omit<CmsEntryListParams, \"where\" | \"after\"> & {\n where: CmsEntryListWhere;\n after?: PrimitiveValue[];\n };\n}\n\nexport interface ICmsEntryOpenSearchBodyBuilder {\n build(params: ICmsEntryOpenSearchBodyBuilderParams): SearchBody;\n}\n\nexport const CmsEntryOpenSearchBodyBuilder = createAbstraction<ICmsEntryOpenSearchBodyBuilder>(\n \"Cms/Entry/OpenSearch/BodyBuilder\"\n);\n\nexport namespace CmsEntryOpenSearchBodyBuilder {\n export type Interface = ICmsEntryOpenSearchBodyBuilder;\n export type Params = ICmsEntryOpenSearchBodyBuilderParams;\n}\n"],"names":["CmsEntryOpenSearchBodyBuilder","createAbstraction"],"mappings":";AAoBO,MAAMA,gCAAgCC,kBACzC"}
1
+ {"version":3,"file":"features/CmsEntryOpenSearchBodyBuilder/abstractions.js","sources":["../../../src/features/CmsEntryOpenSearchBodyBuilder/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type {\n CmsEntryListParams,\n CmsEntryListWhere\n} from \"@webiny/api-headless-cms/types/index.js\";\nimport type { PrimitiveValue, SearchBody } from \"@webiny/api-opensearch/types.js\";\n\nexport interface ICmsEntryOpenSearchBodyBuilderParams {\n model: CmsModel;\n /**\n * Whether the model's index is shared between tenants, from CmsModelOpenSearchIndexProvider.\n */\n shared: boolean;\n params: Omit<CmsEntryListParams, \"where\" | \"after\"> & {\n where: CmsEntryListWhere;\n after?: PrimitiveValue[];\n };\n}\n\nexport interface ICmsEntryOpenSearchBodyBuilder {\n build(params: ICmsEntryOpenSearchBodyBuilderParams): SearchBody;\n}\n\nexport const CmsEntryOpenSearchBodyBuilder = createAbstraction<ICmsEntryOpenSearchBodyBuilder>(\n \"Cms/Entry/OpenSearch/BodyBuilder\"\n);\n\nexport namespace CmsEntryOpenSearchBodyBuilder {\n export type Interface = ICmsEntryOpenSearchBodyBuilder;\n export type Params = ICmsEntryOpenSearchBodyBuilderParams;\n}\n"],"names":["CmsEntryOpenSearchBodyBuilder","createAbstraction"],"mappings":";AAwBO,MAAMA,gCAAgCC,kBACzC"}
@@ -12,16 +12,16 @@ import { TextEncryptedFieldIndex } from "./fields/TextEncryptedFieldIndex.js";
12
12
  const CmsEntryOpenSearchFieldIndexFeature = createFeature({
13
13
  name: "Cms/Entry/OpenSearch/FieldIndexFeature",
14
14
  register: (container)=>{
15
- container.register(RichTextFieldIndex).inSingletonScope();
16
- container.register(JsonFieldIndex).inSingletonScope();
17
- container.register(LongTextFieldIndex).inSingletonScope();
18
- container.register(NumberFieldIndex).inSingletonScope();
19
- container.register(DefaultFieldIndex).inSingletonScope();
20
- container.register(DateTimeFieldIndex).inSingletonScope();
21
- container.register(ObjectFieldIndex).inSingletonScope();
22
- container.register(TextCompressedFieldIndex).inSingletonScope();
23
- container.register(TextEncryptedFieldIndex).inSingletonScope();
24
- container.register(CmsEntryOpenSearchFieldIndexRegistry).inSingletonScope();
15
+ container.register(RichTextFieldIndex).inContainerScope();
16
+ container.register(JsonFieldIndex).inContainerScope();
17
+ container.register(LongTextFieldIndex).inContainerScope();
18
+ container.register(NumberFieldIndex).inContainerScope();
19
+ container.register(DefaultFieldIndex).inContainerScope();
20
+ container.register(DateTimeFieldIndex).inContainerScope();
21
+ container.register(ObjectFieldIndex).inContainerScope();
22
+ container.register(TextCompressedFieldIndex).inContainerScope();
23
+ container.register(TextEncryptedFieldIndex).inContainerScope();
24
+ container.register(CmsEntryOpenSearchFieldIndexRegistry).inContainerScope();
25
25
  }
26
26
  });
27
27
  export { CmsEntryOpenSearchFieldIndexFeature };
@@ -1 +1 @@
1
- {"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/feature.js","sources":["../../../src/features/CmsEntryOpenSearchFieldIndex/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CmsEntryOpenSearchFieldIndexRegistry } from \"./CmsEntryOpenSearchFieldIndexRegistry.js\";\nimport { RichTextFieldIndex } from \"./fields/RichTextFieldIndex.js\";\nimport { JsonFieldIndex } from \"./fields/JsonFieldIndex.js\";\nimport { LongTextFieldIndex } from \"./fields/LongTextFieldIndex.js\";\nimport { NumberFieldIndex } from \"./fields/NumberFieldIndex.js\";\nimport { DefaultFieldIndex } from \"./fields/DefaultFieldIndex.js\";\nimport { DateTimeFieldIndex } from \"./fields/DateTimeFieldIndex.js\";\nimport { ObjectFieldIndex } from \"./fields/ObjectFieldIndex.js\";\nimport { TextCompressedFieldIndex } from \"./fields/TextCompressedFieldIndex.js\";\nimport { TextEncryptedFieldIndex } from \"./fields/TextEncryptedFieldIndex.js\";\n\nexport const CmsEntryOpenSearchFieldIndexFeature = createFeature({\n name: \"Cms/Entry/OpenSearch/FieldIndexFeature\",\n register: container => {\n container.register(RichTextFieldIndex).inSingletonScope();\n container.register(JsonFieldIndex).inSingletonScope();\n container.register(LongTextFieldIndex).inSingletonScope();\n container.register(NumberFieldIndex).inSingletonScope();\n container.register(DefaultFieldIndex).inSingletonScope();\n container.register(DateTimeFieldIndex).inSingletonScope();\n container.register(ObjectFieldIndex).inSingletonScope();\n container.register(TextCompressedFieldIndex).inSingletonScope();\n container.register(TextEncryptedFieldIndex).inSingletonScope();\n\n // must be registered last\n container.register(CmsEntryOpenSearchFieldIndexRegistry).inSingletonScope();\n }\n});\n"],"names":["CmsEntryOpenSearchFieldIndexFeature","createFeature","container","RichTextFieldIndex","JsonFieldIndex","LongTextFieldIndex","NumberFieldIndex","DefaultFieldIndex","DateTimeFieldIndex","ObjectFieldIndex","TextCompressedFieldIndex","TextEncryptedFieldIndex","CmsEntryOpenSearchFieldIndexRegistry"],"mappings":";;;;;;;;;;;AAYO,MAAMA,sCAAsCC,cAAc;IAC7D,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC,oBAAoB,gBAAgB;QACvDD,UAAU,QAAQ,CAACE,gBAAgB,gBAAgB;QACnDF,UAAU,QAAQ,CAACG,oBAAoB,gBAAgB;QACvDH,UAAU,QAAQ,CAACI,kBAAkB,gBAAgB;QACrDJ,UAAU,QAAQ,CAACK,mBAAmB,gBAAgB;QACtDL,UAAU,QAAQ,CAACM,oBAAoB,gBAAgB;QACvDN,UAAU,QAAQ,CAACO,kBAAkB,gBAAgB;QACrDP,UAAU,QAAQ,CAACQ,0BAA0B,gBAAgB;QAC7DR,UAAU,QAAQ,CAACS,yBAAyB,gBAAgB;QAG5DT,UAAU,QAAQ,CAACU,sCAAsC,gBAAgB;IAC7E;AACJ"}
1
+ {"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/feature.js","sources":["../../../src/features/CmsEntryOpenSearchFieldIndex/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CmsEntryOpenSearchFieldIndexRegistry } from \"./CmsEntryOpenSearchFieldIndexRegistry.js\";\nimport { RichTextFieldIndex } from \"./fields/RichTextFieldIndex.js\";\nimport { JsonFieldIndex } from \"./fields/JsonFieldIndex.js\";\nimport { LongTextFieldIndex } from \"./fields/LongTextFieldIndex.js\";\nimport { NumberFieldIndex } from \"./fields/NumberFieldIndex.js\";\nimport { DefaultFieldIndex } from \"./fields/DefaultFieldIndex.js\";\nimport { DateTimeFieldIndex } from \"./fields/DateTimeFieldIndex.js\";\nimport { ObjectFieldIndex } from \"./fields/ObjectFieldIndex.js\";\nimport { TextCompressedFieldIndex } from \"./fields/TextCompressedFieldIndex.js\";\nimport { TextEncryptedFieldIndex } from \"./fields/TextEncryptedFieldIndex.js\";\n\nexport const CmsEntryOpenSearchFieldIndexFeature = createFeature({\n name: \"Cms/Entry/OpenSearch/FieldIndexFeature\",\n register: container => {\n // Container scoped, so registering the feature once in the root still builds these per request:\n // several field indexes depend on the per-request CmsModelFieldToGraphQLRegistry, and the\n // registry collects field indexes that extensions register per request.\n container.register(RichTextFieldIndex).inContainerScope();\n container.register(JsonFieldIndex).inContainerScope();\n container.register(LongTextFieldIndex).inContainerScope();\n container.register(NumberFieldIndex).inContainerScope();\n container.register(DefaultFieldIndex).inContainerScope();\n container.register(DateTimeFieldIndex).inContainerScope();\n container.register(ObjectFieldIndex).inContainerScope();\n container.register(TextCompressedFieldIndex).inContainerScope();\n container.register(TextEncryptedFieldIndex).inContainerScope();\n\n // must be registered last\n container.register(CmsEntryOpenSearchFieldIndexRegistry).inContainerScope();\n }\n});\n"],"names":["CmsEntryOpenSearchFieldIndexFeature","createFeature","container","RichTextFieldIndex","JsonFieldIndex","LongTextFieldIndex","NumberFieldIndex","DefaultFieldIndex","DateTimeFieldIndex","ObjectFieldIndex","TextCompressedFieldIndex","TextEncryptedFieldIndex","CmsEntryOpenSearchFieldIndexRegistry"],"mappings":";;;;;;;;;;;AAYO,MAAMA,sCAAsCC,cAAc;IAC7D,MAAM;IACN,UAAUC,CAAAA;QAINA,UAAU,QAAQ,CAACC,oBAAoB,gBAAgB;QACvDD,UAAU,QAAQ,CAACE,gBAAgB,gBAAgB;QACnDF,UAAU,QAAQ,CAACG,oBAAoB,gBAAgB;QACvDH,UAAU,QAAQ,CAACI,kBAAkB,gBAAgB;QACrDJ,UAAU,QAAQ,CAACK,mBAAmB,gBAAgB;QACtDL,UAAU,QAAQ,CAACM,oBAAoB,gBAAgB;QACvDN,UAAU,QAAQ,CAACO,kBAAkB,gBAAgB;QACrDP,UAAU,QAAQ,CAACQ,0BAA0B,gBAAgB;QAC7DR,UAAU,QAAQ,CAACS,yBAAyB,gBAAgB;QAG5DT,UAAU,QAAQ,CAACU,sCAAsC,gBAAgB;IAC7E;AACJ"}
@@ -19,6 +19,10 @@ class ObjectFieldIndexImpl {
19
19
  model,
20
20
  fields
21
21
  });
22
+ if (initialValue[key]?._id) {
23
+ value._id = initialValue[key]._id;
24
+ rawValue._id = initialValue[key]._id;
25
+ }
22
26
  result.value.push(value);
23
27
  result.rawValue.push(rawValue);
24
28
  }
@@ -40,13 +44,18 @@ class ObjectFieldIndexImpl {
40
44
  const fields = field.settings?.fields || [];
41
45
  if (field.list) {
42
46
  const source = value || rawValue || [];
43
- return source.map((_, index)=>this.processFromIndex({
47
+ return source.map((_, index)=>{
48
+ const processed = this.processFromIndex({
44
49
  value: value ? value[index] || {} : {},
45
50
  rawValue: rawValue ? rawValue[index] || {} : {},
46
51
  getFieldIndex,
47
52
  model,
48
53
  fields
49
- }));
54
+ });
55
+ const sourceItem = value ? value[index] : rawValue ? rawValue[index] : null;
56
+ if (sourceItem?._id) processed._id = sourceItem._id;
57
+ return processed;
58
+ });
50
59
  }
51
60
  return this.processFromIndex({
52
61
  value,
@@ -1 +1 @@
1
- {"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js","sources":["../../../../src/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.ts"],"sourcesContent":["import type { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { getFieldIdentifiers } from \"~/helpers/index.js\";\nimport { CmsEntryOpenSearchFieldIndex } from \"../abstractions/CmsEntryOpenSearchFieldIndex.js\";\n\ninterface ProcessToIndexParams {\n fields: CmsModelField[];\n value: Record<string, any>;\n rawValue: Record<string, any>;\n getFieldIndex: (fieldType: string) => CmsEntryOpenSearchFieldIndex.Interface;\n model: CmsModel;\n}\n\ninterface ReducerValue {\n value: Record<string, any>;\n rawValue: Record<string, any>;\n}\n\ninterface ProcessFromIndexParams {\n fields: CmsModelField[];\n value: Record<string, any>;\n rawValue?: Record<string, any> | null;\n getFieldIndex: (fieldType: string) => CmsEntryOpenSearchFieldIndex.Interface;\n model: CmsModel;\n}\n\nclass ObjectFieldIndexImpl implements CmsEntryOpenSearchFieldIndex.Interface {\n public readonly fieldType = \"object\";\n\n public toIndex({\n model,\n field,\n value: initialValue,\n rawValue: initialRawValue,\n getFieldIndex\n }: CmsEntryOpenSearchFieldIndex.ToIndex): CmsEntryOpenSearchFieldIndex.ToValue {\n if (!initialValue) {\n return { value: null };\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n if (field.list) {\n const result: { value: Record<string, any>[]; rawValue: Record<string, any>[] } = {\n value: [],\n rawValue: []\n };\n for (const key in initialValue) {\n const { value, rawValue } = this.processToIndex({\n value: initialValue[key],\n rawValue: initialRawValue[key],\n getFieldIndex,\n model,\n fields\n });\n\n result.value.push(value);\n result.rawValue.push(rawValue);\n }\n\n return {\n value: result.value.length > 0 ? result.value : undefined,\n rawValue: result.rawValue.length > 0 ? result.rawValue : undefined\n };\n }\n\n return this.processToIndex({\n value: initialValue,\n rawValue: initialRawValue,\n getFieldIndex,\n model,\n fields\n });\n }\n\n public fromIndex({\n field,\n value,\n rawValue,\n model,\n getFieldIndex\n }: CmsEntryOpenSearchFieldIndex.FromIndex): any {\n if (!value) {\n return null;\n }\n\n const fields = field.settings?.fields || [];\n\n if (field.list) {\n const source = value || rawValue || [];\n\n return source.map((_: any, index: number) =>\n this.processFromIndex({\n value: value ? value[index] || {} : {},\n rawValue: rawValue ? rawValue[index] || {} : {},\n getFieldIndex,\n model,\n fields\n })\n );\n }\n\n return this.processFromIndex({\n value,\n rawValue,\n getFieldIndex,\n model,\n fields\n });\n }\n\n private processToIndex(params: ProcessToIndexParams): ReducerValue {\n const {\n fields,\n value: sourceValue,\n rawValue: sourceRawValue,\n getFieldIndex,\n model\n } = params;\n\n return fields.reduce<ReducerValue>(\n (values, field) => {\n const plugin = getFieldIndex(field.type);\n\n const identifiers = getFieldIdentifiers(sourceValue, sourceRawValue, field);\n if (!identifiers) {\n return values;\n }\n\n const { value, rawValue } = plugin.toIndex({\n model,\n field,\n value: sourceValue[\n identifiers.valueIdentifier || identifiers.rawValueIdentifier\n ],\n rawValue:\n sourceRawValue[\n identifiers.rawValueIdentifier || identifiers.valueIdentifier\n ],\n getFieldIndex\n });\n\n if (value !== undefined) {\n values.value[identifiers.valueIdentifier || identifiers.rawValueIdentifier] =\n value;\n }\n if (rawValue !== undefined) {\n values.rawValue[identifiers.rawValueIdentifier || identifiers.valueIdentifier] =\n rawValue;\n }\n\n return values;\n },\n { value: {}, rawValue: {} }\n );\n }\n\n private processFromIndex = (params: ProcessFromIndexParams): Record<string, any> => {\n const {\n fields,\n value: sourceValue,\n rawValue: sourceRawValue,\n getFieldIndex,\n model\n } = params;\n\n return fields.reduce<Record<string, any>>((values, field) => {\n const plugin = getFieldIndex(field.type);\n\n const identifiers = getFieldIdentifiers(sourceValue, sourceRawValue, field);\n if (!identifiers) {\n return values;\n }\n\n const value = plugin.fromIndex({\n model,\n field,\n value: sourceValue[identifiers.valueIdentifier || identifiers.rawValueIdentifier],\n rawValue: sourceRawValue\n ? sourceRawValue[identifiers.rawValueIdentifier || identifiers.valueIdentifier]\n : null,\n getFieldIndex\n });\n\n if (value !== undefined) {\n values[identifiers.valueIdentifier || identifiers.rawValueIdentifier] = value;\n }\n\n return values;\n }, {});\n };\n}\n\nexport const ObjectFieldIndex = CmsEntryOpenSearchFieldIndex.createImplementation({\n implementation: ObjectFieldIndexImpl,\n dependencies: []\n});\n"],"names":["ObjectFieldIndexImpl","model","field","initialValue","initialRawValue","getFieldIndex","fields","result","key","value","rawValue","undefined","source","_","index","params","sourceValue","sourceRawValue","values","plugin","identifiers","getFieldIdentifiers","ObjectFieldIndex","CmsEntryOpenSearchFieldIndex"],"mappings":"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"}
1
+ {"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.js","sources":["../../../../src/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.ts"],"sourcesContent":["import type { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { getFieldIdentifiers } from \"~/helpers/index.js\";\nimport { CmsEntryOpenSearchFieldIndex } from \"../abstractions/CmsEntryOpenSearchFieldIndex.js\";\n\ninterface ProcessToIndexParams {\n fields: CmsModelField[];\n value: Record<string, any>;\n rawValue: Record<string, any>;\n getFieldIndex: (fieldType: string) => CmsEntryOpenSearchFieldIndex.Interface;\n model: CmsModel;\n}\n\ninterface ReducerValue {\n value: Record<string, any>;\n rawValue: Record<string, any>;\n}\n\ninterface ProcessFromIndexParams {\n fields: CmsModelField[];\n value: Record<string, any>;\n rawValue?: Record<string, any> | null;\n getFieldIndex: (fieldType: string) => CmsEntryOpenSearchFieldIndex.Interface;\n model: CmsModel;\n}\n\nclass ObjectFieldIndexImpl implements CmsEntryOpenSearchFieldIndex.Interface {\n public readonly fieldType = \"object\";\n\n public toIndex({\n model,\n field,\n value: initialValue,\n rawValue: initialRawValue,\n getFieldIndex\n }: CmsEntryOpenSearchFieldIndex.ToIndex): CmsEntryOpenSearchFieldIndex.ToValue {\n if (!initialValue) {\n return { value: null };\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n if (field.list) {\n const result: { value: Record<string, any>[]; rawValue: Record<string, any>[] } = {\n value: [],\n rawValue: []\n };\n for (const key in initialValue) {\n const { value, rawValue } = this.processToIndex({\n value: initialValue[key],\n rawValue: initialRawValue[key],\n getFieldIndex,\n model,\n fields\n });\n\n if (initialValue[key]?._id) {\n value._id = initialValue[key]._id;\n rawValue._id = initialValue[key]._id;\n }\n\n result.value.push(value);\n result.rawValue.push(rawValue);\n }\n\n return {\n value: result.value.length > 0 ? result.value : undefined,\n rawValue: result.rawValue.length > 0 ? result.rawValue : undefined\n };\n }\n\n return this.processToIndex({\n value: initialValue,\n rawValue: initialRawValue,\n getFieldIndex,\n model,\n fields\n });\n }\n\n public fromIndex({\n field,\n value,\n rawValue,\n model,\n getFieldIndex\n }: CmsEntryOpenSearchFieldIndex.FromIndex): any {\n if (!value) {\n return null;\n }\n\n const fields = field.settings?.fields || [];\n\n if (field.list) {\n const source = value || rawValue || [];\n\n return source.map((_: any, index: number) => {\n const processed = this.processFromIndex({\n value: value ? value[index] || {} : {},\n rawValue: rawValue ? rawValue[index] || {} : {},\n getFieldIndex,\n model,\n fields\n });\n const sourceItem = value ? value[index] : rawValue ? rawValue[index] : null;\n if (sourceItem?._id) {\n processed._id = sourceItem._id;\n }\n return processed;\n });\n }\n\n return this.processFromIndex({\n value,\n rawValue,\n getFieldIndex,\n model,\n fields\n });\n }\n\n private processToIndex(params: ProcessToIndexParams): ReducerValue {\n const {\n fields,\n value: sourceValue,\n rawValue: sourceRawValue,\n getFieldIndex,\n model\n } = params;\n\n return fields.reduce<ReducerValue>(\n (values, field) => {\n const plugin = getFieldIndex(field.type);\n\n const identifiers = getFieldIdentifiers(sourceValue, sourceRawValue, field);\n if (!identifiers) {\n return values;\n }\n\n const { value, rawValue } = plugin.toIndex({\n model,\n field,\n value: sourceValue[\n identifiers.valueIdentifier || identifiers.rawValueIdentifier\n ],\n rawValue:\n sourceRawValue[\n identifiers.rawValueIdentifier || identifiers.valueIdentifier\n ],\n getFieldIndex\n });\n\n if (value !== undefined) {\n values.value[identifiers.valueIdentifier || identifiers.rawValueIdentifier] =\n value;\n }\n if (rawValue !== undefined) {\n values.rawValue[identifiers.rawValueIdentifier || identifiers.valueIdentifier] =\n rawValue;\n }\n\n return values;\n },\n { value: {}, rawValue: {} }\n );\n }\n\n private processFromIndex = (params: ProcessFromIndexParams): Record<string, any> => {\n const {\n fields,\n value: sourceValue,\n rawValue: sourceRawValue,\n getFieldIndex,\n model\n } = params;\n\n return fields.reduce<Record<string, any>>((values, field) => {\n const plugin = getFieldIndex(field.type);\n\n const identifiers = getFieldIdentifiers(sourceValue, sourceRawValue, field);\n if (!identifiers) {\n return values;\n }\n\n const value = plugin.fromIndex({\n model,\n field,\n value: sourceValue[identifiers.valueIdentifier || identifiers.rawValueIdentifier],\n rawValue: sourceRawValue\n ? sourceRawValue[identifiers.rawValueIdentifier || identifiers.valueIdentifier]\n : null,\n getFieldIndex\n });\n\n if (value !== undefined) {\n values[identifiers.valueIdentifier || identifiers.rawValueIdentifier] = value;\n }\n\n return values;\n }, {});\n };\n}\n\nexport const ObjectFieldIndex = CmsEntryOpenSearchFieldIndex.createImplementation({\n implementation: ObjectFieldIndexImpl,\n dependencies: []\n});\n"],"names":["ObjectFieldIndexImpl","model","field","initialValue","initialRawValue","getFieldIndex","fields","result","key","value","rawValue","undefined","source","_","index","processed","sourceItem","params","sourceValue","sourceRawValue","values","plugin","identifiers","getFieldIdentifiers","ObjectFieldIndex","CmsEntryOpenSearchFieldIndex"],"mappings":"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"}
@@ -3,7 +3,7 @@ import type { OpenSearchIndexRequestBody } from "@webiny/api-opensearch/types.js
3
3
  declare class BaseOpenSearchIndexImpl implements CmsEntryOpenSearchIndex.Interface {
4
4
  readonly body: OpenSearchIndexRequestBody;
5
5
  constructor();
6
- canUse(_: CmsEntryOpenSearchIndex.CanUseParams): boolean;
6
+ canUse(): boolean;
7
7
  }
8
8
  export declare const BaseOpenSearchIndex: typeof BaseOpenSearchIndexImpl & {
9
9
  __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICmsEntryOpenSearchIndex>;
@@ -4,7 +4,7 @@ class BaseOpenSearchIndexImpl {
4
4
  constructor(){
5
5
  this.body = getBaseConfiguration();
6
6
  }
7
- canUse(_) {
7
+ canUse() {
8
8
  return true;
9
9
  }
10
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js","sources":["../../../src/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.ts"],"sourcesContent":["import { getBaseConfiguration } from \"@webiny/api-opensearch\";\nimport { CmsEntryOpenSearchIndex } from \"./abstractions.js\";\nimport type { OpenSearchIndexRequestBody } from \"@webiny/api-opensearch/types.js\";\n\nclass BaseOpenSearchIndexImpl implements CmsEntryOpenSearchIndex.Interface {\n public readonly body: OpenSearchIndexRequestBody;\n\n public constructor() {\n this.body = getBaseConfiguration();\n }\n public canUse(_: CmsEntryOpenSearchIndex.CanUseParams): boolean {\n return true;\n }\n}\n\nexport const BaseOpenSearchIndex = CmsEntryOpenSearchIndex.createImplementation({\n implementation: BaseOpenSearchIndexImpl,\n dependencies: []\n});\n"],"names":["BaseOpenSearchIndexImpl","getBaseConfiguration","_","BaseOpenSearchIndex","CmsEntryOpenSearchIndex"],"mappings":";;AAIA,MAAMA;IAGF,aAAqB;QACjB,IAAI,CAAC,IAAI,GAAGC;IAChB;IACO,OAAOC,CAAuC,EAAW;QAC5D,OAAO;IACX;AACJ;AAEO,MAAMC,sBAAsBC,wBAAwB,oBAAoB,CAAC;IAC5E,gBAAgBJ;IAChB,cAAc,EAAE;AACpB"}
1
+ {"version":3,"file":"features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.js","sources":["../../../src/features/CmsEntryOpenSearchIndex/BaseOpenSearchIndex.ts"],"sourcesContent":["import { getBaseConfiguration } from \"@webiny/api-opensearch\";\nimport { CmsEntryOpenSearchIndex } from \"./abstractions.js\";\nimport type { OpenSearchIndexRequestBody } from \"@webiny/api-opensearch/types.js\";\n\nclass BaseOpenSearchIndexImpl implements CmsEntryOpenSearchIndex.Interface {\n public readonly body: OpenSearchIndexRequestBody;\n\n public constructor() {\n this.body = getBaseConfiguration();\n }\n public canUse(): boolean {\n return true;\n }\n}\n\nexport const BaseOpenSearchIndex = CmsEntryOpenSearchIndex.createImplementation({\n implementation: BaseOpenSearchIndexImpl,\n dependencies: []\n});\n"],"names":["BaseOpenSearchIndexImpl","getBaseConfiguration","BaseOpenSearchIndex","CmsEntryOpenSearchIndex"],"mappings":";;AAIA,MAAMA;IAGF,aAAqB;QACjB,IAAI,CAAC,IAAI,GAAGC;IAChB;IACO,SAAkB;QACrB,OAAO;IACX;AACJ;AAEO,MAAMC,sBAAsBC,wBAAwB,oBAAoB,CAAC;IAC5E,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
@@ -2,7 +2,7 @@ import error from "@webiny/error";
2
2
  import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
3
3
  import { CmsModelOpenSearchIndexProvider } from "../CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js";
4
4
  import { CmsEntryOpenSearchIndexCreate } from "./abstractions.js";
5
- import { getOpenSearchIndexPrefix } from "@webiny/api-opensearch";
5
+ import { createConfigurations } from "../../configurations.js";
6
6
  class CmsEntryOpenSearchIndexCreateImpl {
7
7
  constructor(openSearchClient, indexProvider){
8
8
  this.openSearchClient = openSearchClient;
@@ -11,11 +11,10 @@ class CmsEntryOpenSearchIndexCreateImpl {
11
11
  async execute(params) {
12
12
  const { model } = params;
13
13
  const client = this.openSearchClient.use();
14
- const { index: rawIndex, settings } = await this.indexProvider.execute({
14
+ const configurations = createConfigurations(this.indexProvider);
15
+ const { index, settings } = await configurations.es({
15
16
  model
16
17
  });
17
- const prefix = getOpenSearchIndexPrefix();
18
- const index = prefix ? prefix + rawIndex : rawIndex;
19
18
  try {
20
19
  const response = await client.indices.exists({
21
20
  index,
@@ -1 +1 @@
1
- {"version":3,"file":"features/CmsEntryOpenSearchIndexCreate/CmsEntryOpenSearchIndexCreate.js","sources":["../../../src/features/CmsEntryOpenSearchIndexCreate/CmsEntryOpenSearchIndexCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"~/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js\";\nimport { CmsEntryOpenSearchIndexCreate as CmsEntryOpenSearchIndexCreateAbstraction } from \"./abstractions.js\";\nimport { getOpenSearchIndexPrefix } from \"@webiny/api-opensearch\";\n\nclass CmsEntryOpenSearchIndexCreateImpl\n implements CmsEntryOpenSearchIndexCreateAbstraction.Interface\n{\n public constructor(\n private readonly openSearchClient: OpenSearchClient.Interface,\n private readonly indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {}\n\n public async execute(params: CmsEntryOpenSearchIndexCreateAbstraction.Params): Promise<void> {\n const { model } = params;\n const client = this.openSearchClient.use();\n\n const { index: rawIndex, settings } = await this.indexProvider.execute({ model });\n const prefix = getOpenSearchIndexPrefix();\n const index = prefix ? prefix + rawIndex : rawIndex;\n\n try {\n const response = await client.indices.exists({\n index,\n ignore_unavailable: false,\n allow_no_indices: true,\n include_defaults: true,\n flat_settings: false,\n local: false\n });\n if (response.body) {\n console.log(\n `Elasticsearch index \"${index}\" for the CMS model \"${model.name}\" already exists.`\n );\n return;\n }\n } catch {\n console.error(`Could not determine if the index \"${index}\" exists.`);\n }\n\n try {\n await client.indices.create({\n index,\n body: {\n ...settings\n }\n });\n } catch (ex) {\n console.error(\n `Could not create Elasticsearch index \"${index}\" for the CMS model \"${model.name}\".`\n );\n console.error(ex);\n throw new WebinyError(\n ex.message || \"Could not create OpenSearch index for the CMS entry.\",\n ex.code || \"CREATE_OPENSEARCH_INDEX_ERROR\",\n {\n error: {\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n },\n tenant: model.tenant,\n index,\n body: settings\n }\n );\n }\n }\n}\n\nexport const CmsEntryOpenSearchIndexCreate =\n CmsEntryOpenSearchIndexCreateAbstraction.createImplementation({\n implementation: CmsEntryOpenSearchIndexCreateImpl,\n dependencies: [OpenSearchClient, CmsModelOpenSearchIndexProvider]\n });\n"],"names":["CmsEntryOpenSearchIndexCreateImpl","openSearchClient","indexProvider","params","model","client","rawIndex","settings","prefix","getOpenSearchIndexPrefix","index","response","console","ex","WebinyError","CmsEntryOpenSearchIndexCreate","CmsEntryOpenSearchIndexCreateAbstraction","OpenSearchClient","CmsModelOpenSearchIndexProvider"],"mappings":";;;;;AAMA,MAAMA;IAGF,YACqBC,gBAA4C,EAC5CC,aAAwD,CAC3E;aAFmBD,gBAAgB,GAAhBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAa,QAAQC,MAAuD,EAAiB;QACzF,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAME,SAAS,IAAI,CAAC,gBAAgB,CAAC,GAAG;QAExC,MAAM,EAAE,OAAOC,QAAQ,EAAEC,QAAQ,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAAEH;QAAM;QAC/E,MAAMI,SAASC;QACf,MAAMC,QAAQF,SAASA,SAASF,WAAWA;QAE3C,IAAI;YACA,MAAMK,WAAW,MAAMN,OAAO,OAAO,CAAC,MAAM,CAAC;gBACzCK;gBACA,oBAAoB;gBACpB,kBAAkB;gBAClB,kBAAkB;gBAClB,eAAe;gBACf,OAAO;YACX;YACA,IAAIC,SAAS,IAAI,EAAE,YACfC,QAAQ,GAAG,CACP,CAAC,qBAAqB,EAAEF,MAAM,qBAAqB,EAAEN,MAAM,IAAI,CAAC,iBAAiB,CAAC;QAI9F,EAAE,OAAM;YACJQ,QAAQ,KAAK,CAAC,CAAC,kCAAkC,EAAEF,MAAM,SAAS,CAAC;QACvE;QAEA,IAAI;YACA,MAAML,OAAO,OAAO,CAAC,MAAM,CAAC;gBACxBK;gBACA,MAAM;oBACF,GAAGH,QAAQ;gBACf;YACJ;QACJ,EAAE,OAAOM,IAAI;YACTD,QAAQ,KAAK,CACT,CAAC,sCAAsC,EAAEF,MAAM,qBAAqB,EAAEN,MAAM,IAAI,CAAC,EAAE,CAAC;YAExFQ,QAAQ,KAAK,CAACC;YACd,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wDACdA,GAAG,IAAI,IAAI,iCACX;gBACI,OAAO;oBACH,GAAGA,EAAE;oBACL,SAASA,GAAG,OAAO;oBACnB,MAAMA,GAAG,IAAI;oBACb,MAAMA,GAAG,IAAI;gBACjB;gBACA,QAAQT,MAAM,MAAM;gBACpBM;gBACA,MAAMH;YACV;QAER;IACJ;AACJ;AAEO,MAAMQ,8DACTC,8BAAAA,oBAA6D,CAAC;IAC1D,gBAAgBhB;IAChB,cAAc;QAACiB;QAAkBC;KAAgC;AACrE"}
1
+ {"version":3,"file":"features/CmsEntryOpenSearchIndexCreate/CmsEntryOpenSearchIndexCreate.js","sources":["../../../src/features/CmsEntryOpenSearchIndexCreate/CmsEntryOpenSearchIndexCreate.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"~/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js\";\nimport { CmsEntryOpenSearchIndexCreate as CmsEntryOpenSearchIndexCreateAbstraction } from \"./abstractions.js\";\nimport { createConfigurations } from \"~/configurations.js\";\n\nclass CmsEntryOpenSearchIndexCreateImpl\n implements CmsEntryOpenSearchIndexCreateAbstraction.Interface\n{\n public constructor(\n private readonly openSearchClient: OpenSearchClient.Interface,\n private readonly indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {}\n\n public async execute(params: CmsEntryOpenSearchIndexCreateAbstraction.Params): Promise<void> {\n const { model } = params;\n const client = this.openSearchClient.use();\n\n const configurations = createConfigurations(this.indexProvider);\n const { index, settings } = await configurations.es({ model });\n\n try {\n const response = await client.indices.exists({\n index,\n ignore_unavailable: false,\n allow_no_indices: true,\n include_defaults: true,\n flat_settings: false,\n local: false\n });\n if (response.body) {\n console.log(\n `Elasticsearch index \"${index}\" for the CMS model \"${model.name}\" already exists.`\n );\n return;\n }\n } catch {\n console.error(`Could not determine if the index \"${index}\" exists.`);\n }\n\n try {\n await client.indices.create({\n index,\n body: {\n ...settings\n }\n });\n } catch (ex) {\n console.error(\n `Could not create Elasticsearch index \"${index}\" for the CMS model \"${model.name}\".`\n );\n console.error(ex);\n throw new WebinyError(\n ex.message || \"Could not create OpenSearch index for the CMS entry.\",\n ex.code || \"CREATE_OPENSEARCH_INDEX_ERROR\",\n {\n error: {\n ...ex,\n message: ex.message,\n code: ex.code,\n data: ex.data\n },\n tenant: model.tenant,\n index,\n body: settings\n }\n );\n }\n }\n}\n\nexport const CmsEntryOpenSearchIndexCreate =\n CmsEntryOpenSearchIndexCreateAbstraction.createImplementation({\n implementation: CmsEntryOpenSearchIndexCreateImpl,\n dependencies: [OpenSearchClient, CmsModelOpenSearchIndexProvider]\n });\n"],"names":["CmsEntryOpenSearchIndexCreateImpl","openSearchClient","indexProvider","params","model","client","configurations","createConfigurations","index","settings","response","console","ex","WebinyError","CmsEntryOpenSearchIndexCreate","CmsEntryOpenSearchIndexCreateAbstraction","OpenSearchClient","CmsModelOpenSearchIndexProvider"],"mappings":";;;;;AAMA,MAAMA;IAGF,YACqBC,gBAA4C,EAC5CC,aAAwD,CAC3E;aAFmBD,gBAAgB,GAAhBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAa,QAAQC,MAAuD,EAAiB;QACzF,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAME,SAAS,IAAI,CAAC,gBAAgB,CAAC,GAAG;QAExC,MAAMC,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAE,GAAG,MAAMH,eAAe,EAAE,CAAC;YAAEF;QAAM;QAE5D,IAAI;YACA,MAAMM,WAAW,MAAML,OAAO,OAAO,CAAC,MAAM,CAAC;gBACzCG;gBACA,oBAAoB;gBACpB,kBAAkB;gBAClB,kBAAkB;gBAClB,eAAe;gBACf,OAAO;YACX;YACA,IAAIE,SAAS,IAAI,EAAE,YACfC,QAAQ,GAAG,CACP,CAAC,qBAAqB,EAAEH,MAAM,qBAAqB,EAAEJ,MAAM,IAAI,CAAC,iBAAiB,CAAC;QAI9F,EAAE,OAAM;YACJO,QAAQ,KAAK,CAAC,CAAC,kCAAkC,EAAEH,MAAM,SAAS,CAAC;QACvE;QAEA,IAAI;YACA,MAAMH,OAAO,OAAO,CAAC,MAAM,CAAC;gBACxBG;gBACA,MAAM;oBACF,GAAGC,QAAQ;gBACf;YACJ;QACJ,EAAE,OAAOG,IAAI;YACTD,QAAQ,KAAK,CACT,CAAC,sCAAsC,EAAEH,MAAM,qBAAqB,EAAEJ,MAAM,IAAI,CAAC,EAAE,CAAC;YAExFO,QAAQ,KAAK,CAACC;YACd,MAAM,IAAIC,MACND,GAAG,OAAO,IAAI,wDACdA,GAAG,IAAI,IAAI,iCACX;gBACI,OAAO;oBACH,GAAGA,EAAE;oBACL,SAASA,GAAG,OAAO;oBACnB,MAAMA,GAAG,IAAI;oBACb,MAAMA,GAAG,IAAI;gBACjB;gBACA,QAAQR,MAAM,MAAM;gBACpBI;gBACA,MAAMC;YACV;QAER;IACJ;AACJ;AAEO,MAAMK,8DACTC,8BAAAA,oBAA6D,CAAC;IAC1D,gBAAgBf;IAChB,cAAc;QAACgB;QAAkBC;KAAgC;AACrE"}
@@ -1,7 +1,7 @@
1
1
  import { OpenSearchClient } from "@webiny/api-opensearch/exports/api/opensearch.js";
2
2
  import { CmsModelOpenSearchIndexProvider } from "../CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js";
3
3
  import { CmsEntryOpenSearchIndexDelete } from "./abstractions.js";
4
- import { getOpenSearchIndexPrefix } from "@webiny/api-opensearch";
4
+ import { createConfigurations } from "../../configurations.js";
5
5
  class CmsEntryOpenSearchIndexDeleteImpl {
6
6
  constructor(openSearchClient, indexProvider){
7
7
  this.openSearchClient = openSearchClient;
@@ -9,12 +9,11 @@ class CmsEntryOpenSearchIndexDeleteImpl {
9
9
  }
10
10
  async execute(params) {
11
11
  const { model } = params;
12
- const { index: rawIndex, shared } = await this.indexProvider.execute({
12
+ const configurations = createConfigurations(this.indexProvider);
13
+ const { index, shared } = await configurations.es({
13
14
  model
14
15
  });
15
16
  if (shared) return;
16
- const prefix = getOpenSearchIndexPrefix();
17
- const index = prefix ? prefix + rawIndex : rawIndex;
18
17
  const client = this.openSearchClient.use();
19
18
  const { body: exists } = await client.indices.exists({
20
19
  index
@@ -1 +1 @@
1
- {"version":3,"file":"features/CmsEntryOpenSearchIndexDelete/CmsEntryOpenSearchIndexDelete.js","sources":["../../../src/features/CmsEntryOpenSearchIndexDelete/CmsEntryOpenSearchIndexDelete.ts"],"sourcesContent":["import { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"~/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js\";\nimport { CmsEntryOpenSearchIndexDelete as CmsEntryOpenSearchIndexDeleteAbstraction } from \"./abstractions.js\";\nimport { getOpenSearchIndexPrefix } from \"@webiny/api-opensearch\";\n\nclass CmsEntryOpenSearchIndexDeleteImpl\n implements CmsEntryOpenSearchIndexDeleteAbstraction.Interface\n{\n public constructor(\n private readonly openSearchClient: OpenSearchClient.Interface,\n private readonly indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {}\n\n public async execute(params: CmsEntryOpenSearchIndexDeleteAbstraction.Params): Promise<void> {\n const { model } = params;\n\n const { index: rawIndex, shared } = await this.indexProvider.execute({ model });\n if (shared) {\n return;\n }\n\n const prefix = getOpenSearchIndexPrefix();\n const index = prefix ? prefix + rawIndex : rawIndex;\n const client = this.openSearchClient.use();\n\n const { body: exists } = await client.indices.exists({ index });\n if (!exists) {\n return;\n }\n\n try {\n await client.indices.delete({\n index,\n ignore_unavailable: true\n });\n } catch (ex) {\n console.log(`Could not delete Elasticsearch index \"${index}\". Please do it manually.`);\n console.log(ex.message);\n }\n }\n}\n\nexport const CmsEntryOpenSearchIndexDelete =\n CmsEntryOpenSearchIndexDeleteAbstraction.createImplementation({\n implementation: CmsEntryOpenSearchIndexDeleteImpl,\n dependencies: [OpenSearchClient, CmsModelOpenSearchIndexProvider]\n });\n"],"names":["CmsEntryOpenSearchIndexDeleteImpl","openSearchClient","indexProvider","params","model","rawIndex","shared","prefix","getOpenSearchIndexPrefix","index","client","exists","ex","console","CmsEntryOpenSearchIndexDelete","CmsEntryOpenSearchIndexDeleteAbstraction","OpenSearchClient","CmsModelOpenSearchIndexProvider"],"mappings":";;;;AAKA,MAAMA;IAGF,YACqBC,gBAA4C,EAC5CC,aAAwD,CAC3E;aAFmBD,gBAAgB,GAAhBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAa,QAAQC,MAAuD,EAAiB;QACzF,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAElB,MAAM,EAAE,OAAOE,QAAQ,EAAEC,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAAEF;QAAM;QAC7E,IAAIE,QACA;QAGJ,MAAMC,SAASC;QACf,MAAMC,QAAQF,SAASA,SAASF,WAAWA;QAC3C,MAAMK,SAAS,IAAI,CAAC,gBAAgB,CAAC,GAAG;QAExC,MAAM,EAAE,MAAMC,MAAM,EAAE,GAAG,MAAMD,OAAO,OAAO,CAAC,MAAM,CAAC;YAAED;QAAM;QAC7D,IAAI,CAACE,QACD;QAGJ,IAAI;YACA,MAAMD,OAAO,OAAO,CAAC,MAAM,CAAC;gBACxBD;gBACA,oBAAoB;YACxB;QACJ,EAAE,OAAOG,IAAI;YACTC,QAAQ,GAAG,CAAC,CAAC,sCAAsC,EAAEJ,MAAM,yBAAyB,CAAC;YACrFI,QAAQ,GAAG,CAACD,GAAG,OAAO;QAC1B;IACJ;AACJ;AAEO,MAAME,8DACTC,8BAAAA,oBAA6D,CAAC;IAC1D,gBAAgBf;IAChB,cAAc;QAACgB;QAAkBC;KAAgC;AACrE"}
1
+ {"version":3,"file":"features/CmsEntryOpenSearchIndexDelete/CmsEntryOpenSearchIndexDelete.js","sources":["../../../src/features/CmsEntryOpenSearchIndexDelete/CmsEntryOpenSearchIndexDelete.ts"],"sourcesContent":["import { OpenSearchClient } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"~/features/CmsModelOpenSearchIndex/CmsModelOpenSearchIndexProvider.js\";\nimport { CmsEntryOpenSearchIndexDelete as CmsEntryOpenSearchIndexDeleteAbstraction } from \"./abstractions.js\";\nimport { createConfigurations } from \"~/configurations.js\";\n\nclass CmsEntryOpenSearchIndexDeleteImpl\n implements CmsEntryOpenSearchIndexDeleteAbstraction.Interface\n{\n public constructor(\n private readonly openSearchClient: OpenSearchClient.Interface,\n private readonly indexProvider: CmsModelOpenSearchIndexProvider.Interface\n ) {}\n\n public async execute(params: CmsEntryOpenSearchIndexDeleteAbstraction.Params): Promise<void> {\n const { model } = params;\n\n const configurations = createConfigurations(this.indexProvider);\n const { index, shared } = await configurations.es({ model });\n if (shared) {\n return;\n }\n const client = this.openSearchClient.use();\n\n const { body: exists } = await client.indices.exists({ index });\n if (!exists) {\n return;\n }\n\n try {\n await client.indices.delete({\n index,\n ignore_unavailable: true\n });\n } catch (ex) {\n console.log(`Could not delete Elasticsearch index \"${index}\". Please do it manually.`);\n console.log(ex.message);\n }\n }\n}\n\nexport const CmsEntryOpenSearchIndexDelete =\n CmsEntryOpenSearchIndexDeleteAbstraction.createImplementation({\n implementation: CmsEntryOpenSearchIndexDeleteImpl,\n dependencies: [OpenSearchClient, CmsModelOpenSearchIndexProvider]\n });\n"],"names":["CmsEntryOpenSearchIndexDeleteImpl","openSearchClient","indexProvider","params","model","configurations","createConfigurations","index","shared","client","exists","ex","console","CmsEntryOpenSearchIndexDelete","CmsEntryOpenSearchIndexDeleteAbstraction","OpenSearchClient","CmsModelOpenSearchIndexProvider"],"mappings":";;;;AAKA,MAAMA;IAGF,YACqBC,gBAA4C,EAC5CC,aAAwD,CAC3E;aAFmBD,gBAAgB,GAAhBA;aACAC,aAAa,GAAbA;IAClB;IAEH,MAAa,QAAQC,MAAuD,EAAiB;QACzF,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAElB,MAAME,iBAAiBC,qBAAqB,IAAI,CAAC,aAAa;QAC9D,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAG,MAAMH,eAAe,EAAE,CAAC;YAAED;QAAM;QAC1D,IAAII,QACA;QAEJ,MAAMC,SAAS,IAAI,CAAC,gBAAgB,CAAC,GAAG;QAExC,MAAM,EAAE,MAAMC,MAAM,EAAE,GAAG,MAAMD,OAAO,OAAO,CAAC,MAAM,CAAC;YAAEF;QAAM;QAC7D,IAAI,CAACG,QACD;QAGJ,IAAI;YACA,MAAMD,OAAO,OAAO,CAAC,MAAM,CAAC;gBACxBF;gBACA,oBAAoB;YACxB;QACJ,EAAE,OAAOI,IAAI;YACTC,QAAQ,GAAG,CAAC,CAAC,sCAAsC,EAAEL,MAAM,yBAAyB,CAAC;YACrFK,QAAQ,GAAG,CAACD,GAAG,OAAO;QAC1B;IACJ;AACJ;AAEO,MAAME,8DACTC,8BAAAA,oBAA6D,CAAC;IAC1D,gBAAgBd;IAChB,cAAc;QAACe;QAAkBC;KAAgC;AACrE"}
@@ -13,9 +13,11 @@ import { CmsEntryOpenSearchValueSearchFeature } from "./CmsEntryOpenSearchValueS
13
13
  import { ModelAfterCreateHandler } from "./CmsEntryOpenSearchIndexCreate/ModelAfterCreateHandler.js";
14
14
  import { ModelAfterCreateFromHandler } from "./CmsEntryOpenSearchIndexCreate/ModelAfterCreateFromHandler.js";
15
15
  import { ModelAfterDeleteHandler } from "./CmsEntryOpenSearchIndexDelete/ModelAfterDeleteHandler.js";
16
+ import { CmsModelOpenSearchIndexFeature } from "./CmsModelOpenSearchIndex/index.js";
16
17
  const CmsEntryOpenSearchUtilsFeature = createFeature({
17
18
  name: "Cms/Entry/OpenSearch/UtilsFeature",
18
19
  register: (container)=>{
20
+ CmsModelOpenSearchIndexFeature.register(container);
19
21
  CmsEntryOpenSearchFieldIndexFeature.register(container);
20
22
  CmsEntryOpenSearchFilterFeature.register(container);
21
23
  CmsEntryOpenSearchIndexFeature.register(container);
@@ -1 +1 @@
1
- {"version":3,"file":"features/CmsEntryOpenSearchUtilsFeature.js","sources":["../../src/features/CmsEntryOpenSearchUtilsFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CmsEntryOpenSearchFieldIndexFeature } from \"./CmsEntryOpenSearchFieldIndex/feature.js\";\nimport { CmsEntryOpenSearchFilterFeature } from \"./CmsEntryOpenSearchFilter/feature.js\";\nimport { CmsEntryOpenSearchIndexFeature } from \"./CmsEntryOpenSearchIndex/feature.js\";\nimport { CmsEntryOpenSearchIndexCreateFeature } from \"./CmsEntryOpenSearchIndexCreate/feature.js\";\nimport { CmsEntryOpenSearchIndexDeleteFeature } from \"./CmsEntryOpenSearchIndexDelete/feature.js\";\nimport { CmsEntryOpenSearchFieldPathFactoryFeature } from \"./CmsEntryOpenSearchFieldPathFactory/feature.js\";\nimport { CmsEntryOpenSearchValueTransformerFeature } from \"./CmsEntryOpenSearchValueTransformer/feature.js\";\nimport { CmsEntryOpenSearchOperatorListFeature } from \"./CmsEntryOpenSearchOperatorList/feature.js\";\nimport { CmsEntryOpenSearchExecFilteringFeature } from \"./CmsEntryOpenSearchExecFiltering/feature.js\";\nimport { CmsEntryOpenSearchBodyBuilderFeature } from \"./CmsEntryOpenSearchBodyBuilder/feature.js\";\nimport { CmsEntryOpenSearchValueSearchFeature } from \"./CmsEntryOpenSearchValueSearch/feature.js\";\nimport { ModelAfterCreateHandler } from \"./CmsEntryOpenSearchIndexCreate/ModelAfterCreateHandler.js\";\nimport { ModelAfterCreateFromHandler } from \"./CmsEntryOpenSearchIndexCreate/ModelAfterCreateFromHandler.js\";\nimport { ModelAfterDeleteHandler } from \"./CmsEntryOpenSearchIndexDelete/ModelAfterDeleteHandler.js\";\n\nexport const CmsEntryOpenSearchUtilsFeature = createFeature({\n name: \"Cms/Entry/OpenSearch/UtilsFeature\",\n register: container => {\n CmsEntryOpenSearchFieldIndexFeature.register(container);\n CmsEntryOpenSearchFilterFeature.register(container);\n CmsEntryOpenSearchIndexFeature.register(container);\n CmsEntryOpenSearchIndexCreateFeature.register(container);\n CmsEntryOpenSearchIndexDeleteFeature.register(container);\n CmsEntryOpenSearchFieldPathFactoryFeature.register(container);\n CmsEntryOpenSearchValueTransformerFeature.register(container);\n CmsEntryOpenSearchOperatorListFeature.register(container);\n CmsEntryOpenSearchExecFilteringFeature.register(container);\n CmsEntryOpenSearchBodyBuilderFeature.register(container);\n CmsEntryOpenSearchValueSearchFeature.register(container);\n\n // Model lifecycle event handlers for OpenSearch index management\n container.register(ModelAfterCreateHandler);\n container.register(ModelAfterCreateFromHandler);\n container.register(ModelAfterDeleteHandler);\n }\n});\n"],"names":["CmsEntryOpenSearchUtilsFeature","createFeature","container","CmsEntryOpenSearchFieldIndexFeature","CmsEntryOpenSearchFilterFeature","CmsEntryOpenSearchIndexFeature","CmsEntryOpenSearchIndexCreateFeature","CmsEntryOpenSearchIndexDeleteFeature","CmsEntryOpenSearchFieldPathFactoryFeature","CmsEntryOpenSearchValueTransformerFeature","CmsEntryOpenSearchOperatorListFeature","CmsEntryOpenSearchExecFilteringFeature","CmsEntryOpenSearchBodyBuilderFeature","CmsEntryOpenSearchValueSearchFeature","ModelAfterCreateHandler","ModelAfterCreateFromHandler","ModelAfterDeleteHandler"],"mappings":";;;;;;;;;;;;;;;AAgBO,MAAMA,iCAAiCC,cAAc;IACxD,MAAM;IACN,UAAUC,CAAAA;QACNC,oCAAoC,QAAQ,CAACD;QAC7CE,gCAAgC,QAAQ,CAACF;QACzCG,+BAA+B,QAAQ,CAACH;QACxCI,qCAAqC,QAAQ,CAACJ;QAC9CK,qCAAqC,QAAQ,CAACL;QAC9CM,0CAA0C,QAAQ,CAACN;QACnDO,0CAA0C,QAAQ,CAACP;QACnDQ,sCAAsC,QAAQ,CAACR;QAC/CS,uCAAuC,QAAQ,CAACT;QAChDU,qCAAqC,QAAQ,CAACV;QAC9CW,qCAAqC,QAAQ,CAACX;QAG9CA,UAAU,QAAQ,CAACY;QACnBZ,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;IACvB;AACJ"}
1
+ {"version":3,"file":"features/CmsEntryOpenSearchUtilsFeature.js","sources":["../../src/features/CmsEntryOpenSearchUtilsFeature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { CmsEntryOpenSearchFieldIndexFeature } from \"./CmsEntryOpenSearchFieldIndex/feature.js\";\nimport { CmsEntryOpenSearchFilterFeature } from \"./CmsEntryOpenSearchFilter/feature.js\";\nimport { CmsEntryOpenSearchIndexFeature } from \"./CmsEntryOpenSearchIndex/feature.js\";\nimport { CmsEntryOpenSearchIndexCreateFeature } from \"./CmsEntryOpenSearchIndexCreate/feature.js\";\nimport { CmsEntryOpenSearchIndexDeleteFeature } from \"./CmsEntryOpenSearchIndexDelete/feature.js\";\nimport { CmsEntryOpenSearchFieldPathFactoryFeature } from \"./CmsEntryOpenSearchFieldPathFactory/feature.js\";\nimport { CmsEntryOpenSearchValueTransformerFeature } from \"./CmsEntryOpenSearchValueTransformer/feature.js\";\nimport { CmsEntryOpenSearchOperatorListFeature } from \"./CmsEntryOpenSearchOperatorList/feature.js\";\nimport { CmsEntryOpenSearchExecFilteringFeature } from \"./CmsEntryOpenSearchExecFiltering/feature.js\";\nimport { CmsEntryOpenSearchBodyBuilderFeature } from \"./CmsEntryOpenSearchBodyBuilder/feature.js\";\nimport { CmsEntryOpenSearchValueSearchFeature } from \"./CmsEntryOpenSearchValueSearch/feature.js\";\nimport { ModelAfterCreateHandler } from \"./CmsEntryOpenSearchIndexCreate/ModelAfterCreateHandler.js\";\nimport { ModelAfterCreateFromHandler } from \"./CmsEntryOpenSearchIndexCreate/ModelAfterCreateFromHandler.js\";\nimport { ModelAfterDeleteHandler } from \"./CmsEntryOpenSearchIndexDelete/ModelAfterDeleteHandler.js\";\nimport { CmsModelOpenSearchIndexFeature } from \"./CmsModelOpenSearchIndex/index.js\";\n\nexport const CmsEntryOpenSearchUtilsFeature = createFeature({\n name: \"Cms/Entry/OpenSearch/UtilsFeature\",\n register: container => {\n CmsModelOpenSearchIndexFeature.register(container);\n CmsEntryOpenSearchFieldIndexFeature.register(container);\n CmsEntryOpenSearchFilterFeature.register(container);\n CmsEntryOpenSearchIndexFeature.register(container);\n CmsEntryOpenSearchIndexCreateFeature.register(container);\n CmsEntryOpenSearchIndexDeleteFeature.register(container);\n CmsEntryOpenSearchFieldPathFactoryFeature.register(container);\n CmsEntryOpenSearchValueTransformerFeature.register(container);\n CmsEntryOpenSearchOperatorListFeature.register(container);\n CmsEntryOpenSearchExecFilteringFeature.register(container);\n CmsEntryOpenSearchBodyBuilderFeature.register(container);\n CmsEntryOpenSearchValueSearchFeature.register(container);\n\n // Model lifecycle event handlers for OpenSearch index management\n container.register(ModelAfterCreateHandler);\n container.register(ModelAfterCreateFromHandler);\n container.register(ModelAfterDeleteHandler);\n }\n});\n"],"names":["CmsEntryOpenSearchUtilsFeature","createFeature","container","CmsModelOpenSearchIndexFeature","CmsEntryOpenSearchFieldIndexFeature","CmsEntryOpenSearchFilterFeature","CmsEntryOpenSearchIndexFeature","CmsEntryOpenSearchIndexCreateFeature","CmsEntryOpenSearchIndexDeleteFeature","CmsEntryOpenSearchFieldPathFactoryFeature","CmsEntryOpenSearchValueTransformerFeature","CmsEntryOpenSearchOperatorListFeature","CmsEntryOpenSearchExecFilteringFeature","CmsEntryOpenSearchBodyBuilderFeature","CmsEntryOpenSearchValueSearchFeature","ModelAfterCreateHandler","ModelAfterCreateFromHandler","ModelAfterDeleteHandler"],"mappings":";;;;;;;;;;;;;;;;AAiBO,MAAMA,iCAAiCC,cAAc;IACxD,MAAM;IACN,UAAUC,CAAAA;QACNC,+BAA+B,QAAQ,CAACD;QACxCE,oCAAoC,QAAQ,CAACF;QAC7CG,gCAAgC,QAAQ,CAACH;QACzCI,+BAA+B,QAAQ,CAACJ;QACxCK,qCAAqC,QAAQ,CAACL;QAC9CM,qCAAqC,QAAQ,CAACN;QAC9CO,0CAA0C,QAAQ,CAACP;QACnDQ,0CAA0C,QAAQ,CAACR;QACnDS,sCAAsC,QAAQ,CAACT;QAC/CU,uCAAuC,QAAQ,CAACV;QAChDW,qCAAqC,QAAQ,CAACX;QAC9CY,qCAAqC,QAAQ,CAACZ;QAG9CA,UAAU,QAAQ,CAACa;QACnBb,UAAU,QAAQ,CAACc;QACnBd,UAAU,QAAQ,CAACe;IACvB;AACJ"}
@@ -0,0 +1,8 @@
1
+ import { CmsModelOpenSearchIndex } from "./abstractions.js";
2
+ declare class DefaultCmsModelOpenSearchIndexImpl implements CmsModelOpenSearchIndex.Interface {
3
+ execute(): Promise<CmsModelOpenSearchIndex.Result>;
4
+ }
5
+ export declare const DefaultCmsModelOpenSearchIndex: typeof DefaultCmsModelOpenSearchIndexImpl & {
6
+ __abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ICmsModelOpenSearchIndex>;
7
+ };
8
+ export {};
@@ -0,0 +1,17 @@
1
+ import { getBaseConfiguration, isSharedOpenSearchIndex } from "@webiny/api-opensearch";
2
+ import { CmsModelOpenSearchIndex } from "./abstractions.js";
3
+ class DefaultCmsModelOpenSearchIndexImpl {
4
+ async execute() {
5
+ return {
6
+ settings: getBaseConfiguration(),
7
+ shared: isSharedOpenSearchIndex()
8
+ };
9
+ }
10
+ }
11
+ const DefaultCmsModelOpenSearchIndex = CmsModelOpenSearchIndex.createImplementation({
12
+ implementation: DefaultCmsModelOpenSearchIndexImpl,
13
+ dependencies: []
14
+ });
15
+ export { DefaultCmsModelOpenSearchIndex };
16
+
17
+ //# sourceMappingURL=DefaultCmsModelOpenSearchIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndex.js","sources":["../../../src/features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndex.ts"],"sourcesContent":["import { getBaseConfiguration, isSharedOpenSearchIndex } from \"@webiny/api-opensearch\";\nimport { CmsModelOpenSearchIndex } from \"./abstractions.js\";\n\nclass DefaultCmsModelOpenSearchIndexImpl implements CmsModelOpenSearchIndex.Interface {\n public async execute(): Promise<CmsModelOpenSearchIndex.Result> {\n return {\n settings: getBaseConfiguration(),\n shared: isSharedOpenSearchIndex()\n };\n }\n}\n\nexport const DefaultCmsModelOpenSearchIndex = CmsModelOpenSearchIndex.createImplementation({\n implementation: DefaultCmsModelOpenSearchIndexImpl,\n dependencies: []\n});\n"],"names":["DefaultCmsModelOpenSearchIndexImpl","getBaseConfiguration","isSharedOpenSearchIndex","DefaultCmsModelOpenSearchIndex","CmsModelOpenSearchIndex"],"mappings":";;AAGA,MAAMA;IACF,MAAa,UAAmD;QAC5D,OAAO;YACH,UAAUC;YACV,QAAQC;QACZ;IACJ;AACJ;AAEO,MAAMC,iCAAiCC,wBAAwB,oBAAoB,CAAC;IACvF,gBAAgBJ;IAChB,cAAc,EAAE;AACpB"}
@@ -0,0 +1,12 @@
1
+ import { CmsModelOpenSearchIndexProvider, type ICmsModelOpenSearchIndexProviderResult } from "./CmsModelOpenSearchIndexProvider.js";
2
+ import { CmsModelOpenSearchIndex } from "./abstractions.js";
3
+ declare class CmsModelOpenSearchIndexProviderImpl implements CmsModelOpenSearchIndexProvider.Interface {
4
+ private readonly indexConfig;
5
+ private readonly cache;
6
+ constructor(indexConfig: CmsModelOpenSearchIndex.Interface);
7
+ execute(params: CmsModelOpenSearchIndex.Params): Promise<ICmsModelOpenSearchIndexProviderResult>;
8
+ }
9
+ export declare const DefaultCmsModelOpenSearchIndexProvider: typeof CmsModelOpenSearchIndexProviderImpl & {
10
+ __abstraction: import("@webiny/di").Abstraction<import("./CmsModelOpenSearchIndexProvider.js").ICmsModelOpenSearchIndexProvider>;
11
+ };
12
+ export {};
@@ -0,0 +1,35 @@
1
+ import { CmsModelOpenSearchIndexProvider } from "./CmsModelOpenSearchIndexProvider.js";
2
+ import { CmsModelOpenSearchIndex } from "./abstractions.js";
3
+ class CmsModelOpenSearchIndexProviderImpl {
4
+ constructor(indexConfig){
5
+ this.indexConfig = indexConfig;
6
+ this.cache = new Map();
7
+ }
8
+ async execute(params) {
9
+ const key = `${params.model.tenant}:${params.model.modelId}`;
10
+ const cached = this.cache.get(key);
11
+ if (cached) return cached;
12
+ const { shared, settings } = await this.indexConfig.execute(params);
13
+ const index = [
14
+ shared ? "root" : params.model.tenant,
15
+ "headless-cms",
16
+ params.model.modelId
17
+ ].join("-").toLowerCase();
18
+ const result = {
19
+ index,
20
+ settings,
21
+ shared
22
+ };
23
+ this.cache.set(key, result);
24
+ return result;
25
+ }
26
+ }
27
+ const DefaultCmsModelOpenSearchIndexProvider = CmsModelOpenSearchIndexProvider.createImplementation({
28
+ implementation: CmsModelOpenSearchIndexProviderImpl,
29
+ dependencies: [
30
+ CmsModelOpenSearchIndex
31
+ ]
32
+ });
33
+ export { DefaultCmsModelOpenSearchIndexProvider };
34
+
35
+ //# sourceMappingURL=DefaultCmsModelOpenSearchIndexProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndexProvider.js","sources":["../../../src/features/CmsModelOpenSearchIndex/DefaultCmsModelOpenSearchIndexProvider.ts"],"sourcesContent":["import {\n CmsModelOpenSearchIndexProvider,\n type ICmsModelOpenSearchIndexProviderResult\n} from \"./CmsModelOpenSearchIndexProvider.js\";\nimport { CmsModelOpenSearchIndex } from \"./abstractions.js\";\n\nclass CmsModelOpenSearchIndexProviderImpl implements CmsModelOpenSearchIndexProvider.Interface {\n private readonly cache = new Map<string, ICmsModelOpenSearchIndexProviderResult>();\n\n public constructor(private readonly indexConfig: CmsModelOpenSearchIndex.Interface) {}\n\n public async execute(\n params: CmsModelOpenSearchIndex.Params\n ): Promise<ICmsModelOpenSearchIndexProviderResult> {\n const key = `${params.model.tenant}:${params.model.modelId}`;\n const cached = this.cache.get(key);\n if (cached) {\n return cached;\n }\n\n const { shared, settings } = await this.indexConfig.execute(params);\n\n const index = [shared ? \"root\" : params.model.tenant, \"headless-cms\", params.model.modelId]\n .join(\"-\")\n .toLowerCase();\n\n const result: ICmsModelOpenSearchIndexProviderResult = { index, settings, shared };\n this.cache.set(key, result);\n return result;\n }\n}\n\nexport const DefaultCmsModelOpenSearchIndexProvider =\n CmsModelOpenSearchIndexProvider.createImplementation({\n implementation: CmsModelOpenSearchIndexProviderImpl,\n dependencies: [CmsModelOpenSearchIndex]\n });\n"],"names":["CmsModelOpenSearchIndexProviderImpl","indexConfig","Map","params","key","cached","shared","settings","index","result","DefaultCmsModelOpenSearchIndexProvider","CmsModelOpenSearchIndexProvider","CmsModelOpenSearchIndex"],"mappings":";;AAMA,MAAMA;IAGF,YAAoCC,WAA8C,CAAE;aAAhDA,WAAW,GAAXA;aAFnB,KAAK,GAAG,IAAIC;IAEwD;IAErF,MAAa,QACTC,MAAsC,EACS;QAC/C,MAAMC,MAAM,GAAGD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,EAAEA,OAAO,KAAK,CAAC,OAAO,EAAE;QAC5D,MAAME,SAAS,IAAI,CAAC,KAAK,CAAC,GAAG,CAACD;QAC9B,IAAIC,QACA,OAAOA;QAGX,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAE,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,OAAO,CAACJ;QAE5D,MAAMK,QAAQ;YAACF,SAAS,SAASH,OAAO,KAAK,CAAC,MAAM;YAAE;YAAgBA,OAAO,KAAK,CAAC,OAAO;SAAC,CACtF,IAAI,CAAC,KACL,WAAW;QAEhB,MAAMM,SAAiD;YAAED;YAAOD;YAAUD;QAAO;QACjF,IAAI,CAAC,KAAK,CAAC,GAAG,CAACF,KAAKK;QACpB,OAAOA;IACX;AACJ;AAEO,MAAMC,yCACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBX;IAChB,cAAc;QAACY;KAAwB;AAC3C"}
@@ -0,0 +1,4 @@
1
+ export declare const CmsModelOpenSearchIndexFeature: {
2
+ name: string;
3
+ register(container: import("@webiny/di").Container): void;
4
+ };
@@ -0,0 +1,13 @@
1
+ import { createFeature } from "@webiny/feature/api/index.js";
2
+ import { DefaultCmsModelOpenSearchIndex } from "./DefaultCmsModelOpenSearchIndex.js";
3
+ import { DefaultCmsModelOpenSearchIndexProvider } from "./DefaultCmsModelOpenSearchIndexProvider.js";
4
+ const CmsModelOpenSearchIndexFeature = createFeature({
5
+ name: "Cms/Model/OpenSearch/IndexFeature",
6
+ register: (container)=>{
7
+ container.register(DefaultCmsModelOpenSearchIndex);
8
+ container.register(DefaultCmsModelOpenSearchIndexProvider).inContainerScope();
9
+ }
10
+ });
11
+ export { CmsModelOpenSearchIndexFeature };
12
+
13
+ //# sourceMappingURL=feature.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features/CmsModelOpenSearchIndex/feature.js","sources":["../../../src/features/CmsModelOpenSearchIndex/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api/index.js\";\nimport { DefaultCmsModelOpenSearchIndex } from \"./DefaultCmsModelOpenSearchIndex.js\";\nimport { DefaultCmsModelOpenSearchIndexProvider } from \"./DefaultCmsModelOpenSearchIndexProvider.js\";\n\nexport const CmsModelOpenSearchIndexFeature = createFeature({\n name: \"Cms/Model/OpenSearch/IndexFeature\",\n register: container => {\n container.register(DefaultCmsModelOpenSearchIndex);\n container.register(DefaultCmsModelOpenSearchIndexProvider).inContainerScope();\n }\n});\n"],"names":["CmsModelOpenSearchIndexFeature","createFeature","container","DefaultCmsModelOpenSearchIndex","DefaultCmsModelOpenSearchIndexProvider"],"mappings":";;;AAIO,MAAMA,iCAAiCC,cAAc;IACxD,MAAM;IACN,UAAUC,CAAAA;QACNA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE,wCAAwC,gBAAgB;IAC/E;AACJ"}
@@ -2,3 +2,6 @@ export { CmsModelOpenSearchIndex } from "./abstractions.js";
2
2
  export type { ICmsModelOpenSearchIndex, ICmsModelOpenSearchIndexParams, ICmsModelOpenSearchIndexResult } from "./abstractions.js";
3
3
  export { CmsModelOpenSearchIndexProvider } from "./CmsModelOpenSearchIndexProvider.js";
4
4
  export type { ICmsModelOpenSearchIndexProvider, ICmsModelOpenSearchIndexProviderResult } from "./CmsModelOpenSearchIndexProvider.js";
5
+ export { DefaultCmsModelOpenSearchIndex } from "./DefaultCmsModelOpenSearchIndex.js";
6
+ export { DefaultCmsModelOpenSearchIndexProvider } from "./DefaultCmsModelOpenSearchIndexProvider.js";
7
+ export { CmsModelOpenSearchIndexFeature } from "./feature.js";
@@ -1,2 +1,5 @@
1
1
  export { CmsModelOpenSearchIndex } from "./abstractions.js";
2
2
  export { CmsModelOpenSearchIndexProvider } from "./CmsModelOpenSearchIndexProvider.js";
3
+ export { DefaultCmsModelOpenSearchIndex } from "./DefaultCmsModelOpenSearchIndex.js";
4
+ export { DefaultCmsModelOpenSearchIndexProvider } from "./DefaultCmsModelOpenSearchIndexProvider.js";
5
+ export { CmsModelOpenSearchIndexFeature } from "./feature.js";
@@ -5,6 +5,7 @@ const defaultFullTextSearch = {
5
5
  query.must.push({
6
6
  query_string: {
7
7
  allow_leading_wildcard: true,
8
+ lenient: true,
8
9
  fields: Object.values(fields).map(createFieldPath),
9
10
  query: `*${prepareTerm(term)}*`,
10
11
  default_operator: "and"
@@ -38,7 +39,15 @@ const applyFullTextSearch = (params)=>{
38
39
  createFieldPath: (field)=>{
39
40
  if ("function" == typeof field.path) return field.path(term);
40
41
  if (field.systemField) return field.path || field.field.storageId;
41
- return `values.${field.path || field.field.storageId}`;
42
+ const parents = field.parents.length > 0 ? field.parents.map((p)=>p.storageId) : [
43
+ "values"
44
+ ];
45
+ const path = [
46
+ ...parents,
47
+ field.path || field.field.storageId
48
+ ].join(".");
49
+ if ("searchable-json" === field.type) return `${path}.*`;
50
+ return path;
42
51
  },
43
52
  fields,
44
53
  query,
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/elasticsearch/fullTextSearch.js","sources":["../../../../src/operations/entry/elasticsearch/fullTextSearch.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport { normalizeValue } from \"@webiny/api-opensearch\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\n\n/**\n * Our default implementation works with the AND operator for the multiple words query string.\n */\nconst defaultFullTextSearch: CmsEntryOpenSearchFullTextSearch.Interface = {\n apply: params => {\n const { query, term, fields, createFieldPath, prepareTerm } = params;\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: Object.values(fields).map(createFieldPath),\n query: `*${prepareTerm(term)}*`,\n default_operator: \"and\"\n }\n });\n }\n};\n\ninterface GetFullTextSearchParams {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n}\nconst getFullTextSearch = (\n params: GetFullTextSearchParams\n): CmsEntryOpenSearchFullTextSearch.Interface => {\n const { fullTextSearches, model } = params;\n /**\n * We need to reverse the list, so we can take the last one first - possibility to override existing implementations.\n */\n const reversed = [...fullTextSearches].reverse();\n /**\n * We need to find the most specific implementation for the given model.\n * Also, we need to use the first possible implementation if the specific one is not found.\n */\n let fallback: CmsEntryOpenSearchFullTextSearch.Interface | null = null;\n for (const item of reversed) {\n const models = item.models || [];\n /**\n * We take the first available implementation for the given model.\n */\n if (models.includes(model.modelId)) {\n return item;\n } else if (!fallback && models.length === 0) {\n /**\n * Then we set the first possible implementation, which has no models defined, as the default one.\n * It is important not to set the one which has models defined as they are specifically for the targeted model.\n */\n fallback = item;\n }\n }\n\n return fallback || defaultFullTextSearch;\n};\n\ninterface Params {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n query: OpenSearchBoolQueryConfig;\n term?: string;\n fields: ModelFields;\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { fullTextSearches, query, term, fields, model } = params;\n const keys = Object.keys(fields);\n if (!term || term.length === 0 || keys.length === 0) {\n return;\n }\n\n const fullTextSearch = getFullTextSearch({\n fullTextSearches,\n model\n });\n\n fullTextSearch.apply({\n model,\n createFieldPath: field => {\n if (typeof field.path === \"function\") {\n return field.path(term);\n } else if (field.systemField) {\n return field.path || field.field.storageId;\n }\n return `values.${field.path || field.field.storageId}`;\n },\n fields,\n query,\n term,\n prepareTerm: normalizeValue\n });\n};\n"],"names":["defaultFullTextSearch","params","query","term","fields","createFieldPath","prepareTerm","Object","getFullTextSearch","fullTextSearches","model","reversed","fallback","item","models","applyFullTextSearch","keys","fullTextSearch","field","normalizeValue"],"mappings":";AASA,MAAMA,wBAAoE;IACtE,OAAOC,CAAAA;QACH,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEC,eAAe,EAAEC,WAAW,EAAE,GAAGL;QAE9DC,MAAM,IAAI,CAAC,IAAI,CAAC;YACZ,cAAc;gBACV,wBAAwB;gBACxB,QAAQK,OAAO,MAAM,CAACH,QAAQ,GAAG,CAACC;gBAClC,OAAO,CAAC,CAAC,EAAEC,YAAYH,MAAM,CAAC,CAAC;gBAC/B,kBAAkB;YACtB;QACJ;IACJ;AACJ;AAMA,MAAMK,oBAAoB,CACtBP;IAEA,MAAM,EAAEQ,gBAAgB,EAAEC,KAAK,EAAE,GAAGT;IAIpC,MAAMU,WAAW;WAAIF;KAAiB,CAAC,OAAO;IAK9C,IAAIG,WAA8D;IAClE,KAAK,MAAMC,QAAQF,SAAU;QACzB,MAAMG,SAASD,KAAK,MAAM,IAAI,EAAE;QAIhC,IAAIC,OAAO,QAAQ,CAACJ,MAAM,OAAO,GAC7B,OAAOG;QACJ,IAAI,CAACD,YAAYE,AAAkB,MAAlBA,OAAO,MAAM,EAKjCF,WAAWC;IAEnB;IAEA,OAAOD,YAAYZ;AACvB;AASO,MAAMe,sBAAsB,CAACd;IAChC,MAAM,EAAEQ,gBAAgB,EAAEP,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEM,KAAK,EAAE,GAAGT;IACzD,MAAMe,OAAOT,OAAO,IAAI,CAACH;IACzB,IAAI,CAACD,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,IAAUa,AAAgB,MAAhBA,KAAK,MAAM,EACzC;IAGJ,MAAMC,iBAAiBT,kBAAkB;QACrCC;QACAC;IACJ;IAEAO,eAAe,KAAK,CAAC;QACjBP;QACA,iBAAiBQ,CAAAA;YACb,IAAI,AAAsB,cAAtB,OAAOA,MAAM,IAAI,EACjB,OAAOA,MAAM,IAAI,CAACf;YACf,IAAIe,MAAM,WAAW,EACxB,OAAOA,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS;YAE9C,OAAO,CAAC,OAAO,EAAEA,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS,EAAE;QAC1D;QACAd;QACAF;QACAC;QACA,aAAagB;IACjB;AACJ"}
1
+ {"version":3,"file":"operations/entry/elasticsearch/fullTextSearch.js","sources":["../../../../src/operations/entry/elasticsearch/fullTextSearch.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport { normalizeValue } from \"@webiny/api-opensearch\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\n\n/**\n * Our default implementation works with the AND operator for the multiple words query string.\n */\nconst defaultFullTextSearch: CmsEntryOpenSearchFullTextSearch.Interface = {\n apply: params => {\n const { query, term, fields, createFieldPath, prepareTerm } = params;\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n /**\n * Searchable JSON fields are dynamically mapped, so their subfields can be of any type (date, number, boolean...).\n * Wildcard queries are not allowed on those types, so we need to ignore them instead of failing the whole query.\n */\n lenient: true,\n fields: Object.values(fields).map(createFieldPath),\n query: `*${prepareTerm(term)}*`,\n default_operator: \"and\"\n }\n });\n }\n};\n\ninterface GetFullTextSearchParams {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n}\nconst getFullTextSearch = (\n params: GetFullTextSearchParams\n): CmsEntryOpenSearchFullTextSearch.Interface => {\n const { fullTextSearches, model } = params;\n /**\n * We need to reverse the list, so we can take the last one first - possibility to override existing implementations.\n */\n const reversed = [...fullTextSearches].reverse();\n /**\n * We need to find the most specific implementation for the given model.\n * Also, we need to use the first possible implementation if the specific one is not found.\n */\n let fallback: CmsEntryOpenSearchFullTextSearch.Interface | null = null;\n for (const item of reversed) {\n const models = item.models || [];\n /**\n * We take the first available implementation for the given model.\n */\n if (models.includes(model.modelId)) {\n return item;\n } else if (!fallback && models.length === 0) {\n /**\n * Then we set the first possible implementation, which has no models defined, as the default one.\n * It is important not to set the one which has models defined as they are specifically for the targeted model.\n */\n fallback = item;\n }\n }\n\n return fallback || defaultFullTextSearch;\n};\n\ninterface Params {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n query: OpenSearchBoolQueryConfig;\n term?: string;\n fields: ModelFields;\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { fullTextSearches, query, term, fields, model } = params;\n const keys = Object.keys(fields);\n if (!term || term.length === 0 || keys.length === 0) {\n return;\n }\n\n const fullTextSearch = getFullTextSearch({\n fullTextSearches,\n model\n });\n\n fullTextSearch.apply({\n model,\n createFieldPath: field => {\n if (typeof field.path === \"function\") {\n return field.path(term);\n } else if (field.systemField) {\n return field.path || field.field.storageId;\n }\n /**\n * Fields can live inside object fields, so we need to prepend the storage ids of all the parents.\n * Root fields have the `values` parent only.\n */\n const parents =\n field.parents.length > 0 ? field.parents.map(p => p.storageId) : [\"values\"];\n const path = [...parents, field.path || field.field.storageId].join(\".\");\n /*\n * Searchable JSON fields are indexed as objects, so the searchable values live on the\n * nested keys. Target all of them with a wildcard.\n */\n if (field.type === \"searchable-json\") {\n return `${path}.*`;\n }\n return path;\n },\n fields,\n query,\n term,\n prepareTerm: normalizeValue\n });\n};\n"],"names":["defaultFullTextSearch","params","query","term","fields","createFieldPath","prepareTerm","Object","getFullTextSearch","fullTextSearches","model","reversed","fallback","item","models","applyFullTextSearch","keys","fullTextSearch","field","parents","p","path","normalizeValue"],"mappings":";AASA,MAAMA,wBAAoE;IACtE,OAAOC,CAAAA;QACH,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEC,eAAe,EAAEC,WAAW,EAAE,GAAGL;QAE9DC,MAAM,IAAI,CAAC,IAAI,CAAC;YACZ,cAAc;gBACV,wBAAwB;gBAKxB,SAAS;gBACT,QAAQK,OAAO,MAAM,CAACH,QAAQ,GAAG,CAACC;gBAClC,OAAO,CAAC,CAAC,EAAEC,YAAYH,MAAM,CAAC,CAAC;gBAC/B,kBAAkB;YACtB;QACJ;IACJ;AACJ;AAMA,MAAMK,oBAAoB,CACtBP;IAEA,MAAM,EAAEQ,gBAAgB,EAAEC,KAAK,EAAE,GAAGT;IAIpC,MAAMU,WAAW;WAAIF;KAAiB,CAAC,OAAO;IAK9C,IAAIG,WAA8D;IAClE,KAAK,MAAMC,QAAQF,SAAU;QACzB,MAAMG,SAASD,KAAK,MAAM,IAAI,EAAE;QAIhC,IAAIC,OAAO,QAAQ,CAACJ,MAAM,OAAO,GAC7B,OAAOG;QACJ,IAAI,CAACD,YAAYE,AAAkB,MAAlBA,OAAO,MAAM,EAKjCF,WAAWC;IAEnB;IAEA,OAAOD,YAAYZ;AACvB;AASO,MAAMe,sBAAsB,CAACd;IAChC,MAAM,EAAEQ,gBAAgB,EAAEP,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEM,KAAK,EAAE,GAAGT;IACzD,MAAMe,OAAOT,OAAO,IAAI,CAACH;IACzB,IAAI,CAACD,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,IAAUa,AAAgB,MAAhBA,KAAK,MAAM,EACzC;IAGJ,MAAMC,iBAAiBT,kBAAkB;QACrCC;QACAC;IACJ;IAEAO,eAAe,KAAK,CAAC;QACjBP;QACA,iBAAiBQ,CAAAA;YACb,IAAI,AAAsB,cAAtB,OAAOA,MAAM,IAAI,EACjB,OAAOA,MAAM,IAAI,CAACf;YACf,IAAIe,MAAM,WAAW,EACxB,OAAOA,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS;YAM9C,MAAMC,UACFD,MAAM,OAAO,CAAC,MAAM,GAAG,IAAIA,MAAM,OAAO,CAAC,GAAG,CAACE,CAAAA,IAAKA,EAAE,SAAS,IAAI;gBAAC;aAAS;YAC/E,MAAMC,OAAO;mBAAIF;gBAASD,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS;aAAC,CAAC,IAAI,CAAC;YAKpE,IAAIA,AAAe,sBAAfA,MAAM,IAAI,EACV,OAAO,GAAGG,KAAK,EAAE,CAAC;YAEtB,OAAOA;QACX;QACAjB;QACAF;QACAC;QACA,aAAamB;IACjB;AACJ"}
@@ -2,6 +2,10 @@ import type { OpenSearchBoolQueryConfig } from "@webiny/api-opensearch/types.js"
2
2
  import type { CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types/index.js";
3
3
  export declare const createBaseQuery: () => OpenSearchBoolQueryConfig;
4
4
  interface Params {
5
+ /**
6
+ * Whether the model's index is shared between tenants, from CmsModelOpenSearchIndexProvider.
7
+ */
8
+ shared: boolean;
5
9
  model: CmsModel;
6
10
  where: CmsEntryListWhere;
7
11
  }
@@ -1,6 +1,5 @@
1
1
  import error from "@webiny/error";
2
2
  import { createLatestRecordType, createPublishedRecordType } from "../recordType.js";
3
- import { isSharedOpenSearchIndex } from "@webiny/api-opensearch";
4
3
  const createBaseQuery = ()=>({
5
4
  must: [],
6
5
  must_not: [],
@@ -8,10 +7,9 @@ const createBaseQuery = ()=>({
8
7
  filter: []
9
8
  });
10
9
  const createInitialQuery = (params)=>{
11
- const { model, where } = params;
10
+ const { model, where, shared } = params;
12
11
  const query = createBaseQuery();
13
- const sharedIndex = isSharedOpenSearchIndex();
14
- if (sharedIndex) {
12
+ if (shared) {
15
13
  query.filter.push({
16
14
  term: {
17
15
  "tenant.keyword": model.tenant
@@ -1 +1 @@
1
- {"version":3,"file":"operations/entry/elasticsearch/initialQuery.js","sources":["../../../../src/operations/entry/elasticsearch/initialQuery.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createLatestRecordType, createPublishedRecordType } from \"../recordType.js\";\nimport { isSharedOpenSearchIndex as isSharedElasticsearchIndex } from \"@webiny/api-opensearch\";\n\nexport const createBaseQuery = (): OpenSearchBoolQueryConfig => {\n return {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\ninterface Params {\n model: CmsModel;\n where: CmsEntryListWhere;\n}\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n *\n *\n * We add the query.filter terms because we do not need scored search here and it is a bit faster.\n */\nexport const createInitialQuery = (params: Params): OpenSearchBoolQueryConfig => {\n const { model, where } = params;\n\n const query = createBaseQuery();\n\n /**\n * When ES index is shared between tenants, we need to filter records by tenant ID\n *\n * TODO determine if we want to search across tenants in shared index?\n */\n const sharedIndex = isSharedElasticsearchIndex();\n if (sharedIndex) {\n /**\n * Tenant for the filtering is taken from the model.\n *\n * TODO determine if we want to send it in the \"where\" parameter?\n */\n query.filter.push({\n term: {\n \"tenant.keyword\": model.tenant\n }\n });\n /**\n * Also, we must search only in selected model.\n */\n query.filter.push({\n term: {\n \"modelId.keyword\": model.modelId\n }\n });\n }\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.filter.push({\n term: {\n \"__type.keyword\": createPublishedRecordType()\n }\n });\n } else if (where.latest === true) {\n query.filter.push({\n term: {\n \"__type.keyword\": createLatestRecordType()\n }\n });\n }\n //\n /**\n * We do not allow filtering without the published or latest parameter.\n * Also, we do not want to set the default one, as there is a large possibility for user error when filtering.\n */\n else {\n throw new WebinyError(\n `Cannot call Elasticsearch query when not setting \"published\" or \"latest\".`,\n \"OPENSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n /**\n * We need to remove fields that actually do not exist on the record - it will break otherwise.\n * This will modify the original object, which is what we want.\n */\n delete where.published;\n delete where.latest;\n\n return query;\n};\n"],"names":["createBaseQuery","createInitialQuery","params","model","where","query","sharedIndex","isSharedElasticsearchIndex","createPublishedRecordType","createLatestRecordType","WebinyError"],"mappings":";;;AAMO,MAAMA,kBAAkB,IACpB;QACH,MAAM,EAAE;QACR,UAAU,EAAE;QACZ,QAAQ,EAAE;QACV,QAAQ,EAAE;IACd;AAeG,MAAMC,qBAAqB,CAACC;IAC/B,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF;IAEzB,MAAMG,QAAQL;IAOd,MAAMM,cAAcC;IACpB,IAAID,aAAa;QAMbD,MAAM,MAAM,CAAC,IAAI,CAAC;YACd,MAAM;gBACF,kBAAkBF,MAAM,MAAM;YAClC;QACJ;QAIAE,MAAM,MAAM,CAAC,IAAI,CAAC;YACd,MAAM;gBACF,mBAAmBF,MAAM,OAAO;YACpC;QACJ;IACJ;IAKA,IAAIC,AAAoB,SAApBA,MAAM,SAAS,EACfC,MAAM,MAAM,CAAC,IAAI,CAAC;QACd,MAAM;YACF,kBAAkBG;QACtB;IACJ;SACG,IAAIJ,AAAiB,SAAjBA,MAAM,MAAM,EACnBC,MAAM,MAAM,CAAC,IAAI,CAAC;QACd,MAAM;YACF,kBAAkBI;QACtB;IACJ;SAQA,MAAM,IAAIC,MACN,6EACA,gCACA;QACIN;IACJ;IAOR,OAAOA,MAAM,SAAS;IACtB,OAAOA,MAAM,MAAM;IAEnB,OAAOC;AACX"}
1
+ {"version":3,"file":"operations/entry/elasticsearch/initialQuery.js","sources":["../../../../src/operations/entry/elasticsearch/initialQuery.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createLatestRecordType, createPublishedRecordType } from \"../recordType.js\";\n\nexport const createBaseQuery = (): OpenSearchBoolQueryConfig => {\n return {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n};\n\ninterface Params {\n /**\n * Whether the model's index is shared between tenants, from CmsModelOpenSearchIndexProvider.\n */\n shared: boolean;\n model: CmsModel;\n where: CmsEntryListWhere;\n}\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n *\n *\n * We add the query.filter terms because we do not need scored search here and it is a bit faster.\n */\nexport const createInitialQuery = (params: Params): OpenSearchBoolQueryConfig => {\n const { model, where, shared } = params;\n\n const query = createBaseQuery();\n\n /**\n * When the index is shared between tenants, filter records by tenant ID. The model's index\n * provider decides, so a decorator that isolates or shares an index per model is respected.\n */\n if (shared) {\n /**\n * Tenant for the filtering is taken from the model.\n *\n * TODO determine if we want to send it in the \"where\" parameter?\n */\n query.filter.push({\n term: {\n \"tenant.keyword\": model.tenant\n }\n });\n /**\n * Also, we must search only in selected model.\n */\n query.filter.push({\n term: {\n \"modelId.keyword\": model.modelId\n }\n });\n }\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.filter.push({\n term: {\n \"__type.keyword\": createPublishedRecordType()\n }\n });\n } else if (where.latest === true) {\n query.filter.push({\n term: {\n \"__type.keyword\": createLatestRecordType()\n }\n });\n }\n //\n /**\n * We do not allow filtering without the published or latest parameter.\n * Also, we do not want to set the default one, as there is a large possibility for user error when filtering.\n */\n else {\n throw new WebinyError(\n `Cannot call Elasticsearch query when not setting \"published\" or \"latest\".`,\n \"OPENSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n /**\n * We need to remove fields that actually do not exist on the record - it will break otherwise.\n * This will modify the original object, which is what we want.\n */\n delete where.published;\n delete where.latest;\n\n return query;\n};\n"],"names":["createBaseQuery","createInitialQuery","params","model","where","shared","query","createPublishedRecordType","createLatestRecordType","WebinyError"],"mappings":";;AAKO,MAAMA,kBAAkB,IACpB;QACH,MAAM,EAAE;QACR,UAAU,EAAE;QACZ,QAAQ,EAAE;QACV,QAAQ,EAAE;IACd;AAmBG,MAAMC,qBAAqB,CAACC;IAC/B,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEC,MAAM,EAAE,GAAGH;IAEjC,MAAMI,QAAQN;IAMd,IAAIK,QAAQ;QAMRC,MAAM,MAAM,CAAC,IAAI,CAAC;YACd,MAAM;gBACF,kBAAkBH,MAAM,MAAM;YAClC;QACJ;QAIAG,MAAM,MAAM,CAAC,IAAI,CAAC;YACd,MAAM;gBACF,mBAAmBH,MAAM,OAAO;YACpC;QACJ;IACJ;IAKA,IAAIC,AAAoB,SAApBA,MAAM,SAAS,EACfE,MAAM,MAAM,CAAC,IAAI,CAAC;QACd,MAAM;YACF,kBAAkBC;QACtB;IACJ;SACG,IAAIH,AAAiB,SAAjBA,MAAM,MAAM,EACnBE,MAAM,MAAM,CAAC,IAAI,CAAC;QACd,MAAM;YACF,kBAAkBE;QACtB;IACJ;SAQA,MAAM,IAAIC,MACN,6EACA,gCACA;QACIL;IACJ;IAOR,OAAOA,MAAM,SAAS;IACtB,OAAOA,MAAM,MAAM;IAEnB,OAAOE;AACX"}
@@ -0,0 +1,48 @@
1
+ import { afterEach, describe, expect, it } from "vitest";
2
+ import { createInitialQuery } from "./initialQuery.js";
3
+ const model = {
4
+ modelId: "article",
5
+ tenant: "acme"
6
+ };
7
+ const tenantFilter = {
8
+ term: {
9
+ "tenant.keyword": "acme"
10
+ }
11
+ };
12
+ const modelFilter = {
13
+ term: {
14
+ "modelId.keyword": "article"
15
+ }
16
+ };
17
+ describe("createInitialQuery", ()=>{
18
+ const original = process.env.OPENSEARCH_SHARED_INDEXES;
19
+ afterEach(()=>{
20
+ process.env.OPENSEARCH_SHARED_INDEXES = original;
21
+ });
22
+ it("filters by tenant and model when the index is shared, even if the variable says otherwise", ()=>{
23
+ process.env.OPENSEARCH_SHARED_INDEXES = "false";
24
+ const query = createInitialQuery({
25
+ model: model,
26
+ where: {
27
+ latest: true
28
+ },
29
+ shared: true
30
+ });
31
+ expect(query.filter).toContainEqual(tenantFilter);
32
+ expect(query.filter).toContainEqual(modelFilter);
33
+ });
34
+ it("doesn't filter by tenant when the index isn't shared, even if the variable says it is", ()=>{
35
+ process.env.OPENSEARCH_SHARED_INDEXES = "true";
36
+ const query = createInitialQuery({
37
+ model: model,
38
+ where: {
39
+ latest: true
40
+ },
41
+ shared: false
42
+ });
43
+ expect(query.filter).not.toContainEqual(tenantFilter);
44
+ expect(query.filter).not.toContainEqual(modelFilter);
45
+ });
46
+ });
47
+
48
+ //# sourceMappingURL=initialQuery.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations/entry/elasticsearch/initialQuery.test.js","sources":["../../../../src/operations/entry/elasticsearch/initialQuery.test.ts"],"sourcesContent":["import { afterEach, describe, expect, it } from \"vitest\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createInitialQuery } from \"./initialQuery.js\";\n\nconst model = { modelId: \"article\", tenant: \"acme\" } as CmsModel;\n\nconst tenantFilter = { term: { \"tenant.keyword\": \"acme\" } };\nconst modelFilter = { term: { \"modelId.keyword\": \"article\" } };\n\n/*\n * Whether entries are filtered by tenant must follow the model's index (CmsModelOpenSearchIndex),\n * not the OPENSEARCH_SHARED_INDEXES variable. A decorator can isolate or share an index per model,\n * so the two can disagree.\n */\ndescribe(\"createInitialQuery\", () => {\n const original = process.env.OPENSEARCH_SHARED_INDEXES;\n\n afterEach(() => {\n process.env.OPENSEARCH_SHARED_INDEXES = original;\n });\n\n it(\"filters by tenant and model when the index is shared, even if the variable says otherwise\", () => {\n process.env.OPENSEARCH_SHARED_INDEXES = \"false\";\n\n const query = createInitialQuery({ model, where: { latest: true }, shared: true });\n\n expect(query.filter).toContainEqual(tenantFilter);\n expect(query.filter).toContainEqual(modelFilter);\n });\n\n it(\"doesn't filter by tenant when the index isn't shared, even if the variable says it is\", () => {\n process.env.OPENSEARCH_SHARED_INDEXES = \"true\";\n\n const query = createInitialQuery({ model, where: { latest: true }, shared: false });\n\n expect(query.filter).not.toContainEqual(tenantFilter);\n expect(query.filter).not.toContainEqual(modelFilter);\n });\n});\n"],"names":["model","tenantFilter","modelFilter","describe","original","process","afterEach","it","query","createInitialQuery","expect"],"mappings":";;AAIA,MAAMA,QAAQ;IAAE,SAAS;IAAW,QAAQ;AAAO;AAEnD,MAAMC,eAAe;IAAE,MAAM;QAAE,kBAAkB;IAAO;AAAE;AAC1D,MAAMC,cAAc;IAAE,MAAM;QAAE,mBAAmB;IAAU;AAAE;AAO7DC,SAAS,sBAAsB;IAC3B,MAAMC,WAAWC,QAAQ,GAAG,CAAC,yBAAyB;IAEtDC,UAAU;QACND,QAAQ,GAAG,CAAC,yBAAyB,GAAGD;IAC5C;IAEAG,GAAG,6FAA6F;QAC5FF,QAAQ,GAAG,CAAC,yBAAyB,GAAG;QAExC,MAAMG,QAAQC,mBAAmB;YAAET,OAAAA;YAAO,OAAO;gBAAE,QAAQ;YAAK;YAAG,QAAQ;QAAK;QAEhFU,OAAOF,MAAM,MAAM,EAAE,cAAc,CAACP;QACpCS,OAAOF,MAAM,MAAM,EAAE,cAAc,CAACN;IACxC;IAEAK,GAAG,yFAAyF;QACxFF,QAAQ,GAAG,CAAC,yBAAyB,GAAG;QAExC,MAAMG,QAAQC,mBAAmB;YAAET,OAAAA;YAAO,OAAO;gBAAE,QAAQ;YAAK;YAAG,QAAQ;QAAM;QAEjFU,OAAOF,MAAM,MAAM,EAAE,GAAG,CAAC,cAAc,CAACP;QACxCS,OAAOF,MAAM,MAAM,EAAE,GAAG,CAAC,cAAc,CAACN;IAC5C;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/api-headless-cms-utils-os",
3
- "version": "0.0.0-unstable.0d717d18dd",
3
+ "version": "0.0.0-unstable.7c2def32a7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -15,14 +15,15 @@
15
15
  "license": "MIT",
16
16
  "author": "Webiny Ltd.",
17
17
  "dependencies": {
18
- "@webiny/api-headless-cms": "0.0.0-unstable.0d717d18dd",
19
- "@webiny/api-opensearch": "0.0.0-unstable.0d717d18dd",
20
- "@webiny/error": "0.0.0-unstable.0d717d18dd",
21
- "@webiny/feature": "0.0.0-unstable.0d717d18dd"
18
+ "@webiny/api-headless-cms": "0.0.0-unstable.7c2def32a7",
19
+ "@webiny/api-opensearch": "0.0.0-unstable.7c2def32a7",
20
+ "@webiny/error": "0.0.0-unstable.7c2def32a7",
21
+ "@webiny/feature": "0.0.0-unstable.7c2def32a7"
22
22
  },
23
23
  "devDependencies": {
24
- "@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
25
- "typescript": "7.0.2"
24
+ "@webiny/build-tools": "0.0.0-unstable.7c2def32a7",
25
+ "typescript": "7.0.2",
26
+ "vitest": "4.1.11"
26
27
  },
27
28
  "publishConfig": {
28
29
  "access": "public"
@@ -0,0 +1,3 @@
1
+ import type { Container } from "@webiny/feature/api/index.js";
2
+ import type { CmsModelOpenSearchIndex } from "../features/CmsModelOpenSearchIndex/abstractions.js";
3
+ export declare const createTestModelIndexName: (container: Container, params: CmsModelOpenSearchIndex.Params) => Promise<string>;
@@ -0,0 +1,11 @@
1
+ import { getOpenSearchIndexPrefix } from "@webiny/api-opensearch";
2
+ import { CmsModelOpenSearchIndexProvider } from "../features/CmsModelOpenSearchIndex/index.js";
3
+ const createTestModelIndexName = async (container, params)=>{
4
+ const provider = container.resolve(CmsModelOpenSearchIndexProvider);
5
+ const result = await provider.execute(params);
6
+ const prefix = getOpenSearchIndexPrefix();
7
+ return prefix ? prefix + result.index : result.index;
8
+ };
9
+ export { createTestModelIndexName };
10
+
11
+ //# sourceMappingURL=createTestModelIndexName.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing/createTestModelIndexName.js","sources":["../../src/testing/createTestModelIndexName.ts"],"sourcesContent":["import { getOpenSearchIndexPrefix } from \"@webiny/api-opensearch\";\nimport type { Container } from \"@webiny/feature/api/index.js\";\nimport type { CmsModelOpenSearchIndex } from \"../features/CmsModelOpenSearchIndex/abstractions.js\";\nimport { CmsModelOpenSearchIndexProvider } from \"../features/CmsModelOpenSearchIndex/index.js\";\n\nexport const createTestModelIndexName = async (\n container: Container,\n params: CmsModelOpenSearchIndex.Params\n): Promise<string> => {\n const provider = container.resolve(CmsModelOpenSearchIndexProvider);\n const result = await provider.execute(params);\n const prefix = getOpenSearchIndexPrefix();\n return prefix ? prefix + result.index : result.index;\n};\n"],"names":["createTestModelIndexName","container","params","provider","CmsModelOpenSearchIndexProvider","result","prefix","getOpenSearchIndexPrefix"],"mappings":";;AAKO,MAAMA,2BAA2B,OACpCC,WACAC;IAEA,MAAMC,WAAWF,UAAU,OAAO,CAACG;IACnC,MAAMC,SAAS,MAAMF,SAAS,OAAO,CAACD;IACtC,MAAMI,SAASC;IACf,OAAOD,SAASA,SAASD,OAAO,KAAK,GAAGA,OAAO,KAAK;AACxD"}
@@ -0,0 +1 @@
1
+ export { createTestModelIndexName } from "./createTestModelIndexName.js";
@@ -0,0 +1 @@
1
+ export { createTestModelIndexName } from "./createTestModelIndexName.js";