kuzzle 2.60.1 → 2.61.0-beta.2

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.
Files changed (52) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +2 -0
  3. package/dist/lib/cluster/idCardHandler.d.ts +11 -1
  4. package/dist/lib/cluster/idCardHandler.js +10 -2
  5. package/dist/lib/cluster/node.d.ts +14 -0
  6. package/dist/lib/cluster/node.js +19 -0
  7. package/dist/lib/config/index.js +43 -8
  8. package/dist/lib/core/backend/backendStorage.js +4 -6
  9. package/dist/lib/core/plugin/pluginContext.js +2 -2
  10. package/dist/lib/core/storage/clientAdapter.d.ts +13 -10
  11. package/dist/lib/core/storage/clientAdapter.js +112 -60
  12. package/dist/lib/core/storage/conformance/capabilityCases.d.ts +3 -0
  13. package/dist/lib/core/storage/conformance/capabilityCases.js +121 -0
  14. package/dist/lib/core/storage/conformance/conformanceContext.d.ts +33 -0
  15. package/dist/lib/core/storage/conformance/conformanceContext.js +97 -0
  16. package/dist/lib/core/storage/conformance/conformanceEnvironment.d.ts +7 -0
  17. package/dist/lib/core/storage/conformance/conformanceEnvironment.js +136 -0
  18. package/dist/lib/core/storage/conformance/coreCases.d.ts +3 -0
  19. package/dist/lib/core/storage/conformance/coreCases.js +381 -0
  20. package/dist/lib/core/storage/conformance/storageDriverConformance.d.ts +53 -0
  21. package/dist/lib/core/storage/conformance/storageDriverConformance.js +89 -0
  22. package/dist/lib/core/storage/indexCache.d.ts +26 -2
  23. package/dist/lib/core/storage/indexCache.js +100 -2
  24. package/dist/lib/core/storage/storageDriverLoader.d.ts +41 -0
  25. package/dist/lib/core/storage/storageDriverLoader.js +276 -0
  26. package/dist/lib/core/storage/storageEngine.js +9 -1
  27. package/dist/lib/core/storage/storageError.d.ts +15 -0
  28. package/dist/lib/core/storage/storageError.js +36 -0
  29. package/dist/lib/kerror/codes/1-services.json +35 -0
  30. package/dist/lib/kerror/codes/8-cluster.json +6 -0
  31. package/dist/lib/service/storage/builtInDrivers.d.ts +6 -0
  32. package/dist/lib/service/storage/builtInDrivers.js +103 -0
  33. package/dist/lib/service/storage/storageService.d.ts +13 -0
  34. package/dist/lib/service/storage/storageService.js +44 -0
  35. package/dist/lib/types/config/KuzzleConfiguration.d.ts +8 -0
  36. package/dist/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +13 -1
  37. package/dist/lib/types/index.d.ts +1 -0
  38. package/dist/lib/types/index.js +1 -0
  39. package/dist/lib/types/storage/StorageDriver.d.ts +306 -0
  40. package/dist/lib/types/storage/StorageDriver.js +41 -0
  41. package/dist/package.json +4 -1
  42. package/package.json +4 -1
  43. package/dist/lib/service/storage/7/elasticsearch.d.ts +0 -1054
  44. package/dist/lib/service/storage/7/elasticsearch.js +0 -3063
  45. package/dist/lib/service/storage/7/esWrapper.d.ts +0 -36
  46. package/dist/lib/service/storage/7/esWrapper.js +0 -295
  47. package/dist/lib/service/storage/8/elasticsearch.d.ts +0 -1047
  48. package/dist/lib/service/storage/8/elasticsearch.js +0 -3096
  49. package/dist/lib/service/storage/8/esWrapper.d.ts +0 -36
  50. package/dist/lib/service/storage/8/esWrapper.js +0 -295
  51. package/dist/lib/service/storage/Elasticsearch.d.ts +0 -16
  52. package/dist/lib/service/storage/Elasticsearch.js +0 -48
@@ -1,36 +0,0 @@
1
- import type { Client } from "sdk-es8";
2
- import type { JSONObject } from "../../../types/JSONObject";
3
- import { KuzzleError } from "../../../kerror/errors";
4
- /**
5
- * What the Elasticsearch client throws: an Error, carrying the server's
6
- * response on `meta` for the ones that came back from the cluster. `catch`
7
- * hands callers `unknown`, and this is the shape every reader below assumes.
8
- */
9
- type ThrownESError = Error & {
10
- meta?: JSONObject;
11
- body?: JSONObject;
12
- };
13
- /**
14
- * One that came back from the cluster rather than from the client itself, so
15
- * its `meta` is present — which is what `formatESError` checks before handing
16
- * it to the handlers below.
17
- */
18
- type ThrownESResponseError = ThrownESError & {
19
- meta: JSONObject;
20
- };
21
- declare class ESWrapper {
22
- client: Client;
23
- constructor(client: Client);
24
- /**
25
- * Transforms raw ES errors into a normalized Kuzzle version
26
- *
27
- * @param error
28
- */
29
- formatESError(error: unknown): KuzzleError;
30
- reject(error: unknown): Promise<never>;
31
- _handleConflictError(error: ThrownESResponseError, message: string): KuzzleError;
32
- _handleNotFoundError(error: ThrownESResponseError, message: string): KuzzleError;
33
- _handleBadRequestError(error: ThrownESResponseError, message: string): KuzzleError;
34
- _handleUnknownError(error: ThrownESError, message: string): KuzzleError;
35
- }
36
- export = ESWrapper;
@@ -1,295 +0,0 @@
1
- "use strict";
2
- /*
3
- * Kuzzle, a backend software, self-hostable and ready to use
4
- * to power modern apps
5
- *
6
- * Copyright 2015-2022 Kuzzle
7
- * mailto: support AT kuzzle.io
8
- * website: http://kuzzle.io
9
- *
10
- * Licensed under the Apache License, Version 2.0 (the "License");
11
- * you may not use this file except in compliance with the License.
12
- * You may obtain a copy of the License at
13
- *
14
- * https://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- /* eslint sort-keys: 0 */
26
- const node_util_1 = require("node:util");
27
- const bluebird_1 = __importDefault(require("bluebird"));
28
- const get_1 = __importDefault(require("lodash/get"));
29
- const sdk_es8_1 = require("sdk-es8");
30
- const errors_1 = require("../../../kerror/errors");
31
- const debug_1 = __importDefault(require("../../../util/debug"));
32
- const kerror_1 = require("../../../kerror");
33
- const debug = (0, debug_1.default)("kuzzle:services:storage:ESCommon");
34
- const kerror = (0, kerror_1.wrap)("services", "storage");
35
- function isResponseError(error) {
36
- return Boolean(error.meta);
37
- }
38
- /**
39
- * What the client puts in `message` when the response carried nothing it could
40
- * read: this placeholder, or an empty string for a bodyless response.
41
- */
42
- const CLIENT_PLACEHOLDER_MESSAGE = "Response Error";
43
- function isUsableMessage(message) {
44
- return (typeof message === "string" &&
45
- message.trim() !== "" &&
46
- message !== CLIENT_PLACEHOLDER_MESSAGE);
47
- }
48
- /**
49
- * A message for an error that came with none worth keeping (typically a 503
50
- * with no body while shards initialize), built from what the error still
51
- * carries: the client's error name, the HTTP status and the response body.
52
- */
53
- function describeUnreadableError(error) {
54
- const statusCode = error.meta?.statusCode;
55
- const body = error.meta?.body;
56
- const hasBody = body !== undefined && body !== null && body !== "";
57
- let description = statusCode === undefined
58
- ? "Elasticsearch request failed"
59
- : `Elasticsearch responded ${statusCode}`;
60
- description += hasBody
61
- ? `: ${(0, node_util_1.inspect)(body, { breakLength: Infinity, depth: 3 })}`
62
- : " (no body)";
63
- return error.name && error.name !== "Error"
64
- ? `${error.name}: ${description}`
65
- : description;
66
- }
67
- const errorMessagesMapping = [
68
- {
69
- regex: /^\[es_rejected_execution_exception] rejected execution .*? on EsThreadPoolExecutor\[(.*?), .*$/,
70
- subcode: "too_many_operations",
71
- getPlaceholders: (esError, matches) => [matches[1]],
72
- },
73
- {
74
- // [illegal_argument_exception] object mapping [titi] can't be changed from nested to non-nested
75
- regex: /^\[illegal_argument_exception] object mapping \[(.*?)] can't be changed from nested to non-nested$/,
76
- subcode: "cannot_change_mapping",
77
- getPlaceholders: (esError, matches) => [matches[1]],
78
- },
79
- {
80
- // [illegal_argument_exception] object mapping [baz] can't be changed from non-nested to nested
81
- regex: /^\[illegal_argument_exception] object mapping \[(.*?)] can't be changed from non-nested to nested$/,
82
- subcode: "cannot_change_mapping",
83
- getPlaceholders: (esError, matches) => [matches[1]],
84
- },
85
- {
86
- // [illegal_argument_exception] Can't merge a non object mapping [aeaze] with an object mapping [aeaze]
87
- regex: /^\[illegal_argument_exception] Can't merge a non object mapping \[(.*?)] with an object mapping \[(.*?)]$/,
88
- subcode: "cannot_change_mapping",
89
- getPlaceholders: (esError, matches) => [matches[1]],
90
- },
91
- {
92
- // [illegal_argument_exception] [tutu.tutu] is defined as an object in mapping [aze] but this name is already used for a field in other types
93
- regex: /^\[illegal_argument_exception] \[(.*?)] is defined as an object in mapping \[(.*?)] but this name is already used for a field in other types$/,
94
- subcode: "duplicate_field_mapping",
95
- getPlaceholders: (esError, matches) => [matches[1], matches[2]],
96
- },
97
- {
98
- // [illegal_argument_exception] mapper [source.flags] of different type, current_type [string], merged_type [long]
99
- regex: /^mapper \[(.*?)] of different type, current_type \[(.*?)], merged_type \[(.*?)]$/,
100
- subcode: "cannot_change_mapping",
101
- getPlaceholders: (esError, matches) => [matches[1]],
102
- },
103
- {
104
- // [mapper_parsing_exception] Mapping definition for [flags] has unsupported parameters: [index : not_analyzed]
105
- // eslint-disable-next-line no-regex-spaces
106
- regex: /^\[mapper_parsing_exception] Mapping definition for \[(.*?)] has unsupported parameters: \[(.*?)]$/,
107
- subcode: "unexpected_properties",
108
- getPlaceholders: (esError, matches) => [matches[2], matches[1]],
109
- },
110
- {
111
- // [mapper_parsing_exception] No handler for type [boolean] declared on field [not]
112
- regex: /^\[mapper_parsing_exception] No handler for type \[(.*?)] declared on field \[(.*?)]$/,
113
- subcode: "invalid_mapping_type",
114
- getPlaceholders: (esError, matches) => [matches[2], matches[1]],
115
- },
116
- {
117
- // [mapper_parsing_exception] failed to parse [conditions.host.flags]
118
- regex: /^\[mapper_parsing_exception] failed to parse \[(.*?)]$/,
119
- subcode: "wrong_mapping_property",
120
- getPlaceholders: (esError, matches) => [matches[1]],
121
- },
122
- {
123
- // Failed to parse mapping [_doc]: Expected map for property [fields] on field [enabled] but got a class java.lang.String
124
- regex: /^Failed to parse mapping \[.*\]: Expected \w+ for property \[(.*)\] on field \[(.*)\]/,
125
- subcode: "wrong_mapping_property",
126
- getPlaceholders: (esError, matches) => [`${matches[2]}.${matches[1]}`],
127
- },
128
- {
129
- // [index_not_found_exception] no such index, with { resource.type=index_or_alias & resource.id=foso & index=foso }
130
- regex: /^no such index \[([%&])([^\]]*)\.([^.\]]*)\]$/,
131
- subcode: "unknown_collection",
132
- getPlaceholders: (esError, matches) => [matches[2], matches[3]],
133
- },
134
- {
135
- // [mapper_parsing_exception] Expected map for property [fields] on field [foo] but got a class java.lang.String
136
- regex: /^\[mapper_parsing_exception] Expected map for property \[(.*?)] on field \[(.*?)] but got a class java\.lang\.String$/,
137
- subcode: "wrong_mapping_property",
138
- getPlaceholders: (esError, matches) => [`${matches[2]}.${matches[1]}`],
139
- },
140
- {
141
- regex: /^\[version_conflict_engine_exception] \[data]\[(.*?)]: version conflict.*$/,
142
- subcode: "too_many_changes",
143
- getPlaceholders: (esError, matches) => [matches[1]],
144
- },
145
- {
146
- //[liia]: version conflict, document already exists (current version [2])
147
- regex: /^\[(.*)\]: version conflict, document already exists.*/,
148
- subcode: "document_already_exists",
149
- getPlaceholders: () => [],
150
- },
151
- {
152
- // Unknown key for a START_OBJECT in [term].
153
- regex: /^Unknown key for a START_OBJECT in \[(.*)\].*/,
154
- subcode: "invalid_search_query",
155
- getPlaceholders: (esError, matches) => [matches[1]],
156
- },
157
- {
158
- // [_doc] mapping set to strict, dynamic introduction of [lehuong] within [_doc] is not allowed
159
- regex: /^\[(.+)\] mapping set to strict, dynamic introduction of \[(.+)\] within \[.+\] is not allowed/,
160
- subcode: "strict_mapping_rejection",
161
- getPlaceholders: (esError, matches) => {
162
- // "/%26index.collection/_doc"
163
- const esPath = (0, get_1.default)(esError, "meta.meta.request.params.path", "");
164
- // keep only "index"
165
- const index = esPath.split(".")[0]?.split("%26")[1];
166
- // keep only "collection"
167
- const collection = esPath.substr(esPath.indexOf(".") + 1).split("/")[0];
168
- return [matches[2], index, collection];
169
- },
170
- },
171
- {
172
- // [and] query malformed, no start_object after query name
173
- regex: /^\[(.*)\] query malformed, no start_object after query name/,
174
- subcode: "unknown_query_keyword",
175
- getPlaceholders: (esError, matches) => [matches[1]],
176
- },
177
- {
178
- // no [query] registered for [equals]
179
- regex: /^no \[query\] registered for \[(.*)\]/,
180
- subcode: "unknown_query_keyword",
181
- getPlaceholders: (esError, matches) => [matches[1]],
182
- },
183
- ];
184
- class ESWrapper {
185
- constructor(client) {
186
- this.client = client;
187
- }
188
- /**
189
- * Transforms raw ES errors into a normalized Kuzzle version
190
- *
191
- * @param error
192
- */
193
- formatESError(error) {
194
- if (error instanceof errors_1.KuzzleError) {
195
- return error;
196
- }
197
- // `catch` answers `unknown`, and a rejected client promise can in principle
198
- // carry anything. Everything below reads an Error's shape, so that is what
199
- // it gets — without asserting that whatever arrived already was one.
200
- // `inspect`, not `String`: a thrown object stringifies to "[object
201
- // Object]", which is the one thing the message must not say.
202
- const esError = error instanceof Error ? error : new Error((0, node_util_1.inspect)(error));
203
- global.kuzzle.emit("services:storage:error", {
204
- message: `Elasticsearch Client error: ${esError.message}`,
205
- // /!\ not all ES error classes have a "meta" property
206
- meta: esError.meta || null,
207
- stack: esError.stack,
208
- });
209
- if (error instanceof sdk_es8_1.errors.NoLivingConnectionsError) {
210
- throw kerror.get("not_connected");
211
- }
212
- const message = (0, get_1.default)(esError, "meta.body.error.reason", esError.message);
213
- // Try to match a known elasticsearch error
214
- for (const betterError of errorMessagesMapping) {
215
- const matches = message.match(betterError.regex);
216
- if (matches) {
217
- return kerror.get(betterError.subcode, ...betterError.getPlaceholders(esError, matches));
218
- }
219
- }
220
- // Try to match using error codes
221
- // `meta` is what tells a cluster response from a client-side failure, so
222
- // the three handlers below are declared to require it rather than
223
- // re-checking it four times each. The error itself is handed over, never a
224
- // copy: the client's `ResponseError` exposes `body` as a prototype getter,
225
- // which a spread does not carry — and without it every missing document
226
- // answered `unexpected_not_found` instead of `not_found`.
227
- if (isResponseError(esError)) {
228
- switch (esError.meta.statusCode) {
229
- case 400:
230
- return this._handleBadRequestError(esError, message);
231
- case 404:
232
- return this._handleNotFoundError(esError, message);
233
- case 409:
234
- return this._handleConflictError(esError, message);
235
- default:
236
- break;
237
- }
238
- }
239
- return this._handleUnknownError(esError, message);
240
- }
241
- reject(error) {
242
- return bluebird_1.default.reject(this.formatESError(error));
243
- }
244
- _handleConflictError(error, message) {
245
- debug('unhandled "Conflict" elasticsearch error: %a', error);
246
- return kerror.get("unexpected_error", message);
247
- }
248
- _handleNotFoundError(error, message) {
249
- let errorMessage = message;
250
- const indice = (0, get_1.default)(error, "body._index");
251
- if (!indice) {
252
- return kerror.get("unexpected_not_found", errorMessage);
253
- }
254
- // _index= "&nyc-open-data.yellow-taxi"
255
- const index = indice.split(".")[0]?.slice(1);
256
- const collection = indice.split(".")[1];
257
- // 404 on a GET document
258
- if (error.body?.found === false) {
259
- return kerror.get("not_found", error.body._id, index, collection);
260
- }
261
- // 404 on DELETE document (ES error payloads are so cool!)
262
- if (error.meta.body._id) {
263
- return kerror.get("not_found", error.meta.body._id, index, collection);
264
- }
265
- if (error.meta.body?.error) {
266
- errorMessage = error.meta.body.error
267
- ? `${error.meta.body.error.reason}: ${error.meta.body.error["resource.id"]}`
268
- : `${error.message}: ${error.body?._id}`;
269
- }
270
- debug('unhandled "NotFound" elasticsearch error: %a', error);
271
- return kerror.get("unexpected_not_found", errorMessage);
272
- }
273
- _handleBadRequestError(error, message) {
274
- let errorMessage = message;
275
- if (error.meta.body?.error) {
276
- errorMessage = error.meta.body.error.root_cause
277
- ? error.meta.body.error.root_cause[0].reason
278
- : error.meta.body.error.reason;
279
- // empty query throws exception with ES 7
280
- if (error.meta.body.error.type === "parsing_exception" &&
281
- (0, get_1.default)(error, "meta.body.error.caused_by.type") ===
282
- "illegal_argument_exception") {
283
- errorMessage = error.meta.body.error.caused_by.reason;
284
- }
285
- }
286
- debug('unhandled "BadRequest" elasticsearch error: %a', (0, get_1.default)(error, "meta.body.error.reason", error.message));
287
- return kerror.get("unexpected_bad_request", errorMessage);
288
- }
289
- _handleUnknownError(error, message) {
290
- debug("unhandled elasticsearch error (unhandled type: %s): %o", (0, get_1.default)(error, "meta.statusCode", "<no status code>"), error);
291
- return kerror.get("unexpected_error", isUsableMessage(message) ? message : describeUnreadableError(error));
292
- }
293
- }
294
- module.exports = ESWrapper;
295
- //# sourceMappingURL=esWrapper.js.map
@@ -1,16 +0,0 @@
1
- import { Client as ClientES7 } from "sdk-es7";
2
- import { Client as ClientES8 } from "sdk-es8";
3
- import { ES7 } from "./7/elasticsearch";
4
- import { ES8 } from "./8/elasticsearch";
5
- import Service from "../service";
6
- import { storeScopeEnum } from "../../core/storage/storeScopeEnum";
7
- import type { JSONObject } from "../../types/JSONObject";
8
- import type { StorageEngineElasticsearch } from "../../types/config/storageEngine/StorageEngineElasticsearchConfiguration";
9
- export declare class Elasticsearch extends Service<StorageEngineElasticsearch> {
10
- client: ES7 | ES8;
11
- private readonly logger;
12
- constructor(config: StorageEngineElasticsearch, scope?: storeScopeEnum);
13
- static buildClient(config: JSONObject, version?: "7" | "8"): ClientES7 | ClientES8;
14
- _initSequence(): Promise<void>;
15
- init(): Promise<void>;
16
- }
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Elasticsearch = void 0;
7
- const sdk_es7_1 = require("sdk-es7");
8
- const sdk_es8_1 = require("sdk-es8");
9
- const elasticsearch_1 = require("./7/elasticsearch");
10
- const elasticsearch_2 = require("./8/elasticsearch");
11
- const service_1 = __importDefault(require("../service"));
12
- const storeScopeEnum_1 = require("../../core/storage/storeScopeEnum");
13
- class Elasticsearch extends service_1.default {
14
- constructor(config, scope = storeScopeEnum_1.storeScopeEnum.PUBLIC) {
15
- super("elasticsearch", config);
16
- this.logger = global.kuzzle.log.child("service:storage:elasticsearch");
17
- if (config.majorVersion === "7") {
18
- this.client = new elasticsearch_1.ES7(config, scope);
19
- }
20
- else if (config.majorVersion === "8") {
21
- this.client = new elasticsearch_2.ES8(config, scope);
22
- }
23
- else {
24
- throw new Error("Invalid Elasticsearch version.");
25
- }
26
- }
27
- static buildClient(config, version) {
28
- if (!version) {
29
- version = "7";
30
- }
31
- switch (version) {
32
- case "7":
33
- return new sdk_es7_1.Client(config);
34
- case "8":
35
- return new sdk_es8_1.Client(config);
36
- default:
37
- throw new Error("Invalid Elasticsearch version.");
38
- }
39
- }
40
- async _initSequence() {
41
- await this.client._initSequence();
42
- }
43
- async init() {
44
- await super.init();
45
- }
46
- }
47
- exports.Elasticsearch = Elasticsearch;
48
- //# sourceMappingURL=Elasticsearch.js.map