kuzzle 2.19.2 → 2.19.3

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 (289) hide show
  1. package/lib/api/controllers/adminController.js +94 -80
  2. package/lib/api/controllers/authController.js +239 -212
  3. package/lib/api/controllers/baseController.js +89 -51
  4. package/lib/api/controllers/bulkController.js +62 -49
  5. package/lib/api/controllers/clusterController.js +6 -8
  6. package/lib/api/controllers/collectionController.js +140 -129
  7. package/lib/api/controllers/debugController.d.ts +2 -2
  8. package/lib/api/controllers/debugController.js +33 -31
  9. package/lib/api/controllers/documentController.js +365 -274
  10. package/lib/api/controllers/index.js +13 -13
  11. package/lib/api/controllers/indexController.js +46 -50
  12. package/lib/api/controllers/memoryStorageController.js +410 -360
  13. package/lib/api/controllers/realtimeController.js +37 -36
  14. package/lib/api/controllers/securityController.js +553 -412
  15. package/lib/api/controllers/serverController.js +111 -104
  16. package/lib/api/documentExtractor.js +75 -68
  17. package/lib/api/funnel.js +411 -312
  18. package/lib/api/httpRoutes.js +1493 -324
  19. package/lib/api/openapi/OpenApiManager.d.ts +1 -1
  20. package/lib/api/openapi/OpenApiManager.js +22 -22
  21. package/lib/api/openapi/components/document/count.yaml +1 -1
  22. package/lib/api/openapi/components/document/create.yaml +2 -2
  23. package/lib/api/openapi/components/document/delete.yaml +1 -1
  24. package/lib/api/openapi/components/document/deleteByQuery.yaml +1 -1
  25. package/lib/api/openapi/components/document/exists.yaml +1 -1
  26. package/lib/api/openapi/components/document/get.yaml +2 -2
  27. package/lib/api/openapi/components/document/index.js +12 -12
  28. package/lib/api/openapi/components/document/replace.yaml +1 -1
  29. package/lib/api/openapi/components/document/scroll.yaml +1 -1
  30. package/lib/api/openapi/components/document/validate.yaml +1 -1
  31. package/lib/api/openapi/components/index.d.ts +2 -2
  32. package/lib/api/openapi/components/index.js +1 -1
  33. package/lib/api/openapi/components/security/index.js +1 -1
  34. package/lib/api/openapi/components/security/upsertUser.yaml +2 -3
  35. package/lib/api/openapi/index.d.ts +1 -1
  36. package/lib/api/openapi/openApiGenerator.d.ts +1 -1
  37. package/lib/api/openapi/openApiGenerator.js +7 -7
  38. package/lib/api/rateLimiter.js +12 -13
  39. package/lib/api/request/index.d.ts +4 -4
  40. package/lib/api/request/kuzzleRequest.d.ts +9 -9
  41. package/lib/api/request/kuzzleRequest.js +89 -87
  42. package/lib/api/request/requestContext.d.ts +2 -2
  43. package/lib/api/request/requestContext.js +17 -17
  44. package/lib/api/request/requestInput.d.ts +1 -1
  45. package/lib/api/request/requestInput.js +19 -19
  46. package/lib/api/request/requestResponse.d.ts +4 -4
  47. package/lib/api/request/requestResponse.js +31 -33
  48. package/lib/cluster/command.js +48 -44
  49. package/lib/cluster/idCardHandler.d.ts +1 -1
  50. package/lib/cluster/idCardHandler.js +15 -15
  51. package/lib/cluster/index.js +2 -2
  52. package/lib/cluster/node.js +301 -269
  53. package/lib/cluster/publisher.js +45 -46
  54. package/lib/cluster/state.d.ts +5 -5
  55. package/lib/cluster/state.js +8 -8
  56. package/lib/cluster/subscriber.js +163 -113
  57. package/lib/cluster/workers/IDCardRenewer.js +33 -32
  58. package/lib/config/default.config.d.ts +1 -1
  59. package/lib/config/default.config.js +212 -171
  60. package/lib/config/documentEventAliases.js +6 -6
  61. package/lib/config/index.js +161 -98
  62. package/lib/config/sdkCompatibility.json +8 -8
  63. package/lib/core/auth/formatProcessing.js +7 -7
  64. package/lib/core/auth/passportResponse.js +7 -7
  65. package/lib/core/auth/passportWrapper.js +34 -30
  66. package/lib/core/auth/tokenManager.d.ts +2 -2
  67. package/lib/core/auth/tokenManager.js +11 -10
  68. package/lib/core/backend/applicationManager.d.ts +1 -1
  69. package/lib/core/backend/applicationManager.js +2 -2
  70. package/lib/core/backend/backend.d.ts +3 -3
  71. package/lib/core/backend/backend.js +34 -31
  72. package/lib/core/backend/backendCluster.d.ts +2 -2
  73. package/lib/core/backend/backendCluster.js +5 -5
  74. package/lib/core/backend/backendConfig.d.ts +2 -2
  75. package/lib/core/backend/backendConfig.js +3 -3
  76. package/lib/core/backend/backendController.d.ts +2 -2
  77. package/lib/core/backend/backendController.js +9 -10
  78. package/lib/core/backend/backendErrors.d.ts +3 -3
  79. package/lib/core/backend/backendErrors.js +2 -1
  80. package/lib/core/backend/backendHook.d.ts +2 -2
  81. package/lib/core/backend/backendHook.js +5 -5
  82. package/lib/core/backend/backendImport.d.ts +3 -3
  83. package/lib/core/backend/backendImport.js +23 -23
  84. package/lib/core/backend/backendOpenApi.d.ts +2 -2
  85. package/lib/core/backend/backendOpenApi.js +16 -16
  86. package/lib/core/backend/backendPipe.d.ts +2 -2
  87. package/lib/core/backend/backendPipe.js +6 -6
  88. package/lib/core/backend/backendPlugin.d.ts +4 -4
  89. package/lib/core/backend/backendPlugin.js +14 -14
  90. package/lib/core/backend/backendStorage.d.ts +2 -2
  91. package/lib/core/backend/backendStorage.js +1 -2
  92. package/lib/core/backend/backendVault.d.ts +2 -2
  93. package/lib/core/backend/backendVault.js +3 -3
  94. package/lib/core/backend/index.d.ts +14 -14
  95. package/lib/core/backend/internalLogger.d.ts +1 -1
  96. package/lib/core/backend/internalLogger.js +5 -5
  97. package/lib/core/cache/cacheDbEnum.js +4 -4
  98. package/lib/core/cache/cacheEngine.js +79 -85
  99. package/lib/core/network/accessLogger.js +126 -120
  100. package/lib/core/network/clientConnection.js +5 -5
  101. package/lib/core/network/context.js +8 -8
  102. package/lib/core/network/entryPoint.js +100 -85
  103. package/lib/core/network/httpRouter/index.js +63 -60
  104. package/lib/core/network/httpRouter/routeHandler.js +18 -19
  105. package/lib/core/network/httpRouter/routePart.js +23 -19
  106. package/lib/core/network/protocolManifest.js +3 -3
  107. package/lib/core/network/protocols/httpMessage.js +8 -10
  108. package/lib/core/network/protocols/httpwsProtocol.js +305 -250
  109. package/lib/core/network/protocols/internalProtocol.js +27 -24
  110. package/lib/core/network/protocols/mqttProtocol.js +106 -96
  111. package/lib/core/network/protocols/protocol.js +20 -17
  112. package/lib/core/network/router.js +56 -46
  113. package/lib/core/plugin/plugin.js +151 -120
  114. package/lib/core/plugin/pluginContext.d.ts +7 -7
  115. package/lib/core/plugin/pluginContext.js +48 -44
  116. package/lib/core/plugin/pluginManifest.js +13 -12
  117. package/lib/core/plugin/pluginRepository.js +26 -27
  118. package/lib/core/plugin/pluginsManager.js +425 -304
  119. package/lib/core/plugin/privilegedContext.js +3 -3
  120. package/lib/core/realtime/actionEnum.js +1 -1
  121. package/lib/core/realtime/channel.d.ts +1 -1
  122. package/lib/core/realtime/channel.js +22 -22
  123. package/lib/core/realtime/connectionRooms.d.ts +1 -1
  124. package/lib/core/realtime/hotelClerk.d.ts +2 -2
  125. package/lib/core/realtime/hotelClerk.js +53 -50
  126. package/lib/core/realtime/index.js +5 -5
  127. package/lib/core/realtime/notification/document.js +25 -25
  128. package/lib/core/realtime/notification/index.js +4 -4
  129. package/lib/core/realtime/notification/server.js +3 -3
  130. package/lib/core/realtime/notification/user.js +4 -4
  131. package/lib/core/realtime/notifier.js +113 -75
  132. package/lib/core/realtime/room.d.ts +1 -1
  133. package/lib/core/realtime/subscription.d.ts +1 -1
  134. package/lib/core/realtime/subscription.js +1 -1
  135. package/lib/core/security/index.js +8 -8
  136. package/lib/core/security/profileRepository.d.ts +6 -6
  137. package/lib/core/security/profileRepository.js +48 -45
  138. package/lib/core/security/roleRepository.js +127 -115
  139. package/lib/core/security/securityLoader.js +70 -63
  140. package/lib/core/security/tokenRepository.js +132 -118
  141. package/lib/core/security/userRepository.js +104 -88
  142. package/lib/core/shared/KoncordeWrapper.d.ts +1 -1
  143. package/lib/core/shared/KoncordeWrapper.js +3 -1
  144. package/lib/core/shared/abstractManifest.js +22 -23
  145. package/lib/core/shared/repository.js +69 -67
  146. package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
  147. package/lib/core/shared/sdk/embeddedSdk.js +36 -32
  148. package/lib/core/shared/sdk/funnelProtocol.d.ts +1 -1
  149. package/lib/core/shared/sdk/funnelProtocol.js +11 -11
  150. package/lib/core/shared/sdk/impersonatedSdk.js +19 -18
  151. package/lib/core/shared/store.js +127 -32
  152. package/lib/core/statistics/index.js +2 -2
  153. package/lib/core/statistics/statistics.js +99 -85
  154. package/lib/core/storage/clientAdapter.js +219 -136
  155. package/lib/core/storage/indexCache.js +3 -3
  156. package/lib/core/storage/storageEngine.js +10 -13
  157. package/lib/core/storage/storeScopeEnum.js +3 -3
  158. package/lib/core/validation/baseType.js +12 -10
  159. package/lib/core/validation/index.js +2 -2
  160. package/lib/core/validation/types/anything.js +4 -4
  161. package/lib/core/validation/types/boolean.js +7 -7
  162. package/lib/core/validation/types/date.js +165 -131
  163. package/lib/core/validation/types/email.js +18 -21
  164. package/lib/core/validation/types/enum.js +34 -21
  165. package/lib/core/validation/types/geoPoint.js +7 -7
  166. package/lib/core/validation/types/geoShape.js +148 -125
  167. package/lib/core/validation/types/integer.js +9 -9
  168. package/lib/core/validation/types/ipAddress.js +17 -19
  169. package/lib/core/validation/types/numeric.js +36 -29
  170. package/lib/core/validation/types/object.js +19 -19
  171. package/lib/core/validation/types/string.js +36 -29
  172. package/lib/core/validation/types/url.js +17 -19
  173. package/lib/core/validation/validation.js +422 -378
  174. package/lib/kerror/codes/1-services.json +7 -1
  175. package/lib/kerror/codes/4-plugin.json +2 -2
  176. package/lib/kerror/codes/index.js +85 -63
  177. package/lib/kerror/errors/badRequestError.d.ts +1 -1
  178. package/lib/kerror/errors/externalServiceError.d.ts +1 -1
  179. package/lib/kerror/errors/forbiddenError.d.ts +1 -1
  180. package/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
  181. package/lib/kerror/errors/index.d.ts +15 -15
  182. package/lib/kerror/errors/internalError.d.ts +1 -1
  183. package/lib/kerror/errors/kuzzleError.d.ts +1 -1
  184. package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
  185. package/lib/kerror/errors/multipleErrorsError.js +1 -1
  186. package/lib/kerror/errors/notFoundError.d.ts +1 -1
  187. package/lib/kerror/errors/partialError.d.ts +1 -1
  188. package/lib/kerror/errors/partialError.js +1 -1
  189. package/lib/kerror/errors/pluginImplementationError.d.ts +1 -1
  190. package/lib/kerror/errors/pluginImplementationError.js +2 -1
  191. package/lib/kerror/errors/preconditionError.d.ts +1 -1
  192. package/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
  193. package/lib/kerror/errors/sizeLimitError.d.ts +1 -1
  194. package/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
  195. package/lib/kerror/errors/unauthorizedError.d.ts +1 -1
  196. package/lib/kerror/index.d.ts +3 -3
  197. package/lib/kerror/index.js +17 -16
  198. package/lib/kuzzle/dumpGenerator.js +130 -114
  199. package/lib/kuzzle/event/kuzzleEventEmitter.js +96 -70
  200. package/lib/kuzzle/event/pipeRunner.js +25 -24
  201. package/lib/kuzzle/event/waterfall.js +13 -15
  202. package/lib/kuzzle/index.js +2 -2
  203. package/lib/kuzzle/internalIndexHandler.js +80 -59
  204. package/lib/kuzzle/kuzzle.js +99 -99
  205. package/lib/kuzzle/kuzzleStateEnum.js +1 -1
  206. package/lib/kuzzle/log.js +23 -18
  207. package/lib/kuzzle/vault.js +34 -19
  208. package/lib/model/security/profile.d.ts +3 -3
  209. package/lib/model/security/profile.js +38 -37
  210. package/lib/model/security/rights.js +5 -5
  211. package/lib/model/security/role.d.ts +3 -3
  212. package/lib/model/security/role.js +25 -26
  213. package/lib/model/security/token.d.ts +1 -1
  214. package/lib/model/security/token.js +4 -4
  215. package/lib/model/security/user.d.ts +2 -2
  216. package/lib/model/security/user.js +9 -9
  217. package/lib/model/storage/apiKey.js +43 -33
  218. package/lib/model/storage/baseModel.js +49 -45
  219. package/lib/service/cache/redis.js +60 -55
  220. package/lib/service/service.js +17 -17
  221. package/lib/service/storage/elasticsearch.js +839 -755
  222. package/lib/service/storage/esWrapper.js +103 -86
  223. package/lib/service/storage/queryTranslator.js +52 -59
  224. package/lib/types/Controller.d.ts +3 -3
  225. package/lib/types/ControllerDefinition.d.ts +3 -3
  226. package/lib/types/DebugModule.d.ts +2 -2
  227. package/lib/types/DebugModule.js +1 -1
  228. package/lib/types/Global.d.ts +1 -1
  229. package/lib/types/HttpStream.d.ts +2 -1
  230. package/lib/types/HttpStream.js +7 -5
  231. package/lib/types/Kuzzle.d.ts +1 -1
  232. package/lib/types/KuzzleDocument.d.ts +1 -1
  233. package/lib/types/OpenApiDefinition.d.ts +1 -1
  234. package/lib/types/PasswordPolicy.d.ts +1 -1
  235. package/lib/types/Plugin.d.ts +6 -6
  236. package/lib/types/Plugin.js +2 -2
  237. package/lib/types/Policy.d.ts +1 -1
  238. package/lib/types/RequestPayload.d.ts +1 -1
  239. package/lib/types/ResponsePayload.d.ts +1 -1
  240. package/lib/types/Token.d.ts +1 -1
  241. package/lib/types/User.d.ts +1 -1
  242. package/lib/types/config/DumpConfiguration.d.ts +8 -8
  243. package/lib/types/config/HttpConfiguration.d.ts +1 -1
  244. package/lib/types/config/KuzzleConfiguration.d.ts +1 -1
  245. package/lib/types/config/LimitsConfiguration.d.ts +8 -8
  246. package/lib/types/config/PluginsConfiguration.d.ts +4 -4
  247. package/lib/types/config/SecurityConfiguration.d.ts +62 -62
  248. package/lib/types/config/ServerConfiguration.d.ts +55 -55
  249. package/lib/types/config/ServicesConfiguration.d.ts +2 -2
  250. package/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +10 -10
  251. package/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +3 -3
  252. package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +194 -110
  253. package/lib/types/errors/ErrorDefinition.d.ts +1 -1
  254. package/lib/types/errors/ErrorDomains.d.ts +1 -1
  255. package/lib/types/index.d.ts +38 -38
  256. package/lib/types/realtime/RealtimeScope.d.ts +1 -1
  257. package/lib/types/realtime/RealtimeUsers.d.ts +1 -1
  258. package/lib/util/assertType.js +13 -11
  259. package/lib/util/async.d.ts +1 -0
  260. package/lib/util/async.js +61 -0
  261. package/lib/util/asyncStore.js +19 -21
  262. package/lib/util/bufferedPassThrough.d.ts +2 -2
  263. package/lib/util/bufferedPassThrough.js +4 -4
  264. package/lib/util/bytes.js +9 -13
  265. package/lib/util/crypto.js +1 -1
  266. package/lib/util/debug.js +5 -5
  267. package/lib/util/deprecate.js +24 -21
  268. package/lib/util/didYouMean.js +7 -7
  269. package/lib/util/dump-collection.d.ts +2 -2
  270. package/lib/util/dump-collection.js +26 -26
  271. package/lib/util/esRequest.d.ts +1 -0
  272. package/lib/util/esRequest.js +62 -0
  273. package/lib/util/extractFields.js +24 -25
  274. package/lib/util/inflector.js +5 -5
  275. package/lib/util/koncordeCompat.d.ts +2 -2
  276. package/lib/util/koncordeCompat.js +5 -5
  277. package/lib/util/memoize.js +3 -5
  278. package/lib/util/mutex.d.ts +19 -1
  279. package/lib/util/mutex.js +39 -12
  280. package/lib/util/name-generator.js +1331 -1331
  281. package/lib/util/promback.js +8 -10
  282. package/lib/util/readYamlFile.d.ts +1 -1
  283. package/lib/util/readYamlFile.js +1 -1
  284. package/lib/util/requestAssertions.js +34 -34
  285. package/lib/util/safeObject.js +5 -5
  286. package/lib/util/stackTrace.js +20 -22
  287. package/lib/util/wildcard.js +15 -15
  288. package/package.json +6 -6
  289. package/npm-shrinkwrap.json +0 -19422
@@ -19,18 +19,18 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- const Bluebird = require('bluebird');
24
+ const Bluebird = require("bluebird");
25
25
 
26
26
  class BaseModel {
27
- constructor (_source = {}, _id = null) {
27
+ constructor(_source = {}, _id = null) {
28
28
  this.__id = null;
29
29
  this.__source = {};
30
30
 
31
- Reflect.defineProperty(this, '__persisted', {
31
+ Reflect.defineProperty(this, "__persisted", {
32
32
  value: false,
33
- writable: true
33
+ writable: true,
34
34
  });
35
35
 
36
36
  this._id = _id;
@@ -44,20 +44,20 @@ class BaseModel {
44
44
  *
45
45
  * @param {Model} ModelClass
46
46
  */
47
- static register (ModelClass) {
47
+ static register(ModelClass) {
48
48
  if (this !== BaseModel) {
49
- throw new Error('Incorrect usage of BaseModel.register');
49
+ throw new Error("Incorrect usage of BaseModel.register");
50
50
  }
51
51
 
52
52
  // Define getters and setters for Model fields
53
53
  for (const field of ModelClass.fields) {
54
54
  Reflect.defineProperty(ModelClass.prototype, field, {
55
- get () {
55
+ get() {
56
56
  return this.__source[field];
57
57
  },
58
- set (value) {
58
+ set(value) {
59
59
  this.__source[field] = value;
60
- }
60
+ },
61
61
  });
62
62
  }
63
63
  }
@@ -73,23 +73,24 @@ class BaseModel {
73
73
  *
74
74
  * @returns {Promise}
75
75
  */
76
- async save ({ userId = null, refresh } = {}) {
77
- if (! this.__persisted) {
76
+ async save({ userId = null, refresh } = {}) {
77
+ if (!this.__persisted) {
78
78
  const { _id, _source } = await global.kuzzle.internalIndex.create(
79
79
  this.constructor.collection,
80
80
  this._source,
81
- { id: this._id, refresh, userId });
81
+ { id: this._id, refresh, userId }
82
+ );
82
83
 
83
84
  this._id = _id;
84
85
  this._source = _source;
85
86
  this.__persisted = true;
86
- }
87
- else {
87
+ } else {
88
88
  await global.kuzzle.internalIndex.update(
89
89
  this.constructor.collection,
90
90
  this._id,
91
91
  this._source,
92
- { refresh, userId });
92
+ { refresh, userId }
93
+ );
93
94
  }
94
95
  }
95
96
 
@@ -101,15 +102,16 @@ class BaseModel {
101
102
  *
102
103
  * @returns {Promise}
103
104
  */
104
- async delete ({ refresh } = {}) {
105
- if (! this.__persisted) {
105
+ async delete({ refresh } = {}) {
106
+ if (!this.__persisted) {
106
107
  return;
107
108
  }
108
109
 
109
110
  await global.kuzzle.internalIndex.delete(
110
111
  this.constructor.collection,
111
112
  this._id,
112
- { refresh });
113
+ { refresh }
114
+ );
113
115
 
114
116
  await this._afterDelete();
115
117
 
@@ -121,10 +123,10 @@ class BaseModel {
121
123
  *
122
124
  * @returns {Object} { _id, _source }
123
125
  */
124
- serialize () {
126
+ serialize() {
125
127
  return {
126
128
  _id: this._id,
127
- _source: this._source
129
+ _source: this._source,
128
130
  };
129
131
  }
130
132
 
@@ -135,25 +137,25 @@ class BaseModel {
135
137
  *
136
138
  * @returns {Promise}
137
139
  */
138
- async _afterDelete () {
140
+ async _afterDelete() {
139
141
  return null;
140
142
  }
141
143
 
142
144
  // Getter/Setter =============================================================
143
145
 
144
- get _id () {
146
+ get _id() {
145
147
  return this.__id;
146
148
  }
147
149
 
148
- set _id (_id) {
150
+ set _id(_id) {
149
151
  this.__id = _id;
150
152
  }
151
153
 
152
- get _source () {
154
+ get _source() {
153
155
  return this.__source;
154
156
  }
155
157
 
156
- set _source (_source) {
158
+ set _source(_source) {
157
159
  for (const key of Object.keys(_source)) {
158
160
  if (this.constructor.fields.includes(key)) {
159
161
  this.__source[key] = _source[key];
@@ -170,10 +172,8 @@ class BaseModel {
170
172
  *
171
173
  * @returns {BaseModel}
172
174
  */
173
- static async load (id) {
174
- const result = await global.kuzzle.internalIndex.get(
175
- this.collection,
176
- id);
175
+ static async load(id) {
176
+ const result = await global.kuzzle.internalIndex.get(this.collection, id);
177
177
 
178
178
  return this._instantiateFromDb(result);
179
179
  }
@@ -187,15 +187,17 @@ class BaseModel {
187
187
  *
188
188
  * @returns {Promise}
189
189
  */
190
- static async deleteByQuery (query, { refresh } = {}) {
190
+ static async deleteByQuery(query, { refresh } = {}) {
191
191
  const { documents } = await global.kuzzle.internalIndex.deleteByQuery(
192
192
  this.collection,
193
- query);
193
+ query
194
+ );
194
195
 
195
196
  await Bluebird.map(
196
197
  documents,
197
- document => this._instantiateFromDb(document)._afterDelete(),
198
- { concurrency: 10 }); // limits the load on storage services
198
+ (document) => this._instantiateFromDb(document)._afterDelete(),
199
+ { concurrency: 10 }
200
+ ); // limits the load on storage services
199
201
 
200
202
  if (refresh) {
201
203
  await global.kuzzle.internalIndex.refreshCollection(this.collection);
@@ -210,13 +212,14 @@ class BaseModel {
210
212
  *
211
213
  * @returns {BaseModel[]} - Array of instances
212
214
  */
213
- static async search (searchBody, options) {
215
+ static async search(searchBody, options) {
214
216
  const resp = await global.kuzzle.internalIndex.search(
215
217
  this.collection,
216
218
  searchBody,
217
- options);
219
+ options
220
+ );
218
221
 
219
- return resp.hits.map(hit => this._instantiateFromDb(hit));
222
+ return resp.hits.map((hit) => this._instantiateFromDb(hit));
220
223
  }
221
224
 
222
225
  /**
@@ -226,29 +229,30 @@ class BaseModel {
226
229
  *
227
230
  * @returns {Promise}
228
231
  */
229
- static truncate ({ refresh } = {}) {
232
+ static truncate({ refresh } = {}) {
230
233
  return this.deleteByQuery({ match_all: {} }, { refresh });
231
234
  }
232
235
 
233
- static batchExecute (query, callback) {
236
+ static batchExecute(query, callback) {
234
237
  return global.kuzzle.internalIndex.mExecute(
235
238
  this.collection,
236
239
  query,
237
- callback);
240
+ callback
241
+ );
238
242
  }
239
243
 
240
244
  /**
241
245
  * Must be overriden by children
242
246
  */
243
- static get collection () {
244
- throw new Error('Model.collection must be defined');
247
+ static get collection() {
248
+ throw new Error("Model.collection must be defined");
245
249
  }
246
250
 
247
251
  /**
248
252
  * Must be overriden by children
249
253
  */
250
- static get fields () {
251
- throw new Error('Model.fields must be defined');
254
+ static get fields() {
255
+ throw new Error("Model.fields must be defined");
252
256
  }
253
257
 
254
258
  // Static protected methods ==================================================
@@ -260,7 +264,7 @@ class BaseModel {
260
264
  *
261
265
  * @returns {BaseModel}
262
266
  */
263
- static _instantiateFromDb ({ _id, _source }) {
267
+ static _instantiateFromDb({ _id, _source }) {
264
268
  const model = new this(_source, _id); // NOSONAR
265
269
 
266
270
  model.__persisted = true;
@@ -19,15 +19,14 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- const { flatten, uniq } = require('lodash');
25
- const Bluebird = require('bluebird');
26
- const IORedis = require('ioredis');
27
-
28
- const kerror = require('../../kerror').wrap('services', 'cache');
29
- const Service = require('../service');
24
+ const { flatten, uniq } = require("lodash");
25
+ const Bluebird = require("bluebird");
26
+ const IORedis = require("ioredis");
30
27
 
28
+ const kerror = require("../../kerror").wrap("services", "cache");
29
+ const Service = require("../service");
31
30
 
32
31
  /**
33
32
  * @class Redis
@@ -36,8 +35,8 @@ const Service = require('../service');
36
35
  * @property service
37
36
  */
38
37
  class Redis extends Service {
39
- constructor (config, name) {
40
- super('redis', config);
38
+ constructor(config, name) {
39
+ super("redis", config);
41
40
 
42
41
  this.connected = false;
43
42
  this.client = null;
@@ -52,30 +51,34 @@ class Redis extends Service {
52
51
  *
53
52
  * @returns {Promise}
54
53
  */
55
- _initSequence () {
54
+ _initSequence() {
56
55
  const config = JSON.parse(JSON.stringify(this._config));
57
56
 
58
57
  // Only way to connect to AWS ELastiCache
59
58
  // https://github.com/luin/ioredis#special-note-aws-elasticache-clusters-with-tls
60
59
  if (config.overrideDnsLookup) {
61
- config.clusterOptions.dnsLookup = (address, callback) => callback(null, address);
60
+ config.clusterOptions.dnsLookup = (address, callback) =>
61
+ callback(null, address);
62
62
  }
63
63
 
64
64
  if (config.nodes) {
65
- this.client = this._buildClusterClient(
66
- { ...config.clusterOptions, redisOptions: config.options });
67
- }
68
- else {
65
+ this.client = this._buildClusterClient({
66
+ ...config.clusterOptions,
67
+ redisOptions: config.options,
68
+ });
69
+ } else {
69
70
  this.client = this._buildClient(config.options);
70
71
  }
71
72
 
72
- this.client.on('ready', () => {
73
+ this.client.on("ready", () => {
73
74
  this.connected = true;
74
75
  });
75
76
 
76
- this.client.on('error', error => {
77
+ this.client.on("error", (error) => {
77
78
  if (this.connected) {
78
- global.kuzzle.log.error(`Redis service seem to be down, see original error for more info:\n${error.message}`);
79
+ global.kuzzle.log.error(
80
+ `Redis service seem to be down, see original error for more info:\n${error.message}`
81
+ );
79
82
  }
80
83
  this.connected = false;
81
84
  });
@@ -87,12 +90,15 @@ class Redis extends Service {
87
90
  }
88
91
 
89
92
  return new Bluebird((resolve, reject) => {
90
- this.client.once('ready', async () => {
91
- await this.client.client('SETNAME', `${this.adapterName}/${global.kuzzle.id}`);
93
+ this.client.once("ready", async () => {
94
+ await this.client.client(
95
+ "SETNAME",
96
+ `${this.adapterName}/${global.kuzzle.id}`
97
+ );
92
98
  resolve();
93
99
  });
94
100
 
95
- this.client.once('error', error => {
101
+ this.client.once("error", (error) => {
96
102
  reject(error);
97
103
  });
98
104
  });
@@ -102,13 +108,13 @@ class Redis extends Service {
102
108
  * Setup a ping interval to keep the connection alive
103
109
  * Every 60 seconds a ping is sent to Redis
104
110
  */
105
- _setupKeepAlive (delay) {
106
- this.client.on('ready', async () => {
111
+ _setupKeepAlive(delay) {
112
+ this.client.on("ready", async () => {
107
113
  await this._ping();
108
114
  this.pingIntervalID = setInterval(this._ping.bind(this), delay);
109
115
  });
110
116
 
111
- this.client.on('error', () => {
117
+ this.client.on("error", () => {
112
118
  clearInterval(this.pingIntervalID);
113
119
  this.pingIntervalID = null;
114
120
  });
@@ -117,25 +123,26 @@ class Redis extends Service {
117
123
  /**
118
124
  * Ping Redis
119
125
  */
120
- async _ping () {
126
+ async _ping() {
121
127
  try {
122
128
  await this.client.ping();
123
- }
124
- catch (error) {
125
- global.kuzzle.log.error(`Failed to PING Redis to keep connection alive:\n${error.message}`);
129
+ } catch (error) {
130
+ global.kuzzle.log.error(
131
+ `Failed to PING Redis to keep connection alive:\n${error.message}`
132
+ );
126
133
  }
127
134
  }
128
135
 
129
136
  /**
130
137
  * Initializes the Redis commands list, and add transformers when necessary
131
138
  */
132
- setCommands () {
139
+ setCommands() {
133
140
  const commandsList = this.client.getBuiltinCommands();
134
141
 
135
142
  for (const command of commandsList) {
136
143
  this.commands[command] = async (...args) => {
137
- if (! this.connected) {
138
- throw kerror.get('notconnected');
144
+ if (!this.connected) {
145
+ throw kerror.get("notconnected");
139
146
  }
140
147
 
141
148
  return this.client[command](...args);
@@ -149,15 +156,15 @@ class Redis extends Service {
149
156
  *
150
157
  * @returns {Promise} service informations
151
158
  */
152
- async info () {
159
+ async info() {
153
160
  const result = await this.commands.info();
154
- const arr = result.replace(/\r\n/g, '\n').split('\n');
161
+ const arr = result.replace(/\r\n/g, "\n").split("\n");
155
162
  const info = {};
156
163
 
157
- arr.forEach(item => {
164
+ arr.forEach((item) => {
158
165
  item = item.trim();
159
- if (item.length > 0 && ! item.startsWith('#')) {
160
- const keyValuePair = item.split(':');
166
+ if (item.length > 0 && !item.startsWith("#")) {
167
+ const keyValuePair = item.split(":");
161
168
  info[keyValuePair[0]] = keyValuePair[1];
162
169
  }
163
170
  });
@@ -166,7 +173,7 @@ class Redis extends Service {
166
173
  memoryPeak: info.used_memory_peak_human,
167
174
  memoryUsed: info.used_memory_human,
168
175
  mode: info.redis_mode,
169
- type: 'redis',
176
+ type: "redis",
170
177
  version: info.redis_version,
171
178
  };
172
179
  }
@@ -181,9 +188,9 @@ class Redis extends Service {
181
188
  * @param pattern
182
189
  * @returns {Promise.<string[]>} promise resolving to an array of keys
183
190
  */
184
- async searchKeys (pattern) {
191
+ async searchKeys(pattern) {
185
192
  if (this.client instanceof IORedis.Cluster) {
186
- const keys = await Bluebird.map(this.client.nodes('master'), node => {
193
+ const keys = await Bluebird.map(this.client.nodes("master"), (node) => {
187
194
  return this._searchNodeKeys(node, pattern);
188
195
  });
189
196
 
@@ -198,36 +205,34 @@ class Redis extends Service {
198
205
  *
199
206
  * @returns {Promise}
200
207
  */
201
- mExecute (commands) {
202
- if (! Array.isArray(commands) || commands.length === 0) {
208
+ mExecute(commands) {
209
+ if (!Array.isArray(commands) || commands.length === 0) {
203
210
  return Bluebird.resolve([]);
204
211
  }
205
212
 
206
- return this.client
207
- .multi(commands)
208
- .exec();
213
+ return this.client.multi(commands).exec();
209
214
  }
210
215
 
211
- _searchNodeKeys (node, pattern) {
212
- return new Bluebird(resolve => {
216
+ _searchNodeKeys(node, pattern) {
217
+ return new Bluebird((resolve) => {
213
218
  let keys = [];
214
219
  const stream = node.scanStream({ match: pattern });
215
220
 
216
- stream.on('data', resultKeys => {
221
+ stream.on("data", (resultKeys) => {
217
222
  keys = keys.concat(resultKeys);
218
223
  });
219
224
 
220
- stream.on('end', () => {
225
+ stream.on("end", () => {
221
226
  resolve(uniq(keys));
222
227
  });
223
228
  });
224
229
  }
225
230
 
226
- _buildClient (options) {
231
+ _buildClient(options) {
227
232
  return new IORedis({ ...this._config.node, ...options });
228
233
  }
229
234
 
230
- _buildClusterClient (options) {
235
+ _buildClusterClient(options) {
231
236
  return new IORedis.Cluster(this._config.nodes, options);
232
237
  }
233
238
 
@@ -243,20 +248,20 @@ class Redis extends Service {
243
248
  * @param {{onlyIfNew: boolean, ttl: number}} [options]
244
249
  * @return {boolean} true if the key was set, false otherwise
245
250
  */
246
- async store (key, value, { onlyIfNew = false, ttl = 0 } = {}) {
251
+ async store(key, value, { onlyIfNew = false, ttl = 0 } = {}) {
247
252
  const command = [key, value];
248
253
 
249
254
  if (onlyIfNew) {
250
- command.push('NX');
255
+ command.push("NX");
251
256
  }
252
257
 
253
258
  if (ttl > 0) {
254
- command.push('PX', ttl);
259
+ command.push("PX", ttl);
255
260
  }
256
261
 
257
262
  const result = await this.commands.set(...command);
258
263
 
259
- return result === 'OK';
264
+ return result === "OK";
260
265
  }
261
266
 
262
267
  /**
@@ -265,7 +270,7 @@ class Redis extends Service {
265
270
  * @param {Array} args
266
271
  * @return {Promise.<*>}
267
272
  */
268
- exec (command, ...args) {
273
+ exec(command, ...args) {
269
274
  return this.commands[command](...args);
270
275
  }
271
276
  }
@@ -19,29 +19,30 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- 'use strict';
22
+ "use strict";
23
23
 
24
- const Bluebird = require('bluebird');
24
+ const Bluebird = require("bluebird");
25
25
 
26
- const kerror = require('../kerror');
26
+ const kerror = require("../kerror");
27
27
 
28
28
  /**
29
29
  * Services base class
30
30
  *
31
31
  */
32
32
  class Service {
33
- constructor (name, config) {
33
+ constructor(name, config) {
34
34
  this._name = name;
35
35
  this._config = config;
36
- this._initTimeout = config.initTimeout
37
- || global.kuzzle.config.services.common.defaultInitTimeout;
36
+ this._initTimeout =
37
+ config.initTimeout ||
38
+ global.kuzzle.config.services.common.defaultInitTimeout;
38
39
  }
39
40
 
40
- get config () {
41
+ get config() {
41
42
  return this._config;
42
43
  }
43
44
 
44
- get name () {
45
+ get name() {
45
46
  return this._name;
46
47
  }
47
48
 
@@ -51,13 +52,12 @@ class Service {
51
52
  *
52
53
  * @returns {Promise}
53
54
  */
54
- init () {
55
- return Bluebird
56
- .resolve(this._initSequence())
55
+ init() {
56
+ return Bluebird.resolve(this._initSequence())
57
57
  .timeout(this._initTimeout)
58
- .catch(e => {
58
+ .catch((e) => {
59
59
  if (e instanceof Bluebird.TimeoutError) {
60
- throw kerror.get('core', 'fatal', 'service_timeout', this._name);
60
+ throw kerror.get("core", "fatal", "service_timeout", this._name);
61
61
  }
62
62
 
63
63
  throw e;
@@ -68,16 +68,16 @@ class Service {
68
68
  * @abstract
69
69
  * @returns {Promise}
70
70
  */
71
- _initSequence () {
72
- throw new Error('Not implemented');
71
+ _initSequence() {
72
+ throw new Error("Not implemented");
73
73
  }
74
74
 
75
75
  /**
76
76
  * @abstract
77
77
  * @returns {Promise}
78
78
  */
79
- info () {
80
- throw new Error('Not implemented');
79
+ info() {
80
+ throw new Error("Not implemented");
81
81
  }
82
82
  }
83
83