@webiny/api-elasticsearch 0.0.0-unstable.b14eaecf38 → 0.0.0-unstable.b6408e0dea
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/package.json +8 -8
- package/where.js +1 -1
- package/where.js.map +1 -1
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.b6408e0dea",
|
|
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": "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.b6408e0dea",
|
|
17
|
+
"@webiny/error": "0.0.0-unstable.b6408e0dea",
|
|
18
|
+
"@webiny/plugins": "0.0.0-unstable.b6408e0dea",
|
|
19
|
+
"@webiny/utils": "0.0.0-unstable.b6408e0dea",
|
|
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.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.b6408e0dea",
|
|
28
|
+
"@webiny/project-utils": "^0.0.0-unstable.b6408e0dea",
|
|
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": "b6408e0deaa6ea55327b8bb35391d9ea71afee65"
|
|
49
49
|
}
|
package/where.js
CHANGED
|
@@ -14,7 +14,7 @@ const parseWhereKey = key => {
|
|
|
14
14
|
throw new Error(`It is not possible to search by key "${key}"`);
|
|
15
15
|
}
|
|
16
16
|
const [, field, operation = "eq"] = match;
|
|
17
|
-
if (!field.match(/^([a-zA-
|
|
17
|
+
if (!field.match(/^([a-zA-Z0-9]+)$/)) {
|
|
18
18
|
throw new Error(`Cannot filter by "${field}".`);
|
|
19
19
|
}
|
|
20
20
|
const operator = operation.match(/^_/) ? operation.slice(1) : operation;
|
package/where.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["parseWhereKeyRegExp","RegExp","parseWhereKey","key","match","Error","field","operation","operator","slice","ALL","ElasticsearchFieldPlugin","applyWhere","params","query","where","fields","operators","hasOwnProperty","initialValue","undefined","fieldPlugin","WebinyError","operatorPlugin","path","getPath","basePath","getBasePath","value","toSearchValue","apply","name","keyword"],"sources":["where.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"~/types\";\nimport { ElasticsearchFieldPlugin } from \"~/plugins/definition/ElasticsearchFieldPlugin\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport WebinyError from \"@webiny/error\";\n\ntype Records<T> = Record<string, T>;\n\nexport interface ApplyWhereParams {\n query: ElasticsearchBoolQueryConfig;\n where: Records<any>;\n fields: Records<ElasticsearchFieldPlugin>;\n operators: Records<ElasticsearchQueryBuilderOperatorPlugin>;\n}\n\nexport interface ParseWhereKeyResult {\n field: string;\n operator: string;\n}\n\nconst parseWhereKeyRegExp = new RegExp(/^([a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);\n\nexport const parseWhereKey = (key: string): ParseWhereKeyResult => {\n const match = key.match(parseWhereKeyRegExp);\n\n if (!match) {\n throw new Error(`It is not possible to search by key \"${key}\"`);\n }\n\n const [, field, operation = \"eq\"] = match;\n\n if (!field.match(/^([a-zA-
|
|
1
|
+
{"version":3,"names":["parseWhereKeyRegExp","RegExp","parseWhereKey","key","match","Error","field","operation","operator","slice","ALL","ElasticsearchFieldPlugin","applyWhere","params","query","where","fields","operators","hasOwnProperty","initialValue","undefined","fieldPlugin","WebinyError","operatorPlugin","path","getPath","basePath","getBasePath","value","toSearchValue","apply","name","keyword"],"sources":["where.ts"],"sourcesContent":["import { ElasticsearchBoolQueryConfig } from \"~/types\";\nimport { ElasticsearchFieldPlugin } from \"~/plugins/definition/ElasticsearchFieldPlugin\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport WebinyError from \"@webiny/error\";\n\ntype Records<T> = Record<string, T>;\n\nexport interface ApplyWhereParams {\n query: ElasticsearchBoolQueryConfig;\n where: Records<any>;\n fields: Records<ElasticsearchFieldPlugin>;\n operators: Records<ElasticsearchQueryBuilderOperatorPlugin>;\n}\n\nexport interface ParseWhereKeyResult {\n field: string;\n operator: string;\n}\n\nconst parseWhereKeyRegExp = new RegExp(/^([a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);\n\nexport const parseWhereKey = (key: string): ParseWhereKeyResult => {\n const match = key.match(parseWhereKeyRegExp);\n\n if (!match) {\n throw new Error(`It is not possible to search by key \"${key}\"`);\n }\n\n const [, field, operation = \"eq\"] = match;\n\n if (!field.match(/^([a-zA-Z0-9]+)$/)) {\n throw new Error(`Cannot filter by \"${field}\".`);\n }\n\n const operator = operation.match(/^_/) ? operation.slice(1) : operation;\n\n return { field, operator };\n};\n\nconst ALL = ElasticsearchFieldPlugin.ALL;\n\nexport const applyWhere = (params: ApplyWhereParams): void => {\n const { query, where, fields, operators } = params;\n\n for (const key in where) {\n if (where.hasOwnProperty(key) === false) {\n continue;\n }\n const initialValue = where[key];\n /**\n * There is a possibility that undefined is sent as a value, so just skip it.\n */\n if (initialValue === undefined) {\n continue;\n }\n const { field, operator } = parseWhereKey(key);\n const fieldPlugin: ElasticsearchFieldPlugin = fields[field] || fields[ALL];\n if (!fieldPlugin) {\n throw new WebinyError(\n `Missing plugin for the field \"${field}\".`,\n \"PLUGIN_WHERE_ERROR\",\n {\n field\n }\n );\n }\n const operatorPlugin = operators[operator];\n if (!operatorPlugin) {\n throw new WebinyError(\n `Missing plugin for the operator \"${operator}\"`,\n \"PLUGIN_WHERE_ERROR\",\n {\n operator\n }\n );\n }\n\n /**\n * Get the path but in the case of * (all fields, replace * with the field.\n * Custom path would return its own value anyways.\n */\n const path = fieldPlugin.getPath(field);\n const basePath = fieldPlugin.getBasePath(field);\n /**\n * Transform the value for the search.\n */\n const value = fieldPlugin.toSearchValue({\n value: initialValue,\n path,\n basePath\n });\n\n operatorPlugin.apply(query, {\n name: field,\n value,\n path,\n basePath,\n keyword: fieldPlugin.keyword\n });\n }\n};\n"],"mappings":";;;;;;;AACA;AAEA;AAgBA,MAAMA,mBAAmB,GAAG,IAAIC,MAAM,CAAC,mCAAmC,CAAC;AAEpE,MAAMC,aAAa,GAAIC,GAAW,IAA0B;EAC/D,MAAMC,KAAK,GAAGD,GAAG,CAACC,KAAK,CAACJ,mBAAmB,CAAC;EAE5C,IAAI,CAACI,KAAK,EAAE;IACR,MAAM,IAAIC,KAAK,CAAE,wCAAuCF,GAAI,GAAE,CAAC;EACnE;EAEA,MAAM,GAAGG,KAAK,EAAEC,SAAS,GAAG,IAAI,CAAC,GAAGH,KAAK;EAEzC,IAAI,CAACE,KAAK,CAACF,KAAK,CAAC,kBAAkB,CAAC,EAAE;IAClC,MAAM,IAAI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