@webiny/api-elasticsearch 0.0.0-unstable.c59b9cc5b9 → 0.0.0-unstable.c7dec08bb0
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/plugins/GzipCompression.d.ts +1 -1
- package/plugins/GzipCompression.js.map +1 -1
- package/where.js +5 -2
- 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.c7dec08bb0",
|
|
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.c7dec08bb0",
|
|
17
|
+
"@webiny/error": "0.0.0-unstable.c7dec08bb0",
|
|
18
|
+
"@webiny/plugins": "0.0.0-unstable.c7dec08bb0",
|
|
19
|
+
"@webiny/utils": "0.0.0-unstable.c7dec08bb0",
|
|
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.20.7",
|
|
26
26
|
"@babel/core": "7.20.12",
|
|
27
|
-
"@webiny/cli": "0.0.0-unstable.
|
|
28
|
-
"@webiny/project-utils": "0.0.0-unstable.
|
|
27
|
+
"@webiny/cli": "0.0.0-unstable.c7dec08bb0",
|
|
28
|
+
"@webiny/project-utils": "0.0.0-unstable.c7dec08bb0",
|
|
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": "c7dec08bb095467cca6a61381bd399d66b7bb147"
|
|
49
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","GzipCompression","CompressionPlugin","canCompress","data","compression","console","log","compress","gzip","JSON","stringify","toString","canDecompress","decompress","buf","ungzip","parse","ex","createGzipCompression"],"sources":["GzipCompression.ts"],"sourcesContent":["import { CompressionPlugin } from \"~/plugins/definition/CompressionPlugin\";\nimport { compress as gzip, decompress as ungzip } from \"@webiny/utils/compression/gzip\";\n\nconst GZIP = \"gzip\";\nconst TO_STORAGE_ENCODING = \"base64\";\nconst FROM_STORAGE_ENCODING = \"utf8\";\n\nconst convertToBuffer = (value: string | Buffer) => {\n if (typeof value === \"string\") {\n return Buffer.from(value, TO_STORAGE_ENCODING);\n }\n return value;\n};\n\nexport interface CompressedData {\n compression: string;\n value: string;\n}\n\
|
|
1
|
+
{"version":3,"names":["GZIP","TO_STORAGE_ENCODING","FROM_STORAGE_ENCODING","convertToBuffer","value","Buffer","from","GzipCompression","CompressionPlugin","canCompress","data","compression","console","log","compress","gzip","JSON","stringify","toString","canDecompress","decompress","buf","ungzip","parse","ex","createGzipCompression"],"sources":["GzipCompression.ts"],"sourcesContent":["import { CompressionPlugin } from \"~/plugins/definition/CompressionPlugin\";\nimport { compress as gzip, decompress as ungzip } from \"@webiny/utils/compression/gzip\";\n\nconst GZIP = \"gzip\";\nconst TO_STORAGE_ENCODING = \"base64\";\nconst FROM_STORAGE_ENCODING = \"utf8\";\n\nconst convertToBuffer = (value: string | Buffer) => {\n if (typeof value === \"string\") {\n return Buffer.from(value, TO_STORAGE_ENCODING);\n }\n return value;\n};\n\nexport interface CompressedData {\n compression: string;\n value: string;\n}\n\nexport interface OriginalData {\n [key: string]: any;\n}\n\nclass GzipCompression extends CompressionPlugin {\n public canCompress(data: any): boolean {\n /**\n * If already compressed, skip this.\n */\n if (data.compression) {\n if (data.compression !== \"GZIP\") {\n console.log(`Data is already compressed with \"${data.compression}\".`);\n }\n return false;\n }\n return true;\n }\n public async compress(data: any) {\n const value = await gzip(JSON.stringify(data));\n\n return {\n compression: GZIP,\n value: value.toString(TO_STORAGE_ENCODING)\n };\n }\n\n public canDecompress(data: CompressedData | Record<string, any>): boolean {\n if (!data || !data.compression) {\n return false;\n } else if (data.compression !== GZIP) {\n console.log(\n `Could not decompress given data since its compression is not \"${GZIP}\". It is \"${data.compression}\".`\n );\n return false;\n }\n return true;\n }\n\n public async decompress(data: CompressedData): Promise<OriginalData | null> {\n try {\n const buf = await ungzip(convertToBuffer(data.value));\n const value = buf.toString(FROM_STORAGE_ENCODING);\n return JSON.parse(value);\n } catch (ex) {\n return null;\n }\n }\n}\n\nexport const createGzipCompression = () => {\n return new GzipCompression();\n};\n/**\n * Left due to backward compatibility with older systems.\n * Remove when upgraded the system to run from @webiny/api-serverless-cms-aws\n */\nexport default () => {\n return createGzipCompression();\n};\n"],"mappings":";;;;;;AAAA;AACA;AAEA,MAAMA,IAAI,GAAG,MAAM;AACnB,MAAMC,mBAAmB,GAAG,QAAQ;AACpC,MAAMC,qBAAqB,GAAG,MAAM;AAEpC,MAAMC,eAAe,GAAIC,KAAsB,IAAK;EAChD,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC3B,OAAOC,MAAM,CAACC,IAAI,CAACF,KAAK,EAAEH,mBAAmB,CAAC;EAClD;EACA,OAAOG,KAAK;AAChB,CAAC;AAWD,MAAMG,eAA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C,CAAC;AACD;AACA;AACA;AACA;AAHA;AAAA,eAIe,MAAM;EACjB,OAAOkB,qBAAqB,EAAE;AAClC,CAAC;AAAA"}
|
package/where.js
CHANGED
|
@@ -7,14 +7,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.parseWhereKey = exports.applyWhere = void 0;
|
|
8
8
|
var _ElasticsearchFieldPlugin = require("./plugins/definition/ElasticsearchFieldPlugin");
|
|
9
9
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* TODO remove the wbyAco prefix when we move the user fields to the values property.
|
|
12
|
+
*/
|
|
13
|
+
const parseWhereKeyRegExp = new RegExp(/^((?:wbyAco_)?[a-zA-Z0-9]+)(_[a-zA-Z0-9_]+)?$/);
|
|
11
14
|
const parseWhereKey = key => {
|
|
12
15
|
const match = key.match(parseWhereKeyRegExp);
|
|
13
16
|
if (!match) {
|
|
14
17
|
throw new Error(`It is not possible to search by key "${key}"`);
|
|
15
18
|
}
|
|
16
19
|
const [, field, operation = "eq"] = match;
|
|
17
|
-
if (!field.match(/^([a-zA-Z0-9]+)$/)) {
|
|
20
|
+
if (!field.match(/^(?:wbyAco_)?([a-zA-Z0-9]+)$/)) {
|
|
18
21
|
throw new Error(`Cannot filter by "${field}".`);
|
|
19
22
|
}
|
|
20
23
|
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-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,
|
|
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\n/**\n * TODO remove the wbyAco prefix when we move the user fields to the values property.\n */\nconst parseWhereKeyRegExp = new RegExp(/^((?:wbyAco_)?[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(/^(?:wbyAco_)?([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;AACA;AACA;AACA,MAAMA,mBAAmB,GAAG,IAAIC,MAAM,CAAC,+CAA+C,CAAC;AAEhF,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,KAA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