@webiny/api-headless-cms-utils-os 0.0.0-unstable.5387e5f7c8 → 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.
- package/features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.js +3 -2
- package/features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.js.map +1 -1
- package/features/CmsEntryOpenSearchBodyBuilder/abstractions.d.ts +4 -0
- package/features/CmsEntryOpenSearchBodyBuilder/abstractions.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearch.js +10 -1
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
- package/operations/entry/elasticsearch/initialQuery.d.ts +4 -0
- package/operations/entry/elasticsearch/initialQuery.js +2 -4
- package/operations/entry/elasticsearch/initialQuery.js.map +1 -1
- package/operations/entry/elasticsearch/initialQuery.test.d.ts +1 -0
- package/operations/entry/elasticsearch/initialQuery.test.js +48 -0
- package/operations/entry/elasticsearch/initialQuery.test.js.map +1 -0
- package/package.json +8 -7
|
@@ -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":";;;;;;;;;;;;;;;;;AAsBA,MAAMA;IAGF,YACqBC,aAAwD,EACxDC,gBAA8D,EAC9DC,aAAuD,EACvDC,kBAAkE,EAClEC,aAAyD,EACzDC,aAAyD,EACzDC,cAA2D,EAC3DC,mBAAoE,EACpEC,gBAA8D,EAC9DC,YAA8C,CACjE;aAVmBT,aAAa,GAAbA;aACAC,gBAAgB,GAAhBA;aACAC,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,cAAc,GAAdA;aACAC,mBAAmB,GAAnBA;aACAC,gBAAgB,GAAhBA;aACAC,YAAY,GAAZA;IAClB;IAEI,MAAMC,MAAuD,EAAc;QAC9E,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAClB,MAAM,EAAEE,MAAM,EAAE,QAAQC,IAAI,EAAEC,KAAK,EAAE,MAAMC,WAAW,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGP,OAAO,MAAM;QAEtF,MAAMQ,cAAcC,kBAAkB;YAClCR;YACA,eAAe,IAAI,CAAC,aAAa;YACjC,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;QAEA,MAAMS,2BAA2B,IAAI,CAAC,cAAc,CAAC,MAAM,CAACC,CAAAA,IACjD,CAACA,EAAE,OAAO,IAAIA,EAAE,OAAO,KAAKV,MAAM,OAAO;QAEpD,MAAMW,0BAA0B,IAAI,CAAC,aAAa,CAAC,MAAM,CACrDD,CAAAA,IAAK,CAACA,EAAE,OAAO,IAAIA,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AkB;QACtB;QAEA,KAAK,MAAMa,YAAYN,wBACnBM,SAAS,UAAU,CAAC;YAChBM;YACAxB;YACAG;QACJ;QAGJ,OAAOqB;IACX;AACJ;AAEO,MAAMC,8DACTC,8BAAAA,oBAA6D,CAAC;IAC1D,gBAAgBtC;IAChB,cAAc;QACVuC;QACAC;QACAC;QACAC;QACA;YAACC;YAAgC;gBAAE,UAAU;YAAK;SAAE;QACpD;YAACC;YAAgC;gBAAE,UAAU;YAAK;SAAE;QACpD;YAACC;YAAiC;gBAAE,UAAU;YAAK;SAAE;QACrDC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;QACtDC;KACH;AACL"}
|
|
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":";;;;;;;;;;;;;;;;;AAsBA,MAAMA;IAGF,YACqBC,aAAwD,EACxDC,gBAA8D,EAC9DC,aAAuD,EACvDC,kBAAkE,EAClEC,aAAyD,EACzDC,aAAyD,EACzDC,cAA2D,EAC3DC,mBAAoE,EACpEC,gBAA8D,EAC9DC,YAA8C,CACjE;aAVmBT,aAAa,GAAbA;aACAC,gBAAgB,GAAhBA;aACAC,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aACAC,aAAa,GAAbA;aACAC,aAAa,GAAbA;aACAC,cAAc,GAAdA;aACAC,mBAAmB,GAAnBA;aACAC,gBAAgB,GAAhBA;aACAC,YAAY,GAAZA;IAClB;IAEI,MAAMC,MAAuD,EAAc;QAC9E,MAAM,EAAEC,KAAK,EAA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,UAAU,CAAC;YAChBC;YACApB;QACJ;QAGJ,MAAMsB,YAA6B;YAC/B,MAAMN,MAAM,IAAI,CAAC,MAAM,GAAG,IAAIA,MAAM,IAAI,GAAGO;YAC3C,UAAUP,MAAM,QAAQ,CAAC,MAAM,GAAG,IAAIA,MAAM,QAAQ,GAAGO;YACvD,QAAQP,MAAM,MAAM,CAAC,MAAM,GAAG,IAAIA,MAAM,MAAM,GAAGO;YACjD,QAAQP,MAAM,MAAM,CAAC,MAAM,GAAG,IAAIA,MAAM,MAAM,GAAGO;QACrD;QAEAC,gCAAgC;YAC5B,OAAOF;QACX;QAEA,MAAMG,OAAmB;YACrB,OAAO;gBACH,MAAMH;YACV;YACAF;YACA,MAAOb,AAAAA,CAAAA,SAAS,KAAK;YACrB,cAAcD;YACd,kBAAkB;QACtB;QAEA,KAAK,MAAMa,YAAYN,wBACnBM,SAAS,UAAU,CAAC;YAChBM;YACAzB;YACAI;QACJ;QAGJ,OAAOqB;IACX;AACJ;AAEO,MAAMC,8DACTC,8BAAAA,oBAA6D,CAAC;IAC1D,gBAAgBvC;IAChB,cAAc;QACVwC;QACAC;QACAC;QACAC;QACA;YAACC;YAAgC;gBAAE,UAAU;YAAK;SAAE;QACpD;YAACC;YAAgC;gBAAE,UAAU;YAAK;SAAE;QACpD;YAACC;YAAiC;gBAAE,UAAU;YAAK;SAAE;QACrDC;QACA;YAACC;YAAkC;gBAAE,UAAU;YAAK;SAAE;QACtDC;KACH;AACL"}
|
|
@@ -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":";
|
|
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"}
|
|
@@ -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
|
-
|
|
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
|
|
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,EA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ACFD,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
|
-
|
|
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\";\
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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.
|
|
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.
|
|
19
|
-
"@webiny/api-opensearch": "0.0.0-unstable.
|
|
20
|
-
"@webiny/error": "0.0.0-unstable.
|
|
21
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
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.
|
|
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"
|