@webiny/api-elasticsearch 5.32.0 → 5.33.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-elasticsearch",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.33.0-beta.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/webiny/webiny-js.git",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@elastic/elasticsearch": "7.12.0",
|
|
16
|
-
"@webiny/api": "5.
|
|
17
|
-
"@webiny/error": "5.
|
|
18
|
-
"@webiny/plugins": "5.
|
|
19
|
-
"@webiny/utils": "5.
|
|
16
|
+
"@webiny/api": "5.33.0-beta.0",
|
|
17
|
+
"@webiny/error": "5.33.0-beta.0",
|
|
18
|
+
"@webiny/plugins": "5.33.0-beta.0",
|
|
19
|
+
"@webiny/utils": "5.33.0-beta.0",
|
|
20
20
|
"aws-elasticsearch-connector": "9.2.0",
|
|
21
21
|
"aws-sdk": "2.1188.0",
|
|
22
22
|
"elastic-ts": "0.7.0"
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/cli": "^7.16.0",
|
|
26
26
|
"@babel/core": "^7.16.0",
|
|
27
|
-
"@webiny/cli": "^5.
|
|
28
|
-
"@webiny/project-utils": "^5.
|
|
27
|
+
"@webiny/cli": "^5.33.0-beta.0",
|
|
28
|
+
"@webiny/project-utils": "^5.33.0-beta.0",
|
|
29
29
|
"rimraf": "^3.0.2",
|
|
30
30
|
"ttypescript": "^1.5.12",
|
|
31
31
|
"typescript": "4.7.4"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
]
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "8809a70796e5117e92416d6859c1f5dcae2a8c98"
|
|
49
49
|
}
|
|
@@ -51,18 +51,12 @@ export interface ElasticsearchFieldPluginParams {
|
|
|
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
|
-
get field(): string;
|
|
61
|
-
get path(): string;
|
|
62
|
-
get keyword(): boolean;
|
|
63
|
-
get unmappedType(): string | undefined;
|
|
64
|
-
get sortable(): boolean;
|
|
65
|
-
get searchable(): boolean;
|
|
54
|
+
readonly field: string;
|
|
55
|
+
readonly path: string;
|
|
56
|
+
readonly keyword: boolean;
|
|
57
|
+
readonly unmappedType?: string;
|
|
58
|
+
readonly sortable: boolean;
|
|
59
|
+
readonly searchable: boolean;
|
|
66
60
|
constructor(params: ElasticsearchFieldPluginParams);
|
|
67
61
|
/**
|
|
68
62
|
* The default sort options. Extend in your own plugin if you want to add more options.
|
|
@@ -28,49 +28,25 @@ const unmappedTypeHasKeyword = type => {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
31
|
-
get field() {
|
|
32
|
-
return this._field;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get path() {
|
|
36
|
-
return this._path;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get keyword() {
|
|
40
|
-
return this._keyword;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get unmappedType() {
|
|
44
|
-
return this._unmappedType;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
get sortable() {
|
|
48
|
-
return this._sortable;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
get searchable() {
|
|
52
|
-
return this._searchable;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
31
|
constructor(params) {
|
|
56
32
|
super();
|
|
57
|
-
(0, _defineProperty2.default)(this, "
|
|
58
|
-
(0, _defineProperty2.default)(this, "
|
|
59
|
-
(0, _defineProperty2.default)(this, "
|
|
60
|
-
(0, _defineProperty2.default)(this, "
|
|
61
|
-
(0, _defineProperty2.default)(this, "
|
|
62
|
-
(0, _defineProperty2.default)(this, "
|
|
63
|
-
this.
|
|
64
|
-
this.
|
|
65
|
-
this.
|
|
66
|
-
this.
|
|
33
|
+
(0, _defineProperty2.default)(this, "field", void 0);
|
|
34
|
+
(0, _defineProperty2.default)(this, "path", void 0);
|
|
35
|
+
(0, _defineProperty2.default)(this, "keyword", void 0);
|
|
36
|
+
(0, _defineProperty2.default)(this, "unmappedType", void 0);
|
|
37
|
+
(0, _defineProperty2.default)(this, "sortable", void 0);
|
|
38
|
+
(0, _defineProperty2.default)(this, "searchable", void 0);
|
|
39
|
+
this.field = params.field;
|
|
40
|
+
this.path = params.path || params.field;
|
|
41
|
+
this.keyword = params.keyword === undefined ? true : params.keyword;
|
|
42
|
+
this.unmappedType = params.unmappedType;
|
|
67
43
|
|
|
68
44
|
if (unmappedTypeHasKeyword(params.unmappedType) === false) {
|
|
69
|
-
this.
|
|
45
|
+
this.keyword = false;
|
|
70
46
|
}
|
|
71
47
|
|
|
72
|
-
this.
|
|
73
|
-
this.
|
|
48
|
+
this.sortable = params.sortable === undefined ? true : params.sortable;
|
|
49
|
+
this.searchable = params.searchable === undefined ? true : params.searchable;
|
|
74
50
|
}
|
|
75
51
|
/**
|
|
76
52
|
* The default sort options. Extend in your own plugin if you want to add more options.
|
|
@@ -82,12 +58,12 @@ class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
|
82
58
|
order
|
|
83
59
|
};
|
|
84
60
|
|
|
85
|
-
if (!this.
|
|
61
|
+
if (!this.unmappedType) {
|
|
86
62
|
return options;
|
|
87
63
|
}
|
|
88
64
|
|
|
89
65
|
return _objectSpread(_objectSpread({}, options), {}, {
|
|
90
|
-
unmapped_type: this.
|
|
66
|
+
unmapped_type: this.unmappedType
|
|
91
67
|
});
|
|
92
68
|
}
|
|
93
69
|
/**
|
|
@@ -97,7 +73,7 @@ class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
|
97
73
|
|
|
98
74
|
|
|
99
75
|
getPath(field) {
|
|
100
|
-
return `${this.getBasePath(field)}${this.
|
|
76
|
+
return `${this.getBasePath(field)}${this.keyword ? ".keyword" : ""}`;
|
|
101
77
|
}
|
|
102
78
|
/**
|
|
103
79
|
* @see getPath
|
|
@@ -107,11 +83,11 @@ class ElasticsearchFieldPlugin extends _plugins.Plugin {
|
|
|
107
83
|
|
|
108
84
|
|
|
109
85
|
getBasePath(field) {
|
|
110
|
-
if (this.
|
|
86
|
+
if (this.path === ElasticsearchFieldPlugin.ALL) {
|
|
111
87
|
return field;
|
|
112
88
|
}
|
|
113
89
|
|
|
114
|
-
return this.
|
|
90
|
+
return this.path;
|
|
115
91
|
}
|
|
116
92
|
/**
|
|
117
93
|
* The default transformer. Just returns the value by default.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["keywordLessUnmappedType","unmappedTypeHasKeyword","type","includes","ElasticsearchFieldPlugin","Plugin","
|
|
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,uCACOA,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"}
|
package/sort.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { SortType, SortOrder } from "./types";
|
|
2
2
|
import { ElasticsearchFieldPlugin } from "./plugins/definition/ElasticsearchFieldPlugin";
|
|
3
|
+
interface SortOption {
|
|
4
|
+
path: string;
|
|
5
|
+
order: "ASC" | "DESC" | "asc" | "desc";
|
|
6
|
+
}
|
|
3
7
|
interface CreateSortParams {
|
|
4
|
-
sort: string[];
|
|
8
|
+
sort: string[] | SortOption[];
|
|
5
9
|
defaults?: {
|
|
6
10
|
field?: string;
|
|
7
11
|
order?: SortOrder;
|
package/sort.js
CHANGED
|
@@ -9,8 +9,9 @@ exports.createSort = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
11
11
|
|
|
12
|
-
const sortRegExp = new RegExp(/^([a-zA-Z-0-9_]+)_(ASC|DESC)$/);
|
|
12
|
+
const sortRegExp = new RegExp(/^([a-zA-Z-0-9_@]+)_(ASC|DESC)$/);
|
|
13
13
|
|
|
14
|
+
// TODO refactor so the sort input is of SortOption type
|
|
14
15
|
const createSort = params => {
|
|
15
16
|
const {
|
|
16
17
|
sort,
|
|
@@ -35,8 +36,17 @@ const createSort = params => {
|
|
|
35
36
|
}
|
|
36
37
|
};
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Cast as string because nothing else should be allowed yet.
|
|
41
|
+
*/
|
|
42
|
+
// @ts-refactor
|
|
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) {
|
package/sort.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["sortRegExp","RegExp","createSort","params","sort","defaults","fieldPlugins","length","field","order","unmappedType","unmapped_type","undefined","reduce","acc","value","
|
|
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","path","getPath","getSortOptions"],"sources":["sort.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport { FieldSortOptions, SortType, SortOrder } from \"./types\";\nimport { ElasticsearchFieldPlugin } from \"./plugins/definition/ElasticsearchFieldPlugin\";\n\nconst sortRegExp = new RegExp(/^([a-zA-Z-0-9_@]+)_(ASC|DESC)$/);\n\ninterface SortOption {\n path: string;\n order: \"ASC\" | \"DESC\" | \"asc\" | \"desc\";\n}\ninterface CreateSortParams {\n sort: string[] | SortOption[];\n defaults?: {\n field?: string;\n order?: SortOrder;\n unmappedType?: string;\n };\n fieldPlugins: Record<string, ElasticsearchFieldPlugin>;\n}\n// TODO refactor so the sort input is of SortOption type\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 // @ts-refactor\n return (sort as string[]).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 = fieldPlugins[field] || fieldPlugins[\"*\"];\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;;AAIA,MAAMA,UAAU,GAAG,IAAIC,MAAJ,CAAW,gCAAX,CAAnB;;AAeA;AACO,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;;;EACA,OAAQR,IAAD,CAAmBS,MAAnB,CAA0B,CAACC,GAAD,EAAMC,KAAN,KAAgB;IAC7C,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,GAAGd,YAAY,CAACE,KAAD,CAAZ,IAAuBF,YAAY,CAAC,GAAD,CAA5E;;IACA,IAAI,CAACc,MAAL,EAAa;MACT,MAAM,IAAIJ,cAAJ,CAAiB,iCAAgCR,KAAM,GAAvD,EAA2D,mBAA3D,EAAgF;QAClFA;MADkF,CAAhF,CAAN;IAGH;IACD;AACR;AACA;AACA;;;IACQ,MAAMa,IAAI,GAAGD,MAAM,CAACE,OAAP,CAAed,KAAf,CAAb;IAEAM,GAAG,CAACO,IAAD,CAAH,GAAYD,MAAM,CAACG,cAAP,CAAsBd,KAAtB,CAAZ;IAEA,OAAOK,GAAP;EACH,CA5BM,EA4BJ,EA5BI,CAAP;AA6BH,CA/CM"}
|