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,1054 +0,0 @@
1
- import _ from "lodash";
2
- import type { RequestParams } from "sdk-es7";
3
- import { Client } from "sdk-es7";
4
- import type { ElasticsearchVersionInfo, ShardStatistics, TypeMapping } from "sdk-es7/api/types";
5
- import type { AliasToTargets, CatAliasRecord, InfoResult, JSONObject, KImportError, KImportResult, KMExecuteResult, KRequestBody, KRequestParams } from "../../../types/storage/7/Elasticsearch";
6
- import type { ValidatedTarget } from "../../../types/Target";
7
- import { storeScopeEnum } from "../../../core/storage/storeScopeEnum";
8
- import type { StorageEngineElasticsearch } from "../../../types/config/storageEngine/StorageEngineElasticsearchConfiguration";
9
- import { QueryTranslator } from "../commons/queryTranslator";
10
- import ESWrapper from "./esWrapper";
11
- /**
12
- * @param {Kuzzle} kuzzle kuzzle instance
13
- * @param {Object} config Service configuration
14
- * @param {storeScopeEnum} scope
15
- * @constructor
16
- */
17
- export declare class ES7 {
18
- /**
19
- * Built by `init()`, and read nowhere before it — the `null` the constructor
20
- * used to write was never observed. See TD-62.
21
- */
22
- _client: Client;
23
- _scope: storeScopeEnum;
24
- _indexPrefix: string;
25
- _esWrapper: ESWrapper;
26
- _esVersion: ElasticsearchVersionInfo | null;
27
- _translator: QueryTranslator;
28
- searchBodyKeys: string[];
29
- scriptKeys: string[];
30
- scriptAllowedArgs: string[];
31
- maxScrollDuration: number;
32
- scrollTTL: number;
33
- _config: StorageEngineElasticsearch;
34
- private readonly logger;
35
- constructor(config: StorageEngineElasticsearch, scope?: storeScopeEnum);
36
- get scope(): storeScopeEnum;
37
- /**
38
- * Initializes the elasticsearch client
39
- *
40
- * @override
41
- * @returns {Promise}
42
- */
43
- _initSequence(): Promise<void>;
44
- /**
45
- * Translate Koncorde filters to Elasticsearch query
46
- *
47
- * @param {Object} filters - Set of valid Koncorde filters
48
- * @returns {Object} Equivalent Elasticsearch query
49
- */
50
- translateKoncordeFilters(filters: JSONObject): any;
51
- /**
52
- * Returns some basic information about this service
53
- * @override
54
- *
55
- * @returns {Promise.<Object>} service informations
56
- */
57
- info(): Promise<InfoResult>;
58
- /**
59
- * Returns detailed multi-level storage stats data
60
- *
61
- * @returns {Promise.<Object>}
62
- */
63
- stats(): Promise<{
64
- indexes: {
65
- collections: JSONObject[];
66
- name: string;
67
- size: number;
68
- }[];
69
- size: number;
70
- }>;
71
- /**
72
- * Scrolls results from previous elasticsearch query.
73
- * Automatically clears the scroll context after the last result page has
74
- * been fetched.
75
- *
76
- * @param {String} scrollId - Scroll identifier
77
- * @param {Object} options - scrollTTL (default scrollTTL)
78
- *
79
- * @returns {Promise.<{ scrollId, hits, aggregations, total }>}
80
- */
81
- scroll(scrollId: string, { scrollTTL }?: {
82
- scrollTTL?: string;
83
- }): Promise<{
84
- aggregations: any;
85
- hits: {
86
- _id: any;
87
- _score: any;
88
- _source: any;
89
- collection: string | undefined;
90
- highlight: any;
91
- index: string | undefined;
92
- inner_hits: {
93
- [k: string]: unknown[];
94
- } | undefined;
95
- }[];
96
- remaining: any;
97
- scrollId: any;
98
- suggest: any;
99
- total: any;
100
- }>;
101
- /**
102
- * Searches documents from elasticsearch with a query
103
- *
104
- * @param {String} index - Index name
105
- * @param {String} collection - Collection name
106
- * @param {Object} searchBody - Search request body (query, sort, etc.)
107
- * @param {Object} options - from (undefined), size (undefined), scroll (undefined)
108
- *
109
- * @returns {Promise.<{ scrollId, hits, aggregations, suggest, total }>}
110
- */
111
- search({ index, collection, searchBody, targets, }?: {
112
- index?: string;
113
- collection?: string;
114
- searchBody?: JSONObject;
115
- targets?: ValidatedTarget[];
116
- }, { from, size, scroll, }?: {
117
- from?: number;
118
- size?: number;
119
- scroll?: string;
120
- }): Promise<{
121
- aggregations: any;
122
- hits: {
123
- _id: any;
124
- _score: any;
125
- _source: any;
126
- collection: string | undefined;
127
- highlight: any;
128
- index: string | undefined;
129
- inner_hits: {
130
- [k: string]: unknown[];
131
- } | undefined;
132
- }[];
133
- remaining: any;
134
- scrollId: any;
135
- suggest: any;
136
- total: any;
137
- }>;
138
- /**
139
- * The comma-separated alias list a multi-target search is run against.
140
- *
141
- * @param targets - targets already through `assertTargetsAreValid`
142
- */
143
- _targetsToIndexes(targets: ValidatedTarget[]): string;
144
- /**
145
- * Generate a map that associate an alias to a pair of index and collection
146
- *
147
- * @param {*} targets
148
- * @returns
149
- */
150
- _mapTargetsToAlias(targets: ValidatedTarget[]): AliasToTargets;
151
- _formatSearchResult(body: JSONObject, searchInfo?: {
152
- collection?: string;
153
- index?: string;
154
- targets?: ValidatedTarget[];
155
- }): Promise<{
156
- aggregations: any;
157
- hits: {
158
- _id: any;
159
- _score: any;
160
- _source: any;
161
- collection: string | undefined;
162
- highlight: any;
163
- index: string | undefined;
164
- inner_hits: {
165
- [k: string]: unknown[];
166
- } | undefined;
167
- }[];
168
- remaining: any;
169
- scrollId: any;
170
- suggest: any;
171
- total: any;
172
- }>;
173
- /**
174
- * Gets the document with given ID
175
- *
176
- * @param {String} index - Index name
177
- * @param {String} collection - Collection name
178
- * @param {String} id - Document ID
179
- *
180
- * @returns {Promise.<{ _id, _version, _source }>}
181
- */
182
- get(index: string, collection: string, id: string): Promise<any>;
183
- /**
184
- * Returns the list of documents matching the ids given in the body param
185
- * NB: Due to internal Kuzzle mechanism, can only be called on a single
186
- * index/collection, using the body { ids: [.. } syntax.
187
- *
188
- * @param {String} index - Index name
189
- * @param {String} collection - Collection name
190
- * @param {Array.<String>} ids - Document IDs
191
- *
192
- * @returns {Promise.<{ items: Array<{ _id, _source, _version }>, errors }>}
193
- */
194
- mGet(index: string, collection: string, ids: string[]): Promise<{
195
- errors: any[];
196
- items: {
197
- _id: any;
198
- _source: any;
199
- _version: any;
200
- }[];
201
- }>;
202
- /**
203
- * Counts how many documents match the filter given in body
204
- *
205
- * @param {String} index - Index name
206
- * @param {String} collection - Collection name
207
- * @param {Object} searchBody - Search request body (query, sort, etc.)
208
- *
209
- * @returns {Promise.<Number>} count
210
- */
211
- count(index: string, collection: string, searchBody?: {}): Promise<any>;
212
- /**
213
- * Sends the new document to elasticsearch
214
- * Cleans data to match elasticsearch specifications
215
- *
216
- * @param {String} index - Index name
217
- * @param {String} collection - Collection name
218
- * @param {Object} content - Document content
219
- * @param {Object} options - id (undefined), refresh (undefined), userId (null)
220
- *
221
- * @returns {Promise.<Object>} { _id, _version, _source }
222
- */
223
- create(index: string, collection: string, content: JSONObject, { id, refresh, userId, injectKuzzleMeta, }?: {
224
- id?: string;
225
- refresh?: boolean | "wait_for";
226
- userId?: string | null;
227
- injectKuzzleMeta?: boolean;
228
- }): Promise<{
229
- _id: any;
230
- _source: KRequestBody<JSONObject>;
231
- _version: any;
232
- }>;
233
- /**
234
- * Creates a new document to Elasticsearch, or replace it if it already exist
235
- *
236
- * @param {String} index - Index name
237
- * @param {String} collection - Collection name
238
- * @param {String} id - Document id
239
- * @param {Object} content - Document content
240
- * @param {Object} options - refresh (undefined), userId (null), injectKuzzleMeta (true)
241
- *
242
- * @returns {Promise.<Object>} { _id, _version, _source, created }
243
- */
244
- createOrReplace(index: string, collection: string, id: string, content: JSONObject, { refresh, userId, injectKuzzleMeta, }?: {
245
- refresh?: boolean | "wait_for";
246
- userId?: string | null;
247
- injectKuzzleMeta?: boolean;
248
- }): Promise<{
249
- _id: any;
250
- _source: JSONObject;
251
- _version: any;
252
- created: boolean;
253
- }>;
254
- /**
255
- * Sends the partial document to elasticsearch with the id to update
256
- *
257
- * @param {String} index - Index name
258
- * @param {String} collection - Collection name
259
- * @param {String} id - Document id
260
- * @param {Object} content - Updated content
261
- * @param {Object} options - refresh (undefined), userId (null), retryOnConflict (0)
262
- *
263
- * @returns {Promise.<{ _id, _version }>}
264
- */
265
- update(index: string, collection: string, id: string, content: JSONObject, { refresh, userId, retryOnConflict, injectKuzzleMeta, }?: {
266
- refresh?: boolean | "wait_for";
267
- userId?: string | null;
268
- retryOnConflict?: number;
269
- injectKuzzleMeta?: boolean;
270
- }): Promise<{
271
- _id: any;
272
- _source: any;
273
- _version: any;
274
- }>;
275
- /**
276
- * Sends the partial document to elasticsearch with the id to update
277
- * Creates the document if it doesn't already exist
278
- *
279
- * @param {String} index - Index name
280
- * @param {String} collection - Collection name
281
- * @param {String} id - Document id
282
- * @param {Object} content - Updated content
283
- * @param {Object} options - defaultValues ({}), refresh (undefined), userId (null), retryOnConflict (0)
284
- *
285
- * @returns {Promise.<{ _id, _version }>}
286
- */
287
- upsert(index: string, collection: string, id: string, content: JSONObject, { defaultValues, refresh, userId, retryOnConflict, injectKuzzleMeta, }?: {
288
- defaultValues?: JSONObject;
289
- refresh?: boolean | "wait_for";
290
- userId?: string | null;
291
- retryOnConflict?: number;
292
- injectKuzzleMeta?: boolean;
293
- }): Promise<{
294
- _id: any;
295
- _source: any;
296
- _version: any;
297
- created: boolean;
298
- }>;
299
- /**
300
- * Replaces a document to Elasticsearch
301
- *
302
- * @param {String} index - Index name
303
- * @param {String} collection - Collection name
304
- * @param {String} id - Document id
305
- * @param {Object} content - Document content
306
- * @param {Object} options - refresh (undefined), userId (null)
307
- *
308
- * @returns {Promise.<{ _id, _version, _source }>}
309
- */
310
- replace(index: string, collection: string, id: string, content: JSONObject, { refresh, userId, injectKuzzleMeta, }?: {
311
- refresh?: boolean | "wait_for";
312
- userId?: string | null;
313
- injectKuzzleMeta?: boolean;
314
- }): Promise<{
315
- _id: string;
316
- _source: JSONObject;
317
- _version: any;
318
- }>;
319
- /**
320
- * Sends to elasticsearch the document id to delete
321
- *
322
- * @param {String} index - Index name
323
- * @param {String} collection - Collection name
324
- * @param {String} id - Document id
325
- * @param {Object} options - refresh (undefined)
326
- *
327
- * @returns {Promise}
328
- */
329
- delete(index: string, collection: string, id: string, { refresh, }?: {
330
- refresh?: boolean | "wait_for";
331
- }): Promise<null>;
332
- /**
333
- * Deletes all documents matching the provided filters.
334
- * If fetch=false, the max documents write limit is not applied.
335
- *
336
- * Options:
337
- * - size: size of the batch to retrieve documents (no-op if fetch=false)
338
- * - refresh: refresh option for ES
339
- * - fetch: if true, will fetch the documents before delete them
340
- *
341
- * @param {String} index - Index name
342
- * @param {String} collection - Collection name
343
- * @param {Object} query - Query to match documents
344
- * @param {Object} options - size (undefined), refresh (undefined), fetch (true)
345
- *
346
- * @returns {Promise.<{ documents, total, deleted, failures: Array<{ _shardId, reason }> }>}
347
- */
348
- deleteByQuery(index: string, collection: string, query: JSONObject, { refresh, size, fetch, }?: {
349
- refresh?: boolean | "wait_for";
350
- size?: number;
351
- fetch?: boolean;
352
- }): Promise<{
353
- deleted: any;
354
- documents: any;
355
- failures: any;
356
- total: any;
357
- }>;
358
- /**
359
- * Delete fields of a document and replace it
360
- *
361
- * @param {String} index - Index name
362
- * @param {String} collection - Collection name
363
- * @param {String} id - Document id
364
- * @param {Array} fields - Document fields to be removed
365
- * @param {Object} options - refresh (undefined), userId (null)
366
- *
367
- * @returns {Promise.<{ _id, _version, _source }>}
368
- */
369
- deleteFields(index: string, collection: string, id: string, fields: string[], { refresh, userId, }?: {
370
- refresh?: boolean | "wait_for";
371
- userId?: string | null;
372
- }): Promise<{
373
- _id: string;
374
- _source: any;
375
- _version: any;
376
- }>;
377
- /**
378
- * Updates all documents matching the provided filters
379
- *
380
- * @param {String} index - Index name
381
- * @param {String} collection - Collection name
382
- * @param {Object} query - Query to match documents
383
- * @param {Object} changes - Changes wanted on documents
384
- * @param {Object} options - refresh (undefined), size (undefined)
385
- *
386
- * @returns {Promise.<{ successes: [_id, _source, _status], errors: [ document, status, reason ] }>}
387
- */
388
- updateByQuery(index: string, collection: string, query: JSONObject, changes: JSONObject, { refresh, size, userId, }?: {
389
- refresh?: boolean | "wait_for";
390
- size?: number;
391
- userId?: string | null;
392
- }): Promise<{
393
- errors: JSONObject[];
394
- successes: JSONObject[];
395
- }>;
396
- /**
397
- * Updates all documents matching the provided filters
398
- *
399
- * @param {String} index - Index name
400
- * @param {String} collection - Collection name
401
- * @param {Object} query - Query to match documents
402
- * @param {Object} changes - Changes wanted on documents
403
- * @param {Object} options - refresh (undefined)
404
- *
405
- * @returns {Promise.<{ successes: [_id, _source, _status], errors: [ document, status, reason ] }>}
406
- */
407
- bulkUpdateByQuery(index: string, collection: string, query: JSONObject, changes: JSONObject, { refresh, }?: {
408
- refresh?: boolean;
409
- }): Promise<{
410
- updated: any;
411
- }>;
412
- /**
413
- * Execute the callback with a batch of documents of specified size until all
414
- * documents matched by the query have been processed.
415
- *
416
- * @param {String} index - Index name
417
- * @param {String} collection - Collection name
418
- * @param {Object} query - Query to match documents
419
- * @param {Function} callback - callback that will be called with the "hits" array
420
- * @param {Object} options - size (10), scrollTTL ('5s')
421
- *
422
- * @returns {Promise.<any[]>} Array of results returned by the callback
423
- */
424
- mExecute(index: string, collection: string, query: JSONObject, callback: (hits: JSONObject[]) => unknown, { size, scrollTTl, }?: {
425
- size?: number;
426
- scrollTTl?: string;
427
- }): Promise<unknown[]>;
428
- /**
429
- * Creates a new index.
430
- *
431
- * This methods creates an hidden collection in the provided index to be
432
- * able to list it.
433
- * This methods resolves if the index name does not already exists either as
434
- * private or public index.
435
- *
436
- * @param {String} index - Index name
437
- *
438
- * @returns {Promise}
439
- */
440
- createIndex(index: string): Promise<null>;
441
- /**
442
- * Creates an empty collection.
443
- * Mappings and settings will be applied if supplied.
444
- *
445
- * @param {String} index - Index name
446
- * @param {String} collection - Collection name
447
- * @param {Object} config - mappings ({}), settings ({})
448
- *
449
- * @returns {Promise}
450
- */
451
- createCollection(index: string, collection: string, { mappings, settings, }?: {
452
- mappings?: TypeMapping;
453
- settings?: JSONObject;
454
- }): Promise<null>;
455
- /**
456
- * Applies the mappings and settings of a `createCollection` call to a
457
- * collection that already exists because another request created it,
458
- * maybe so recently that its primary shards are still initializing.
459
- */
460
- private _updateConcurrentlyCreatedCollection;
461
- /**
462
- * Waits until the primary shards of a collection are active, for at most
463
- * `timeout`, and rejects if they are not by then.
464
- *
465
- * A collection another node has just created is in the cluster state, so
466
- * it exists, before its primary shard is active: until then, Elasticsearch
467
- * answers 503 to any document request on it. The node that creates a
468
- * collection waits for its shards (`wait_for_active_shards`); a node that
469
- * finds it already there calls this instead. It answers at once when the
470
- * shards are already active.
471
- *
472
- * A `yellow` status alone does not wait: Elasticsearch reports a new index
473
- * whose primaries are still initializing as `yellow` (#3074). Asking for as
474
- * many active shard copies as the index has primaries does, and, unlike
475
- * `wait_for_no_initializing_shards`, does not also wait for replicas that
476
- * are recovering, which a collection with data may take longer to do.
477
- */
478
- waitForCollectionShards(index: string, collection: string, timeout?: string): Promise<void>;
479
- /**
480
- * Retrieves settings definition for index/type
481
- *
482
- * @param {String} index - Index name
483
- * @param {String} collection - Collection name
484
- *
485
- * @returns {Promise.<{ settings }>}
486
- */
487
- getSettings(index: string, collection: string): Promise<any>;
488
- /**
489
- * Retrieves mapping definition for index/type
490
- *
491
- * @param {String} index - Index name
492
- * @param {String} collection - Collection name
493
- * @param {Object} options - includeKuzzleMeta (false)
494
- *
495
- * @returns {Promise.<{ dynamic, _meta, properties }>}
496
- */
497
- getMapping(index: string, collection: string, { includeKuzzleMeta, }?: {
498
- includeKuzzleMeta?: boolean;
499
- }): Promise<{
500
- _meta: any;
501
- dynamic: any;
502
- properties: any;
503
- }>;
504
- /**
505
- * Updates a collection mappings and settings
506
- *
507
- * @param {String} index - Index name
508
- * @param {String} collection - Collection name
509
- * @param {Object} config - mappings ({}), settings ({})
510
- *
511
- * @returns {Promise}
512
- */
513
- updateCollection(index: string, collection: string, { mappings, reindexCollection, settings, }?: {
514
- mappings?: TypeMapping;
515
- reindexCollection?: boolean;
516
- settings?: JSONObject;
517
- }): Promise<null>;
518
- /**
519
- * Given index settings we return a new version of index settings
520
- * only with allowed settings that can be set (during update or create index).
521
- * @param indexSettings the index settings
522
- * @returns {{index: *}} a new index settings with only allowed settings.
523
- */
524
- getAllowedIndexSettings(indexSettings: JSONObject): {
525
- index: _.Omit<any, "version" | "creation_date" | "provided_name" | "uuid">;
526
- };
527
- /**
528
- * Sends an empty UpdateByQuery request to update the search index
529
- *
530
- * @param {String} index - Index name
531
- * @param {String} collection - Collection name
532
- * @returns {Promise.<Object>} {}
533
- */
534
- updateSearchIndex(index: string, collection: string): Promise<void>;
535
- /**
536
- * Update a collection mappings
537
- *
538
- * @param {String} index - Index name
539
- * @param {String} collection - Collection name
540
- * @param {Object} mappings - Collection mappings in ES format
541
- *
542
- * @returns {Promise.<{ dynamic, _meta, properties }>}
543
- */
544
- updateMapping(index: string, collection: string, mappings?: TypeMapping): Promise<{
545
- dynamic: string;
546
- _meta: JSONObject;
547
- properties: JSONObject;
548
- }>;
549
- /**
550
- * Updates a collection settings (eg: analyzers)
551
- *
552
- * @param {String} index - Index name
553
- * @param {String} collection - Collection name
554
- * @param {Object} settings - Collection settings in ES format
555
- *
556
- * @returns {Promise}
557
- */
558
- updateSettings(index: string, collection: string, settings?: JSONObject): Promise<null>;
559
- /**
560
- * Empties the content of a collection. Keep the existing mapping and settings.
561
- *
562
- * @param {String} index - Index name
563
- * @param {String} collection - Collection name
564
- *
565
- * @returns {Promise}
566
- */
567
- truncateCollection(index: string, collection: string): Promise<null>;
568
- /**
569
- * Runs several action and document
570
- *
571
- * @param {String} index - Index name
572
- * @param {String} collection - Collection name
573
- * @param {Object[]} documents - Documents to import
574
- * @param {Object} options - timeout (undefined), refresh (undefined), userId (null)
575
- *
576
- * @returns {Promise.<{ items, errors }>
577
- */
578
- import(index: string, collection: string, documents: JSONObject[], { refresh, timeout, userId, }?: {
579
- refresh?: boolean | "wait_for";
580
- timeout?: string;
581
- userId?: string | null;
582
- }): Promise<KImportResult>;
583
- /**
584
- * The error entry `import` reports for one rejected bulk row.
585
- *
586
- * @param action - the bulk action Elasticsearch echoed back
587
- * @param item - that action's answer
588
- * @param payload - the action's payload, absent for a delete
589
- */
590
- _importError(action: string, item: JSONObject, payload: JSONObject | undefined): KImportError;
591
- /**
592
- * Retrieves the complete list of existing collections in the current index
593
- *
594
- * @param {String} index - Index name
595
- * @param {Object.Boolean} includeHidden - Optional: include HIDDEN_COLLECTION in results
596
- *
597
- * @returns {Promise.<Array>} Collection names
598
- */
599
- listCollections(index: string, { includeHidden }?: {
600
- includeHidden?: boolean | undefined;
601
- }): Promise<string[]>;
602
- /**
603
- * Retrieves the complete list of indexes
604
- *
605
- * @returns {Promise.<Array>} Index names
606
- */
607
- listIndexes(): Promise<string[]>;
608
- /**
609
- * Returns an object containing the list of indexes and collections
610
- *
611
- * @returns {Object.<String, String[]>} Object<index, collections>
612
- */
613
- getSchema(): Promise<Record<string, string[]>>;
614
- /**
615
- * Retrieves the complete list of aliases
616
- *
617
- * @returns {Promise.<Object[]>} [ { alias, index, collection, indice } ]
618
- */
619
- listAliases(): Promise<{
620
- alias: string;
621
- collection: string;
622
- index: string;
623
- indice: string;
624
- }[]>;
625
- /**
626
- * Deletes a collection
627
- *
628
- * @param {String} index - Index name
629
- * @param {String} collection - Collection name
630
- *
631
- * @returns {Promise}
632
- */
633
- deleteCollection(index: string, collection: string): Promise<null>;
634
- /**
635
- * Deletes multiple indexes
636
- *
637
- * @param {String[]} indexes - Index names
638
- *
639
- * @returns {Promise.<String[]>}
640
- */
641
- deleteIndexes(indexes?: string[]): Promise<string[]>;
642
- /**
643
- * Deletes an index
644
- *
645
- * @param {String} index - Index name
646
- *
647
- * @returns {Promise}
648
- */
649
- deleteIndex(index: string): Promise<null>;
650
- /**
651
- * Forces a refresh on the collection.
652
- *
653
- * /!\ Can lead to some performance issues.
654
- * cf https://www.elastic.co/guide/en/elasticsearch/guide/current/near-real-time.html for more details
655
- *
656
- * @param {String} index - Index name
657
- * @param {String} collection - Collection name
658
- *
659
- * @returns {Promise.<Object>} { _shards }
660
- */
661
- refreshCollection(index: string, collection: string): Promise<{
662
- _shards: ShardStatistics;
663
- }>;
664
- /**
665
- * Returns true if the document exists
666
- *
667
- * @param {String} index - Index name
668
- * @param {String} collection - Collection name
669
- * @param {String} id - Document ID
670
- *
671
- * @returns {Promise.<boolean>}
672
- */
673
- exists(index: string, collection: string, id: string): Promise<boolean>;
674
- /**
675
- * Returns the list of documents existing with the ids given in the body param
676
- * NB: Due to internal Kuzzle mechanism, can only be called on a single
677
- * index/collection, using the body { ids: [.. } syntax.
678
- *
679
- * @param {String} index - Index name
680
- * @param {String} collection - Collection name
681
- * @param {Array.<String>} ids - Document IDs
682
- *
683
- * @returns {Promise.<{ items: Array<{ _id, _source, _version }>, errors }>}
684
- */
685
- mExists(index: string, collection: string, ids: string[]): Promise<{
686
- errors: any[];
687
- items: any[];
688
- }>;
689
- /**
690
- * Returns true if the index exists
691
- *
692
- * @param {String} index - Index name
693
- *
694
- * @returns {Promise.<boolean>}
695
- */
696
- hasIndex(index: string): Promise<boolean>;
697
- /**
698
- * Returns true if the collection exists
699
- *
700
- * @param {String} index - Index name
701
- * @param {String} collection - Collection name
702
- *
703
- * @returns {Promise.<boolean>}
704
- */
705
- hasCollection(index: string, collection: string): Promise<boolean>;
706
- /**
707
- * Returns true if the index has the hidden collection
708
- *
709
- * @param {String} index - Index name
710
- *
711
- * @returns {Promise.<boolean>}
712
- */
713
- _hasHiddenCollection(index: string): Promise<boolean>;
714
- /**
715
- * Creates multiple documents at once.
716
- * If a content has no id, one is automatically generated and assigned to it.
717
- * If a content has a specified identifier, it is rejected if it already exists
718
- *
719
- * @param {String} index - Index name
720
- * @param {String} collection - Collection name
721
- * @param {Object[]} documents - Documents
722
- * @param {Object} options - timeout (undefined), refresh (undefined), userId (null)
723
- *
724
- * @returns {Promise.<Object>} { items, errors }
725
- */
726
- mCreate(index: string, collection: string, documents: JSONObject[], { refresh, timeout, userId, }?: {
727
- refresh?: boolean | "wait_for";
728
- timeout?: string;
729
- userId?: string | null;
730
- }): Promise<KMExecuteResult>;
731
- /**
732
- * Creates or replaces multiple documents at once.
733
- *
734
- * @param {String} index - Index name
735
- * @param {String} collection - Collection name
736
- * @param {Object[]} documents - Documents
737
- * @param {Object} options - timeout (undefined), refresh (undefined), userId (null), injectKuzzleMeta (false), limits (true)
738
- *
739
- * @returns {Promise.<{ items, errors }>
740
- */
741
- mCreateOrReplace(index: string, collection: string, documents: JSONObject[], { refresh, timeout, userId, injectKuzzleMeta, limits, source, }?: KRequestParams): Promise<KMExecuteResult>;
742
- /**
743
- * Updates multiple documents with one request
744
- * Replacements are rejected if targeted documents do not exist
745
- * (like with the normal "update" method)
746
- *
747
- * @param {String} index - Index name
748
- * @param {String} collection - Collection name
749
- * @param {Object[]} documents - Documents
750
- * @param {Object} options - timeout (undefined), refresh (undefined), retryOnConflict (0), userId (null)
751
- *
752
- * @returns {Promise.<Object>} { items, errors }
753
- */
754
- mUpdate(index: string, collection: string, documents: JSONObject[], { refresh, retryOnConflict, timeout, userId, }?: {
755
- refresh?: boolean | "wait_for";
756
- retryOnConflict?: number;
757
- timeout?: string;
758
- userId?: string | null;
759
- }): Promise<KMExecuteResult>;
760
- /**
761
- * Creates or replaces multiple documents at once.
762
- *
763
- * @param {String} index - Index name
764
- * @param {String} collection - Collection name
765
- * @param {Object[]} documents - Documents
766
- * @param {Object} options - refresh (undefined), retryOnConflict (0), timeout (undefined), userId (null)
767
- *
768
- * @returns {Promise.<{ items, errors }>
769
- */
770
- mUpsert(index: string, collection: string, documents: JSONObject[], { refresh, retryOnConflict, timeout, userId, }?: {
771
- refresh?: boolean | "wait_for";
772
- retryOnConflict?: number;
773
- timeout?: string;
774
- userId?: string | null;
775
- }): Promise<KMExecuteResult>;
776
- /**
777
- * Replaces multiple documents at once.
778
- * Replacements are rejected if targeted documents do not exist
779
- * (like with the normal "replace" method)
780
- *
781
- * @param {String} index - Index name
782
- * @param {String} collection - Collection name
783
- * @param {Object[]} documents - Documents
784
- * @param {Object} options - timeout (undefined), refresh (undefined), userId (null)
785
- *
786
- * @returns {Promise.<Object>} { items, errors }
787
- */
788
- mReplace(index: string, collection: string, documents: JSONObject[], { refresh, timeout, userId, }?: {
789
- refresh?: boolean | "wait_for";
790
- timeout?: string;
791
- userId?: string | null;
792
- }): Promise<KMExecuteResult>;
793
- /**
794
- * Deletes multiple documents with one request
795
- *
796
- * @param {String} index - Index name
797
- * @param {String} collection - Collection name
798
- * @param {Array.<String>} ids - Documents IDs
799
- * @param {Object} options - timeout (undefined), refresh (undefined)
800
- *
801
- * @returns {Promise.<{ documents, errors }>
802
- */
803
- mDelete(index: string, collection: string, ids: string[], { refresh, }?: {
804
- refresh?: boolean | "wait_for";
805
- timeout?: number;
806
- }): Promise<{
807
- documents: any;
808
- errors: ({
809
- _id: undefined;
810
- reason: string;
811
- status: number;
812
- } | {
813
- _id: string;
814
- reason: string;
815
- status: number;
816
- })[];
817
- }>;
818
- /**
819
- * Executes an ES request prepared by mcreate, mupdate, mreplace, mdelete or mwriteDocuments
820
- * Returns a standardized ES response object, containing the list of
821
- * successfully performed operations, and the rejected ones
822
- *
823
- * @param {Object} esRequest - Elasticsearch request
824
- * @param {Object[]} documents - Document sources (format: {_id, _source})
825
- * @param {Object[]} partialErrors - pre-rejected documents
826
- * @param {Object} options - limits (true)
827
- *
828
- * @returns {Promise.<Object[]>} results
829
- */
830
- _mExecute(esRequest: RequestParams.Bulk, documents: JSONObject[], partialErrors?: JSONObject[], { limits, source }?: {
831
- limits?: boolean | undefined;
832
- source?: boolean | undefined;
833
- }): Promise<KMExecuteResult>;
834
- /**
835
- * The partial-error entry `_mExecute` reports for one rejected bulk row.
836
- *
837
- * A 404 answers no reason of its own, and reports the document by id and
838
- * body rather than whole, which is what the m* callers read back.
839
- */
840
- _mExecuteRejection(result: JSONObject, document: JSONObject): JSONObject;
841
- /**
842
- * Extracts, injects metadata and validates documents contained
843
- * in a Request
844
- *
845
- * Used by mCreate, mUpdate, mUpsert, mReplace and mCreateOrReplace
846
- *
847
- * @param {Object[]} documents - Documents
848
- * @param {Object} metadata - Kuzzle metadata
849
- * @param {Object} options - prepareMGet (false), requireId (false)
850
- *
851
- * @returns {Object} { rejected, extractedDocuments, documentsToGet }
852
- */
853
- _extractMDocuments(documents: JSONObject[], metadata: JSONObject, { prepareMGet, requireId, prepareMUpsert }?: {
854
- prepareMGet?: boolean | undefined;
855
- requireId?: boolean | undefined;
856
- prepareMUpsert?: boolean | undefined;
857
- }): {
858
- documentsToGet: JSONObject[];
859
- extractedDocuments: JSONObject[];
860
- rejected: JSONObject[];
861
- };
862
- private _hasExceededLimit;
863
- private _processExtract;
864
- /**
865
- * Throws an error if the provided mapping is invalid
866
- *
867
- * @param {Object} mapping
868
- * @throws
869
- */
870
- _checkMappings(mapping: JSONObject, path?: string[], check?: boolean): void;
871
- /**
872
- * Given index + collection, returns the associated alias name.
873
- * Prefer this function to `_getIndice` and `_getAvailableIndice` whenever it is possible.
874
- *
875
- * @param {String} index
876
- * @param {String} collection
877
- *
878
- * @returns {String} Alias name (eg: '@&nepali.liia')
879
- */
880
- _getAlias(index: string, collection?: string): string;
881
- /**
882
- * Given an alias name, returns the associated index name.
883
- */
884
- _checkIfAliasExists(aliasName: string): Promise<boolean>;
885
- /**
886
- * Given index + collection, returns the associated indice name.
887
- * Use this function if ES does not accept aliases in the request. Otherwise use `_getAlias`.
888
- *
889
- * @param {String} index
890
- * @param {String} collection
891
- *
892
- * @returns {String} Indice name (eg: '&nepali.liia')
893
- * @throws If there is not exactly one indice associated
894
- */
895
- _getIndice(index: string, collection: string): Promise<string>;
896
- /**
897
- * Given an ES Request returns the settings of the corresponding indice.
898
- *
899
- * @param esRequest the ES Request with wanted settings.
900
- * @return {Promise<*>} the settings of the indice.
901
- * @private
902
- */
903
- _getSettings(esRequest: RequestParams.IndicesGetSettings): Promise<JSONObject>;
904
- /**
905
- * Given index + collection, returns an available indice name.
906
- * Use this function when creating the associated indice. Otherwise use `_getAlias`.
907
- *
908
- * @param {String} index
909
- * @param {String} collection
910
- *
911
- * @returns {String} Available indice name (eg: '&nepali.liia2')
912
- */
913
- _getAvailableIndice(index: string, collection: string): Promise<string>;
914
- /**
915
- * Given an indice, returns the associated alias name.
916
- *
917
- * @param {String} indice
918
- *
919
- * @returns {String} Alias name (eg: '@&nepali.liia')
920
- * @throws If there is not exactly one alias associated that is prefixed with @
921
- */
922
- /**
923
- * `cat.aliases` answers untyped rows whose `alias` and `index` the client
924
- * declares as optional. Defaulting them once here is what lets every caller
925
- * index into an alias without repeating the check — and an empty alias fails
926
- * the index-prefix test every caller applies, which is what a row without one
927
- * used to throw on.
928
- */
929
- _catAliases(name?: string): Promise<CatAliasRecord[]>;
930
- _getAliasFromIndice(indice: string): Promise<[string, ...string[]]>;
931
- /**
932
- * Check for each indice whether it has an alias or not.
933
- * When the latter is missing, create one based on the indice name.
934
- *
935
- * This check avoids a breaking change for those who were using Kuzzle before
936
- * alias attribution for each indice turned into a standard (appear in 2.14.0).
937
- */
938
- generateMissingAliases(): Promise<void>;
939
- /**
940
- * Throws if index or collection includes forbidden characters
941
- *
942
- * @param {String} index
943
- * @param {String} collection
944
- */
945
- _assertValidIndexAndCollection(index: string, collection?: string | null): void;
946
- /**
947
- * Given an alias, extract the associated index.
948
- *
949
- * @param {String} alias
950
- *
951
- * @returns {String} Index name
952
- */
953
- _extractIndex(alias: string): string;
954
- /**
955
- * Given an alias, extract the associated collection.
956
- *
957
- * @param {String} alias
958
- *
959
- * @returns {String} Collection name
960
- */
961
- _extractCollection(alias: string): string;
962
- /**
963
- * Given aliases, extract indexes and collections.
964
- *
965
- * @param {Array.<String>} aliases
966
- * @param {Object.Boolean} includeHidden Only refers to `HIDDEN_COLLECTION` occurences. An empty index will still be listed. Default to `false`.
967
- *
968
- * @returns {Object.<String, String[]>} Indexes as key and an array of their collections as value
969
- */
970
- _extractSchema(aliases: string[], { includeHidden }?: {
971
- includeHidden?: boolean | undefined;
972
- }): Record<string, string[]>;
973
- /**
974
- * Creates the hidden collection on the provided index if it does not already
975
- * exists
976
- *
977
- * @param {String} index Index name
978
- */
979
- _createHiddenCollection(index: string): Promise<void>;
980
- /**
981
- * We need to always wait for a minimal number of shards to be available
982
- * before answering to the client. This is to avoid Elasticsearch node
983
- * to return a 404 Not Found error when the client tries to index a
984
- * document in the index.
985
- * To find the best value for this setting, we need to take into account
986
- * the number of nodes in the cluster and the number of shards per index.
987
- */
988
- _getWaitForActiveShards(): Promise<string>;
989
- /**
990
- * Scroll indice in elasticsearch and return all document that match the filter
991
- * /!\ throws a write_limit_exceed error: this method is intended to be used
992
- * by deleteByQuery and updateByQuery
993
- *
994
- * @param {Object} esRequest - Search request body
995
- *
996
- * @returns {Promise.<Array>} resolve to an array of documents
997
- */
998
- _getAllDocumentsFromQuery(esRequest: RequestParams.Search<JSONObject>): Promise<any>;
999
- /**
1000
- * Clean and normalize the searchBody
1001
- * Ensure only allowed parameters are passed to ES
1002
- *
1003
- * @param {Object} searchBody - ES search body (with query, aggregations, sort, etc)
1004
- */
1005
- _sanitizeSearchBody(searchBody?: JSONObject): JSONObject;
1006
- /**
1007
- * Throw if a script is used in the query.
1008
- *
1009
- * Only Stored Scripts are accepted
1010
- *
1011
- * @param {Object} object
1012
- */
1013
- _scriptCheck(object: JSONObject): void;
1014
- /**
1015
- * Checks if a collection name is valid
1016
- * @param {string} name
1017
- * @returns {Boolean}
1018
- */
1019
- isCollectionNameValid(name: string): boolean;
1020
- /**
1021
- * Checks if a collection name is valid
1022
- * @param {string} name
1023
- * @returns {Boolean}
1024
- */
1025
- isIndexNameValid(name: string): boolean;
1026
- /**
1027
- * Clears an allocated scroll
1028
- * @param {[type]} id [description]
1029
- * @returns {[type]} [description]
1030
- */
1031
- clearScroll(id?: string): Promise<void>;
1032
- /**
1033
- * Loads a configuration value from services.storageEngine and assert a valid
1034
- * ms format.
1035
- *
1036
- * @param {String} key - relative path to the key in configuration
1037
- *
1038
- * @returns {Number} milliseconds
1039
- */
1040
- _loadMsConfig(key: string): number;
1041
- /**
1042
- * Returns true if one of the mappings dynamic property changes value from
1043
- * false to true
1044
- */
1045
- _dynamicChanges(previousMappings: JSONObject, newMappings: JSONObject): boolean;
1046
- waitForElasticsearch(): Promise<void>;
1047
- /**
1048
- * Checks if the dynamic properties are correct
1049
- */
1050
- _checkDynamicProperty(mappings: JSONObject): void;
1051
- _setLastActionToKuzzleMeta(esRequest: JSONObject, alias: string, kuzzleMeta: JSONObject): void;
1052
- _setLastActionToKuzzleMetaUpdate(item: JSONObject, kuzzleMeta: JSONObject): void;
1053
- _getRandomNumber(number: number): number;
1054
- }