@webiny/api-elasticsearch 0.0.0-mt-2 → 0.0.0-unstable.13771d80a8
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/client.js +17 -9
- package/client.js.map +1 -0
- package/compression.js.map +1 -0
- package/cursors.d.ts +3 -2
- package/cursors.js +7 -1
- package/cursors.js.map +1 -0
- package/index.d.ts +14 -2
- package/index.js +169 -4
- package/index.js.map +1 -0
- package/indexConfiguration/base.d.ts +6 -0
- package/indexConfiguration/base.js +45 -0
- package/indexConfiguration/base.js.map +1 -0
- package/indexConfiguration/common.d.ts +9 -0
- package/indexConfiguration/common.js +45 -0
- package/indexConfiguration/common.js.map +1 -0
- package/indexConfiguration/index.d.ts +3 -0
- package/indexConfiguration/index.js +44 -0
- package/indexConfiguration/index.js.map +1 -0
- package/indexConfiguration/japanese.d.ts +6 -0
- package/indexConfiguration/japanese.js +124 -0
- package/indexConfiguration/japanese.js.map +1 -0
- package/indices.d.ts +9 -0
- package/indices.js +35 -0
- package/indices.js.map +1 -0
- package/limit.js.map +1 -0
- package/normalize.js +11 -8
- package/normalize.js.map +1 -0
- package/operators.d.ts +5 -14
- package/operators.js +41 -27
- package/operators.js.map +1 -0
- package/package.json +14 -14
- package/plugins/GzipCompression.d.ts +5 -0
- package/plugins/GzipCompression.js +13 -2
- package/plugins/GzipCompression.js.map +1 -0
- package/plugins/definition/CompressionPlugin.d.ts +1 -1
- package/plugins/definition/CompressionPlugin.js +1 -1
- package/plugins/definition/CompressionPlugin.js.map +1 -0
- package/plugins/definition/ElasticsearchBodyModifierPlugin.js +1 -1
- package/plugins/definition/ElasticsearchBodyModifierPlugin.js.map +1 -0
- package/plugins/definition/ElasticsearchFieldPlugin.d.ts +8 -14
- package/plugins/definition/ElasticsearchFieldPlugin.js +25 -49
- package/plugins/definition/ElasticsearchFieldPlugin.js.map +1 -0
- package/plugins/definition/ElasticsearchIndexPlugin.d.ts +18 -0
- package/plugins/definition/ElasticsearchIndexPlugin.js +46 -0
- package/plugins/definition/ElasticsearchIndexPlugin.js.map +1 -0
- package/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin.d.ts +5 -1
- package/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin.js +11 -2
- package/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin.js.map +1 -0
- package/plugins/definition/ElasticsearchQueryModifierPlugin.js +1 -1
- package/plugins/definition/ElasticsearchQueryModifierPlugin.js.map +1 -0
- package/plugins/definition/ElasticsearchSortModifierPlugin.js +1 -1
- package/plugins/definition/ElasticsearchSortModifierPlugin.js.map +1 -0
- package/plugins/definition/index.d.ts +7 -0
- package/plugins/definition/index.js +96 -0
- package/plugins/definition/index.js.map +1 -0
- package/plugins/index.d.ts +2 -0
- package/plugins/index.js +31 -0
- package/plugins/index.js.map +1 -0
- package/plugins/operator/andIn.js +2 -2
- package/plugins/operator/andIn.js.map +1 -0
- package/plugins/operator/between.js +6 -5
- package/plugins/operator/between.js.map +1 -0
- package/plugins/operator/contains.js +2 -2
- package/plugins/operator/contains.js.map +1 -0
- package/plugins/operator/equal.js +34 -5
- package/plugins/operator/equal.js.map +1 -0
- package/plugins/operator/gt.js +2 -2
- package/plugins/operator/gt.js.map +1 -0
- package/plugins/operator/gte.js +2 -2
- package/plugins/operator/gte.js.map +1 -0
- package/plugins/operator/in.js +7 -13
- package/plugins/operator/in.js.map +1 -0
- package/plugins/operator/index.d.ts +3 -0
- package/plugins/operator/index.js +39 -0
- package/plugins/operator/index.js.map +1 -0
- package/plugins/operator/japanese/contains.d.ts +8 -0
- package/plugins/operator/japanese/contains.js +58 -0
- package/plugins/operator/japanese/contains.js.map +1 -0
- package/plugins/operator/lt.js +2 -2
- package/plugins/operator/lt.js.map +1 -0
- package/plugins/operator/lte.js +2 -2
- package/plugins/operator/lte.js.map +1 -0
- package/plugins/operator/not.js +25 -3
- package/plugins/operator/not.js.map +1 -0
- package/plugins/operator/notBetween.js +5 -4
- package/plugins/operator/notBetween.js.map +1 -0
- package/plugins/operator/notContains.js +2 -2
- package/plugins/operator/notContains.js.map +1 -0
- package/plugins/operator/notIn.js +4 -3
- package/plugins/operator/notIn.js.map +1 -0
- package/plugins/operator/notStartsWith.d.ts +7 -0
- package/plugins/operator/notStartsWith.js +38 -0
- package/plugins/operator/notStartsWith.js.map +1 -0
- package/plugins/operator/startsWith.d.ts +7 -0
- package/plugins/operator/startsWith.js +38 -0
- package/plugins/operator/startsWith.js.map +1 -0
- package/sort.d.ts +4 -3
- package/sort.js +13 -3
- package/sort.js.map +1 -0
- package/types.d.ts +163 -4
- package/types.js +12 -0
- package/types.js.map +1 -0
- package/where.d.ts +2 -2
- package/where.js +3 -2
- package/where.js.map +1 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("../../definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
|
+
|
|
14
|
+
var _normalize = require("../../../normalize");
|
|
15
|
+
|
|
16
|
+
class ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin extends _ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin {
|
|
17
|
+
constructor(...args) {
|
|
18
|
+
super(...args);
|
|
19
|
+
(0, _defineProperty2.default)(this, "name", "elasticsearch.queryBuilder.operator.contains.japanese");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
isLocaleSupported(code) {
|
|
23
|
+
if (!code) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return ["ja", "ja-jp"].includes(code.toLowerCase());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getOperator() {
|
|
31
|
+
return "contains";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
apply(query, params) {
|
|
35
|
+
const {
|
|
36
|
+
value: initialValue,
|
|
37
|
+
basePath
|
|
38
|
+
} = params;
|
|
39
|
+
const value = (0, _normalize.normalizeValue)(initialValue);
|
|
40
|
+
query.must.push({
|
|
41
|
+
multi_match: {
|
|
42
|
+
query: `*${value}*`,
|
|
43
|
+
type: "phrase",
|
|
44
|
+
fields: [`${basePath}.ngram`]
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
query.should.push({
|
|
48
|
+
multi_match: {
|
|
49
|
+
query: `*${value}*`,
|
|
50
|
+
type: "phrase",
|
|
51
|
+
fields: [`${basePath}`]
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin = ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin;
|
|
@@ -0,0 +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}*`,\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"}
|
package/plugins/operator/lt.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -26,7 +26,7 @@ class ElasticsearchQueryBuilderOperatorLesserThanPlugin extends _ElasticsearchQu
|
|
|
26
26
|
value,
|
|
27
27
|
basePath
|
|
28
28
|
} = params;
|
|
29
|
-
query.
|
|
29
|
+
query.filter.push({
|
|
30
30
|
range: {
|
|
31
31
|
[basePath]: {
|
|
32
32
|
lt: value
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorLesserThanPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","filter","push","range","lt"],"sources":["lt.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorLesserThanPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.lesserThan.default\";\n\n public getOperator(): string {\n return \"lt\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath } = params;\n query.filter.push({\n range: {\n [basePath]: {\n lt: value\n }\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAGO,MAAMA,iDAAN,SAAgEC,gFAAhE,CAAwG;EAAA;IAAA;IAAA,4CACpF,wDADoF;EAAA;;EAGpGC,WAAW,GAAW;IACzB,OAAO,IAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAsBF,MAA5B;IACAD,KAAK,CAACI,MAAN,CAAaC,IAAb,CAAkB;MACdC,KAAK,EAAE;QACH,CAACH,QAAD,GAAY;UACRI,EAAE,EAAEL;QADI;MADT;IADO,CAAlB;EAOH;;AAnB0G"}
|
package/plugins/operator/lte.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -26,7 +26,7 @@ class ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin extends _Elasti
|
|
|
26
26
|
value,
|
|
27
27
|
basePath
|
|
28
28
|
} = params;
|
|
29
|
-
query.
|
|
29
|
+
query.filter.push({
|
|
30
30
|
range: {
|
|
31
31
|
[basePath]: {
|
|
32
32
|
lte: value
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","filter","push","range","lte"],"sources":["lte.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.lesserThanOrEqualTo.default\";\n\n public getOperator(): string {\n return \"lte\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath } = params;\n query.filter.push({\n range: {\n [basePath]: {\n lte: value\n }\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAGO,MAAMA,0DAAN,SAAyEC,gFAAzE,CAAiH;EAAA;IAAA;IAAA,4CAC7F,iEAD6F;EAAA;;EAG7GC,WAAW,GAAW;IACzB,OAAO,KAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAsBF,MAA5B;IACAD,KAAK,CAACI,MAAN,CAAaC,IAAb,CAAkB;MACdC,KAAK,EAAE;QACH,CAACH,QAAD,GAAY;UACRI,GAAG,EAAEL;QADG;MADT;IADO,CAAlB;EAOH;;AAnBmH"}
|
package/plugins/operator/not.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -27,10 +27,32 @@ class ElasticsearchQueryBuilderOperatorNotPlugin extends _ElasticsearchQueryBuil
|
|
|
27
27
|
path,
|
|
28
28
|
basePath
|
|
29
29
|
} = params;
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
if (value === null) {
|
|
32
|
+
query.filter.push({
|
|
33
|
+
exists: {
|
|
34
|
+
field: path
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const typeOf = typeof value;
|
|
41
|
+
|
|
42
|
+
if (typeOf === "boolean") {
|
|
43
|
+
query.filter.push({
|
|
44
|
+
term: {
|
|
45
|
+
[basePath]: !value
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const useBasePath = typeOf !== "string";
|
|
52
|
+
const valuePath = useBasePath ? basePath : path;
|
|
31
53
|
query.must_not.push({
|
|
32
54
|
term: {
|
|
33
|
-
[
|
|
55
|
+
[valuePath]: value
|
|
34
56
|
}
|
|
35
57
|
});
|
|
36
58
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorNotPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","path","basePath","filter","push","exists","field","typeOf","term","useBasePath","valuePath","must_not"],"sources":["not.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorNotPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.not.default\";\n\n public getOperator(): string {\n return \"not\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, path, basePath } = params;\n\n if (value === null) {\n query.filter.push({\n exists: {\n field: path\n }\n });\n return;\n }\n\n const typeOf = typeof value;\n\n if (typeOf === \"boolean\") {\n query.filter.push({\n term: {\n [basePath]: !value\n }\n });\n return;\n }\n\n const useBasePath = typeOf !== \"string\";\n const valuePath = useBasePath ? basePath : path;\n query.must_not.push({\n term: {\n [valuePath]: value\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAGO,MAAMA,0CAAN,SAAyDC,gFAAzD,CAAiG;EAAA;IAAA;IAAA,4CAC7E,iDAD6E;EAAA;;EAG7FC,WAAW,GAAW;IACzB,OAAO,KAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAF;MAASC,IAAT;MAAeC;IAAf,IAA4BH,MAAlC;;IAEA,IAAIC,KAAK,KAAK,IAAd,EAAoB;MAChBF,KAAK,CAACK,MAAN,CAAaC,IAAb,CAAkB;QACdC,MAAM,EAAE;UACJC,KAAK,EAAEL;QADH;MADM,CAAlB;MAKA;IACH;;IAED,MAAMM,MAAM,GAAG,OAAOP,KAAtB;;IAEA,IAAIO,MAAM,KAAK,SAAf,EAA0B;MACtBT,KAAK,CAACK,MAAN,CAAaC,IAAb,CAAkB;QACdI,IAAI,EAAE;UACF,CAACN,QAAD,GAAY,CAACF;QADX;MADQ,CAAlB;MAKA;IACH;;IAED,MAAMS,WAAW,GAAGF,MAAM,KAAK,QAA/B;IACA,MAAMG,SAAS,GAAGD,WAAW,GAAGP,QAAH,GAAcD,IAA3C;IACAH,KAAK,CAACa,QAAN,CAAeP,IAAf,CAAoB;MAChBI,IAAI,EAAE;QACF,CAACE,SAAD,GAAaV;MADX;IADU,CAApB;EAKH;;AAxCmG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -24,13 +24,14 @@ class ElasticsearchQueryBuilderOperatorNotBetweenPlugin extends _ElasticsearchQu
|
|
|
24
24
|
apply(query, params) {
|
|
25
25
|
const {
|
|
26
26
|
value,
|
|
27
|
-
basePath
|
|
27
|
+
basePath,
|
|
28
|
+
name
|
|
28
29
|
} = params;
|
|
29
30
|
|
|
30
31
|
if (Array.isArray(value) === false) {
|
|
31
|
-
throw new Error(`You cannot filter field path "${
|
|
32
|
+
throw new Error(`You cannot filter field path "${name}" with "not_between" query and not send an array of values.`);
|
|
32
33
|
} else if (value.length !== 2) {
|
|
33
|
-
throw new Error(`You must pass 2 values in the array for field path "${
|
|
34
|
+
throw new Error(`You must pass 2 values in the array for field path "${name}" filtering.`);
|
|
34
35
|
} // we take gte first because it should be a lesser value than lte, eg [5, 10]
|
|
35
36
|
// 6 >= gte && 6 <= lte === true which in this case it means that record will not match
|
|
36
37
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorNotBetweenPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","name","Array","isArray","Error","length","gte","lte","must_not","push","range"],"sources":["notBetween.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorNotBetweenPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.notBetween.default\";\n\n public getOperator(): string {\n return \"not_between\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath, name } = params;\n if (Array.isArray(value) === false) {\n throw new Error(\n `You cannot filter field path \"${name}\" with \"not_between\" query and not send an array of values.`\n );\n } else if (value.length !== 2) {\n throw new Error(\n `You must pass 2 values in the array for field path \"${name}\" filtering.`\n );\n }\n // we take gte first because it should be a lesser value than lte, eg [5, 10]\n // 6 >= gte && 6 <= lte === true which in this case it means that record will not match\n const [gte, lte] = value;\n query.must_not.push({\n range: {\n [basePath]: {\n lte,\n gte\n }\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAGO,MAAMA,iDAAN,SAAgEC,gFAAhE,CAAwG;EAAA;IAAA;IAAA,4CACpF,wDADoF;EAAA;;EAGpGC,WAAW,GAAW;IACzB,OAAO,aAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAF;MAASC,QAAT;MAAmBC;IAAnB,IAA4BH,MAAlC;;IACA,IAAII,KAAK,CAACC,OAAN,CAAcJ,KAAd,MAAyB,KAA7B,EAAoC;MAChC,MAAM,IAAIK,KAAJ,CACD,iCAAgCH,IAAK,6DADpC,CAAN;IAGH,CAJD,MAIO,IAAIF,KAAK,CAACM,MAAN,KAAiB,CAArB,EAAwB;MAC3B,MAAM,IAAID,KAAJ,CACD,uDAAsDH,IAAK,cAD1D,CAAN;IAGH,CAVG,CAWJ;IACA;;;IACA,MAAM,CAACK,GAAD,EAAMC,GAAN,IAAaR,KAAnB;IACAF,KAAK,CAACW,QAAN,CAAeC,IAAf,CAAoB;MAChBC,KAAK,EAAE;QACH,CAACV,QAAD,GAAY;UACRO,GADQ;UAERD;QAFQ;MADT;IADS,CAApB;EAQH;;AAhC0G"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -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
|
});
|
|
@@ -0,0 +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)}*`,\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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -25,12 +25,13 @@ class ElasticsearchQueryBuilderOperatorNotInPlugin extends _ElasticsearchQueryBu
|
|
|
25
25
|
const {
|
|
26
26
|
value: values,
|
|
27
27
|
path,
|
|
28
|
-
basePath
|
|
28
|
+
basePath,
|
|
29
|
+
name
|
|
29
30
|
} = params;
|
|
30
31
|
const isArray = Array.isArray(values);
|
|
31
32
|
|
|
32
33
|
if (isArray === false || values.length === 0) {
|
|
33
|
-
throw new Error(`You cannot filter field
|
|
34
|
+
throw new Error(`You cannot filter field "${name}" with "not_in" operator and not send an array of values.`);
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const useBasePath = values.some(value => typeof value !== "string");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorNotInPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","values","path","basePath","name","isArray","Array","length","Error","useBasePath","some","must_not","push","terms"],"sources":["notIn.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorNotInPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.notIn.default\";\n\n public getOperator(): string {\n return \"not_in\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value: values, path, basePath, name } = params;\n const isArray = Array.isArray(values);\n if (isArray === false || values.length === 0) {\n throw new Error(\n `You cannot filter field \"${name}\" with \"not_in\" operator and not send an array of values.`\n );\n }\n\n const useBasePath = values.some(\n (value: string | number | boolean | null | undefined) => typeof value !== \"string\"\n );\n\n query.must_not.push({\n terms: {\n [useBasePath ? basePath : path]: values\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAGO,MAAMA,4CAAN,SAA2DC,gFAA3D,CAAmG;EAAA;IAAA;IAAA,4CAC/E,mDAD+E;EAAA;;EAG/FC,WAAW,GAAW;IACzB,OAAO,QAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAK,EAAEC,MAAT;MAAiBC,IAAjB;MAAuBC,QAAvB;MAAiCC;IAAjC,IAA0CL,MAAhD;IACA,MAAMM,OAAO,GAAGC,KAAK,CAACD,OAAN,CAAcJ,MAAd,CAAhB;;IACA,IAAII,OAAO,KAAK,KAAZ,IAAqBJ,MAAM,CAACM,MAAP,KAAkB,CAA3C,EAA8C;MAC1C,MAAM,IAAIC,KAAJ,CACD,4BAA2BJ,IAAK,2DAD/B,CAAN;IAGH;;IAED,MAAMK,WAAW,GAAGR,MAAM,CAACS,IAAP,CACfV,KAAD,IAAyD,OAAOA,KAAP,KAAiB,QAD1D,CAApB;IAIAF,KAAK,CAACa,QAAN,CAAeC,IAAf,CAAoB;MAChBC,KAAK,EAAE;QACH,CAACJ,WAAW,GAAGN,QAAH,GAAcD,IAA1B,GAAiCD;MAD9B;IADS,CAApB;EAKH;;AA5BqG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "../definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
export declare class ElasticsearchQueryBuilderOperatorNotStartsWithPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
getOperator(): string;
|
|
6
|
+
apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderOperatorNotStartsWithPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("../definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
|
+
|
|
14
|
+
class ElasticsearchQueryBuilderOperatorNotStartsWithPlugin extends _ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
(0, _defineProperty2.default)(this, "name", "elasticsearch.queryBuilder.operator.notStartsWith.default");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getOperator() {
|
|
21
|
+
return "not_startsWith";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
apply(query, params) {
|
|
25
|
+
const {
|
|
26
|
+
value,
|
|
27
|
+
basePath
|
|
28
|
+
} = params;
|
|
29
|
+
query.must_not.push({
|
|
30
|
+
match_phrase_prefix: {
|
|
31
|
+
[basePath]: value
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.ElasticsearchQueryBuilderOperatorNotStartsWithPlugin = ElasticsearchQueryBuilderOperatorNotStartsWithPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorNotStartsWithPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","must_not","push","match_phrase_prefix"],"sources":["notStartsWith.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorNotStartsWithPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.notStartsWith.default\";\n\n public getOperator(): string {\n return \"not_startsWith\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath } = params;\n query.must_not.push({\n match_phrase_prefix: {\n [basePath]: value\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAGO,MAAMA,oDAAN,SAAmEC,gFAAnE,CAA2G;EAAA;IAAA;IAAA,4CACvF,2DADuF;EAAA;;EAGvGC,WAAW,GAAW;IACzB,OAAO,gBAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAsBF,MAA5B;IACAD,KAAK,CAACI,QAAN,CAAeC,IAAf,CAAoB;MAChBC,mBAAmB,EAAE;QACjB,CAACH,QAAD,GAAYD;MADK;IADL,CAApB;EAKH;;AAjB6G"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "../definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
2
|
+
import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from "../../types";
|
|
3
|
+
export declare class ElasticsearchQueryBuilderOperatorStartsWithPlugin extends ElasticsearchQueryBuilderOperatorPlugin {
|
|
4
|
+
name: string;
|
|
5
|
+
getOperator(): string;
|
|
6
|
+
apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.ElasticsearchQueryBuilderOperatorStartsWithPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("../definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
13
|
+
|
|
14
|
+
class ElasticsearchQueryBuilderOperatorStartsWithPlugin extends _ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin {
|
|
15
|
+
constructor(...args) {
|
|
16
|
+
super(...args);
|
|
17
|
+
(0, _defineProperty2.default)(this, "name", "elasticsearch.queryBuilder.operator.startsWith.default");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
getOperator() {
|
|
21
|
+
return "startsWith";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
apply(query, params) {
|
|
25
|
+
const {
|
|
26
|
+
value,
|
|
27
|
+
basePath
|
|
28
|
+
} = params;
|
|
29
|
+
query.filter.push({
|
|
30
|
+
match_phrase_prefix: {
|
|
31
|
+
[basePath]: value
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
exports.ElasticsearchQueryBuilderOperatorStartsWithPlugin = ElasticsearchQueryBuilderOperatorStartsWithPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchQueryBuilderOperatorStartsWithPlugin","ElasticsearchQueryBuilderOperatorPlugin","getOperator","apply","query","params","value","basePath","filter","push","match_phrase_prefix"],"sources":["startsWith.ts"],"sourcesContent":["import { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\nimport { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } from \"~/types\";\n\nexport class ElasticsearchQueryBuilderOperatorStartsWithPlugin extends ElasticsearchQueryBuilderOperatorPlugin {\n public override name = \"elasticsearch.queryBuilder.operator.startsWith.default\";\n\n public getOperator(): string {\n return \"startsWith\";\n }\n\n public apply(\n query: ElasticsearchBoolQueryConfig,\n params: ElasticsearchQueryBuilderArgsPlugin\n ): void {\n const { value, basePath } = params;\n query.filter.push({\n match_phrase_prefix: {\n [basePath]: value\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAGO,MAAMA,iDAAN,SAAgEC,gFAAhE,CAAwG;EAAA;IAAA;IAAA,4CACpF,wDADoF;EAAA;;EAGpGC,WAAW,GAAW;IACzB,OAAO,YAAP;EACH;;EAEMC,KAAK,CACRC,KADQ,EAERC,MAFQ,EAGJ;IACJ,MAAM;MAAEC,KAAF;MAASC;IAAT,IAAsBF,MAA5B;IACAD,KAAK,CAACI,MAAN,CAAaC,IAAb,CAAkB;MACdC,mBAAmB,EAAE;QACjB,CAACH,QAAD,GAAYD;MADK;IADP,CAAlB;EAKH;;AAjB0G"}
|
package/sort.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SortType, SortOrder } from "./types";
|
|
2
|
-
import { ElasticsearchFieldPlugin } from "./plugins
|
|
3
|
-
|
|
2
|
+
import { ElasticsearchFieldPlugin } from "./plugins";
|
|
3
|
+
interface CreateSortParams {
|
|
4
4
|
sort: string[];
|
|
5
5
|
defaults?: {
|
|
6
6
|
field?: string;
|
|
@@ -9,4 +9,5 @@ export interface Params {
|
|
|
9
9
|
};
|
|
10
10
|
fieldPlugins: Record<string, ElasticsearchFieldPlugin>;
|
|
11
11
|
}
|
|
12
|
-
export declare const createSort: (params:
|
|
12
|
+
export declare const createSort: (params: CreateSortParams) => SortType;
|
|
13
|
+
export {};
|
package/sort.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
@@ -9,7 +9,9 @@ exports.createSort = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
var _plugins = require("./plugins");
|
|
13
|
+
|
|
14
|
+
const sortRegExp = new RegExp(/^([a-zA-Z-0-9_@]+)_(ASC|DESC)$/);
|
|
13
15
|
|
|
14
16
|
const createSort = params => {
|
|
15
17
|
const {
|
|
@@ -35,8 +37,16 @@ const createSort = params => {
|
|
|
35
37
|
}
|
|
36
38
|
};
|
|
37
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Cast as string because nothing else should be allowed yet.
|
|
42
|
+
*/
|
|
43
|
+
|
|
38
44
|
|
|
39
45
|
return sort.reduce((acc, value) => {
|
|
46
|
+
if (typeof value !== "string") {
|
|
47
|
+
throw new _error.default(`Sort as object is not supported..`);
|
|
48
|
+
}
|
|
49
|
+
|
|
40
50
|
const match = value.match(sortRegExp);
|
|
41
51
|
|
|
42
52
|
if (!match) {
|
|
@@ -45,7 +55,7 @@ const createSort = params => {
|
|
|
45
55
|
|
|
46
56
|
const [, field, initialOrder] = match;
|
|
47
57
|
const order = initialOrder.toLowerCase() === "asc" ? "asc" : "desc";
|
|
48
|
-
const plugin = fieldPlugins[field] || fieldPlugins[
|
|
58
|
+
const plugin = fieldPlugins[field] || fieldPlugins[_plugins.ElasticsearchFieldPlugin.ALL];
|
|
49
59
|
|
|
50
60
|
if (!plugin) {
|
|
51
61
|
throw new _error.default(`Missing plugin for the field "${field}"`, "PLUGIN_SORT_ERROR", {
|
package/sort.js.map
ADDED
|
@@ -0,0 +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","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"}
|
package/types.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { Client } from "@elastic/elasticsearch";
|
|
1
|
+
import { Client, ApiResponse } from "@elastic/elasticsearch";
|
|
2
2
|
import { BoolQueryConfig as esBoolQueryConfig, Query as esQuery } from "elastic-ts";
|
|
3
|
-
import {
|
|
3
|
+
import { Context } from "@webiny/api/types";
|
|
4
|
+
/**
|
|
5
|
+
* Re-export some dep lib types.
|
|
6
|
+
*/
|
|
4
7
|
export * from "elastic-ts";
|
|
5
|
-
export
|
|
8
|
+
export { ApiResponse };
|
|
9
|
+
export interface ElasticsearchContext extends Context {
|
|
6
10
|
elasticsearch: Client;
|
|
7
11
|
}
|
|
8
12
|
/**
|
|
@@ -20,7 +24,7 @@ export interface ElasticsearchBoolQueryConfig extends esBoolQueryConfig {
|
|
|
20
24
|
*
|
|
21
25
|
* @category Elasticsearch
|
|
22
26
|
*/
|
|
23
|
-
export declare type ElasticsearchQueryOperator = "eq" | "not" | "in" | "not_in" | "contains" | "not_contains" | "between" | "not_between" | "gt" | "gte" | "lt" | "lte";
|
|
27
|
+
export declare type ElasticsearchQueryOperator = "eq" | "not" | "in" | "not_in" | "contains" | "not_contains" | "between" | "not_between" | "gt" | "gte" | "lt" | "lte" | string;
|
|
24
28
|
/**
|
|
25
29
|
* Definition for arguments of the ElasticsearchQueryBuilderOperatorPlugin.apply method.
|
|
26
30
|
*
|
|
@@ -30,6 +34,10 @@ export declare type ElasticsearchQueryOperator = "eq" | "not" | "in" | "not_in"
|
|
|
30
34
|
* @category Elasticsearch
|
|
31
35
|
*/
|
|
32
36
|
export interface ElasticsearchQueryBuilderArgsPlugin {
|
|
37
|
+
/**
|
|
38
|
+
* Name of the field.
|
|
39
|
+
*/
|
|
40
|
+
name: string;
|
|
33
41
|
/**
|
|
34
42
|
* A full path to the field. Including the ".keyword" if it is added.
|
|
35
43
|
*/
|
|
@@ -47,3 +55,154 @@ export interface ElasticsearchQueryBuilderArgsPlugin {
|
|
|
47
55
|
*/
|
|
48
56
|
keyword: boolean;
|
|
49
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Elasticsearch responses.
|
|
60
|
+
*/
|
|
61
|
+
export interface ElasticsearchSearchResponseHit<T> {
|
|
62
|
+
_source: T;
|
|
63
|
+
sort: string;
|
|
64
|
+
}
|
|
65
|
+
export interface ElasticsearchSearchResponseAggregationBucket<T> {
|
|
66
|
+
key: T;
|
|
67
|
+
}
|
|
68
|
+
export interface ElasticsearchSearchResponse<T = any> {
|
|
69
|
+
body: {
|
|
70
|
+
hits: {
|
|
71
|
+
hits: ElasticsearchSearchResponseHit<T>[];
|
|
72
|
+
total: {
|
|
73
|
+
value: number;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
aggregations: {
|
|
77
|
+
[key: string]: {
|
|
78
|
+
buckets: ElasticsearchSearchResponseAggregationBucket<T>[];
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export interface ElasticsearchIndexRequestBodyMappingsDynamicTemplate {
|
|
84
|
+
[key: string]: {
|
|
85
|
+
path_match?: string;
|
|
86
|
+
path_unmatch?: string;
|
|
87
|
+
match_mapping_type?: string;
|
|
88
|
+
match?: string;
|
|
89
|
+
unmatch?: string;
|
|
90
|
+
mapping?: {
|
|
91
|
+
numeric_detection?: boolean;
|
|
92
|
+
date_detection?: boolean;
|
|
93
|
+
type?: "string" | "date" | "binary" | "boolean" | "object" | "ip" | "geo" | "long" | "integer" | "short" | "byte" | "double" | "float" | "half_float" | "scaled_float" | "unsigned_long" | string;
|
|
94
|
+
search_analyzer?: string;
|
|
95
|
+
analyzer?: string;
|
|
96
|
+
fields?: {
|
|
97
|
+
[key: string]: {
|
|
98
|
+
type: string;
|
|
99
|
+
search_analyzer?: string;
|
|
100
|
+
analyzer?: string;
|
|
101
|
+
ignore_above?: number;
|
|
102
|
+
[key: string]: any;
|
|
103
|
+
} | undefined;
|
|
104
|
+
};
|
|
105
|
+
[key: string]: any;
|
|
106
|
+
};
|
|
107
|
+
[key: string]: any;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
interface ElasticsearchIndexRequestBodySettings {
|
|
111
|
+
analysis?: {
|
|
112
|
+
[key: string]: any;
|
|
113
|
+
};
|
|
114
|
+
number_of_shards?: number;
|
|
115
|
+
number_of_routing_shards?: number;
|
|
116
|
+
codec?: string;
|
|
117
|
+
routing_partition_size?: number;
|
|
118
|
+
soft_deletes?: {
|
|
119
|
+
enabled?: boolean;
|
|
120
|
+
retention_lease?: {
|
|
121
|
+
period?: string;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
load_fixed_bitset_filters_eagerly?: boolean;
|
|
125
|
+
shard?: {
|
|
126
|
+
check_on_startup?: boolean | "checksum";
|
|
127
|
+
};
|
|
128
|
+
number_of_replicas?: number;
|
|
129
|
+
auto_expand_replicas?: string | "all" | false;
|
|
130
|
+
search?: {
|
|
131
|
+
idle?: {
|
|
132
|
+
after?: string;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
refresh_interval?: string;
|
|
136
|
+
max_result_window?: number;
|
|
137
|
+
max_inner_result_window?: number;
|
|
138
|
+
max_rescore_window?: number;
|
|
139
|
+
max_docvalue_fields_search?: number;
|
|
140
|
+
max_script_fields?: number;
|
|
141
|
+
max_ngram_diff?: number;
|
|
142
|
+
max_shingle_diff?: number;
|
|
143
|
+
max_refresh_listeners?: number;
|
|
144
|
+
analyze?: {
|
|
145
|
+
max_token_count?: number;
|
|
146
|
+
};
|
|
147
|
+
highlight?: {
|
|
148
|
+
max_analyzed_offset?: number;
|
|
149
|
+
};
|
|
150
|
+
max_terms_count?: number;
|
|
151
|
+
max_regex_length?: number;
|
|
152
|
+
query?: {
|
|
153
|
+
default_field?: string;
|
|
154
|
+
};
|
|
155
|
+
routing?: {
|
|
156
|
+
allocation?: {
|
|
157
|
+
enable?: "all" | "primaries" | "new_primaries" | "none";
|
|
158
|
+
};
|
|
159
|
+
rebalance?: {
|
|
160
|
+
enable?: "all" | "primaries" | "new_primaries" | "none";
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
gc_deletes?: string;
|
|
164
|
+
default_pipeline?: string;
|
|
165
|
+
final_pipeline?: string;
|
|
166
|
+
hidden?: boolean;
|
|
167
|
+
[key: string]: any;
|
|
168
|
+
}
|
|
169
|
+
export interface ElasticsearchIndexRequestBody {
|
|
170
|
+
settings?: {
|
|
171
|
+
index?: Partial<ElasticsearchIndexRequestBodySettings>;
|
|
172
|
+
};
|
|
173
|
+
mappings: {
|
|
174
|
+
numeric_detection?: boolean;
|
|
175
|
+
dynamic_templates?: ElasticsearchIndexRequestBodyMappingsDynamicTemplate[];
|
|
176
|
+
properties?: {
|
|
177
|
+
[key: string]: {
|
|
178
|
+
analyzer?: string;
|
|
179
|
+
type?: string;
|
|
180
|
+
normalizer?: string;
|
|
181
|
+
index?: string;
|
|
182
|
+
fields?: {
|
|
183
|
+
[key: string]: {
|
|
184
|
+
type: string;
|
|
185
|
+
ignore_above?: number;
|
|
186
|
+
search_analyzer?: string;
|
|
187
|
+
analyzer?: string;
|
|
188
|
+
[key: string]: any;
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
[key: string]: any;
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
[key: string]: any;
|
|
195
|
+
};
|
|
196
|
+
aliases?: {
|
|
197
|
+
[key: string]: {
|
|
198
|
+
filter?: {
|
|
199
|
+
[key: string]: any;
|
|
200
|
+
};
|
|
201
|
+
index_routing?: string;
|
|
202
|
+
is_hidden?: boolean;
|
|
203
|
+
is_write_index?: boolean;
|
|
204
|
+
routing?: string;
|
|
205
|
+
search_routing?: string;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
}
|
package/types.js
CHANGED
|
@@ -3,11 +3,23 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
ApiResponse: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "ApiResponse", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _elasticsearch.ApiResponse;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var _elasticsearch = require("@elastic/elasticsearch");
|
|
6
17
|
|
|
7
18
|
var _elasticTs = require("elastic-ts");
|
|
8
19
|
|
|
9
20
|
Object.keys(_elasticTs).forEach(function (key) {
|
|
10
21
|
if (key === "default" || key === "__esModule") return;
|
|
22
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
11
23
|
if (key in exports && exports[key] === _elasticTs[key]) return;
|
|
12
24
|
Object.defineProperty(exports, key, {
|
|
13
25
|
enumerable: true,
|