@webiny/api-headless-cms-ddb-es 5.32.0 → 5.33.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/dynamoDb/index.js +4 -6
- package/dynamoDb/index.js.map +1 -1
- package/dynamoDb/storage/date.d.ts +1 -2
- package/dynamoDb/storage/date.js +78 -44
- package/dynamoDb/storage/date.js.map +1 -1
- package/dynamoDb/storage/longText.d.ts +6 -3
- package/dynamoDb/storage/longText.js +68 -55
- package/dynamoDb/storage/longText.js.map +1 -1
- package/dynamoDb/storage/richText.d.ts +1 -2
- package/dynamoDb/storage/richText.js +70 -72
- package/dynamoDb/storage/richText.js.map +1 -1
- package/elasticsearch/indexing/dateTimeIndexing.js +14 -0
- package/elasticsearch/indexing/dateTimeIndexing.js.map +1 -1
- package/elasticsearch/indexing/objectIndexing.d.ts +9 -0
- package/elasticsearch/indexing/objectIndexing.js +16 -7
- package/elasticsearch/indexing/objectIndexing.js.map +1 -1
- package/elasticsearch/search/refSearch.js +2 -2
- package/elasticsearch/search/refSearch.js.map +1 -1
- package/helpers/createElasticsearchQueryBody.js +74 -15
- package/helpers/createElasticsearchQueryBody.js.map +1 -1
- package/helpers/entryIndexHelpers.js +8 -8
- package/helpers/entryIndexHelpers.js.map +1 -1
- package/helpers/fields.d.ts +3 -1
- package/helpers/fields.js +27 -5
- package/helpers/fields.js.map +1 -1
- package/operations/entry/index.js +221 -59
- package/operations/entry/index.js.map +1 -1
- package/operations/model/index.js +2 -2
- package/operations/model/index.js.map +1 -1
- package/package.json +14 -14
- package/operations/entry/fields.d.ts +0 -3
- package/operations/entry/fields.js +0 -69
- package/operations/entry/fields.js.map +0 -1
|
@@ -71,6 +71,14 @@ var _default = () => ({
|
|
|
71
71
|
field,
|
|
72
72
|
value
|
|
73
73
|
}) {
|
|
74
|
+
if (Array.isArray(value) === true) {
|
|
75
|
+
return {
|
|
76
|
+
value: value.map(v => {
|
|
77
|
+
return convertValueToIndex(v, field);
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
74
82
|
const dateValue = convertValueToIndex(value, field);
|
|
75
83
|
return {
|
|
76
84
|
value: dateValue
|
|
@@ -81,6 +89,12 @@ var _default = () => ({
|
|
|
81
89
|
field,
|
|
82
90
|
value
|
|
83
91
|
}) {
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
return value.map(v => {
|
|
94
|
+
return convertValueFromIndex(v, field);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
84
98
|
return convertValueFromIndex(value, field);
|
|
85
99
|
}
|
|
86
100
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["convertTimeToNumber","time","hours","minutes","seconds","split","map","Number","convertNumberToTime","value","undefined","String","match","Math","floor","v","padStart","join","convertValueFromIndex","field","type","settings","dateValue","Date","toISOString","slice","convertValueToIndex","name","fieldType","unmappedType","toIndex","fromIndex"],"sources":["dateTimeIndexing.ts"],"sourcesContent":["import { CmsModelDateTimeField } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\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 // TODO remove when v5 goes out\n // this is a fix for pre beta.5\n if (String(value).match(/^([0-9]{2}):([0-9]{2})/) !== null) {\n return String(value);\n }\n //\n const hours = Math.floor(value / 60 / 60);\n\n const minutes = Math.floor((value - hours * 60 * 60) / 60);\n\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 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\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\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-datetime\",\n fieldType: \"datetime\",\n unmappedType: () => {\n return \"date\";\n },\n toIndex({ field, value }) {\n const dateValue = convertValueToIndex(value, field as CmsModelDateTimeField);\n return {\n value: dateValue\n };\n },\n fromIndex({ field, value }) {\n return convertValueFromIndex(value, field as CmsModelDateTimeField);\n }\n});\n"],"mappings":";;;;;;;AAGA,MAAMA,mBAAmB,GAAIC,IAAD,IAAkC;EAC1D,IAAI,CAACA,IAAL,EAAW;IACP,OAAO,IAAP;EACH;;EACD,MAAM,CAACC,KAAD,EAAQC,OAAR,EAAiBC,OAAO,GAAG,CAA3B,IAAgCH,IAAI,CAACI,KAAL,CAAW,GAAX,EAAgBC,GAAhB,CAAoBC,MAApB,CAAtC;EACA,OAAOL,KAAK,GAAG,EAAR,GAAa,EAAb,GAAkBC,OAAO,GAAG,EAA5B,GAAiCC,OAAxC;AACH,CAND;;AAQA,MAAMI,mBAAmB,GAAIC,KAAD,IAAmC;EAC3D,IAAIA,KAAK,KAAKC,SAAV,IAAuBD,KAAK,KAAK,IAArC,EAA2C;IACvC,OAAO,IAAP;EACH,CAH0D,CAI3D;EACA;;;EACA,IAAIE,MAAM,CAACF,KAAD,CAAN,CAAcG,KAAd,CAAoB,wBAApB,MAAkD,IAAtD,EAA4D;IACxD,OAAOD,MAAM,CAACF,KAAD,CAAb;EACH,CAR0D,CAS3D;;;EACA,MAAMP,KAAK,GAAGW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IAAP;EACH,CAFD,MAEO,IAAIU,KAAK,CAACE,QAAN,CAAeD,IAAf,KAAwB,MAA5B,EAAoC;IACvC,OAAOpB,mBAAmB,CAACS,KAAD,CAA1B;EACH;;EACD,OAAOA,KAAP;AACH,CAPD;;eASe,OAA2C;EACtDW,IAAI,EAAE,mCADgD;EAEtDO,IAAI,EAAE,4CAFgD;EAGtDC,SAAS,EAAE,UAH2C;EAItDC,YAAY,EAAE,MAAM;IAChB,OAAO,MAAP;EACH,CANqD;;EAOtDC,OAAO,CAAC;IAAEX,KAAF;IAASV;EAAT,CAAD,EAAmB;IACtB,
|
|
1
|
+
{"version":3,"names":["convertTimeToNumber","time","hours","minutes","seconds","split","map","Number","convertNumberToTime","value","undefined","String","match","Math","floor","v","padStart","join","convertValueFromIndex","field","type","settings","dateValue","Date","toISOString","slice","convertValueToIndex","name","fieldType","unmappedType","toIndex","Array","isArray","fromIndex"],"sources":["dateTimeIndexing.ts"],"sourcesContent":["import { CmsModelDateTimeField } from \"@webiny/api-headless-cms/types\";\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\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 // TODO remove when v5 goes out\n // this is a fix for pre beta.5\n if (String(value).match(/^([0-9]{2}):([0-9]{2})/) !== null) {\n return String(value);\n }\n //\n const hours = Math.floor(value / 60 / 60);\n\n const minutes = Math.floor((value - hours * 60 * 60) / 60);\n\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 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\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\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-datetime\",\n fieldType: \"datetime\",\n unmappedType: () => {\n return \"date\";\n },\n toIndex({ field, value }) {\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 const dateValue = convertValueToIndex(value, field as CmsModelDateTimeField);\n return {\n value: dateValue\n };\n },\n fromIndex({ field, value }) {\n if (Array.isArray(value)) {\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"],"mappings":";;;;;;;AAGA,MAAMA,mBAAmB,GAAIC,IAAD,IAAkC;EAC1D,IAAI,CAACA,IAAL,EAAW;IACP,OAAO,IAAP;EACH;;EACD,MAAM,CAACC,KAAD,EAAQC,OAAR,EAAiBC,OAAO,GAAG,CAA3B,IAAgCH,IAAI,CAACI,KAAL,CAAW,GAAX,EAAgBC,GAAhB,CAAoBC,MAApB,CAAtC;EACA,OAAOL,KAAK,GAAG,EAAR,GAAa,EAAb,GAAkBC,OAAO,GAAG,EAA5B,GAAiCC,OAAxC;AACH,CAND;;AAQA,MAAMI,mBAAmB,GAAIC,KAAD,IAAmC;EAC3D,IAAIA,KAAK,KAAKC,SAAV,IAAuBD,KAAK,KAAK,IAArC,EAA2C;IACvC,OAAO,IAAP;EACH,CAH0D,CAI3D;EACA;;;EACA,IAAIE,MAAM,CAACF,KAAD,CAAN,CAAcG,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O remove rawValue when field aliases and field types targeting will be active.
|
|
3
|
+
*
|
|
4
|
+
* Currently we use rawValue for the values that we do not want to be indexed.
|
|
5
|
+
* When field aliases and types in the value path will be active, we can target the keys directly.
|
|
6
|
+
*
|
|
7
|
+
* This change will be incompatible with the current systems so we will need to release a major version.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
1
10
|
import { CmsModelFieldToElasticsearchPlugin } from "../../types";
|
|
2
11
|
declare const _default: () => CmsModelFieldToElasticsearchPlugin;
|
|
3
12
|
export default _default;
|
|
@@ -5,6 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* TODO remove rawValue when field aliases and field types targeting will be active.
|
|
10
|
+
*
|
|
11
|
+
* Currently we use rawValue for the values that we do not want to be indexed.
|
|
12
|
+
* When field aliases and types in the value path will be active, we can target the keys directly.
|
|
13
|
+
*
|
|
14
|
+
* This change will be incompatible with the current systems so we will need to release a major version.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
8
17
|
const processToIndex = ({
|
|
9
18
|
fields,
|
|
10
19
|
value: sourceValue,
|
|
@@ -27,19 +36,19 @@ const processToIndex = ({
|
|
|
27
36
|
} = plugin.toIndex({
|
|
28
37
|
model,
|
|
29
38
|
field,
|
|
30
|
-
value: sourceValue[field.
|
|
31
|
-
rawValue: sourceRawValue[field.
|
|
39
|
+
value: sourceValue[field.storageId],
|
|
40
|
+
rawValue: sourceRawValue[field.storageId],
|
|
32
41
|
getFieldIndexPlugin,
|
|
33
42
|
getFieldTypePlugin,
|
|
34
43
|
plugins
|
|
35
44
|
});
|
|
36
45
|
|
|
37
46
|
if (value !== undefined) {
|
|
38
|
-
values.value[field.
|
|
47
|
+
values.value[field.storageId] = value;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
if (rawValue !== undefined) {
|
|
42
|
-
values.rawValue[field.
|
|
51
|
+
values.rawValue[field.storageId] = rawValue;
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
return values;
|
|
@@ -71,14 +80,14 @@ const processFromIndex = ({
|
|
|
71
80
|
plugins,
|
|
72
81
|
model,
|
|
73
82
|
field,
|
|
74
|
-
value: sourceValue[field.
|
|
75
|
-
rawValue: sourceRawValue[field.
|
|
83
|
+
value: sourceValue[field.storageId],
|
|
84
|
+
rawValue: sourceRawValue[field.storageId],
|
|
76
85
|
getFieldIndexPlugin,
|
|
77
86
|
getFieldTypePlugin
|
|
78
87
|
});
|
|
79
88
|
|
|
80
89
|
if (value !== undefined) {
|
|
81
|
-
values[field.
|
|
90
|
+
values[field.storageId] = value;
|
|
82
91
|
}
|
|
83
92
|
|
|
84
93
|
return values;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["processToIndex","fields","value","sourceValue","rawValue","sourceRawValue","getFieldIndexPlugin","getFieldTypePlugin","plugins","model","reducer","values","field","plugin","type","toIndex","fieldId","undefined","reduce","processFromIndex","fromIndex","name","fieldType","initialValue","initialRawValue","settings","multipleValues","result","key","Object","keys","length","push","source","map","_","index"],"sources":["objectIndexing.ts"],"sourcesContent":["import { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin\n} from \"@webiny/api-headless-cms/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface ProcessToIndex {\n (params: {\n fields: CmsModelField[];\n value: Record<string, any>;\n rawValue: Record<string, any>;\n getFieldIndexPlugin: (fieldType: string) => CmsModelFieldToElasticsearchPlugin;\n getFieldTypePlugin: (fieldType: string) => CmsModelFieldToGraphQLPlugin;\n plugins: PluginsContainer;\n model: CmsModel;\n }): Record<\"value\" | \"rawValue\", Record<string, any>>;\n}\n\ninterface ProcessFromIndex {\n (params: {\n fields: CmsModelField[];\n value: Record<string, any>;\n rawValue: Record<string, any>;\n getFieldIndexPlugin: (fieldType: string) => CmsModelFieldToElasticsearchPlugin;\n getFieldTypePlugin: (fieldType: string) => CmsModelFieldToGraphQLPlugin;\n plugins: PluginsContainer;\n model: CmsModel;\n }): Record<string, any>;\n}\n\ninterface ReducerValue {\n value: {\n [key: string]: string;\n };\n rawValue: {\n [key: string]: string;\n };\n}\n\nconst processToIndex: ProcessToIndex = ({\n fields,\n value: sourceValue,\n rawValue: sourceRawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n plugins,\n model\n}) => {\n const reducer = (values: ReducerValue, field: CmsModelField) => {\n const plugin = getFieldIndexPlugin(field.type);\n if (!plugin || !plugin.toIndex) {\n return values;\n }\n const { value, rawValue } = plugin.toIndex({\n model,\n field,\n value: sourceValue[field.fieldId],\n rawValue: sourceRawValue[field.fieldId],\n getFieldIndexPlugin,\n getFieldTypePlugin,\n plugins\n });\n\n if (value !== undefined) {\n values.value[field.fieldId] = value;\n }\n\n if (rawValue !== undefined) {\n values.rawValue[field.fieldId] = rawValue;\n }\n\n return values;\n };\n\n return fields.reduce(reducer, { value: {}, rawValue: {} });\n};\nconst processFromIndex: ProcessFromIndex = ({\n fields,\n value: sourceValue,\n rawValue: sourceRawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n plugins,\n model\n}) => {\n const reducer = (values: Record<string, string>, field: CmsModelField) => {\n const plugin = getFieldIndexPlugin(field.type);\n if (!plugin || !plugin.fromIndex) {\n return values;\n }\n const value = plugin.fromIndex({\n plugins,\n model,\n field,\n value: sourceValue[field.fieldId],\n rawValue: sourceRawValue[field.fieldId],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (value !== undefined) {\n values[field.fieldId] = value;\n }\n\n return values;\n };\n\n return fields.reduce(reducer, {});\n};\n\ninterface ToIndexMultipleFieldValue {\n value: Record<string, string>[];\n rawValue: Record<string, string>[];\n}\n\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-object\",\n fieldType: \"object\",\n toIndex({\n plugins,\n model,\n field,\n value: initialValue,\n rawValue: initialRawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin\n }) {\n if (!initialValue) {\n return { value: null };\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n /**\n * In \"object\" field, value is either an object or an array of objects.\n */\n if (field.multipleValues) {\n const result: ToIndexMultipleFieldValue = {\n value: [],\n rawValue: []\n };\n for (const key in initialValue) {\n const { value, rawValue } = processToIndex({\n value: initialValue[key],\n rawValue: initialRawValue[key],\n getFieldIndexPlugin,\n getFieldTypePlugin,\n model,\n plugins,\n fields\n });\n if (Object.keys(value).length > 0) {\n result.value.push(value);\n }\n\n if (Object.keys(rawValue).length > 0) {\n result.rawValue.push(rawValue);\n }\n }\n\n return {\n value: result.value.length > 0 ? result.value : undefined,\n rawValue: result.rawValue.length > 0 ? result.rawValue : undefined\n };\n }\n\n return processToIndex({\n value: initialValue,\n rawValue: initialRawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n model,\n plugins,\n fields\n });\n },\n fromIndex({ field, value, rawValue, model, plugins, getFieldIndexPlugin, getFieldTypePlugin }) {\n if (!value) {\n return null;\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n /**\n * In \"object\" field, value is either an object or an array of objects.\n */\n if (field.multipleValues) {\n /**\n * Why this `value || rawValue || []`?\n * It's possible that an object contains all non-indexable fields, or vice-versa, and so\n * we can never be sure which array we can reliably use as a source of values.\n */\n const source = value || rawValue || [];\n\n return source.map((_: any, index: number) =>\n processFromIndex({\n value: value ? value[index] || {} : {},\n rawValue: rawValue ? rawValue[index] || {} : {},\n getFieldIndexPlugin,\n getFieldTypePlugin,\n model,\n plugins,\n fields\n })\n );\n }\n\n return processFromIndex({\n value,\n rawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n model,\n plugins,\n fields\n });\n }\n});\n"],"mappings":";;;;;;;AAyCA,MAAMA,cAA8B,GAAG,CAAC;EACpCC,MADoC;EAEpCC,KAAK,EAAEC,WAF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AED,MAAMD,MAAM,GAAI,qBAAAW,KAAK,CAACa,QAAN,sEAAgBxB,MAAhB,KAA0B,EAA1C;IAEA;AACR;AACA;;IACQ,IAAIW,KAAK,CAACc,cAAV,EAA0B;MACtB;AACZ;AACA;AACA;AACA;MACY,MAAMO,MAAM,GAAG/B,KAAK,IAAIE,QAAT,IAAqB,EAApC;MAEA,OAAO6B,MAAM,CAACC,GAAP,CAAW,CAACC,CAAD,EAASC,KAAT,KACdjB,gBAAgB,CAAC;QACbjB,KAAK,EAAEA,KAAK,GAAGA,KAAK,CAACkC,KAAD,CAAL,IAAgB,EAAnB,GAAwB,EADvB;QAEbhC,QAAQ,EAAEA,QAAQ,GAAGA,QAAQ,CAACgC,KAAD,CAAR,IAAmB,EAAtB,GAA2B,EAFhC;QAGb9B,mBAHa;QAIbC,kBAJa;QAKbE,KALa;QAMbD,OANa;QAObP;MAPa,CAAD,CADb,CAAP;IAWH;;IAED,OAAOkB,gBAAgB,CAAC;MACpBjB,KADoB;MAEpBE,QAFoB;MAGpBE,mBAHoB;MAIpBC,kBAJoB;MAKpBE,KALoB;MAMpBD,OANoB;MAOpBP;IAPoB,CAAD,CAAvB;EASH;;AAtGqD,CAA3C,C"}
|
|
1
|
+
{"version":3,"names":["processToIndex","fields","value","sourceValue","rawValue","sourceRawValue","getFieldIndexPlugin","getFieldTypePlugin","plugins","model","reducer","values","field","plugin","type","toIndex","storageId","undefined","reduce","processFromIndex","fromIndex","name","fieldType","initialValue","initialRawValue","settings","multipleValues","result","key","Object","keys","length","push","source","map","_","index"],"sources":["objectIndexing.ts"],"sourcesContent":["/**\n * TODO remove rawValue when field aliases and field types targeting will be active.\n *\n * Currently we use rawValue for the values that we do not want to be indexed.\n * When field aliases and types in the value path will be active, we can target the keys directly.\n *\n * This change will be incompatible with the current systems so we will need to release a major version.\n *\n */\n\nimport { CmsModelFieldToElasticsearchPlugin } from \"~/types\";\nimport {\n CmsModel,\n CmsModelField,\n CmsModelFieldToGraphQLPlugin\n} from \"@webiny/api-headless-cms/types\";\nimport { PluginsContainer } from \"@webiny/plugins\";\n\ninterface ProcessToIndex {\n (params: {\n fields: CmsModelField[];\n value: Record<string, any>;\n rawValue: Record<string, any>;\n getFieldIndexPlugin: (fieldType: string) => CmsModelFieldToElasticsearchPlugin;\n getFieldTypePlugin: (fieldType: string) => CmsModelFieldToGraphQLPlugin;\n plugins: PluginsContainer;\n model: CmsModel;\n }): Record<\"value\" | \"rawValue\", Record<string, any>>;\n}\n\ninterface ProcessFromIndex {\n (params: {\n fields: CmsModelField[];\n value: Record<string, any>;\n rawValue: Record<string, any>;\n getFieldIndexPlugin: (fieldType: string) => CmsModelFieldToElasticsearchPlugin;\n getFieldTypePlugin: (fieldType: string) => CmsModelFieldToGraphQLPlugin;\n plugins: PluginsContainer;\n model: CmsModel;\n }): Record<string, any>;\n}\n\ninterface ReducerValue {\n value: {\n [key: string]: string;\n };\n rawValue: {\n [key: string]: string;\n };\n}\n\nconst processToIndex: ProcessToIndex = ({\n fields,\n value: sourceValue,\n rawValue: sourceRawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n plugins,\n model\n}) => {\n const reducer = (values: ReducerValue, field: CmsModelField) => {\n const plugin = getFieldIndexPlugin(field.type);\n if (!plugin || !plugin.toIndex) {\n return values;\n }\n const { value, rawValue } = plugin.toIndex({\n model,\n field,\n value: sourceValue[field.storageId],\n rawValue: sourceRawValue[field.storageId],\n getFieldIndexPlugin,\n getFieldTypePlugin,\n plugins\n });\n\n if (value !== undefined) {\n values.value[field.storageId] = value;\n }\n if (rawValue !== undefined) {\n values.rawValue[field.storageId] = rawValue;\n }\n\n return values;\n };\n\n return fields.reduce(reducer, { value: {}, rawValue: {} });\n};\nconst processFromIndex: ProcessFromIndex = ({\n fields,\n value: sourceValue,\n rawValue: sourceRawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n plugins,\n model\n}) => {\n const reducer = (values: Record<string, string>, field: CmsModelField) => {\n const plugin = getFieldIndexPlugin(field.type);\n if (!plugin || !plugin.fromIndex) {\n return values;\n }\n const value = plugin.fromIndex({\n plugins,\n model,\n field,\n value: sourceValue[field.storageId],\n rawValue: sourceRawValue[field.storageId],\n getFieldIndexPlugin,\n getFieldTypePlugin\n });\n\n if (value !== undefined) {\n values[field.storageId] = value;\n }\n\n return values;\n };\n\n return fields.reduce(reducer, {});\n};\n\ninterface ToIndexMultipleFieldValue {\n value: Record<string, string>[];\n rawValue: Record<string, string>[];\n}\n\nexport default (): CmsModelFieldToElasticsearchPlugin => ({\n type: \"cms-model-field-to-elastic-search\",\n name: \"cms-model-field-to-elastic-search-object\",\n fieldType: \"object\",\n toIndex({\n plugins,\n model,\n field,\n value: initialValue,\n rawValue: initialRawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin\n }) {\n if (!initialValue) {\n return { value: null };\n }\n\n const fields = (field.settings?.fields || []) as CmsModelField[];\n\n /**\n * In \"object\" field, value is either an object or an array of objects.\n */\n if (field.multipleValues) {\n const result: ToIndexMultipleFieldValue = {\n value: [],\n rawValue: []\n };\n for (const key in initialValue) {\n const { value, rawValue } = processToIndex({\n value: initialValue[key],\n rawValue: initialRawValue[key],\n getFieldIndexPlugin,\n getFieldTypePlugin,\n model,\n plugins,\n fields\n });\n if (Object.keys(value).length > 0) {\n result.value.push(value);\n }\n\n if (Object.keys(rawValue).length > 0) {\n result.rawValue.push(rawValue);\n }\n }\n\n return {\n value: result.value.length > 0 ? result.value : undefined,\n rawValue: result.rawValue.length > 0 ? result.rawValue : undefined\n };\n }\n\n return processToIndex({\n value: initialValue,\n rawValue: initialRawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n model,\n plugins,\n fields\n });\n },\n fromIndex({ field, value, rawValue, model, plugins, getFieldIndexPlugin, getFieldTypePlugin }) {\n if (!value) {\n return null;\n }\n\n const fields = field.settings?.fields || [];\n\n /**\n * In \"object\" field, value is either an object or an array of objects.\n */\n if (field.multipleValues) {\n /**\n * Why this `value || rawValue || []`?\n * It's possible that an object contains all non-indexable fields, or vice-versa, and so\n * we can never be sure which array we can reliably use as a source of values.\n */\n const source = value || rawValue || [];\n\n return source.map((_: any, index: number) =>\n processFromIndex({\n value: value ? value[index] || {} : {},\n rawValue: rawValue ? rawValue[index] || {} : {},\n getFieldIndexPlugin,\n getFieldTypePlugin,\n model,\n plugins,\n fields\n })\n );\n }\n\n return processFromIndex({\n value,\n rawValue,\n getFieldIndexPlugin,\n getFieldTypePlugin,\n model,\n plugins,\n fields\n });\n }\n});\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AA2CA,MAAMA,cAA8B,GAAG,CAAC;EACpCC,MADoC;EAEpCC,KAAK,EAAEC,WAF6B;EAGpCC,QAAQ,EAAEC,cAH0B;EAIpCC,mBAJoC;EAKpCC,kBALoC;EAMpCC,OANoC;EAOpCC;AAPoC,CAAD,KAQjC;EACF,MAAMC,OAAO,GAAG,CAACC,MAAD,EAAuBC,KAAvB,KAAgD;IAC5D,MAAMC,MAAM,GAAGP,mBAAmB,CAACM,KAAK,CAACE,IAAP,CAAlC;;IACA,IAAI,CAACD,MAAD,IAAW,CAACA,MAAM,CAACE,OAAvB,EAAgC;MAC5B,OAAOJ,MAAP;IACH;;IACD,MAAM;MAAET,KAAF;MAASE;IAAT,IAAsBS,MAAM,CAACE,OAAP,CAAe;MACvCN,KADuC;MAEvCG,KAFuC;MAGvCV,KAAK,EAAEC,WAAW,CAACS,KAAK,CAACI,SAAP,CAHqB;MAIvCZ,QAAQ,EAAEC,cAAc,CAACO,KAAK,CAACI,SAAP,CAJe;MAKvCV,mBALuC;MAMvCC,kBANuC;MAOvCC;IAPuC,CAAf,CAA5B;;IAUA,IAAIN,KAAK,KAAKe,SAAd,EAAyB;MACrBN,MAAM,CAACT,KAAP,CAAaU,KAAK,CAACI,SAAnB,IAAgCd,KAAhC;IACH;;IACD,IAAIE,QAAQ,KAAKa,SAAjB,EAA4B;MACxBN,MAAM,CAACP,QAAP,CAAgBQ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
|
12
12
|
key
|
|
13
13
|
}) => {
|
|
14
14
|
if (key && key.match("entryId") === null) {
|
|
15
|
-
return `${field.
|
|
15
|
+
return `${field.storageId}.id`;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
return `${field.
|
|
18
|
+
return `${field.storageId}.entryId`;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const transform = params => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createPath","field","key","match","
|
|
1
|
+
{"version":3,"names":["createPath","field","key","match","storageId","transform","params","value","createRefSearchPlugin","CmsEntryElasticsearchQueryBuilderValueSearchPlugin","fieldType","path"],"sources":["refSearch.ts"],"sourcesContent":["import {\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CreatePathCallable,\n TransformCallable\n} from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin\";\n\nconst createPath: CreatePathCallable<string> = ({ field, key }) => {\n if (key && key.match(\"entryId\") === null) {\n return `${field.storageId}.id`;\n }\n return `${field.storageId}.entryId`;\n};\n\nconst transform: TransformCallable<string> = params => {\n return params.value;\n};\n\nexport const createRefSearchPlugin = (): CmsEntryElasticsearchQueryBuilderValueSearchPlugin => {\n return new CmsEntryElasticsearchQueryBuilderValueSearchPlugin({\n fieldType: \"ref\",\n path: createPath,\n transform\n });\n};\n"],"mappings":";;;;;;;AAAA;;AAMA,MAAMA,UAAsC,GAAG,CAAC;EAAEC,KAAF;EAASC;AAAT,CAAD,KAAoB;EAC/D,IAAIA,GAAG,IAAIA,GAAG,CAACC,KAAJ,CAAU,SAAV,MAAyB,IAApC,EAA0C;IACtC,OAAQ,GAAEF,KAAK,CAACG,SAAU,KAA1B;EACH;;EACD,OAAQ,GAAEH,KAAK,CAACG,SAAU,UAA1B;AACH,CALD;;AAOA,MAAMC,SAAoC,GAAGC,MAAM,IAAI;EACnD,OAAOA,MAAM,CAACC,KAAd;AACH,CAFD;;AAIO,MAAMC,qBAAqB,GAAG,MAA0D;EAC3F,OAAO,IAAIC,sGAAJ,CAAuD;IAC1DC,SAAS,EAAE,KAD+C;IAE1DC,IAAI,EAAEX,UAFoD;IAG1DK;EAH0D,CAAvD,CAAP;AAKH,CANM"}
|
|
@@ -42,7 +42,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
42
42
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
43
43
|
|
|
44
44
|
const specialFields = ["published", "latest"];
|
|
45
|
-
const noKeywordFields = ["date", "number", "boolean"];
|
|
45
|
+
const noKeywordFields = ["date", "datetime", "number", "boolean"];
|
|
46
46
|
|
|
47
47
|
const createElasticsearchSortParams = args => {
|
|
48
48
|
const {
|
|
@@ -56,16 +56,26 @@ const createElasticsearchSortParams = args => {
|
|
|
56
56
|
return [];
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
const fieldIdToStorageIdIdMap = {};
|
|
59
60
|
const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {
|
|
60
61
|
const searchPlugin = searchPlugins[modelField.type];
|
|
61
|
-
|
|
62
|
+
const {
|
|
63
|
+
fieldId,
|
|
64
|
+
storageId
|
|
65
|
+
} = modelField.field;
|
|
66
|
+
fieldIdToStorageIdIdMap[fieldId] = fieldId;
|
|
67
|
+
/**
|
|
68
|
+
* Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
plugins[fieldId] = new _CmsEntryElasticsearchFieldPlugin.CmsEntryElasticsearchFieldPlugin({
|
|
62
72
|
unmappedType: modelField.unmappedType,
|
|
63
73
|
keyword: hasKeyword(modelField),
|
|
64
74
|
sortable: modelField.isSortable,
|
|
65
75
|
searchable: modelField.isSearchable,
|
|
66
|
-
field:
|
|
76
|
+
field: fieldId,
|
|
67
77
|
path: createFieldPath({
|
|
68
|
-
key:
|
|
78
|
+
key: storageId,
|
|
69
79
|
parentPath,
|
|
70
80
|
modelField,
|
|
71
81
|
searchPlugin
|
|
@@ -73,9 +83,30 @@ const createElasticsearchSortParams = args => {
|
|
|
73
83
|
});
|
|
74
84
|
return plugins;
|
|
75
85
|
}, {});
|
|
86
|
+
const transformedSort = sort.map(value => {
|
|
87
|
+
const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);
|
|
88
|
+
|
|
89
|
+
if (!matched) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const [, fieldId, order] = matched;
|
|
94
|
+
|
|
95
|
+
if (fieldIdToStorageIdIdMap[fieldId]) {
|
|
96
|
+
return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return value;
|
|
100
|
+
}).filter(Boolean);
|
|
76
101
|
return (0, _sort.createSort)({
|
|
77
102
|
fieldPlugins: sortPlugins,
|
|
78
|
-
sort
|
|
103
|
+
sort: transformedSort
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const findFieldByFieldId = (model, fieldId) => {
|
|
108
|
+
return model.fields.find(field => {
|
|
109
|
+
return field.fieldId === fieldId;
|
|
79
110
|
});
|
|
80
111
|
};
|
|
81
112
|
/**
|
|
@@ -160,14 +191,14 @@ const createFieldPath = ({
|
|
|
160
191
|
key
|
|
161
192
|
});
|
|
162
193
|
} else if (typeof modelField.path === "function") {
|
|
163
|
-
path = modelField.path(modelField.field.
|
|
194
|
+
path = modelField.path(modelField.field.storageId);
|
|
164
195
|
}
|
|
165
196
|
|
|
166
197
|
if (!path) {
|
|
167
198
|
/**
|
|
168
199
|
* We know that modelFieldPath is a string or undefined at this point.
|
|
169
200
|
*/
|
|
170
|
-
path = modelField.path || modelField.field.
|
|
201
|
+
path = modelField.path || modelField.field.storageId || modelField.field.id;
|
|
171
202
|
}
|
|
172
203
|
|
|
173
204
|
return modelField.isSystemField || !parentPath || path.match(parentPath) ? path : `${parentPath}.${path}`;
|
|
@@ -246,7 +277,7 @@ const fieldPathFactory = params => {
|
|
|
246
277
|
}
|
|
247
278
|
|
|
248
279
|
if (!fieldPath) {
|
|
249
|
-
fieldPath = field.
|
|
280
|
+
fieldPath = field.storageId;
|
|
250
281
|
|
|
251
282
|
if (modelField.path) {
|
|
252
283
|
fieldPath = typeof modelField.path === "function" ? modelField.path(value) : modelField.path;
|
|
@@ -322,13 +353,13 @@ const applyFullTextSearch = params => {
|
|
|
322
353
|
}
|
|
323
354
|
|
|
324
355
|
const fieldPaths = fields.reduce((collection, field) => {
|
|
325
|
-
const modelField = modelFields[field];
|
|
356
|
+
const modelField = modelFields[field.fieldId];
|
|
326
357
|
|
|
327
358
|
if (!modelField) {
|
|
328
359
|
return collection;
|
|
329
360
|
}
|
|
330
361
|
|
|
331
|
-
collection.push(`values.${field}`);
|
|
362
|
+
collection.push(`values.${field.storageId}`);
|
|
332
363
|
return collection;
|
|
333
364
|
}, []);
|
|
334
365
|
query.must.push({
|
|
@@ -406,10 +437,26 @@ const execElasticsearchBuildQueryPlugins = params => {
|
|
|
406
437
|
field,
|
|
407
438
|
operator
|
|
408
439
|
} = (0, _where.parseWhereKey)(key);
|
|
409
|
-
|
|
440
|
+
/**
|
|
441
|
+
* TODO This will be required until the storage operations receive the fieldId instead of field storageId.
|
|
442
|
+
* TODO For this to work without field searching, we need to refactor how the query looks like.
|
|
443
|
+
*
|
|
444
|
+
* Storage operations should NEVER receive an field storageId, only alias - fieldId.
|
|
445
|
+
*/
|
|
446
|
+
|
|
447
|
+
let fieldId = field;
|
|
448
|
+
const cmsModelField = findFieldByFieldId(model, fieldId);
|
|
449
|
+
|
|
450
|
+
if (!cmsModelField && !modelFields[fieldId]) {
|
|
451
|
+
throw new _error.default(`There is no CMS Model Field field "${fieldId}".`);
|
|
452
|
+
} else if (cmsModelField) {
|
|
453
|
+
fieldId = cmsModelField.fieldId;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const modelField = modelFields[fieldId];
|
|
410
457
|
|
|
411
458
|
if (!modelField) {
|
|
412
|
-
throw new _error.default(`There is no field "${
|
|
459
|
+
throw new _error.default(`There is no field "${fieldId}".`);
|
|
413
460
|
}
|
|
414
461
|
|
|
415
462
|
const {
|
|
@@ -418,7 +465,7 @@ const execElasticsearchBuildQueryPlugins = params => {
|
|
|
418
465
|
} = modelField;
|
|
419
466
|
|
|
420
467
|
if (!isSearchable) {
|
|
421
|
-
throw new _error.default(`Field "${
|
|
468
|
+
throw new _error.default(`Field "${fieldId}" is not searchable.`);
|
|
422
469
|
}
|
|
423
470
|
/**
|
|
424
471
|
* There is a possibility that value is an object.
|
|
@@ -481,10 +528,22 @@ const createElasticsearchQueryBody = params => {
|
|
|
481
528
|
limit,
|
|
482
529
|
sort: initialSort,
|
|
483
530
|
search,
|
|
484
|
-
fields
|
|
531
|
+
fields = []
|
|
485
532
|
} = args;
|
|
486
533
|
const modelFields = (0, _fields.createModelFields)(plugins, model);
|
|
487
534
|
const searchPlugins = (0, _searchPluginsList.searchPluginsList)(plugins);
|
|
535
|
+
const fullTextSearchFields = [];
|
|
536
|
+
|
|
537
|
+
for (const fieldId of fields) {
|
|
538
|
+
const field = model.fields.find(f => f.fieldId === fieldId);
|
|
539
|
+
|
|
540
|
+
if (!field) {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
fullTextSearchFields.push(field);
|
|
545
|
+
}
|
|
546
|
+
|
|
488
547
|
const query = execElasticsearchBuildQueryPlugins({
|
|
489
548
|
model,
|
|
490
549
|
plugins,
|
|
@@ -494,7 +553,7 @@ const createElasticsearchQueryBody = params => {
|
|
|
494
553
|
searchPlugins,
|
|
495
554
|
fullTextSearch: {
|
|
496
555
|
term: search,
|
|
497
|
-
fields:
|
|
556
|
+
fields: fullTextSearchFields
|
|
498
557
|
}
|
|
499
558
|
});
|
|
500
559
|
const queryPlugins = plugins.byType(_CmsEntryElasticsearchQueryModifierPlugin.CmsEntryElasticsearchQueryModifierPlugin.type).filter(pl => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["specialFields","noKeywordFields","createElasticsearchSortParams","args","sort","modelFields","parentPath","searchPlugins","length","sortPlugins","Object","values","reduce","plugins","modelField","searchPlugin","type","field","fieldId","CmsEntryElasticsearchFieldPlugin","unmappedType","keyword","hasKeyword","sortable","isSortable","searchable","isSearchable","path","createFieldPath","key","createSort","fieldPlugins","createInitialQueryValue","params","model","where","initialWhere","query","must","must_not","should","filter","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","push","term","tenant","locale","published","createPublishedType","latest","createLatestType","WebinyError","createPath","value","id","isSystemField","match","includes","nonRefFieldTypes","isRefFieldFiltering","typeOf","Array","isArray","Date","toISOString","fieldPathFactory","plugin","fieldPath","keywordValue","applyFiltering","operator","initialValue","operatorPlugins","fieldSearchPlugin","transformValueForSearch","apply","basePath","applyFullTextSearch","fields","fieldPaths","collection","query_string","allow_leading_wildcard","normalizeValue","default_operator","execElasticsearchBuildQueryPlugins","fullTextSearch","sf","keys","getElasticsearchOperatorPluginsByLocale","hasOwnProperty","undefined","parseWhereKey","cmsField","whereKey","createElasticsearchQueryBody","after","limit","initialSort","search","createModelFields","searchPluginsList","queryPlugins","byType","CmsEntryElasticsearchQueryModifierPlugin","pl","modelId","modifyQuery","CmsEntryElasticsearchSortModifierPlugin","modifySort","body","bool","size","search_after","decodeCursor","track_total_hits","bodyPlugins","CmsEntryElasticsearchBodyModifierPlugin","modifyBody"],"sources":["createElasticsearchQueryBody.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"./transformValueForSearch\";\nimport { searchPluginsList } from \"./searchPluginsList\";\nimport {\n CmsEntryListParams,\n CmsEntryListSort,\n CmsEntryListWhere,\n CmsModel,\n CmsModelField\n} from \"@webiny/api-headless-cms/types\";\nimport {\n SearchBody as esSearchBody,\n Sort as esSort,\n ElasticsearchBoolQueryConfig\n} from \"@webiny/api-elasticsearch/types\";\nimport { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createModelFields, ModelField, ModelFields } from \"./fields\";\nimport { CmsEntryElasticsearchFieldPlugin } from \"~/plugins/CmsEntryElasticsearchFieldPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch/where\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createLatestType, createPublishedType } from \"~/operations/entry\";\nimport { CmsEntryElasticsearchQueryModifierPlugin } from \"~/plugins/CmsEntryElasticsearchQueryModifierPlugin\";\nimport { CmsEntryElasticsearchSortModifierPlugin } from \"~/plugins/CmsEntryElasticsearchSortModifierPlugin\";\nimport { CmsEntryElasticsearchBodyModifierPlugin } from \"~/plugins/CmsEntryElasticsearchBodyModifierPlugin\";\nimport {\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CreatePathCallableParams\n} from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin\";\nimport { getElasticsearchOperatorPluginsByLocale } from \"@webiny/api-elasticsearch/operators\";\nimport { normalizeValue } from \"@webiny/api-elasticsearch/normalize\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\n\ninterface CreateElasticsearchParams {\n plugins: PluginsContainer;\n model: CmsModel;\n args: CmsEntryListParams;\n parentPath?: string;\n}\n\ninterface CreateElasticsearchSortParams {\n plugins: PluginsContainer;\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n parentPath?: string | null;\n model: CmsModel;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n}\n\ninterface CreateElasticsearchQueryArgs {\n model: CmsModel;\n plugins: PluginsContainer;\n where: CmsEntryListWhere;\n modelFields: ModelFields;\n parentPath?: string | null;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n fullTextSearch: {\n term?: string;\n fields: string[];\n };\n}\n\nconst specialFields: (keyof Partial<CmsEntryListWhere>)[] = [\"published\", \"latest\"];\nconst noKeywordFields = [\"date\", \"number\", \"boolean\"];\n\nconst createElasticsearchSortParams = (args: CreateElasticsearchSortParams): esSort => {\n const { sort, modelFields, parentPath, searchPlugins } = args;\n\n if (!sort || sort.length === 0) {\n return [];\n }\n\n const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {\n const searchPlugin = searchPlugins[modelField.type];\n\n plugins[modelField.field.fieldId] = new CmsEntryElasticsearchFieldPlugin({\n unmappedType: modelField.unmappedType,\n keyword: hasKeyword(modelField),\n sortable: modelField.isSortable,\n searchable: modelField.isSearchable,\n field: modelField.field.fieldId,\n path: createFieldPath({\n key: modelField.field.fieldId,\n parentPath,\n modelField,\n searchPlugin\n })\n });\n return plugins;\n }, {} as Record<string, CmsEntryElasticsearchFieldPlugin>);\n\n return createSort({\n fieldPlugins: sortPlugins,\n sort\n });\n};\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n */\nconst createInitialQueryValue = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const { model, where: initialWhere } = params;\n /**\n * Cast as partial so we can remove unnecessary keys.\n */\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n const query: ElasticsearchBoolQueryConfig = {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n\n // When ES index is shared between tenants, we need to filter records by tenant ID\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex) {\n query.must.push({ term: { \"tenant.keyword\": model.tenant } });\n }\n\n query.must.push({\n term: {\n \"locale.keyword\": model.locale\n }\n });\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createPublishedType()\n }\n });\n } else if (where.latest === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createLatestType()\n }\n });\n }\n // we do not allow not published and not latest\n else {\n throw new WebinyError(\n `Cannot call Elasticsearch query when not setting \"published\" or \"latest\".`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n //\n return query;\n};\n\ninterface CreateFieldPathParams {\n modelField: ModelField;\n key: string;\n searchPlugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n parentPath?: string | null;\n}\nconst createFieldPath = ({\n modelField,\n searchPlugin,\n parentPath,\n key\n}: CreateFieldPathParams): string => {\n let path: string | null = null;\n if (searchPlugin && typeof searchPlugin.createPath === \"function\") {\n path = searchPlugin.createPath({\n field: modelField.field,\n value: null,\n key\n });\n } else if (typeof modelField.path === \"function\") {\n path = modelField.path(modelField.field.fieldId);\n }\n if (!path) {\n /**\n * We know that modelFieldPath is a string or undefined at this point.\n */\n path = (modelField.path as string) || modelField.field.fieldId || modelField.field.id;\n }\n return modelField.isSystemField || !parentPath || path.match(parentPath)\n ? path\n : `${parentPath}.${path}`;\n};\n\nconst hasKeyword = (modelField: ModelField): boolean => {\n /**\n * We defined some field types that MUST have no keyword added to the field path\n */\n if (noKeywordFields.includes(modelField.type)) {\n return false;\n } else if (modelField.unmappedType) {\n /**\n * If modelField has unmapped type defined, do not add keyword.\n */\n return false;\n } else if (modelField.keyword === false) {\n /**\n * And if specifically defined that modelField has no keyword, do not add it.\n */\n return false;\n }\n /**\n * All other fields have keyword added.\n */\n return true;\n};\n\ninterface IsRefFieldFilteringParams {\n key: string;\n value: any;\n field: CmsModelField;\n}\n\n/**\n * A list of typeof strings that are 100% not ref field filtering.\n * We also need to check for array and date.\n */\nconst nonRefFieldTypes: string[] = [\n \"string\",\n \"number\",\n \"undefined\",\n \"symbol\",\n \"bigint\",\n \"function\",\n \"boolean\"\n];\nconst isRefFieldFiltering = (params: IsRefFieldFilteringParams): boolean => {\n const { key, value, field } = params;\n const typeOf = typeof value;\n if (\n !value ||\n nonRefFieldTypes.includes(typeOf) ||\n Array.isArray(value) ||\n value instanceof Date ||\n !!value.toISOString\n ) {\n return false;\n } else if (typeOf === \"object\" && field.type === \"ref\") {\n return true;\n }\n throw new WebinyError(\n \"Could not determine if the search value is ref field search.\",\n \"REF_FIELD_SEARCH_ERROR\",\n {\n value,\n field,\n key\n }\n );\n};\n\ninterface FieldPathFactoryParams extends Omit<CreatePathCallableParams, \"field\"> {\n plugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n modelField: ModelField;\n key: string;\n parentPath?: string | null;\n keyword?: boolean;\n}\nconst fieldPathFactory = (params: FieldPathFactoryParams): string => {\n const { plugin, modelField, value, parentPath, keyword, key } = params;\n\n const field = modelField.field;\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field, value, key });\n }\n if (!fieldPath) {\n fieldPath = field.fieldId;\n if (modelField.path) {\n fieldPath =\n typeof modelField.path === \"function\" ? modelField.path(value) : modelField.path;\n }\n }\n\n const keywordValue = keyword ? \".keyword\" : \"\";\n if (!parentPath) {\n return `${fieldPath}${keywordValue}`;\n }\n return `${parentPath}.${fieldPath}${keywordValue}`;\n};\n\ninterface ApplyFilteringParams {\n query: ElasticsearchBoolQueryConfig;\n modelField: ModelField;\n operator: string;\n key: string;\n value: any;\n operatorPlugins: Record<string, ElasticsearchQueryBuilderOperatorPlugin>;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n parentPath?: string | null;\n}\nconst applyFiltering = (params: ApplyFilteringParams) => {\n const {\n query,\n modelField,\n operator,\n key,\n value: initialValue,\n operatorPlugins,\n searchPlugins,\n parentPath\n } = params;\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"Operator plugin missing.\", \"PLUGIN_MISSING\", {\n operator\n });\n }\n const fieldSearchPlugin = searchPlugins[modelField.type];\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: modelField.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(modelField);\n plugin.apply(query, {\n basePath: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n parentPath: modelField.isSystemField ? null : parentPath,\n value,\n key\n }),\n path: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n value,\n parentPath: modelField.isSystemField ? null : parentPath,\n keyword,\n key\n }),\n value,\n keyword\n });\n};\n\ninterface ApplyFullTextSearchParams {\n query: ElasticsearchBoolQueryConfig;\n modelFields: ModelFields;\n term?: string;\n fields: string[];\n}\nconst applyFullTextSearch = (params: ApplyFullTextSearchParams): void => {\n const { query, modelFields, term, fields } = params;\n if (!term || term.length === 0 || fields.length === 0) {\n return;\n }\n\n const fieldPaths = fields.reduce((collection, field) => {\n const modelField = modelFields[field];\n if (!modelField) {\n return collection;\n }\n\n collection.push(`values.${field}`);\n\n return collection;\n }, [] as string[]);\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: fieldPaths,\n query: normalizeValue(term),\n default_operator: \"or\"\n }\n });\n};\n/*\n * Iterate through where keys and apply plugins where necessary\n */\nconst execElasticsearchBuildQueryPlugins = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const {\n model,\n where: initialWhere,\n modelFields,\n parentPath,\n plugins,\n searchPlugins,\n fullTextSearch\n } = params;\n\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n const query = createInitialQueryValue({\n ...params,\n where\n });\n\n /**\n * Add full text search for requested fields.\n */\n applyFullTextSearch({\n query,\n modelFields,\n term: fullTextSearch.term,\n fields: fullTextSearch.fields\n });\n\n /**\n * Always remove special fields, as these do not exist in Elasticsearch.\n */\n for (const sf of specialFields) {\n delete where[sf];\n }\n\n if (Object.keys(where).length === 0) {\n return query;\n }\n\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, model.locale);\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n /**\n * We do not need to go further if value is undefined.\n * There are few hardcoded possibilities when value is undefined, for example, ownedBy.\n */\n // TODO figure out how to have type.\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n const modelField = modelFields[field];\n\n if (!modelField) {\n throw new WebinyError(`There is no field \"${field}\".`);\n }\n const { isSearchable = false, field: cmsField } = modelField;\n if (!isSearchable) {\n throw new WebinyError(`Field \"${field}\" is not searchable.`);\n }\n /**\n * There is a possibility that value is an object.\n * In that case, check if field is ref field and continue a bit differently.\n */\n if (isRefFieldFiltering({ key, value, field: cmsField })) {\n /**\n * We we need to go through each key in where[key] to determine the filters.\n */\n for (const whereKey in value) {\n const { operator } = parseWhereKey(whereKey);\n applyFiltering({\n query,\n modelField,\n operator,\n key: whereKey,\n value: value[whereKey],\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n continue;\n }\n applyFiltering({\n query,\n modelField,\n operator,\n key,\n value,\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n\n return query;\n};\n\nexport const createElasticsearchQueryBody = (params: CreateElasticsearchParams): esSearchBody => {\n const { plugins, model, args, parentPath = null } = params;\n const { where = {}, after, limit, sort: initialSort, search, fields } = args;\n\n const modelFields = createModelFields(plugins, model);\n const searchPlugins = searchPluginsList(plugins);\n\n const query = execElasticsearchBuildQueryPlugins({\n model,\n plugins,\n where,\n modelFields,\n parentPath,\n searchPlugins,\n fullTextSearch: {\n term: search,\n fields: fields || []\n }\n });\n\n const queryPlugins = plugins\n .byType<CmsEntryElasticsearchQueryModifierPlugin>(\n CmsEntryElasticsearchQueryModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of queryPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSortParams({\n plugins,\n sort: initialSort,\n modelFields,\n parentPath,\n model,\n searchPlugins\n });\n\n const sortPlugins = plugins\n .byType<CmsEntryElasticsearchSortModifierPlugin>(\n CmsEntryElasticsearchSortModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of sortPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const body: esSearchBody = {\n query: {\n bool: {\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 sort,\n size: (limit || 0) + 1,\n // eslint-disable-next-line\n search_after: decodeCursor(after) as any,\n // eslint-disable-next-line\n track_total_hits: true\n };\n\n const bodyPlugins = plugins\n .byType<CmsEntryElasticsearchBodyModifierPlugin>(\n CmsEntryElasticsearchBodyModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of bodyPlugins) {\n pl.modifyBody({\n body,\n model\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAaA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AACA;;;;;;AAgCA,MAAMA,aAAmD,GAAG,CAAC,WAAD,EAAc,QAAd,CAA5D;AACA,MAAMC,eAAe,GAAG,CAAC,MAAD,EAAS,QAAT,EAAmB,SAAnB,CAAxB;;AAEA,MAAMC,6BAA6B,GAAIC,IAAD,IAAiD;EACnF,MAAM;IAAEC,IAAF;IAAQC,WAAR;IAAqBC,UAArB;IAAiCC;EAAjC,IAAmDJ,IAAzD;;EAEA,IAAI,CAACC,IAAD,IAASA,IAAI,CAACI,MAAL,KAAgB,CAA7B,EAAgC;IAC5B,OAAO,EAAP;EACH;;EAED,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAP,CAAcN,WAAd,EAA2B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,IAAAC,qBAAA,EAAalB,KAAb,CAZS;IAavB;IACAmB,gBAAgB,EAAE;EAdK,CAA3B;EAiBA,MAAMC,WAAW,GAAG1G,OAAO,CACtB6F,MADe,CAEZc,gFAAA,CAAwCxG,IAF5B,EAIfyB,MAJe,CAIRmE,EAAE,IAAI;IACV,OAAO,CAACA,EAAE,CAACC,OAAJ,IAAeD,EAAE,CAACC,OAAH,KAAe3E,KAAK,CAAC2E,OAA3C;EACH,CANe,CAApB;;EAOA,KAAK,MAAMD,EAAX,IAAiBW,WAAjB,EAA8B;IAC1BX,EAAE,CAACa,UAAH,CAAc;MACVR,IADU;MAEV/E;IAFU,CAAd;EAIH;;EAED,OAAO+E,IAAP;AACH,CAtFM"}
|
|
1
|
+
{"version":3,"names":["specialFields","noKeywordFields","createElasticsearchSortParams","args","sort","modelFields","parentPath","searchPlugins","length","fieldIdToStorageIdIdMap","sortPlugins","Object","values","reduce","plugins","modelField","searchPlugin","type","fieldId","storageId","field","CmsEntryElasticsearchFieldPlugin","unmappedType","keyword","hasKeyword","sortable","isSortable","searchable","isSearchable","path","createFieldPath","key","transformedSort","map","value","matched","match","order","filter","Boolean","createSort","fieldPlugins","findFieldByFieldId","model","fields","find","createInitialQueryValue","params","where","initialWhere","query","must","must_not","should","sharedIndex","process","env","ELASTICSEARCH_SHARED_INDEXES","push","term","tenant","locale","published","createPublishedType","latest","createLatestType","WebinyError","createPath","id","isSystemField","includes","nonRefFieldTypes","isRefFieldFiltering","typeOf","Array","isArray","Date","toISOString","fieldPathFactory","plugin","fieldPath","keywordValue","applyFiltering","operator","initialValue","operatorPlugins","fieldSearchPlugin","transformValueForSearch","apply","basePath","applyFullTextSearch","fieldPaths","collection","query_string","allow_leading_wildcard","normalizeValue","default_operator","execElasticsearchBuildQueryPlugins","fullTextSearch","sf","keys","getElasticsearchOperatorPluginsByLocale","hasOwnProperty","undefined","parseWhereKey","cmsModelField","cmsField","whereKey","createElasticsearchQueryBody","after","limit","initialSort","search","createModelFields","searchPluginsList","fullTextSearchFields","f","queryPlugins","byType","CmsEntryElasticsearchQueryModifierPlugin","pl","modelId","modifyQuery","CmsEntryElasticsearchSortModifierPlugin","modifySort","body","bool","size","search_after","decodeCursor","track_total_hits","bodyPlugins","CmsEntryElasticsearchBodyModifierPlugin","modifyBody"],"sources":["createElasticsearchQueryBody.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { transformValueForSearch } from \"./transformValueForSearch\";\nimport { searchPluginsList } from \"./searchPluginsList\";\nimport {\n CmsEntryListParams,\n CmsEntryListSort,\n CmsEntryListWhere,\n CmsModel,\n CmsModelField\n} from \"@webiny/api-headless-cms/types\";\nimport {\n SearchBody as esSearchBody,\n Sort as esSort,\n ElasticsearchBoolQueryConfig\n} from \"@webiny/api-elasticsearch/types\";\nimport { decodeCursor } from \"@webiny/api-elasticsearch/cursors\";\nimport { createSort } from \"@webiny/api-elasticsearch/sort\";\nimport { createModelFields, ModelField, ModelFields } from \"./fields\";\nimport { CmsEntryElasticsearchFieldPlugin } from \"~/plugins/CmsEntryElasticsearchFieldPlugin\";\nimport { parseWhereKey } from \"@webiny/api-elasticsearch/where\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { createLatestType, createPublishedType } from \"~/operations/entry\";\nimport { CmsEntryElasticsearchQueryModifierPlugin } from \"~/plugins/CmsEntryElasticsearchQueryModifierPlugin\";\nimport { CmsEntryElasticsearchSortModifierPlugin } from \"~/plugins/CmsEntryElasticsearchSortModifierPlugin\";\nimport { CmsEntryElasticsearchBodyModifierPlugin } from \"~/plugins/CmsEntryElasticsearchBodyModifierPlugin\";\nimport {\n CmsEntryElasticsearchQueryBuilderValueSearchPlugin,\n CreatePathCallableParams\n} from \"~/plugins/CmsEntryElasticsearchQueryBuilderValueSearchPlugin\";\nimport { getElasticsearchOperatorPluginsByLocale } from \"@webiny/api-elasticsearch/operators\";\nimport { normalizeValue } from \"@webiny/api-elasticsearch/normalize\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"@webiny/api-elasticsearch/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\n\ninterface CreateElasticsearchParams {\n plugins: PluginsContainer;\n model: CmsModel;\n args: CmsEntryListParams;\n parentPath?: string;\n}\n\ninterface CreateElasticsearchSortParams {\n plugins: PluginsContainer;\n sort?: CmsEntryListSort;\n modelFields: ModelFields;\n parentPath?: string | null;\n model: CmsModel;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n}\n\ninterface CreateElasticsearchQueryArgs {\n model: CmsModel;\n plugins: PluginsContainer;\n where: CmsEntryListWhere;\n modelFields: ModelFields;\n parentPath?: string | null;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n fullTextSearch: {\n term?: string;\n fields: CmsModelField[];\n };\n}\n\nconst specialFields: (keyof Partial<CmsEntryListWhere>)[] = [\"published\", \"latest\"];\nconst noKeywordFields = [\"date\", \"datetime\", \"number\", \"boolean\"];\n\nconst createElasticsearchSortParams = (args: CreateElasticsearchSortParams): esSort => {\n const { sort, modelFields, parentPath, searchPlugins } = args;\n\n if (!sort || sort.length === 0) {\n return [];\n }\n\n const fieldIdToStorageIdIdMap: Record<string, string> = {};\n\n const sortPlugins = Object.values(modelFields).reduce((plugins, modelField) => {\n const searchPlugin = searchPlugins[modelField.type];\n\n const { fieldId, storageId } = modelField.field;\n\n fieldIdToStorageIdIdMap[fieldId] = fieldId;\n /**\n * Plugins must be stored with fieldId as key because it is later used to find the sorting plugin.\n */\n plugins[fieldId] = new CmsEntryElasticsearchFieldPlugin({\n unmappedType: modelField.unmappedType,\n keyword: hasKeyword(modelField),\n sortable: modelField.isSortable,\n searchable: modelField.isSearchable,\n field: fieldId,\n path: createFieldPath({\n key: storageId,\n parentPath,\n modelField,\n searchPlugin\n })\n });\n return plugins;\n }, {} as Record<string, CmsEntryElasticsearchFieldPlugin>);\n\n const transformedSort = sort\n .map(value => {\n const matched = value.match(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);\n if (!matched) {\n return null;\n }\n const [, fieldId, order] = matched;\n if (fieldIdToStorageIdIdMap[fieldId]) {\n return `${fieldIdToStorageIdIdMap[fieldId]}_${order}`;\n }\n\n return value;\n })\n .filter(Boolean) as string[];\n return createSort({\n fieldPlugins: sortPlugins,\n sort: transformedSort\n });\n};\n\nconst findFieldByFieldId = (model: CmsModel, fieldId: string): CmsModelField | undefined => {\n return model.fields.find(field => {\n return field.fieldId === fieldId;\n });\n};\n/**\n * Latest and published are specific in Elasticsearch to that extend that they are tagged in the __type property.\n * We allow either published or either latest.\n * Latest is used in the manage API and published in the read API.\n */\nconst createInitialQueryValue = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const { model, where: initialWhere } = params;\n /**\n * Cast as partial so we can remove unnecessary keys.\n */\n const where: CmsEntryListWhere = {\n ...initialWhere\n };\n\n const query: ElasticsearchBoolQueryConfig = {\n must: [],\n must_not: [],\n should: [],\n filter: []\n };\n\n // When ES index is shared between tenants, we need to filter records by tenant ID\n const sharedIndex = process.env.ELASTICSEARCH_SHARED_INDEXES === \"true\";\n if (sharedIndex) {\n query.must.push({ term: { \"tenant.keyword\": model.tenant } });\n }\n\n query.must.push({\n term: {\n \"locale.keyword\": model.locale\n }\n });\n\n /**\n * We must transform published and latest where args into something that is understandable by our Elasticsearch\n */\n if (where.published === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createPublishedType()\n }\n });\n } else if (where.latest === true) {\n query.must.push({\n term: {\n \"__type.keyword\": createLatestType()\n }\n });\n }\n // we do not allow not published and not latest\n else {\n throw new WebinyError(\n `Cannot call Elasticsearch query when not setting \"published\" or \"latest\".`,\n \"ELASTICSEARCH_UNSUPPORTED_QUERY\",\n {\n where\n }\n );\n }\n //\n return query;\n};\n\ninterface CreateFieldPathParams {\n modelField: ModelField;\n key: string;\n searchPlugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n parentPath?: string | null;\n}\nconst createFieldPath = ({\n modelField,\n searchPlugin,\n parentPath,\n key\n}: CreateFieldPathParams): string => {\n let path: string | null = null;\n if (searchPlugin && typeof searchPlugin.createPath === \"function\") {\n path = searchPlugin.createPath({\n field: modelField.field,\n value: null,\n key\n });\n } else if (typeof modelField.path === \"function\") {\n path = modelField.path(modelField.field.storageId);\n }\n if (!path) {\n /**\n * We know that modelFieldPath is a string or undefined at this point.\n */\n path = (modelField.path as string) || modelField.field.storageId || modelField.field.id;\n }\n return modelField.isSystemField || !parentPath || path.match(parentPath)\n ? path\n : `${parentPath}.${path}`;\n};\n\nconst hasKeyword = (modelField: ModelField): boolean => {\n /**\n * We defined some field types that MUST have no keyword added to the field path\n */\n if (noKeywordFields.includes(modelField.type)) {\n return false;\n } else if (modelField.unmappedType) {\n /**\n * If modelField has unmapped type defined, do not add keyword.\n */\n return false;\n } else if (modelField.keyword === false) {\n /**\n * And if specifically defined that modelField has no keyword, do not add it.\n */\n return false;\n }\n /**\n * All other fields have keyword added.\n */\n return true;\n};\n\ninterface IsRefFieldFilteringParams {\n key: string;\n value: any;\n field: CmsModelField;\n}\n\n/**\n * A list of typeof strings that are 100% not ref field filtering.\n * We also need to check for array and date.\n */\nconst nonRefFieldTypes: string[] = [\n \"string\",\n \"number\",\n \"undefined\",\n \"symbol\",\n \"bigint\",\n \"function\",\n \"boolean\"\n];\nconst isRefFieldFiltering = (params: IsRefFieldFilteringParams): boolean => {\n const { key, value, field } = params;\n const typeOf = typeof value;\n if (\n !value ||\n nonRefFieldTypes.includes(typeOf) ||\n Array.isArray(value) ||\n value instanceof Date ||\n !!value.toISOString\n ) {\n return false;\n } else if (typeOf === \"object\" && field.type === \"ref\") {\n return true;\n }\n throw new WebinyError(\n \"Could not determine if the search value is ref field search.\",\n \"REF_FIELD_SEARCH_ERROR\",\n {\n value,\n field,\n key\n }\n );\n};\n\ninterface FieldPathFactoryParams extends Omit<CreatePathCallableParams, \"field\"> {\n plugin?: CmsEntryElasticsearchQueryBuilderValueSearchPlugin;\n modelField: ModelField;\n key: string;\n parentPath?: string | null;\n keyword?: boolean;\n}\nconst fieldPathFactory = (params: FieldPathFactoryParams): string => {\n const { plugin, modelField, value, parentPath, keyword, key } = params;\n\n const field = modelField.field;\n\n let fieldPath: string | null = null;\n if (plugin) {\n fieldPath = plugin.createPath({ field, value, key });\n }\n if (!fieldPath) {\n fieldPath = field.storageId;\n if (modelField.path) {\n fieldPath =\n typeof modelField.path === \"function\" ? modelField.path(value) : modelField.path;\n }\n }\n\n const keywordValue = keyword ? \".keyword\" : \"\";\n if (!parentPath) {\n return `${fieldPath}${keywordValue}`;\n }\n return `${parentPath}.${fieldPath}${keywordValue}`;\n};\n\ninterface ApplyFilteringParams {\n query: ElasticsearchBoolQueryConfig;\n modelField: ModelField;\n operator: string;\n key: string;\n value: any;\n operatorPlugins: Record<string, ElasticsearchQueryBuilderOperatorPlugin>;\n searchPlugins: Record<string, CmsEntryElasticsearchQueryBuilderValueSearchPlugin>;\n parentPath?: string | null;\n}\nconst applyFiltering = (params: ApplyFilteringParams) => {\n const {\n query,\n modelField,\n operator,\n key,\n value: initialValue,\n operatorPlugins,\n searchPlugins,\n parentPath\n } = params;\n const plugin = operatorPlugins[operator];\n if (!plugin) {\n throw new WebinyError(\"Operator plugin missing.\", \"PLUGIN_MISSING\", {\n operator\n });\n }\n const fieldSearchPlugin = searchPlugins[modelField.type];\n const value = transformValueForSearch({\n plugins: searchPlugins,\n field: modelField.field,\n value: initialValue\n });\n\n const keyword = hasKeyword(modelField);\n plugin.apply(query, {\n basePath: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n parentPath: modelField.isSystemField ? null : parentPath,\n value,\n key\n }),\n path: fieldPathFactory({\n plugin: fieldSearchPlugin,\n modelField,\n value,\n parentPath: modelField.isSystemField ? null : parentPath,\n keyword,\n key\n }),\n value,\n keyword\n });\n};\n\ninterface ApplyFullTextSearchParams {\n query: ElasticsearchBoolQueryConfig;\n modelFields: ModelFields;\n term?: string;\n fields: CmsModelField[];\n}\nconst applyFullTextSearch = (params: ApplyFullTextSearchParams): void => {\n const { query, modelFields, term, fields } = params;\n if (!term || term.length === 0 || fields.length === 0) {\n return;\n }\n\n const fieldPaths = fields.reduce((collection, field) => {\n const modelField = modelFields[field.fieldId];\n if (!modelField) {\n return collection;\n }\n\n collection.push(`values.${field.storageId}`);\n\n return collection;\n }, [] as string[]);\n\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: fieldPaths,\n query: normalizeValue(term),\n default_operator: \"or\"\n }\n });\n};\n\n/*\n * Iterate through where keys and apply plugins where necessary\n */\nconst execElasticsearchBuildQueryPlugins = (\n params: CreateElasticsearchQueryArgs\n): ElasticsearchBoolQueryConfig => {\n const {\n model,\n where: initialWhere,\n modelFields,\n parentPath,\n plugins,\n searchPlugins,\n fullTextSearch\n } = params;\n\n const where: Partial<CmsEntryListWhere> = {\n ...initialWhere\n };\n const query = createInitialQueryValue({\n ...params,\n where\n });\n\n /**\n * Add full text search for requested fields.\n */\n applyFullTextSearch({\n query,\n modelFields,\n term: fullTextSearch.term,\n fields: fullTextSearch.fields\n });\n\n /**\n * Always remove special fields, as these do not exist in Elasticsearch.\n */\n for (const sf of specialFields) {\n delete where[sf];\n }\n\n if (Object.keys(where).length === 0) {\n return query;\n }\n\n const operatorPlugins = getElasticsearchOperatorPluginsByLocale(plugins, model.locale);\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n /**\n * We do not need to go further if value is undefined.\n * There are few hardcoded possibilities when value is undefined, for example, ownedBy.\n */\n // TODO figure out how to have type.\n const value = (where as any)[key];\n if (value === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n /**\n * TODO This will be required until the storage operations receive the fieldId instead of field storageId.\n * TODO For this to work without field searching, we need to refactor how the query looks like.\n *\n * Storage operations should NEVER receive an field storageId, only alias - fieldId.\n */\n\n let fieldId = field;\n const cmsModelField = findFieldByFieldId(model, fieldId);\n if (!cmsModelField && !modelFields[fieldId]) {\n throw new WebinyError(`There is no CMS Model Field field \"${fieldId}\".`);\n } else if (cmsModelField) {\n fieldId = cmsModelField.fieldId;\n }\n\n const modelField = modelFields[fieldId];\n\n if (!modelField) {\n throw new WebinyError(`There is no field \"${fieldId}\".`);\n }\n const { isSearchable = false, field: cmsField } = modelField;\n if (!isSearchable) {\n throw new WebinyError(`Field \"${fieldId}\" is not searchable.`);\n }\n /**\n * There is a possibility that value is an object.\n * In that case, check if field is ref field and continue a bit differently.\n */\n if (isRefFieldFiltering({ key, value, field: cmsField })) {\n /**\n * We we need to go through each key in where[key] to determine the filters.\n */\n for (const whereKey in value) {\n const { operator } = parseWhereKey(whereKey);\n applyFiltering({\n query,\n modelField,\n operator,\n key: whereKey,\n value: value[whereKey],\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n continue;\n }\n applyFiltering({\n query,\n modelField,\n operator,\n key,\n value,\n searchPlugins,\n operatorPlugins,\n parentPath\n });\n }\n\n return query;\n};\n\nexport const createElasticsearchQueryBody = (params: CreateElasticsearchParams): esSearchBody => {\n const { plugins, model, args, parentPath = null } = params;\n const { where = {}, after, limit, sort: initialSort, search, fields = [] } = args;\n\n const modelFields = createModelFields(plugins, model);\n const searchPlugins = searchPluginsList(plugins);\n\n const fullTextSearchFields: CmsModelField[] = [];\n for (const fieldId of fields) {\n const field = model.fields.find(f => f.fieldId === fieldId);\n if (!field) {\n continue;\n }\n fullTextSearchFields.push(field);\n }\n\n const query = execElasticsearchBuildQueryPlugins({\n model,\n plugins,\n where,\n modelFields,\n parentPath,\n searchPlugins,\n fullTextSearch: {\n term: search,\n fields: fullTextSearchFields\n }\n });\n\n const queryPlugins = plugins\n .byType<CmsEntryElasticsearchQueryModifierPlugin>(\n CmsEntryElasticsearchQueryModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of queryPlugins) {\n pl.modifyQuery({ query, model, where });\n }\n\n const sort = createElasticsearchSortParams({\n plugins,\n sort: initialSort,\n modelFields,\n parentPath,\n model,\n searchPlugins\n });\n\n const sortPlugins = plugins\n .byType<CmsEntryElasticsearchSortModifierPlugin>(\n CmsEntryElasticsearchSortModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of sortPlugins) {\n pl.modifySort({\n sort,\n model\n });\n }\n\n const body: esSearchBody = {\n query: {\n bool: {\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 sort,\n size: (limit || 0) + 1,\n // eslint-disable-next-line\n search_after: decodeCursor(after) as any,\n // eslint-disable-next-line\n track_total_hits: true\n };\n\n const bodyPlugins = plugins\n .byType<CmsEntryElasticsearchBodyModifierPlugin>(\n CmsEntryElasticsearchBodyModifierPlugin.type\n )\n .filter(pl => {\n return !pl.modelId || pl.modelId === model.modelId;\n });\n for (const pl of bodyPlugins) {\n pl.modifyBody({\n body,\n model\n });\n }\n\n return body;\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAaA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAKA;;AACA;;;;;;AAgCA,MAAMA,aAAmD,GAAG,CAAC,WAAD,EAAc,QAAd,CAA5D;AACA,MAAMC,eAAe,GAAG,CAAC,MAAD,EAAS,UAAT,EAAqB,QAArB,EAA+B,SAA/B,CAAxB;;AAEA,MAAMC,6BAA6B,GAAIC,IAAD,IAAiD;EACnF,MAAM;IAAEC,IAAF;IAAQC,WAAR;IAAqBC,UAArB;IAAiCC;EAAjC,IAAmDJ,IAAzD;;EAEA,IAAI,CAACC,IAAD,IAASA,IAAI,CAACI,MAAL,KAAgB,CAA7B,EAAgC;IAC5B,OAAO,EAAP;EACH;;EAED,MAAMC,uBAA+C,GAAG,EAAxD;EAEA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAP,CAAc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CAAa9B,MAAb,GAAsB,CAAtB,GAA0B0C,KAAK,CAACZ,MAAhC,GAAyCiE;MAJ/C;IADH,CADgB;IASvBnG,IATuB;IAUvB2H,IAAI,EAAE,CAACjB,KAAK,IAAI,CAAV,IAAe,CAVE;IAWvB;IACAkB,YAAY,EAAE,IAAAC,qBAAA,EAAapB,KAAb,CAZS;IAavB;IACAqB,gBAAgB,EAAE;EAdK,CAA3B;EAiBA,MAAMC,WAAW,GAAGrH,OAAO,CACtBwG,MADe,CAEZc,gFAAA,CAAwCnH,IAF5B,EAIfqB,MAJe,CAIRkF,EAAE,IAAI;IACV,OAAO,CAACA,EAAE,CAACC,OAAJ,IAAeD,EAAE,CAACC,OAAH,KAAe9E,KAAK,CAAC8E,OAA3C;EACH,CANe,CAApB;;EAOA,KAAK,MAAMD,EAAX,IAAiBW,WAAjB,EAA8B;IAC1BX,EAAE,CAACa,UAAH,CAAc;MACVR,IADU;MAEVlF;IAFU,CAAd;EAIH;;EAED,OAAOkF,IAAP;AACH,CA/FM"}
|
|
@@ -49,7 +49,7 @@ const prepareEntryToIndex = params => {
|
|
|
49
49
|
const rawValues = {}; // We're only interested in current model fields.
|
|
50
50
|
|
|
51
51
|
for (const field of model.fields) {
|
|
52
|
-
if (storageEntry.values.hasOwnProperty(field.
|
|
52
|
+
if (storageEntry.values.hasOwnProperty(field.storageId) === false) {
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -66,18 +66,18 @@ const prepareEntryToIndex = params => {
|
|
|
66
66
|
plugins,
|
|
67
67
|
model,
|
|
68
68
|
field,
|
|
69
|
-
rawValue: entry.values[field.
|
|
70
|
-
value: storageEntry.values[field.
|
|
69
|
+
rawValue: entry.values[field.storageId],
|
|
70
|
+
value: storageEntry.values[field.storageId],
|
|
71
71
|
getFieldIndexPlugin,
|
|
72
72
|
getFieldTypePlugin
|
|
73
73
|
});
|
|
74
74
|
|
|
75
75
|
if (typeof value !== "undefined") {
|
|
76
|
-
values[field.
|
|
76
|
+
values[field.storageId] = value;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
if (typeof rawValue !== "undefined") {
|
|
80
|
-
rawValues[field.
|
|
80
|
+
rawValues[field.storageId] = rawValue;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -157,18 +157,18 @@ const extractEntriesFromIndex = ({
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
try {
|
|
160
|
-
indexValues[field.
|
|
160
|
+
indexValues[field.storageId] = targetFieldPlugin.fromIndex({
|
|
161
161
|
plugins,
|
|
162
162
|
model,
|
|
163
163
|
field,
|
|
164
164
|
getFieldIndexPlugin,
|
|
165
165
|
getFieldTypePlugin,
|
|
166
|
-
value: entry.values[field.
|
|
166
|
+
value: entry.values[field.storageId],
|
|
167
167
|
|
|
168
168
|
/**
|
|
169
169
|
* Possibly no rawValues so we must check for the existence of the field.
|
|
170
170
|
*/
|
|
171
|
-
rawValue: entry.rawValues ? entry.rawValues[field.
|
|
171
|
+
rawValue: entry.rawValues ? entry.rawValues[field.storageId] : null
|
|
172
172
|
});
|
|
173
173
|
} catch (ex) {
|
|
174
174
|
throw new _error.default(ex.message || "Could not transform entry field from index.", ex.code || "FIELD_FROM_INDEX_ERROR", {
|