kuzzle 2.31.0-elasticsearch-8.2 → 2.31.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.
Files changed (32) hide show
  1. package/lib/api/controllers/authController.d.ts +2 -3
  2. package/lib/api/controllers/memoryStorageController.js +11 -3
  3. package/lib/api/funnel.js +3 -0
  4. package/lib/api/request/requestInput.d.ts +2 -0
  5. package/lib/api/request/requestInput.js +9 -0
  6. package/lib/config/default.config.js +0 -1
  7. package/lib/core/backend/backendStorage.d.ts +5 -3
  8. package/lib/core/backend/backendStorage.js +10 -8
  9. package/lib/core/plugin/pluginContext.d.ts +3 -2
  10. package/lib/core/plugin/pluginContext.js +4 -6
  11. package/lib/core/security/profileRepository.d.ts +5 -14
  12. package/lib/core/security/profileRepository.js +17 -50
  13. package/lib/core/security/roleRepository.js +1 -1
  14. package/lib/core/shared/ObjectRepository.js +1 -1
  15. package/lib/core/storage/clientAdapter.js +4 -6
  16. package/lib/core/storage/storageEngine.js +5 -4
  17. package/lib/kuzzle/kuzzle.js +1 -1
  18. package/lib/service/storage/{7/elasticsearch.d.ts → elasticsearch.d.ts} +22 -40
  19. package/lib/service/storage/{7/elasticsearch.js → elasticsearch.js} +42 -23
  20. package/lib/service/storage/{7/esWrapper.js → esWrapper.js} +4 -6
  21. package/lib/service/storage/{commons/queryTranslator.js → queryTranslator.js} +1 -1
  22. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +2 -6
  23. package/lib/types/storage/{7/Elasticsearch.d.ts → Elasticsearch.d.ts} +1 -1
  24. package/package.json +5 -7
  25. package/lib/service/storage/8/elasticsearch.d.ts +0 -972
  26. package/lib/service/storage/8/elasticsearch.js +0 -2925
  27. package/lib/service/storage/8/esWrapper.js +0 -303
  28. package/lib/service/storage/Elasticsearch.d.ts +0 -9
  29. package/lib/service/storage/Elasticsearch.js +0 -48
  30. package/lib/types/storage/8/Elasticsearch.d.ts +0 -59
  31. package/lib/types/storage/8/Elasticsearch.js +0 -3
  32. /package/lib/types/storage/{7/Elasticsearch.js → Elasticsearch.js} +0 -0
@@ -1,4 +1,3 @@
1
- import Bluebird from "bluebird";
2
1
  import { KuzzleRequest } from "../request";
3
2
  import { NativeController } from "./baseController";
4
3
  export declare class AuthController extends NativeController {
@@ -79,7 +78,7 @@ export declare class AuthController extends NativeController {
79
78
  * @param {KuzzleRequest} request
80
79
  * @returns {Promise<Object>}
81
80
  */
82
- getCurrentUser(request: any): Bluebird<any>;
81
+ getCurrentUser(request: any): any;
83
82
  /**
84
83
  * Returns the rights of the user identified by the given jwt token
85
84
  *
@@ -116,7 +115,7 @@ export declare class AuthController extends NativeController {
116
115
  *
117
116
  * @returns {Promise.<string[]>}
118
117
  */
119
- getStrategies(): Bluebird<any>;
118
+ getStrategies(): any;
120
119
  /**
121
120
  * @param {KuzzleRequest} request
122
121
  * @returns {Promise.<Object>}
@@ -267,11 +267,15 @@ function initMapping() {
267
267
  kassert.assertBodyAttributeType(request, "entries", "array");
268
268
 
269
269
  val.forEach((v) => {
270
- if (typeof v !== "object" || !v.field || !v.value) {
270
+ if (
271
+ typeof v !== "object" ||
272
+ !v.field ||
273
+ (!v.value && v.value !== 0)
274
+ ) {
271
275
  throw kerror.get(
272
276
  "invalid_argument",
273
277
  "entries",
274
- "<array of object>",
278
+ "<array of objects>",
275
279
  );
276
280
  }
277
281
 
@@ -348,7 +352,11 @@ function initMapping() {
348
352
  kassert.assertBodyHasAttribute(request, "entries");
349
353
  kassert.assertBodyAttributeType(request, "entries", "array");
350
354
  val.forEach((entry) => {
351
- if (typeof entry !== "object" || !entry.key || !entry.value) {
355
+ if (
356
+ typeof entry !== "object" ||
357
+ !entry.key ||
358
+ (!entry.value && entry.value !== 0)
359
+ ) {
352
360
  throw kerror.get(
353
361
  "invalid_argument",
354
362
  "entries",
package/lib/api/funnel.js CHANGED
@@ -753,6 +753,9 @@ class Funnel {
753
753
  */
754
754
  async executePluginRequest(request) {
755
755
  try {
756
+ if (request.input.triggerEvents) {
757
+ return await this.processRequest(request);
758
+ }
756
759
  return await doAction(this.getController(request), request);
757
760
  } catch (e) {
758
761
  this.handleErrorDump(e);
@@ -135,6 +135,8 @@ export declare class RequestInput {
135
135
  */
136
136
  get action(): string | null;
137
137
  set action(str: string);
138
+ get triggerEvents(): boolean | undefined;
139
+ set triggerEvents(bool: boolean);
138
140
  /**
139
141
  * Request body.
140
142
  * In Http it's the request body parsed.
@@ -54,6 +54,7 @@ const _body = "body\u200b";
54
54
  const _headers = "headers\u200b";
55
55
  const _controller = "controller\u200b";
56
56
  const _action = "action\u200b";
57
+ const _triggerEvents = "triggerEvents\u200b";
57
58
  // any property not listed here will be copied into
58
59
  // RequestInput.args
59
60
  const resourceProperties = new Set([
@@ -126,6 +127,7 @@ class RequestInput {
126
127
  this[_body] = null;
127
128
  this[_controller] = null;
128
129
  this[_action] = null;
130
+ this[_triggerEvents] = null;
129
131
  // default value to null for former "resources" to avoid breaking
130
132
  this.args = {};
131
133
  this.resource = new RequestResource(this.args);
@@ -147,6 +149,7 @@ class RequestInput {
147
149
  this.body = data.body;
148
150
  this.controller = data.controller;
149
151
  this.action = data.action;
152
+ this.triggerEvents = data.triggerEvents;
150
153
  }
151
154
  /**
152
155
  * Authentication token.
@@ -223,6 +226,12 @@ class RequestInput {
223
226
  this[_action] = assert.assertString("action", str);
224
227
  }
225
228
  }
229
+ get triggerEvents() {
230
+ return this[_triggerEvents];
231
+ }
232
+ set triggerEvents(bool) {
233
+ this[_triggerEvents] = bool === true ? true : undefined;
234
+ }
226
235
  /**
227
236
  * Request body.
228
237
  * In Http it's the request body parsed.
@@ -275,7 +275,6 @@ const defaultConfig = {
275
275
  bootstrapLockTimeout: 60000,
276
276
  },
277
277
  storageEngine: {
278
- majorVersion: "7",
279
278
  aliases: ["storageEngine"],
280
279
  backend: "elasticsearch",
281
280
  client: {
@@ -1,17 +1,19 @@
1
- import { ApplicationManager } from "./index";
1
+ import { Client } from "@elastic/elasticsearch";
2
+ import { ApplicationManager, Backend } from "./index";
2
3
  export declare class BackendStorage extends ApplicationManager {
3
4
  private _client;
4
5
  private _Client;
6
+ constructor(application: Backend);
5
7
  /**
6
8
  * Storage client constructor.
7
9
  * (Currently Elasticsearch)
8
10
  *
9
11
  * @param clientConfig Overload configuration for the underlaying storage client
10
12
  */
11
- get StorageClient(): new (clientConfig?: any) => any;
13
+ get StorageClient(): new (clientConfig?: any) => Client;
12
14
  /**
13
15
  * Access to the underlaying storage engine client.
14
16
  * (Currently Elasticsearch)
15
17
  */
16
- get storageClient(): any;
18
+ get storageClient(): Client;
17
19
  }
@@ -19,13 +19,16 @@
19
19
  * See the License for the specific language governing permissions and
20
20
  * limitations under the License.
21
21
  */
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
26
  exports.BackendStorage = void 0;
24
- const Elasticsearch_1 = require("../../service/storage/Elasticsearch");
27
+ const elasticsearch_1 = __importDefault(require("../../service/storage/elasticsearch"));
25
28
  const index_1 = require("./index");
26
29
  class BackendStorage extends index_1.ApplicationManager {
27
- constructor() {
28
- super(...arguments);
30
+ constructor(application) {
31
+ super(application);
29
32
  this._client = null;
30
33
  this._Client = null;
31
34
  }
@@ -36,13 +39,13 @@ class BackendStorage extends index_1.ApplicationManager {
36
39
  * @param clientConfig Overload configuration for the underlaying storage client
37
40
  */
38
41
  get StorageClient() {
39
- const kuzzle = this._kuzzle;
40
42
  if (!this._Client) {
43
+ const kuzzle = this._kuzzle;
41
44
  this._Client = function ESClient(clientConfig = {}) {
42
- return Elasticsearch_1.Elasticsearch.buildClient({
45
+ return elasticsearch_1.default.buildClient({
43
46
  ...kuzzle.config.services.storageEngine.client,
44
47
  ...clientConfig,
45
- }, kuzzle.config.services.storageEngine.majorVersion);
48
+ });
46
49
  };
47
50
  }
48
51
  return this._Client;
@@ -52,9 +55,8 @@ class BackendStorage extends index_1.ApplicationManager {
52
55
  * (Currently Elasticsearch)
53
56
  */
54
57
  get storageClient() {
55
- const kuzzle = this._kuzzle;
56
58
  if (!this._client) {
57
- this._client = Elasticsearch_1.Elasticsearch.buildClient(kuzzle.config.services.storageEngine.client, kuzzle.config.services.storageEngine.majorVersion);
59
+ this._client = elasticsearch_1.default.buildClient(this._kuzzle.config.services.storageEngine.client);
58
60
  }
59
61
  return this._client;
60
62
  }
@@ -1,5 +1,6 @@
1
- import { Koncorde } from "../shared/KoncordeWrapper";
1
+ import { Client } from "@elastic/elasticsearch";
2
2
  import { JSONObject } from "kuzzle-sdk";
3
+ import { Koncorde } from "../shared/KoncordeWrapper";
3
4
  import { KuzzleRequest, RequestContext, RequestInput } from "../../../index";
4
5
  import { Mutex } from "../../util/mutex";
5
6
  import { BackendCluster } from "../backend";
@@ -121,7 +122,7 @@ export declare class PluginContext {
121
122
  /**
122
123
  * Constructor for Elasticsearch SDK Client
123
124
  */
124
- ESClient: new () => any;
125
+ ESClient: typeof Client;
125
126
  };
126
127
  /**
127
128
  * @deprecated import directly: `import { BadRequestError, ... } from 'kuzzle'`
@@ -52,7 +52,7 @@ const KoncordeWrapper_1 = require("../shared/KoncordeWrapper");
52
52
  const index_1 = require("../../../index");
53
53
  const kerror = __importStar(require("../../kerror"));
54
54
  const errors_1 = require("../../kerror/errors");
55
- const Elasticsearch_1 = require("../../service/storage/Elasticsearch");
55
+ const elasticsearch_1 = __importDefault(require("../../service/storage/elasticsearch"));
56
56
  const mutex_1 = require("../../util/mutex");
57
57
  const promback_1 = __importDefault(require("../../util/promback"));
58
58
  const safeObject_1 = require("../../util/safeObject");
@@ -111,8 +111,9 @@ class PluginContext {
111
111
  update: (...args) => pluginRepository.update(...args),
112
112
  };
113
113
  }
114
+ // eslint-disable-next-line no-inner-declarations
114
115
  function PluginContextESClient() {
115
- return Elasticsearch_1.Elasticsearch.buildClient(global.kuzzle.config.services.storageEngine.client);
116
+ return elasticsearch_1.default.buildClient(global.kuzzle.config.services.storageEngine.client);
116
117
  }
117
118
  this.constructors = {
118
119
  BaseValidationType: require("../validation/baseType"),
@@ -251,10 +252,7 @@ function instantiateRequest(request, data, options = {}) {
251
252
  target.input.jwt = _request.input.jwt;
252
253
  }
253
254
  if (_data) {
254
- target.input.volatile = {
255
- ..._request.input.volatile,
256
- ..._data.volatile,
257
- };
255
+ target.input.volatile = Object.assign({}, _request.input.volatile, _data.volatile);
258
256
  }
259
257
  else {
260
258
  target.input.volatile = _request.input.volatile;
@@ -29,7 +29,6 @@ type UpdateOptions = {
29
29
  */
30
30
  export declare class ProfileRepository extends ObjectRepository<Profile> {
31
31
  private module;
32
- private profiles;
33
32
  /**
34
33
  * @constructor
35
34
  */
@@ -42,7 +41,9 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
42
41
  * @returns {Promise.<Promise>}
43
42
  * @throws {NotFoundError} If the corresponding profile doesn't exist
44
43
  */
45
- load(id: string): Promise<Profile>;
44
+ load(id: string, options?: {
45
+ key?: string;
46
+ }): Promise<Profile>;
46
47
  /**
47
48
  * Loads a Profile object given its id.
48
49
  * Stores the promise of the profile being loaded in the memcache
@@ -140,16 +141,6 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
140
141
  * @returns {Promise<Profile>}
141
142
  */
142
143
  fromDTO(dto: JSONObject): Promise<Profile>;
143
- /**
144
- * @override
145
- */
146
- truncate(opts: JSONObject): Promise<void>;
147
- /**
148
- * Invalidate the cache entries for the given profile. If none is provided,
149
- * the entire cache is emptied.
150
- * @param {string} [profileId]
151
- */
152
- invalidate(profileId?: string): void;
153
144
  /**
154
145
  * Optimize each policy to get a O(1) index access time
155
146
  * and a O(log(n)) collection search time.
@@ -168,8 +159,8 @@ export declare class ProfileRepository extends ObjectRepository<Profile> {
168
159
  * @param policy
169
160
  */
170
161
  private optimizePolicy;
171
- toDTO(dto: Profile): Promise<JSONObject>;
172
- deleteFromDatabase(id: string, options: JSONObject): Promise<any>;
162
+ toDTO(dto: Profile): JSONObject;
163
+ deleteFromDatabase(id: string, options: JSONObject): any;
173
164
  search(searchBody: JSONObject, options: JSONObject): Promise<{
174
165
  aggregations: any;
175
166
  hits: any[];
@@ -51,7 +51,6 @@ const bluebird_1 = __importDefault(require("bluebird"));
51
51
  const lodash_1 = require("lodash");
52
52
  const kerror = __importStar(require("../../kerror"));
53
53
  const profile_1 = require("../../model/security/profile");
54
- const cacheDbEnum_1 = require("../cache/cacheDbEnum");
55
54
  const ObjectRepository_1 = require("../shared/ObjectRepository");
56
55
  /**
57
56
  * @class ProfileRepository
@@ -62,12 +61,8 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
62
61
  * @constructor
63
62
  */
64
63
  constructor(securityModule) {
65
- super({
66
- cache: cacheDbEnum_1.cacheDbEnum.NONE,
67
- store: global.kuzzle.internalIndex,
68
- });
64
+ super({ store: global.kuzzle.internalIndex });
69
65
  this.module = securityModule;
70
- this.profiles = new Map();
71
66
  this.collection = "profiles";
72
67
  this.ObjectConstructor = profile_1.Profile;
73
68
  }
@@ -111,7 +106,7 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
111
106
  *
112
107
  * @param {String} [id] - profile identifier
113
108
  */
114
- global.kuzzle.onAsk("core:security:profile:invalidate", (id) => this.invalidate(id));
109
+ global.kuzzle.onAsk("core:security:profile:invalidate", (id) => this.deleteFromCache(id));
115
110
  /**
116
111
  * Gets multiple profiles
117
112
  * @param {Array} ids
@@ -156,13 +151,18 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
156
151
  * @returns {Promise.<Promise>}
157
152
  * @throws {NotFoundError} If the corresponding profile doesn't exist
158
153
  */
159
- async load(id) {
160
- if (this.profiles.has(id)) {
161
- return this.profiles.get(id);
154
+ async load(id, options = {}) {
155
+ const profile = await this.loadFromCache(id, options);
156
+ if (profile === null) {
157
+ const profileFromDatabase = await this.loadOneFromDatabase(id);
158
+ if (profileFromDatabase !== null) {
159
+ await this.persistToCache(profileFromDatabase);
160
+ profileFromDatabase.optimizedPolicies = this.optimizePolicies(profileFromDatabase.policies);
161
+ }
162
+ return profileFromDatabase;
162
163
  }
163
- const profile = await super.load(id);
164
164
  profile.optimizedPolicies = this.optimizePolicies(profile.policies);
165
- this.profiles.set(id, profile);
165
+ await this.refreshCacheTTL(profile);
166
166
  return profile;
167
167
  }
168
168
  /**
@@ -185,14 +185,7 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
185
185
  throw kerror.get("api", "assert", "invalid_type", "profileIds", "string[]");
186
186
  }
187
187
  for (const id of profileIds) {
188
- let profile = this.profiles.get(id);
189
- if (!profile) {
190
- profile = this.loadOneFromDatabase(id).then((p) => {
191
- p.optimizedPolicies = this.optimizePolicies(p.policies);
192
- this.profiles.set(id, p);
193
- return p;
194
- });
195
- }
188
+ const profile = this.load(id);
196
189
  profiles.push(profile);
197
190
  }
198
191
  return bluebird_1.default.all(profiles);
@@ -342,7 +335,7 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
342
335
  }
343
336
  }
344
337
  await this.deleteFromDatabase(profile._id, { refresh });
345
- this.profiles.delete(profile._id);
338
+ await this.deleteFromCache(profile._id);
346
339
  }
347
340
  /**
348
341
  * From a Profile object, returns a serialized object ready to be persisted
@@ -384,9 +377,9 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
384
377
  retryOnConflict,
385
378
  });
386
379
  const updatedProfile = await this.loadOneFromDatabase(profile._id);
380
+ await this.persistToCache(updatedProfile);
387
381
  // Recompute optimized policies based on new policies
388
382
  updatedProfile.optimizedPolicies = this.optimizePolicies(updatedProfile.policies);
389
- this.profiles.set(profile._id, updatedProfile);
390
383
  return updatedProfile;
391
384
  }
392
385
  /**
@@ -410,32 +403,6 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
410
403
  }
411
404
  return profile;
412
405
  }
413
- /**
414
- * @override
415
- */
416
- async truncate(opts) {
417
- try {
418
- await super.truncate(opts);
419
- }
420
- finally {
421
- // always clear the RAM cache: even if truncate fails in the middle of it,
422
- // some of the cached profiles might not be valid anymore
423
- this.invalidate();
424
- }
425
- }
426
- /**
427
- * Invalidate the cache entries for the given profile. If none is provided,
428
- * the entire cache is emptied.
429
- * @param {string} [profileId]
430
- */
431
- invalidate(profileId) {
432
- if (!profileId) {
433
- this.profiles.clear();
434
- }
435
- else {
436
- this.profiles.delete(profileId);
437
- }
438
- }
439
406
  /**
440
407
  * Optimize each policy to get a O(1) index access time
441
408
  * and a O(log(n)) collection search time.
@@ -496,10 +463,10 @@ class ProfileRepository extends ObjectRepository_1.ObjectRepository {
496
463
  // Every method described after are for testing purpose only
497
464
  // Otherwise we cannot stub them
498
465
  // ============================================
499
- async toDTO(dto) {
466
+ toDTO(dto) {
500
467
  return super.toDTO(dto);
501
468
  }
502
- async deleteFromDatabase(id, options) {
469
+ deleteFromDatabase(id, options) {
503
470
  return super.deleteFromDatabase(id, options);
504
471
  }
505
472
  async search(searchBody, options) {
@@ -43,7 +43,7 @@ class RoleRepository extends ObjectRepository {
43
43
  */
44
44
  constructor(securityModule) {
45
45
  super({
46
- cache: cacheDbEnum.NONE,
46
+ cache: cacheDbEnum.INTERNAL,
47
47
  store: global.kuzzle.internalIndex,
48
48
  });
49
49
 
@@ -127,7 +127,7 @@ class ObjectRepository {
127
127
  let response;
128
128
  try {
129
129
  response = await global.kuzzle.ask(`core:cache:${this.cacheDb}:get`, key);
130
- if (response === null) {
130
+ if (response === null || response === undefined) {
131
131
  return null;
132
132
  }
133
133
  return await this.fromDTO({ ...JSON.parse(response) });
@@ -21,7 +21,7 @@
21
21
 
22
22
  "use strict";
23
23
 
24
- const { Elasticsearch } = require("../../service/storage/Elasticsearch");
24
+ const Elasticsearch = require("../../service/storage/elasticsearch");
25
25
  const { IndexCache } = require("./indexCache");
26
26
  const { isPlainObject } = require("../../util/safeObject");
27
27
  const kerror = require("../../kerror");
@@ -38,17 +38,16 @@ class ClientAdapter {
38
38
  * @param {storeScopeEnum} scope
39
39
  */
40
40
  constructor(scope) {
41
- this.es = new Elasticsearch(
41
+ this.client = new Elasticsearch(
42
42
  global.kuzzle.config.services.storageEngine,
43
43
  scope,
44
44
  );
45
- this.client = this.es.client;
46
45
  this.scope = scope;
47
46
  this.cache = new IndexCache();
48
47
  }
49
48
 
50
49
  async init() {
51
- await this.es.init();
50
+ await this.client.init();
52
51
  await this.populateCache();
53
52
 
54
53
  this.registerCollectionEvents();
@@ -203,7 +202,6 @@ class ClientAdapter {
203
202
  * @return {Promise}
204
203
  * @throws
205
204
  */
206
-
207
205
  global.kuzzle.onAsk(
208
206
  `core:storage:${this.scope}:collection:create`,
209
207
  (index, collection, opts, creationOptions) =>
@@ -456,7 +454,7 @@ class ClientAdapter {
456
454
  * @param {string} collection
457
455
  * @param {Object} query
458
456
  * @param {Object} [opts] -- see Elasticsearch "deleteByQuery" options
459
- * @returns {Promise.<{ documents, total, deleted, failures: [ id, reason ] }>}
457
+ * @returns {Promise.<{ documents, total, deleted, failures: [ _shardId, reason ] }>}
460
458
  */
461
459
  global.kuzzle.onAsk(
462
460
  `core:storage:${this.scope}:document:deleteByQuery`,
@@ -21,6 +21,8 @@
21
21
 
22
22
  "use strict";
23
23
 
24
+ const Bluebird = require("bluebird");
25
+
24
26
  const kerror = require("../../kerror").wrap("services", "storage");
25
27
  const ClientAdapter = require("./clientAdapter");
26
28
  const { storeScopeEnum } = require("./storeScopeEnum");
@@ -40,12 +42,11 @@ class StorageEngine {
40
42
  * @returns {Promise}
41
43
  */
42
44
  async init() {
43
- await Promise.all([this.public.init(), this.private.init()]);
45
+ await Bluebird.all([this.public.init(), this.private.init()]);
44
46
 
45
- const privateIndexes = this.private.cache.listIndexes();
46
- const publicIndexes = this.public.cache.listIndexes();
47
+ const privateIndexes = await this.private.cache.listIndexes();
47
48
 
48
- for (const publicIndex of publicIndexes) {
49
+ for (const publicIndex of await this.public.cache.listIndexes()) {
49
50
  if (privateIndexes.includes(publicIndex)) {
50
51
  throw kerror.get("index_already_exists", "public", publicIndex);
51
52
  }
@@ -240,7 +240,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
240
240
  * @returns {Promise<void>}
241
241
  */
242
242
  async install(installations) {
243
- if (!installations?.length) {
243
+ if (!installations || !installations.length) {
244
244
  return;
245
245
  }
246
246
  const mutex = new mutex_1.Mutex("backend:installations");
@@ -1,18 +1,19 @@
1
1
  import _ from "lodash";
2
- import { RequestParams, Client } from "sdk-es7";
3
- import { TypeMapping } from "sdk-es7/api/types";
4
- import { JSONObject, KRequestBody, KRequestParams } from "../../../types/storage/7/Elasticsearch";
2
+ import { RequestParams, Client as StorageClient } from "@elastic/elasticsearch";
3
+ import { JSONObject, KRequestBody, KRequestParams } from "../../types/storage/Elasticsearch";
4
+ import { TypeMapping } from "@elastic/elasticsearch/api/types";
5
+ import { storeScopeEnum } from "../../core/storage/storeScopeEnum";
6
+ import Service from "../service";
5
7
  import ESWrapper from "./esWrapper";
6
- import QueryTranslator from "../commons/queryTranslator";
7
- import { storeScopeEnum } from "../../../core/storage/storeScopeEnum";
8
+ import QueryTranslator from "./queryTranslator";
8
9
  /**
9
10
  * @param {Kuzzle} kuzzle kuzzle instance
10
11
  * @param {Object} config Service configuration
11
12
  * @param {storeScopeEnum} scope
12
13
  * @constructor
13
14
  */
14
- export declare class ES7 {
15
- _client: Client;
15
+ export default class ElasticSearch extends Service {
16
+ _client: StorageClient;
16
17
  _scope: storeScopeEnum;
17
18
  _indexPrefix: string;
18
19
  _esWrapper: ESWrapper;
@@ -24,6 +25,12 @@ export declare class ES7 {
24
25
  maxScrollDuration: number;
25
26
  scrollTTL: number;
26
27
  _config: any;
28
+ /**
29
+ * Returns a new elasticsearch client instance
30
+ *
31
+ * @returns {Object}
32
+ */
33
+ static buildClient(config: any): StorageClient;
27
34
  constructor(config: any, scope?: storeScopeEnum);
28
35
  get scope(): storeScopeEnum;
29
36
  /**
@@ -70,15 +77,7 @@ export declare class ES7 {
70
77
  scrollTTL?: string;
71
78
  }): Promise<{
72
79
  aggregations: any;
73
- hits: {
74
- _id: any;
75
- _score: any;
76
- _source: any;
77
- collection: any;
78
- highlight: any;
79
- index: any;
80
- inner_hits: {};
81
- }[];
80
+ hits: any;
82
81
  remaining: any;
83
82
  scrollId: any;
84
83
  suggest: any;
@@ -105,15 +104,7 @@ export declare class ES7 {
105
104
  scroll?: string;
106
105
  }): Promise<{
107
106
  aggregations: any;
108
- hits: {
109
- _id: any;
110
- _score: any;
111
- _source: any;
112
- collection: any;
113
- highlight: any;
114
- index: any;
115
- inner_hits: {};
116
- }[];
107
+ hits: any;
117
108
  remaining: any;
118
109
  scrollId: any;
119
110
  suggest: any;
@@ -128,15 +119,7 @@ export declare class ES7 {
128
119
  _mapTargetsToAlias(targets: any): {};
129
120
  _formatSearchResult(body: any, searchInfo?: any): Promise<{
130
121
  aggregations: any;
131
- hits: {
132
- _id: any;
133
- _score: any;
134
- _source: any;
135
- collection: any;
136
- highlight: any;
137
- index: any;
138
- inner_hits: {};
139
- }[];
122
+ hits: any;
140
123
  remaining: any;
141
124
  scrollId: any;
142
125
  suggest: any;
@@ -204,7 +187,7 @@ export declare class ES7 {
204
187
  _version: any;
205
188
  }>;
206
189
  /**
207
- * Creates a new document to Elasticsearch, or replace it if it already exist
190
+ * Creates a new document to ElasticSearch, or replace it if it already exist
208
191
  *
209
192
  * @param {String} index - Index name
210
193
  * @param {String} collection - Collection name
@@ -270,7 +253,7 @@ export declare class ES7 {
270
253
  created: boolean;
271
254
  }>;
272
255
  /**
273
- * Replaces a document to Elasticsearch
256
+ * Replaces a document to ElasticSearch
274
257
  *
275
258
  * @param {String} index - Index name
276
259
  * @param {String} collection - Collection name
@@ -576,7 +559,7 @@ export declare class ES7 {
576
559
  *
577
560
  * @returns {Promise.<String[]>}
578
561
  */
579
- deleteIndexes(indexes?: string[]): Promise<any[]>;
562
+ deleteIndexes(indexes?: string[]): Promise<any>;
580
563
  /**
581
564
  * Deletes an index
582
565
  *
@@ -847,7 +830,7 @@ export declare class ES7 {
847
830
  * @returns {String} Alias name (eg: '@&nepali.liia')
848
831
  * @throws If there is not exactly one alias associated that is prefixed with @
849
832
  */
850
- _getAliasFromIndice(indice: string): Promise<string[]>;
833
+ _getAliasFromIndice(indice: any): Promise<string[]>;
851
834
  /**
852
835
  * Check for each indice whether it has an alias or not.
853
836
  * When the latter is missing, create one based on the indice name.
@@ -887,7 +870,7 @@ export declare class ES7 {
887
870
  *
888
871
  * @returns {Object.<String, String[]>} Indexes as key and an array of their collections as value
889
872
  */
890
- _extractSchema(aliases: string[], { includeHidden }?: {
873
+ _extractSchema(aliases: any, { includeHidden }?: {
891
874
  includeHidden?: boolean;
892
875
  }): {};
893
876
  /**
@@ -970,5 +953,4 @@ export declare class ES7 {
970
953
  _checkDynamicProperty(mappings: any): void;
971
954
  _setLastActionToKuzzleMeta(esRequest: JSONObject, alias: string, kuzzleMeta: JSONObject): void;
972
955
  _setLastActionToKuzzleMetaUpdate(item: JSONObject, kuzzleMeta: JSONObject): void;
973
- _getRandomNumber(number: number): number;
974
956
  }