kuzzle 2.30.0 → 2.31.0-elasticsearch-8.1

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.
@@ -1,3 +1,4 @@
1
+ import Bluebird from "bluebird";
1
2
  import { KuzzleRequest } from "../request";
2
3
  import { NativeController } from "./baseController";
3
4
  export declare class AuthController extends NativeController {
@@ -78,7 +79,7 @@ export declare class AuthController extends NativeController {
78
79
  * @param {KuzzleRequest} request
79
80
  * @returns {Promise<Object>}
80
81
  */
81
- getCurrentUser(request: any): any;
82
+ getCurrentUser(request: any): Bluebird<any>;
82
83
  /**
83
84
  * Returns the rights of the user identified by the given jwt token
84
85
  *
@@ -115,7 +116,7 @@ export declare class AuthController extends NativeController {
115
116
  *
116
117
  * @returns {Promise.<string[]>}
117
118
  */
118
- getStrategies(): any;
119
+ getStrategies(): Bluebird<any>;
119
120
  /**
120
121
  * @param {KuzzleRequest} request
121
122
  * @returns {Promise.<Object>}
@@ -275,6 +275,7 @@ const defaultConfig = {
275
275
  bootstrapLockTimeout: 60000,
276
276
  },
277
277
  storageEngine: {
278
+ majorVersion: "7",
278
279
  aliases: ["storageEngine"],
279
280
  backend: "elasticsearch",
280
281
  client: {
@@ -1,19 +1,17 @@
1
- import { Client } from "@elastic/elasticsearch";
2
- import { ApplicationManager, Backend } from "./index";
1
+ import { ApplicationManager } from "./index";
3
2
  export declare class BackendStorage extends ApplicationManager {
4
3
  private _client;
5
4
  private _Client;
6
- constructor(application: Backend);
7
5
  /**
8
6
  * Storage client constructor.
9
7
  * (Currently Elasticsearch)
10
8
  *
11
9
  * @param clientConfig Overload configuration for the underlaying storage client
12
10
  */
13
- get StorageClient(): new (clientConfig?: any) => Client;
11
+ get StorageClient(): new (clientConfig?: any) => any;
14
12
  /**
15
13
  * Access to the underlaying storage engine client.
16
14
  * (Currently Elasticsearch)
17
15
  */
18
- get storageClient(): Client;
16
+ get storageClient(): any;
19
17
  }
@@ -19,16 +19,13 @@
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
- };
25
22
  Object.defineProperty(exports, "__esModule", { value: true });
26
23
  exports.BackendStorage = void 0;
27
- const elasticsearch_1 = __importDefault(require("../../service/storage/elasticsearch"));
24
+ const Elasticsearch_1 = require("../../service/storage/Elasticsearch");
28
25
  const index_1 = require("./index");
29
26
  class BackendStorage extends index_1.ApplicationManager {
30
- constructor(application) {
31
- super(application);
27
+ constructor() {
28
+ super(...arguments);
32
29
  this._client = null;
33
30
  this._Client = null;
34
31
  }
@@ -39,13 +36,13 @@ class BackendStorage extends index_1.ApplicationManager {
39
36
  * @param clientConfig Overload configuration for the underlaying storage client
40
37
  */
41
38
  get StorageClient() {
39
+ const kuzzle = this._kuzzle;
42
40
  if (!this._Client) {
43
- const kuzzle = this._kuzzle;
44
41
  this._Client = function ESClient(clientConfig = {}) {
45
- return elasticsearch_1.default.buildClient({
42
+ return Elasticsearch_1.Elasticsearch.buildClient({
46
43
  ...kuzzle.config.services.storageEngine.client,
47
44
  ...clientConfig,
48
- });
45
+ }, kuzzle.config.services.storageEngine.majorVersion);
49
46
  };
50
47
  }
51
48
  return this._Client;
@@ -55,8 +52,9 @@ class BackendStorage extends index_1.ApplicationManager {
55
52
  * (Currently Elasticsearch)
56
53
  */
57
54
  get storageClient() {
55
+ const kuzzle = this._kuzzle;
58
56
  if (!this._client) {
59
- this._client = elasticsearch_1.default.buildClient(this._kuzzle.config.services.storageEngine.client);
57
+ this._client = Elasticsearch_1.Elasticsearch.buildClient(kuzzle.config.services.storageEngine.client, kuzzle.config.services.storageEngine.majorVersion);
60
58
  }
61
59
  return this._client;
62
60
  }
@@ -1,6 +1,5 @@
1
- import { Client } from "@elastic/elasticsearch";
2
- import { JSONObject } from "kuzzle-sdk";
3
1
  import { Koncorde } from "../shared/KoncordeWrapper";
2
+ import { JSONObject } from "kuzzle-sdk";
4
3
  import { KuzzleRequest, RequestContext, RequestInput } from "../../../index";
5
4
  import { Mutex } from "../../util/mutex";
6
5
  import { BackendCluster } from "../backend";
@@ -122,7 +121,7 @@ export declare class PluginContext {
122
121
  /**
123
122
  * Constructor for Elasticsearch SDK Client
124
123
  */
125
- ESClient: typeof Client;
124
+ ESClient: new () => any;
126
125
  };
127
126
  /**
128
127
  * @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 = __importDefault(require("../../service/storage/elasticsearch"));
55
+ const Elasticsearch_1 = 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,9 +111,8 @@ class PluginContext {
111
111
  update: (...args) => pluginRepository.update(...args),
112
112
  };
113
113
  }
114
- // eslint-disable-next-line no-inner-declarations
115
114
  function PluginContextESClient() {
116
- return elasticsearch_1.default.buildClient(global.kuzzle.config.services.storageEngine.client);
115
+ return Elasticsearch_1.Elasticsearch.buildClient(global.kuzzle.config.services.storageEngine.client);
117
116
  }
118
117
  this.constructors = {
119
118
  BaseValidationType: require("../validation/baseType"),
@@ -252,7 +251,10 @@ function instantiateRequest(request, data, options = {}) {
252
251
  target.input.jwt = _request.input.jwt;
253
252
  }
254
253
  if (_data) {
255
- target.input.volatile = Object.assign({}, _request.input.volatile, _data.volatile);
254
+ target.input.volatile = {
255
+ ..._request.input.volatile,
256
+ ..._data.volatile,
257
+ };
256
258
  }
257
259
  else {
258
260
  target.input.volatile = _request.input.volatile;
@@ -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,16 +38,17 @@ class ClientAdapter {
38
38
  * @param {storeScopeEnum} scope
39
39
  */
40
40
  constructor(scope) {
41
- this.client = new Elasticsearch(
41
+ this.es = new Elasticsearch(
42
42
  global.kuzzle.config.services.storageEngine,
43
43
  scope,
44
44
  );
45
+ this.client = this.es.client;
45
46
  this.scope = scope;
46
47
  this.cache = new IndexCache();
47
48
  }
48
49
 
49
50
  async init() {
50
- await this.client.init();
51
+ await this.es.init();
51
52
  await this.populateCache();
52
53
 
53
54
  this.registerCollectionEvents();
@@ -202,6 +203,7 @@ class ClientAdapter {
202
203
  * @return {Promise}
203
204
  * @throws
204
205
  */
206
+
205
207
  global.kuzzle.onAsk(
206
208
  `core:storage:${this.scope}:collection:create`,
207
209
  (index, collection, opts, creationOptions) =>
@@ -454,7 +456,7 @@ class ClientAdapter {
454
456
  * @param {string} collection
455
457
  * @param {Object} query
456
458
  * @param {Object} [opts] -- see Elasticsearch "deleteByQuery" options
457
- * @returns {Promise.<{ documents, total, deleted, failures: [ _shardId, reason ] }>}
459
+ * @returns {Promise.<{ documents, total, deleted, failures: [ id, reason ] }>}
458
460
  */
459
461
  global.kuzzle.onAsk(
460
462
  `core:storage:${this.scope}:document:deleteByQuery`,
@@ -21,8 +21,6 @@
21
21
 
22
22
  "use strict";
23
23
 
24
- const Bluebird = require("bluebird");
25
-
26
24
  const kerror = require("../../kerror").wrap("services", "storage");
27
25
  const ClientAdapter = require("./clientAdapter");
28
26
  const { storeScopeEnum } = require("./storeScopeEnum");
@@ -42,11 +40,12 @@ class StorageEngine {
42
40
  * @returns {Promise}
43
41
  */
44
42
  async init() {
45
- await Bluebird.all([this.public.init(), this.private.init()]);
43
+ await Promise.all([this.public.init(), this.private.init()]);
46
44
 
47
- const privateIndexes = await this.private.cache.listIndexes();
45
+ const privateIndexes = this.private.cache.listIndexes();
46
+ const publicIndexes = this.public.cache.listIndexes();
48
47
 
49
- for (const publicIndex of await this.public.cache.listIndexes()) {
48
+ for (const publicIndex of publicIndexes) {
50
49
  if (privateIndexes.includes(publicIndex)) {
51
50
  throw kerror.get("index_already_exists", "public", publicIndex);
52
51
  }
@@ -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 || !installations.length) {
243
+ if (!installations?.length) {
244
244
  return;
245
245
  }
246
246
  const mutex = new mutex_1.Mutex("backend:installations");
@@ -1,19 +1,18 @@
1
1
  import _ from "lodash";
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";
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";
7
5
  import ESWrapper from "./esWrapper";
8
- import QueryTranslator from "./queryTranslator";
6
+ import QueryTranslator from "../commons/queryTranslator";
7
+ import { storeScopeEnum } from "../../../core/storage/storeScopeEnum";
9
8
  /**
10
9
  * @param {Kuzzle} kuzzle kuzzle instance
11
10
  * @param {Object} config Service configuration
12
11
  * @param {storeScopeEnum} scope
13
12
  * @constructor
14
13
  */
15
- export default class ElasticSearch extends Service {
16
- _client: StorageClient;
14
+ export declare class ES7 {
15
+ _client: Client;
17
16
  _scope: storeScopeEnum;
18
17
  _indexPrefix: string;
19
18
  _esWrapper: ESWrapper;
@@ -25,12 +24,6 @@ export default class ElasticSearch extends Service {
25
24
  maxScrollDuration: number;
26
25
  scrollTTL: number;
27
26
  _config: any;
28
- /**
29
- * Returns a new elasticsearch client instance
30
- *
31
- * @returns {Object}
32
- */
33
- static buildClient(config: any): StorageClient;
34
27
  constructor(config: any, scope?: storeScopeEnum);
35
28
  get scope(): storeScopeEnum;
36
29
  /**
@@ -77,7 +70,15 @@ export default class ElasticSearch extends Service {
77
70
  scrollTTL?: string;
78
71
  }): Promise<{
79
72
  aggregations: any;
80
- hits: 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
+ }[];
81
82
  remaining: any;
82
83
  scrollId: any;
83
84
  suggest: any;
@@ -104,7 +105,15 @@ export default class ElasticSearch extends Service {
104
105
  scroll?: string;
105
106
  }): Promise<{
106
107
  aggregations: any;
107
- hits: 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
+ }[];
108
117
  remaining: any;
109
118
  scrollId: any;
110
119
  suggest: any;
@@ -119,7 +128,15 @@ export default class ElasticSearch extends Service {
119
128
  _mapTargetsToAlias(targets: any): {};
120
129
  _formatSearchResult(body: any, searchInfo?: any): Promise<{
121
130
  aggregations: any;
122
- hits: 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
+ }[];
123
140
  remaining: any;
124
141
  scrollId: any;
125
142
  suggest: any;
@@ -187,7 +204,7 @@ export default class ElasticSearch extends Service {
187
204
  _version: any;
188
205
  }>;
189
206
  /**
190
- * Creates a new document to ElasticSearch, or replace it if it already exist
207
+ * Creates a new document to Elasticsearch, or replace it if it already exist
191
208
  *
192
209
  * @param {String} index - Index name
193
210
  * @param {String} collection - Collection name
@@ -253,7 +270,7 @@ export default class ElasticSearch extends Service {
253
270
  created: boolean;
254
271
  }>;
255
272
  /**
256
- * Replaces a document to ElasticSearch
273
+ * Replaces a document to Elasticsearch
257
274
  *
258
275
  * @param {String} index - Index name
259
276
  * @param {String} collection - Collection name
@@ -559,7 +576,7 @@ export default class ElasticSearch extends Service {
559
576
  *
560
577
  * @returns {Promise.<String[]>}
561
578
  */
562
- deleteIndexes(indexes?: string[]): Promise<any>;
579
+ deleteIndexes(indexes?: string[]): Promise<any[]>;
563
580
  /**
564
581
  * Deletes an index
565
582
  *
@@ -830,7 +847,7 @@ export default class ElasticSearch extends Service {
830
847
  * @returns {String} Alias name (eg: '@&nepali.liia')
831
848
  * @throws If there is not exactly one alias associated that is prefixed with @
832
849
  */
833
- _getAliasFromIndice(indice: any): Promise<string[]>;
850
+ _getAliasFromIndice(indice: string): Promise<string[]>;
834
851
  /**
835
852
  * Check for each indice whether it has an alias or not.
836
853
  * When the latter is missing, create one based on the indice name.
@@ -870,7 +887,7 @@ export default class ElasticSearch extends Service {
870
887
  *
871
888
  * @returns {Object.<String, String[]>} Indexes as key and an array of their collections as value
872
889
  */
873
- _extractSchema(aliases: any, { includeHidden }?: {
890
+ _extractSchema(aliases: string[], { includeHidden }?: {
874
891
  includeHidden?: boolean;
875
892
  }): {};
876
893
  /**
@@ -953,4 +970,5 @@ export default class ElasticSearch extends Service {
953
970
  _checkDynamicProperty(mappings: any): void;
954
971
  _setLastActionToKuzzleMeta(esRequest: JSONObject, alias: string, kuzzleMeta: JSONObject): void;
955
972
  _setLastActionToKuzzleMetaUpdate(item: JSONObject, kuzzleMeta: JSONObject): void;
973
+ _getRandomNumber(number: number): number;
956
974
  }
@@ -46,24 +46,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
46
46
  return (mod && mod.__esModule) ? mod : { "default": mod };
47
47
  };
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
+ exports.ES7 = void 0;
49
50
  const lodash_1 = __importDefault(require("lodash"));
50
- const elasticsearch_1 = require("@elastic/elasticsearch");
51
+ const sdk_es7_1 = require("sdk-es7");
51
52
  const assert_1 = __importDefault(require("assert"));
52
53
  const bluebird_1 = __importDefault(require("bluebird"));
53
54
  const ms_1 = __importDefault(require("ms"));
54
55
  const semver_1 = __importDefault(require("semver"));
55
- const debug_1 = __importDefault(require("../../util/debug"));
56
- const storeScopeEnum_1 = require("../../core/storage/storeScopeEnum");
57
- const kerror = __importStar(require("../../kerror"));
58
- const didYouMean_1 = __importDefault(require("../../util/didYouMean"));
59
- const extractFields_1 = __importDefault(require("../../util/extractFields"));
60
- const mutex_1 = require("../../util/mutex");
61
- const name_generator_1 = require("../../util/name-generator");
62
- const requestAssertions_1 = require("../../util/requestAssertions");
63
- const safeObject_1 = require("../../util/safeObject");
64
- const service_1 = __importDefault(require("../service"));
56
+ const debug_1 = __importDefault(require("../../../util/debug"));
65
57
  const esWrapper_1 = __importDefault(require("./esWrapper"));
66
- const queryTranslator_1 = __importDefault(require("./queryTranslator"));
58
+ const queryTranslator_1 = __importDefault(require("../commons/queryTranslator"));
59
+ const didYouMean_1 = __importDefault(require("../../../util/didYouMean"));
60
+ const kerror = __importStar(require("../../../kerror"));
61
+ const requestAssertions_1 = require("../../../util/requestAssertions");
62
+ const safeObject_1 = require("../../../util/safeObject");
63
+ const extractFields_1 = __importDefault(require("../../../util/extractFields"));
64
+ const mutex_1 = require("../../../util/mutex");
65
+ const name_generator_1 = require("../../../util/name-generator");
66
+ const storeScopeEnum_1 = require("../../../core/storage/storeScopeEnum");
67
67
  (0, debug_1.default)("kuzzle:services:elasticsearch");
68
68
  const SCROLL_CACHE_PREFIX = "_docscroll_";
69
69
  const ROOT_MAPPING_PROPERTIES = [
@@ -97,28 +97,9 @@ let esState = esStateEnum.NONE;
97
97
  * @param {storeScopeEnum} scope
98
98
  * @constructor
99
99
  */
100
- class ElasticSearch extends service_1.default {
101
- /**
102
- * Returns a new elasticsearch client instance
103
- *
104
- * @returns {Object}
105
- */
106
- static buildClient(config) {
107
- // Passed to Elasticsearch's client to make it use
108
- // Bluebird instead of ES6 promises
109
- const defer = function defer() {
110
- let resolve;
111
- let reject;
112
- const promise = new bluebird_1.default((res, rej) => {
113
- resolve = res;
114
- reject = rej;
115
- });
116
- return { promise, reject, resolve };
117
- };
118
- return new elasticsearch_1.Client({ defer, ...config });
119
- }
100
+ class ES7 {
120
101
  constructor(config, scope = storeScopeEnum_1.storeScopeEnum.PUBLIC) {
121
- super("elasticsearch", config);
102
+ this._config = config;
122
103
  this._scope = scope;
123
104
  this._indexPrefix =
124
105
  scope === storeScopeEnum_1.storeScopeEnum.PRIVATE ? PRIVATE_PREFIX : PUBLIC_PREFIX;
@@ -175,7 +156,7 @@ class ElasticSearch extends service_1.default {
175
156
  'See the "services.storageEngine.commonMapping.dynamic" option in the kuzzlerc configuration file to change this value.',
176
157
  ].join("\n"));
177
158
  }
178
- this._client = ElasticSearch.buildClient(this._config.client);
159
+ this._client = new sdk_es7_1.Client(this._config.client);
179
160
  await this.waitForElasticsearch();
180
161
  this._esWrapper = new esWrapper_1.default(this._client);
181
162
  const { body: { version }, } = await this._client.info();
@@ -619,7 +600,7 @@ class ElasticSearch extends service_1.default {
619
600
  }
620
601
  }
621
602
  /**
622
- * Creates a new document to ElasticSearch, or replace it if it already exist
603
+ * Creates a new document to Elasticsearch, or replace it if it already exist
623
604
  *
624
605
  * @param {String} index - Index name
625
606
  * @param {String} collection - Collection name
@@ -757,7 +738,7 @@ class ElasticSearch extends service_1.default {
757
738
  }
758
739
  }
759
740
  /**
760
- * Replaces a document to ElasticSearch
741
+ * Replaces a document to Elasticsearch
761
742
  *
762
743
  * @param {String} index - Index name
763
744
  * @param {String} collection - Collection name
@@ -2468,7 +2449,7 @@ class ElasticSearch extends service_1.default {
2468
2449
  let notAvailable;
2469
2450
  let suffix;
2470
2451
  do {
2471
- suffix = `.${(0, name_generator_1.randomNumber)(100000)}`;
2452
+ suffix = `.${this._getRandomNumber(100000)}`;
2472
2453
  const overflow = Buffer.from(indice + suffix).length - 255;
2473
2454
  if (overflow > 0) {
2474
2455
  const indiceBuffer = Buffer.from(indice);
@@ -2574,7 +2555,7 @@ class ElasticSearch extends service_1.default {
2574
2555
  const schema = {};
2575
2556
  for (const alias of aliases) {
2576
2557
  const [indexName, collectionName] = alias
2577
- .substr(INDEX_PREFIX_POSITION_IN_ALIAS + 1, alias.length)
2558
+ .slice(INDEX_PREFIX_POSITION_IN_ALIAS + 1)
2578
2559
  .split(NAME_SEPARATOR);
2579
2560
  if (alias[INDEX_PREFIX_POSITION_IN_ALIAS] === this._indexPrefix &&
2580
2561
  (collectionName !== HIDDEN_COLLECTION || includeHidden)) {
@@ -2856,8 +2837,11 @@ class ElasticSearch extends service_1.default {
2856
2837
  }
2857
2838
  }
2858
2839
  }
2840
+ _getRandomNumber(number) {
2841
+ return (0, name_generator_1.randomNumber)(number);
2842
+ }
2859
2843
  }
2860
- exports.default = ElasticSearch;
2844
+ exports.ES7 = ES7;
2861
2845
  /**
2862
2846
  * Finds paths and values of mappings dynamic properties
2863
2847
  *
@@ -2942,7 +2926,4 @@ function _isObjectNameValid(name) {
2942
2926
  }
2943
2927
  return valid;
2944
2928
  }
2945
- // TODO: Remove this function when we move to Jest
2946
- // This is kept because we use an old ReRequire that use require() instead of import
2947
- module.exports = ElasticSearch;
2948
2929
  //# sourceMappingURL=elasticsearch.js.map
@@ -25,11 +25,13 @@
25
25
 
26
26
  const Bluebird = require("bluebird");
27
27
  const _ = require("lodash");
28
- const es = require("@elastic/elasticsearch");
28
+ const es = require("sdk-es7");
29
29
 
30
- const { KuzzleError } = require("../../kerror/errors");
31
- const debug = require("../../util/debug")("kuzzle:services:storage:ESCommon");
32
- const kerror = require("../../kerror").wrap("services", "storage");
30
+ const { KuzzleError } = require("../../../kerror/errors");
31
+ const debug = require("../../../util/debug")(
32
+ "kuzzle:services:storage:ESCommon",
33
+ );
34
+ const kerror = require("../../../kerror").wrap("services", "storage");
33
35
 
34
36
  const errorMessagesMapping = [
35
37
  {