@webiny/api-elasticsearch 5.34.0-beta.2 → 5.34.1-beta.0
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 +8 -2
- package/normalize.js.map +1 -1
- package/package.json +8 -8
- package/sort.js +3 -1
- package/sort.js.map +1 -1
package/normalize.js
CHANGED
|
@@ -9,10 +9,16 @@ 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}`);
|
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 ? `*${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,GAAI,IAAGA,MAAO,GAAd,GAAmB,EAAhC;AACH,CAXM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-elasticsearch",
|
|
3
|
-
"version": "5.34.
|
|
3
|
+
"version": "5.34.1-beta.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/webiny/webiny-js.git",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@elastic/elasticsearch": "7.12.0",
|
|
16
|
-
"@webiny/api": "5.34.
|
|
17
|
-
"@webiny/error": "5.34.
|
|
18
|
-
"@webiny/plugins": "5.34.
|
|
19
|
-
"@webiny/utils": "5.34.
|
|
16
|
+
"@webiny/api": "5.34.1-beta.0",
|
|
17
|
+
"@webiny/error": "5.34.1-beta.0",
|
|
18
|
+
"@webiny/plugins": "5.34.1-beta.0",
|
|
19
|
+
"@webiny/utils": "5.34.1-beta.0",
|
|
20
20
|
"aws-elasticsearch-connector": "9.2.0",
|
|
21
21
|
"aws-sdk": "2.1230.0",
|
|
22
22
|
"elastic-ts": "0.8.0"
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/cli": "^7.16.0",
|
|
26
26
|
"@babel/core": "^7.16.0",
|
|
27
|
-
"@webiny/cli": "^5.34.
|
|
28
|
-
"@webiny/project-utils": "^5.34.
|
|
27
|
+
"@webiny/cli": "^5.34.1-beta.0",
|
|
28
|
+
"@webiny/project-utils": "^5.34.1-beta.0",
|
|
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": "c893b6c771e45d4b2ea13da4f17455abdaef8239"
|
|
49
49
|
}
|
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,CAAC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