@webiny/api-headless-cms-utils-os 0.0.0-unstable.7c2def32a7 → 0.0.0-unstable.9609e4e0c9
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.d.ts +3 -1
- package/features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.js +12 -3
- package/features/CmsEntryOpenSearchBodyBuilder/CmsEntryOpenSearchBodyBuilder.js.map +1 -1
- package/features/CmsEntryOpenSearchExecFiltering/CmsEntryOpenSearchExecFiltering.js +2 -3
- package/features/CmsEntryOpenSearchExecFiltering/CmsEntryOpenSearchExecFiltering.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js +4 -4
- package/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.js +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.js +1 -1
- package/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.js.map +1 -1
- package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js +1 -1
- package/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js.map +1 -1
- package/helpers/fieldIdentifier.js +2 -2
- package/helpers/fieldIdentifier.js.map +1 -1
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js +2 -2
- package/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js.map +1 -1
- package/operations/entry/elasticsearch/fields/system.d.ts +7 -0
- package/operations/entry/elasticsearch/fields/system.js +58 -0
- package/operations/entry/elasticsearch/fields/system.js.map +1 -0
- package/operations/entry/elasticsearch/fields.d.ts +4 -2
- package/operations/entry/elasticsearch/fields.js +6 -4
- package/operations/entry/elasticsearch/fields.js.map +1 -1
- package/operations/entry/elasticsearch/fullTextSearch.js +2 -2
- package/operations/entry/elasticsearch/fullTextSearch.js.map +1 -1
- package/operations/entry/elasticsearch/keyword.js +2 -2
- package/operations/entry/elasticsearch/keyword.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SearchBody } from "@webiny/api-opensearch/types.js";
|
|
2
2
|
import { OpenSearchFieldFactory } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
3
3
|
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
4
|
+
import { CmsEntrySystemField } from "@webiny/api-headless-cms/features/contentEntry/EntrySystemField/index.js";
|
|
4
5
|
import { CmsEntryOpenSearchFieldIndexRegistry } from "../../features/CmsEntryOpenSearchFieldIndex/index.js";
|
|
5
6
|
import { CmsEntryOpenSearchBodyModifier } from "../../features/CmsEntryOpenSearchBodyModifier/index.js";
|
|
6
7
|
import { CmsEntryOpenSearchSortModifier } from "../../features/CmsEntryOpenSearchSortModifier/index.js";
|
|
@@ -21,7 +22,8 @@ declare class CmsEntryOpenSearchBodyBuilderImpl implements CmsEntryOpenSearchBod
|
|
|
21
22
|
private readonly valueSearchRegistry;
|
|
22
23
|
private readonly fullTextSearches;
|
|
23
24
|
private readonly fieldFactory;
|
|
24
|
-
|
|
25
|
+
private readonly entrySystemFields;
|
|
26
|
+
constructor(execFiltering: CmsEntryOpenSearchExecFiltering.Interface, fieldPathFactory: CmsEntryOpenSearchFieldPathFactory.Interface, fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface, fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface, bodyModifiers: CmsEntryOpenSearchBodyModifier.Interface[], sortModifiers: CmsEntryOpenSearchSortModifier.Interface[], queryModifiers: CmsEntryOpenSearchQueryModifier.Interface[], valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface, fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[], fieldFactory: OpenSearchFieldFactory.Interface, entrySystemFields: CmsEntrySystemField.Interface[]);
|
|
25
27
|
build(params: CmsEntryOpenSearchBodyBuilderAbstraction.Params): SearchBody;
|
|
26
28
|
}
|
|
27
29
|
export declare const CmsEntryOpenSearchBodyBuilder: typeof CmsEntryOpenSearchBodyBuilderImpl & {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OpenSearchFieldFactory } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
2
2
|
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
3
|
+
import { CmsEntrySystemField } from "@webiny/api-headless-cms/features/contentEntry/EntrySystemField/index.js";
|
|
3
4
|
import { CmsEntryOpenSearchFieldIndexRegistry } from "../CmsEntryOpenSearchFieldIndex/index.js";
|
|
4
5
|
import { CmsEntryOpenSearchBodyModifier } from "../CmsEntryOpenSearchBodyModifier/index.js";
|
|
5
6
|
import { CmsEntryOpenSearchSortModifier } from "../CmsEntryOpenSearchSortModifier/index.js";
|
|
@@ -16,7 +17,7 @@ import { assignMinimumShouldMatchToQuery } from "../../operations/entry/elastics
|
|
|
16
17
|
import { createElasticsearchSort } from "./sort.js";
|
|
17
18
|
import { CmsEntryOpenSearchBodyBuilder } from "./abstractions.js";
|
|
18
19
|
class CmsEntryOpenSearchBodyBuilderImpl {
|
|
19
|
-
constructor(execFiltering, fieldPathFactory, fieldRegistry, fieldIndexRegistry, bodyModifiers, sortModifiers, queryModifiers, valueSearchRegistry, fullTextSearches, fieldFactory){
|
|
20
|
+
constructor(execFiltering, fieldPathFactory, fieldRegistry, fieldIndexRegistry, bodyModifiers, sortModifiers, queryModifiers, valueSearchRegistry, fullTextSearches, fieldFactory, entrySystemFields){
|
|
20
21
|
this.execFiltering = execFiltering;
|
|
21
22
|
this.fieldPathFactory = fieldPathFactory;
|
|
22
23
|
this.fieldRegistry = fieldRegistry;
|
|
@@ -27,6 +28,7 @@ class CmsEntryOpenSearchBodyBuilderImpl {
|
|
|
27
28
|
this.valueSearchRegistry = valueSearchRegistry;
|
|
28
29
|
this.fullTextSearches = fullTextSearches;
|
|
29
30
|
this.fieldFactory = fieldFactory;
|
|
31
|
+
this.entrySystemFields = entrySystemFields;
|
|
30
32
|
}
|
|
31
33
|
build(params) {
|
|
32
34
|
const { model, shared } = params;
|
|
@@ -34,7 +36,8 @@ class CmsEntryOpenSearchBodyBuilderImpl {
|
|
|
34
36
|
const modelFields = createModelFields({
|
|
35
37
|
model,
|
|
36
38
|
fieldRegistry: this.fieldRegistry,
|
|
37
|
-
fieldIndexRegistry: this.fieldIndexRegistry
|
|
39
|
+
fieldIndexRegistry: this.fieldIndexRegistry,
|
|
40
|
+
systemFields: this.entrySystemFields.map((systemField)=>systemField.field)
|
|
38
41
|
});
|
|
39
42
|
const applicableQueryModifiers = this.queryModifiers.filter((m)=>!m.modelId || m.modelId === model.modelId);
|
|
40
43
|
const applicableSortModifiers = this.sortModifiers.filter((m)=>!m.modelId || m.modelId === model.modelId);
|
|
@@ -137,7 +140,13 @@ const CmsEntryOpenSearchBodyBuilder_CmsEntryOpenSearchBodyBuilder = CmsEntryOpen
|
|
|
137
140
|
multiple: true
|
|
138
141
|
}
|
|
139
142
|
],
|
|
140
|
-
OpenSearchFieldFactory
|
|
143
|
+
OpenSearchFieldFactory,
|
|
144
|
+
[
|
|
145
|
+
CmsEntrySystemField,
|
|
146
|
+
{
|
|
147
|
+
multiple: true
|
|
148
|
+
}
|
|
149
|
+
]
|
|
141
150
|
]
|
|
142
151
|
});
|
|
143
152
|
export { CmsEntryOpenSearchBodyBuilder_CmsEntryOpenSearchBodyBuilder as CmsEntryOpenSearchBodyBuilder };
|
|
@@ -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, 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,EAAEC,MAAM,EAAE,GAAGF;QAC1B,MAAM,EAAEG,MAAM,EAAE,QAAQC,IAAI,EAAEC,KAAK,EAAE,MAAMC,WAAW,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGR,OAAO,MAAM;QAEtF,MAAMS,cAAcC,kBAAkB;YAClCT;YACA,eAAe,IAAI,CAAC,aAAa;YACjC,oBAAoB,IAAI,CAAC,kBAAkB;QAC/C;QAEA,MAAMU,2BAA2B,IAAI,CAAC,cAAc,CAAC,MAAM,CAACC,CAAAA,IACjD,CAACA,EAAE,OAAO,IAAIA,EAAE,OAAO,KAAKX,MAAM,OAAO;QAEpD,MAAMY,0BAA0B,IAAI,CAAC,aAAa,CAAC,MAAM,CACrDD,CAAAA,IAAK,CAACA,EAAE,OAAO,IAAIA,EAAE,OAAO,KAAKX,MAAM,OAAO;QAElD,M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,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"}
|
|
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 { CmsEntrySystemField } from \"@webiny/api-headless-cms/features/contentEntry/EntrySystemField/index.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 private readonly entrySystemFields: CmsEntrySystemField.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 systemFields: this.entrySystemFields.map(systemField => systemField.field)\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 [CmsEntrySystemField, { multiple: true }]\n ]\n });\n"],"names":["CmsEntryOpenSearchBodyBuilderImpl","execFiltering","fieldPathFactory","fieldRegistry","fieldIndexRegistry","bodyModifiers","sortModifiers","queryModifiers","valueSearchRegistry","fullTextSearches","fieldFactory","entrySystemFields","params","model","shared","fields","term","where","initialSort","after","limit","modelFields","createModelFields","systemField","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","CmsEntrySystemField"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,MAAMA;IAGF,YACqBC,aAAwD,EACxDC,gBAA8D,EAC9DC,aAAuD,EACvDC,kBAAkE,EAClEC,aAAyD,EACzDC,aAAyD,EACzDC,cAA2D,EAC3DC,mBAAoE,EACpEC,gBAA8D,EAC9DC,YAA8C,EAC9CC,iBAAkD,CACrE;aAXmBV,aAAa,GAAbA;aACAC,gBAAgB,GAAhBA;aACAC,aAAa,GAAbA;aACAC,kBAAkB,GAAlBA;aACA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KAC5C;AACL"}
|
|
@@ -34,7 +34,7 @@ class CmsEntryOpenSearchExecFilteringImpl {
|
|
|
34
34
|
for(const key in where){
|
|
35
35
|
const value = where[key];
|
|
36
36
|
if (void 0 === value) continue;
|
|
37
|
-
if ("AND" === key) {
|
|
37
|
+
else if ("AND" === key) {
|
|
38
38
|
const childWhereList = getWhereValues(value, "AND");
|
|
39
39
|
const childQuery = createBaseQuery();
|
|
40
40
|
for (const childWhere of childWhereList)execFiltering({
|
|
@@ -48,8 +48,7 @@ class CmsEntryOpenSearchExecFilteringImpl {
|
|
|
48
48
|
bool: childQueryBool
|
|
49
49
|
});
|
|
50
50
|
continue;
|
|
51
|
-
}
|
|
52
|
-
if ("OR" === key) {
|
|
51
|
+
} else if ("OR" === key) {
|
|
53
52
|
const childWhereList = getWhereValues(value, "OR");
|
|
54
53
|
const should = [];
|
|
55
54
|
for (const childWhere of childWhereList){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CmsEntryOpenSearchExecFiltering/CmsEntryOpenSearchExecFiltering.js","sources":["../../../src/features/CmsEntryOpenSearchExecFiltering/CmsEntryOpenSearchExecFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { QueryDslQueryContainer as Query } from \"@webiny/api-opensearch/types.js\";\nimport { parseWhereKey } from \"@webiny/api-opensearch\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery.js\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js\";\nimport { CmsEntryOpenSearchFilterRegistry } from \"~/features/CmsEntryOpenSearchFilter/index.js\";\nimport { CmsEntryOpenSearchOperatorList } from \"~/features/CmsEntryOpenSearchOperatorList/index.js\";\nimport { CmsEntryOpenSearchValueTransformer } from \"~/features/CmsEntryOpenSearchValueTransformer/index.js\";\nimport { CmsEntryOpenSearchFieldPathFactory } from \"~/features/CmsEntryOpenSearchFieldPathFactory/index.js\";\nimport { CmsEntryOpenSearchExecFiltering as CmsEntryOpenSearchExecFilteringAbstraction } from \"./abstractions.js\";\nimport { getWhereValues } from \"./values.js\";\nimport { getPopulated } from \"./populated.js\";\nimport { createApplyFiltering } from \"./applyFiltering.js\";\n\ninterface InternalExecParams {\n where: CmsEntryListWhere;\n query: CmsEntryOpenSearchExecFilteringAbstraction.Params[\"query\"];\n isValues?: boolean;\n}\n\nclass CmsEntryOpenSearchExecFilteringImpl\n implements CmsEntryOpenSearchExecFilteringAbstraction.Interface\n{\n public constructor(\n private readonly operatorList: CmsEntryOpenSearchOperatorList.Interface,\n private readonly valueTransformer: CmsEntryOpenSearchValueTransformer.Interface,\n private readonly fieldPathFactory: CmsEntryOpenSearchFieldPathFactory.Interface,\n private readonly filterRegistry: CmsEntryOpenSearchFilterRegistry.Interface\n ) {}\n\n public execute(params: CmsEntryOpenSearchExecFilteringAbstraction.Params): void {\n const { model, fields, where, query } = params;\n\n const operators = this.operatorList.getAll();\n\n const applyFiltering = createApplyFiltering({\n operators,\n valueTransformer: this.valueTransformer,\n fieldPathFactory: this.fieldPathFactory\n });\n\n const getFilter = (type: string) => {\n return this.filterRegistry.get(type);\n };\n\n const execFiltering = (params: InternalExecParams) => {\n const { where: initialWhere, query, isValues = false } = params;\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where = structuredClone(initialWhere);\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\n if (value === undefined) {\n continue;\n } else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n const childQuery = createBaseQuery();\n for (const childWhere of childWhereList) {\n execFiltering({ query: childQuery, where: childWhere, isValues });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({ bool: childQueryBool });\n continue;\n } else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({ query: childQuery, where: childWhere, isValues });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({ bool: childQueryBool });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n assignMinimumShouldMatchToQuery({ query });\n continue;\n } else if (key === \"values\") {\n execFiltering({\n query,\n where: where[key] as CmsEntryListWhere,\n isValues: true\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n let fieldId: string = isValues ? `values.${whereFieldId}` : whereFieldId;\n\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field \"${fieldId}\".`,\n \"EXEC_FILTERING_ERROR\"\n );\n }\n const filter = getFilter(field.type);\n\n filter.exec({\n applyFiltering,\n getFilter,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n execFiltering({ where, query });\n }\n}\n\nexport const CmsEntryOpenSearchExecFiltering =\n CmsEntryOpenSearchExecFilteringAbstraction.createImplementation({\n implementation: CmsEntryOpenSearchExecFilteringImpl,\n dependencies: [\n CmsEntryOpenSearchOperatorList,\n CmsEntryOpenSearchValueTransformer,\n CmsEntryOpenSearchFieldPathFactory,\n CmsEntryOpenSearchFilterRegistry\n ]\n });\n"],"names":["CmsEntryOpenSearchExecFilteringImpl","operatorList","valueTransformer","fieldPathFactory","filterRegistry","params","model","fields","where","query","operators","applyFiltering","createApplyFiltering","getFilter","type","execFiltering","initialWhere","isValues","keys","Object","structuredClone","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","should","assignMinimumShouldMatchToQuery","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","f","WebinyError","field","filter","CmsEntryOpenSearchExecFiltering","CmsEntryOpenSearchExecFilteringAbstraction","CmsEntryOpenSearchOperatorList","CmsEntryOpenSearchValueTransformer","CmsEntryOpenSearchFieldPathFactory","CmsEntryOpenSearchFilterRegistry"],"mappings":";;;;;;;;;;;;AAqBA,MAAMA;IAGF,YACqBC,YAAsD,EACtDC,gBAA8D,EAC9DC,gBAA8D,EAC9DC,cAA0D,CAC7E;aAJmBH,YAAY,GAAZA;aACAC,gBAAgB,GAAhBA;aACAC,gBAAgB,GAAhBA;aACAC,cAAc,GAAdA;IAClB;IAEI,QAAQC,MAAyD,EAAQ;QAC5E,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGJ;QAExC,MAAMK,YAAY,IAAI,CAAC,YAAY,CAAC,MAAM;QAE1C,MAAMC,iBAAiBC,qBAAqB;YACxCF;YACA,kBAAkB,IAAI,CAAC,gBAAgB;YACvC,kBAAkB,IAAI,CAAC,gBAAgB;QAC3C;QAEA,MAAMG,YAAY,CAACC,OACR,IAAI,CAAC,cAAc,CAAC,GAAG,CAACA;QAGnC,MAAMC,gBAAgB,CAACV;YACnB,MAAM,EAAE,OAAOW,YAAY,EAAEP,KAAK,EAAEQ,WAAW,KAAK,EAAE,GAAGZ;YACzD,MAAMa,OAAOC,OAAO,IAAI,CAACH;YACzB,IAAIE,AAAgB,MAAhBA,KAAK,MAAM,EACX;YAEJ,MAAMV,QAAQY,gBAAgBJ;YAE9B,IAAK,MAAMK,OAAOb,MAAO;gBACrB,MAAMc,QAAQd,KAAK,CAACa,IAA0B;gBAC9C,IAAIC,AAAUC,WAAVD,OACA;
|
|
1
|
+
{"version":3,"file":"features/CmsEntryOpenSearchExecFiltering/CmsEntryOpenSearchExecFiltering.js","sources":["../../../src/features/CmsEntryOpenSearchExecFiltering/CmsEntryOpenSearchExecFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { QueryDslQueryContainer as Query } from \"@webiny/api-opensearch/types.js\";\nimport { parseWhereKey } from \"@webiny/api-opensearch\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery.js\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js\";\nimport { CmsEntryOpenSearchFilterRegistry } from \"~/features/CmsEntryOpenSearchFilter/index.js\";\nimport { CmsEntryOpenSearchOperatorList } from \"~/features/CmsEntryOpenSearchOperatorList/index.js\";\nimport { CmsEntryOpenSearchValueTransformer } from \"~/features/CmsEntryOpenSearchValueTransformer/index.js\";\nimport { CmsEntryOpenSearchFieldPathFactory } from \"~/features/CmsEntryOpenSearchFieldPathFactory/index.js\";\nimport { CmsEntryOpenSearchExecFiltering as CmsEntryOpenSearchExecFilteringAbstraction } from \"./abstractions.js\";\nimport { getWhereValues } from \"./values.js\";\nimport { getPopulated } from \"./populated.js\";\nimport { createApplyFiltering } from \"./applyFiltering.js\";\n\ninterface InternalExecParams {\n where: CmsEntryListWhere;\n query: CmsEntryOpenSearchExecFilteringAbstraction.Params[\"query\"];\n isValues?: boolean;\n}\n\nclass CmsEntryOpenSearchExecFilteringImpl\n implements CmsEntryOpenSearchExecFilteringAbstraction.Interface\n{\n public constructor(\n private readonly operatorList: CmsEntryOpenSearchOperatorList.Interface,\n private readonly valueTransformer: CmsEntryOpenSearchValueTransformer.Interface,\n private readonly fieldPathFactory: CmsEntryOpenSearchFieldPathFactory.Interface,\n private readonly filterRegistry: CmsEntryOpenSearchFilterRegistry.Interface\n ) {}\n\n public execute(params: CmsEntryOpenSearchExecFilteringAbstraction.Params): void {\n const { model, fields, where, query } = params;\n\n const operators = this.operatorList.getAll();\n\n const applyFiltering = createApplyFiltering({\n operators,\n valueTransformer: this.valueTransformer,\n fieldPathFactory: this.fieldPathFactory\n });\n\n const getFilter = (type: string) => {\n return this.filterRegistry.get(type);\n };\n\n const execFiltering = (params: InternalExecParams) => {\n const { where: initialWhere, query, isValues = false } = params;\n const keys = Object.keys(initialWhere);\n if (keys.length === 0) {\n return;\n }\n const where = structuredClone(initialWhere);\n\n for (const key in where) {\n const value = where[key as keyof typeof where];\n if (value === undefined) {\n continue;\n } else if (key === \"AND\") {\n const childWhereList = getWhereValues(value, \"AND\");\n const childQuery = createBaseQuery();\n for (const childWhere of childWhereList) {\n execFiltering({ query: childQuery, where: childWhere, isValues });\n }\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n query.filter.push({ bool: childQueryBool });\n continue;\n } else if (key === \"OR\") {\n const childWhereList = getWhereValues(value, \"OR\");\n const should: Query[] = [];\n for (const childWhere of childWhereList) {\n const childQuery = createBaseQuery();\n execFiltering({ query: childQuery, where: childWhere, isValues });\n const childQueryBool = getPopulated(childQuery);\n if (Object.keys(childQueryBool).length === 0) {\n continue;\n }\n should.push({ bool: childQueryBool });\n }\n if (should.length === 0) {\n continue;\n }\n query.should.push(...should);\n assignMinimumShouldMatchToQuery({ query });\n continue;\n } else if (key === \"values\") {\n execFiltering({\n query,\n where: where[key] as CmsEntryListWhere,\n isValues: true\n });\n continue;\n }\n const { field: whereFieldId, operator } = parseWhereKey(key);\n let fieldId: string = isValues ? `values.${whereFieldId}` : whereFieldId;\n\n const cmsModelField = model.fields.find(f => f.fieldId === fieldId);\n if (!cmsModelField && !fields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const field = fields[fieldId];\n if (!field) {\n throw new WebinyError(\n `There is no field \"${fieldId}\".`,\n \"EXEC_FILTERING_ERROR\"\n );\n }\n const filter = getFilter(field.type);\n\n filter.exec({\n applyFiltering,\n getFilter,\n key,\n value,\n operator,\n field,\n fields,\n query\n });\n }\n };\n\n execFiltering({ where, query });\n }\n}\n\nexport const CmsEntryOpenSearchExecFiltering =\n CmsEntryOpenSearchExecFilteringAbstraction.createImplementation({\n implementation: CmsEntryOpenSearchExecFilteringImpl,\n dependencies: [\n CmsEntryOpenSearchOperatorList,\n CmsEntryOpenSearchValueTransformer,\n CmsEntryOpenSearchFieldPathFactory,\n CmsEntryOpenSearchFilterRegistry\n ]\n });\n"],"names":["CmsEntryOpenSearchExecFilteringImpl","operatorList","valueTransformer","fieldPathFactory","filterRegistry","params","model","fields","where","query","operators","applyFiltering","createApplyFiltering","getFilter","type","execFiltering","initialWhere","isValues","keys","Object","structuredClone","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","should","assignMinimumShouldMatchToQuery","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","f","WebinyError","field","filter","CmsEntryOpenSearchExecFiltering","CmsEntryOpenSearchExecFilteringAbstraction","CmsEntryOpenSearchOperatorList","CmsEntryOpenSearchValueTransformer","CmsEntryOpenSearchFieldPathFactory","CmsEntryOpenSearchFilterRegistry"],"mappings":";;;;;;;;;;;;AAqBA,MAAMA;IAGF,YACqBC,YAAsD,EACtDC,gBAA8D,EAC9DC,gBAA8D,EAC9DC,cAA0D,CAC7E;aAJmBH,YAAY,GAAZA;aACAC,gBAAgB,GAAhBA;aACAC,gBAAgB,GAAhBA;aACAC,cAAc,GAAdA;IAClB;IAEI,QAAQC,MAAyD,EAAQ;QAC5E,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGJ;QAExC,MAAMK,YAAY,IAAI,CAAC,YAAY,CAAC,MAAM;QAE1C,MAAMC,iBAAiBC,qBAAqB;YACxCF;YACA,kBAAkB,IAAI,CAAC,gBAAgB;YACvC,kBAAkB,IAAI,CAAC,gBAAgB;QAC3C;QAEA,MAAMG,YAAY,CAACC,OACR,IAAI,CAAC,cAAc,CAAC,GAAG,CAACA;QAGnC,MAAMC,gBAAgB,CAACV;YACnB,MAAM,EAAE,OAAOW,YAAY,EAAEP,KAAK,EAA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BACJ;gBACA,MAAM,EAAE,OAAOY,YAAY,EAAEC,QAAQ,EAAE,GAAGC,cAAcd;gBACxD,IAAIe,UAAkBnB,WAAW,CAAC,OAAO,EAAEgB,cAAc,GAAGA;gBAE5D,MAAMI,gBAAgB/B,MAAM,MAAM,CAAC,IAAI,CAACgC,CAAAA,IAAKA,EAAE,OAAO,KAAKF;gBAC3D,IAAI,AAACC,iBAAkB9B,MAAM,CAAC6B,QAAQ,EAE/B;oBAAA,IAAIC,eACPD,UAAUC,cAAc,OAAO;gBACnC,OAHI,MAAM,IAAIE,MAAY,CAAC,6BAA6B,EAAEH,QAAQ,EAAE,CAAC;gBAKrE,MAAMI,QAAQjC,MAAM,CAAC6B,QAAQ;gBAC7B,IAAI,CAACI,OACD,MAAM,IAAID,MACN,CAAC,mBAAmB,EAAEH,QAAQ,EAAE,CAAC,EACjC;gBAGR,MAAMK,SAAS5B,UAAU2B,MAAM,IAAI;gBAEnCC,OAAO,IAAI,CAAC;oBACR9B;oBACAE;oBACAQ;oBACAC;oBACAY;oBACAM;oBACAjC;oBACAE;gBACJ;YACJ;QACJ;QAEAM,cAAc;YAAEP;YAAOC;QAAM;IACjC;AACJ;AAEO,MAAMiC,kEACTC,gCAAAA,oBAA+D,CAAC;IAC5D,gBAAgB3C;IAChB,cAAc;QACV4C;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -17,15 +17,15 @@ const convertNumberToTime = (value)=>{
|
|
|
17
17
|
};
|
|
18
18
|
const convertValueToIndex = (value, field)=>{
|
|
19
19
|
if (!value) return null;
|
|
20
|
-
if (field.settings?.type === "time") return convertTimeToNumber(value);
|
|
20
|
+
else if (field.settings?.type === "time") return convertTimeToNumber(value);
|
|
21
21
|
return value;
|
|
22
22
|
};
|
|
23
23
|
const convertValueFromIndex = (value, field)=>{
|
|
24
24
|
const type = field.settings?.type;
|
|
25
25
|
if ("time" === type) return convertNumberToTime(value);
|
|
26
|
-
if (!value) return null;
|
|
27
|
-
if ("dateTimeWithTimezone" === type) return value;
|
|
28
|
-
if ("date" === type) {
|
|
26
|
+
else if (!value) return null;
|
|
27
|
+
else if ("dateTimeWithTimezone" === type) return value;
|
|
28
|
+
else if ("date" === type) {
|
|
29
29
|
const dateValue = new Date(value);
|
|
30
30
|
return dateValue.toISOString().slice(0, 10);
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js","sources":["../../../../src/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.ts"],"sourcesContent":["import type { CmsModelDateTimeField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CmsEntryOpenSearchFieldIndex } from \"../abstractions/CmsEntryOpenSearchFieldIndex.js\";\n\nconst convertTimeToNumber = (time?: string): number | null => {\n if (!time) {\n return null;\n }\n const [hours, minutes, seconds = 0] = time.split(\":\").map(Number);\n return hours * 60 * 60 + minutes * 60 + seconds;\n};\n\nconst convertNumberToTime = (value?: number): string | null => {\n if (value === undefined || value === null) {\n return null;\n }\n\n const hours = Math.floor(value / 60 / 60);\n const minutes = Math.floor((value - hours * 60 * 60) / 60);\n const seconds = Math.floor(value - hours * 60 * 60 - minutes * 60);\n\n return [hours, minutes, seconds].map(v => String(v).padStart(2, \"0\")).join(\":\");\n};\n\nconst convertValueToIndex = (value: string, field: CmsModelDateTimeField) => {\n if (!value) {\n return null;\n } else if (field.settings?.type === \"time\") {\n return convertTimeToNumber(value);\n }\n return value;\n};\n\nconst convertValueFromIndex = (\n value: string | number,\n field: CmsModelDateTimeField\n): string | null => {\n const type = field.settings?.type;\n if (type === \"time\") {\n return convertNumberToTime(value as number);\n } else if (!value) {\n return null;\n } else if (type === \"dateTimeWithTimezone\") {\n return value as string;\n } else if (type === \"date\") {\n const dateValue = new Date(value);\n return dateValue.toISOString().slice(0, 10);\n }\n return new Date(value).toISOString();\n};\n\nclass DateTimeFieldIndexImpl implements CmsEntryOpenSearchFieldIndex.Interface {\n public readonly fieldType = \"datetime\";\n\n public unmappedType(): string {\n return \"date\";\n }\n\n public toIndex({\n field,\n value\n }: CmsEntryOpenSearchFieldIndex.ToIndex): CmsEntryOpenSearchFieldIndex.ToValue {\n if (Array.isArray(value) === true) {\n return {\n value: value.map((v: string) => {\n return convertValueToIndex(v, field as CmsModelDateTimeField);\n })\n };\n }\n return {\n value: convertValueToIndex(value, field as CmsModelDateTimeField)\n };\n }\n\n public fromIndex({ field, value }: CmsEntryOpenSearchFieldIndex.FromIndex): any {\n if (Array.isArray(value) === true) {\n return value.map((v: string) => {\n return convertValueFromIndex(v, field as CmsModelDateTimeField);\n });\n }\n return convertValueFromIndex(value, field as CmsModelDateTimeField);\n }\n}\n\nexport const DateTimeFieldIndex = CmsEntryOpenSearchFieldIndex.createImplementation({\n implementation: DateTimeFieldIndexImpl,\n dependencies: []\n});\n"],"names":["convertTimeToNumber","time","hours","minutes","seconds","Number","convertNumberToTime","value","Math","v","String","convertValueToIndex","field","convertValueFromIndex","type","dateValue","Date","DateTimeFieldIndexImpl","Array","DateTimeFieldIndex","CmsEntryOpenSearchFieldIndex"],"mappings":";AAGA,MAAMA,sBAAsB,CAACC;IACzB,IAAI,CAACA,MACD,OAAO;IAEX,MAAM,CAACC,OAAOC,SAASC,UAAU,CAAC,CAAC,GAAGH,KAAK,KAAK,CAAC,KAAK,GAAG,CAACI;IAC1D,OAAOH,AAAQ,KAARA,QAAa,KAAKC,AAAU,KAAVA,UAAeC;AAC5C;AAEA,MAAME,sBAAsB,CAACC;IACzB,IAAIA,QAAAA,OACA,OAAO;IAGX,MAAML,QAAQM,KAAK,KAAK,CAACD,QAAQ,KAAK;IACtC,MAAMJ,UAAUK,KAAK,KAAK,CAAED,AAAAA,CAAAA,QAAQL,AAAQ,KAARA,QAAa,EAAC,IAAK;IACvD,MAAME,UAAUI,KAAK,KAAK,CAACD,QAAQL,AAAQ,KAARA,QAAa,KAAKC,AAAU,KAAVA;IAErD,OAAO;QAACD;QAAOC;QAASC;KAAQ,CAAC,GAAG,CAACK,CAAAA,IAAKC,OAAOD,GAAG,QAAQ,CAAC,GAAG,MAAM,IAAI,CAAC;AAC/E;AAEA,MAAME,sBAAsB,CAACJ,OAAeK;IACxC,IAAI,CAACL,OACD,OAAO;
|
|
1
|
+
{"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.js","sources":["../../../../src/features/CmsEntryOpenSearchFieldIndex/fields/DateTimeFieldIndex.ts"],"sourcesContent":["import type { CmsModelDateTimeField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CmsEntryOpenSearchFieldIndex } from \"../abstractions/CmsEntryOpenSearchFieldIndex.js\";\n\nconst convertTimeToNumber = (time?: string): number | null => {\n if (!time) {\n return null;\n }\n const [hours, minutes, seconds = 0] = time.split(\":\").map(Number);\n return hours * 60 * 60 + minutes * 60 + seconds;\n};\n\nconst convertNumberToTime = (value?: number): string | null => {\n if (value === undefined || value === null) {\n return null;\n }\n\n const hours = Math.floor(value / 60 / 60);\n const minutes = Math.floor((value - hours * 60 * 60) / 60);\n const seconds = Math.floor(value - hours * 60 * 60 - minutes * 60);\n\n return [hours, minutes, seconds].map(v => String(v).padStart(2, \"0\")).join(\":\");\n};\n\nconst convertValueToIndex = (value: string, field: CmsModelDateTimeField) => {\n if (!value) {\n return null;\n } else if (field.settings?.type === \"time\") {\n return convertTimeToNumber(value);\n }\n return value;\n};\n\nconst convertValueFromIndex = (\n value: string | number,\n field: CmsModelDateTimeField\n): string | null => {\n const type = field.settings?.type;\n if (type === \"time\") {\n return convertNumberToTime(value as number);\n } else if (!value) {\n return null;\n } else if (type === \"dateTimeWithTimezone\") {\n return value as string;\n } else if (type === \"date\") {\n const dateValue = new Date(value);\n return dateValue.toISOString().slice(0, 10);\n }\n return new Date(value).toISOString();\n};\n\nclass DateTimeFieldIndexImpl implements CmsEntryOpenSearchFieldIndex.Interface {\n public readonly fieldType = \"datetime\";\n\n public unmappedType(): string {\n return \"date\";\n }\n\n public toIndex({\n field,\n value\n }: CmsEntryOpenSearchFieldIndex.ToIndex): CmsEntryOpenSearchFieldIndex.ToValue {\n if (Array.isArray(value) === true) {\n return {\n value: value.map((v: string) => {\n return convertValueToIndex(v, field as CmsModelDateTimeField);\n })\n };\n }\n return {\n value: convertValueToIndex(value, field as CmsModelDateTimeField)\n };\n }\n\n public fromIndex({ field, value }: CmsEntryOpenSearchFieldIndex.FromIndex): any {\n if (Array.isArray(value) === true) {\n return value.map((v: string) => {\n return convertValueFromIndex(v, field as CmsModelDateTimeField);\n });\n }\n return convertValueFromIndex(value, field as CmsModelDateTimeField);\n }\n}\n\nexport const DateTimeFieldIndex = CmsEntryOpenSearchFieldIndex.createImplementation({\n implementation: DateTimeFieldIndexImpl,\n dependencies: []\n});\n"],"names":["convertTimeToNumber","time","hours","minutes","seconds","Number","convertNumberToTime","value","Math","v","String","convertValueToIndex","field","convertValueFromIndex","type","dateValue","Date","DateTimeFieldIndexImpl","Array","DateTimeFieldIndex","CmsEntryOpenSearchFieldIndex"],"mappings":";AAGA,MAAMA,sBAAsB,CAACC;IACzB,IAAI,CAACA,MACD,OAAO;IAEX,MAAM,CAACC,OAAOC,SAASC,UAAU,CAAC,CAAC,GAAGH,KAAK,KAAK,CAAC,KAAK,GAAG,CAACI;IAC1D,OAAOH,AAAQ,KAARA,QAAa,KAAKC,AAAU,KAAVA,UAAeC;AAC5C;AAEA,MAAME,sBAAsB,CAACC;IACzB,IAAIA,QAAAA,OACA,OAAO;IAGX,MAAML,QAAQM,KAAK,KAAK,CAACD,QAAQ,KAAK;IACtC,MAAMJ,UAAUK,KAAK,KAAK,CAAED,AAAAA,CAAAA,QAAQL,AAAQ,KAARA,QAAa,EAAC,IAAK;IACvD,MAAME,UAAUI,KAAK,KAAK,CAACD,QAAQL,AAAQ,KAARA,QAAa,KAAKC,AAAU,KAAVA;IAErD,OAAO;QAACD;QAAOC;QAASC;KAAQ,CAAC,GAAG,CAACK,CAAAA,IAAKC,OAAOD,GAA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ldType = this.fieldRegistry.get(field.type);
|
|
27
27
|
if (!fieldType?.isSearchable) return false;
|
|
28
|
-
if (field.settings?.disableFullTextSearch === true) return false;
|
|
28
|
+
else if (field.settings?.disableFullTextSearch === true) return false;
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.js","sources":["../../../../src/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.ts"],"sourcesContent":["import { CmsEntryOpenSearchFieldIndex } from \"../abstractions/CmsEntryOpenSearchFieldIndex.js\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { TextFieldTypes } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\n\nclass TextCompressedFieldIndexImpl implements CmsEntryOpenSearchFieldIndex.Interface {\n public readonly fieldType = TextFieldTypes.COMPRESSED;\n\n public constructor(private readonly fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface) {}\n\n public toIndex(\n params: CmsEntryOpenSearchFieldIndex.ToIndex\n ): CmsEntryOpenSearchFieldIndex.ToValue {\n const { field, value } = params;\n const isSearchable = this.isSearchable(field);\n\n if (isSearchable) {\n return { value };\n }\n\n return {\n rawValue: value\n };\n }\n\n public fromIndex(params: CmsEntryOpenSearchFieldIndex.FromIndex): any {\n const { field, value, rawValue } = params;\n const isSearchable = this.isSearchable(field);\n\n if (isSearchable) {\n return value === undefined ? rawValue : value;\n }\n return rawValue === undefined ? value : rawValue;\n }\n\n private isSearchable(field: CmsModelField): boolean {\n const fieldType = this.fieldRegistry.get(field.type);\n if (!fieldType?.isSearchable) {\n return false;\n } else if (field.settings?.disableFullTextSearch === true) {\n return false;\n }\n return true;\n }\n}\n\nexport const TextCompressedFieldIndex = CmsEntryOpenSearchFieldIndex.createImplementation({\n implementation: TextCompressedFieldIndexImpl,\n dependencies: [CmsModelFieldToGraphQLRegistry]\n});\n"],"names":["TextCompressedFieldIndexImpl","fieldRegistry","TextFieldTypes","params","field","value","isSearchable","rawValue","undefined","fieldType","TextCompressedFieldIndex","CmsEntryOpenSearchFieldIndex","CmsModelFieldToGraphQLRegistry"],"mappings":";;;AAKA,MAAMA;IAGF,YAAoCC,aAAuD,CAAE;aAAzDA,aAAa,GAAbA;aAFpB,SAAS,GAAGC,eAAe,UAAU;IAEyC;IAEvF,QACHC,MAA4C,EACR;QACpC,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF;QACzB,MAAMG,eAAe,IAAI,CAAC,YAAY,CAACF;QAEvC,IAAIE,cACA,OAAO;YAAED;QAAM;QAGnB,OAAO;YACH,UAAUA;QACd;IACJ;IAEO,UAAUF,MAA8C,EAAO;QAClE,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEE,QAAQ,EAAE,GAAGJ;QACnC,MAAMG,eAAe,IAAI,CAAC,YAAY,CAACF;QAEvC,IAAIE,cACA,OAAOD,AAAUG,WAAVH,QAAsBE,WAAWF;QAE5C,OAAOE,AAAaC,WAAbD,WAAyBF,QAAQE;IAC5C;IAEQ,aAAaH,KAAoB,EAAW;QAChD,MAAMK,YAAY,IAAI,CAAC,aAAa,CAAC,GAAG,CAACL,MAAM,IAAI;QACnD,IAAI,CAACK,WAAW,cACZ,OAAO;
|
|
1
|
+
{"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.js","sources":["../../../../src/features/CmsEntryOpenSearchFieldIndex/fields/TextCompressedFieldIndex.ts"],"sourcesContent":["import { CmsEntryOpenSearchFieldIndex } from \"../abstractions/CmsEntryOpenSearchFieldIndex.js\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { TextFieldTypes } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\n\nclass TextCompressedFieldIndexImpl implements CmsEntryOpenSearchFieldIndex.Interface {\n public readonly fieldType = TextFieldTypes.COMPRESSED;\n\n public constructor(private readonly fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface) {}\n\n public toIndex(\n params: CmsEntryOpenSearchFieldIndex.ToIndex\n ): CmsEntryOpenSearchFieldIndex.ToValue {\n const { field, value } = params;\n const isSearchable = this.isSearchable(field);\n\n if (isSearchable) {\n return { value };\n }\n\n return {\n rawValue: value\n };\n }\n\n public fromIndex(params: CmsEntryOpenSearchFieldIndex.FromIndex): any {\n const { field, value, rawValue } = params;\n const isSearchable = this.isSearchable(field);\n\n if (isSearchable) {\n return value === undefined ? rawValue : value;\n }\n return rawValue === undefined ? value : rawValue;\n }\n\n private isSearchable(field: CmsModelField): boolean {\n const fieldType = this.fieldRegistry.get(field.type);\n if (!fieldType?.isSearchable) {\n return false;\n } else if (field.settings?.disableFullTextSearch === true) {\n return false;\n }\n return true;\n }\n}\n\nexport const TextCompressedFieldIndex = CmsEntryOpenSearchFieldIndex.createImplementation({\n implementation: TextCompressedFieldIndexImpl,\n dependencies: [CmsModelFieldToGraphQLRegistry]\n});\n"],"names":["TextCompressedFieldIndexImpl","fieldRegistry","TextFieldTypes","params","field","value","isSearchable","rawValue","undefined","fieldType","TextCompressedFieldIndex","CmsEntryOpenSearchFieldIndex","CmsModelFieldToGraphQLRegistry"],"mappings":";;;AAKA,MAAMA;IAGF,YAAoCC,aAAuD,CAAE;aAAzDA,aAAa,GAAbA;aAFpB,SAAS,GAAGC,eAAe,UAAU;IAEyC;IAEvF,QACHC,MAA4C,EACR;QACpC,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF;QACzB,MAAMG,eAAe,IAAI,CAAC,YAAY,CAACF;QAEvC,IAAIE,cACA,OAAO;YAAED;QAAM;QAGnB,OAAO;YACH,UAAUA;QACd;IACJ;IAEO,UAAUF,MAA8C,EAAO;QAClE,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEE,QAAQ,EAAE,GAAGJ;QACnC,MAAMG,eAAe,IAAI,CAAC,YAAY,CAACF;QAEvC,IAAIE,cACA,OAAOD,AAAUG,WAAVH,QAAsBE,WAAWF;QAE5C,OAAOE,AAAaC,WAAbD,WAAyBF,QAAQE;IAC5C;IAEQ,aAAaH,KAAoB,EAAW;QAChD,MAAMK,YAAY,IAAI,CAAC,aAAa,CAAC,GAAG,CAACL,MAAM,IAAI;QACnD,IAAI,CAACK,WAAW,cACZ,OAAO;aACJ,IAAIL,MAAM,QAAQ,EAAE,0BAA0B,MACjD,OAAO;QAEX,OAAO;IACX;AACJ;AAEO,MAAMM,2BAA2BC,6BAA6B,oBAAoB,CAAC;IACtF,gBAAgBX;IAChB,cAAc;QAACY;KAA+B;AAClD"}
|
|
@@ -25,7 +25,7 @@ class TextEncryptedFieldIndexImpl {
|
|
|
25
25
|
isSearchable(field) {
|
|
26
26
|
const fieldType = this.fieldRegistry.get(field.type);
|
|
27
27
|
if (!fieldType?.isSearchable) return false;
|
|
28
|
-
if (field.settings?.disableFullTextSearch === true) return false;
|
|
28
|
+
else if (field.settings?.disableFullTextSearch === true) return false;
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.js","sources":["../../../../src/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.ts"],"sourcesContent":["import { CmsEntryOpenSearchFieldIndex } from \"../abstractions/CmsEntryOpenSearchFieldIndex.js\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { TextFieldTypes } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\n\nclass TextEncryptedFieldIndexImpl implements CmsEntryOpenSearchFieldIndex.Interface {\n public readonly fieldType = TextFieldTypes.ENCRYPTED;\n\n public constructor(private readonly fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface) {}\n\n public toIndex(\n params: CmsEntryOpenSearchFieldIndex.ToIndex\n ): CmsEntryOpenSearchFieldIndex.ToValue {\n const { field, value } = params;\n const isSearchable = this.isSearchable(field);\n\n if (isSearchable) {\n return { value };\n }\n\n return {\n rawValue: value\n };\n }\n\n public fromIndex(params: CmsEntryOpenSearchFieldIndex.FromIndex): any {\n const { field, value, rawValue } = params;\n const isSearchable = this.isSearchable(field);\n\n if (isSearchable) {\n return value === undefined ? rawValue : value;\n }\n return rawValue === undefined ? value : rawValue;\n }\n\n private isSearchable(field: CmsModelField): boolean {\n const fieldType = this.fieldRegistry.get(field.type);\n if (!fieldType?.isSearchable) {\n return false;\n } else if (field.settings?.disableFullTextSearch === true) {\n return false;\n }\n return true;\n }\n}\n\nexport const TextEncryptedFieldIndex = CmsEntryOpenSearchFieldIndex.createImplementation({\n implementation: TextEncryptedFieldIndexImpl,\n dependencies: [CmsModelFieldToGraphQLRegistry]\n});\n"],"names":["TextEncryptedFieldIndexImpl","fieldRegistry","TextFieldTypes","params","field","value","isSearchable","rawValue","undefined","fieldType","TextEncryptedFieldIndex","CmsEntryOpenSearchFieldIndex","CmsModelFieldToGraphQLRegistry"],"mappings":";;;AAKA,MAAMA;IAGF,YAAoCC,aAAuD,CAAE;aAAzDA,aAAa,GAAbA;aAFpB,SAAS,GAAGC,eAAe,SAAS;IAE0C;IAEvF,QACHC,MAA4C,EACR;QACpC,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF;QACzB,MAAMG,eAAe,IAAI,CAAC,YAAY,CAACF;QAEvC,IAAIE,cACA,OAAO;YAAED;QAAM;QAGnB,OAAO;YACH,UAAUA;QACd;IACJ;IAEO,UAAUF,MAA8C,EAAO;QAClE,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEE,QAAQ,EAAE,GAAGJ;QACnC,MAAMG,eAAe,IAAI,CAAC,YAAY,CAACF;QAEvC,IAAIE,cACA,OAAOD,AAAUG,WAAVH,QAAsBE,WAAWF;QAE5C,OAAOE,AAAaC,WAAbD,WAAyBF,QAAQE;IAC5C;IAEQ,aAAaH,KAAoB,EAAW;QAChD,MAAMK,YAAY,IAAI,CAAC,aAAa,CAAC,GAAG,CAACL,MAAM,IAAI;QACnD,IAAI,CAACK,WAAW,cACZ,OAAO;
|
|
1
|
+
{"version":3,"file":"features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.js","sources":["../../../../src/features/CmsEntryOpenSearchFieldIndex/fields/TextEncryptedFieldIndex.ts"],"sourcesContent":["import { CmsEntryOpenSearchFieldIndex } from \"../abstractions/CmsEntryOpenSearchFieldIndex.js\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/exports/api/cms/graphql.js\";\nimport { TextFieldTypes } from \"@webiny/api-headless-cms/features/modelBuilder/index.js\";\n\nclass TextEncryptedFieldIndexImpl implements CmsEntryOpenSearchFieldIndex.Interface {\n public readonly fieldType = TextFieldTypes.ENCRYPTED;\n\n public constructor(private readonly fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface) {}\n\n public toIndex(\n params: CmsEntryOpenSearchFieldIndex.ToIndex\n ): CmsEntryOpenSearchFieldIndex.ToValue {\n const { field, value } = params;\n const isSearchable = this.isSearchable(field);\n\n if (isSearchable) {\n return { value };\n }\n\n return {\n rawValue: value\n };\n }\n\n public fromIndex(params: CmsEntryOpenSearchFieldIndex.FromIndex): any {\n const { field, value, rawValue } = params;\n const isSearchable = this.isSearchable(field);\n\n if (isSearchable) {\n return value === undefined ? rawValue : value;\n }\n return rawValue === undefined ? value : rawValue;\n }\n\n private isSearchable(field: CmsModelField): boolean {\n const fieldType = this.fieldRegistry.get(field.type);\n if (!fieldType?.isSearchable) {\n return false;\n } else if (field.settings?.disableFullTextSearch === true) {\n return false;\n }\n return true;\n }\n}\n\nexport const TextEncryptedFieldIndex = CmsEntryOpenSearchFieldIndex.createImplementation({\n implementation: TextEncryptedFieldIndexImpl,\n dependencies: [CmsModelFieldToGraphQLRegistry]\n});\n"],"names":["TextEncryptedFieldIndexImpl","fieldRegistry","TextFieldTypes","params","field","value","isSearchable","rawValue","undefined","fieldType","TextEncryptedFieldIndex","CmsEntryOpenSearchFieldIndex","CmsModelFieldToGraphQLRegistry"],"mappings":";;;AAKA,MAAMA;IAGF,YAAoCC,aAAuD,CAAE;aAAzDA,aAAa,GAAbA;aAFpB,SAAS,GAAGC,eAAe,SAAS;IAE0C;IAEvF,QACHC,MAA4C,EACR;QACpC,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF;QACzB,MAAMG,eAAe,IAAI,CAAC,YAAY,CAACF;QAEvC,IAAIE,cACA,OAAO;YAAED;QAAM;QAGnB,OAAO;YACH,UAAUA;QACd;IACJ;IAEO,UAAUF,MAA8C,EAAO;QAClE,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAEE,QAAQ,EAAE,GAAGJ;QACnC,MAAMG,eAAe,IAAI,CAAC,YAAY,CAACF;QAEvC,IAAIE,cACA,OAAOD,AAAUG,WAAVH,QAAsBE,WAAWF;QAE5C,OAAOE,AAAaC,WAAbD,WAAyBF,QAAQE;IAC5C;IAEQ,aAAaH,KAAoB,EAAW;QAChD,MAAMK,YAAY,IAAI,CAAC,aAAa,CAAC,GAAG,CAACL,MAAM,IAAI;QACnD,IAAI,CAACK,WAAW,cACZ,OAAO;aACJ,IAAIL,MAAM,QAAQ,EAAE,0BAA0B,MACjD,OAAO;QAEX,OAAO;IACX;AACJ;AAEO,MAAMM,0BAA0BC,6BAA6B,oBAAoB,CAAC;IACrF,gBAAgBX;IAChB,cAAc;QAACY;KAA+B;AAClD"}
|
|
@@ -8,7 +8,7 @@ const getKey = (params)=>{
|
|
|
8
8
|
field,
|
|
9
9
|
value
|
|
10
10
|
});
|
|
11
|
-
if (keys.length > 1) throw new WebinyError(`Searchable JSON field "${field.fieldId}" can only have one key.`, "MULTIPLE_KEYS_IN_SEARCHABLE_JSON_FIELD", {
|
|
11
|
+
else if (keys.length > 1) throw new WebinyError(`Searchable JSON field "${field.fieldId}" can only have one key.`, "MULTIPLE_KEYS_IN_SEARCHABLE_JSON_FIELD", {
|
|
12
12
|
field,
|
|
13
13
|
value,
|
|
14
14
|
keys
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js","sources":["../../../../src/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CmsEntryOpenSearchValueSearch } from \"../abstractions/CmsEntryOpenSearchValueSearch.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { NoValueContainer } from \"~/values/NoValueContainer.js\";\n\ninterface IGetKeyParams {\n field: CmsModelField;\n value: {\n [key: string]: any;\n };\n}\n\nconst getKey = (params: IGetKeyParams): string => {\n const { field, value } = params;\n const keys = Object.keys(value);\n if (keys.length === 0) {\n throw new WebinyError(\n `Searchable JSON field \"${field.fieldId}\" cannot be empty.`,\n \"EMPTY_SEARCHABLE_JSON_FIELD\",\n {\n field,\n value\n }\n );\n } else if (keys.length > 1) {\n throw new WebinyError(\n `Searchable JSON field \"${field.fieldId}\" can only have one key.`,\n \"MULTIPLE_KEYS_IN_SEARCHABLE_JSON_FIELD\",\n {\n field,\n value,\n keys\n }\n );\n }\n return keys[0];\n};\n\nclass SearchableJsonSearchImpl implements CmsEntryOpenSearchValueSearch.Interface {\n public readonly fieldType = \"searchable-json\";\n\n public transform(params: CmsEntryOpenSearchValueSearch.Transform): any {\n const { value } = params;\n\n if (NoValueContainer.is(value)) {\n return null;\n }\n\n const key = getKey(params);\n return value[key] || null;\n }\n\n public createPath(params: CmsEntryOpenSearchValueSearch.CreatePath): string | null {\n const { field } = params;\n\n if (NoValueContainer.is(params.originalValue)) {\n return `${field.storageId}.unknown`;\n }\n\n const key = getKey({\n field,\n value: params.originalValue\n });\n\n return `${field.storageId}.${key}`;\n }\n}\n\nexport const SearchableJsonSearch = CmsEntryOpenSearchValueSearch.createImplementation({\n implementation: SearchableJsonSearchImpl,\n dependencies: []\n});\n"],"names":["getKey","params","field","value","keys","Object","WebinyError","SearchableJsonSearchImpl","NoValueContainer","key","SearchableJsonSearch","CmsEntryOpenSearchValueSearch"],"mappings":";;;AAYA,MAAMA,SAAS,CAACC;IACZ,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF;IACzB,MAAMG,OAAOC,OAAO,IAAI,CAACF;IACzB,IAAIC,AAAgB,MAAhBA,KAAK,MAAM,EACX,MAAM,IAAIE,YACN,CAAC,uBAAuB,EAAEJ,MAAM,OAAO,CAAC,kBAAkB,CAAC,EAC3D,+BACA;QACIA;QACAC;IACJ;
|
|
1
|
+
{"version":3,"file":"features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.js","sources":["../../../../src/features/CmsEntryOpenSearchValueSearch/fields/SearchableJsonSearch.ts"],"sourcesContent":["import { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { CmsEntryOpenSearchValueSearch } from \"../abstractions/CmsEntryOpenSearchValueSearch.js\";\nimport { WebinyError } from \"@webiny/error\";\nimport { NoValueContainer } from \"~/values/NoValueContainer.js\";\n\ninterface IGetKeyParams {\n field: CmsModelField;\n value: {\n [key: string]: any;\n };\n}\n\nconst getKey = (params: IGetKeyParams): string => {\n const { field, value } = params;\n const keys = Object.keys(value);\n if (keys.length === 0) {\n throw new WebinyError(\n `Searchable JSON field \"${field.fieldId}\" cannot be empty.`,\n \"EMPTY_SEARCHABLE_JSON_FIELD\",\n {\n field,\n value\n }\n );\n } else if (keys.length > 1) {\n throw new WebinyError(\n `Searchable JSON field \"${field.fieldId}\" can only have one key.`,\n \"MULTIPLE_KEYS_IN_SEARCHABLE_JSON_FIELD\",\n {\n field,\n value,\n keys\n }\n );\n }\n return keys[0];\n};\n\nclass SearchableJsonSearchImpl implements CmsEntryOpenSearchValueSearch.Interface {\n public readonly fieldType = \"searchable-json\";\n\n public transform(params: CmsEntryOpenSearchValueSearch.Transform): any {\n const { value } = params;\n\n if (NoValueContainer.is(value)) {\n return null;\n }\n\n const key = getKey(params);\n return value[key] || null;\n }\n\n public createPath(params: CmsEntryOpenSearchValueSearch.CreatePath): string | null {\n const { field } = params;\n\n if (NoValueContainer.is(params.originalValue)) {\n return `${field.storageId}.unknown`;\n }\n\n const key = getKey({\n field,\n value: params.originalValue\n });\n\n return `${field.storageId}.${key}`;\n }\n}\n\nexport const SearchableJsonSearch = CmsEntryOpenSearchValueSearch.createImplementation({\n implementation: SearchableJsonSearchImpl,\n dependencies: []\n});\n"],"names":["getKey","params","field","value","keys","Object","WebinyError","SearchableJsonSearchImpl","NoValueContainer","key","SearchableJsonSearch","CmsEntryOpenSearchValueSearch"],"mappings":";;;AAYA,MAAMA,SAAS,CAACC;IACZ,MAAM,EAAEC,KAAK,EAAEC,KAAK,EAAE,GAAGF;IACzB,MAAMG,OAAOC,OAAO,IAAI,CAACF;IACzB,IAAIC,AAAgB,MAAhBA,KAAK,MAAM,EACX,MAAM,IAAIE,YACN,CAAC,uBAAuB,EAAEJ,MAAM,OAAO,CAAC,kBAAkB,CAAC,EAC3D,+BACA;QACIA;QACAC;IACJ;SAED,IAAIC,KAAK,MAAM,GAAG,GACrB,MAAM,IAAIE,YACN,CAAC,uBAAuB,EAAEJ,MAAM,OAAO,CAAC,wBAAwB,CAAC,EACjE,0CACA;QACIA;QACAC;QACAC;IACJ;IAGR,OAAOA,IAAI,CAAC,EAAE;AAClB;AAEA,MAAMG;IAGK,UAAUN,MAA+C,EAAO;QACnE,MAAM,EAAEE,KAAK,EAAE,GAAGF;QAElB,IAAIO,iBAAiB,EAAE,CAACL,QACpB,OAAO;QAGX,MAAMM,MAAMT,OAAOC;QACnB,OAAOE,KAAK,CAACM,IAAI,IAAI;IACzB;IAEO,WAAWR,MAAgD,EAAiB;QAC/E,MAAM,EAAEC,KAAK,EAAE,GAAGD;QAElB,IAAIO,iBAAiB,EAAE,CAACP,OAAO,aAAa,GACxC,OAAO,GAAGC,MAAM,SAAS,CAAC,QAAQ,CAAC;QAGvC,MAAMO,MAAMT,OAAO;YACfE;YACA,OAAOD,OAAO,aAAa;QAC/B;QAEA,OAAO,GAAGC,MAAM,SAAS,CAAC,CAAC,EAAEO,KAAK;IACtC;;aA1BgB,SAAS,GAAG;;AA2BhC;AAEO,MAAMC,uBAAuBC,8BAA8B,oBAAoB,CAAC;IACnF,gBAAgBJ;IAChB,cAAc,EAAE;AACpB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const fieldIdentifier_hasOwnProperty = (values = {}, property)=>{
|
|
2
2
|
if (!values) return false;
|
|
3
|
-
if (values.hasOwnProperty) return values.hasOwnProperty(property);
|
|
3
|
+
else if (values.hasOwnProperty) return values.hasOwnProperty(property);
|
|
4
4
|
return void 0 !== values[property];
|
|
5
5
|
};
|
|
6
6
|
const getFieldIdentifier = (values, field)=>{
|
|
7
7
|
if (field.storageId && fieldIdentifier_hasOwnProperty(values, field.storageId)) return field.storageId;
|
|
8
|
-
if (fieldIdentifier_hasOwnProperty(values, field.fieldId)) return field.fieldId;
|
|
8
|
+
else if (fieldIdentifier_hasOwnProperty(values, field.fieldId)) return field.fieldId;
|
|
9
9
|
};
|
|
10
10
|
const getFieldIdentifiers = (values, rawValues, field)=>{
|
|
11
11
|
let valueIdentifier = getFieldIdentifier(values, field);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers/fieldIdentifier.js","sources":["../../src/helpers/fieldIdentifier.ts"],"sourcesContent":["import type { CmsEntryValues, CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst hasOwnProperty = (\n values: CmsEntryValues | null | undefined = {},\n property: string\n): boolean => {\n if (!values) {\n return false;\n } else if (values.hasOwnProperty) {\n return values.hasOwnProperty(property);\n }\n return values[property] !== undefined;\n};\n\nexport const getFieldIdentifier = (\n values: CmsEntryValues | null | undefined,\n field: CmsModelField\n): string | undefined => {\n if (field.storageId && hasOwnProperty(values, field.storageId)) {\n return field.storageId;\n } else if (hasOwnProperty(values, field.fieldId)) {\n return field.fieldId;\n }\n return undefined;\n};\n\nexport const getFieldIdentifiers = (\n values: CmsEntryValues,\n rawValues: CmsEntryValues | null | undefined,\n field: CmsModelField\n) => {\n let valueIdentifier = getFieldIdentifier(values, field);\n let rawValueIdentifier = getFieldIdentifier(rawValues, field);\n if (!valueIdentifier && !rawValueIdentifier) {\n return null;\n }\n if (!valueIdentifier) {\n valueIdentifier = rawValueIdentifier as string;\n }\n if (!rawValueIdentifier) {\n rawValueIdentifier = valueIdentifier as string;\n }\n return {\n valueIdentifier,\n rawValueIdentifier\n };\n};\n"],"names":["hasOwnProperty","values","property","undefined","getFieldIdentifier","field","getFieldIdentifiers","rawValues","valueIdentifier","rawValueIdentifier"],"mappings":"AAEA,MAAMA,iCAAiB,CACnBC,SAA4C,CAAC,CAAC,EAC9CC;IAEA,IAAI,CAACD,QACD,OAAO;
|
|
1
|
+
{"version":3,"file":"helpers/fieldIdentifier.js","sources":["../../src/helpers/fieldIdentifier.ts"],"sourcesContent":["import type { CmsEntryValues, CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\n\nconst hasOwnProperty = (\n values: CmsEntryValues | null | undefined = {},\n property: string\n): boolean => {\n if (!values) {\n return false;\n } else if (values.hasOwnProperty) {\n return values.hasOwnProperty(property);\n }\n return values[property] !== undefined;\n};\n\nexport const getFieldIdentifier = (\n values: CmsEntryValues | null | undefined,\n field: CmsModelField\n): string | undefined => {\n if (field.storageId && hasOwnProperty(values, field.storageId)) {\n return field.storageId;\n } else if (hasOwnProperty(values, field.fieldId)) {\n return field.fieldId;\n }\n return undefined;\n};\n\nexport const getFieldIdentifiers = (\n values: CmsEntryValues,\n rawValues: CmsEntryValues | null | undefined,\n field: CmsModelField\n) => {\n let valueIdentifier = getFieldIdentifier(values, field);\n let rawValueIdentifier = getFieldIdentifier(rawValues, field);\n if (!valueIdentifier && !rawValueIdentifier) {\n return null;\n }\n if (!valueIdentifier) {\n valueIdentifier = rawValueIdentifier as string;\n }\n if (!rawValueIdentifier) {\n rawValueIdentifier = valueIdentifier as string;\n }\n return {\n valueIdentifier,\n rawValueIdentifier\n };\n};\n"],"names":["hasOwnProperty","values","property","undefined","getFieldIdentifier","field","getFieldIdentifiers","rawValues","valueIdentifier","rawValueIdentifier"],"mappings":"AAEA,MAAMA,iCAAiB,CACnBC,SAA4C,CAAC,CAAC,EAC9CC;IAEA,IAAI,CAACD,QACD,OAAO;SACJ,IAAIA,OAAO,cAAc,EAC5B,OAAOA,OAAO,cAAc,CAACC;IAEjC,OAAOD,AAAqBE,WAArBF,MAAM,CAACC,SAAS;AAC3B;AAEO,MAAME,qBAAqB,CAC9BH,QACAI;IAEA,IAAIA,MAAM,SAAS,IAAIL,+BAAeC,QAAQI,MAAM,SAAS,GACzD,OAAOA,MAAM,SAAS;SACnB,IAAIL,+BAAeC,QAAQI,MAAM,OAAO,GAC3C,OAAOA,MAAM,OAAO;AAG5B;AAEO,MAAMC,sBAAsB,CAC/BL,QACAM,WACAF;IAEA,IAAIG,kBAAkBJ,mBAAmBH,QAAQI;IACjD,IAAII,qBAAqBL,mBAAmBG,WAAWF;IACvD,IAAI,CAACG,mBAAmB,CAACC,oBACrB,OAAO;IAEX,IAAI,CAACD,iBACDA,kBAAkBC;IAEtB,IAAI,CAACA,oBACDA,qBAAqBD;IAEzB,OAAO;QACHA;QACAC;IACJ;AACJ"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const assignMinimumShouldMatchToQuery = ({ query, value = 1 })=>{
|
|
2
2
|
if (!Array.isArray(query.should)) return;
|
|
3
|
-
if (0 === query.should.length) return;
|
|
4
|
-
if (query.minimum_should_match) return;
|
|
3
|
+
else if (0 === query.should.length) return;
|
|
4
|
+
else if (query.minimum_should_match) return;
|
|
5
5
|
query.minimum_should_match = value > 0 ? value : 1;
|
|
6
6
|
};
|
|
7
7
|
export { assignMinimumShouldMatchToQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js","sources":["../../../../src/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.ts"],"sourcesContent":["import type { QueryDslBoolQuery as BoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\n\n/**\n * This function will assign a minimum_should_match for the query if conditions are met:\n * * should is an array\n * * it is not empty\n * * minimum_should_match is not already set\n *\n *\n * By the default we set it to 1 as we want at least one OR condition to produce results.\n *\n * Users can modify minimum_should_match value via the body or query modification plugins.\n */\ninterface Params {\n query: BoolQueryConfig;\n value?: number;\n}\nexport const assignMinimumShouldMatchToQuery = ({ query, value = 1 }: Params): void => {\n if (!Array.isArray(query.should)) {\n return;\n } else if (query.should.length === 0) {\n return;\n } else if (query.minimum_should_match) {\n return;\n }\n query.minimum_should_match = value > 0 ? value : 1;\n};\n"],"names":["assignMinimumShouldMatchToQuery","query","value","Array"],"mappings":"AAiBO,MAAMA,kCAAkC,CAAC,EAAEC,KAAK,EAAEC,QAAQ,CAAC,EAAU;IACxE,IAAI,CAACC,MAAM,OAAO,CAACF,MAAM,MAAM,GAC3B;
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js","sources":["../../../../src/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.ts"],"sourcesContent":["import type { QueryDslBoolQuery as BoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\n\n/**\n * This function will assign a minimum_should_match for the query if conditions are met:\n * * should is an array\n * * it is not empty\n * * minimum_should_match is not already set\n *\n *\n * By the default we set it to 1 as we want at least one OR condition to produce results.\n *\n * Users can modify minimum_should_match value via the body or query modification plugins.\n */\ninterface Params {\n query: BoolQueryConfig;\n value?: number;\n}\nexport const assignMinimumShouldMatchToQuery = ({ query, value = 1 }: Params): void => {\n if (!Array.isArray(query.should)) {\n return;\n } else if (query.should.length === 0) {\n return;\n } else if (query.minimum_should_match) {\n return;\n }\n query.minimum_should_match = value > 0 ? value : 1;\n};\n"],"names":["assignMinimumShouldMatchToQuery","query","value","Array"],"mappings":"AAiBO,MAAMA,kCAAkC,CAAC,EAAEC,KAAK,EAAEC,QAAQ,CAAC,EAAU;IACxE,IAAI,CAACC,MAAM,OAAO,CAACF,MAAM,MAAM,GAC3B;SACG,IAAIA,AAAwB,MAAxBA,MAAM,MAAM,CAAC,MAAM,EAC1B;SACG,IAAIA,MAAM,oBAAoB,EACjC;IAEJA,MAAM,oBAAoB,GAAGC,QAAQ,IAAIA,QAAQ;AACrD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ModelFields } from "../../../../operations/entry/elasticsearch/types.js";
|
|
2
|
+
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Filter fields for the fields registered as `CmsEntrySystemField`. The `system` object is indexed
|
|
5
|
+
* as-is (raw storage ids), so a text field resolves to `system.<path>.keyword`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const createEntrySystemFields: (fields: CmsModelField[]) => ModelFields;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createSystemField } from "./createSystemField.js";
|
|
2
|
+
const systemParent = {
|
|
3
|
+
fieldId: "system",
|
|
4
|
+
type: "object",
|
|
5
|
+
storageId: "system"
|
|
6
|
+
};
|
|
7
|
+
const addFields = (result, fields, parents)=>{
|
|
8
|
+
for (const field of fields){
|
|
9
|
+
const path = [
|
|
10
|
+
...parents.map((parent)=>parent.fieldId),
|
|
11
|
+
field.fieldId
|
|
12
|
+
].join(".");
|
|
13
|
+
result[path] = {
|
|
14
|
+
type: field.type,
|
|
15
|
+
systemField: true,
|
|
16
|
+
searchable: true,
|
|
17
|
+
sortable: false,
|
|
18
|
+
parents,
|
|
19
|
+
field
|
|
20
|
+
};
|
|
21
|
+
const children = field.settings?.fields;
|
|
22
|
+
if (children?.length) addFields(result, children, [
|
|
23
|
+
...parents,
|
|
24
|
+
{
|
|
25
|
+
fieldId: field.fieldId,
|
|
26
|
+
type: field.type,
|
|
27
|
+
storageId: field.storageId
|
|
28
|
+
}
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const createEntrySystemFields = (fields)=>{
|
|
33
|
+
if (0 === fields.length) return {};
|
|
34
|
+
const result = {
|
|
35
|
+
system: {
|
|
36
|
+
type: "object",
|
|
37
|
+
systemField: true,
|
|
38
|
+
searchable: true,
|
|
39
|
+
sortable: false,
|
|
40
|
+
field: createSystemField({
|
|
41
|
+
storageId: "system",
|
|
42
|
+
fieldId: "system",
|
|
43
|
+
type: "object",
|
|
44
|
+
settings: {
|
|
45
|
+
fields
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
parents: []
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
addFields(result, fields, [
|
|
52
|
+
systemParent
|
|
53
|
+
]);
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
export { createEntrySystemFields };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=system.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/fields/system.js","sources":["../../../../../src/operations/entry/elasticsearch/fields/system.ts"],"sourcesContent":["import type { ModelFieldParent, ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\nimport type { CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport { createSystemField } from \"./createSystemField.js\";\n\nconst systemParent: ModelFieldParent = {\n fieldId: \"system\",\n type: \"object\",\n storageId: \"system\"\n};\n\n/**\n * ObjectFilter resolves one level at a time, so every nested object needs its own entry.\n */\nconst addFields = (result: ModelFields, fields: CmsModelField[], parents: ModelFieldParent[]) => {\n for (const field of fields) {\n const path = [...parents.map(parent => parent.fieldId), field.fieldId].join(\".\");\n result[path] = {\n type: field.type,\n systemField: true,\n searchable: true,\n sortable: false,\n parents,\n field\n };\n const children = field.settings?.fields;\n if (!children?.length) {\n continue;\n }\n addFields(result, children, [\n ...parents,\n {\n fieldId: field.fieldId,\n type: field.type,\n storageId: field.storageId\n }\n ]);\n }\n};\n\n/**\n * Filter fields for the fields registered as `CmsEntrySystemField`. The `system` object is indexed\n * as-is (raw storage ids), so a text field resolves to `system.<path>.keyword`.\n */\nexport const createEntrySystemFields = (fields: CmsModelField[]): ModelFields => {\n if (fields.length === 0) {\n return {};\n }\n const result: ModelFields = {\n system: {\n type: \"object\",\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"system\",\n fieldId: \"system\",\n type: \"object\",\n settings: {\n fields\n }\n }),\n parents: []\n }\n };\n addFields(result, fields, [systemParent]);\n return result;\n};\n"],"names":["systemParent","addFields","result","fields","parents","field","path","parent","children","createEntrySystemFields","createSystemField"],"mappings":";AAIA,MAAMA,eAAiC;IACnC,SAAS;IACT,MAAM;IACN,WAAW;AACf;AAKA,MAAMC,YAAY,CAACC,QAAqBC,QAAyBC;IAC7D,KAAK,MAAMC,SAASF,OAAQ;QACxB,MAAMG,OAAO;eAAIF,QAAQ,GAAG,CAACG,CAAAA,SAAUA,OAAO,OAAO;YAAGF,MAAM,OAAO;SAAC,CAAC,IAAI,CAAC;QAC5EH,MAAM,CAACI,KAAK,GAAG;YACX,MAAMD,MAAM,IAAI;YAChB,aAAa;YACb,YAAY;YACZ,UAAU;YACVD;YACAC;QACJ;QACA,MAAMG,WAAWH,MAAM,QAAQ,EAAE;QACjC,IAAKG,UAAU,QAGfP,UAAUC,QAAQM,UAAU;eACrBJ;YACH;gBACI,SAASC,MAAM,OAAO;gBACtB,MAAMA,MAAM,IAAI;gBAChB,WAAWA,MAAM,SAAS;YAC9B;SACH;IACL;AACJ;AAMO,MAAMI,0BAA0B,CAACN;IACpC,IAAIA,AAAkB,MAAlBA,OAAO,MAAM,EACb,OAAO,CAAC;IAEZ,MAAMD,SAAsB;QACxB,QAAQ;YACJ,MAAM;YACN,aAAa;YACb,YAAY;YACZ,UAAU;YACV,OAAOQ,kBAAkB;gBACrB,WAAW;gBACX,SAAS;gBACT,MAAM;gBACN,UAAU;oBACNP;gBACJ;YACJ;YACA,SAAS,EAAE;QACf;IACJ;IACAF,UAAUC,QAAQC,QAAQ;QAACH;KAAa;IACxC,OAAOE;AACX"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
1
|
+
import type { CmsModel, CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
2
2
|
import { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/features/graphql/index.js";
|
|
3
3
|
import { CmsEntryOpenSearchFieldIndexRegistry } from "../../../features/CmsEntryOpenSearchFieldIndex/index.js";
|
|
4
4
|
interface ICreateModelFieldsParams {
|
|
5
5
|
model: CmsModel;
|
|
6
6
|
fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;
|
|
7
7
|
fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface;
|
|
8
|
+
/** Fields registered as `CmsEntrySystemField`, filterable under `system`. */
|
|
9
|
+
systemFields: CmsModelField[];
|
|
8
10
|
}
|
|
9
|
-
export declare const createModelFields: ({ model, fieldRegistry, fieldIndexRegistry }: ICreateModelFieldsParams) => {
|
|
11
|
+
export declare const createModelFields: ({ model, fieldRegistry, fieldIndexRegistry, systemFields }: ICreateModelFieldsParams) => {
|
|
10
12
|
[x: string]: import("./types.js").ModelField;
|
|
11
13
|
};
|
|
12
14
|
export {};
|
|
@@ -5,7 +5,8 @@ import { liveFields } from "./fields/live.js";
|
|
|
5
5
|
import { createSystemField } from "./fields/createSystemField.js";
|
|
6
6
|
import { stateFields } from "./fields/state.js";
|
|
7
7
|
import { locationFields } from "./fields/location.js";
|
|
8
|
-
|
|
8
|
+
import { createEntrySystemFields } from "./fields/system.js";
|
|
9
|
+
const createSystemFields = (entrySystemFields)=>{
|
|
9
10
|
const onMetaFields = ENTRY_META_FIELDS.filter(isDateTimeEntryMetaField).reduce((current, fieldName)=>({
|
|
10
11
|
...current,
|
|
11
12
|
[fieldName]: {
|
|
@@ -128,7 +129,8 @@ const createSystemFields = ()=>{
|
|
|
128
129
|
parents: []
|
|
129
130
|
},
|
|
130
131
|
...stateFields,
|
|
131
|
-
...liveFields
|
|
132
|
+
...liveFields,
|
|
133
|
+
...createEntrySystemFields(entrySystemFields)
|
|
132
134
|
};
|
|
133
135
|
};
|
|
134
136
|
const buildFieldsList = (params)=>{
|
|
@@ -171,7 +173,7 @@ const buildFieldsList = (params)=>{
|
|
|
171
173
|
return result;
|
|
172
174
|
}, {});
|
|
173
175
|
};
|
|
174
|
-
const createModelFields = ({ model, fieldRegistry, fieldIndexRegistry })=>{
|
|
176
|
+
const createModelFields = ({ model, fieldRegistry, fieldIndexRegistry, systemFields })=>{
|
|
175
177
|
const fields = model.fields;
|
|
176
178
|
const unmappedTypes = fieldIndexRegistry.getAll().reduce((acc, fieldIndex)=>{
|
|
177
179
|
if (!fieldIndex.unmappedType) return acc;
|
|
@@ -188,7 +190,7 @@ const createModelFields = ({ model, fieldRegistry, fieldIndexRegistry })=>{
|
|
|
188
190
|
return types;
|
|
189
191
|
}, {});
|
|
190
192
|
return {
|
|
191
|
-
...createSystemFields(),
|
|
193
|
+
...createSystemFields(systemFields),
|
|
192
194
|
...buildFieldsList({
|
|
193
195
|
fields,
|
|
194
196
|
plugins: fieldTypePlugins,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/elasticsearch/fields.js","sources":["../../../../src/operations/entry/elasticsearch/fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ModelFieldParent, ModelFields } from \"./types.js\";\nimport {\n ENTRY_META_FIELDS,\n isDateTimeEntryMetaField,\n isIdentityEntryMetaField\n} from \"@webiny/api-headless-cms/constants.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\nimport { liveFields } from \"./fields/live.js\";\nimport { createSystemField } from \"./fields/createSystemField.js\";\nimport { stateFields } from \"./fields/state.js\";\nimport { locationFields } from \"./fields/location.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/features/graphql/index.js\";\nimport { CmsEntryOpenSearchFieldIndexRegistry } from \"~/features/CmsEntryOpenSearchFieldIndex/index.js\";\n\nconst createSystemFields = (): ModelFields => {\n const onMetaFields = ENTRY_META_FIELDS.filter(isDateTimeEntryMetaField).reduce(\n (current, fieldName) => {\n return {\n ...current,\n [fieldName]: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: fieldName,\n fieldId: fieldName,\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n }\n };\n },\n {}\n );\n\n const byMetaFields = ENTRY_META_FIELDS.filter(isIdentityEntryMetaField).reduce(\n (current, fieldName) => {\n return {\n ...current,\n [fieldName]: {\n type: \"text\",\n unmappedType: undefined,\n systemField: true,\n searchable: true,\n sortable: true,\n path: `${fieldName}.id`,\n field: createSystemField({\n storageId: fieldName,\n fieldId: fieldName,\n type: \"text\"\n }),\n parents: []\n }\n };\n },\n {}\n );\n\n return {\n id: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n\n ...onMetaFields,\n ...byMetaFields,\n\n ...locationFields,\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n },\n wbyDeleted: {\n type: \"boolean\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"wbyDeleted\",\n fieldId: \"wbyDeleted\",\n type: \"boolean\"\n }),\n parents: []\n },\n binOriginalFolderId: {\n type: \"text\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"binOriginalFolderId\",\n fieldId: \"binOriginalFolderId\",\n type: \"text\"\n }),\n parents: []\n },\n ...stateFields,\n ...liveFields\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n searchable: boolean;\n sortable: boolean;\n isFullTextSearchable?: boolean;\n}\n\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\n\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const fieldType = getBaseFieldType(field);\n const plugin = plugins[fieldType];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { searchable, sortable, unmappedType, isFullTextSearchable: fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: fieldType\n }\n ]\n });\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: fieldType,\n parents,\n searchable,\n sortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n systemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface ICreateModelFieldsParams {\n model: CmsModel;\n fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;\n fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface;\n}\n\nexport const createModelFields = ({\n model,\n fieldRegistry,\n fieldIndexRegistry\n}: ICreateModelFieldsParams) => {\n const fields = model.fields;\n /**\n * Collect all unmappedType from field index registry.\n */\n const unmappedTypes = fieldIndexRegistry\n .getAll()\n .reduce<UnmappedFieldTypes>((acc, fieldIndex) => {\n if (!fieldIndex.unmappedType) {\n return acc;\n }\n acc[fieldIndex.fieldType] = fieldIndex.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = fieldRegistry.getAll().reduce<FieldTypePlugins>((types, field) => {\n types[field.fieldType] = {\n unmappedType: unmappedTypes[field.fieldType],\n searchable: field.isSearchable,\n sortable: field.isSortable,\n isFullTextSearchable: field.isFullTextSearchable\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(),\n ...buildFieldsList({\n fields,\n plugins: fieldTypePlugins,\n parents: [\n {\n fieldId: \"values\",\n type: \"object\",\n storageId: \"values\"\n }\n ]\n })\n };\n};\n"],"names":["createSystemFields","onMetaFields","ENTRY_META_FIELDS","isDateTimeEntryMetaField","current","fieldName","createSystemField","byMetaFields","isIdentityEntryMetaField","undefined","locationFields","stateFields","liveFields","buildFieldsList","params","plugins","fields","parents","result","field","fieldType","getBaseFieldType","plugin","WebinyError","searchable","sortable","unmappedType","fullTextSearch","childFields","childResult","Object","identifier","p","createModelFields","model","fieldRegistry","fieldIndexRegistry","unmappedTypes","acc","fieldIndex","fieldTypePlugins","types"],"mappings":";;;;;;;AAgBA,MAAMA,qBAAqB;IACvB,MAAMC,eAAeC,kBAAkB,MAAM,CAACC,0BAA0B,MAAM,CAC1E,CAACC,SAASC,YACC;YACH,GAAGD,OAAO;YACV,CAACC,UAAU,EAAE;gBACT,MAAM;gBACN,cAAc;gBACd,SAAS;gBACT,aAAa;gBACb,YAAY;gBACZ,UAAU;gBACV,OAAOC,kBAAkB;oBACrB,WAAWD;oBACX,SAASA;oBACT,MAAM;oBACN,UAAU;wBACN,MAAM;oBACV;gBACJ;gBACA,SAAS,EAAE;YACf;QACJ,IAEJ,CAAC;IAGL,MAAME,eAAeL,kBAAkB,MAAM,CAACM,0BAA0B,MAAM,CAC1E,CAACJ,SAASC,YACC;YACH,GAAGD,OAAO;YACV,CAACC,UAAU,EAAE;gBACT,MAAM;gBACN,cAAcI;gBACd,aAAa;gBACb,YAAY;gBACZ,UAAU;gBACV,MAAM,GAAGJ,UAAU,GAAG,CAAC;gBACvB,OAAOC,kBAAkB;oBACrB,WAAWD;oBACX,SAASA;oBACT,MAAM;gBACV;gBACA,SAAS,EAAE;YACf;QACJ,IAEJ,CAAC;IAGL,OAAO;QACH,IAAI;YACA,MAAM;YACN,aAAa;YACb,YAAY;YACZ,UAAU;YACV,OAAOC,kBAAkB;gBACrB,WAAW;gBACX,SAAS;gBACT,MAAM;YACV;YACA,SAAS,EAAE;QACf;QACA,SAAS;YACL,MAAM;YACN,aAAa;YACb,YAAY;YACZ,UAAU;YACV,OAAOA,kBAAkB;gBACrB,WAAW;gBACX,SAAS;gBACT,MAAM;YACV;YACA,SAAS,EAAE;QACf;QAEA,GAAGL,YAAY;QACf,GAAGM,YAAY;QAEf,GAAGG,cAAc;QACjB,SAAS;YACL,MAAM;YACN,cAAcD;YACd,SAAS;YACT,aAAa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BACtB,WAAWA,MAAM,SAAS;wBAC1B,MAAMC;oBACV;iBACH;YACL;YACAU,OAAO,MAAM,CAACZ,QAAQW;QAC1B;QAEA,MAAME,aAAa;eAAId,QAAQ,GAAG,CAACe,CAAAA,IAAKA,EAAE,OAAO;YAAGb,MAAM,OAAO;SAAC,CAAC,IAAI,CAAC;QAExED,MAAM,CAACa,WAAW,GAAG;YACjB,MAAMX;YACNH;YACAO;YACAC;YACAE;YACA,cAAc,AAAwB,cAAxB,OAAOD,eAA8BA,aAAaP,SAASV;YACzE,aAAa;YACbU;QACJ;QAEA,OAAOD;IACX,GAAG,CAAC;AACR;AAQO,MAAMe,oBAAoB,CAAC,EAC9BC,KAAK,EACLC,aAAa,EACbC,kBAAkB,EACK;IACvB,MAAMpB,SAASkB,MAAM,MAAM;IAI3B,MAAMG,gBAAgBD,mBACjB,MAAM,GACN,MAAM,CAAqB,CAACE,KAAKC;QAC9B,IAAI,CAACA,WAAW,YAAY,EACxB,OAAOD;QAEXA,GAAG,CAACC,WAAW,SAAS,CAAC,GAAGA,WAAW,YAAY;QACnD,OAAOD;IACX,GAAG,CAAC;IAIR,MAAME,mBAAmBL,cAAc,MAAM,GAAG,MAAM,CAAmB,CAACM,OAAOtB;QAC7EsB,KAAK,CAACtB,MAAM,SAAS,CAAC,GAAG;YACrB,cAAckB,aAAa,CAAClB,MAAM,SAAS,CAAC;YAC5C,YAAYA,MAAM,YAAY;YAC9B,UAAUA,MAAM,UAAU;YAC1B,sBAAsBA,MAAM,oBAAoB;QACpD;QACA,OAAOsB;IACX,GAAG,CAAC;IAEJ,OAAO;QACH,GAAGzC,oBAAoB;QACvB,GAAGa,gBAAgB;YACfG;YACA,SAASwB;YACT,SAAS;gBACL;oBACI,SAAS;oBACT,MAAM;oBACN,WAAW;gBACf;aACH;QACL,EAAE;IACN;AACJ"}
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/fields.js","sources":["../../../../src/operations/entry/elasticsearch/fields.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsModel, CmsModelField } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ModelFieldParent, ModelFields } from \"./types.js\";\nimport {\n ENTRY_META_FIELDS,\n isDateTimeEntryMetaField,\n isIdentityEntryMetaField\n} from \"@webiny/api-headless-cms/constants.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\nimport { liveFields } from \"./fields/live.js\";\nimport { createSystemField } from \"./fields/createSystemField.js\";\nimport { stateFields } from \"./fields/state.js\";\nimport { locationFields } from \"./fields/location.js\";\nimport { createEntrySystemFields } from \"./fields/system.js\";\nimport { CmsModelFieldToGraphQLRegistry } from \"@webiny/api-headless-cms/features/graphql/index.js\";\nimport { CmsEntryOpenSearchFieldIndexRegistry } from \"~/features/CmsEntryOpenSearchFieldIndex/index.js\";\n\nconst createSystemFields = (entrySystemFields: CmsModelField[]): ModelFields => {\n const onMetaFields = ENTRY_META_FIELDS.filter(isDateTimeEntryMetaField).reduce(\n (current, fieldName) => {\n return {\n ...current,\n [fieldName]: {\n type: \"date\",\n unmappedType: \"date\",\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: fieldName,\n fieldId: fieldName,\n type: \"text\",\n settings: {\n type: \"dateTimeWithoutTimezone\"\n }\n }),\n parents: []\n }\n };\n },\n {}\n );\n\n const byMetaFields = ENTRY_META_FIELDS.filter(isIdentityEntryMetaField).reduce(\n (current, fieldName) => {\n return {\n ...current,\n [fieldName]: {\n type: \"text\",\n unmappedType: undefined,\n systemField: true,\n searchable: true,\n sortable: true,\n path: `${fieldName}.id`,\n field: createSystemField({\n storageId: fieldName,\n fieldId: fieldName,\n type: \"text\"\n }),\n parents: []\n }\n };\n },\n {}\n );\n\n return {\n id: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"id\",\n fieldId: \"id\",\n type: \"text\"\n }),\n parents: []\n },\n entryId: {\n type: \"text\",\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"entryId\",\n fieldId: \"entryId\",\n type: \"text\"\n }),\n parents: []\n },\n\n ...onMetaFields,\n ...byMetaFields,\n\n ...locationFields,\n version: {\n type: \"number\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: true,\n field: createSystemField({\n storageId: \"version\",\n fieldId: \"version\",\n type: \"number\"\n }),\n parents: []\n },\n status: {\n type: \"string\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"status\",\n fieldId: \"status\",\n type: \"string\"\n }),\n parents: []\n },\n wbyDeleted: {\n type: \"boolean\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"wbyDeleted\",\n fieldId: \"wbyDeleted\",\n type: \"boolean\"\n }),\n parents: []\n },\n binOriginalFolderId: {\n type: \"text\",\n unmappedType: undefined,\n keyword: false,\n systemField: true,\n searchable: true,\n sortable: false,\n field: createSystemField({\n storageId: \"binOriginalFolderId\",\n fieldId: \"binOriginalFolderId\",\n type: \"text\"\n }),\n parents: []\n },\n ...stateFields,\n ...liveFields,\n ...createEntrySystemFields(entrySystemFields)\n };\n};\n\ninterface UnmappedFieldTypes {\n [type: string]: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n}\n\ninterface FieldTypePlugin {\n unmappedType?: (field: Pick<CmsModelField, \"fieldId\" | \"type\">) => string | undefined;\n searchable: boolean;\n sortable: boolean;\n isFullTextSearchable?: boolean;\n}\n\ninterface FieldTypePlugins {\n [key: string]: FieldTypePlugin;\n}\n\ninterface BuildParams {\n plugins: FieldTypePlugins;\n fields: CmsModelField[];\n parents: ModelFieldParent[];\n}\n\nconst buildFieldsList = (params: BuildParams): ModelFields => {\n const { plugins, fields, parents } = params;\n\n return fields.reduce<ModelFields>((result, field) => {\n const fieldType = getBaseFieldType(field);\n const plugin = plugins[fieldType];\n if (!plugin) {\n throw new WebinyError(`There is no plugin for field type \"${field.type}\".`);\n }\n\n const { searchable, sortable, unmappedType, isFullTextSearchable: fullTextSearch } = plugin;\n /**\n * If a field has child fields, go through them and add them to a result.\n */\n const childFields = field.settings?.fields || [];\n if (childFields.length > 0) {\n /**\n * Let's build all the child fields\n */\n const childResult = buildFieldsList({\n fields: childFields,\n plugins,\n parents: [\n ...parents,\n {\n fieldId: field.fieldId,\n storageId: field.storageId,\n type: fieldType\n }\n ]\n });\n Object.assign(result, childResult);\n }\n\n const identifier = [...parents.map(p => p.fieldId), field.fieldId].join(\".\");\n\n result[identifier] = {\n type: fieldType,\n parents,\n searchable,\n sortable,\n fullTextSearch,\n unmappedType: typeof unmappedType === \"function\" ? unmappedType(field) : undefined,\n systemField: false,\n field\n };\n\n return result;\n }, {});\n};\n\ninterface ICreateModelFieldsParams {\n model: CmsModel;\n fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;\n fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface;\n /** Fields registered as `CmsEntrySystemField`, filterable under `system`. */\n systemFields: CmsModelField[];\n}\n\nexport const createModelFields = ({\n model,\n fieldRegistry,\n fieldIndexRegistry,\n systemFields\n}: ICreateModelFieldsParams) => {\n const fields = model.fields;\n /**\n * Collect all unmappedType from field index registry.\n */\n const unmappedTypes = fieldIndexRegistry\n .getAll()\n .reduce<UnmappedFieldTypes>((acc, fieldIndex) => {\n if (!fieldIndex.unmappedType) {\n return acc;\n }\n acc[fieldIndex.fieldType] = fieldIndex.unmappedType;\n return acc;\n }, {});\n /**\n * Collect all field types from the plugins.\n */\n const fieldTypePlugins = fieldRegistry.getAll().reduce<FieldTypePlugins>((types, field) => {\n types[field.fieldType] = {\n unmappedType: unmappedTypes[field.fieldType],\n searchable: field.isSearchable,\n sortable: field.isSortable,\n isFullTextSearchable: field.isFullTextSearchable\n };\n return types;\n }, {});\n\n return {\n ...createSystemFields(systemFields),\n ...buildFieldsList({\n fields,\n plugins: fieldTypePlugins,\n parents: [\n {\n fieldId: \"values\",\n type: \"object\",\n storageId: \"values\"\n }\n ]\n })\n };\n};\n"],"names":["createSystemFields","entrySystemFields","onMetaFields","ENTRY_META_FIELDS","isDateTimeEntryMetaField","current","fieldName","createSystemField","byMetaFields","isIdentityEntryMetaField","undefined","locationFields","stateFields","liveFields","createEntrySystemFields","buildFieldsList","params","plugins","fields","parents","result","field","fieldType","getBaseFieldType","plugin","WebinyError","searchable","sortable","unmappedType","fullTextSearch","childFields","childResult","Object","identifier","p","createModelFields","model","fieldRegistry","fieldIndexRegistry","systemFields","unmappedTypes","acc","fieldIndex","fieldTypePlugins","types"],"mappings":";;;;;;;;AAiBA,MAAMA,qBAAqB,CAACC;IACxB,MAAMC,eAAeC,kBAAkB,MAAM,CAACC,0BAA0B,MAAM,CAC1E,CAACC,SAASC,YACC;YACH,GAAGD,OAAO;YACV,CAACC,UAAU,EAAE;gBACT,MAAM;gBACN,cAAc;gBACd,SAAS;gBACT,aAAa;gBACb,YAAY;gBACZ,UAAU;gBACV,OAAOC,kBAAkB;oBACrB,WAAWD;oBACX,SAASA;oBACT,MAAM;oBACN,UAAU;wBACN,MAAM;oBACV;gBACJ;gBACA,SAAS,EAAE;YACf;QACJ,IAEJ,CAAC;IAGL,MAAME,eAAeL,kBAAkB,MAAM,CAACM,0BAA0B,MAAM,CAC1E,CAACJ,SAASC,YACC;YACH,GAAGD,OAAO;YACV,CAACC,UAAU,EAAE;gBACT,MAAM;gBACN,cAAcI;gBACd,aAAa;gBACb,YAAY;gBACZ,UAAU;gBACV,MAAM,GAAGJ,UAAU,GAAG,CAAC;gBACvB,OAAOC,kBAAkB;oBACrB,WAAWD;oBACX,SAASA;oBACT,MAAM;gBACV;gBACA,SAAS,EAAE;YACf;QACJ,IAEJ,CAAC;IAGL,OAAO;QACH,IAAI;YACA,MAAM;YACN,aAAa;YACb,YAAY;YACZ,UAAU;YACV,OAAOC,kBAAkB;gBACrB,W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Y;YAC9B,UAAUA,MAAM,UAAU;YAC1B,sBAAsBA,MAAM,oBAAoB;QACpD;QACA,OAAOuB;IACX,GAAG,CAAC;IAEJ,OAAO;QACH,GAAG5C,mBAAmBuC,aAAa;QACnC,GAAGxB,gBAAgB;YACfG;YACA,SAASyB;YACT,SAAS;gBACL;oBACI,SAAS;oBACT,MAAM;oBACN,WAAW;gBACf;aACH;QACL,EAAE;IACN;AACJ"}
|
|
@@ -22,7 +22,7 @@ const getFullTextSearch = (params)=>{
|
|
|
22
22
|
for (const item of reversed){
|
|
23
23
|
const models = item.models || [];
|
|
24
24
|
if (models.includes(model.modelId)) return item;
|
|
25
|
-
if (!fallback && 0 === models.length) fallback = item;
|
|
25
|
+
else if (!fallback && 0 === models.length) fallback = item;
|
|
26
26
|
}
|
|
27
27
|
return fallback || defaultFullTextSearch;
|
|
28
28
|
};
|
|
@@ -38,7 +38,7 @@ const applyFullTextSearch = (params)=>{
|
|
|
38
38
|
model,
|
|
39
39
|
createFieldPath: (field)=>{
|
|
40
40
|
if ("function" == typeof field.path) return field.path(term);
|
|
41
|
-
if (field.systemField) return field.path || field.field.storageId;
|
|
41
|
+
else if (field.systemField) return field.path || field.field.storageId;
|
|
42
42
|
const parents = field.parents.length > 0 ? field.parents.map((p)=>p.storageId) : [
|
|
43
43
|
"values"
|
|
44
44
|
];
|
|
@@ -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 /**\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;
|
|
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;I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KeywordFields = [
|
|
|
8
8
|
const hasKeyword = (field)=>{
|
|
9
9
|
const fieldType = getBaseFieldType(field);
|
|
10
10
|
if (noKeywordFields.includes(fieldType)) return false;
|
|
11
|
-
if (field.unmappedType) return false;
|
|
12
|
-
if (false === field.keyword) return false;
|
|
11
|
+
else if (field.unmappedType) return false;
|
|
12
|
+
else if (false === field.keyword) return false;
|
|
13
13
|
return true;
|
|
14
14
|
};
|
|
15
15
|
export { hasKeyword };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/elasticsearch/keyword.js","sources":["../../../../src/operations/entry/elasticsearch/keyword.ts"],"sourcesContent":["import type { ModelField } from \"./types.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\nconst noKeywordFields: string[] = [\"date\", \"datetime\", \"number\", \"boolean\"];\nexport const hasKeyword = (field: ModelField): boolean => {\n const fieldType = getBaseFieldType(field);\n /**\n * We defined some field types that MUST have no keyword added to the field path\n */\n if (noKeywordFields.includes(fieldType)) {\n return false;\n }\n /**\n * If field has unmapped type defined, do not add keyword.\n */\n //\n else if (field.unmappedType) {\n return false;\n }\n /**\n * And if specifically defined that field has no keyword, do not add it.\n */\n //\n else if (field.keyword === false) {\n return false;\n }\n /**\n * All other fields have keyword added.\n */\n return true;\n};\n"],"names":["noKeywordFields","hasKeyword","field","fieldType","getBaseFieldType"],"mappings":";AAGA,MAAMA,kBAA4B;IAAC;IAAQ;IAAY;IAAU;CAAU;AACpE,MAAMC,aAAa,CAACC;IACvB,MAAMC,YAAYC,iBAAiBF;IAInC,IAAIF,gBAAgB,QAAQ,CAACG,YACzB,OAAO;
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/keyword.js","sources":["../../../../src/operations/entry/elasticsearch/keyword.ts"],"sourcesContent":["import type { ModelField } from \"./types.js\";\nimport { getBaseFieldType } from \"@webiny/api-headless-cms/utils/getBaseFieldType.js\";\n\nconst noKeywordFields: string[] = [\"date\", \"datetime\", \"number\", \"boolean\"];\nexport const hasKeyword = (field: ModelField): boolean => {\n const fieldType = getBaseFieldType(field);\n /**\n * We defined some field types that MUST have no keyword added to the field path\n */\n if (noKeywordFields.includes(fieldType)) {\n return false;\n }\n /**\n * If field has unmapped type defined, do not add keyword.\n */\n //\n else if (field.unmappedType) {\n return false;\n }\n /**\n * And if specifically defined that field has no keyword, do not add it.\n */\n //\n else if (field.keyword === false) {\n return false;\n }\n /**\n * All other fields have keyword added.\n */\n return true;\n};\n"],"names":["noKeywordFields","hasKeyword","field","fieldType","getBaseFieldType"],"mappings":";AAGA,MAAMA,kBAA4B;IAAC;IAAQ;IAAY;IAAU;CAAU;AACpE,MAAMC,aAAa,CAACC;IACvB,MAAMC,YAAYC,iBAAiBF;IAInC,IAAIF,gBAAgB,QAAQ,CAACG,YACzB,OAAO;SAMN,IAAID,MAAM,YAAY,EACvB,OAAO;SAMN,IAAIA,AAAkB,UAAlBA,MAAM,OAAO,EAClB,OAAO;IAKX,OAAO;AACX"}
|
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.9609e4e0c9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -15,15 +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.9609e4e0c9",
|
|
19
|
+
"@webiny/api-opensearch": "0.0.0-unstable.9609e4e0c9",
|
|
20
|
+
"@webiny/error": "0.0.0-unstable.9609e4e0c9",
|
|
21
|
+
"@webiny/feature": "0.0.0-unstable.9609e4e0c9"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
24
|
+
"@webiny/build-tools": "0.0.0-unstable.9609e4e0c9",
|
|
25
25
|
"typescript": "7.0.2",
|
|
26
|
-
"vitest": "
|
|
26
|
+
"vitest": "5.0.5"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|