kuzzle 2.56.0 → 2.57.0-beta.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.
Files changed (408) hide show
  1. package/dist/bin/copy-binaries.js +71 -4
  2. package/dist/bin/start-kuzzle-server +191 -97
  3. package/dist/index.d.ts +31 -1
  4. package/dist/index.js +45 -2
  5. package/dist/lib/api/controllers/adminController.d.ts +4 -3
  6. package/dist/lib/api/controllers/adminController.js +1 -2
  7. package/dist/lib/api/controllers/authController.d.ts +37 -16
  8. package/dist/lib/api/controllers/authController.js +88 -39
  9. package/dist/lib/api/controllers/baseController.d.ts +10 -5
  10. package/dist/lib/api/controllers/baseController.js +36 -15
  11. package/dist/lib/api/controllers/bulkController.d.ts +11 -7
  12. package/dist/lib/api/controllers/bulkController.js +28 -5
  13. package/dist/lib/api/controllers/clusterController.d.ts +2 -2
  14. package/dist/lib/api/controllers/clusterController.js +3 -3
  15. package/dist/lib/api/controllers/collectionController.d.ts +57 -21
  16. package/dist/lib/api/controllers/collectionController.js +40 -11
  17. package/dist/lib/api/controllers/debugController.d.ts +1 -1
  18. package/dist/lib/api/controllers/documentController.d.ts +137 -28
  19. package/dist/lib/api/controllers/documentController.js +156 -125
  20. package/dist/lib/api/controllers/index.d.ts +27 -12
  21. package/dist/lib/api/controllers/index.js +28 -13
  22. package/dist/lib/api/controllers/indexController.d.ts +17 -10
  23. package/dist/lib/api/controllers/indexController.js +13 -11
  24. package/dist/lib/api/controllers/memoryStorageController.d.ts +2 -5
  25. package/dist/lib/api/controllers/memoryStorageController.js +199 -127
  26. package/dist/lib/api/controllers/realtimeController.d.ts +19 -9
  27. package/dist/lib/api/controllers/realtimeController.js +8 -4
  28. package/dist/lib/api/controllers/securityController.d.ts +42 -29
  29. package/dist/lib/api/controllers/securityController.js +35 -19
  30. package/dist/lib/api/controllers/serverController.d.ts +114 -19
  31. package/dist/lib/api/controllers/serverController.js +69 -29
  32. package/dist/lib/api/documentExtractor.d.ts +9 -7
  33. package/dist/lib/api/documentExtractor.js +105 -41
  34. package/dist/lib/api/funnel.d.ts +131 -29
  35. package/dist/lib/api/funnel.js +436 -225
  36. package/dist/lib/api/httpRoutes.d.ts +16 -11
  37. package/dist/lib/api/httpRoutes.js +272 -2
  38. package/dist/lib/api/openapi/OpenApiManager.d.ts +1 -1
  39. package/dist/lib/api/openapi/openApiGenerator.d.ts +1 -1
  40. package/dist/lib/api/rateLimiter.d.ts +15 -5
  41. package/dist/lib/api/rateLimiter.js +42 -14
  42. package/dist/lib/api/request/kuzzleRequest.d.ts +83 -12
  43. package/dist/lib/api/request/kuzzleRequest.js +88 -23
  44. package/dist/lib/api/request/requestContext.d.ts +20 -5
  45. package/dist/lib/api/request/requestContext.js +14 -4
  46. package/dist/lib/api/request/requestInput.d.ts +37 -6
  47. package/dist/lib/api/request/requestInput.js +22 -9
  48. package/dist/lib/api/request/requestResponse.d.ts +45 -9
  49. package/dist/lib/api/request/requestResponse.js +34 -3
  50. package/dist/lib/cluster/command.d.ts +131 -37
  51. package/dist/lib/cluster/command.js +243 -71
  52. package/dist/lib/cluster/idCardHandler.d.ts +18 -5
  53. package/dist/lib/cluster/idCardHandler.js +52 -19
  54. package/dist/lib/cluster/index.d.ts +8 -2
  55. package/dist/lib/cluster/index.js +6 -2
  56. package/dist/lib/cluster/node.d.ts +127 -49
  57. package/dist/lib/cluster/node.js +412 -179
  58. package/dist/lib/cluster/protobuf/command.proto +18 -0
  59. package/dist/lib/cluster/protobuf/commandMessages.d.ts +104 -0
  60. package/dist/lib/cluster/protobuf/commandMessages.js +30 -0
  61. package/dist/lib/cluster/protobuf/syncMessages.d.ts +184 -0
  62. package/dist/lib/cluster/protobuf/syncMessages.js +23 -0
  63. package/dist/lib/cluster/publisher.d.ts +118 -78
  64. package/dist/lib/cluster/publisher.js +174 -72
  65. package/dist/lib/cluster/state.d.ts +15 -9
  66. package/dist/lib/cluster/state.js +12 -8
  67. package/dist/lib/cluster/subscriber.d.ts +185 -131
  68. package/dist/lib/cluster/subscriber.js +357 -95
  69. package/dist/lib/cluster/workers/IDCardRenewer.d.ts +39 -8
  70. package/dist/lib/cluster/workers/IDCardRenewer.js +88 -23
  71. package/dist/lib/config/default.config.d.ts +2 -2
  72. package/dist/lib/config/default.config.js +10 -3
  73. package/dist/lib/config/documentEventAliases.d.ts +1 -1
  74. package/dist/lib/config/index.d.ts +2 -5
  75. package/dist/lib/config/index.js +30 -17
  76. package/dist/lib/core/auth/formatProcessing.d.ts +3 -3
  77. package/dist/lib/core/auth/passportResponse.d.ts +1 -1
  78. package/dist/lib/core/auth/passportWrapper.d.ts +1 -1
  79. package/dist/lib/core/auth/passportWrapper.js +14 -13
  80. package/dist/lib/core/auth/tokenManager.d.ts +24 -3
  81. package/dist/lib/core/auth/tokenManager.js +47 -19
  82. package/dist/lib/core/backend/applicationManager.d.ts +2 -2
  83. package/dist/lib/core/backend/backend.d.ts +16 -5
  84. package/dist/lib/core/backend/backend.js +14 -6
  85. package/dist/lib/core/backend/backendCluster.d.ts +1 -1
  86. package/dist/lib/core/backend/backendConfig.d.ts +17 -5
  87. package/dist/lib/core/backend/backendConfig.js +1 -0
  88. package/dist/lib/core/backend/backendController.d.ts +1 -1
  89. package/dist/lib/core/backend/backendController.js +8 -1
  90. package/dist/lib/core/backend/backendErrors.d.ts +15 -8
  91. package/dist/lib/core/backend/backendErrors.js +5 -0
  92. package/dist/lib/core/backend/backendHook.d.ts +1 -1
  93. package/dist/lib/core/backend/backendImport.d.ts +1 -1
  94. package/dist/lib/core/backend/backendOpenApi.d.ts +3 -2
  95. package/dist/lib/core/backend/backendPipe.d.ts +1 -1
  96. package/dist/lib/core/backend/backendPipe.js +9 -1
  97. package/dist/lib/core/backend/backendPlugin.d.ts +2 -2
  98. package/dist/lib/core/backend/backendSubscription.d.ts +2 -2
  99. package/dist/lib/core/backend/backendVault.d.ts +1 -1
  100. package/dist/lib/core/backend/backendVault.js +8 -1
  101. package/dist/lib/core/cache/cacheEngine.d.ts +7 -4
  102. package/dist/lib/core/cache/cacheEngine.js +25 -8
  103. package/dist/lib/core/debug/kuzzleDebugger.d.ts +2 -1
  104. package/dist/lib/core/debug/kuzzleDebugger.js +31 -17
  105. package/dist/lib/core/network/accessLogger.d.ts +33 -18
  106. package/dist/lib/core/network/accessLogger.js +135 -73
  107. package/dist/lib/core/network/clientConnection.d.ts +13 -11
  108. package/dist/lib/core/network/clientConnection.js +33 -9
  109. package/dist/lib/core/network/context.d.ts +17 -22
  110. package/dist/lib/core/network/context.js +43 -26
  111. package/dist/lib/core/network/entryPoint.d.ts +38 -16
  112. package/dist/lib/core/network/entryPoint.js +119 -48
  113. package/dist/lib/core/network/httpRouter/index.d.ts +20 -50
  114. package/dist/lib/core/network/httpRouter/index.js +61 -75
  115. package/dist/lib/core/network/httpRouter/routeHandler.d.ts +17 -32
  116. package/dist/lib/core/network/httpRouter/routeHandler.js +26 -36
  117. package/dist/lib/core/network/httpRouter/routePart.d.ts +9 -18
  118. package/dist/lib/core/network/httpRouter/routePart.js +61 -43
  119. package/dist/lib/core/network/httpRouter/routeTypes.d.ts +3 -0
  120. package/dist/lib/core/network/httpRouter/routeTypes.js +23 -0
  121. package/dist/lib/core/network/networkEntryPoint.d.ts +20 -0
  122. package/dist/lib/core/network/networkEntryPoint.js +23 -0
  123. package/dist/lib/core/network/protocolManifest.d.ts +5 -4
  124. package/dist/lib/core/network/protocolManifest.js +6 -3
  125. package/dist/lib/core/network/protocols/httpMessage.d.ts +25 -18
  126. package/dist/lib/core/network/protocols/httpMessage.js +14 -11
  127. package/dist/lib/core/network/protocols/httpwsProtocol.d.ts +84 -93
  128. package/dist/lib/core/network/protocols/httpwsProtocol.js +284 -129
  129. package/dist/lib/core/network/protocols/internalProtocol.d.ts +26 -15
  130. package/dist/lib/core/network/protocols/internalProtocol.js +17 -16
  131. package/dist/lib/core/network/protocols/mqttProtocol.d.ts +56 -32
  132. package/dist/lib/core/network/protocols/mqttProtocol.js +91 -44
  133. package/dist/lib/core/network/protocols/protocol.d.ts +85 -21
  134. package/dist/lib/core/network/protocols/protocol.js +83 -27
  135. package/dist/lib/core/network/router.d.ts +13 -22
  136. package/dist/lib/core/network/router.js +59 -46
  137. package/dist/lib/core/plugin/plugin.d.ts +57 -51
  138. package/dist/lib/core/plugin/plugin.js +218 -103
  139. package/dist/lib/core/plugin/pluginContext.d.ts +54 -11
  140. package/dist/lib/core/plugin/pluginContext.js +99 -58
  141. package/dist/lib/core/plugin/pluginManifest.d.ts +6 -2
  142. package/dist/lib/core/plugin/pluginManifest.js +18 -11
  143. package/dist/lib/core/plugin/pluginRepository.d.ts +35 -44
  144. package/dist/lib/core/plugin/pluginRepository.js +35 -50
  145. package/dist/lib/core/plugin/pluginsManager.d.ts +128 -46
  146. package/dist/lib/core/plugin/pluginsManager.js +468 -231
  147. package/dist/lib/core/plugin/privilegedContext.d.ts +4 -9
  148. package/dist/lib/core/plugin/privilegedContext.js +5 -10
  149. package/dist/lib/core/realtime/actionEnum.d.ts +12 -21
  150. package/dist/lib/core/realtime/actionEnum.js +6 -7
  151. package/dist/lib/core/realtime/channel.d.ts +11 -5
  152. package/dist/lib/core/realtime/channel.js +17 -2
  153. package/dist/lib/core/realtime/connectionRooms.d.ts +2 -2
  154. package/dist/lib/core/realtime/hotelClerk.d.ts +12 -6
  155. package/dist/lib/core/realtime/hotelClerk.js +29 -11
  156. package/dist/lib/core/realtime/index.d.ts +8 -3
  157. package/dist/lib/core/realtime/index.js +12 -5
  158. package/dist/lib/core/realtime/notification/document.d.ts +54 -25
  159. package/dist/lib/core/realtime/notification/document.js +10 -13
  160. package/dist/lib/core/realtime/notification/index.d.ts +9 -3
  161. package/dist/lib/core/realtime/notification/index.js +10 -4
  162. package/dist/lib/core/realtime/notification/server.d.ts +7 -10
  163. package/dist/lib/core/realtime/notification/server.js +4 -7
  164. package/dist/lib/core/realtime/notification/user.d.ts +45 -21
  165. package/dist/lib/core/realtime/notification/user.js +8 -9
  166. package/dist/lib/core/realtime/notifier.d.ts +52 -40
  167. package/dist/lib/core/realtime/notifier.js +60 -25
  168. package/dist/lib/core/realtime/room.d.ts +1 -1
  169. package/dist/lib/core/realtime/subscription.d.ts +11 -6
  170. package/dist/lib/core/realtime/subscription.js +5 -1
  171. package/dist/lib/core/security/index.d.ts +14 -6
  172. package/dist/lib/core/security/index.js +27 -13
  173. package/dist/lib/core/security/profileRepository.d.ts +24 -19
  174. package/dist/lib/core/security/profileRepository.js +23 -10
  175. package/dist/lib/core/security/roleRepository.d.ts +60 -23
  176. package/dist/lib/core/security/roleRepository.js +122 -53
  177. package/dist/lib/core/security/securityLoader.d.ts +33 -18
  178. package/dist/lib/core/security/securityLoader.js +43 -16
  179. package/dist/lib/core/security/tokenRepository.d.ts +21 -7
  180. package/dist/lib/core/security/tokenRepository.js +50 -23
  181. package/dist/lib/core/security/userRepository.d.ts +44 -21
  182. package/dist/lib/core/security/userRepository.js +59 -19
  183. package/dist/lib/core/shared/KoncordeWrapper.d.ts +1 -1
  184. package/dist/lib/core/shared/ObjectRepository.d.ts +80 -18
  185. package/dist/lib/core/shared/ObjectRepository.js +57 -29
  186. package/dist/lib/core/shared/abstractManifest.d.ts +21 -8
  187. package/dist/lib/core/shared/abstractManifest.js +57 -17
  188. package/dist/lib/core/shared/sdk/embeddedSdk.d.ts +3 -1
  189. package/dist/lib/core/shared/sdk/embeddedSdk.js +8 -7
  190. package/dist/lib/core/shared/sdk/funnelProtocol.d.ts +2 -1
  191. package/dist/lib/core/shared/sdk/funnelProtocol.js +12 -3
  192. package/dist/lib/core/shared/sdk/impersonatedSdk.d.ts +11 -5
  193. package/dist/lib/core/shared/sdk/impersonatedSdk.js +22 -9
  194. package/dist/lib/core/shared/store.d.ts +45 -29
  195. package/dist/lib/core/shared/store.js +48 -27
  196. package/dist/lib/core/statistics/statistics.d.ts +1 -1
  197. package/dist/lib/core/storage/clientAdapter.d.ts +39 -21
  198. package/dist/lib/core/storage/clientAdapter.js +88 -48
  199. package/dist/lib/core/storage/indexCache.d.ts +8 -0
  200. package/dist/lib/core/storage/indexCache.js +16 -7
  201. package/dist/lib/core/storage/storageEngine.d.ts +7 -6
  202. package/dist/lib/core/storage/storageEngine.js +11 -8
  203. package/dist/lib/core/validation/baseType.d.ts +22 -22
  204. package/dist/lib/core/validation/baseType.js +11 -26
  205. package/dist/lib/core/validation/specification.d.ts +148 -0
  206. package/dist/lib/core/validation/specification.js +34 -0
  207. package/dist/lib/core/validation/typeOptions.d.ts +62 -0
  208. package/dist/lib/core/validation/typeOptions.js +23 -0
  209. package/dist/lib/core/validation/types/anything.d.ts +3 -6
  210. package/dist/lib/core/validation/types/anything.js +7 -7
  211. package/dist/lib/core/validation/types/boolean.d.ts +5 -12
  212. package/dist/lib/core/validation/types/boolean.js +7 -12
  213. package/dist/lib/core/validation/types/date.d.ts +19 -11
  214. package/dist/lib/core/validation/types/date.js +212 -161
  215. package/dist/lib/core/validation/types/email.d.ts +7 -11
  216. package/dist/lib/core/validation/types/email.js +13 -17
  217. package/dist/lib/core/validation/types/enum.d.ts +7 -11
  218. package/dist/lib/core/validation/types/enum.js +39 -20
  219. package/dist/lib/core/validation/types/geoPoint.d.ts +5 -13
  220. package/dist/lib/core/validation/types/geoPoint.js +10 -15
  221. package/dist/lib/core/validation/types/geoShape.d.ts +22 -21
  222. package/dist/lib/core/validation/types/geoShape.js +113 -129
  223. package/dist/lib/core/validation/types/geoShapeUtils.d.ts +15 -0
  224. package/dist/lib/core/validation/types/geoShapeUtils.js +75 -0
  225. package/dist/lib/core/validation/types/integer.d.ts +7 -5
  226. package/dist/lib/core/validation/types/integer.js +7 -13
  227. package/dist/lib/core/validation/types/ipAddress.d.ts +7 -11
  228. package/dist/lib/core/validation/types/ipAddress.js +13 -17
  229. package/dist/lib/core/validation/types/numeric.d.ts +7 -11
  230. package/dist/lib/core/validation/types/numeric.js +22 -29
  231. package/dist/lib/core/validation/types/object.d.ts +8 -15
  232. package/dist/lib/core/validation/types/object.js +12 -21
  233. package/dist/lib/core/validation/types/string.d.ts +7 -11
  234. package/dist/lib/core/validation/types/string.js +22 -29
  235. package/dist/lib/core/validation/types/url.d.ts +7 -11
  236. package/dist/lib/core/validation/types/url.js +14 -18
  237. package/dist/lib/core/validation/validation.d.ts +119 -80
  238. package/dist/lib/core/validation/validation.js +470 -412
  239. package/dist/lib/core/validation/validationUtils.d.ts +31 -0
  240. package/dist/lib/core/validation/validationUtils.js +190 -0
  241. package/dist/lib/kerror/codes/4-plugin.json +0 -12
  242. package/dist/lib/kerror/codes/index.d.ts +12 -2
  243. package/dist/lib/kerror/codes/index.js +5 -4
  244. package/dist/lib/kerror/errors/badRequestError.d.ts +1 -1
  245. package/dist/lib/kerror/errors/badRequestError.js +1 -1
  246. package/dist/lib/kerror/errors/externalServiceError.d.ts +1 -1
  247. package/dist/lib/kerror/errors/externalServiceError.js +1 -1
  248. package/dist/lib/kerror/errors/forbiddenError.d.ts +1 -1
  249. package/dist/lib/kerror/errors/forbiddenError.js +1 -1
  250. package/dist/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
  251. package/dist/lib/kerror/errors/gatewayTimeoutError.js +1 -1
  252. package/dist/lib/kerror/errors/internalError.d.ts +1 -1
  253. package/dist/lib/kerror/errors/internalError.js +1 -1
  254. package/dist/lib/kerror/errors/kuzzleError.d.ts +32 -3
  255. package/dist/lib/kerror/errors/kuzzleError.js +21 -7
  256. package/dist/lib/kerror/errors/multipleErrorsError.d.ts +2 -2
  257. package/dist/lib/kerror/errors/multipleErrorsError.js +2 -2
  258. package/dist/lib/kerror/errors/notFoundError.d.ts +1 -1
  259. package/dist/lib/kerror/errors/notFoundError.js +1 -1
  260. package/dist/lib/kerror/errors/partialError.d.ts +8 -2
  261. package/dist/lib/kerror/errors/partialError.js +22 -9
  262. package/dist/lib/kerror/errors/pluginImplementationError.d.ts +9 -1
  263. package/dist/lib/kerror/errors/pluginImplementationError.js +9 -3
  264. package/dist/lib/kerror/errors/preconditionError.d.ts +1 -1
  265. package/dist/lib/kerror/errors/preconditionError.js +1 -1
  266. package/dist/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
  267. package/dist/lib/kerror/errors/serviceUnavailableError.js +1 -1
  268. package/dist/lib/kerror/errors/sizeLimitError.d.ts +1 -1
  269. package/dist/lib/kerror/errors/sizeLimitError.js +1 -1
  270. package/dist/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
  271. package/dist/lib/kerror/errors/tooManyRequestsError.js +1 -1
  272. package/dist/lib/kerror/errors/unauthorizedError.d.ts +1 -1
  273. package/dist/lib/kerror/errors/unauthorizedError.js +1 -1
  274. package/dist/lib/kerror/index.d.ts +19 -13
  275. package/dist/lib/kerror/index.js +60 -19
  276. package/dist/lib/kuzzle/Logger.d.ts +2 -2
  277. package/dist/lib/kuzzle/dumpGenerator.d.ts +12 -8
  278. package/dist/lib/kuzzle/dumpGenerator.js +130 -62
  279. package/dist/lib/kuzzle/event/KuzzleEventEmitter.d.ts +18 -9
  280. package/dist/lib/kuzzle/event/KuzzleEventEmitter.js +45 -18
  281. package/dist/lib/kuzzle/event/pipeRunner.d.ts +37 -16
  282. package/dist/lib/kuzzle/event/pipeRunner.js +73 -26
  283. package/dist/lib/kuzzle/event/waterfall.d.ts +11 -1
  284. package/dist/lib/kuzzle/event/waterfall.js +38 -13
  285. package/dist/lib/kuzzle/internalIndexHandler.d.ts +11 -174
  286. package/dist/lib/kuzzle/internalIndexHandler.js +58 -29
  287. package/dist/lib/kuzzle/kuzzle.d.ts +25 -10
  288. package/dist/lib/kuzzle/kuzzle.js +74 -17
  289. package/dist/lib/kuzzle/kuzzleStateEnum.d.ts +16 -12
  290. package/dist/lib/kuzzle/kuzzleStateEnum.js +5 -7
  291. package/dist/lib/kuzzle/vault.d.ts +5 -1
  292. package/dist/lib/kuzzle/vault.js +29 -17
  293. package/dist/lib/model/security/profile.d.ts +34 -5
  294. package/dist/lib/model/security/profile.js +6 -5
  295. package/dist/lib/model/security/rights.d.ts +12 -4
  296. package/dist/lib/model/security/rights.js +7 -6
  297. package/dist/lib/model/security/role.d.ts +8 -4
  298. package/dist/lib/model/security/role.js +12 -6
  299. package/dist/lib/model/security/token.d.ts +8 -0
  300. package/dist/lib/model/security/user.d.ts +8 -2
  301. package/dist/lib/model/security/user.js +7 -4
  302. package/dist/lib/model/storage/apiKey.d.ts +55 -26
  303. package/dist/lib/model/storage/apiKey.js +97 -24
  304. package/dist/lib/model/storage/baseModel.d.ts +77 -66
  305. package/dist/lib/model/storage/baseModel.js +21 -34
  306. package/dist/lib/service/cache/redis.d.ts +53 -36
  307. package/dist/lib/service/cache/redis.js +148 -71
  308. package/dist/lib/service/service.d.ts +14 -19
  309. package/dist/lib/service/service.js +41 -22
  310. package/dist/lib/service/storage/7/elasticsearch.d.ts +136 -93
  311. package/dist/lib/service/storage/7/elasticsearch.js +218 -165
  312. package/dist/lib/service/storage/7/esWrapper.d.ts +30 -13
  313. package/dist/lib/service/storage/7/esWrapper.js +58 -37
  314. package/dist/lib/service/storage/8/elasticsearch.d.ts +153 -119
  315. package/dist/lib/service/storage/8/elasticsearch.js +286 -213
  316. package/dist/lib/service/storage/8/esWrapper.d.ts +30 -13
  317. package/dist/lib/service/storage/8/esWrapper.js +59 -38
  318. package/dist/lib/service/storage/commons/queryTranslator.d.ts +3 -3
  319. package/dist/lib/service/storage/commons/queryTranslator.js +71 -35
  320. package/dist/lib/types/ApiRoute.d.ts +12 -0
  321. package/dist/lib/types/ApiRoute.js +23 -0
  322. package/dist/lib/types/ClientConnection.d.ts +1 -1
  323. package/dist/lib/types/EventHandler.d.ts +10 -0
  324. package/dist/lib/types/Global.d.ts +8 -3
  325. package/dist/lib/types/HttpMessage.d.ts +2 -2
  326. package/dist/lib/types/HttpStream.d.ts +1 -1
  327. package/dist/lib/types/HttpStream.js +3 -1
  328. package/dist/lib/types/JSONObject.d.ts +9 -0
  329. package/dist/lib/types/JSONObject.js +23 -0
  330. package/dist/lib/types/Kuzzle.d.ts +5 -3
  331. package/dist/lib/types/KuzzleDocument.d.ts +1 -1
  332. package/dist/lib/types/KuzzleWebSocket.d.ts +24 -0
  333. package/dist/lib/types/KuzzleWebSocket.js +23 -0
  334. package/dist/lib/types/OpenApiDefinition.d.ts +1 -1
  335. package/dist/lib/types/Plugin.d.ts +33 -8
  336. package/dist/lib/types/PluginInstance.d.ts +67 -0
  337. package/dist/lib/types/PluginInstance.js +23 -0
  338. package/dist/lib/types/Policy.d.ts +1 -1
  339. package/dist/lib/types/Target.d.ts +8 -0
  340. package/dist/lib/types/Token.d.ts +14 -2
  341. package/dist/lib/types/config/HttpConfiguration.d.ts +5 -0
  342. package/dist/lib/types/config/KuzzleConfiguration.d.ts +102 -1
  343. package/dist/lib/types/config/PluginsConfiguration.d.ts +3 -2
  344. package/dist/lib/types/config/SecurityConfiguration.d.ts +6 -2
  345. package/dist/lib/types/config/ServerConfiguration.d.ts +2 -2
  346. package/dist/lib/types/config/ServicesConfiguration.d.ts +1 -1
  347. package/dist/lib/types/config/cache/BaseCacheRedisConfiguration.d.ts +131 -0
  348. package/dist/lib/types/config/cache/BaseCacheRedisConfiguration.js +3 -0
  349. package/dist/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +2 -106
  350. package/dist/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +2 -26
  351. package/dist/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +3 -0
  352. package/dist/lib/types/controllers/Controller.d.ts +12 -3
  353. package/dist/lib/types/controllers/ControllerDefinition.d.ts +2 -2
  354. package/dist/lib/types/controllers/{adminControlller.type.js → adminController.type.js} +1 -1
  355. package/dist/lib/types/controllers/authController.type.d.ts +2 -2
  356. package/dist/lib/types/core/auth/formatProcessing.type.d.ts +7 -1
  357. package/dist/lib/types/errors/ErrorDomains.d.ts +1 -1
  358. package/dist/lib/types/events/EventGenericDocument.d.ts +10 -9
  359. package/dist/lib/types/events/EventProtocol.d.ts +4 -4
  360. package/dist/lib/types/index.d.ts +7 -0
  361. package/dist/lib/types/index.js +7 -0
  362. package/dist/lib/types/shared/StoreCollectionsDefinition.d.ts +1 -1
  363. package/dist/lib/types/storage/7/Elasticsearch.d.ts +62 -13
  364. package/dist/lib/types/storage/8/Elasticsearch.d.ts +62 -13
  365. package/dist/lib/util/Inflector.d.ts +4 -1
  366. package/dist/lib/util/Inflector.js +0 -3
  367. package/dist/lib/util/assertType.d.ts +24 -27
  368. package/dist/lib/util/assertType.js +28 -39
  369. package/dist/lib/util/async.js +19 -6
  370. package/dist/lib/util/asyncStore.js +1 -1
  371. package/dist/lib/util/bufferedPassThrough.d.ts +9 -0
  372. package/dist/lib/util/bufferedPassThrough.js +27 -13
  373. package/dist/lib/util/bytes.d.ts +1 -1
  374. package/dist/lib/util/bytes.js +6 -2
  375. package/dist/lib/util/debug.d.ts +3 -1
  376. package/dist/lib/util/debug.js +42 -10
  377. package/dist/lib/util/deprecate.d.ts +9 -1
  378. package/dist/lib/util/deprecate.js +10 -6
  379. package/dist/lib/util/didYouMean.d.ts +2 -1
  380. package/dist/lib/util/didYouMean.js +8 -4
  381. package/dist/lib/util/distributedLock.d.ts +56 -0
  382. package/dist/lib/util/distributedLock.js +166 -0
  383. package/dist/lib/util/dump-collection.d.ts +1 -1
  384. package/dist/lib/util/dump-collection.js +4 -5
  385. package/dist/lib/util/extractFields.d.ts +15 -11
  386. package/dist/lib/util/extractFields.js +8 -9
  387. package/dist/lib/util/koncordeCompat.d.ts +2 -2
  388. package/dist/lib/util/koncordeCompat.js +33 -0
  389. package/dist/lib/util/memoize.d.ts +7 -6
  390. package/dist/lib/util/memoize.js +3 -3
  391. package/dist/lib/util/mutex.d.ts +22 -2
  392. package/dist/lib/util/mutex.js +39 -1
  393. package/dist/lib/util/name-generator.js +14 -2
  394. package/dist/lib/util/promback.d.ts +20 -11
  395. package/dist/lib/util/promback.js +14 -7
  396. package/dist/lib/util/requestAssertions.d.ts +30 -10
  397. package/dist/lib/util/requestAssertions.js +125 -121
  398. package/dist/lib/util/safeObject.d.ts +3 -3
  399. package/dist/lib/util/safeObject.js +7 -3
  400. package/dist/lib/util/stackTrace.d.ts +13 -5
  401. package/dist/lib/util/stackTrace.js +17 -12
  402. package/dist/lib/util/thrown.d.ts +13 -0
  403. package/dist/lib/util/thrown.js +46 -0
  404. package/dist/package.json +24 -17
  405. package/package.json +24 -17
  406. package/dist/lib/util/wildcard.d.ts +0 -1
  407. package/dist/lib/util/wildcard.js +0 -46
  408. /package/dist/lib/types/controllers/{adminControlller.type.d.ts → adminController.type.d.ts} +0 -0
@@ -102,8 +102,6 @@ class ES8 {
102
102
  this._scope = scope;
103
103
  this._indexPrefix =
104
104
  scope === storeScopeEnum_1.storeScopeEnum.PRIVATE ? PRIVATE_PREFIX : PUBLIC_PREFIX;
105
- this._client = null;
106
- this._esWrapper = null;
107
105
  this._esVersion = null;
108
106
  this._translator = new queryTranslator_1.QueryTranslator();
109
107
  // Allowed root key of a search query
@@ -160,9 +158,11 @@ class ES8 {
160
158
  await this.waitForElasticsearch();
161
159
  this._esWrapper = new esWrapper_1.default(this._client);
162
160
  const { version } = await this._client.info();
163
- if (version &&
164
- !semver_1.default.satisfies(semver_1.default.coerce(version.number), ">=8.0.0")) {
165
- throw kerror.get("services", "storage", "version_mismatch", version.number);
161
+ if (version) {
162
+ const coerced = semver_1.default.coerce(version.number);
163
+ if (coerced === null || !semver_1.default.satisfies(coerced, ">=8.0.0")) {
164
+ throw kerror.get("services", "storage", "version_mismatch", version.number);
165
+ }
166
166
  }
167
167
  this._esVersion = version;
168
168
  }
@@ -213,7 +213,7 @@ class ES8 {
213
213
  const stats = await this._client.indices.stats(esRequest);
214
214
  const indexes = {};
215
215
  let size = 0;
216
- for (const [indice, indiceInfo] of Object.entries(stats.indices)) {
216
+ for (const [indice, indiceInfo] of Object.entries(stats.indices ?? {})) {
217
217
  const infos = indiceInfo;
218
218
  // Ignore non-Kuzzle indices
219
219
  if (!indice.startsWith(PRIVATE_PREFIX) &&
@@ -228,19 +228,17 @@ class ES8 {
228
228
  collectionName === HIDDEN_COLLECTION) {
229
229
  continue;
230
230
  }
231
- if (!indexes[indexName]) {
232
- indexes[indexName] = {
233
- collections: [],
234
- name: indexName,
235
- size: 0,
236
- };
237
- }
238
- indexes[indexName].collections.push({
231
+ const indexStats = (indexes[indexName] ?? (indexes[indexName] = {
232
+ collections: [],
233
+ name: indexName,
234
+ size: 0,
235
+ }));
236
+ indexStats.collections.push({
239
237
  documentCount: infos.total.docs.count,
240
238
  name: collectionName,
241
239
  size: infos.total.store.size_in_bytes,
242
240
  });
243
- indexes[indexName].size += infos.total.store.size_in_bytes;
241
+ indexStats.size += infos.total.store.size_in_bytes;
244
242
  size += infos.total.store.size_in_bytes;
245
243
  }
246
244
  return {
@@ -267,7 +265,7 @@ class ES8 {
267
265
  const cacheKey = SCROLL_CACHE_PREFIX + global.kuzzle.hash(esRequest.scroll_id);
268
266
  this.logger.debug("Scroll: %o", esRequest);
269
267
  if (_scrollTTL) {
270
- const scrollDuration = (0, ms_1.default)(_scrollTTL);
268
+ const scrollDuration = (0, ms_1.default)(_scrollTTL) ?? 0;
271
269
  if (scrollDuration > this.maxScrollDuration) {
272
270
  throw kerror.get("services", "storage", "scroll_duration_too_great", _scrollTTL);
273
271
  }
@@ -311,16 +309,12 @@ class ES8 {
311
309
  async search({ index, collection, searchBody, targets, } = {}, { from, size, scroll, } = {}) {
312
310
  let esIndexes;
313
311
  if (targets && targets.length > 0) {
314
- const indexes = new Set();
315
- for (const target of targets) {
316
- for (const targetCollection of target.collections) {
317
- const alias = this._getAlias(target.index, targetCollection);
318
- indexes.add(alias);
319
- }
320
- }
321
- esIndexes = Array.from(indexes).join(",");
312
+ esIndexes = this._targetsToIndexes(targets);
322
313
  }
323
314
  else {
315
+ if (index === undefined) {
316
+ throw kerror.get("services", "storage", "missing_argument", "index");
317
+ }
324
318
  esIndexes = this._getAlias(index, collection);
325
319
  }
326
320
  const esRequest = {
@@ -332,7 +326,7 @@ class ES8 {
332
326
  track_total_hits: true,
333
327
  };
334
328
  if (scroll) {
335
- const scrollDuration = (0, ms_1.default)(scroll);
329
+ const scrollDuration = (0, ms_1.default)(scroll) ?? 0;
336
330
  if (scrollDuration > this.maxScrollDuration) {
337
331
  throw kerror.get("services", "storage", "scroll_duration_too_great", scroll);
338
332
  }
@@ -343,8 +337,8 @@ class ES8 {
343
337
  const totalHitsValue = this._getHitsTotalValue(body.hits);
344
338
  let remaining;
345
339
  if (body._scroll_id) {
346
- const ttl = (esRequest.scroll && (0, ms_1.default)(esRequest.scroll)) ||
347
- (0, ms_1.default)(this._config.defaults.scrollTTL);
340
+ const scrollTTL = this._config.defaults.scrollTTL;
341
+ const ttl = (scroll && (0, ms_1.default)(scroll)) || (0, ms_1.default)(scrollTTL);
348
342
  await global.kuzzle.ask("core:cache:internal:store", SCROLL_CACHE_PREFIX + global.kuzzle.hash(body._scroll_id), JSON.stringify({
349
343
  collection,
350
344
  fetched: body.hits.hits.length,
@@ -363,6 +357,20 @@ class ES8 {
363
357
  throw this._esWrapper.formatESError(error);
364
358
  }
365
359
  }
360
+ /**
361
+ * The comma-separated alias list a multi-target search is run against.
362
+ *
363
+ * @param targets - targets already through `assertTargetsAreValid`
364
+ */
365
+ _targetsToIndexes(targets) {
366
+ const indexes = new Set();
367
+ for (const target of targets) {
368
+ for (const targetCollection of target.collections) {
369
+ indexes.add(this._getAlias(target.index, targetCollection));
370
+ }
371
+ }
372
+ return Array.from(indexes).join(",");
373
+ }
366
374
  /**
367
375
  * Generate a map that associate an alias to a pair of index and collection
368
376
  *
@@ -415,10 +423,15 @@ class ES8 {
415
423
  * find the first alias that exists in the map of aliases associated
416
424
  * to the targets.
417
425
  */
418
- const alias = aliases.find((_alias) => aliasToTargets[_alias]);
419
426
  // Retrieve index and collection information based on the matching alias
420
- index = aliasToTargets[alias].index;
421
- collection = aliasToTargets[alias].collection;
427
+ for (const _alias of aliases) {
428
+ const target = aliasToTargets[_alias];
429
+ if (target) {
430
+ index = target.index;
431
+ collection = target.collection;
432
+ break;
433
+ }
434
+ }
422
435
  }
423
436
  return {
424
437
  _id: hit._id,
@@ -498,7 +511,7 @@ class ES8 {
498
511
  */
499
512
  async mGet(index, collection, ids) {
500
513
  if (ids.length === 0) {
501
- return { errors: [], item: [] };
514
+ return { errors: [], items: [] };
502
515
  }
503
516
  const esRequest = {
504
517
  docs: ids.map((_id) => ({
@@ -566,8 +579,12 @@ class ES8 {
566
579
  */
567
580
  async create(index, collection, content, { id, refresh, userId = null, injectKuzzleMeta = true, } = {}) {
568
581
  (0, requestAssertions_1.assertIsObject)(content);
582
+ // `document` is optional on an IndexRequest, so the metadata is written
583
+ // through the local the request holds by reference rather than read back
584
+ // off the request.
585
+ const document = content;
569
586
  const esRequest = {
570
- document: content,
587
+ document,
571
588
  id,
572
589
  index: this._getAlias(index, collection),
573
590
  op_type: id ? "create" : "index",
@@ -577,7 +594,7 @@ class ES8 {
577
594
  assertWellFormedRefresh(esRequest);
578
595
  // Add metadata
579
596
  if (injectKuzzleMeta) {
580
- esRequest.document._kuzzle_info = {
597
+ document._kuzzle_info = {
581
598
  author: getKuid(userId),
582
599
  createdAt: Date.now(),
583
600
  updatedAt: null,
@@ -589,7 +606,7 @@ class ES8 {
589
606
  const body = await this._client.index(esRequest);
590
607
  return {
591
608
  _id: body._id,
592
- _source: esRequest.document,
609
+ _source: document,
593
610
  _version: body._version,
594
611
  };
595
612
  }
@@ -609,8 +626,9 @@ class ES8 {
609
626
  * @returns {Promise.<Object>} { _id, _version, _source, created }
610
627
  */
611
628
  async createOrReplace(index, collection, id, content, { refresh, userId = null, injectKuzzleMeta = true, } = {}) {
629
+ const document = content;
612
630
  const esRequest = {
613
- document: content,
631
+ document,
614
632
  id,
615
633
  index: this._getAlias(index, collection),
616
634
  refresh,
@@ -619,7 +637,7 @@ class ES8 {
619
637
  assertWellFormedRefresh(esRequest);
620
638
  // Add metadata
621
639
  if (injectKuzzleMeta) {
622
- esRequest.document._kuzzle_info = {
640
+ document._kuzzle_info = {
623
641
  author: getKuid(userId),
624
642
  createdAt: Date.now(),
625
643
  updatedAt: Date.now(),
@@ -631,7 +649,7 @@ class ES8 {
631
649
  const body = await this._client.index(esRequest);
632
650
  return {
633
651
  _id: body._id,
634
- _source: esRequest.document,
652
+ _source: document,
635
653
  _version: body._version,
636
654
  created: body.result === "created", // Needed by the notifier
637
655
  };
@@ -652,9 +670,10 @@ class ES8 {
652
670
  * @returns {Promise.<{ _id, _version }>}
653
671
  */
654
672
  async update(index, collection, id, content, { refresh, userId = null, retryOnConflict, injectKuzzleMeta = true, } = {}) {
673
+ const doc = content;
655
674
  const esRequest = {
656
675
  _source: true,
657
- doc: content,
676
+ doc,
658
677
  id,
659
678
  index: this._getAlias(index, collection),
660
679
  refresh,
@@ -664,8 +683,8 @@ class ES8 {
664
683
  assertWellFormedRefresh(esRequest);
665
684
  if (injectKuzzleMeta) {
666
685
  // Add metadata
667
- esRequest.doc._kuzzle_info = {
668
- ...esRequest.doc._kuzzle_info,
686
+ doc._kuzzle_info = {
687
+ ...doc._kuzzle_info,
669
688
  updatedAt: Date.now(),
670
689
  updater: getKuid(userId),
671
690
  };
@@ -675,7 +694,7 @@ class ES8 {
675
694
  const body = await this._client.update(esRequest);
676
695
  return {
677
696
  _id: body._id,
678
- _source: body.get._source,
697
+ _source: body.get?._source,
679
698
  _version: body._version,
680
699
  };
681
700
  }
@@ -696,14 +715,16 @@ class ES8 {
696
715
  * @returns {Promise.<{ _id, _version }>}
697
716
  */
698
717
  async upsert(index, collection, id, content, { defaultValues = {}, refresh, userId = null, retryOnConflict, injectKuzzleMeta = true, } = {}) {
718
+ const doc = content;
719
+ const upsert = { ...defaultValues, ...content };
699
720
  const esRequest = {
700
721
  _source: true,
701
- doc: content,
722
+ doc,
702
723
  id,
703
724
  index: this._getAlias(index, collection),
704
725
  refresh,
705
726
  retry_on_conflict: retryOnConflict || this._config.defaults.onUpdateConflictRetries,
706
- upsert: { ...defaultValues, ...content },
727
+ upsert,
707
728
  };
708
729
  assertNoRouting(esRequest);
709
730
  assertWellFormedRefresh(esRequest);
@@ -711,13 +732,13 @@ class ES8 {
711
732
  const user = getKuid(userId);
712
733
  const now = Date.now();
713
734
  if (injectKuzzleMeta) {
714
- esRequest.doc._kuzzle_info = {
715
- ...esRequest.doc._kuzzle_info,
735
+ doc._kuzzle_info = {
736
+ ...doc._kuzzle_info,
716
737
  updatedAt: now,
717
738
  updater: user,
718
739
  };
719
- esRequest.upsert._kuzzle_info = {
720
- ...esRequest.upsert._kuzzle_info,
740
+ upsert._kuzzle_info = {
741
+ ...upsert._kuzzle_info,
721
742
  author: user,
722
743
  createdAt: now,
723
744
  };
@@ -727,7 +748,7 @@ class ES8 {
727
748
  const body = await this._client.update(esRequest);
728
749
  return {
729
750
  _id: body._id,
730
- _source: body.get._source,
751
+ _source: body.get?._source,
731
752
  _version: body._version,
732
753
  created: body.result === "created",
733
754
  };
@@ -749,8 +770,9 @@ class ES8 {
749
770
  */
750
771
  async replace(index, collection, id, content, { refresh, userId = null, injectKuzzleMeta = true, } = {}) {
751
772
  const alias = this._getAlias(index, collection);
773
+ const document = content;
752
774
  const esRequest = {
753
- document: content,
775
+ document,
754
776
  id,
755
777
  index: alias,
756
778
  refresh,
@@ -759,7 +781,7 @@ class ES8 {
759
781
  assertWellFormedRefresh(esRequest);
760
782
  if (injectKuzzleMeta) {
761
783
  // Add metadata
762
- esRequest.document._kuzzle_info = {
784
+ document._kuzzle_info = {
763
785
  author: getKuid(userId),
764
786
  createdAt: Date.now(),
765
787
  updatedAt: Date.now(),
@@ -843,21 +865,24 @@ class ES8 {
843
865
  });
844
866
  }
845
867
  this.logger.debug("Delete by query: %o", esRequest);
846
- esRequest.refresh = refresh === "wait_for" ? true : refresh;
847
868
  const request = {
848
869
  ...esRequest,
849
- max_docs: size,
870
+ // Built in rather than assigned onto `esRequest` afterwards: that
871
+ // object is spread into the search above, and mutating it after the
872
+ // fact meant its declared shape and its real one disagreed.
873
+ refresh: refresh === "wait_for" ? true : refresh,
874
+ // -1 is Kuzzle's "no limit"; ES wants the property absent rather than
875
+ // set to undefined after the fact, which was a `number` field being
876
+ // assigned undefined.
877
+ max_docs: size === -1 ? undefined : size,
850
878
  };
851
- if (request.max_docs === -1) {
852
- request.max_docs = undefined;
853
- }
854
879
  const body = await this._client.deleteByQuery(request);
855
880
  return {
856
881
  deleted: body.deleted,
857
882
  documents,
858
- failures: body.failures.map(({ id, cause }) => ({
883
+ failures: (body.failures ?? []).map(({ id, cause }) => ({
859
884
  id,
860
- reason: cause.reason,
885
+ reason: cause?.reason,
861
886
  })),
862
887
  total: body.total,
863
888
  };
@@ -886,26 +911,30 @@ class ES8 {
886
911
  try {
887
912
  this.logger.debug("DeleteFields document: %o", esRequest);
888
913
  const body = await this._client.get(esRequest);
914
+ const source = body._source;
915
+ if (source === undefined) {
916
+ throw kerror.get("services", "storage", "not_found", id, index, collection);
917
+ }
889
918
  for (const field of fields) {
890
- if (lodash_1.default.has(body._source, field)) {
891
- lodash_1.default.set(body._source, field, undefined);
919
+ if (lodash_1.default.has(source, field)) {
920
+ lodash_1.default.set(source, field, undefined);
892
921
  }
893
922
  }
894
923
  const updatedInfos = {
895
924
  updatedAt: Date.now(),
896
925
  updater: getKuid(userId),
897
926
  };
898
- if (typeof body._source._kuzzle_info === "object") {
899
- body._source._kuzzle_info = {
900
- ...body._source._kuzzle_info,
927
+ if (typeof source._kuzzle_info === "object") {
928
+ source._kuzzle_info = {
929
+ ...source._kuzzle_info,
901
930
  ...updatedInfos,
902
931
  };
903
932
  }
904
933
  else {
905
- body._source._kuzzle_info = updatedInfos;
934
+ source._kuzzle_info = updatedInfos;
906
935
  }
907
936
  const newEsRequest = {
908
- document: body._source,
937
+ document: source,
909
938
  id,
910
939
  index: alias,
911
940
  refresh,
@@ -915,7 +944,7 @@ class ES8 {
915
944
  const updated = await this._client.index(newEsRequest);
916
945
  return {
917
946
  _id: id,
918
- _source: body._source,
947
+ _source: source,
919
948
  _version: updated._version,
920
949
  };
921
950
  }
@@ -995,8 +1024,9 @@ class ES8 {
995
1024
  catch (error) {
996
1025
  throw this._esWrapper.formatESError(error);
997
1026
  }
998
- if (response.failures.length) {
999
- const errors = response.failures.map(({ id, cause }) => ({
1027
+ const failures = response.failures ?? [];
1028
+ if (failures.length) {
1029
+ const errors = failures.map(({ id, cause }) => ({
1000
1030
  cause,
1001
1031
  id,
1002
1032
  }));
@@ -1031,7 +1061,7 @@ class ES8 {
1031
1061
  }
1032
1062
  const results = [];
1033
1063
  let processed = 0;
1034
- let scrollId = null;
1064
+ let scrollId;
1035
1065
  try {
1036
1066
  let body = await this._client.search(esRequest);
1037
1067
  const totalHitsValue = this._getHitsTotalValue(body.hits);
@@ -1066,7 +1096,7 @@ class ES8 {
1066
1096
  this._assertValidIndexAndCollection(index);
1067
1097
  let body;
1068
1098
  try {
1069
- body = await this._client.cat.aliases({ format: "json" });
1099
+ body = await this._catAliases();
1070
1100
  }
1071
1101
  catch (error) {
1072
1102
  throw this._esWrapper.formatESError(error);
@@ -1132,11 +1162,11 @@ class ES8 {
1132
1162
  dynamic: mappings.dynamic || this._config.commonMapping.dynamic,
1133
1163
  properties: lodash_1.default.merge(mappings.properties, this._config.commonMapping.properties),
1134
1164
  };
1135
- esRequest.settings.number_of_replicas =
1136
- esRequest.settings.number_of_replicas ||
1165
+ settings.number_of_replicas =
1166
+ settings.number_of_replicas ||
1137
1167
  this._config.defaultSettings.number_of_replicas;
1138
- esRequest.settings.number_of_shards =
1139
- esRequest.settings.number_of_shards ||
1168
+ settings.number_of_shards =
1169
+ settings.number_of_shards ||
1140
1170
  this._config.defaultSettings.number_of_shards;
1141
1171
  try {
1142
1172
  await this._client.indices.create(esRequest);
@@ -1168,7 +1198,7 @@ class ES8 {
1168
1198
  this.logger.debug("Get settings: %o", esRequest);
1169
1199
  try {
1170
1200
  const body = await this._client.indices.getSettings(esRequest);
1171
- return body[indice].settings.index;
1201
+ return body[indice]?.settings?.index;
1172
1202
  }
1173
1203
  catch (error) {
1174
1204
  throw this._esWrapper.formatESError(error);
@@ -1191,12 +1221,13 @@ class ES8 {
1191
1221
  this.logger.debug("Get mapping: %o", esRequest);
1192
1222
  try {
1193
1223
  const body = await this._client.indices.getMapping(esRequest);
1224
+ const mappings = body[indice]?.mappings ?? {};
1194
1225
  const properties = includeKuzzleMeta
1195
- ? body[indice].mappings.properties
1196
- : lodash_1.default.omit(body[indice].mappings.properties, "_kuzzle_info");
1226
+ ? mappings.properties
1227
+ : lodash_1.default.omit(mappings.properties, "_kuzzle_info");
1197
1228
  return {
1198
- _meta: body[indice].mappings._meta,
1199
- dynamic: body[indice].mappings.dynamic,
1229
+ _meta: mappings._meta,
1230
+ dynamic: mappings.dynamic,
1200
1231
  properties,
1201
1232
  };
1202
1233
  }
@@ -1313,10 +1344,12 @@ class ES8 {
1313
1344
  includeKuzzleMeta: true,
1314
1345
  });
1315
1346
  this._checkMappings(mappings);
1347
+ const _meta = mappings._meta || collectionMappings._meta;
1348
+ const dynamic = mappings.dynamic || collectionMappings.dynamic;
1316
1349
  esRequest = {
1317
1350
  ...esRequest,
1318
- _meta: mappings._meta || collectionMappings._meta,
1319
- dynamic: mappings.dynamic || collectionMappings.dynamic,
1351
+ _meta,
1352
+ dynamic,
1320
1353
  properties: mappings.properties,
1321
1354
  };
1322
1355
  this.logger.debug("Update mapping: %o", esRequest);
@@ -1328,8 +1361,8 @@ class ES8 {
1328
1361
  }
1329
1362
  const fullProperties = lodash_1.default.merge(collectionMappings.properties, mappings.properties);
1330
1363
  return {
1331
- _meta: esRequest._meta,
1332
- dynamic: esRequest.dynamic.toString(),
1364
+ _meta,
1365
+ dynamic: dynamic?.toString(),
1333
1366
  properties: fullProperties,
1334
1367
  };
1335
1368
  }
@@ -1447,34 +1480,18 @@ class ES8 {
1447
1480
  *
1448
1481
  * bulk body can contain more than 10K elements
1449
1482
  */
1450
- for (let i = 0; i < body.items.length; i++) {
1451
- const row = body.items[i];
1452
- const action = Object.keys(row)[0];
1453
- const item = row[action];
1483
+ for (const row of body.items) {
1484
+ // Elasticsearch answers exactly one action per row; a row carrying none
1485
+ // describes no document, so there is nothing to report on it.
1486
+ const [action = ""] = Object.keys(row);
1487
+ const item = Object.values(row)[0];
1488
+ if (item === undefined) {
1489
+ continue;
1490
+ }
1454
1491
  if (item.status >= 400) {
1455
- const error = {
1456
- _id: item._id,
1457
- status: item.status,
1458
- };
1459
- // update action contain body in "doc" field
1460
- // the delete action is not followed by an action payload
1461
- if (action === "update") {
1462
- error._source = documents[idx + 1].doc;
1463
- error._source._kuzzle_info = undefined;
1464
- }
1465
- else if (action !== "delete") {
1466
- error._source = documents[idx + 1];
1467
- error._source._kuzzle_info = undefined;
1468
- }
1469
- // ES response does not systematicaly include an error object
1470
- // (e.g. delete action with 404 status)
1471
- if (item.error) {
1472
- error.error = {
1473
- reason: item.error.reason,
1474
- type: item.error.type,
1475
- };
1476
- }
1477
- result.errors.push({ [action]: error });
1492
+ result.errors.push({
1493
+ [action]: this._importError(action, item, documents[idx + 1]),
1494
+ });
1478
1495
  }
1479
1496
  else {
1480
1497
  result.items.push({
@@ -1490,6 +1507,35 @@ class ES8 {
1490
1507
  /* end critical code section */
1491
1508
  return result;
1492
1509
  }
1510
+ /**
1511
+ * The error entry `import` reports for one rejected bulk row.
1512
+ *
1513
+ * @param action - the bulk action Elasticsearch echoed back
1514
+ * @param item - that action's answer
1515
+ * @param payload - the action's payload, absent for a delete
1516
+ */
1517
+ _importError(action, item, payload) {
1518
+ const error = {
1519
+ _id: item._id,
1520
+ status: item.status,
1521
+ };
1522
+ // update action contain body in "doc" field
1523
+ // the delete action is not followed by an action payload
1524
+ if (action !== "delete") {
1525
+ const source = (action === "update" ? payload?.doc : payload) ?? {};
1526
+ source._kuzzle_info = undefined;
1527
+ error._source = source;
1528
+ }
1529
+ // ES response does not systematicaly include an error object
1530
+ // (e.g. delete action with 404 status)
1531
+ if (item.error) {
1532
+ error.error = {
1533
+ reason: item.error.reason ?? "",
1534
+ type: item.error.type,
1535
+ };
1536
+ }
1537
+ return error;
1538
+ }
1493
1539
  /**
1494
1540
  * Retrieves the complete list of existing collections in the current index
1495
1541
  *
@@ -1501,7 +1547,7 @@ class ES8 {
1501
1547
  async listCollections(index, { includeHidden = false } = {}) {
1502
1548
  let body;
1503
1549
  try {
1504
- body = await this._client.cat.aliases({ format: "json" });
1550
+ body = await this._catAliases();
1505
1551
  }
1506
1552
  catch (error) {
1507
1553
  throw this._esWrapper.formatESError(error);
@@ -1518,7 +1564,7 @@ class ES8 {
1518
1564
  async listIndexes() {
1519
1565
  let body;
1520
1566
  try {
1521
- body = await this._client.cat.aliases({ format: "json" });
1567
+ body = await this._catAliases();
1522
1568
  }
1523
1569
  catch (error) {
1524
1570
  throw this._esWrapper.formatESError(error);
@@ -1535,7 +1581,7 @@ class ES8 {
1535
1581
  async getSchema() {
1536
1582
  let body;
1537
1583
  try {
1538
- body = await this._client.cat.aliases({ format: "json" });
1584
+ body = await this._catAliases();
1539
1585
  }
1540
1586
  catch (error) {
1541
1587
  throw this._esWrapper.formatESError(error);
@@ -1555,7 +1601,7 @@ class ES8 {
1555
1601
  async listAliases() {
1556
1602
  let body;
1557
1603
  try {
1558
- body = await this._client.cat.aliases({ format: "json" });
1604
+ body = await this._catAliases();
1559
1605
  }
1560
1606
  catch (error) {
1561
1607
  throw this._esWrapper.formatESError(error);
@@ -1615,7 +1661,7 @@ class ES8 {
1615
1661
  }
1616
1662
  const deleted = new Set();
1617
1663
  try {
1618
- const body = await this._client.cat.aliases({ format: "json" });
1664
+ const body = await this._catAliases();
1619
1665
  const esRequest = body.reduce((request, { alias, index: indice }) => {
1620
1666
  const index = this._extractIndex(alias);
1621
1667
  if (alias[INDEX_PREFIX_POSITION_IN_ALIAS] !== this._indexPrefix ||
@@ -1706,7 +1752,7 @@ class ES8 {
1706
1752
  */
1707
1753
  async mExists(index, collection, ids) {
1708
1754
  if (ids.length === 0) {
1709
- return { errors: [], item: [] };
1755
+ return { errors: [], items: [] };
1710
1756
  }
1711
1757
  const esRequest = {
1712
1758
  _source: "false",
@@ -1723,8 +1769,7 @@ class ES8 {
1723
1769
  }
1724
1770
  const errors = [];
1725
1771
  const items = [];
1726
- for (let i = 0; i < body.docs.length; i++) {
1727
- const doc = body.docs[i];
1772
+ for (const doc of body.docs) {
1728
1773
  if (!("error" in doc) && doc.found) {
1729
1774
  items.push(doc._id);
1730
1775
  }
@@ -1768,7 +1813,7 @@ class ES8 {
1768
1813
  const collections = await this.listCollections(index, {
1769
1814
  includeHidden: true,
1770
1815
  });
1771
- return collections.some((col) => col === HIDDEN_COLLECTION);
1816
+ return collections.includes(HIDDEN_COLLECTION);
1772
1817
  }
1773
1818
  /**
1774
1819
  * Creates multiple documents at once.
@@ -1799,9 +1844,10 @@ class ES8 {
1799
1844
  })
1800
1845
  : { docs: [] };
1801
1846
  const existingDocuments = body.docs;
1847
+ const operations = [];
1802
1848
  const esRequest = {
1803
1849
  index: alias,
1804
- operations: [],
1850
+ operations,
1805
1851
  refresh,
1806
1852
  timeout,
1807
1853
  };
@@ -1811,11 +1857,11 @@ class ES8 {
1811
1857
  *
1812
1858
  * request can contain more than 10K elements
1813
1859
  */
1814
- for (let i = 0, idx = 0; i < extractedDocuments.length; i++) {
1815
- const document = extractedDocuments[i];
1860
+ let idx = 0;
1861
+ for (const document of extractedDocuments) {
1862
+ const doc = existingDocuments[idx];
1816
1863
  // Documents are retrieved in the same order than we got them from user
1817
- if (typeof document._id === "string" && existingDocuments[idx]) {
1818
- const doc = existingDocuments[idx];
1864
+ if (typeof document._id === "string" && doc !== undefined) {
1819
1865
  if (!("error" in doc) && doc.found) {
1820
1866
  document._source._kuzzle_info = undefined;
1821
1867
  rejected.push({
@@ -1828,20 +1874,18 @@ class ES8 {
1828
1874
  });
1829
1875
  }
1830
1876
  else {
1831
- esRequest.operations.push({
1877
+ operations.push({
1832
1878
  index: {
1833
1879
  _id: document._id,
1834
1880
  _index: alias,
1835
1881
  },
1836
- });
1837
- esRequest.operations.push(document._source);
1882
+ }, document._source);
1838
1883
  toImport.push(document);
1839
1884
  }
1840
1885
  idx++;
1841
1886
  }
1842
1887
  else {
1843
- esRequest.operations.push({ index: { _index: alias } });
1844
- esRequest.operations.push(document._source);
1888
+ operations.push({ index: { _index: alias } }, document._source);
1845
1889
  toImport.push(document);
1846
1890
  }
1847
1891
  }
@@ -1871,27 +1915,26 @@ class ES8 {
1871
1915
  };
1872
1916
  }
1873
1917
  const alias = this._getAlias(index, collection);
1918
+ const operations = [];
1874
1919
  const esRequest = {
1875
1920
  index: alias,
1876
- operations: [],
1921
+ operations,
1877
1922
  refresh,
1878
1923
  timeout,
1879
1924
  };
1880
1925
  const { rejected, extractedDocuments } = this._extractMDocuments(documents, kuzzleMeta);
1881
- esRequest.operations = [];
1882
1926
  /**
1883
1927
  * @warning Critical code section
1884
1928
  *
1885
1929
  * request can contain more than 10K elements
1886
1930
  */
1887
- for (let i = 0; i < extractedDocuments.length; i++) {
1888
- esRequest.operations.push({
1931
+ for (const extractedDocument of extractedDocuments) {
1932
+ operations.push({
1889
1933
  index: {
1890
- _id: extractedDocuments[i]._id,
1934
+ _id: extractedDocument._id,
1891
1935
  _index: alias,
1892
1936
  },
1893
- });
1894
- esRequest.operations.push(extractedDocuments[i]._source);
1937
+ }, extractedDocument._source);
1895
1938
  }
1896
1939
  /* end critical code section */
1897
1940
  return this._mExecute(esRequest, extractedDocuments, rejected, {
@@ -1911,10 +1954,11 @@ class ES8 {
1911
1954
  *
1912
1955
  * @returns {Promise.<Object>} { items, errors }
1913
1956
  */
1914
- async mUpdate(index, collection, documents, { refresh = undefined, retryOnConflict = 0, timeout = undefined, userId = null, } = {}) {
1957
+ async mUpdate(index, collection, documents, { refresh, retryOnConflict = 0, timeout, userId = null, } = {}) {
1958
+ const operations = [];
1915
1959
  const alias = this._getAlias(index, collection), toImport = [], esRequest = {
1916
1960
  index: alias,
1917
- operations: [],
1961
+ operations,
1918
1962
  refresh,
1919
1963
  timeout,
1920
1964
  }, kuzzleMeta = {
@@ -1928,19 +1972,19 @@ class ES8 {
1928
1972
  *
1929
1973
  * request can contain more than 10K elements
1930
1974
  */
1931
- for (let i = 0; i < extractedDocuments.length; i++) {
1932
- const extractedDocument = extractedDocuments[i];
1975
+ for (const extractedDocument of extractedDocuments) {
1933
1976
  if (typeof extractedDocument._id === "string") {
1934
- esRequest.operations.push({
1977
+ operations.push({
1935
1978
  update: {
1936
1979
  _id: extractedDocument._id,
1937
1980
  _index: alias,
1938
- retry_on_conflict: retryOnConflict || this._config.defaults.onUpdateConflictRetries,
1981
+ retry_on_conflict: retryOnConflict ||
1982
+ this._config.defaults.onUpdateConflictRetries,
1939
1983
  },
1940
- });
1941
- // _source: true => makes ES return the updated document source in the
1942
- // response. Required by the real-time notifier component
1943
- esRequest.operations.push({
1984
+ },
1985
+ // _source: true => makes ES return the updated document source in
1986
+ // the response. Required by the real-time notifier component
1987
+ {
1944
1988
  _source: true,
1945
1989
  doc: extractedDocument._source,
1946
1990
  });
@@ -1984,8 +2028,9 @@ class ES8 {
1984
2028
  */
1985
2029
  async mUpsert(index, collection, documents, { refresh, retryOnConflict = 0, timeout, userId = null, } = {}) {
1986
2030
  const alias = this._getAlias(index, collection);
2031
+ const operations = [];
1987
2032
  const esRequest = {
1988
- operations: [],
2033
+ operations,
1989
2034
  refresh,
1990
2035
  timeout,
1991
2036
  };
@@ -2014,17 +2059,17 @@ class ES8 {
2014
2059
  *
2015
2060
  * request can contain more than 10K elements
2016
2061
  */
2017
- for (let i = 0; i < extractedDocuments.length; i++) {
2018
- esRequest.operations.push({
2062
+ for (const extractedDocument of extractedDocuments) {
2063
+ operations.push({
2019
2064
  update: {
2020
- _id: extractedDocuments[i]._id,
2065
+ _id: extractedDocument._id,
2021
2066
  _index: alias,
2022
2067
  _source: true,
2023
2068
  retry_on_conflict: retryOnConflict || this._config.defaults.onUpdateConflictRetries,
2024
2069
  },
2025
2070
  }, {
2026
- doc: extractedDocuments[i]._source.changes,
2027
- upsert: extractedDocuments[i]._source.default,
2071
+ doc: extractedDocument._source.changes,
2072
+ upsert: extractedDocument._source.default,
2028
2073
  });
2029
2074
  // _source: true
2030
2075
  // Makes ES return the updated document source in the response.
@@ -2077,8 +2122,9 @@ class ES8 {
2077
2122
  index: alias,
2078
2123
  });
2079
2124
  const existingDocuments = body.docs;
2125
+ const operations = [];
2080
2126
  const esRequest = {
2081
- operations: [],
2127
+ operations,
2082
2128
  refresh,
2083
2129
  timeout,
2084
2130
  };
@@ -2088,18 +2134,19 @@ class ES8 {
2088
2134
  *
2089
2135
  * request can contain more than 10K elements
2090
2136
  */
2091
- for (let i = 0; i < extractedDocuments.length; i++) {
2092
- const document = extractedDocuments[i];
2137
+ for (const [i, document] of extractedDocuments.entries()) {
2093
2138
  // Documents are retrieved in the same order than we got them from user
2094
2139
  const doc = existingDocuments[i];
2095
- if (!("error" in doc) && doc?.found) {
2096
- esRequest.operations.push({
2140
+ // `doc` used to be read with `"error" in doc` and only then with `?.`:
2141
+ // a shorter mget answer than the request reached the `in` first, which
2142
+ // throws on undefined.
2143
+ if (doc !== undefined && !("error" in doc) && doc.found) {
2144
+ operations.push({
2097
2145
  index: {
2098
2146
  _id: document._id,
2099
2147
  _index: alias,
2100
2148
  },
2101
- });
2102
- esRequest.operations.push(document._source);
2149
+ }, document._source);
2103
2150
  toImport.push(document);
2104
2151
  }
2105
2152
  else {
@@ -2136,8 +2183,7 @@ class ES8 {
2136
2183
  *
2137
2184
  * request can contain more than 10K elements
2138
2185
  */
2139
- for (let i = 0; i < ids.length; i++) {
2140
- const _id = ids[i];
2186
+ for (const _id of ids) {
2141
2187
  if (typeof _id === "string") {
2142
2188
  validIds.push(_id);
2143
2189
  }
@@ -2158,8 +2204,7 @@ class ES8 {
2158
2204
  *
2159
2205
  * request can contain more than 10K elements
2160
2206
  */
2161
- for (let i = 0; i < validIds.length; i++) {
2162
- const validId = validIds[i];
2207
+ for (const validId of validIds) {
2163
2208
  const item = items[idx];
2164
2209
  if (item && item._id === validId) {
2165
2210
  query.ids.values.push(validId);
@@ -2198,10 +2243,10 @@ class ES8 {
2198
2243
  if (this._hasExceededLimit(limits, documents)) {
2199
2244
  return kerror.reject("services", "storage", "write_limit_exceeded");
2200
2245
  }
2201
- let body = { items: [] };
2246
+ let items = [];
2202
2247
  if (documents.length > 0) {
2203
2248
  try {
2204
- body = await this._client.bulk(esRequest);
2249
+ ({ items } = await this._client.bulk(esRequest));
2205
2250
  }
2206
2251
  catch (error) {
2207
2252
  throw this._esWrapper.formatESError(error);
@@ -2213,32 +2258,21 @@ class ES8 {
2213
2258
  *
2214
2259
  * request can contain more than 10K elements
2215
2260
  */
2216
- for (let i = 0; i < body.items.length; i++) {
2217
- const item = body.items[i];
2218
- const result = item[Object.keys(item)[0]];
2261
+ for (const [i, item] of items.entries()) {
2262
+ const result = Object.values(item)[0];
2263
+ const document = documents[i];
2264
+ // An answer carries exactly one result per document sent; a row without
2265
+ // its counterpart is one neither branch below could describe.
2266
+ if (result === undefined || document === undefined) {
2267
+ continue;
2268
+ }
2219
2269
  if (result.status >= 400) {
2220
- if (result.status === 404) {
2221
- partialErrors.push({
2222
- document: {
2223
- _id: documents[i]._id,
2224
- body: documents[i]._source,
2225
- },
2226
- reason: "document not found",
2227
- status: result.status,
2228
- });
2229
- }
2230
- else {
2231
- partialErrors.push({
2232
- document: documents[i],
2233
- reason: result.error.reason,
2234
- status: result.status,
2235
- });
2236
- }
2270
+ partialErrors.push(this._mExecuteRejection(result, document));
2237
2271
  }
2238
2272
  else {
2239
2273
  successes.push({
2240
2274
  _id: result._id,
2241
- _source: source ? documents[i]._source : undefined,
2275
+ _source: source ? document._source : undefined,
2242
2276
  _version: result._version,
2243
2277
  created: result.result === "created",
2244
2278
  get: result.get,
@@ -2253,6 +2287,29 @@ class ES8 {
2253
2287
  items: successes,
2254
2288
  };
2255
2289
  }
2290
+ /**
2291
+ * The partial-error entry `_mExecute` reports for one rejected bulk row.
2292
+ *
2293
+ * A 404 answers no reason of its own, and reports the document by id and
2294
+ * body rather than whole, which is what the m* callers read back.
2295
+ */
2296
+ _mExecuteRejection(result, document) {
2297
+ if (result.status === 404) {
2298
+ return {
2299
+ document: {
2300
+ _id: document._id,
2301
+ body: document._source,
2302
+ },
2303
+ reason: "document not found",
2304
+ status: result.status,
2305
+ };
2306
+ }
2307
+ return {
2308
+ document,
2309
+ reason: result.error?.reason,
2310
+ status: result.status,
2311
+ };
2312
+ }
2256
2313
  /**
2257
2314
  * Extracts, injects metadata and validates documents contained
2258
2315
  * in a Request
@@ -2274,8 +2331,7 @@ class ES8 {
2274
2331
  *
2275
2332
  * request can contain more than 10K elements
2276
2333
  */
2277
- for (let i = 0; i < documents.length; i++) {
2278
- const document = documents[i];
2334
+ for (const document of documents) {
2279
2335
  if (!(0, safeObject_1.isPlainObject)(document.body) && !prepareMUpsert) {
2280
2336
  rejected.push({
2281
2337
  document,
@@ -2406,17 +2462,15 @@ class ES8 {
2406
2462
  */
2407
2463
  async _getIndice(index, collection) {
2408
2464
  const alias = `${ALIAS_PREFIX}${this._indexPrefix}${index}${NAME_SEPARATOR}${collection}`;
2409
- const body = await this._client.cat.aliases({
2410
- format: "json",
2411
- name: alias,
2412
- });
2413
- if (body.length < 1) {
2465
+ const body = await this._catAliases(alias);
2466
+ const [record] = body;
2467
+ if (record === undefined) {
2414
2468
  throw kerror.get("services", "storage", "unknown_index_collection");
2415
2469
  }
2416
2470
  else if (body.length > 1) {
2417
2471
  throw kerror.get("services", "storage", "multiple_indice_alias", `"alias" starting with "${ALIAS_PREFIX}"`, '"indices"');
2418
2472
  }
2419
- return body[0].index;
2473
+ return record.index;
2420
2474
  }
2421
2475
  /**
2422
2476
  * Given an ES Request returns the settings of the corresponding indice.
@@ -2428,7 +2482,7 @@ class ES8 {
2428
2482
  async _getSettings(esRequest) {
2429
2483
  const response = await this._client.indices.getSettings(esRequest);
2430
2484
  const index = esRequest.index;
2431
- return response[index].settings;
2485
+ return response[index]?.settings;
2432
2486
  }
2433
2487
  /**
2434
2488
  * Given index + collection, returns an available indice name.
@@ -2471,11 +2525,27 @@ class ES8 {
2471
2525
  */
2472
2526
  async _getAliasFromIndice(indice) {
2473
2527
  const body = await this._client.indices.getAlias({ index: indice });
2474
- const aliases = Object.keys(body[indice].aliases).filter((alias) => alias.startsWith(ALIAS_PREFIX));
2475
- if (aliases.length < 1) {
2528
+ const indiceAliases = body[indice]?.aliases ?? {};
2529
+ const [first, ...others] = Object.keys(indiceAliases).filter((alias) => alias.startsWith(ALIAS_PREFIX));
2530
+ // The non-empty tuple is what lets every caller read aliases[0] without a
2531
+ // guard the throw below already made redundant.
2532
+ if (first === undefined) {
2476
2533
  throw kerror.get("services", "storage", "unknown_index_collection");
2477
2534
  }
2478
- return aliases;
2535
+ return [first, ...others];
2536
+ }
2537
+ /**
2538
+ * `cat.aliases` declares `alias` and `index` as optional. Defaulting them
2539
+ * once here is what lets every caller index into an alias without repeating
2540
+ * the check — and an empty alias fails the index-prefix test every caller
2541
+ * applies, which is what a row without one used to throw on.
2542
+ */
2543
+ async _catAliases(name) {
2544
+ const body = await this._client.cat.aliases(name === undefined ? { format: "json" } : { format: "json", name });
2545
+ return body.map(({ alias, index }) => ({
2546
+ alias: alias ?? "",
2547
+ index: index ?? "",
2548
+ }));
2479
2549
  }
2480
2550
  /**
2481
2551
  * Check for each indice whether it has an alias or not.
@@ -2487,11 +2557,13 @@ class ES8 {
2487
2557
  async generateMissingAliases() {
2488
2558
  try {
2489
2559
  const body = await this._client.cat.indices({ format: "json" });
2490
- const indices = body.map(({ index: indice }) => indice);
2560
+ const indices = body.flatMap(({ index: indice }) => indice === undefined ? [] : [indice]);
2491
2561
  const aliases = await this.listAliases();
2492
2562
  const indicesWithoutAlias = indices.filter((indice) => indice[INDEX_PREFIX_POSITION_IN_INDICE] === this._indexPrefix &&
2493
2563
  !aliases.some((alias) => alias.indice === indice));
2494
- const esRequest = { body: { actions: [] } };
2564
+ const esRequest = {
2565
+ body: { actions: [] },
2566
+ };
2495
2567
  for (const indice of indicesWithoutAlias) {
2496
2568
  esRequest.body.actions.push({
2497
2569
  add: { alias: `${ALIAS_PREFIX}${indice}`, index: indice },
@@ -2551,16 +2623,16 @@ class ES8 {
2551
2623
  _extractSchema(aliases, { includeHidden = false } = {}) {
2552
2624
  const schema = {};
2553
2625
  for (const alias of aliases) {
2554
- const [indexName, collectionName] = alias
2626
+ // `split` always yields a first element; the defaults are what make that
2627
+ // readable to the compiler.
2628
+ const [indexName = "", collectionName = ""] = alias
2555
2629
  .slice(INDEX_PREFIX_POSITION_IN_ALIAS + 1)
2556
2630
  .split(NAME_SEPARATOR);
2557
2631
  if (alias[INDEX_PREFIX_POSITION_IN_ALIAS] === this._indexPrefix &&
2558
2632
  (collectionName !== HIDDEN_COLLECTION || includeHidden)) {
2559
- if (!schema[indexName]) {
2560
- schema[indexName] = [];
2561
- }
2562
- if (!schema[indexName].includes(collectionName)) {
2563
- schema[indexName].push(collectionName);
2633
+ const collections = (schema[indexName] ?? (schema[indexName] = []));
2634
+ if (!collections.includes(collectionName)) {
2635
+ collections.push(collectionName);
2564
2636
  }
2565
2637
  }
2566
2638
  }
@@ -2655,7 +2727,7 @@ class ES8 {
2655
2727
  *
2656
2728
  * @param {Object} searchBody - ES search body (with query, aggregations, sort, etc)
2657
2729
  */
2658
- _sanitizeSearchBody(searchBody) {
2730
+ _sanitizeSearchBody(searchBody = {}) {
2659
2731
  // Only allow a whitelist of top level properties
2660
2732
  for (const key of Object.keys(searchBody)) {
2661
2733
  if (searchBody[key] !== undefined && !this.searchBodyKeys.includes(key)) {
@@ -2776,7 +2848,7 @@ class ES8 {
2776
2848
  await bluebird_1.default.delay(1000);
2777
2849
  }
2778
2850
  }
2779
- catch (e) {
2851
+ catch {
2780
2852
  await bluebird_1.default.delay(1000);
2781
2853
  }
2782
2854
  }
@@ -2809,7 +2881,7 @@ class ES8 {
2809
2881
  const actionNames = ["index", "create", "update", "delete"];
2810
2882
  for (let i = 0; i < esRequest.operations.length; i++) {
2811
2883
  const item = esRequest.operations[i];
2812
- const action = Object.keys(item)[0];
2884
+ const action = Object.keys(item)[0] ?? "";
2813
2885
  if (actionNames.indexOf(action) !== -1) {
2814
2886
  lastAction = action;
2815
2887
  item[action]._index = alias;
@@ -2837,7 +2909,7 @@ class ES8 {
2837
2909
  if (typeof hits.total === "number") {
2838
2910
  return hits.total;
2839
2911
  }
2840
- return hits.total.value;
2912
+ return hits.total?.value ?? 0;
2841
2913
  }
2842
2914
  _getRandomNumber(number) {
2843
2915
  return (0, name_generator_1.randomNumber)(number);
@@ -2922,10 +2994,11 @@ function _isObjectNameValid(name) {
2922
2994
  if (name === "_all") {
2923
2995
  return false;
2924
2996
  }
2925
- let valid = true;
2926
- for (let i = 0; valid && i < FORBIDDEN_CHARS.length; i++) {
2927
- valid = !name.includes(FORBIDDEN_CHARS[i]);
2997
+ for (const forbiddenChar of FORBIDDEN_CHARS) {
2998
+ if (name.includes(forbiddenChar)) {
2999
+ return false;
3000
+ }
2928
3001
  }
2929
- return valid;
3002
+ return true;
2930
3003
  }
2931
3004
  //# sourceMappingURL=elasticsearch.js.map