@webiny/api-headless-cms-ddb-es 6.4.12-beta.5 → 6.5.0-beta.1
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/exports/api/cms/opensearch.d.ts +1 -1
- package/exports/api/cms/opensearch.js +1 -1
- package/feature.js +29 -15
- package/feature.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/ObjectFieldIndex.js +11 -2
- package/features/CmsEntryOpenSearchFieldIndex/fields/ObjectFieldIndex.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/body.d.ts +5 -3
- package/operations/entry/elasticsearch/body.js +4 -3
- package/operations/entry/elasticsearch/body.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/applyFiltering.d.ts +3 -3
- package/operations/entry/elasticsearch/filtering/applyFiltering.js +2 -2
- package/operations/entry/elasticsearch/filtering/applyFiltering.js.map +1 -1
- package/operations/entry/elasticsearch/filtering/exec.d.ts +2 -2
- package/operations/entry/elasticsearch/filtering/exec.js +7 -6
- package/operations/entry/elasticsearch/filtering/exec.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/operations/entry/elasticsearch/plugins/operator.d.ts +4 -4
- package/operations/entry/elasticsearch/plugins/operator.js +3 -6
- package/operations/entry/elasticsearch/plugins/operator.js.map +1 -1
- package/operations/entry/elasticsearch/sort.d.ts +4 -1
- package/operations/entry/elasticsearch/sort.js +5 -5
- package/operations/entry/elasticsearch/sort.js.map +1 -1
- package/operations/entry/elasticsearch/types.d.ts +3 -6
- package/operations/entry/index.d.ts +4 -3
- package/operations/entry/index.js +40 -18
- package/operations/entry/index.js.map +1 -1
- package/operations/entry/transformations/modifyEntryValues.d.ts +1 -1
- package/package.json +24 -24
- package/tasks/CreateElasticsearchIndexTask.d.ts +16 -0
- package/tasks/{createIndexTaskPlugin.js → CreateElasticsearchIndexTask.js} +25 -20
- package/tasks/CreateElasticsearchIndexTask.js.map +1 -0
- package/types.d.ts +4 -7
- package/types.js.map +1 -1
- package/debuggerNamespaces.d.ts +0 -12
- package/debuggerNamespaces.js +0 -0
- package/tasks/createIndexTaskPlugin.d.ts +0 -2
- package/tasks/createIndexTaskPlugin.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OpenSearchQueryBuilderOperators } from "../../../../operations/entry/elasticsearch/types.js";
|
|
2
2
|
import type { CmsEntryOpenSearchFilter } from "../../../../features/CmsEntryOpenSearchFilter/index.js";
|
|
3
3
|
import type { CmsEntryOpenSearchValueSearchRegistry } from "../../../../features/CmsEntryOpenSearchValueSearch/index.js";
|
|
4
4
|
interface CreateParams {
|
|
5
|
-
|
|
5
|
+
operators: OpenSearchQueryBuilderOperators;
|
|
6
6
|
valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;
|
|
7
7
|
}
|
|
8
|
-
export declare const createApplyFiltering: ({
|
|
8
|
+
export declare const createApplyFiltering: ({ operators, valueSearchRegistry }: CreateParams) => CmsEntryOpenSearchFilter.ApplyFiltering;
|
|
9
9
|
export {};
|
|
@@ -2,13 +2,13 @@ import error from "@webiny/error";
|
|
|
2
2
|
import { transformValueForSearch } from "../transformValueForSearch.js";
|
|
3
3
|
import { hasKeyword } from "../keyword.js";
|
|
4
4
|
import { createFieldPathFactory } from "./path.js";
|
|
5
|
-
const createApplyFiltering = ({
|
|
5
|
+
const createApplyFiltering = ({ operators, valueSearchRegistry })=>{
|
|
6
6
|
const createFieldPath = createFieldPathFactory({
|
|
7
7
|
valueSearchRegistry
|
|
8
8
|
});
|
|
9
9
|
return (params)=>{
|
|
10
10
|
const { key, value: initialValue, query, operator, field } = params;
|
|
11
|
-
const plugin =
|
|
11
|
+
const plugin = operators[operator];
|
|
12
12
|
if (!plugin) throw new error(`Elasticsearch operator "${operator}" plugin missing.`, "PLUGIN_MISSING", {
|
|
13
13
|
operator
|
|
14
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/elasticsearch/filtering/applyFiltering.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/applyFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"~/operations/entry/elasticsearch/transformValueForSearch.js\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/filtering/applyFiltering.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/applyFiltering.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"~/operations/entry/elasticsearch/transformValueForSearch.js\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword.js\";\nimport type { OpenSearchQueryBuilderOperators } from \"~/operations/entry/elasticsearch/types.js\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path.js\";\nimport type { CmsEntryOpenSearchFilter } from \"~/features/CmsEntryOpenSearchFilter/index.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\n\ninterface CreateParams {\n operators: OpenSearchQueryBuilderOperators;\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n}\n\nexport const createApplyFiltering = ({\n operators,\n valueSearchRegistry\n}: CreateParams): CmsEntryOpenSearchFilter.ApplyFiltering => {\n const createFieldPath = createFieldPathFactory({\n valueSearchRegistry\n });\n\n return params => {\n const { key, value: initialValue, query, operator, field } = params;\n\n const plugin = operators[operator];\n if (!plugin) {\n throw new WebinyError(\n `Elasticsearch operator \"${operator}\" plugin missing.`,\n \"PLUGIN_MISSING\",\n {\n operator\n }\n );\n }\n\n const value = transformValueForSearch({\n valueSearchRegistry,\n field: field.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(field);\n\n const { basePath, path } = createFieldPath({\n field,\n value,\n originalValue: initialValue,\n key,\n keyword\n });\n\n plugin.apply(query, {\n name: field.field.fieldId,\n basePath,\n path,\n value,\n keyword\n });\n };\n};\n"],"names":["createApplyFiltering","operators","valueSearchRegistry","createFieldPath","createFieldPathFactory","params","key","initialValue","query","operator","field","plugin","WebinyError","value","transformValueForSearch","keyword","hasKeyword","basePath","path"],"mappings":";;;;AAaO,MAAMA,uBAAuB,CAAC,EACjCC,SAAS,EACTC,mBAAmB,EACR;IACX,MAAMC,kBAAkBC,uBAAuB;QAC3CF;IACJ;IAEA,OAAOG,CAAAA;QACH,MAAM,EAAEC,GAAG,EAAE,OAAOC,YAAY,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGL;QAE7D,MAAMM,SAASV,SAAS,CAACQ,SAAS;QAClC,IAAI,CAACE,QACD,MAAM,IAAIC,MACN,CAAC,wBAAwB,EAAEH,SAAS,iBAAiB,CAAC,EACtD,kBACA;YACIA;QACJ;QAIR,MAAMI,QAAQC,wBAAwB;YAClCZ;YACA,OAAOQ,MAAM,KAAK;YAClB,OAAOH;QACX;QAEA,MAAMQ,UAAUC,WAAWN;QAE3B,MAAM,EAAEO,QAAQ,EAAEC,IAAI,EAAE,GAAGf,gBAAgB;YACvCO;YACAG;YACA,eAAeN;YACfD;YACAS;QACJ;QAEAJ,OAAO,KAAK,CAACH,OAAO;YAChB,MAAME,MAAM,KAAK,CAAC,OAAO;YACzBO;YACAC;YACAL;YACAE;QACJ;IACJ;AACJ"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { CmsEntryListWhere, CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
2
2
|
import type { ModelFields } from "../../../../operations/entry/elasticsearch/types.js";
|
|
3
|
-
import type { PluginsContainer } from "@webiny/plugins";
|
|
4
3
|
import type { OpenSearchBoolQueryConfig } from "@webiny/api-opensearch/types.js";
|
|
4
|
+
import type { OpenSearchQueryBuilderOperatorRegistry } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
5
5
|
import type { CmsEntryOpenSearchValueSearchRegistry } from "../../../../features/CmsEntryOpenSearchValueSearch/index.js";
|
|
6
6
|
import type { CmsEntryOpenSearchFilterRegistry } from "../../../../features/CmsEntryOpenSearchFilter/index.js";
|
|
7
7
|
export interface CreateExecParams {
|
|
8
8
|
model: CmsModel;
|
|
9
9
|
fields: ModelFields;
|
|
10
|
-
|
|
10
|
+
operatorRegistry: OpenSearchQueryBuilderOperatorRegistry.Interface;
|
|
11
11
|
valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;
|
|
12
12
|
filterRegistry: CmsEntryOpenSearchFilterRegistry.Interface;
|
|
13
13
|
}
|
|
@@ -7,12 +7,12 @@ import { getPopulated } from "./populated.js";
|
|
|
7
7
|
import { createApplyFiltering } from "./applyFiltering.js";
|
|
8
8
|
import { assignMinimumShouldMatchToQuery } from "../assignMinimumShouldMatchToQuery.js";
|
|
9
9
|
const createExecFiltering = (params)=>{
|
|
10
|
-
const { fields,
|
|
11
|
-
const
|
|
12
|
-
|
|
10
|
+
const { fields, operatorRegistry, model, valueSearchRegistry, filterRegistry } = params;
|
|
11
|
+
const operators = createOperatorPluginList({
|
|
12
|
+
registry: operatorRegistry
|
|
13
13
|
});
|
|
14
14
|
const applyFiltering = createApplyFiltering({
|
|
15
|
-
|
|
15
|
+
operators,
|
|
16
16
|
valueSearchRegistry
|
|
17
17
|
});
|
|
18
18
|
const getFilter = (type)=>filterRegistry.get(type);
|
|
@@ -24,7 +24,7 @@ const createExecFiltering = (params)=>{
|
|
|
24
24
|
for(const key in where){
|
|
25
25
|
const value = where[key];
|
|
26
26
|
if (void 0 === value) continue;
|
|
27
|
-
|
|
27
|
+
if ("AND" === key) {
|
|
28
28
|
const childWhereList = getWhereValues(value, "AND");
|
|
29
29
|
const childQuery = createBaseQuery();
|
|
30
30
|
for (const childWhere of childWhereList)execFiltering({
|
|
@@ -38,7 +38,8 @@ const createExecFiltering = (params)=>{
|
|
|
38
38
|
bool: childQueryBool
|
|
39
39
|
});
|
|
40
40
|
continue;
|
|
41
|
-
}
|
|
41
|
+
}
|
|
42
|
+
if ("OR" === key) {
|
|
42
43
|
const childWhereList = getWhereValues(value, "OR");
|
|
43
44
|
const should = [];
|
|
44
45
|
for (const childWhere of childWhereList){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/elasticsearch/filtering/exec.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/filtering/exec.js","sources":["../../../../../src/operations/entry/elasticsearch/filtering/exec.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { CmsEntryListWhere, CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\nimport type {\n OpenSearchBoolQueryConfig,\n QueryDslQueryContainer as Query\n} from \"@webiny/api-opensearch/types.js\";\nimport type { OpenSearchQueryBuilderOperatorRegistry } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport { createOperatorPluginList } from \"~/operations/entry/elasticsearch/plugins/operator.js\";\nimport { createBaseQuery } from \"~/operations/entry/elasticsearch/initialQuery.js\";\nimport { parseWhereKey } from \"@webiny/api-opensearch\";\nimport { getWhereValues } from \"./values.js\";\nimport { getPopulated } from \"./populated.js\";\nimport { createApplyFiltering } from \"./applyFiltering.js\";\nimport { assignMinimumShouldMatchToQuery } from \"~/operations/entry/elasticsearch/assignMinimumShouldMatchToQuery.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\nimport type { CmsEntryOpenSearchFilterRegistry } from \"~/features/CmsEntryOpenSearchFilter/index.js\";\n\nexport interface CreateExecParams {\n model: CmsModel;\n fields: ModelFields;\n operatorRegistry: OpenSearchQueryBuilderOperatorRegistry.Interface;\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n filterRegistry: CmsEntryOpenSearchFilterRegistry.Interface;\n}\nexport interface IExecParams {\n where: CmsEntryListWhere;\n query: OpenSearchBoolQueryConfig;\n isValues?: boolean;\n}\nexport interface CreateExecFilteringResponse {\n (params: IExecParams): void;\n}\nexport const createExecFiltering = (params: CreateExecParams): CreateExecFilteringResponse => {\n const { fields, operatorRegistry, model, valueSearchRegistry, filterRegistry } = params;\n\n const operators = createOperatorPluginList({\n registry: operatorRegistry\n });\n\n const applyFiltering = createApplyFiltering({\n operators,\n valueSearchRegistry\n });\n\n const getFilter = (type: string) => {\n return filterRegistry.get(type);\n };\n\n const execFiltering = (params: IExecParams) => {\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(`There is no field \"${fieldId}\".`, \"EXEC_FILTERING_ERROR\");\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 return execFiltering;\n};\n"],"names":["createExecFiltering","params","fields","operatorRegistry","model","valueSearchRegistry","filterRegistry","operators","createOperatorPluginList","applyFiltering","createApplyFiltering","getFilter","type","execFiltering","initialWhere","query","isValues","keys","Object","where","structuredClone","key","value","undefined","childWhereList","getWhereValues","childQuery","createBaseQuery","childWhere","childQueryBool","getPopulated","should","assignMinimumShouldMatchToQuery","whereFieldId","operator","parseWhereKey","fieldId","cmsModelField","f","WebinyError","field","filter"],"mappings":";;;;;;;;AAiCO,MAAMA,sBAAsB,CAACC;IAChC,MAAM,EAAEC,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAEC,mBAAmB,EAAEC,cAAc,EAAE,GAAGL;IAEjF,MAAMM,YAAYC,yBAAyB;QACvC,UAAUL;IACd;IAEA,MAAMM,iBAAiBC,qBAAqB;QACxCH;QACAF;IACJ;IAEA,MAAMM,YAAY,CAACC,OACRN,eAAe,GAAG,CAACM;IAG9B,MAAMC,gBAAgB,CAACZ;QACnB,MAAM,EAAE,OAAOa,YAAY,EAAEC,KAAK,EAAEC,WAAW,KAAK,EAAE,GAAGf;QACzD,MAAMgB,OAAOC,OAAO,IAAI,CAACJ;QACzB,IAAIG,AAAgB,MAAhBA,KAAK,MAAM,EACX;QAEJ,MAAME,QAAQC,gBAAgBN;QAE9B,IAAK,MAAMO,OAAOF,MAAO;YACrB,MAAMG,QAAQH,KAAK,CAACE,IAA0B;YAC9C,IAAIC,AAAUC,WAAVD,OACA;YACG,IAAID,AAAQ,UAARA,KAAe;gBACtB,MAAMG,iBAAiBC,eAAeH,OAAO;gBAC7C,MAAMI,aAAaC;gBACnB,KAAK,MAAMC,cAAcJ,eACrBX,cAAc;oBAAE,OAAOa;oBAAY,OAAOE;oBAAYZ;gBAAS;gBAEnE,MAAMa,iBAAiBC,aAAaJ;gBACpC,IAAIR,AAAuC,MAAvCA,OAAO,IAAI,CAACW,gBAAgB,MAAM,EAClC;gBAEJd,MAAM,MAAM,CAAC,IAAI,CAAC;oBAAE,MAAMc;gBAAe;gBACzC;YACJ;YAAO,IAAIR,AAAQ,SAARA,KAAc;gBACrB,MAAMG,iBAAiBC,eAAeH,OAAO;gBAC7C,MAAMS,SAAkB,EAAE;gBAC1B,KAAK,MAAMH,cAAcJ,eAAgB;oBACrC,MAAME,aAAaC;oBACnBd,cAAc;wBAAE,OAAOa;wBAAY,OAAOE;wBAAYZ;oBAAS;oBAC/D,MAAMa,iBAAiBC,aAAaJ;oBACpC,IAAIR,AAAuC,MAAvCA,OAAO,IAAI,CAACW,gBAAgB,MAAM,EAGtCE,OAAO,IAAI,CAAC;wBAAE,MAAMF;oBAAe;gBACvC;gBACA,IAAIE,AAAkB,MAAlBA,OAAO,MAAM,EACb;gBAEJhB,MAAM,MAAM,CAAC,IAAI,IAAIgB;gBACrBC,gCAAgC;oBAAEjB;gBAAM;gBACxC;YACJ,OAAO,IAAIM,AAAQ,aAARA,KAAkB;gBACzBR,cAAc;oBACVE;oBACA,OAAOI,KAAK,CAACE,IAAI;oBACjB,UAAU;gBACd;gBACA;YACJ;YACA,MAAM,EAAE,OAAOY,YAAY,EAAEC,QAAQ,EAAE,GAAGC,cAAcd;YACxD,IAAIe,UAAkBpB,WAAW,CAAC,OAAO,EAAEiB,cAAc,GAAGA;YAE5D,MAAMI,gBAAgBjC,MAAM,MAAM,CAAC,IAAI,CAACkC,CAAAA,IAAKA,EAAE,OAAO,KAAKF;YAC3D,IAAI,AAACC,iBAAkBnC,MAAM,CAACkC,QAAQ,EAE/B;gBAAA,IAAIC,eACPD,UAAUC,cAAc,OAAO;YACnC,OAHI,MAAM,IAAIE,MAAY,CAAC,6BAA6B,EAAEH,QAAQ,EAAE,CAAC;YAKrE,MAAMI,QAAQtC,MAAM,CAACkC,QAAQ;YAC7B,IAAI,CAACI,OACD,MAAM,IAAID,MAAY,CAAC,mBAAmB,EAAEH,QAAQ,EAAE,CAAC,EAAE;YAE7D,MAAMK,SAAS9B,UAAU6B,MAAM,IAAI;YAEnCC,OAAO,IAAI,CAAC;gBACRhC;gBACAE;gBACAU;gBACAC;gBACAY;gBACAM;gBACAtC;gBACAa;YACJ;QACJ;IACJ;IAEA,OAAOF;AACX"}
|
|
@@ -21,7 +21,7 @@ const getFullTextSearch = (params)=>{
|
|
|
21
21
|
for (const item of reversed){
|
|
22
22
|
const models = item.models || [];
|
|
23
23
|
if (models.includes(model.modelId)) return item;
|
|
24
|
-
|
|
24
|
+
if (!fallback && 0 === models.length) fallback = item;
|
|
25
25
|
}
|
|
26
26
|
return fallback || defaultFullTextSearch;
|
|
27
27
|
};
|
|
@@ -37,7 +37,7 @@ const applyFullTextSearch = (params)=>{
|
|
|
37
37
|
model,
|
|
38
38
|
createFieldPath: (field)=>{
|
|
39
39
|
if ("function" == typeof field.path) return field.path(term);
|
|
40
|
-
|
|
40
|
+
if (field.systemField) return field.path || field.field.storageId;
|
|
41
41
|
const path = `values.${field.path || field.field.storageId}`;
|
|
42
42
|
if ("searchable-json" === field.type) return `${path}.*`;
|
|
43
43
|
return path;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/elasticsearch/fullTextSearch.js","sources":["../../../../src/operations/entry/elasticsearch/fullTextSearch.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport { normalizeValue } from \"@webiny/api-opensearch\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\n\n/**\n * Our default implementation works with the AND operator for the multiple words query string.\n */\nconst defaultFullTextSearch: CmsEntryOpenSearchFullTextSearch.Interface = {\n apply: params => {\n const { query, term, fields, createFieldPath, prepareTerm } = params;\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: Object.values(fields).map(createFieldPath),\n query: `*${prepareTerm(term)}*`,\n default_operator: \"and\"\n }\n });\n }\n};\n\ninterface GetFullTextSearchParams {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n}\nconst getFullTextSearch = (\n params: GetFullTextSearchParams\n): CmsEntryOpenSearchFullTextSearch.Interface => {\n const { fullTextSearches, model } = params;\n /**\n * We need to reverse the list, so we can take the last one first - possibility to override existing implementations.\n */\n const reversed = [...fullTextSearches].reverse();\n /**\n * We need to find the most specific implementation for the given model.\n * Also, we need to use the first possible implementation if the specific one is not found.\n */\n let fallback: CmsEntryOpenSearchFullTextSearch.Interface | null = null;\n for (const item of reversed) {\n const models = item.models || [];\n /**\n * We take the first available implementation for the given model.\n */\n if (models.includes(model.modelId)) {\n return item;\n } else if (!fallback && models.length === 0) {\n /**\n * Then we set the first possible implementation, which has no models defined, as the default one.\n * It is important not to set the one which has models defined as they are specifically for the targeted model.\n */\n fallback = item;\n }\n }\n\n return fallback || defaultFullTextSearch;\n};\n\ninterface Params {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n query: OpenSearchBoolQueryConfig;\n term?: string;\n fields: ModelFields;\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { fullTextSearches, query, term, fields, model } = params;\n const keys = Object.keys(fields);\n if (!term || term.length === 0 || keys.length === 0) {\n return;\n }\n\n const fullTextSearch = getFullTextSearch({\n fullTextSearches,\n model\n });\n\n fullTextSearch.apply({\n model,\n createFieldPath: field => {\n if (typeof field.path === \"function\") {\n return field.path(term);\n } else if (field.systemField) {\n return field.path || field.field.storageId;\n }\n const path = `values.${field.path || field.field.storageId}`;\n /**\n * Searchable JSON fields are indexed as objects, so the actual searchable values\n * live on the nested keys. Target them all via 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","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;gBACxB,QAAQK,OAAO,MAAM,CAACH,QAAQ,GAAG,CAACC;gBAClC,OAAO,CAAC,CAAC,EAAEC,YAAYH,MAAM,CAAC,CAAC;gBAC/B,kBAAkB;YACtB;QACJ;IACJ;AACJ;AAMA,MAAMK,oBAAoB,CACtBP;IAEA,MAAM,EAAEQ,gBAAgB,EAAEC,KAAK,EAAE,GAAGT;IAIpC,MAAMU,WAAW;WAAIF;KAAiB,CAAC,OAAO;IAK9C,IAAIG,WAA8D;IAClE,KAAK,MAAMC,QAAQF,SAAU;QACzB,MAAMG,SAASD,KAAK,MAAM,IAAI,EAAE;QAIhC,IAAIC,OAAO,QAAQ,CAACJ,MAAM,OAAO,GAC7B,OAAOG;
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/fullTextSearch.js","sources":["../../../../src/operations/entry/elasticsearch/fullTextSearch.ts"],"sourcesContent":["import type { OpenSearchBoolQueryConfig } from \"@webiny/api-opensearch/types.js\";\nimport { normalizeValue } from \"@webiny/api-opensearch\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsEntryOpenSearchFullTextSearch } from \"~/features/CmsEntryOpenSearchFullTextSearch/index.js\";\nimport type { ModelFields } from \"~/operations/entry/elasticsearch/types.js\";\n\n/**\n * Our default implementation works with the AND operator for the multiple words query string.\n */\nconst defaultFullTextSearch: CmsEntryOpenSearchFullTextSearch.Interface = {\n apply: params => {\n const { query, term, fields, createFieldPath, prepareTerm } = params;\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: Object.values(fields).map(createFieldPath),\n query: `*${prepareTerm(term)}*`,\n default_operator: \"and\"\n }\n });\n }\n};\n\ninterface GetFullTextSearchParams {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n}\nconst getFullTextSearch = (\n params: GetFullTextSearchParams\n): CmsEntryOpenSearchFullTextSearch.Interface => {\n const { fullTextSearches, model } = params;\n /**\n * We need to reverse the list, so we can take the last one first - possibility to override existing implementations.\n */\n const reversed = [...fullTextSearches].reverse();\n /**\n * We need to find the most specific implementation for the given model.\n * Also, we need to use the first possible implementation if the specific one is not found.\n */\n let fallback: CmsEntryOpenSearchFullTextSearch.Interface | null = null;\n for (const item of reversed) {\n const models = item.models || [];\n /**\n * We take the first available implementation for the given model.\n */\n if (models.includes(model.modelId)) {\n return item;\n } else if (!fallback && models.length === 0) {\n /**\n * Then we set the first possible implementation, which has no models defined, as the default one.\n * It is important not to set the one which has models defined as they are specifically for the targeted model.\n */\n fallback = item;\n }\n }\n\n return fallback || defaultFullTextSearch;\n};\n\ninterface Params {\n fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];\n model: CmsModel;\n query: OpenSearchBoolQueryConfig;\n term?: string;\n fields: ModelFields;\n}\nexport const applyFullTextSearch = (params: Params): void => {\n const { fullTextSearches, query, term, fields, model } = params;\n const keys = Object.keys(fields);\n if (!term || term.length === 0 || keys.length === 0) {\n return;\n }\n\n const fullTextSearch = getFullTextSearch({\n fullTextSearches,\n model\n });\n\n fullTextSearch.apply({\n model,\n createFieldPath: field => {\n if (typeof field.path === \"function\") {\n return field.path(term);\n } else if (field.systemField) {\n return field.path || field.field.storageId;\n }\n const path = `values.${field.path || field.field.storageId}`;\n /**\n * Searchable JSON fields are indexed as objects, so the actual searchable values\n * live on the nested keys. Target them all via 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","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;gBACxB,QAAQK,OAAO,MAAM,CAACH,QAAQ,GAAG,CAACC;gBAClC,OAAO,CAAC,CAAC,EAAEC,YAAYH,MAAM,CAAC,CAAC;gBAC/B,kBAAkB;YACtB;QACJ;IACJ;AACJ;AAMA,MAAMK,oBAAoB,CACtBP;IAEA,MAAM,EAAEQ,gBAAgB,EAAEC,KAAK,EAAE,GAAGT;IAIpC,MAAMU,WAAW;WAAIF;KAAiB,CAAC,OAAO;IAK9C,IAAIG,WAA8D;IAClE,KAAK,MAAMC,QAAQF,SAAU;QACzB,MAAMG,SAASD,KAAK,MAAM,IAAI,EAAE;QAIhC,IAAIC,OAAO,QAAQ,CAACJ,MAAM,OAAO,GAC7B,OAAOG;QACJ,IAAI,CAACD,YAAYE,AAAkB,MAAlBA,OAAO,MAAM,EAKjCF,WAAWC;IAEnB;IAEA,OAAOD,YAAYZ;AACvB;AASO,MAAMe,sBAAsB,CAACd;IAChC,MAAM,EAAEQ,gBAAgB,EAAEP,KAAK,EAAEC,IAAI,EAAEC,MAAM,EAAEM,KAAK,EAAE,GAAGT;IACzD,MAAMe,OAAOT,OAAO,IAAI,CAACH;IACzB,IAAI,CAACD,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,IAAUa,AAAgB,MAAhBA,KAAK,MAAM,EACzC;IAGJ,MAAMC,iBAAiBT,kBAAkB;QACrCC;QACAC;IACJ;IAEAO,eAAe,KAAK,CAAC;QACjBP;QACA,iBAAiBQ,CAAAA;YACb,IAAI,AAAsB,cAAtB,OAAOA,MAAM,IAAI,EACjB,OAAOA,MAAM,IAAI,CAACf;YACf,IAAIe,MAAM,WAAW,EACxB,OAAOA,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS;YAE9C,MAAMC,OAAO,CAAC,OAAO,EAAED,MAAM,IAAI,IAAIA,MAAM,KAAK,CAAC,SAAS,EAAE;YAK5D,IAAIA,AAAe,sBAAfA,MAAM,IAAI,EACV,OAAO,GAAGC,KAAK,EAAE,CAAC;YAEtB,OAAOA;QACX;QACAf;QACAF;QACAC;QACA,aAAaiB;IACjB;AACJ"}
|
|
@@ -8,8 +8,8 @@ const noKeywordFields = [
|
|
|
8
8
|
const hasKeyword = (field)=>{
|
|
9
9
|
const fieldType = getBaseFieldType(field);
|
|
10
10
|
if (noKeywordFields.includes(fieldType)) return false;
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (field.unmappedType) return false;
|
|
12
|
+
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;IAMN,IAAID,MAAM,YAAY,EACvB,OAAO;IAMN,IAAIA,AAAkB,UAAlBA,MAAM,OAAO,EAClB,OAAO;IAKX,OAAO;AACX"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { OpenSearchQueryBuilderOperatorRegistry } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
2
|
+
import type { OpenSearchQueryBuilderOperators } from "../types.js";
|
|
3
3
|
interface Params {
|
|
4
|
-
|
|
4
|
+
registry: OpenSearchQueryBuilderOperatorRegistry.Interface;
|
|
5
5
|
}
|
|
6
|
-
export declare const createOperatorPluginList: (params: Params) =>
|
|
6
|
+
export declare const createOperatorPluginList: (params: Params) => OpenSearchQueryBuilderOperators;
|
|
7
7
|
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { OpenSearchQueryBuilderOperatorPlugin } from "@webiny/api-opensearch";
|
|
2
1
|
const createOperatorPluginList = (params)=>{
|
|
3
|
-
const {
|
|
4
|
-
return
|
|
5
|
-
|
|
6
|
-
if (!!acc[operator] && (plugin.name || "").match(/\.default$/)) return acc;
|
|
7
|
-
acc[operator] = plugin;
|
|
2
|
+
const { registry } = params;
|
|
3
|
+
return registry.getAll().reduce((acc, operator)=>{
|
|
4
|
+
acc[operator.getOperator()] = operator;
|
|
8
5
|
return acc;
|
|
9
6
|
}, {});
|
|
10
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/elasticsearch/plugins/operator.js","sources":["../../../../../src/operations/entry/elasticsearch/plugins/operator.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/plugins/operator.js","sources":["../../../../../src/operations/entry/elasticsearch/plugins/operator.ts"],"sourcesContent":["import type { OpenSearchQueryBuilderOperatorRegistry } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { OpenSearchQueryBuilderOperators } from \"../types.js\";\n\ninterface Params {\n registry: OpenSearchQueryBuilderOperatorRegistry.Interface;\n}\n\nexport const createOperatorPluginList = (params: Params): OpenSearchQueryBuilderOperators => {\n const { registry } = params;\n return registry.getAll().reduce<OpenSearchQueryBuilderOperators>((acc, operator) => {\n acc[operator.getOperator()] = operator;\n return acc;\n }, {});\n};\n"],"names":["createOperatorPluginList","params","registry","acc","operator"],"mappings":"AAOO,MAAMA,2BAA2B,CAACC;IACrC,MAAM,EAAEC,QAAQ,EAAE,GAAGD;IACrB,OAAOC,SAAS,MAAM,GAAG,MAAM,CAAkC,CAACC,KAAKC;QACnED,GAAG,CAACC,SAAS,WAAW,GAAG,GAAGA;QAC9B,OAAOD;IACX,GAAG,CAAC;AACR"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Sort as OpenSearchSort } from "@webiny/api-opensearch/types.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { OpenSearchFieldFactory } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
3
|
+
import type { CmsEntryListSort } from "@webiny/api-headless-cms/types/index.js";
|
|
4
|
+
import type { CmsModel } from "@webiny/api-headless-cms/types/index.js";
|
|
3
5
|
import type { ModelFields } from "./types.js";
|
|
4
6
|
import type { CmsEntryOpenSearchValueSearchRegistry } from "../../../features/CmsEntryOpenSearchValueSearch/index.js";
|
|
5
7
|
interface Params {
|
|
@@ -7,6 +9,7 @@ interface Params {
|
|
|
7
9
|
modelFields: ModelFields;
|
|
8
10
|
model: CmsModel;
|
|
9
11
|
valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;
|
|
12
|
+
fieldFactory: OpenSearchFieldFactory.Interface;
|
|
10
13
|
}
|
|
11
14
|
export declare const createElasticsearchSort: (params: Params) => OpenSearchSort;
|
|
12
15
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSort } from "@webiny/api-opensearch";
|
|
2
2
|
import { hasKeyword } from "./keyword.js";
|
|
3
3
|
import { createFieldPathFactory } from "./filtering/path.js";
|
|
4
4
|
import { NoValueContainer } from "../../../values/NoValueContainer.js";
|
|
@@ -22,7 +22,7 @@ const matchField = (input)=>{
|
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
const createElasticsearchSort = (params)=>{
|
|
25
|
-
const { sort, modelFields, valueSearchRegistry } = params;
|
|
25
|
+
const { sort, modelFields, valueSearchRegistry, fieldFactory } = params;
|
|
26
26
|
if (!sort || 0 === sort.length) return [
|
|
27
27
|
{
|
|
28
28
|
["id.keyword"]: {
|
|
@@ -47,7 +47,7 @@ const createElasticsearchSort = (params)=>{
|
|
|
47
47
|
keyword: false,
|
|
48
48
|
originalValue: NoValueContainer.create()
|
|
49
49
|
});
|
|
50
|
-
plugins[fieldIdPath] =
|
|
50
|
+
plugins[fieldIdPath] = fieldFactory.create({
|
|
51
51
|
unmappedType: field.unmappedType,
|
|
52
52
|
keyword: hasKeyword(field),
|
|
53
53
|
sortable: field.sortable,
|
|
@@ -57,8 +57,8 @@ const createElasticsearchSort = (params)=>{
|
|
|
57
57
|
});
|
|
58
58
|
return plugins;
|
|
59
59
|
}, {
|
|
60
|
-
["*"]:
|
|
61
|
-
field:
|
|
60
|
+
["*"]: fieldFactory.create({
|
|
61
|
+
field: "*",
|
|
62
62
|
keyword: false
|
|
63
63
|
})
|
|
64
64
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations/entry/elasticsearch/sort.js","sources":["../../../../src/operations/entry/elasticsearch/sort.ts"],"sourcesContent":["import type { Sort as OpenSearchSort } from \"@webiny/api-opensearch/types.js\";\nimport { createSort
|
|
1
|
+
{"version":3,"file":"operations/entry/elasticsearch/sort.js","sources":["../../../../src/operations/entry/elasticsearch/sort.ts"],"sourcesContent":["import type { Sort as OpenSearchSort } from \"@webiny/api-opensearch/types.js\";\nimport { createSort } from \"@webiny/api-opensearch\";\nimport type { OpenSearchField } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { OpenSearchFieldFactory } from \"@webiny/api-opensearch/exports/api/opensearch.js\";\nimport type { CmsEntryListSort } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { CmsModel } from \"@webiny/api-headless-cms/types/index.js\";\nimport type { ModelFields } from \"./types.js\";\nimport { hasKeyword } from \"~/operations/entry/elasticsearch/keyword.js\";\nimport { createFieldPathFactory } from \"~/operations/entry/elasticsearch/filtering/path.js\";\nimport { NoValueContainer } from \"~/values/NoValueContainer.js\";\nimport type { CmsEntryOpenSearchValueSearchRegistry } from \"~/features/CmsEntryOpenSearchValueSearch/index.js\";\n\ninterface IMatchFieldResponse {\n fieldId: string;\n isValues: boolean;\n order: \"ASC\" | \"DESC\";\n}\n\nconst matchField = (input: string): IMatchFieldResponse | null => {\n const valuesMatch = input.match(/^values_([a-zA-Z-0-9_]+)_(ASC|DESC)$/);\n if (valuesMatch) {\n const [, fieldId, order] = valuesMatch;\n return {\n fieldId,\n isValues: true,\n order: order as \"ASC\" | \"DESC\"\n };\n }\n const nonValues = input.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);\n if (!nonValues) {\n return null;\n }\n const [, fieldId, order] = nonValues;\n return {\n fieldId,\n isValues: false,\n order: order as \"ASC\" | \"DESC\"\n };\n};\n\ninterface Params {\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n model: CmsModel;\n valueSearchRegistry: CmsEntryOpenSearchValueSearchRegistry.Interface;\n fieldFactory: OpenSearchFieldFactory.Interface;\n}\n\nexport const createElasticsearchSort = (params: Params): OpenSearchSort => {\n const { sort, modelFields, valueSearchRegistry, fieldFactory } = params;\n\n if (!sort || sort.length === 0) {\n return [\n {\n [\"id.keyword\"]: {\n order: \"asc\"\n }\n }\n ];\n }\n\n const createFieldPath = createFieldPathFactory({\n valueSearchRegistry\n });\n\n const fieldIdToStorageIdIdMap: Record<string, string> = {};\n\n const sortPlugins = Object.values(modelFields).reduce<\n Record<string, OpenSearchField.Interface>\n >(\n (plugins, field) => {\n const isValues = field.parents.length === 1 && field.parents[0].fieldId === \"values\";\n if (field.parents.length > 0 && !isValues) {\n return plugins;\n }\n\n const fieldId = field.field.fieldId;\n const fieldIdPath = isValues ? `values.${fieldId}` : fieldId;\n\n fieldIdToStorageIdIdMap[fieldIdPath] = fieldIdPath;\n\n const { path } = createFieldPath({\n key: field.field.storageId,\n field,\n value: NoValueContainer.create(),\n keyword: false,\n originalValue: NoValueContainer.create()\n });\n plugins[fieldIdPath] = fieldFactory.create({\n unmappedType: field.unmappedType,\n keyword: hasKeyword(field),\n sortable: field.sortable,\n searchable: field.searchable,\n field: fieldId,\n path\n });\n return plugins;\n },\n {\n [\"*\"]: fieldFactory.create({\n field: \"*\",\n keyword: false\n })\n }\n );\n\n const transformedSort = sort\n .map(value => {\n const matched = matchField(value);\n if (!matched) {\n return null;\n }\n const { fieldId, order, isValues } = matched;\n const key = isValues ? `values.${fieldId}` : fieldId;\n if (fieldIdToStorageIdIdMap[key]) {\n return `${fieldIdToStorageIdIdMap[key]}_${order}`;\n }\n\n return value;\n })\n .filter(Boolean) as string[];\n return createSort({\n fieldPlugins: sortPlugins,\n sort: transformedSort\n });\n};\n"],"names":["matchField","input","valuesMatch","fieldId","order","nonValues","createElasticsearchSort","params","sort","modelFields","valueSearchRegistry","fieldFactory","createFieldPath","createFieldPathFactory","fieldIdToStorageIdIdMap","sortPlugins","Object","plugins","field","isValues","fieldIdPath","path","NoValueContainer","hasKeyword","transformedSort","value","matched","key","Boolean","createSort"],"mappings":";;;;AAkBA,MAAMA,aAAa,CAACC;IAChB,MAAMC,cAAcD,MAAM,KAAK,CAAC;IAChC,IAAIC,aAAa;QACb,MAAM,GAAGC,SAASC,MAAM,GAAGF;QAC3B,OAAO;YACHC;YACA,UAAU;YACV,OAAOC;QACX;IACJ;IACA,MAAMC,YAAYJ,MAAM,KAAK,CAAC;IAC9B,IAAI,CAACI,WACD,OAAO;IAEX,MAAM,GAAGF,SAASC,MAAM,GAAGC;IAC3B,OAAO;QACHF;QACA,UAAU;QACV,OAAOC;IACX;AACJ;AAUO,MAAME,0BAA0B,CAACC;IACpC,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAEC,mBAAmB,EAAEC,YAAY,EAAE,GAAGJ;IAEjE,IAAI,CAACC,QAAQA,AAAgB,MAAhBA,KAAK,MAAM,EACpB,OAAO;QACH;YACI,CAAC,aAAa,EAAE;gBACZ,OAAO;YACX;QACJ;KACH;IAGL,MAAMI,kBAAkBC,uBAAuB;QAC3CH;IACJ;IAEA,MAAMI,0BAAkD,CAAC;IAEzD,MAAMC,cAAcC,OAAO,MAAM,CAACP,aAAa,MAAM,CAGjD,CAACQ,SAASC;QACN,MAAMC,WAAWD,AAAyB,MAAzBA,MAAM,OAAO,CAAC,MAAM,IAAUA,AAA6B,aAA7BA,MAAM,OAAO,CAAC,EAAE,CAAC,OAAO;QACvE,IAAIA,MAAM,OAAO,CAAC,MAAM,GAAG,KAAK,CAACC,UAC7B,OAAOF;QAGX,MAAMd,UAAUe,MAAM,KAAK,CAAC,OAAO;QACnC,MAAME,cAAcD,WAAW,CAAC,OAAO,EAAEhB,SAAS,GAAGA;QAErDW,uBAAuB,CAACM,YAAY,GAAGA;QAEvC,MAAM,EAAEC,IAAI,EAAE,GAAGT,gBAAgB;YAC7B,KAAKM,MAAM,KAAK,CAAC,SAAS;YAC1BA;YACA,OAAOI,iBAAiB,MAAM;YAC9B,SAAS;YACT,eAAeA,iBAAiB,MAAM;QAC1C;QACAL,OAAO,CAACG,YAAY,GAAGT,aAAa,MAAM,CAAC;YACvC,cAAcO,MAAM,YAAY;YAChC,SAASK,WAAWL;YACpB,UAAUA,MAAM,QAAQ;YACxB,YAAYA,MAAM,UAAU;YAC5B,OAAOf;YACPkB;QACJ;QACA,OAAOJ;IACX,GACA;QACI,CAAC,IAAI,EAAEN,aAAa,MAAM,CAAC;YACvB,OAAO;YACP,SAAS;QACb;IACJ;IAGJ,MAAMa,kBAAkBhB,KACnB,GAAG,CAACiB,CAAAA;QACD,MAAMC,UAAU1B,WAAWyB;QAC3B,IAAI,CAACC,SACD,OAAO;QAEX,MAAM,EAAEvB,OAAO,EAAEC,KAAK,EAAEe,QAAQ,EAAE,GAAGO;QACrC,MAAMC,MAAMR,WAAW,CAAC,OAAO,EAAEhB,SAAS,GAAGA;QAC7C,IAAIW,uBAAuB,CAACa,IAAI,EAC5B,OAAO,GAAGb,uBAAuB,CAACa,IAAI,CAAC,CAAC,EAAEvB,OAAO;QAGrD,OAAOqB;IACX,GACC,MAAM,CAACG;IACZ,OAAOC,WAAW;QACd,cAAcd;QACd,MAAMS;IACV;AACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OpenSearchQueryBuilderOperator } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
2
2
|
import type { CmsModelField } from "@webiny/api-headless-cms/types/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* ./fields
|
|
@@ -25,10 +25,7 @@ export interface ModelField {
|
|
|
25
25
|
export interface ModelFields {
|
|
26
26
|
[fieldId: string]: ModelField;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*/
|
|
31
|
-
export interface OpenSearchQueryBuilderOperatorPlugins {
|
|
32
|
-
[key: string]: OpenSearchQueryBuilderOperatorPlugin;
|
|
28
|
+
export interface OpenSearchQueryBuilderOperators {
|
|
29
|
+
[key: string]: OpenSearchQueryBuilderOperator.Interface;
|
|
33
30
|
}
|
|
34
31
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Debugger } from "@webiny/api-core/features/debugger/index.js";
|
|
2
|
-
import "~/debuggerNamespaces.js";
|
|
3
1
|
import type { Configurations } from "../../configurations.js";
|
|
4
2
|
import type { Client } from "@webiny/api-opensearch";
|
|
5
3
|
import { type IOpenSearchEntity as IElasticsearchEntity } from "@webiny/api-opensearch";
|
|
6
4
|
import type { PluginsContainer } from "@webiny/plugins";
|
|
5
|
+
import type { OpenSearchQueryBuilderOperatorRegistry } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
6
|
+
import type { OpenSearchFieldFactory } from "@webiny/api-opensearch/exports/api/opensearch.js";
|
|
7
7
|
import type { CmsEntryStorageOperations } from "../../types.js";
|
|
8
8
|
import type { IEntryEntity } from "../../definitions/types.js";
|
|
9
9
|
import type { CmsModelFieldToGraphQLRegistry } from "@webiny/api-headless-cms/exports/api/cms/graphql.js";
|
|
@@ -22,6 +22,7 @@ export interface CreateEntriesStorageOperationsParams {
|
|
|
22
22
|
elasticsearch: Client;
|
|
23
23
|
plugins: PluginsContainer;
|
|
24
24
|
configurations: Configurations;
|
|
25
|
+
operatorRegistry: OpenSearchQueryBuilderOperatorRegistry.Interface;
|
|
25
26
|
fieldRegistry: CmsModelFieldToGraphQLRegistry.Interface;
|
|
26
27
|
fieldIndexRegistry: CmsEntryOpenSearchFieldIndexRegistry.Interface;
|
|
27
28
|
compressionHandler: CompressionHandler.Interface;
|
|
@@ -32,6 +33,6 @@ export interface CreateEntriesStorageOperationsParams {
|
|
|
32
33
|
fullTextSearches: CmsEntryOpenSearchFullTextSearch.Interface[];
|
|
33
34
|
valuesModifiers: CmsEntryOpenSearchValuesModifier.Interface[];
|
|
34
35
|
filterRegistry: CmsEntryOpenSearchFilterRegistry.Interface;
|
|
35
|
-
|
|
36
|
+
fieldFactory: OpenSearchFieldFactory.Interface;
|
|
36
37
|
}
|
|
37
38
|
export declare const createEntriesStorageOperations: (params: CreateEntriesStorageOperationsParams) => CmsEntryStorageOperations;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { WebinyError } from "@webiny/error";
|
|
2
|
-
import "../../debuggerNamespaces.js";
|
|
3
2
|
import { CONTENT_ENTRY_STATUS } from "@webiny/api-headless-cms/types/index.js";
|
|
4
3
|
import { extractEntriesFromIndex } from "../../helpers/index.js";
|
|
5
4
|
import { createLimit, decodeCursor, encodeCursor } from "@webiny/api-opensearch";
|
|
@@ -24,7 +23,7 @@ const convertToStorageEntry = (params)=>{
|
|
|
24
23
|
};
|
|
25
24
|
};
|
|
26
25
|
const createEntriesStorageOperations = (params)=>{
|
|
27
|
-
const { entity, esEntity, elasticsearch, plugins, configurations, fieldRegistry, fieldIndexRegistry, compressionHandler, bodyModifiers, sortModifiers, queryModifiers, valueSearchRegistry, fullTextSearches, valuesModifiers, filterRegistry,
|
|
26
|
+
const { entity, esEntity, elasticsearch, plugins, configurations, operatorRegistry, fieldRegistry, fieldIndexRegistry, compressionHandler, bodyModifiers, sortModifiers, queryModifiers, valueSearchRegistry, fullTextSearches, valuesModifiers, filterRegistry, fieldFactory } = params;
|
|
28
27
|
let storageOperationsCmsModelPlugin;
|
|
29
28
|
const getStorageOperationsCmsModelPlugin = ()=>{
|
|
30
29
|
if (storageOperationsCmsModelPlugin) return storageOperationsCmsModelPlugin;
|
|
@@ -349,6 +348,40 @@ const createEntriesStorageOperations = (params)=>{
|
|
|
349
348
|
}
|
|
350
349
|
return initialStorageEntry;
|
|
351
350
|
};
|
|
351
|
+
const updateRevision = async (initialModel, params)=>{
|
|
352
|
+
const { entry: initialEntry, storageEntry: initialStorageEntry } = params;
|
|
353
|
+
const model = getStorageOperationsModel(initialModel);
|
|
354
|
+
const transformer = createTransformer({
|
|
355
|
+
valuesModifiers,
|
|
356
|
+
model,
|
|
357
|
+
entry: initialEntry,
|
|
358
|
+
storageEntry: initialStorageEntry,
|
|
359
|
+
fieldIndexRegistry,
|
|
360
|
+
compressionHandler
|
|
361
|
+
});
|
|
362
|
+
const { storageEntry } = transformer.transformEntryKeys();
|
|
363
|
+
const revisionKeys = createEntryRevisionKeys(storageEntry);
|
|
364
|
+
const entityBatch = entity.createEntityWriter({
|
|
365
|
+
put: [
|
|
366
|
+
{
|
|
367
|
+
...revisionKeys,
|
|
368
|
+
data: storageEntry
|
|
369
|
+
}
|
|
370
|
+
]
|
|
371
|
+
});
|
|
372
|
+
try {
|
|
373
|
+
await entityBatch.execute();
|
|
374
|
+
dataLoaders.clearAll({
|
|
375
|
+
tenant: initialEntry.tenant
|
|
376
|
+
});
|
|
377
|
+
return initialStorageEntry;
|
|
378
|
+
} catch (ex) {
|
|
379
|
+
throw new WebinyError(ex.message || "Could not update revision.", ex.code || "UPDATE_REVISION_ERROR", {
|
|
380
|
+
error: ex,
|
|
381
|
+
entry: initialEntry
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
};
|
|
352
385
|
const move = async (initialModel, id, folderId)=>{
|
|
353
386
|
const model = getStorageOperationsModel(initialModel);
|
|
354
387
|
const partitionKey = createPartitionKey({
|
|
@@ -832,34 +865,21 @@ const createEntriesStorageOperations = (params)=>{
|
|
|
832
865
|
valueSearchRegistry,
|
|
833
866
|
fullTextSearches,
|
|
834
867
|
filterRegistry,
|
|
868
|
+
fieldFactory,
|
|
835
869
|
params: {
|
|
836
870
|
...params,
|
|
837
871
|
limit,
|
|
838
872
|
after: decodeCursor(params.after)
|
|
839
873
|
},
|
|
840
|
-
|
|
874
|
+
operatorRegistry
|
|
841
875
|
});
|
|
842
876
|
let response;
|
|
843
|
-
const startedAt = Date.now();
|
|
844
877
|
try {
|
|
845
878
|
response = await elasticsearch.search({
|
|
846
879
|
index,
|
|
847
880
|
body
|
|
848
881
|
});
|
|
849
|
-
debuggerService.log("cms.os.list", ()=>({
|
|
850
|
-
index,
|
|
851
|
-
query: body,
|
|
852
|
-
body: response.body,
|
|
853
|
-
statusCode: response.statusCode,
|
|
854
|
-
tookMs: Date.now() - startedAt
|
|
855
|
-
}));
|
|
856
882
|
} catch (error) {
|
|
857
|
-
debuggerService.log("cms.os.list", ()=>({
|
|
858
|
-
index,
|
|
859
|
-
query: body,
|
|
860
|
-
error,
|
|
861
|
-
tookMs: Date.now() - startedAt
|
|
862
|
-
}));
|
|
863
883
|
if (shouldIgnoreEsResponseError(error)) return {
|
|
864
884
|
hasMoreItems: false,
|
|
865
885
|
totalCount: 0,
|
|
@@ -1305,11 +1325,12 @@ const createEntriesStorageOperations = (params)=>{
|
|
|
1305
1325
|
valueSearchRegistry,
|
|
1306
1326
|
fullTextSearches,
|
|
1307
1327
|
filterRegistry,
|
|
1328
|
+
fieldFactory,
|
|
1308
1329
|
params: {
|
|
1309
1330
|
limit: 1,
|
|
1310
1331
|
where
|
|
1311
1332
|
},
|
|
1312
|
-
|
|
1333
|
+
operatorRegistry
|
|
1313
1334
|
});
|
|
1314
1335
|
const field = model.fields.find((f)=>f.fieldId === fieldId);
|
|
1315
1336
|
if (!field) throw new WebinyError('Could not find field with given "fieldId" value.', "FIELD_NOT_FOUND", {
|
|
@@ -1354,6 +1375,7 @@ const createEntriesStorageOperations = (params)=>{
|
|
|
1354
1375
|
create,
|
|
1355
1376
|
createRevisionFrom,
|
|
1356
1377
|
update,
|
|
1378
|
+
updateRevision,
|
|
1357
1379
|
move,
|
|
1358
1380
|
delete: deleteEntry,
|
|
1359
1381
|
moveToBin,
|