@webiny/api-elasticsearch 5.37.4 → 5.37.5-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/normalize.js +16 -3
- package/normalize.js.map +1 -1
- package/package.json +8 -8
package/normalize.js
CHANGED
|
@@ -9,12 +9,19 @@ exports.normalizeValueWithAsterisk = exports.normalizeValue = void 0;
|
|
|
9
9
|
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
const specialCharactersToRemove = [`\\?`];
|
|
12
13
|
const specialCharacterToSpace = ["-"];
|
|
13
14
|
const specialCharacters = ["\\\\", "\\+",
|
|
14
15
|
// "\\-",
|
|
15
|
-
"\\=",
|
|
16
|
+
"\\=", `\&`, `\\|`, ">", "<", `\!`, "\\(", "\\)", "\\{", "\\}", "\\[", "\\]", "\\^", '\\"', "\\~", "\\*", `\:`, `\/`, "\\#"];
|
|
16
17
|
const normalizeValue = value => {
|
|
17
18
|
let result = value || "";
|
|
19
|
+
if (!result) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
for (const character of specialCharactersToRemove) {
|
|
23
|
+
result = result.replace(new RegExp(character, "g"), "");
|
|
24
|
+
}
|
|
18
25
|
for (const character of specialCharacterToSpace) {
|
|
19
26
|
result = result.replace(new RegExp(character, "g"), " ");
|
|
20
27
|
}
|
|
@@ -24,6 +31,12 @@ const normalizeValue = value => {
|
|
|
24
31
|
return result || "";
|
|
25
32
|
};
|
|
26
33
|
exports.normalizeValue = normalizeValue;
|
|
34
|
+
const hasSpecialChar = value => {
|
|
35
|
+
if (!value) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return value.match(/^([0-9a-zA-Z]+)$/i) === null;
|
|
39
|
+
};
|
|
27
40
|
const normalizeValueWithAsterisk = initial => {
|
|
28
41
|
const value = normalizeValue(initial);
|
|
29
42
|
const results = value.split(" ");
|
|
@@ -32,14 +45,14 @@ const normalizeValueWithAsterisk = initial => {
|
|
|
32
45
|
* If there is a / in the first word, do not put asterisk in front of it.
|
|
33
46
|
*/
|
|
34
47
|
const firstWord = results[0];
|
|
35
|
-
if (firstWord
|
|
48
|
+
if (hasSpecialChar(firstWord) === false) {
|
|
36
49
|
result = `*${result}`;
|
|
37
50
|
}
|
|
38
51
|
/**
|
|
39
52
|
* If there is a / in the last word, do not put asterisk at the end of it.
|
|
40
53
|
*/
|
|
41
54
|
const lastWord = results[results.length - 1];
|
|
42
|
-
if (lastWord
|
|
55
|
+
if (hasSpecialChar(lastWord) === false) {
|
|
43
56
|
result = `${result}*`;
|
|
44
57
|
}
|
|
45
58
|
return result;
|
package/normalize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["specialCharacterToSpace","specialCharacters","normalizeValue","value","result","character","replace","RegExp","exports","normalizeValueWithAsterisk","initial","results","split","firstWord","
|
|
1
|
+
{"version":3,"names":["specialCharactersToRemove","specialCharacterToSpace","specialCharacters","normalizeValue","value","result","character","replace","RegExp","exports","hasSpecialChar","match","normalizeValueWithAsterisk","initial","results","split","firstWord","lastWord","length"],"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 specialCharactersToRemove = [`\\\\?`];\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\nexport const normalizeValue = (value: string) => {\n let result = value || \"\";\n if (!result) {\n return result;\n }\n for (const character of specialCharactersToRemove) {\n result = result.replace(new RegExp(character, \"g\"), \"\");\n }\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\nconst hasSpecialChar = (value: string): boolean | null => {\n if (!value) {\n return null;\n }\n return value.match(/^([0-9a-zA-Z]+)$/i) === null;\n};\n\nexport const normalizeValueWithAsterisk = (initial: string) => {\n const value = normalizeValue(initial);\n const results = value.split(\" \");\n\n let result = value;\n /**\n * If there is a / in the first word, do not put asterisk in front of it.\n */\n const firstWord = results[0];\n if (hasSpecialChar(firstWord) === false) {\n result = `*${result}`;\n }\n /**\n * If there is a / in the last word, do not put asterisk at the end of it.\n */\n const lastWord = results[results.length - 1];\n if (hasSpecialChar(lastWord) === false) {\n result = `${result}*`;\n }\n\n return result;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;;AAEA,MAAMA,yBAAyB,GAAG,CAAE,KAAI,CAAC;AAEzC,MAAMC,uBAAuB,GAAG,CAAC,GAAG,CAAC;AAErC,MAAMC,iBAAiB,GAAG,CACtB,MAAM,EACN,KAAK;AACL;AACA,KAAK,EACJ,IAAG,EACH,KAAI,EACL,GAAG,EACH,GAAG,EACF,IAAG,EACJ,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACJ,IAAG,EACH,IAAG,EACJ,KAAK,CACR;AAEM,MAAMC,cAAc,GAAIC,KAAa,IAAK;EAC7C,IAAIC,MAAM,GAAGD,KAAK,IAAI,EAAE;EACxB,IAAI,CAACC,MAAM,EAAE;IACT,OAAOA,MAAM;EACjB;EACA,KAAK,MAAMC,SAAS,IAAIN,yBAAyB,EAAE;IAC/CK,MAAM,GAAGA,M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AOA,MAAM;AACjB,CAAC;AAACI,OAAA,CAAAG,0BAAA,GAAAA,0BAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-elasticsearch",
|
|
3
|
-
"version": "5.37.
|
|
3
|
+
"version": "5.37.5-beta.1",
|
|
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.37.
|
|
17
|
-
"@webiny/error": "5.37.
|
|
18
|
-
"@webiny/plugins": "5.37.
|
|
19
|
-
"@webiny/utils": "5.37.
|
|
16
|
+
"@webiny/api": "5.37.5-beta.1",
|
|
17
|
+
"@webiny/error": "5.37.5-beta.1",
|
|
18
|
+
"@webiny/plugins": "5.37.5-beta.1",
|
|
19
|
+
"@webiny/utils": "5.37.5-beta.1",
|
|
20
20
|
"aws-elasticsearch-connector": "9.2.0",
|
|
21
21
|
"aws-sdk": "2.1310.0",
|
|
22
22
|
"elastic-ts": "0.8.0"
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/cli": "7.22.6",
|
|
26
26
|
"@babel/core": "7.22.8",
|
|
27
|
-
"@webiny/cli": "5.37.
|
|
28
|
-
"@webiny/project-utils": "5.37.
|
|
27
|
+
"@webiny/cli": "5.37.5-beta.1",
|
|
28
|
+
"@webiny/project-utils": "5.37.5-beta.1",
|
|
29
29
|
"rimraf": "3.0.2",
|
|
30
30
|
"ttypescript": "1.5.15",
|
|
31
31
|
"typescript": "4.7.4"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
]
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "88829ab0c5d875491d6b260f184b7b7fe3a6d449"
|
|
49
49
|
}
|