kuzzle 2.59.0 → 2.60.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 (174) hide show
  1. package/dist/bin/copy-binaries.js +17 -7
  2. package/dist/bin/start-kuzzle-server +17 -7
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +6 -2
  5. package/dist/lib/api/controllers/adminController.d.ts +9 -3
  6. package/dist/lib/api/controllers/adminController.js +42 -26
  7. package/dist/lib/api/controllers/authController.d.ts +15 -5
  8. package/dist/lib/api/controllers/authController.js +35 -20
  9. package/dist/lib/api/controllers/baseController.js +17 -7
  10. package/dist/lib/api/controllers/bulkController.js +17 -7
  11. package/dist/lib/api/controllers/collectionController.js +17 -7
  12. package/dist/lib/api/controllers/debugController.js +17 -7
  13. package/dist/lib/api/controllers/documentController.js +17 -7
  14. package/dist/lib/api/controllers/indexController.d.ts +1 -1
  15. package/dist/lib/api/controllers/memoryStorageController.js +17 -7
  16. package/dist/lib/api/controllers/securityController.d.ts +30 -28
  17. package/dist/lib/api/controllers/securityController.js +18 -8
  18. package/dist/lib/api/controllers/serverController.d.ts +0 -1
  19. package/dist/lib/api/controllers/serverController.js +17 -7
  20. package/dist/lib/api/documentExtractor.js +17 -7
  21. package/dist/lib/api/funnel.js +19 -9
  22. package/dist/lib/api/httpRoutes.d.ts +2 -1
  23. package/dist/lib/api/openapi/OpenApiManager.d.ts +2 -1
  24. package/dist/lib/api/openapi/openApiGenerator.js +1 -2
  25. package/dist/lib/api/request/kuzzleRequest.d.ts +9 -2
  26. package/dist/lib/api/request/kuzzleRequest.js +21 -7
  27. package/dist/lib/api/request/requestContext.d.ts +7 -2
  28. package/dist/lib/api/request/requestContext.js +17 -7
  29. package/dist/lib/api/request/requestInput.d.ts +1 -1
  30. package/dist/lib/api/request/requestInput.js +17 -7
  31. package/dist/lib/api/request/requestResponse.d.ts +2 -2
  32. package/dist/lib/api/request/requestResponse.js +21 -10
  33. package/dist/lib/cluster/command.d.ts +0 -2
  34. package/dist/lib/cluster/command.js +17 -7
  35. package/dist/lib/cluster/idCardHandler.d.ts +3 -2
  36. package/dist/lib/cluster/idCardHandler.js +1 -1
  37. package/dist/lib/cluster/node.js +69 -64
  38. package/dist/lib/cluster/protobuf/command.proto +23 -22
  39. package/dist/lib/cluster/protobuf/sync.proto +91 -85
  40. package/dist/lib/cluster/publisher.js +17 -7
  41. package/dist/lib/cluster/state.js +17 -7
  42. package/dist/lib/cluster/subscriber.d.ts +0 -2
  43. package/dist/lib/cluster/subscriber.js +17 -7
  44. package/dist/lib/cluster/workers/IDCardRenewer.d.ts +0 -1
  45. package/dist/lib/config/index.js +20 -14
  46. package/dist/lib/core/auth/formatProcessing.d.ts +1 -1
  47. package/dist/lib/core/auth/formatProcessing.js +3 -3
  48. package/dist/lib/core/auth/passportResponse.d.ts +0 -1
  49. package/dist/lib/core/auth/passportWrapper.js +22 -8
  50. package/dist/lib/core/backend/backend.js +17 -7
  51. package/dist/lib/core/backend/backendConfig.d.ts +1 -1
  52. package/dist/lib/core/backend/backendConfig.js +17 -7
  53. package/dist/lib/core/backend/backendController.js +17 -7
  54. package/dist/lib/core/backend/backendErrors.js +17 -7
  55. package/dist/lib/core/backend/backendHook.js +17 -7
  56. package/dist/lib/core/backend/backendImport.js +17 -7
  57. package/dist/lib/core/backend/backendPipe.d.ts +4 -1
  58. package/dist/lib/core/backend/backendPipe.js +17 -7
  59. package/dist/lib/core/backend/backendPlugin.js +17 -7
  60. package/dist/lib/core/backend/backendStorage.js +8 -8
  61. package/dist/lib/core/backend/backendSubscription.js +17 -7
  62. package/dist/lib/core/backend/backendVault.js +17 -7
  63. package/dist/lib/core/backend/internalLogger.d.ts +7 -7
  64. package/dist/lib/core/debug/kuzzleDebugger.js +17 -7
  65. package/dist/lib/core/network/accessLogger.d.ts +0 -1
  66. package/dist/lib/core/network/accessLogger.js +17 -7
  67. package/dist/lib/core/network/clientConnection.js +17 -7
  68. package/dist/lib/core/network/context.d.ts +0 -1
  69. package/dist/lib/core/network/entryPoint.js +17 -7
  70. package/dist/lib/core/network/httpRouter/routePart.js +17 -7
  71. package/dist/lib/core/network/protocols/httpMessage.d.ts +0 -2
  72. package/dist/lib/core/network/protocols/httpwsProtocol.d.ts +0 -3
  73. package/dist/lib/core/network/protocols/httpwsProtocol.js +29 -12
  74. package/dist/lib/core/network/protocols/mqttProtocol.d.ts +1 -2
  75. package/dist/lib/core/network/protocols/mqttProtocol.js +31 -10
  76. package/dist/lib/core/network/router.js +17 -7
  77. package/dist/lib/core/plugin/plugin.js +17 -7
  78. package/dist/lib/core/plugin/pluginContext.d.ts +20 -9
  79. package/dist/lib/core/plugin/pluginContext.js +39 -24
  80. package/dist/lib/core/plugin/pluginsManager.js +17 -7
  81. package/dist/lib/core/realtime/channel.js +17 -7
  82. package/dist/lib/core/realtime/hotelClerk.d.ts +3 -2
  83. package/dist/lib/core/realtime/hotelClerk.js +17 -7
  84. package/dist/lib/core/realtime/notifier.js +17 -7
  85. package/dist/lib/core/security/profileRepository.js +17 -7
  86. package/dist/lib/core/security/roleRepository.js +17 -7
  87. package/dist/lib/core/security/securityLoader.js +17 -7
  88. package/dist/lib/core/security/tokenRepository.js +18 -8
  89. package/dist/lib/core/security/userRepository.js +17 -7
  90. package/dist/lib/core/shared/ObjectRepository.js +20 -7
  91. package/dist/lib/core/shared/abstractManifest.js +17 -7
  92. package/dist/lib/core/shared/sdk/embeddedSdk.js +20 -8
  93. package/dist/lib/core/shared/sdk/funnelProtocol.js +17 -7
  94. package/dist/lib/core/shared/store.d.ts +11 -1
  95. package/dist/lib/core/shared/store.js +26 -30
  96. package/dist/lib/core/statistics/statistics.d.ts +0 -1
  97. package/dist/lib/core/statistics/statistics.js +17 -7
  98. package/dist/lib/core/storage/clientAdapter.d.ts +4 -6
  99. package/dist/lib/core/storage/clientAdapter.js +24 -18
  100. package/dist/lib/core/storage/indexCache.js +17 -7
  101. package/dist/lib/core/validation/specification.js +1 -2
  102. package/dist/lib/core/validation/types/date.js +17 -7
  103. package/dist/lib/core/validation/types/enum.js +17 -7
  104. package/dist/lib/core/validation/types/geoShape.js +17 -7
  105. package/dist/lib/core/validation/types/geoShapeUtils.js +6 -7
  106. package/dist/lib/core/validation/validation.js +17 -7
  107. package/dist/lib/core/validation/validationUtils.js +24 -15
  108. package/dist/lib/kerror/codes/index.js +20 -10
  109. package/dist/lib/kerror/errors/kuzzleError.js +18 -8
  110. package/dist/lib/kerror/index.js +31 -18
  111. package/dist/lib/kuzzle/Logger.js +4 -3
  112. package/dist/lib/kuzzle/dumpGenerator.js +17 -7
  113. package/dist/lib/kuzzle/event/KuzzleEventEmitter.d.ts +3 -3
  114. package/dist/lib/kuzzle/event/KuzzleEventEmitter.js +17 -7
  115. package/dist/lib/kuzzle/event/pipeRunner.js +17 -7
  116. package/dist/lib/kuzzle/internalIndexHandler.js +37 -32
  117. package/dist/lib/kuzzle/kuzzle.d.ts +13 -8
  118. package/dist/lib/kuzzle/kuzzle.js +103 -128
  119. package/dist/lib/model/security/profile.js +17 -7
  120. package/dist/lib/model/security/role.js +17 -7
  121. package/dist/lib/model/security/user.js +17 -7
  122. package/dist/lib/model/storage/apiKey.d.ts +1 -1
  123. package/dist/lib/model/storage/apiKey.js +17 -7
  124. package/dist/lib/service/cache/redis.js +40 -9
  125. package/dist/lib/service/service.js +17 -7
  126. package/dist/lib/service/storage/7/elasticsearch.d.ts +36 -25
  127. package/dist/lib/service/storage/7/elasticsearch.js +73 -55
  128. package/dist/lib/service/storage/8/elasticsearch.d.ts +47 -36
  129. package/dist/lib/service/storage/8/elasticsearch.js +73 -55
  130. package/dist/lib/service/storage/Elasticsearch.d.ts +10 -4
  131. package/dist/lib/types/HttpStream.d.ts +0 -1
  132. package/dist/lib/types/Plugin.js +17 -7
  133. package/dist/lib/types/config/SecurityConfiguration.d.ts +0 -2
  134. package/dist/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +5 -0
  135. package/dist/lib/types/controllers/GetCurrentUserResponse.d.ts +5 -0
  136. package/dist/lib/types/controllers/GetCurrentUserResponse.js +3 -0
  137. package/dist/lib/types/controllers/ResetSecurityResult.d.ts +5 -0
  138. package/dist/lib/types/controllers/ResetSecurityResult.js +3 -0
  139. package/dist/lib/types/controllers/adminController.type.d.ts +7 -5
  140. package/dist/lib/types/controllers/authController.type.d.ts +7 -5
  141. package/dist/lib/types/core/auth/Serialized.d.ts +14 -0
  142. package/dist/lib/types/core/auth/Serialized.js +3 -0
  143. package/dist/lib/types/core/auth/formatProcessing.type.d.ts +5 -11
  144. package/dist/lib/types/events/EventProtocol.d.ts +0 -2
  145. package/dist/lib/types/index.d.ts +1 -0
  146. package/dist/lib/types/index.js +1 -0
  147. package/dist/lib/types/storage/8/Elasticsearch.d.ts +4 -3
  148. package/dist/lib/util/array.d.ts +1 -1
  149. package/dist/lib/util/array.js +7 -6
  150. package/dist/lib/util/assertType.js +5 -6
  151. package/dist/lib/util/async.js +1 -2
  152. package/dist/lib/util/asyncStore.d.ts +0 -1
  153. package/dist/lib/util/bufferedPassThrough.d.ts +0 -3
  154. package/dist/lib/util/crypto.js +1 -2
  155. package/dist/lib/util/debug.d.ts +0 -1
  156. package/dist/lib/util/debug.js +17 -7
  157. package/dist/lib/util/distributedLock.d.ts +27 -4
  158. package/dist/lib/util/distributedLock.js +69 -16
  159. package/dist/lib/util/dump-collection.d.ts +2 -2
  160. package/dist/lib/util/dump-collection.js +22 -13
  161. package/dist/lib/util/esRequest.js +1 -2
  162. package/dist/lib/util/extractFields.d.ts +16 -7
  163. package/dist/lib/util/extractFields.js +1 -10
  164. package/dist/lib/util/koncordeCompat.js +22 -13
  165. package/dist/lib/util/mutex.d.ts +4 -4
  166. package/dist/lib/util/mutex.js +21 -11
  167. package/dist/lib/util/name-generator.js +2 -2
  168. package/dist/lib/util/requestAssertions.js +27 -18
  169. package/dist/lib/util/safeObject.js +3 -4
  170. package/dist/lib/util/stackTrace.js +2 -3
  171. package/dist/lib/util/thrown.js +1 -2
  172. package/dist/lib/util/time.js +1 -2
  173. package/dist/package.json +22 -15
  174. package/package.json +22 -15
@@ -3,6 +3,7 @@ import type { estypes } from "sdk-es8";
3
3
  import { Client } from "sdk-es8";
4
4
  import type { AliasToTargets, CatAliasRecord, InfoResult, JSONObject, KImportError, KImportResult, KMExecuteResult, KRequestBody, KRequestParams, KStats, KUpdateResponse } from "../../../types/storage/8/Elasticsearch";
5
5
  import { storeScopeEnum } from "../../../core/storage/storeScopeEnum";
6
+ import type { StorageEngineElasticsearch } from "../../../types/config/storageEngine/StorageEngineElasticsearchConfiguration";
6
7
  import type { ValidatedTarget } from "../../../types/Target";
7
8
  import { QueryTranslator } from "../commons/queryTranslator";
8
9
  import ESWrapper from "./esWrapper";
@@ -21,16 +22,16 @@ export declare class ES8 {
21
22
  _scope: storeScopeEnum;
22
23
  _indexPrefix: string;
23
24
  _esWrapper: ESWrapper;
24
- _esVersion: any;
25
+ _esVersion: estypes.ElasticsearchVersionInfo | null;
25
26
  _translator: QueryTranslator;
26
27
  searchBodyKeys: string[];
27
28
  scriptKeys: string[];
28
29
  scriptAllowedArgs: string[];
29
30
  maxScrollDuration: number;
30
31
  scrollTTL: number;
31
- _config: any;
32
+ _config: StorageEngineElasticsearch;
32
33
  private readonly logger;
33
- constructor(config: any, scope?: storeScopeEnum);
34
+ constructor(config: StorageEngineElasticsearch, scope?: storeScopeEnum);
34
35
  get scope(): storeScopeEnum;
35
36
  /**
36
37
  * Initializes the elasticsearch client
@@ -72,20 +73,22 @@ export declare class ES8 {
72
73
  scroll(scrollId: string, { scrollTTL }?: {
73
74
  scrollTTL?: string;
74
75
  }): Promise<{
75
- aggregations: any;
76
+ aggregations: Record<string, estypes.AggregationsAggregate> | undefined;
76
77
  hits: {
77
78
  _id: string | undefined;
78
79
  _score: number | null | undefined;
79
80
  _source: unknown;
80
- collection: any;
81
+ collection: string | undefined;
81
82
  highlight: Record<string, string[]> | undefined;
82
- index: any;
83
- inner_hits: JSONObject | undefined;
83
+ index: string | undefined;
84
+ inner_hits: {
85
+ [k: string]: unknown[];
86
+ } | undefined;
84
87
  }[];
85
88
  remaining: number | undefined;
86
- scrollId: any;
87
- suggest: any;
88
- total: any;
89
+ scrollId: string | undefined;
90
+ suggest: Record<string, estypes.SearchSuggest<unknown>[]> | undefined;
91
+ total: number;
89
92
  }>;
90
93
  /**
91
94
  * Searches documents from elasticsearch with a query
@@ -101,26 +104,28 @@ export declare class ES8 {
101
104
  index?: string;
102
105
  collection?: string;
103
106
  searchBody?: JSONObject;
104
- targets?: any[];
107
+ targets?: ValidatedTarget[];
105
108
  }, { from, size, scroll, }?: {
106
109
  from?: number;
107
110
  size?: number;
108
111
  scroll?: string;
109
112
  }): Promise<{
110
- aggregations: any;
113
+ aggregations: Record<string, estypes.AggregationsAggregate> | undefined;
111
114
  hits: {
112
115
  _id: string | undefined;
113
116
  _score: number | null | undefined;
114
117
  _source: unknown;
115
- collection: any;
118
+ collection: string | undefined;
116
119
  highlight: Record<string, string[]> | undefined;
117
- index: any;
118
- inner_hits: JSONObject | undefined;
120
+ index: string | undefined;
121
+ inner_hits: {
122
+ [k: string]: unknown[];
123
+ } | undefined;
119
124
  }[];
120
125
  remaining: number | undefined;
121
- scrollId: any;
122
- suggest: any;
123
- total: any;
126
+ scrollId: string | undefined;
127
+ suggest: Record<string, estypes.SearchSuggest<unknown>[]> | undefined;
128
+ total: number;
124
129
  }>;
125
130
  /**
126
131
  * The comma-separated alias list a multi-target search is run against.
@@ -135,21 +140,27 @@ export declare class ES8 {
135
140
  * @returns
136
141
  */
137
142
  _mapTargetsToAlias(targets: ValidatedTarget[]): AliasToTargets;
138
- _formatSearchResult(body: any, remaining?: number, searchInfo?: any): Promise<{
139
- aggregations: any;
143
+ _formatSearchResult(body: estypes.SearchResponse, remaining?: number, searchInfo?: {
144
+ collection?: string;
145
+ index?: string;
146
+ targets?: ValidatedTarget[];
147
+ }): Promise<{
148
+ aggregations: Record<string, estypes.AggregationsAggregate> | undefined;
140
149
  hits: {
141
150
  _id: string | undefined;
142
151
  _score: number | null | undefined;
143
152
  _source: unknown;
144
- collection: any;
153
+ collection: string | undefined;
145
154
  highlight: Record<string, string[]> | undefined;
146
- index: any;
147
- inner_hits: JSONObject | undefined;
155
+ index: string | undefined;
156
+ inner_hits: {
157
+ [k: string]: unknown[];
158
+ } | undefined;
148
159
  }[];
149
160
  remaining: number | undefined;
150
- scrollId: any;
151
- suggest: any;
152
- total: any;
161
+ scrollId: string | undefined;
162
+ suggest: Record<string, estypes.SearchSuggest<unknown>[]> | undefined;
163
+ total: number;
153
164
  }>;
154
165
  /**
155
166
  * Gets the document with given ID
@@ -346,7 +357,7 @@ export declare class ES8 {
346
357
  *
347
358
  * @returns {Promise.<{ _id, _version, _source }>}
348
359
  */
349
- deleteFields(index: string, collection: string, id: string, fields: string, { refresh, userId, }?: {
360
+ deleteFields(index: string, collection: string, id: string, fields: string[], { refresh, userId, }?: {
350
361
  refresh?: boolean | "wait_for";
351
362
  userId?: string | null;
352
363
  }): Promise<{
@@ -401,10 +412,10 @@ export declare class ES8 {
401
412
  *
402
413
  * @returns {Promise.<any[]>} Array of results returned by the callback
403
414
  */
404
- mExecute(index: string, collection: string, query: JSONObject, callback: any, { size, scrollTTl, }?: {
415
+ mExecute(index: string, collection: string, query: JSONObject, callback: (hits: estypes.SearchHit[]) => unknown, { size, scrollTTl, }?: {
405
416
  size?: number;
406
417
  scrollTTl?: string;
407
- }): Promise<any>;
418
+ }): Promise<unknown[]>;
408
419
  /**
409
420
  * Creates a new index.
410
421
  *
@@ -430,7 +441,7 @@ export declare class ES8 {
430
441
  */
431
442
  createCollection(index: string, collection: string, { mappings, settings, }?: {
432
443
  mappings?: estypes.MappingTypeMapping;
433
- settings?: Record<string, any>;
444
+ settings?: estypes.IndicesIndexSettings;
434
445
  }): Promise<null>;
435
446
  /**
436
447
  * Retrieves settings definition for index/type
@@ -469,7 +480,7 @@ export declare class ES8 {
469
480
  updateCollection(index: string, collection: string, { mappings, reindexCollection, settings, }?: {
470
481
  mappings?: estypes.MappingTypeMapping;
471
482
  reindexCollection?: boolean;
472
- settings?: Record<string, any>;
483
+ settings?: estypes.IndicesIndexSettings;
473
484
  }): Promise<null>;
474
485
  /**
475
486
  * Given index settings we return a new version of index settings
@@ -477,8 +488,8 @@ export declare class ES8 {
477
488
  * @param indexSettings the index settings
478
489
  * @returns {{index: *}} a new index settings with only allowed settings.
479
490
  */
480
- getAllowedIndexSettings(indexSettings: JSONObject): {
481
- index: _.Omit<any, "version" | "creation_date" | "provided_name" | "uuid">;
491
+ getAllowedIndexSettings(indexSettings: estypes.IndicesIndexSettings | undefined): {
492
+ index: _.Omit<estypes.IndicesIndexSettings, "version" | "creation_date" | "provided_name" | "uuid">;
482
493
  };
483
494
  /**
484
495
  * Sends an empty UpdateByQuery request to update the search index
@@ -594,7 +605,7 @@ export declare class ES8 {
594
605
  *
595
606
  * @returns {Promise.<String[]>}
596
607
  */
597
- deleteIndexes(indexes?: string[]): Promise<unknown[]>;
608
+ deleteIndexes(indexes?: string[]): Promise<string[]>;
598
609
  /**
599
610
  * Deletes an index
600
611
  *
@@ -677,7 +688,7 @@ export declare class ES8 {
677
688
  *
678
689
  * @returns {Promise.<Object>} { items, errors }
679
690
  */
680
- mCreate(index: string, collection: string, documents: JSON[], { refresh, timeout, userId, }?: {
691
+ mCreate(index: string, collection: string, documents: JSONObject[], { refresh, timeout, userId, }?: {
681
692
  refresh?: boolean | "wait_for";
682
693
  timeout?: string;
683
694
  userId?: string | null;
@@ -850,7 +861,7 @@ export declare class ES8 {
850
861
  * @return {Promise<*>} the settings of the indice.
851
862
  * @private
852
863
  */
853
- _getSettings(esRequest: estypes.IndicesGetSettingsRequest): Promise<any>;
864
+ _getSettings(esRequest: estypes.IndicesGetSettingsRequest): Promise<estypes.IndicesIndexSettings | undefined>;
854
865
  /**
855
866
  * Given index + collection, returns an available indice name.
856
867
  * Use this function when creating the associated indice. Otherwise use `_getAlias`.
@@ -35,13 +35,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
35
35
  }) : function(o, v) {
36
36
  o["default"] = v;
37
37
  });
38
- var __importStar = (this && this.__importStar) || function (mod) {
39
- if (mod && mod.__esModule) return mod;
40
- var result = {};
41
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
42
- __setModuleDefault(result, mod);
43
- return result;
44
- };
38
+ var __importStar = (this && this.__importStar) || (function () {
39
+ var ownKeys = function(o) {
40
+ ownKeys = Object.getOwnPropertyNames || function (o) {
41
+ var ar = [];
42
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
43
+ return ar;
44
+ };
45
+ return ownKeys(o);
46
+ };
47
+ return function (mod) {
48
+ if (mod && mod.__esModule) return mod;
49
+ var result = {};
50
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
51
+ __setModuleDefault(result, mod);
52
+ return result;
53
+ };
54
+ })();
45
55
  var __importDefault = (this && this.__importDefault) || function (mod) {
46
56
  return (mod && mod.__esModule) ? mod : { "default": mod };
47
57
  };
@@ -57,7 +67,7 @@ const storeScopeEnum_1 = require("../../../core/storage/storeScopeEnum");
57
67
  const kerror = __importStar(require("../../../kerror"));
58
68
  const didYouMean_1 = __importDefault(require("../../../util/didYouMean"));
59
69
  const extractFields_1 = __importDefault(require("../../../util/extractFields"));
60
- const mutex_1 = require("../../../util/mutex");
70
+ const distributedLock_1 = require("../../../util/distributedLock");
61
71
  const name_generator_1 = require("../../../util/name-generator");
62
72
  const requestAssertions_1 = require("../../../util/requestAssertions");
63
73
  const safeObject_1 = require("../../../util/safeObject");
@@ -73,6 +83,12 @@ const ROOT_MAPPING_PROPERTIES = [
73
83
  const CHILD_MAPPING_PROPERTIES = ["type"];
74
84
  // Used for collection emulation
75
85
  const HIDDEN_COLLECTION = "_kuzzle_keep";
86
+ // The hidden collection locks wait for as long as it takes, as the `Mutex`
87
+ // they replace did: they guard a collection creation, which must not fail
88
+ // only because another request on the same index got there first. The lock
89
+ // is refreshed while held, so a live holder is never overtaken; a crashed
90
+ // one leaves it for at most `ttl` (30 s).
91
+ const HIDDEN_COLLECTION_LOCK = { retryAttempts: Number.POSITIVE_INFINITY };
76
92
  const ALIAS_PREFIX = "@"; // @todo next major release: Add ALIAS_PREFIX in FORBIDDEN_CHARS
77
93
  const PRIVATE_PREFIX = "%";
78
94
  const PUBLIC_PREFIX = "&";
@@ -192,7 +208,7 @@ class ES8 {
192
208
  async info() {
193
209
  const result = {
194
210
  type: "elasticsearch",
195
- version: this._esVersion,
211
+ version: this._esVersion?.number ?? "",
196
212
  };
197
213
  try {
198
214
  const info = await this._client.info();
@@ -223,7 +239,6 @@ class ES8 {
223
239
  const indexes = {};
224
240
  let size = 0;
225
241
  for (const [indice, indiceInfo] of Object.entries(stats.indices ?? {})) {
226
- const infos = indiceInfo;
227
242
  // Ignore non-Kuzzle indices, and the ones Kuzzle must leave alone
228
243
  if ((!indice.startsWith(PRIVATE_PREFIX) &&
229
244
  !indice.startsWith(PUBLIC_PREFIX)) ||
@@ -243,13 +258,15 @@ class ES8 {
243
258
  name: indexName,
244
259
  size: 0,
245
260
  }));
261
+ // Both are there: the request asks for the `docs` and `store` metrics.
262
+ const sizeInBytes = indiceInfo.total?.store?.size_in_bytes ?? 0;
246
263
  indexStats.collections.push({
247
- documentCount: infos.total.docs.count,
264
+ documentCount: indiceInfo.total?.docs?.count ?? 0,
248
265
  name: collectionName,
249
- size: infos.total.store.size_in_bytes,
266
+ size: sizeInBytes,
250
267
  });
251
- indexStats.size += infos.total.store.size_in_bytes;
252
- size += infos.total.store.size_in_bytes;
268
+ indexStats.size += sizeInBytes;
269
+ size += sizeInBytes;
253
270
  }
254
271
  return {
255
272
  indexes: Object.values(indexes),
@@ -456,11 +473,11 @@ class ES8 {
456
473
  if (!innerHits) {
457
474
  return undefined;
458
475
  }
459
- const formattedInnerHits = {};
460
- for (const [name, innerHit] of Object.entries(innerHits)) {
461
- formattedInnerHits[name] = await bluebird_1.default.map(innerHit.hits.hits, formatHit);
462
- }
463
- return formattedInnerHits;
476
+ const formatted = await Promise.all(Object.entries(innerHits).map(async ([name, innerHit]) => [
477
+ name,
478
+ await bluebird_1.default.map(innerHit.hits.hits, formatHit),
479
+ ]));
480
+ return Object.fromEntries(formatted);
464
481
  }
465
482
  const hits = await bluebird_1.default.map(body.hits.hits, async (hit) => ({
466
483
  inner_hits: await formatInnerHits(hit.inner_hits),
@@ -472,7 +489,7 @@ class ES8 {
472
489
  remaining,
473
490
  scrollId: body._scroll_id,
474
491
  suggest: body.suggest,
475
- total: body.hits.total.value,
492
+ total: this._getHitsTotalValue(body.hits),
476
493
  };
477
494
  }
478
495
  /**
@@ -1139,19 +1156,6 @@ class ES8 {
1139
1156
  if (collection === HIDDEN_COLLECTION) {
1140
1157
  throw kerror.get("services", "storage", "collection_reserved", HIDDEN_COLLECTION);
1141
1158
  }
1142
- const mutex = new mutex_1.Mutex(`hiddenCollection/create/${index}`);
1143
- try {
1144
- await mutex.lock();
1145
- if (await this._hasHiddenCollection(index)) {
1146
- await this.deleteCollection(index, HIDDEN_COLLECTION);
1147
- }
1148
- }
1149
- catch (error) {
1150
- throw this._esWrapper.formatESError(error);
1151
- }
1152
- finally {
1153
- await mutex.unlock();
1154
- }
1155
1159
  const esRequest = {
1156
1160
  aliases: {
1157
1161
  [this._getAlias(index, collection)]: {},
@@ -1190,6 +1194,19 @@ class ES8 {
1190
1194
  }
1191
1195
  throw this._esWrapper.formatESError(error);
1192
1196
  }
1197
+ // Only once the real collection exists: dropping the placeholder first
1198
+ // would leave the index with no indice at all if the creation failed.
1199
+ // Lock and ES errors alike reach the caller through `formatESError`
1200
+ try {
1201
+ await (0, distributedLock_1.withLock)(`hiddenCollection/create/${index}`, async () => {
1202
+ if (await this._hasHiddenCollection(index)) {
1203
+ await this.deleteCollection(index, HIDDEN_COLLECTION);
1204
+ }
1205
+ }, HIDDEN_COLLECTION_LOCK);
1206
+ }
1207
+ catch (error) {
1208
+ throw this._esWrapper.formatESError(error);
1209
+ }
1193
1210
  return null;
1194
1211
  }
1195
1212
  /**
@@ -1302,7 +1319,7 @@ class ES8 {
1302
1319
  */
1303
1320
  getAllowedIndexSettings(indexSettings) {
1304
1321
  return {
1305
- index: lodash_1.default.omit(indexSettings.index, [
1322
+ index: lodash_1.default.omit(indexSettings?.index, [
1306
1323
  "creation_date",
1307
1324
  "provided_name",
1308
1325
  "uuid",
@@ -1651,7 +1668,11 @@ class ES8 {
1651
1668
  name: alias,
1652
1669
  });
1653
1670
  }
1654
- await this._createHiddenCollection(index);
1671
+ // `createCollection` drops the placeholder through here: recreating it
1672
+ // would undo that.
1673
+ if (collection !== HIDDEN_COLLECTION) {
1674
+ await this._createHiddenCollection(index);
1675
+ }
1655
1676
  }
1656
1677
  catch (e) {
1657
1678
  throw this._esWrapper.formatESError(e);
@@ -2666,31 +2687,28 @@ class ES8 {
2666
2687
  * @param {String} index Index name
2667
2688
  */
2668
2689
  async _createHiddenCollection(index) {
2669
- const mutex = new mutex_1.Mutex(`hiddenCollection/${index}`);
2670
2690
  try {
2671
- await mutex.lock();
2672
- if (await this._hasHiddenCollection(index)) {
2673
- return;
2674
- }
2675
- const esRequest = {
2676
- aliases: {
2677
- [this._getAlias(index, HIDDEN_COLLECTION)]: {},
2678
- },
2679
- index: await this._getAvailableIndice(index, HIDDEN_COLLECTION),
2680
- settings: {
2681
- number_of_replicas: this._config.defaultSettings.number_of_replicas,
2682
- number_of_shards: this._config.defaultSettings.number_of_shards,
2683
- },
2684
- wait_for_active_shards: await this._getWaitForActiveShards(),
2685
- };
2686
- await this._client.indices.create(esRequest);
2691
+ await (0, distributedLock_1.withLock)(`hiddenCollection/${index}`, async () => {
2692
+ if (await this._hasHiddenCollection(index)) {
2693
+ return;
2694
+ }
2695
+ const esRequest = {
2696
+ aliases: {
2697
+ [this._getAlias(index, HIDDEN_COLLECTION)]: {},
2698
+ },
2699
+ index: await this._getAvailableIndice(index, HIDDEN_COLLECTION),
2700
+ settings: {
2701
+ number_of_replicas: this._config.defaultSettings.number_of_replicas,
2702
+ number_of_shards: this._config.defaultSettings.number_of_shards,
2703
+ },
2704
+ wait_for_active_shards: await this._getWaitForActiveShards(),
2705
+ };
2706
+ await this._client.indices.create(esRequest);
2707
+ }, HIDDEN_COLLECTION_LOCK);
2687
2708
  }
2688
2709
  catch (e) {
2689
2710
  throw this._esWrapper.formatESError(e);
2690
2711
  }
2691
- finally {
2692
- await mutex.unlock();
2693
- }
2694
2712
  }
2695
2713
  /**
2696
2714
  * We need to always wait for a minimal number of shards to be available
@@ -1,10 +1,16 @@
1
+ import { Client as ClientES7 } from "sdk-es7";
2
+ import { Client as ClientES8 } from "sdk-es8";
3
+ import { ES7 } from "./7/elasticsearch";
4
+ import { ES8 } from "./8/elasticsearch";
1
5
  import Service from "../service";
2
6
  import { storeScopeEnum } from "../../core/storage/storeScopeEnum";
3
- export declare class Elasticsearch extends Service {
4
- client: any;
7
+ import type { JSONObject } from "../../types/JSONObject";
8
+ import type { StorageEngineElasticsearch } from "../../types/config/storageEngine/StorageEngineElasticsearchConfiguration";
9
+ export declare class Elasticsearch extends Service<StorageEngineElasticsearch> {
10
+ client: ES7 | ES8;
5
11
  private readonly logger;
6
- constructor(config: any, scope?: storeScopeEnum);
7
- static buildClient(config: any, version?: "7" | "8"): any;
12
+ constructor(config: StorageEngineElasticsearch, scope?: storeScopeEnum);
13
+ static buildClient(config: JSONObject, version?: "7" | "8"): ClientES7 | ClientES8;
8
14
  _initSequence(): Promise<void>;
9
15
  init(): Promise<void>;
10
16
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { Readable } from "stream";
3
2
  export type HttpStreamProperties = {
4
3
  totalBytes?: number;
@@ -35,13 +35,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
35
35
  }) : function(o, v) {
36
36
  o["default"] = v;
37
37
  });
38
- var __importStar = (this && this.__importStar) || function (mod) {
39
- if (mod && mod.__esModule) return mod;
40
- var result = {};
41
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
42
- __setModuleDefault(result, mod);
43
- return result;
44
- };
38
+ var __importStar = (this && this.__importStar) || (function () {
39
+ var ownKeys = function(o) {
40
+ ownKeys = Object.getOwnPropertyNames || function (o) {
41
+ var ar = [];
42
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
43
+ return ar;
44
+ };
45
+ return ownKeys(o);
46
+ };
47
+ return function (mod) {
48
+ if (mod && mod.__esModule) return mod;
49
+ var result = {};
50
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
51
+ __setModuleDefault(result, mod);
52
+ return result;
53
+ };
54
+ })();
45
55
  Object.defineProperty(exports, "__esModule", { value: true });
46
56
  exports.Plugin = void 0;
47
57
  const kerror = __importStar(require("../kerror"));
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { JSONObject } from "../JSONObject";
4
2
  import type { RoleDefinition, ProfileDefinition } from "../index";
5
3
  export type SecurityConfiguration = {
@@ -40,6 +40,11 @@ export type StorageEngineElasticsearch = {
40
40
  * @see https://www.elastic.co/guide/en/elasticsearch/reference/7.4/dynamic-mapping.html
41
41
  */
42
42
  commonMapping: {
43
+ /**
44
+ * Collection metadata applied to a new collection whose mappings carry
45
+ * none of their own. Not in the defaults.
46
+ */
47
+ _meta?: Record<string, unknown>;
43
48
  /**
44
49
  * @default "false"
45
50
  */
@@ -0,0 +1,5 @@
1
+ import type { User } from "../../model/security/user";
2
+ import type { Serialized } from "../core/auth/Serialized";
3
+ export type GetCurrentUserResponse = Serialized<User> & {
4
+ strategies: any;
5
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=GetCurrentUserResponse.js.map
@@ -0,0 +1,5 @@
1
+ export type ResetSecurityResult = {
2
+ deletedUsers?: (event: string, ...args: any[]) => Promise<any>;
3
+ deletedProfiles?: (event: string, ...args: any[]) => Promise<any>;
4
+ deletedRoles?: (event: string, ...args: any[]) => Promise<any>;
5
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ResetSecurityResult.js.map
@@ -1,5 +1,7 @@
1
- export type ResetSecurityResult = {
2
- deletedUsers?: (event: string, ...args: any[]) => Promise<any>;
3
- deletedProfiles?: (event: string, ...args: any[]) => Promise<any>;
4
- deletedRoles?: (event: string, ...args: any[]) => Promise<any>;
5
- };
1
+ /**
2
+ * @deprecated Moved to `./ResetSecurityResult` when `lib/types/` settled on
3
+ * PascalCase file names (TD-08). Kept so that deep imports of the published
4
+ * `dist/lib/...` path keep compiling; removed in v3
5
+ * (docs/v3-breaking-changes.md).
6
+ */
7
+ export type { ResetSecurityResult } from "./ResetSecurityResult";
@@ -1,5 +1,7 @@
1
- import type { User } from "../../model/security/user";
2
- import type { Serialized } from "../core/auth/formatProcessing.type";
3
- export type GetCurrentUserResponse = Serialized<User> & {
4
- strategies: any;
5
- };
1
+ /**
2
+ * @deprecated Moved to `./GetCurrentUserResponse` when `lib/types/` settled on
3
+ * PascalCase file names (TD-08). Kept so that deep imports of the published
4
+ * `dist/lib/...` path keep compiling; removed in v3
5
+ * (docs/v3-breaking-changes.md).
6
+ */
7
+ export type { GetCurrentUserResponse } from "./GetCurrentUserResponse";
@@ -0,0 +1,14 @@
1
+ import type { JSONObject } from "../../JSONObject";
2
+ /**
3
+ * What `formatProcessing` can serialize: anything carrying an id. The id is
4
+ * nullable because the security models are — they carry `null` until they have
5
+ * been stored (ADR-0001, TD-62) — and `Serialized` echoes back whichever it
6
+ * has rather than widening it for everyone.
7
+ */
8
+ export type Serializable = {
9
+ _id: string | null;
10
+ };
11
+ export type Serialized<T extends Serializable> = {
12
+ _id: T["_id"];
13
+ _source: JSONObject;
14
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Serialized.js.map
@@ -1,13 +1,7 @@
1
1
  /**
2
- * What `formatProcessing` can serialize: anything carrying an id. The id is
3
- * nullable because the security models are — they carry `null` until they have
4
- * been stored (ADR-0001, TD-62) — and `Serialized` echoes back whichever it
5
- * has rather than widening it for everyone.
2
+ * @deprecated Moved to `./Serialized` when `lib/types/` settled on PascalCase
3
+ * file names (TD-08). Kept so that deep imports of the published
4
+ * `dist/lib/...` path keep compiling; removed in v3
5
+ * (docs/v3-breaking-changes.md).
6
6
  */
7
- export type Serializable = {
8
- _id: string | null;
9
- };
10
- export type Serialized<T extends Serializable> = {
11
- _id: T["_id"];
12
- _source: Record<string, any>;
13
- };
7
+ export type { Serializable, Serialized } from "./Serialized";
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { JSONObject } from "../JSONObject";
4
2
  import type { PipeEventHandler } from "../../../index";
5
3
  import type { ClientConnection } from "../ClientConnection";
@@ -9,6 +9,7 @@ export * from "./Global";
9
9
  export * from "./HttpMessage";
10
10
  export * from "./HttpStream";
11
11
  export * from "./JSONObject";
12
+ export * from "./Kuzzle";
12
13
  export * from "./KuzzleDocument";
13
14
  export * from "./OpenApiDefinition";
14
15
  export * from "./PasswordPolicy";
@@ -45,6 +45,7 @@ __exportStar(require("./Global"), exports);
45
45
  __exportStar(require("./HttpMessage"), exports);
46
46
  __exportStar(require("./HttpStream"), exports);
47
47
  __exportStar(require("./JSONObject"), exports);
48
+ __exportStar(require("./Kuzzle"), exports);
48
49
  __exportStar(require("./KuzzleDocument"), exports);
49
50
  __exportStar(require("./OpenApiDefinition"), exports);
50
51
  __exportStar(require("./PasswordPolicy"), exports);