@webiny/api-elasticsearch 0.0.0-unstable.615a930a68 → 0.0.0-unstable.6509387258
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/normalize.js +9 -3
- package/normalize.js.map +1 -1
- package/package.json +9 -9
- package/plugins/operator/contains.js +1 -1
- package/plugins/operator/contains.js.map +1 -1
- package/plugins/operator/japanese/contains.js +2 -2
- package/plugins/operator/japanese/contains.js.map +1 -1
- package/plugins/operator/notContains.js +1 -1
- package/plugins/operator/notContains.js.map +1 -1
- package/sort.js +3 -1
- package/sort.js.map +1 -1
package/normalize.js
CHANGED
|
@@ -9,16 +9,22 @@ exports.normalizeValue = void 0;
|
|
|
9
9
|
* Before performing the query, we need to escape all special characters.
|
|
10
10
|
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
|
|
11
11
|
*/
|
|
12
|
-
const
|
|
12
|
+
const specialCharacterToSpace = ["-"];
|
|
13
|
+
const specialCharacters = ["\\\\", "\\+", // "\\-",
|
|
14
|
+
"\\=", "\\&\\&", "\\|\\|", ">", "<", "\\!", "\\(", "\\)", "\\{", "\\}", "\\[", "\\]", "\\^", '\\"', "\\~", "\\*", "\\?", "\\:", "\\/", "\\#"];
|
|
13
15
|
|
|
14
16
|
const normalizeValue = value => {
|
|
15
|
-
let result = value;
|
|
17
|
+
let result = value || "";
|
|
18
|
+
|
|
19
|
+
for (const character of specialCharacterToSpace) {
|
|
20
|
+
result = result.replace(new RegExp(character, "g"), " ");
|
|
21
|
+
}
|
|
16
22
|
|
|
17
23
|
for (const character of specialCharacters) {
|
|
18
24
|
result = result.replace(new RegExp(character, "g"), `\\${character}`);
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
return result
|
|
27
|
+
return result || "";
|
|
22
28
|
};
|
|
23
29
|
|
|
24
30
|
exports.normalizeValue = normalizeValue;
|
package/normalize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["specialCharacters","normalizeValue","value","result","character","replace","RegExp"],"sources":["normalize.ts"],"sourcesContent":["/**\n * Before performing the query, we need to escape all special characters.\n * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters\n */\n\nconst specialCharacters = [\n \"\\\\+\",\n \"\\\\-\",\n \"\\\\=\",\n \"\\\\&\\\\&\",\n \"\\\\|\\\\|\",\n \">\",\n \"<\",\n \"\\\\!\",\n \"\\\\(\",\n \"\\\\)\",\n \"\\\\{\",\n \"\\\\}\",\n \"\\\\[\",\n \"\\\\]\",\n \"\\\\^\",\n '\\\\\"',\n \"\\\\~\",\n \"\\\\*\",\n \"\\\\?\",\n \"\\\\:\",\n \"
|
|
1
|
+
{"version":3,"names":["specialCharacterToSpace","specialCharacters","normalizeValue","value","result","character","replace","RegExp"],"sources":["normalize.ts"],"sourcesContent":["/**\n * Before performing the query, we need to escape all special characters.\n * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters\n */\n\nconst specialCharacterToSpace = [\"-\"];\n\nconst specialCharacters = [\n \"\\\\\\\\\",\n \"\\\\+\",\n // \"\\\\-\",\n \"\\\\=\",\n \"\\\\&\\\\&\",\n \"\\\\|\\\\|\",\n \">\",\n \"<\",\n \"\\\\!\",\n \"\\\\(\",\n \"\\\\)\",\n \"\\\\{\",\n \"\\\\}\",\n \"\\\\[\",\n \"\\\\]\",\n \"\\\\^\",\n '\\\\\"',\n \"\\\\~\",\n \"\\\\*\",\n \"\\\\?\",\n \"\\\\:\",\n \"\\\\/\",\n \"\\\\#\"\n];\n\nexport const normalizeValue = (value: string) => {\n let result = value || \"\";\n for (const character of specialCharacterToSpace) {\n result = result.replace(new RegExp(character, \"g\"), \" \");\n }\n\n for (const character of specialCharacters) {\n result = result.replace(new RegExp(character, \"g\"), `\\\\${character}`);\n }\n\n return result || \"\";\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AAEA,MAAMA,uBAAuB,GAAG,CAAC,GAAD,CAAhC;AAEA,MAAMC,iBAAiB,GAAG,CACtB,MADsB,EAEtB,KAFsB,EAGtB;AACA,KAJsB,EAKtB,QALsB,EAMtB,QANsB,EAOtB,GAPsB,EAQtB,GARsB,EAStB,KATsB,EAUtB,KAVsB,EAWtB,KAXsB,EAYtB,KAZsB,EAatB,KAbsB,EActB,KAdsB,EAetB,KAfsB,EAgBtB,KAhBsB,EAiBtB,KAjBsB,EAkBtB,KAlBsB,EAmBtB,KAnBsB,EAoBtB,KApBsB,EAqBtB,KArBsB,EAsBtB,KAtBsB,EAuBtB,KAvBsB,CAA1B;;AA0BO,MAAMC,cAAc,GAAIC,KAAD,IAAmB;EAC7C,IAAIC,MAAM,GAAGD,KAAK,IAAI,EAAtB;;EACA,KAAK,MAAME,SAAX,IAAwBL,uBAAxB,EAAiD;IAC7CI,MAAM,GAAGA,MAAM,CAACE,OAAP,CAAe,IAAIC,MAAJ,CAAWF,SAAX,EAAsB,GAAtB,CAAf,EAA2C,GAA3C,CAAT;EACH;;EAED,KAAK,MAAMA,SAAX,IAAwBJ,iBAAxB,EAA2C;IACvCG,MAAM,GAAGA,MAAM,CAACE,OAAP,CAAe,IAAIC,MAAJ,CAAWF,SAAX,EAAsB,GAAtB,CAAf,EAA4C,KAAIA,SAAU,EAA1D,CAAT;EACH;;EAED,OAAOD,MAAM,IAAI,EAAjB;AACH,CAXM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-elasticsearch",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.6509387258",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/webiny/webiny-js.git",
|
|
@@ -13,19 +13,19 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@elastic/elasticsearch": "7.12.0",
|
|
16
|
-
"@webiny/api": "0.0.0-unstable.
|
|
17
|
-
"@webiny/error": "0.0.0-unstable.
|
|
18
|
-
"@webiny/plugins": "0.0.0-unstable.
|
|
19
|
-
"@webiny/utils": "0.0.0-unstable.
|
|
16
|
+
"@webiny/api": "0.0.0-unstable.6509387258",
|
|
17
|
+
"@webiny/error": "0.0.0-unstable.6509387258",
|
|
18
|
+
"@webiny/plugins": "0.0.0-unstable.6509387258",
|
|
19
|
+
"@webiny/utils": "0.0.0-unstable.6509387258",
|
|
20
20
|
"aws-elasticsearch-connector": "9.2.0",
|
|
21
|
-
"aws-sdk": "2.
|
|
21
|
+
"aws-sdk": "2.1310.0",
|
|
22
22
|
"elastic-ts": "0.8.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/cli": "^7.19.3",
|
|
26
26
|
"@babel/core": "^7.19.3",
|
|
27
|
-
"@webiny/cli": "^0.0.0-unstable.
|
|
28
|
-
"@webiny/project-utils": "^0.0.0-unstable.
|
|
27
|
+
"@webiny/cli": "^0.0.0-unstable.6509387258",
|
|
28
|
+
"@webiny/project-utils": "^0.0.0-unstable.6509387258",
|
|
29
29
|
"rimraf": "^3.0.2",
|
|
30
30
|
"ttypescript": "^1.5.12",
|
|
31
31
|
"typescript": "4.7.4"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
]
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "6509387258f8fe18e270a16d0f5b89ba4134f088"
|
|
49
49
|
}
|
|
@@ -32,7 +32,7 @@ class ElasticsearchQueryBuilderOperatorContainsPlugin extends _ElasticsearchQuer
|
|
|
32
32
|
query_string: {
|
|
33
33
|
allow_leading_wildcard: true,
|
|
34
34
|
fields: [basePath],
|
|
35
|
-
query: (0, _normalize.normalizeValue)(value)
|
|
35
|
+
query: `*${(0, _normalize.normalizeValue)(value)}*`,
|
|
36
36
|
default_operator: "and"
|
|
37
37
|
}
|
|
38
38
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ElasticsearchQueryBuilderOperatorContainsPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","must","push","query_string","allow_leading_wildcard","fields","normalizeValue","default_operator"],"sources":["contains.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { normalizeValue } from \"~/normalize\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.contains.default\";\n\n public getOperator(): string {\n return \"contains\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath } = params;\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: [basePath],\n query: normalizeValue(value)
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorContainsPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","must","push","query_string","allow_leading_wildcard","fields","normalizeValue","default_operator"],"sources":["contains.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { normalizeValue } from \"~/normalize\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.contains.default\";\n\n public getOperator(): string {\n return \"contains\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath } = params;\n query.must.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: [basePath],\n query: `*${normalizeValue(value)}*`,\n default_operator: \"and\"\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGO,MAAMA,+CAAN,SAA8DC,gFAA9D,CAAsG;EAAA;IAAA;IAAA,4CAClF,sDADkF;EAAA;;EAGlGC,WAAW,GAAW;IACzB,OAAO,UAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAsBF,MAA5B;IACAD,KAAK,CAACI,IAAN,CAAWC,IAAX,CAAgB;MACZC,YAAY,EAAE;QACVC,sBAAsB,EAAE,IADd;QAEVC,MAAM,EAAE,CAACL,QAAD,CAFE;QAGVH,KAAK,EAAG,IAAG,IAAAS,yBAAA,EAAeP,KAAf,CAAsB,GAHvB;QAIVQ,gBAAgB,EAAE;MAJR;IADF,CAAhB;EAQH;;AApBwG"}
|
|
@@ -39,14 +39,14 @@ class ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin extends _Elasticse
|
|
|
39
39
|
const value = (0, _normalize.normalizeValue)(initialValue);
|
|
40
40
|
query.must.push({
|
|
41
41
|
multi_match: {
|
|
42
|
-
query: value
|
|
42
|
+
query: `*${value}*`,
|
|
43
43
|
type: "phrase",
|
|
44
44
|
fields: [`${basePath}.ngram`]
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
query.should.push({
|
|
48
48
|
multi_match: {
|
|
49
|
-
query: value
|
|
49
|
+
query: `*${value}*`,
|
|
50
50
|
type: "phrase",
|
|
51
51
|
fields: [`${basePath}`]
|
|
52
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin","ElasticsearchQueryBuilderOperatorPlugin","isLocaleSupported","code","includes","toLowerCase","getOperator","apply","query","params","value","initialValue","basePath","normalizeValue","must","push","multi_match","type","fields","should"],"sources":["contains.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { normalizeValue } from \"~/normalize\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.contains.japanese\";\n\n public override isLocaleSupported(code: string): boolean {\n if (!code) {\n return false;\n }\n return [\"ja\", \"ja-jp\"].includes(code.toLowerCase());\n }\n\n public getOperator(): string {\n return \"contains\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value: initialValue, basePath } = params;\n\n const value = normalizeValue(initialValue);\n query.must.push({\n multi_match: {\n query: value
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin","ElasticsearchQueryBuilderOperatorPlugin","isLocaleSupported","code","includes","toLowerCase","getOperator","apply","query","params","value","initialValue","basePath","normalizeValue","must","push","multi_match","type","fields","should"],"sources":["contains.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { normalizeValue } from \"~/normalize\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.contains.japanese\";\n\n public override isLocaleSupported(code: string): boolean {\n if (!code) {\n return false;\n }\n return [\"ja\", \"ja-jp\"].includes(code.toLowerCase());\n }\n\n public getOperator(): string {\n return \"contains\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value: initialValue, basePath } = params;\n\n const value = normalizeValue(initialValue);\n query.must.push({\n multi_match: {\n query: `*${value}*`,\n type: \"phrase\",\n fields: [`${basePath}.ngram`]\n }\n });\n query.should.push({\n multi_match: {\n query: `*${value}*`,\n type: \"phrase\",\n fields: [`${basePath}`]\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGO,MAAMA,uDAAN,SAAsEC,gFAAtE,CAA8G;EAAA;IAAA;IAAA,4CAC1F,uDAD0F;EAAA;;EAGjGC,iBAAiB,CAACC,IAAD,EAAwB;IACrD,IAAI,CAACA,IAAL,EAAW;MACP,OAAO,KAAP;IACH;;IACD,OAAO,CAAC,IAAD,EAAO,OAAP,EAAgBC,QAAhB,CAAyBD,IAAI,CAACE,WAAL,EAAzB,CAAP;EACH;;EAEMC,WAAW,GAAW;IACzB,OAAO,UAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAK,EAAEC,YAAT;MAAuBC;IAAvB,IAAoCH,MAA1C;IAEA,MAAMC,KAAK,GAAG,IAAAG,yBAAA,EAAeF,YAAf,CAAd;IACAH,KAAK,CAACM,IAAN,CAAWC,IAAX,CAAgB;MACZC,WAAW,EAAE;QACTR,KAAK,EAAG,IAAGE,KAAM,GADR;QAETO,IAAI,EAAE,QAFG;QAGTC,MAAM,EAAE,CAAE,GAAEN,QAAS,QAAb;MAHC;IADD,CAAhB;IAOAJ,KAAK,CAACW,MAAN,CAAaJ,IAAb,CAAkB;MACdC,WAAW,EAAE;QACTR,KAAK,EAAG,IAAGE,KAAM,GADR;QAETO,IAAI,EAAE,QAFG;QAGTC,MAAM,EAAE,CAAE,GAAEN,QAAS,EAAb;MAHC;IADC,CAAlB;EAOH;;AAnCgH"}
|
|
@@ -32,7 +32,7 @@ class ElasticsearchQueryBuilderOperatorNotContainsPlugin extends _ElasticsearchQ
|
|
|
32
32
|
query_string: {
|
|
33
33
|
allow_leading_wildcard: true,
|
|
34
34
|
fields: [basePath],
|
|
35
|
-
query: (0, _normalize.normalizeValue)(value)
|
|
35
|
+
query: `*${(0, _normalize.normalizeValue)(value)}*`,
|
|
36
36
|
default_operator: "and"
|
|
37
37
|
}
|
|
38
38
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["ElasticsearchQueryBuilderOperatorNotContainsPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","must_not","push","query_string","allow_leading_wildcard","fields","normalizeValue","default_operator"],"sources":["notContains.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { normalizeValue } from \"~/normalize\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorNotContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.notContains.default\";\n\n public getOperator(): string {\n return \"not_contains\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath } = params;\n query.must_not.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: [basePath],\n query: normalizeValue(value)
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorNotContainsPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","must_not","push","query_string","allow_leading_wildcard","fields","normalizeValue","default_operator"],"sources":["notContains.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { normalizeValue } from \"~/normalize\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorNotContainsPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.notContains.default\";\n\n public getOperator(): string {\n return \"not_contains\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath } = params;\n query.must_not.push({\n query_string: {\n allow_leading_wildcard: true,\n fields: [basePath],\n query: `*${normalizeValue(value)}*`,\n default_operator: \"and\"\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAGO,MAAMA,kDAAN,SAAiEC,gFAAjE,CAAyG;EAAA;IAAA;IAAA,4CACrF,yDADqF;EAAA;;EAGrGC,WAAW,GAAW;IACzB,OAAO,cAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAsBF,MAA5B;IACAD,KAAK,CAACI,QAAN,CAAeC,IAAf,CAAoB;MAChBC,YAAY,EAAE;QACVC,sBAAsB,EAAE,IADd;QAEVC,MAAM,EAAE,CAACL,QAAD,CAFE;QAGVH,KAAK,EAAG,IAAG,IAAAS,yBAAA,EAAeP,KAAf,CAAsB,GAHvB;QAIVQ,gBAAgB,EAAE;MAJR;IADE,CAApB;EAQH;;AApB2G"}
|
package/sort.js
CHANGED
|
@@ -9,6 +9,8 @@ exports.createSort = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
11
|
|
|
12
|
+
var _plugins = require("./plugins");
|
|
13
|
+
|
|
12
14
|
const sortRegExp = new RegExp(/^([a-zA-Z-0-9_@]+)_(ASC|DESC)$/);
|
|
13
15
|
|
|
14
16
|
const createSort = params => {
|
|
@@ -53,7 +55,7 @@ const createSort = params => {
|
|
|
53
55
|
|
|
54
56
|
const [, field, initialOrder] = match;
|
|
55
57
|
const order = initialOrder.toLowerCase() === "asc" ? "asc" : "desc";
|
|
56
|
-
const plugin = fieldPlugins[field] || fieldPlugins[
|
|
58
|
+
const plugin = fieldPlugins[field] || fieldPlugins[_plugins.ElasticsearchFieldPlugin.ALL];
|
|
57
59
|
|
|
58
60
|
if (!plugin) {
|
|
59
61
|
throw new _error.default(`Missing plugin for the field "${field}"`, "PLUGIN_SORT_ERROR", {
|
package/sort.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["sortRegExp","RegExp","createSort","params","sort","defaults","fieldPlugins","length","field","order","unmappedType","unmapped_type","undefined","reduce","acc","value","WebinyError","match","initialOrder","toLowerCase","plugin","path","getPath","getSortOptions"],"sources":["sort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { FieldSortOptions, SortType, SortOrder } from \"~/types\";\nimport { ElasticsearchFieldPlugin } from \"~/plugins\";\n\nconst sortRegExp = new RegExp(/^([a-zA-Z-0-9_@]+)_(ASC|DESC)$/);\n\ninterface CreateSortParams {\n sort: string[];\n defaults?: {\n field?: string;\n order?: SortOrder;\n unmappedType?: string;\n };\n fieldPlugins: Record<string, ElasticsearchFieldPlugin>;\n}\n\nexport const createSort = (params: CreateSortParams): SortType => {\n const { sort, defaults, fieldPlugins } = params;\n if (!sort || sort.length === 0) {\n const { field, order, unmappedType } = defaults || {};\n /**\n * We say that our system defaults is always id since all records we create have some kind of primary ID.\n */\n return {\n [field || \"id.keyword\"]: {\n order: order || \"desc\",\n unmapped_type: unmappedType || undefined\n }\n };\n }\n /**\n * Cast as string because nothing else should be allowed yet.\n */\n return sort.reduce((acc, value) => {\n if (typeof value !== \"string\") {\n throw new WebinyError(`Sort as object is not supported..`);\n }\n const match = value.match(sortRegExp);\n\n if (!match) {\n throw new WebinyError(`Cannot sort by \"${value}\".`);\n }\n\n const [, field, initialOrder] = match;\n const order: SortOrder = initialOrder.toLowerCase() === \"asc\" ? \"asc\" : \"desc\";\n\n const plugin: ElasticsearchFieldPlugin
|
|
1
|
+
{"version":3,"names":["sortRegExp","RegExp","createSort","params","sort","defaults","fieldPlugins","length","field","order","unmappedType","unmapped_type","undefined","reduce","acc","value","WebinyError","match","initialOrder","toLowerCase","plugin","ElasticsearchFieldPlugin","ALL","path","getPath","getSortOptions"],"sources":["sort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { FieldSortOptions, SortType, SortOrder } from \"~/types\";\nimport { ElasticsearchFieldPlugin } from \"~/plugins\";\n\nconst sortRegExp = new RegExp(/^([a-zA-Z-0-9_@]+)_(ASC|DESC)$/);\n\ninterface CreateSortParams {\n sort: string[];\n defaults?: {\n field?: string;\n order?: SortOrder;\n unmappedType?: string;\n };\n fieldPlugins: Record<string, ElasticsearchFieldPlugin>;\n}\n\nexport const createSort = (params: CreateSortParams): SortType => {\n const { sort, defaults, fieldPlugins } = params;\n if (!sort || sort.length === 0) {\n const { field, order, unmappedType } = defaults || {};\n /**\n * We say that our system defaults is always id since all records we create have some kind of primary ID.\n */\n return {\n [field || \"id.keyword\"]: {\n order: order || \"desc\",\n unmapped_type: unmappedType || undefined\n }\n };\n }\n /**\n * Cast as string because nothing else should be allowed yet.\n */\n return sort.reduce((acc, value) => {\n if (typeof value !== \"string\") {\n throw new WebinyError(`Sort as object is not supported..`);\n }\n const match = value.match(sortRegExp);\n\n if (!match) {\n throw new WebinyError(`Cannot sort by \"${value}\".`);\n }\n\n const [, field, initialOrder] = match;\n const order: SortOrder = initialOrder.toLowerCase() === \"asc\" ? \"asc\" : \"desc\";\n\n const plugin: ElasticsearchFieldPlugin =\n fieldPlugins[field] || fieldPlugins[ElasticsearchFieldPlugin.ALL];\n if (!plugin) {\n throw new WebinyError(`Missing plugin for the field \"${field}\"`, \"PLUGIN_SORT_ERROR\", {\n field\n });\n }\n /**\n * In case field plugin is the global one, change the * with actual field name.\n * Custom path methods will return their own values anyway so replacing * will not matter.\n */\n const path = plugin.getPath(field);\n\n acc[path] = plugin.getSortOptions(order);\n\n return acc;\n }, {} as Record<string, FieldSortOptions>);\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AAEA,MAAMA,UAAU,GAAG,IAAIC,MAAJ,CAAW,gCAAX,CAAnB;;AAYO,MAAMC,UAAU,GAAIC,MAAD,IAAwC;EAC9D,MAAM;IAAEC,IAAF;IAAQC,QAAR;IAAkBC;EAAlB,IAAmCH,MAAzC;;EACA,IAAI,CAACC,IAAD,IAASA,IAAI,CAACG,MAAL,KAAgB,CAA7B,EAAgC;IAC5B,MAAM;MAAEC,KAAF;MAASC,KAAT;MAAgBC;IAAhB,IAAiCL,QAAQ,IAAI,EAAnD;IACA;AACR;AACA;;IACQ,OAAO;MACH,CAACG,KAAK,IAAI,YAAV,GAAyB;QACrBC,KAAK,EAAEA,KAAK,IAAI,MADK;QAErBE,aAAa,EAAED,YAAY,IAAIE;MAFV;IADtB,CAAP;EAMH;EACD;AACJ;AACA;;;EACI,OAAOR,IAAI,CAACS,MAAL,CAAY,CAACC,GAAD,EAAMC,KAAN,KAAgB;IAC/B,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;MAC3B,MAAM,IAAIC,cAAJ,CAAiB,mCAAjB,CAAN;IACH;;IACD,MAAMC,KAAK,GAAGF,KAAK,CAACE,KAAN,CAAYjB,UAAZ,CAAd;;IAEA,IAAI,CAACiB,KAAL,EAAY;MACR,MAAM,IAAID,cAAJ,CAAiB,mBAAkBD,KAAM,IAAzC,CAAN;IACH;;IAED,MAAM,GAAGP,KAAH,EAAUU,YAAV,IAA0BD,KAAhC;IACA,MAAMR,KAAgB,GAAGS,YAAY,CAACC,WAAb,OAA+B,KAA/B,GAAuC,KAAvC,GAA+C,MAAxE;IAEA,MAAMC,MAAgC,GAClCd,YAAY,CAACE,KAAD,CAAZ,IAAuBF,YAAY,CAACe,iCAAA,CAAyBC,GAA1B,CADvC;;IAEA,IAAI,CAACF,MAAL,EAAa;MACT,MAAM,IAAIJ,cAAJ,CAAiB,iCAAgCR,KAAM,GAAvD,EAA2D,mBAA3D,EAAgF;QAClFA;MADkF,CAAhF,CAAN;IAGH;IACD;AACR;AACA;AACA;;;IACQ,MAAMe,IAAI,GAAGH,MAAM,CAACI,OAAP,CAAehB,KAAf,CAAb;IAEAM,GAAG,CAACS,IAAD,CAAH,GAAYH,MAAM,CAACK,cAAP,CAAsBhB,KAAtB,CAAZ;IAEA,OAAOK,GAAP;EACH,CA7BM,EA6BJ,EA7BI,CAAP;AA8BH,CA/CM"}
|