@webiny/api-elasticsearch 0.0.0-mt-3 → 0.0.0-unstable.40876133bb
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 +2 -2
- 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.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 +1 -1
- package/plugins/operator/andIn.js.map +1 -0
- package/plugins/operator/between.js +1 -1
- package/plugins/operator/between.js.map +1 -0
- package/plugins/operator/contains.js +1 -1
- package/plugins/operator/contains.js.map +1 -0
- package/plugins/operator/equal.js +11 -1
- package/plugins/operator/equal.js.map +1 -0
- package/plugins/operator/gt.js +1 -1
- package/plugins/operator/gt.js.map +1 -0
- package/plugins/operator/gte.js +1 -1
- package/plugins/operator/gte.js.map +1 -0
- package/plugins/operator/in.js +1 -1
- 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 +1 -1
- package/plugins/operator/lt.js.map +1 -0
- package/plugins/operator/lte.js +1 -1
- package/plugins/operator/lte.js.map +1 -0
- package/plugins/operator/not.js +11 -1
- package/plugins/operator/not.js.map +1 -0
- package/plugins/operator/notBetween.js +1 -1
- package/plugins/operator/notBetween.js.map +1 -0
- package/plugins/operator/notContains.js +1 -1
- package/plugins/operator/notContains.js.map +1 -0
- package/plugins/operator/notIn.js +1 -1
- 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 +8 -3
- package/sort.js +12 -2
- package/sort.js.map +1 -0
- package/types.d.ts +158 -2
- package/types.js +12 -0
- package/types.js.map +1 -0
- package/where.d.ts +2 -2
- package/where.js +2 -2
- package/where.js.map +1 -0
package/indices.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ElasticsearchIndexPlugin } from "./plugins/definition/ElasticsearchIndexPlugin";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
interface IndicesPluginsParams {
|
|
4
|
+
container: PluginsContainer;
|
|
5
|
+
type: string;
|
|
6
|
+
locale: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const getLastAddedIndexPlugin: <T extends ElasticsearchIndexPlugin>(params: IndicesPluginsParams) => T;
|
|
9
|
+
export {};
|
package/indices.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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.getLastAddedIndexPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
|
+
|
|
12
|
+
const listIndicesPlugins = ({
|
|
13
|
+
container,
|
|
14
|
+
type,
|
|
15
|
+
locale
|
|
16
|
+
}) => {
|
|
17
|
+
return container.byType(type).filter(plugin => {
|
|
18
|
+
return plugin.canUse(locale);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getLastAddedIndexPlugin = params => {
|
|
23
|
+
const plugins = listIndicesPlugins(params);
|
|
24
|
+
|
|
25
|
+
if (plugins.length === 0) {
|
|
26
|
+
throw new _error.default(`Could not find a single ElasticsearchIndexPlugin of type "${params.type}".`, "ELASTICSEARCH_INDEX_TEMPLATE_ERROR", {
|
|
27
|
+
type: params.type,
|
|
28
|
+
locale: params.locale
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return plugins.pop();
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.getLastAddedIndexPlugin = getLastAddedIndexPlugin;
|
package/indices.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["listIndicesPlugins","container","type","locale","byType","filter","plugin","canUse","getLastAddedIndexPlugin","params","plugins","length","WebinyError","pop"],"sources":["indices.ts"],"sourcesContent":["import { ElasticsearchIndexPlugin } from \"~/plugins/definition/ElasticsearchIndexPlugin\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport WebinyError from \"@webiny/error\";\n\ninterface IndicesPluginsParams {\n container: PluginsContainer;\n type: string;\n locale: string;\n}\nconst listIndicesPlugins = <T extends ElasticsearchIndexPlugin>({\n container,\n type,\n locale\n}: IndicesPluginsParams): T[] => {\n return container.byType<T>(type).filter(plugin => {\n return plugin.canUse(locale);\n });\n};\n\nexport const getLastAddedIndexPlugin = <T extends ElasticsearchIndexPlugin>(\n params: IndicesPluginsParams\n): T => {\n const plugins = listIndicesPlugins<T>(params);\n if (plugins.length === 0) {\n throw new WebinyError(\n `Could not find a single ElasticsearchIndexPlugin of type \"${params.type}\".`,\n \"ELASTICSEARCH_INDEX_TEMPLATE_ERROR\",\n {\n type: params.type,\n locale: params.locale\n }\n );\n }\n\n return plugins.pop() as T;\n};\n"],"mappings":";;;;;;;;;AAEA;;AAOA,MAAMA,kBAAkB,GAAG,CAAqC;EAC5DC,SAD4D;EAE5DC,IAF4D;EAG5DC;AAH4D,CAArC,KAIM;EAC7B,OAAOF,SAAS,CAACG,MAAV,CAAoBF,IAApB,EAA0BG,MAA1B,CAAiCC,MAAM,IAAI;IAC9C,OAAOA,MAAM,CAACC,MAAP,CAAcJ,MAAd,CAAP;EACH,CAFM,CAAP;AAGH,CARD;;AAUO,MAAMK,uBAAuB,GAChCC,MADmC,IAE/B;EACJ,MAAMC,OAAO,GAAGV,kBAAkB,CAAIS,MAAJ,CAAlC;;EACA,IAAIC,OAAO,CAACC,MAAR,KAAmB,CAAvB,EAA0B;IACtB,MAAM,IAAIC,cAAJ,CACD,6DAA4DH,MAAM,CAACP,IAAK,IADvE,EAEF,oCAFE,EAGF;MACIA,IAAI,EAAEO,MAAM,CAACP,IADjB;MAEIC,MAAM,EAAEM,MAAM,CAACN;IAFnB,CAHE,CAAN;EAQH;;EAED,OAAOO,OAAO,CAACG,GAAR,EAAP;AACH,CAhBM"}
|
package/limit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ES_LIMIT_MAX","ES_LIMIT_DEFAULT","createLimit","limit","defaultValue"],"sources":["limit.ts"],"sourcesContent":["/**\n * This is the max limit of the Elasticsearch.\n * Change here if it changes (and if it is necessary).\n */\nconst ES_LIMIT_MAX = 10000;\n/**\n * Our system default limit.\n */\nconst ES_LIMIT_DEFAULT = 50;\n\nexport const createLimit = (limit?: number, defaultValue = ES_LIMIT_DEFAULT): number => {\n /**\n * Limit can possibly be null/undefined or less than 1.\n * In that case return the defaults.\n */\n if (!limit || limit < 1) {\n return defaultValue;\n }\n /**\n * Users input limit cannot be greater than the Elasticsearch one.\n * Elasticsearch query breaks because of that.\n */\n if (limit < ES_LIMIT_MAX) {\n return limit;\n }\n /**\n * Always reduce by 1 because we check if there are more items by adding 1 to the limit\n * and then remove that last one loaded.\n */\n return ES_LIMIT_MAX - 1;\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA,MAAMA,YAAY,GAAG,KAArB;AACA;AACA;AACA;;AACA,MAAMC,gBAAgB,GAAG,EAAzB;;AAEO,MAAMC,WAAW,GAAG,CAACC,KAAD,EAAiBC,YAAY,GAAGH,gBAAhC,KAA6D;EACpF;AACJ;AACA;AACA;EACI,IAAI,CAACE,KAAD,IAAUA,KAAK,GAAG,CAAtB,EAAyB;IACrB,OAAOC,YAAP;EACH;EACD;AACJ;AACA;AACA;;;EACI,IAAID,KAAK,GAAGH,YAAZ,EAA0B;IACtB,OAAOG,KAAP;EACH;EACD;AACJ;AACA;AACA;;;EACI,OAAOH,YAAY,GAAG,CAAtB;AACH,CApBM"}
|
package/normalize.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RESERVED_CHARACTERS","escape","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 RESERVED_CHARACTERS = {\n // These characters need to be escaped with backslash (\"\\\").\n escape: [\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 RESERVED_CHARACTERS.escape) {\n result = result.replace(new RegExp(`${character}`, \"g\"), ` `);\n }\n\n return result ? `*${result}*` : \"\";\n};\n"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AAEA,MAAMA,mBAAmB,GAAG;EACxB;EACAC,MAAM,EAAE,CACJ,MADI,EAEJ,KAFI,EAGJ,KAHI,EAIJ,KAJI,EAKJ,KALI,EAMJ,QANI,EAOJ,QAPI,EAQJ,KARI,EASJ,KATI,EAUJ,KAVI,EAWJ,KAXI,EAYJ,KAZI,EAaJ,KAbI,EAcJ,KAdI,EAeJ,KAfI,EAgBJ,KAhBI,EAiBJ,KAjBI,EAkBJ,KAlBI,EAmBJ,KAnBI,EAoBJ,KApBI,EAqBJ,KArBI,EAsBJ,KAtBI;AAFgB,CAA5B;;AA4BO,MAAMC,cAAc,GAAIC,KAAD,IAAmB;EAC7C,IAAIC,MAAM,GAAGD,KAAb;;EACA,KAAK,MAAME,SAAX,IAAwBL,mBAAmB,CAACC,MAA5C,EAAoD;IAChDG,MAAM,GAAGA,MAAM,CAACE,OAAP,CAAe,IAAIC,MAAJ,CAAY,GAAEF,SAAU,EAAxB,EAA2B,GAA3B,CAAf,EAAiD,GAAjD,CAAT;EACH;;EAED,OAAOD,MAAM,GAAI,IAAGA,MAAO,GAAd,GAAmB,EAAhC;AACH,CAPM"}
|
package/operators.d.ts
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import { ElasticsearchQueryBuilderOperatorBetweenPlugin } from "./plugins/operator
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ElasticsearchQueryBuilderOperatorNotContainsPlugin } from "./plugins/operator/notContains";
|
|
5
|
-
import { ElasticsearchQueryBuilderOperatorEqualPlugin } from "./plugins/operator/equal";
|
|
6
|
-
import { ElasticsearchQueryBuilderOperatorNotPlugin } from "./plugins/operator/not";
|
|
7
|
-
import { ElasticsearchQueryBuilderOperatorGreaterThanPlugin } from "./plugins/operator/gt";
|
|
8
|
-
import { ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin } from "./plugins/operator/gte";
|
|
9
|
-
import { ElasticsearchQueryBuilderOperatorLesserThanPlugin } from "./plugins/operator/lt";
|
|
10
|
-
import { ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin } from "./plugins/operator/lte";
|
|
11
|
-
import { ElasticsearchQueryBuilderOperatorInPlugin } from "./plugins/operator/in";
|
|
12
|
-
import { ElasticsearchQueryBuilderOperatorAndInPlugin } from "./plugins/operator/andIn";
|
|
13
|
-
import { ElasticsearchQueryBuilderOperatorNotInPlugin } from "./plugins/operator/notIn";
|
|
1
|
+
import { ElasticsearchQueryBuilderOperatorBetweenPlugin, ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin, ElasticsearchQueryBuilderOperatorAndInPlugin, ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin, ElasticsearchQueryBuilderOperatorGreaterThanPlugin, ElasticsearchQueryBuilderOperatorContainsPlugin, ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin, ElasticsearchQueryBuilderOperatorInPlugin, ElasticsearchQueryBuilderOperatorLesserThanPlugin, ElasticsearchQueryBuilderOperatorNotBetweenPlugin, ElasticsearchQueryBuilderOperatorNotContainsPlugin, ElasticsearchQueryBuilderOperatorNotPlugin, ElasticsearchQueryBuilderOperatorNotInPlugin, ElasticsearchQueryBuilderOperatorEqualPlugin, ElasticsearchQueryBuilderOperatorStartsWithPlugin, ElasticsearchQueryBuilderOperatorNotStartsWithPlugin } from "./plugins/operator";
|
|
2
|
+
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
+
import { ElasticsearchQueryBuilderOperatorPlugin } from "./plugins/definition/ElasticsearchQueryBuilderOperatorPlugin";
|
|
14
4
|
/**
|
|
15
5
|
* We export as a function because there might be something to be sent to the operators at some point.
|
|
16
6
|
* This way, we make it easier to upgrade.
|
|
17
7
|
*/
|
|
18
|
-
export declare const getElasticsearchOperators: () => (ElasticsearchQueryBuilderOperatorBetweenPlugin |
|
|
8
|
+
export declare const getElasticsearchOperators: () => (ElasticsearchQueryBuilderOperatorBetweenPlugin | ElasticsearchQueryBuilderOperatorContainsPlugin | ElasticsearchQueryBuilderOperatorEqualPlugin | ElasticsearchQueryBuilderOperatorGreaterThanPlugin | ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin | ElasticsearchQueryBuilderOperatorAndInPlugin | ElasticsearchQueryBuilderOperatorInPlugin | ElasticsearchQueryBuilderOperatorLesserThanPlugin | ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin | ElasticsearchQueryBuilderOperatorNotPlugin | ElasticsearchQueryBuilderOperatorNotBetweenPlugin | ElasticsearchQueryBuilderOperatorNotContainsPlugin | ElasticsearchQueryBuilderOperatorNotInPlugin | ElasticsearchQueryBuilderOperatorStartsWithPlugin | ElasticsearchQueryBuilderOperatorNotStartsWithPlugin | ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin)[];
|
|
9
|
+
export declare const getElasticsearchOperatorPluginsByLocale: (plugins: PluginsContainer, locale: string) => Record<string, ElasticsearchQueryBuilderOperatorPlugin>;
|
package/operators.js
CHANGED
|
@@ -3,35 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getElasticsearchOperators = void 0;
|
|
6
|
+
exports.getElasticsearchOperators = exports.getElasticsearchOperatorPluginsByLocale = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _operator = require("./plugins/operator");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _ElasticsearchQueryBuilderOperatorPlugin = require("./plugins/definition/ElasticsearchQueryBuilderOperatorPlugin");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _not = require("./plugins/operator/not");
|
|
19
|
-
|
|
20
|
-
var _gt = require("./plugins/operator/gt");
|
|
21
|
-
|
|
22
|
-
var _gte = require("./plugins/operator/gte");
|
|
23
|
-
|
|
24
|
-
var _lt = require("./plugins/operator/lt");
|
|
25
|
-
|
|
26
|
-
var _lte = require("./plugins/operator/lte");
|
|
27
|
-
|
|
28
|
-
var _in = require("./plugins/operator/in");
|
|
29
|
-
|
|
30
|
-
var _andIn = require("./plugins/operator/andIn");
|
|
31
|
-
|
|
32
|
-
var _notIn = require("./plugins/operator/notIn");
|
|
33
|
-
|
|
34
|
-
const operators = [new _between.ElasticsearchQueryBuilderOperatorBetweenPlugin(), new _notBetween.ElasticsearchQueryBuilderOperatorNotBetweenPlugin(), new _contains.ElasticsearchQueryBuilderOperatorContainsPlugin(), new _notContains.ElasticsearchQueryBuilderOperatorNotContainsPlugin(), new _equal.ElasticsearchQueryBuilderOperatorEqualPlugin(), new _not.ElasticsearchQueryBuilderOperatorNotPlugin(), new _gt.ElasticsearchQueryBuilderOperatorGreaterThanPlugin(), new _gte.ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin(), new _lt.ElasticsearchQueryBuilderOperatorLesserThanPlugin(), new _lte.ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin(), new _in.ElasticsearchQueryBuilderOperatorInPlugin(), new _andIn.ElasticsearchQueryBuilderOperatorAndInPlugin(), new _notIn.ElasticsearchQueryBuilderOperatorNotInPlugin()];
|
|
12
|
+
const operators = [new _operator.ElasticsearchQueryBuilderOperatorBetweenPlugin(), new _operator.ElasticsearchQueryBuilderOperatorNotBetweenPlugin(), new _operator.ElasticsearchQueryBuilderOperatorContainsPlugin(), new _operator.ElasticsearchQueryBuilderOperatorNotContainsPlugin(), new _operator.ElasticsearchQueryBuilderOperatorEqualPlugin(), new _operator.ElasticsearchQueryBuilderOperatorNotPlugin(), new _operator.ElasticsearchQueryBuilderOperatorGreaterThanPlugin(), new _operator.ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin(), new _operator.ElasticsearchQueryBuilderOperatorLesserThanPlugin(), new _operator.ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin(), new _operator.ElasticsearchQueryBuilderOperatorInPlugin(), new _operator.ElasticsearchQueryBuilderOperatorAndInPlugin(), new _operator.ElasticsearchQueryBuilderOperatorNotInPlugin(), new _operator.ElasticsearchQueryBuilderOperatorStartsWithPlugin(), new _operator.ElasticsearchQueryBuilderOperatorNotStartsWithPlugin(),
|
|
13
|
+
/**
|
|
14
|
+
* Japanese
|
|
15
|
+
*/
|
|
16
|
+
new _operator.ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin()];
|
|
35
17
|
/**
|
|
36
18
|
* We export as a function because there might be something to be sent to the operators at some point.
|
|
37
19
|
* This way, we make it easier to upgrade.
|
|
@@ -39,4 +21,36 @@ const operators = [new _between.ElasticsearchQueryBuilderOperatorBetweenPlugin()
|
|
|
39
21
|
|
|
40
22
|
const getElasticsearchOperators = () => operators;
|
|
41
23
|
|
|
42
|
-
exports.getElasticsearchOperators = getElasticsearchOperators;
|
|
24
|
+
exports.getElasticsearchOperators = getElasticsearchOperators;
|
|
25
|
+
|
|
26
|
+
const getElasticsearchOperatorPluginsByLocale = (plugins, locale) => {
|
|
27
|
+
/**
|
|
28
|
+
* We always set the last one operator plugin added.
|
|
29
|
+
* This way user can override the plugins.
|
|
30
|
+
*/
|
|
31
|
+
return plugins.byType(_ElasticsearchQueryBuilderOperatorPlugin.ElasticsearchQueryBuilderOperatorPlugin.type).reduce((acc, plugin) => {
|
|
32
|
+
const op = plugin.getOperator();
|
|
33
|
+
/**
|
|
34
|
+
* We only allow the plugins which can pass the locale test.
|
|
35
|
+
* The default plugins always return true.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
if (plugin.isLocaleSupported(locale) === false) {
|
|
39
|
+
return acc;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* We also only allow the override of the plugins if the new plugin is NOT a default one.
|
|
43
|
+
* If a user names the plugin with .default, we cannot do anything about it.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if (!!acc[op] && (plugin.name || "").match(/\.default$/)) {
|
|
48
|
+
return acc;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
acc[op] = plugin;
|
|
52
|
+
return acc;
|
|
53
|
+
}, {});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.getElasticsearchOperatorPluginsByLocale = getElasticsearchOperatorPluginsByLocale;
|
package/operators.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["operators","ElasticsearchQueryBuilderOperatorBetweenPlugin","ElasticsearchQueryBuilderOperatorNotBetweenPlugin","ElasticsearchQueryBuilderOperatorContainsPlugin","ElasticsearchQueryBuilderOperatorNotContainsPlugin","ElasticsearchQueryBuilderOperatorEqualPlugin","ElasticsearchQueryBuilderOperatorNotPlugin","ElasticsearchQueryBuilderOperatorGreaterThanPlugin","ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin","ElasticsearchQueryBuilderOperatorLesserThanPlugin","ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin","ElasticsearchQueryBuilderOperatorInPlugin","ElasticsearchQueryBuilderOperatorAndInPlugin","ElasticsearchQueryBuilderOperatorNotInPlugin","ElasticsearchQueryBuilderOperatorStartsWithPlugin","ElasticsearchQueryBuilderOperatorNotStartsWithPlugin","ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin","getElasticsearchOperators","getElasticsearchOperatorPluginsByLocale","plugins","locale","byType","ElasticsearchQueryBuilderOperatorPlugin","type","reduce","acc","plugin","op","getOperator","isLocaleSupported","name","match"],"sources":["operators.ts"],"sourcesContent":["import {\n ElasticsearchQueryBuilderOperatorBetweenPlugin,\n ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin,\n ElasticsearchQueryBuilderOperatorAndInPlugin,\n ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin,\n ElasticsearchQueryBuilderOperatorGreaterThanPlugin,\n ElasticsearchQueryBuilderOperatorContainsPlugin,\n ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin,\n ElasticsearchQueryBuilderOperatorInPlugin,\n ElasticsearchQueryBuilderOperatorLesserThanPlugin,\n ElasticsearchQueryBuilderOperatorNotBetweenPlugin,\n ElasticsearchQueryBuilderOperatorNotContainsPlugin,\n ElasticsearchQueryBuilderOperatorNotPlugin,\n ElasticsearchQueryBuilderOperatorNotInPlugin,\n ElasticsearchQueryBuilderOperatorEqualPlugin,\n ElasticsearchQueryBuilderOperatorStartsWithPlugin,\n ElasticsearchQueryBuilderOperatorNotStartsWithPlugin\n} from \"~/plugins/operator\";\nimport { PluginsContainer } from \"@webiny/plugins\";\nimport { ElasticsearchQueryBuilderOperatorPlugin } from \"~/plugins/definition/ElasticsearchQueryBuilderOperatorPlugin\";\n\nconst operators = [\n new ElasticsearchQueryBuilderOperatorBetweenPlugin(),\n new ElasticsearchQueryBuilderOperatorNotBetweenPlugin(),\n new ElasticsearchQueryBuilderOperatorContainsPlugin(),\n new ElasticsearchQueryBuilderOperatorNotContainsPlugin(),\n new ElasticsearchQueryBuilderOperatorEqualPlugin(),\n new ElasticsearchQueryBuilderOperatorNotPlugin(),\n new ElasticsearchQueryBuilderOperatorGreaterThanPlugin(),\n new ElasticsearchQueryBuilderOperatorGreaterThanOrEqualToPlugin(),\n new ElasticsearchQueryBuilderOperatorLesserThanPlugin(),\n new ElasticsearchQueryBuilderOperatorLesserThanOrEqualToPlugin(),\n new ElasticsearchQueryBuilderOperatorInPlugin(),\n new ElasticsearchQueryBuilderOperatorAndInPlugin(),\n new ElasticsearchQueryBuilderOperatorNotInPlugin(),\n new ElasticsearchQueryBuilderOperatorStartsWithPlugin(),\n new ElasticsearchQueryBuilderOperatorNotStartsWithPlugin(),\n /**\n * Japanese\n */\n new ElasticsearchQueryBuilderJapaneseOperatorContainsPlugin()\n];\n/**\n * We export as a function because there might be something to be sent to the operators at some point.\n * This way, we make it easier to upgrade.\n */\nexport const getElasticsearchOperators = () => operators;\n\nexport const getElasticsearchOperatorPluginsByLocale = (\n plugins: PluginsContainer,\n locale: string\n): Record<string, ElasticsearchQueryBuilderOperatorPlugin> => {\n /**\n * We always set the last one operator plugin added.\n * This way user can override the plugins.\n */\n return plugins\n .byType<ElasticsearchQueryBuilderOperatorPlugin>(\n ElasticsearchQueryBuilderOperatorPlugin.type\n )\n .reduce((acc, plugin) => {\n const op = plugin.getOperator();\n /**\n * We only allow the plugins which can pass the locale test.\n * The default plugins always return true.\n */\n if (plugin.isLocaleSupported(locale) === false) {\n return acc;\n }\n /**\n * We also only allow the override of the plugins if the new plugin is NOT a default one.\n * If a user names the plugin with .default, we cannot do anything about it.\n */\n if (!!acc[op] && (plugin.name || \"\").match(/\\.default$/)) {\n return acc;\n }\n acc[op] = plugin;\n return acc;\n }, {} as Record<string, ElasticsearchQueryBuilderOperatorPlugin>);\n};\n"],"mappings":";;;;;;;AAAA;;AAmBA;;AAEA,MAAMA,SAAS,GAAG,CACd,IAAIC,wDAAJ,EADc,EAEd,IAAIC,2DAAJ,EAFc,EAGd,IAAIC,yDAAJ,EAHc,EAId,IAAIC,4DAAJ,EAJc,EAKd,IAAIC,sDAAJ,EALc,EAMd,IAAIC,oDAAJ,EANc,EAOd,IAAIC,4DAAJ,EAPc,EAQd,IAAIC,qEAAJ,EARc,EASd,IAAIC,2DAAJ,EATc,EAUd,IAAIC,oEAAJ,EAVc,EAWd,IAAIC,mDAAJ,EAXc,EAYd,IAAIC,sDAAJ,EAZc,EAad,IAAIC,sDAAJ,EAbc,EAcd,IAAIC,2DAAJ,EAdc,EAed,IAAIC,8DAAJ,EAfc;AAgBd;AACJ;AACA;AACI,IAAIC,iEAAJ,EAnBc,CAAlB;AAqBA;AACA;AACA;AACA;;AACO,MAAMC,yBAAyB,GAAG,MAAMjB,SAAxC;;;;AAEA,MAAMkB,uCAAuC,GAAG,CACnDC,OADmD,EAEnDC,MAFmD,KAGO;EAC1D;AACJ;AACA;AACA;EACI,OAAOD,OAAO,CACTE,MADE,CAECC,gFAAA,CAAwCC,IAFzC,EAIFC,MAJE,CAIK,CAACC,GAAD,EAAMC,MAAN,KAAiB;IACrB,MAAMC,EAAE,GAAGD,MAAM,CAACE,WAAP,EAAX;IACA;AACZ;AACA;AACA;;IACY,IAAIF,MAAM,CAACG,iBAAP,CAAyBT,MAAzB,MAAqC,KAAzC,EAAgD;MAC5C,OAAOK,GAAP;IACH;IACD;AACZ;AACA;AACA;;;IACY,IAAI,CAAC,CAACA,GAAG,CAACE,EAAD,CAAL,IAAa,CAACD,MAAM,CAACI,IAAP,IAAe,EAAhB,EAAoBC,KAApB,CAA0B,YAA1B,CAAjB,EAA0D;MACtD,OAAON,GAAP;IACH;;IACDA,GAAG,CAACE,EAAD,CAAH,GAAUD,MAAV;IACA,OAAOD,GAAP;EACH,CAtBE,EAsBA,EAtBA,CAAP;AAuBH,CA/BM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-elasticsearch",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-unstable.40876133bb",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/webiny/webiny-js.git",
|
|
@@ -13,22 +13,22 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@elastic/elasticsearch": "7.12.0",
|
|
16
|
-
"@webiny/
|
|
17
|
-
"@webiny/
|
|
18
|
-
"@webiny/plugins": "0.0.0-
|
|
19
|
-
"@webiny/utils": "0.0.0-
|
|
20
|
-
"aws-elasticsearch-connector": "9.0
|
|
21
|
-
"aws-sdk": "2.
|
|
22
|
-
"elastic-ts": "0.
|
|
16
|
+
"@webiny/api": "0.0.0-unstable.40876133bb",
|
|
17
|
+
"@webiny/error": "0.0.0-unstable.40876133bb",
|
|
18
|
+
"@webiny/plugins": "0.0.0-unstable.40876133bb",
|
|
19
|
+
"@webiny/utils": "0.0.0-unstable.40876133bb",
|
|
20
|
+
"aws-elasticsearch-connector": "9.2.0",
|
|
21
|
+
"aws-sdk": "2.1230.0",
|
|
22
|
+
"elastic-ts": "0.8.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@babel/cli": "^7.
|
|
26
|
-
"@babel/core": "^7.
|
|
27
|
-
"@webiny/cli": "^0.0.0-
|
|
28
|
-
"@webiny/project-utils": "^0.0.0-
|
|
25
|
+
"@babel/cli": "^7.19.3",
|
|
26
|
+
"@babel/core": "^7.19.3",
|
|
27
|
+
"@webiny/cli": "^0.0.0-unstable.40876133bb",
|
|
28
|
+
"@webiny/project-utils": "^0.0.0-unstable.40876133bb",
|
|
29
29
|
"rimraf": "^3.0.2",
|
|
30
30
|
"ttypescript": "^1.5.12",
|
|
31
|
-
"typescript": "
|
|
31
|
+
"typescript": "4.7.4"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
]
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f33811072795d25c5787ae39808e75e3312fb247"
|
|
49
49
|
}
|
|
@@ -15,5 +15,10 @@ declare class GzipCompression extends CompressionPlugin {
|
|
|
15
15
|
canDecompress(data: CompressedData | Record<string, any>): boolean;
|
|
16
16
|
decompress(data: CompressedData): Promise<OriginalData | null>;
|
|
17
17
|
}
|
|
18
|
+
export declare const createGzipCompression: () => GzipCompression;
|
|
19
|
+
/**
|
|
20
|
+
* Left due to backward compatibility with older systems.
|
|
21
|
+
* Remove when upgraded the system to run from @webiny/api-serverless-cms-aws
|
|
22
|
+
*/
|
|
18
23
|
declare const _default: () => GzipCompression;
|
|
19
24
|
export default _default;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.createGzipCompression = void 0;
|
|
7
7
|
|
|
8
8
|
var _CompressionPlugin = require("./definition/CompressionPlugin");
|
|
9
9
|
|
|
@@ -68,8 +68,19 @@ class GzipCompression extends _CompressionPlugin.CompressionPlugin {
|
|
|
68
68
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
|
|
71
|
+
const createGzipCompression = () => {
|
|
72
72
|
return new GzipCompression();
|
|
73
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* Left due to backward compatibility with older systems.
|
|
76
|
+
* Remove when upgraded the system to run from @webiny/api-serverless-cms-aws
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
exports.createGzipCompression = createGzipCompression;
|
|
81
|
+
|
|
82
|
+
var _default = () => {
|
|
83
|
+
return createGzipCompression();
|
|
84
|
+
};
|
|
74
85
|
|
|
75
86
|
exports.default = _default;
|
|
@@ -0,0 +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\ninterface 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,MAAb;AACA,MAAMC,mBAAmB,GAAG,QAA5B;AACA,MAAMC,qBAAqB,GAAG,MAA9B;;AAEA,MAAMC,eAAe,GAAIC,KAAD,IAA4B;EAChD,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC3B,OAAOC,MAAM,CAACC,IAAP,CAAYF,KAAZ,EAAmBH,mBAAnB,CAAP;EACH;;EACD,OAAOG,KAAP;AACH,CALD;;AAgBA,MAAMG,eAAN,SAA8BC,oCAA9B,CAAgD;EACrCC,WAAW,CAACC,IAAD,EAAqB;IACnC;AACR;AACA;IACQ,IAAIA,IAAI,CAACC,WAAT,EAAsB;MAClB,IAAID,IAAI,CAACC,WAAL,KAAqB,MAAzB,EAAiC;QAC7BC,OAAO,CAACC,GAAR,CAAa,oCAAmCH,IAAI,CAACC,WAAY,IAAjE;MACH;;MACD,OAAO,KAAP;IACH;;IACD,OAAO,IAAP;EACH;;EACoB,MAARG,QAAQ,CAACJ,IAAD,EAAY;IAC7B,MAAMN,KAAK,GAAG,MAAM,IAAAW,cAAA,EAAKC,IAAI,CAACC,SAAL,CAAeP,IAAf,CAAL,CAApB;IAEA,OAAO;MACHC,WAAW,EAAEX,IADV;MAEHI,KAAK,EAAEA,KAAK,CAACc,QAAN,CAAejB,mBAAf;IAFJ,CAAP;EAIH;;EAEMkB,aAAa,CAACT,IAAD,EAAsD;IACtE,IAAI,CAACA,IAAD,IAAS,CAACA,IAAI,CAACC,WAAnB,EAAgC;MAC5B,OAAO,KAAP;IACH,CAFD,MAEO,IAAID,IAAI,CAACC,WAAL,KAAqBX,IAAzB,EAA+B;MAClCY,OAAO,CAACC,GAAR,CACK,iEAAgEb,IAAK,aAAYU,IAAI,CAACC,WAAY,IADvG;MAGA,OAAO,KAAP;IACH;;IACD,OAAO,IAAP;EACH;;EAEsB,MAAVS,UAAU,CAACV,IAAD,EAAqD;IACxE,IAAI;MACA,MAAMW,GAAG,GAAG,MAAM,IAAAC,gBAAA,EAAOnB,eAAe,CAACO,IAAI,CAACN,KAAN,CAAtB,CAAlB;MACA,MAAMA,KAAK,GAAGiB,GAAG,CAACH,QAAJ,CAAahB,qBAAb,CAAd;MACA,OAAOc,IAAI,CAACO,KAAL,CAAWnB,KAAX,CAAP;IACH,CAJD,CAIE,OAAOoB,EAAP,EAAW;MACT,OAAO,IAAP;IACH;EACJ;;AA1C2C;;AA6CzC,MAAMC,qBAAqB,GAAG,MAAM;EACvC,OAAO,IAAIlB,eAAJ,EAAP;AACH,CAFM;AAGP;AACA;AACA;AACA;;;;;eACe,MAAM;EACjB,OAAOkB,qBAAqB,EAA5B;AACH,C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["CompressionPlugin","Plugin"],"sources":["CompressionPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\n\nexport abstract class CompressionPlugin extends Plugin {\n public static override readonly type: string = \"elasticsearch.compression\";\n /**\n * Check if data can be compressed.\n */\n public abstract canCompress(data: any): boolean;\n /**\n * Pass the data to get the compressed one back.\n */\n public abstract compress(data: any): Promise<any>;\n /**\n * Check if data can be decompressed.\n */\n public abstract canDecompress(data: any): boolean;\n /**\n * Passed the compressed data to get the original data back.\n */\n public abstract decompress(data: any): Promise<any>;\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAEO,MAAeA,iBAAf,SAAyCC,eAAzC,CAAgD;;;8BAAjCD,iB,UAC6B,2B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchBodyModifierPlugin","Plugin","constructor","callable","modifyBody","params","WebinyError"],"sources":["ElasticsearchBodyModifierPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins\";\nimport { SearchBody } from \"elastic-ts\";\n\nexport interface ModifyBodyParams {\n body: SearchBody;\n}\n\nexport interface ModifyBodyCallable<T extends ModifyBodyParams> {\n (params: T): void;\n}\n\nexport abstract class ElasticsearchBodyModifierPlugin<\n T extends ModifyBodyParams = ModifyBodyParams\n> extends Plugin {\n private readonly callable?: ModifyBodyCallable<T>;\n\n public constructor(callable?: ModifyBodyCallable<T>) {\n super();\n this.callable = callable;\n }\n\n public modifyBody(params: T): void {\n if (typeof this.callable !== \"function\") {\n throw new WebinyError(\n `Missing modification for the body.`,\n \"BODY_MODIFICATION_MISSING\",\n {\n params\n }\n );\n }\n this.callable(params);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAWO,MAAeA,+BAAf,SAEGC,eAFH,CAEU;EAGNC,WAAW,CAACC,QAAD,EAAmC;IACjD;IADiD;IAEjD,KAAKA,QAAL,GAAgBA,QAAhB;EACH;;EAEMC,UAAU,CAACC,MAAD,EAAkB;IAC/B,IAAI,OAAO,KAAKF,QAAZ,KAAyB,UAA7B,EAAyC;MACrC,MAAM,IAAIG,cAAJ,CACD,oCADC,EAEF,2BAFE,EAGF;QACID;MADJ,CAHE,CAAN;IAOH;;IACD,KAAKF,QAAL,CAAcE,MAAd;EACH;;AAnBY"}
|
|
@@ -15,7 +15,7 @@ export interface ToSearchValueParams {
|
|
|
15
15
|
*/
|
|
16
16
|
basePath: string;
|
|
17
17
|
}
|
|
18
|
-
export interface
|
|
18
|
+
export interface ElasticsearchFieldPluginParams {
|
|
19
19
|
/**
|
|
20
20
|
* Which field is this plugin for.
|
|
21
21
|
*/
|
|
@@ -51,19 +51,13 @@ export interface Params {
|
|
|
51
51
|
export declare abstract class ElasticsearchFieldPlugin extends Plugin {
|
|
52
52
|
static readonly type: string;
|
|
53
53
|
static readonly ALL: string;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
get path(): string;
|
|
62
|
-
get keyword(): boolean;
|
|
63
|
-
get unmappedType(): string | undefined;
|
|
64
|
-
get sortable(): boolean;
|
|
65
|
-
get searchable(): boolean;
|
|
66
|
-
constructor(params: Params);
|
|
54
|
+
readonly field: string;
|
|
55
|
+
readonly path: string;
|
|
56
|
+
readonly keyword: boolean;
|
|
57
|
+
readonly unmappedType?: string;
|
|
58
|
+
readonly sortable: boolean;
|
|
59
|
+
readonly searchable: boolean;
|
|
60
|
+
constructor(params: ElasticsearchFieldPluginParams);
|
|
67
61
|
/**
|
|
68
62
|
* The default sort options. Extend in your own plugin if you want to add more options.
|
|
69
63
|
*/
|
|
@@ -1,24 +1,24 @@
|
|
|
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
|
|
7
7
|
});
|
|
8
8
|
exports.ElasticsearchFieldPlugin = void 0;
|
|
9
9
|
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
10
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
13
|
|
|
12
14
|
var _plugins = require("@webiny/plugins");
|
|
13
15
|
|
|
14
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
-
|
|
16
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
17
|
-
|
|
18
16
|
const keywordLessUnmappedType = ["date", "long"];
|
|
19
17
|
|
|
20
18
|
const unmappedTypeHasKeyword = type => {
|
|
21
|
-
if (
|
|
19
|
+
if (!type) {
|
|
20
|
+
return true;
|
|
21
|
+
} else if (keywordLessUnmappedType.includes(type)) {
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -26,49 +26,25 @@ const unmappedTypeHasKeyword = type => {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
29
|
-
get field() {
|
|
30
|
-
return this._field;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get path() {
|
|
34
|
-
return this._path;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get keyword() {
|
|
38
|
-
return this._keyword;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get unmappedType() {
|
|
42
|
-
return this._unmappedType;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get sortable() {
|
|
46
|
-
return this._sortable;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
get searchable() {
|
|
50
|
-
return this._searchable;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
29
|
constructor(params) {
|
|
54
30
|
super();
|
|
55
|
-
(0, _defineProperty2.default)(this, "
|
|
56
|
-
(0, _defineProperty2.default)(this, "
|
|
57
|
-
(0, _defineProperty2.default)(this, "
|
|
58
|
-
(0, _defineProperty2.default)(this, "
|
|
59
|
-
(0, _defineProperty2.default)(this, "
|
|
60
|
-
(0, _defineProperty2.default)(this, "
|
|
61
|
-
this.
|
|
62
|
-
this.
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
31
|
+
(0, _defineProperty2.default)(this, "field", void 0);
|
|
32
|
+
(0, _defineProperty2.default)(this, "path", void 0);
|
|
33
|
+
(0, _defineProperty2.default)(this, "keyword", void 0);
|
|
34
|
+
(0, _defineProperty2.default)(this, "unmappedType", void 0);
|
|
35
|
+
(0, _defineProperty2.default)(this, "sortable", void 0);
|
|
36
|
+
(0, _defineProperty2.default)(this, "searchable", void 0);
|
|
37
|
+
this.field = params.field;
|
|
38
|
+
this.path = params.path || params.field;
|
|
39
|
+
this.keyword = params.keyword === undefined ? true : params.keyword;
|
|
40
|
+
this.unmappedType = params.unmappedType;
|
|
65
41
|
|
|
66
42
|
if (unmappedTypeHasKeyword(params.unmappedType) === false) {
|
|
67
|
-
this.
|
|
43
|
+
this.keyword = false;
|
|
68
44
|
}
|
|
69
45
|
|
|
70
|
-
this.
|
|
71
|
-
this.
|
|
46
|
+
this.sortable = params.sortable === undefined ? true : params.sortable;
|
|
47
|
+
this.searchable = params.searchable === undefined ? true : params.searchable;
|
|
72
48
|
}
|
|
73
49
|
/**
|
|
74
50
|
* The default sort options. Extend in your own plugin if you want to add more options.
|
|
@@ -80,12 +56,12 @@ class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
|
80
56
|
order
|
|
81
57
|
};
|
|
82
58
|
|
|
83
|
-
if (!this.
|
|
59
|
+
if (!this.unmappedType) {
|
|
84
60
|
return options;
|
|
85
61
|
}
|
|
86
62
|
|
|
87
|
-
return
|
|
88
|
-
unmapped_type: this.
|
|
63
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, options), {}, {
|
|
64
|
+
unmapped_type: this.unmappedType
|
|
89
65
|
});
|
|
90
66
|
}
|
|
91
67
|
/**
|
|
@@ -95,7 +71,7 @@ class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
|
95
71
|
|
|
96
72
|
|
|
97
73
|
getPath(field) {
|
|
98
|
-
return `${this.getBasePath(field)}${this.
|
|
74
|
+
return `${this.getBasePath(field)}${this.keyword ? ".keyword" : ""}`;
|
|
99
75
|
}
|
|
100
76
|
/**
|
|
101
77
|
* @see getPath
|
|
@@ -105,11 +81,11 @@ class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
|
105
81
|
|
|
106
82
|
|
|
107
83
|
getBasePath(field) {
|
|
108
|
-
if (this.
|
|
84
|
+
if (this.path === ElasticsearchFieldPlugin.ALL) {
|
|
109
85
|
return field;
|
|
110
86
|
}
|
|
111
87
|
|
|
112
|
-
return this.
|
|
88
|
+
return this.path;
|
|
113
89
|
}
|
|
114
90
|
/**
|
|
115
91
|
* The default transformer. Just returns the value by default.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["keywordLessUnmappedType","unmappedTypeHasKeyword","type","includes","ElasticsearchFieldPlugin","Plugin","constructor","params","field","path","keyword","undefined","unmappedType","sortable","searchable","getSortOptions","order","options","unmapped_type","getPath","getBasePath","ALL","toSearchValue","value"],"sources":["ElasticsearchFieldPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { FieldSortOptions, SortOrder } from \"elastic-ts\";\n\nexport type UnmappedTypes = \"date\" | \"long\" | string;\n\nconst keywordLessUnmappedType = [\"date\", \"long\"];\n\nconst unmappedTypeHasKeyword = (type?: string): boolean => {\n if (!type) {\n return true;\n } else if (keywordLessUnmappedType.includes(type)) {\n return false;\n }\n return true;\n};\n\nexport interface ToSearchValueParams {\n /**\n * The value to transform.\n */\n value: any;\n /**\n * When using toSearchValue() in our code we send a field.getPath() value here.\n */\n path: string;\n /**\n * When using toSearchValue() in our code we send a field.getBasePath() value here.\n */\n basePath: string;\n}\nexport interface ElasticsearchFieldPluginParams {\n /**\n * Which field is this plugin for.\n */\n field: string;\n /**\n * Some specific path of a field?\n * Example: createdBy is createdBy.id\n */\n path?: string;\n /**\n * Add a .keyword at the end of the field path?\n */\n keyword?: boolean;\n /**\n * Is the field of a specific type, but possibly not mapped?\n * Happens when inserting a date in string format.\n * You need to cast it as date when running the search/sort to work correctly.\n */\n unmappedType?: UnmappedTypes;\n /**\n * Is the field sortable?\n */\n sortable?: boolean;\n /**\n * Is the field searchable?\n */\n searchable?: boolean;\n /**\n * Used to transform the input value for the search.\n */\n toSearchValue?: (params: ToSearchValueParams) => any;\n}\n\nexport abstract class ElasticsearchFieldPlugin extends Plugin {\n public static override readonly type: string = \"elasticsearch.fieldDefinition\";\n public static readonly ALL: string = \"*\";\n\n public readonly field: string;\n public readonly path: string;\n public readonly keyword: boolean;\n public readonly unmappedType?: string;\n public readonly sortable: boolean;\n public readonly searchable: boolean;\n\n constructor(params: ElasticsearchFieldPluginParams) {\n super();\n this.field = params.field;\n this.path = params.path || params.field;\n this.keyword = params.keyword === undefined ? true : params.keyword;\n this.unmappedType = params.unmappedType;\n if (unmappedTypeHasKeyword(params.unmappedType) === false) {\n this.keyword = false;\n }\n this.sortable = params.sortable === undefined ? true : params.sortable;\n this.searchable = params.searchable === undefined ? true : params.searchable;\n }\n /**\n * The default sort options. Extend in your own plugin if you want to add more options.\n */\n public getSortOptions(order: SortOrder): FieldSortOptions {\n const options = {\n order\n };\n if (!this.unmappedType) {\n return options;\n }\n return {\n ...options,\n unmapped_type: this.unmappedType\n };\n }\n /**\n * The default path generator. Extend in your own plugin if you want to add more options.\n * Field parameter is here because there is a possibility that this is the ALL field plugin, so we need to know which field are we working on.\n */\n public getPath(field: string): string {\n return `${this.getBasePath(field)}${this.keyword ? \".keyword\" : \"\"}`;\n }\n /**\n * @see getPath\n *\n * This is the default base path generator. Basically it replaces ALL with given field name.\n */\n public getBasePath(field: string): string {\n if (this.path === ElasticsearchFieldPlugin.ALL) {\n return field;\n }\n return this.path;\n }\n /**\n * The default transformer. Just returns the value by default.\n * Override to implement what ever is required.\n */\n public toSearchValue(params: ToSearchValueParams): any {\n return params.value;\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AAKA,MAAMA,uBAAuB,GAAG,CAAC,MAAD,EAAS,MAAT,CAAhC;;AAEA,MAAMC,sBAAsB,GAAIC,IAAD,IAA4B;EACvD,IAAI,CAACA,IAAL,EAAW;IACP,OAAO,IAAP;EACH,CAFD,MAEO,IAAIF,uBAAuB,CAACG,QAAxB,CAAiCD,IAAjC,CAAJ,EAA4C;IAC/C,OAAO,KAAP;EACH;;EACD,OAAO,IAAP;AACH,CAPD;;AAyDO,MAAeE,wBAAf,SAAgDC,eAAhD,CAAuD;EAW1DC,WAAW,CAACC,MAAD,EAAyC;IAChD;IADgD;IAAA;IAAA;IAAA;IAAA;IAAA;IAEhD,KAAKC,KAAL,GAAaD,MAAM,CAACC,KAApB;IACA,KAAKC,IAAL,GAAYF,MAAM,CAACE,IAAP,IAAeF,MAAM,CAACC,KAAlC;IACA,KAAKE,OAAL,GAAeH,MAAM,CAACG,OAAP,KAAmBC,SAAnB,GAA+B,IAA/B,GAAsCJ,MAAM,CAACG,OAA5D;IACA,KAAKE,YAAL,GAAoBL,MAAM,CAACK,YAA3B;;IACA,IAAIX,sBAAsB,CAACM,MAAM,CAACK,YAAR,CAAtB,KAAgD,KAApD,EAA2D;MACvD,KAAKF,OAAL,GAAe,KAAf;IACH;;IACD,KAAKG,QAAL,GAAgBN,MAAM,CAACM,QAAP,KAAoBF,SAApB,GAAgC,IAAhC,GAAuCJ,MAAM,CAACM,QAA9D;IACA,KAAKC,UAAL,GAAkBP,MAAM,CAACO,UAAP,KAAsBH,SAAtB,GAAkC,IAAlC,GAAyCJ,MAAM,CAACO,UAAlE;EACH;EACD;AACJ;AACA;;;EACWC,cAAc,CAACC,KAAD,EAAqC;IACtD,MAAMC,OAAO,GAAG;MACZD;IADY,CAAhB;;IAGA,IAAI,CAAC,KAAKJ,YAAV,EAAwB;MACpB,OAAOK,OAAP;IACH;;IACD,mEACOA,OADP;MAEIC,aAAa,EAAE,KAAKN;IAFxB;EAIH;EACD;AACJ;AACA;AACA;;;EACWO,OAAO,CAACX,KAAD,EAAwB;IAClC,OAAQ,GAAE,KAAKY,WAAL,CAAiBZ,KAAjB,CAAwB,GAAE,KAAKE,OAAL,GAAe,UAAf,GAA4B,EAAG,EAAnE;EACH;EACD;AACJ;AACA;AACA;AACA;;;EACWU,WAAW,CAACZ,KAAD,EAAwB;IACtC,IAAI,KAAKC,IAAL,KAAcL,wBAAwB,CAACiB,GAA3C,EAAgD;MAC5C,OAAOb,KAAP;IACH;;IACD,OAAO,KAAKC,IAAZ;EACH;EACD;AACJ;AACA;AACA;;;EACWa,aAAa,CAACf,MAAD,EAAmC;IACnD,OAAOA,MAAM,CAACgB,KAAd;EACH;;AA9DyD;;;8BAAxCnB,wB,UAC6B,+B;8BAD7BA,wB,SAEmB,G"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import { ElasticsearchIndexRequestBody } from "../../types";
|
|
3
|
+
export interface ElasticsearchIndexPluginParams {
|
|
4
|
+
/**
|
|
5
|
+
* For which locales are we applying this plugin.
|
|
6
|
+
* Options:
|
|
7
|
+
* - locale codes to target specific locale
|
|
8
|
+
* - null for all
|
|
9
|
+
*/
|
|
10
|
+
locales?: string[];
|
|
11
|
+
body: ElasticsearchIndexRequestBody;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class ElasticsearchIndexPlugin extends Plugin {
|
|
14
|
+
readonly body: ElasticsearchIndexRequestBody;
|
|
15
|
+
private readonly locales;
|
|
16
|
+
constructor(params: ElasticsearchIndexPluginParams);
|
|
17
|
+
canUse(locale: string): boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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.ElasticsearchIndexPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
15
|
+
|
|
16
|
+
var _plugins = require("@webiny/plugins");
|
|
17
|
+
|
|
18
|
+
class ElasticsearchIndexPlugin extends _plugins.Plugin {
|
|
19
|
+
constructor(params) {
|
|
20
|
+
super();
|
|
21
|
+
(0, _defineProperty2.default)(this, "body", void 0);
|
|
22
|
+
(0, _defineProperty2.default)(this, "locales", void 0);
|
|
23
|
+
const {
|
|
24
|
+
locales,
|
|
25
|
+
body
|
|
26
|
+
} = params;
|
|
27
|
+
this.body = (0, _objectSpread2.default)({}, body);
|
|
28
|
+
this.locales = locales ? locales.map(locale => locale.toLowerCase()) : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
canUse(locale) {
|
|
32
|
+
if (!this.locales) {
|
|
33
|
+
return true;
|
|
34
|
+
} else if (this.locales.length === 0) {
|
|
35
|
+
throw new _error.default("Cannot have Elasticsearch Index Template plugin with no locales defined.", "LOCALES_ERROR", {
|
|
36
|
+
body: this.body,
|
|
37
|
+
locales: this.locales
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return this.locales.includes(locale.toLowerCase());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
exports.ElasticsearchIndexPlugin = ElasticsearchIndexPlugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ElasticsearchIndexPlugin","Plugin","constructor","params","locales","body","map","locale","toLowerCase","undefined","canUse","length","WebinyError","includes"],"sources":["ElasticsearchIndexPlugin.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { Plugin } from \"@webiny/plugins\";\nimport { ElasticsearchIndexRequestBody } from \"~/types\";\n\nexport interface ElasticsearchIndexPluginParams {\n /**\n * For which locales are we applying this plugin.\n * Options:\n * - locale codes to target specific locale\n * - null for all\n */\n locales?: string[];\n body: ElasticsearchIndexRequestBody;\n}\n\nexport abstract class ElasticsearchIndexPlugin extends Plugin {\n public readonly body: ElasticsearchIndexRequestBody;\n private readonly locales: string[] | undefined;\n\n public constructor(params: ElasticsearchIndexPluginParams) {\n super();\n const { locales, body } = params;\n this.body = {\n ...body\n };\n this.locales = locales ? locales.map(locale => locale.toLowerCase()) : undefined;\n }\n\n public canUse(locale: string): boolean {\n if (!this.locales) {\n return true;\n } else if (this.locales.length === 0) {\n throw new WebinyError(\n \"Cannot have Elasticsearch Index Template plugin with no locales defined.\",\n \"LOCALES_ERROR\",\n {\n body: this.body,\n locales: this.locales\n }\n );\n }\n return this.locales.includes(locale.toLowerCase());\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAcO,MAAeA,wBAAf,SAAgDC,eAAhD,CAAuD;EAInDC,WAAW,CAACC,MAAD,EAAyC;IACvD;IADuD;IAAA;IAEvD,MAAM;MAAEC,OAAF;MAAWC;IAAX,IAAoBF,MAA1B;IACA,KAAKE,IAAL,mCACOA,IADP;IAGA,KAAKD,OAAL,GAAeA,OAAO,GAAGA,OAAO,CAACE,GAAR,CAAYC,MAAM,IAAIA,MAAM,CAACC,WAAP,EAAtB,CAAH,GAAiDC,SAAvE;EACH;;EAEMC,MAAM,CAACH,MAAD,EAA0B;IACnC,IAAI,CAAC,KAAKH,OAAV,EAAmB;MACf,OAAO,IAAP;IACH,CAFD,MAEO,IAAI,KAAKA,OAAL,CAAaO,MAAb,KAAwB,CAA5B,EAA+B;MAClC,MAAM,IAAIC,cAAJ,CACF,0EADE,EAEF,eAFE,EAGF;QACIP,IAAI,EAAE,KAAKA,IADf;QAEID,OAAO,EAAE,KAAKA;MAFlB,CAHE,CAAN;IAQH;;IACD,OAAO,KAAKA,OAAL,CAAaS,QAAb,CAAsBN,MAAM,CAACC,WAAP,EAAtB,CAAP;EACH;;AA3ByD"}
|
|
@@ -4,7 +4,11 @@ import { ElasticsearchBoolQueryConfig, ElasticsearchQueryBuilderArgsPlugin } fro
|
|
|
4
4
|
* Built-in operators name ends with .default because user can override the operator, just write a name without the .default keyword.
|
|
5
5
|
*/
|
|
6
6
|
export declare abstract class ElasticsearchQueryBuilderOperatorPlugin extends Plugin {
|
|
7
|
-
static readonly type
|
|
7
|
+
static readonly type: string;
|
|
8
|
+
/**
|
|
9
|
+
* Check if current locale is supported by this plugin.
|
|
10
|
+
*/
|
|
11
|
+
isLocaleSupported(_: string): boolean;
|
|
8
12
|
abstract getOperator(): string;
|
|
9
13
|
abstract apply(query: ElasticsearchBoolQueryConfig, params: ElasticsearchQueryBuilderArgsPlugin): void;
|
|
10
14
|
}
|