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
@@ -21,14 +21,14 @@
21
21
 
22
22
  /* eslint sort-keys: 0 */
23
23
 
24
- 'use strict';
24
+ "use strict";
25
25
 
26
- const kerror = require('../../kerror').wrap('api', 'assert');
26
+ const kerror = require("../../kerror").wrap("api", "assert");
27
27
 
28
- const { Request } = require('../request');
29
- const { NativeController } = require('./baseController');
30
- const kassert = require('../../util/requestAssertions');
31
- const { isPlainObject, has } = require('../../util/safeObject');
28
+ const { Request } = require("../request");
29
+ const { NativeController } = require("./baseController");
30
+ const kassert = require("../../util/requestAssertions");
31
+ const { isPlainObject, has } = require("../../util/safeObject");
32
32
 
33
33
  let mapping;
34
34
 
@@ -36,31 +36,37 @@ let mapping;
36
36
  * @class MemoryStorageController
37
37
  */
38
38
  class MemoryStorageController extends NativeController {
39
- constructor () {
39
+ constructor() {
40
40
  super();
41
41
 
42
42
  initMapping();
43
43
 
44
- const buildCommandFn = command => {
45
- if (command === 'mexecute') {
46
- return async request => global.kuzzle.ask(
47
- 'core:cache:public:mExecute',
48
- extractArgumentsFromRequest(command, request));
44
+ const buildCommandFn = (command) => {
45
+ if (command === "mexecute") {
46
+ return async (request) =>
47
+ global.kuzzle.ask(
48
+ "core:cache:public:mExecute",
49
+ extractArgumentsFromRequest(command, request)
50
+ );
49
51
  }
50
52
 
51
- const largeCommands = [ 'mset', 'mget', 'msetnx' ];
53
+ const largeCommands = ["mset", "mget", "msetnx"];
52
54
 
53
55
  if (largeCommands.includes(command)) {
54
- return async request => global.kuzzle.ask(
55
- 'core:cache:public:execute',
56
- command,
57
- extractArgumentsFromRequest(command, request));
56
+ return async (request) =>
57
+ global.kuzzle.ask(
58
+ "core:cache:public:execute",
59
+ command,
60
+ extractArgumentsFromRequest(command, request)
61
+ );
58
62
  }
59
63
 
60
- return async request => global.kuzzle.ask(
61
- 'core:cache:public:execute',
62
- command,
63
- ...extractArgumentsFromRequest(command, request));
64
+ return async (request) =>
65
+ global.kuzzle.ask(
66
+ "core:cache:public:execute",
67
+ command,
68
+ ...extractArgumentsFromRequest(command, request)
69
+ );
64
70
  };
65
71
 
66
72
  for (const command of Object.keys(mapping)) {
@@ -75,190 +81,198 @@ module.exports = MemoryStorageController;
75
81
  const scanMatchProperty = {
76
82
  skip: true,
77
83
  merge: true,
78
- path: ['args', 'match'],
79
- map: val => {
80
- if (typeof val !== 'string') {
81
- throw kerror.get('invalid_type', 'match', '<string>');
84
+ path: ["args", "match"],
85
+ map: (val) => {
86
+ if (typeof val !== "string") {
87
+ throw kerror.get("invalid_type", "match", "<string>");
82
88
  }
83
89
 
84
- return ['MATCH', val];
85
- }
90
+ return ["MATCH", val];
91
+ },
86
92
  };
87
93
 
88
94
  const scanCountProperty = {
89
95
  skip: true,
90
96
  merge: true,
91
- path: ['args', 'count'],
97
+ path: ["args", "count"],
92
98
  map: (val, request) => {
93
- assertInt(request, 'count', val);
94
- return ['COUNT', val];
95
- }
99
+ assertInt(request, "count", val);
100
+ return ["COUNT", val];
101
+ },
96
102
  };
97
103
 
98
104
  const zrangebyscoreOptionsProperty = {
99
105
  skip: true,
100
106
  merge: true,
101
- map: val => sanitizeArrayArgument(val),
102
- path: ['args', 'options']
107
+ map: (val) => sanitizeArrayArgument(val),
108
+ path: ["args", "options"],
103
109
  };
104
110
 
105
111
  const zrangebyscoreLimitProperty = {
106
112
  skip: true,
107
113
  merge: true,
108
- map: val => processLimit(val),
109
- path: ['args', 'limit']
114
+ map: (val) => processLimit(val),
115
+ path: ["args", "limit"],
110
116
  };
111
117
 
112
- function initMapping () {
118
+ function initMapping() {
113
119
  mapping = {
114
120
  append: {
115
- key: ['resource', '_id'],
116
- value: ['body', 'value']
121
+ key: ["resource", "_id"],
122
+ value: ["body", "value"],
117
123
  },
118
124
  bitcount: {
119
- key: ['resource', '_id'],
120
- start: { skip: true, path: ['args', 'start'] },
121
- end: { skip: true, path: ['args', 'end'] }
125
+ key: ["resource", "_id"],
126
+ start: { skip: true, path: ["args", "start"] },
127
+ end: { skip: true, path: ["args", "end"] },
122
128
  },
123
129
  bitop: {
124
- operation: ['body', 'operation'],
125
- destkey: ['resource', '_id'],
126
- keys: { merge: true, path: ['body', 'keys'] }
130
+ operation: ["body", "operation"],
131
+ destkey: ["resource", "_id"],
132
+ keys: { merge: true, path: ["body", "keys"] },
127
133
  },
128
134
  bitpos: {
129
- key: ['resource', '_id'],
130
- bit: ['args', 'bit'],
131
- start: { skip: true, path: ['args', 'start'] },
132
- end: { skip: true, path: ['args', 'end'] }
135
+ key: ["resource", "_id"],
136
+ bit: ["args", "bit"],
137
+ start: { skip: true, path: ["args", "start"] },
138
+ end: { skip: true, path: ["args", "end"] },
133
139
  },
134
140
  dbsize: null,
135
141
  decrby: {
136
- key: ['resource', '_id'],
137
- value: ['body', 'value']
142
+ key: ["resource", "_id"],
143
+ value: ["body", "value"],
138
144
  },
139
145
  del: {
140
- keys: ['body', 'keys']
146
+ keys: ["body", "keys"],
141
147
  },
142
148
  expire: {
143
- key: ['resource', '_id'],
144
- seconds: ['body', 'seconds']
149
+ key: ["resource", "_id"],
150
+ seconds: ["body", "seconds"],
145
151
  },
146
152
  expireat: {
147
- key: ['resource', '_id'],
148
- timestamp: ['body', 'timestamp']
153
+ key: ["resource", "_id"],
154
+ timestamp: ["body", "timestamp"],
149
155
  },
150
156
  flushdb: null,
151
157
  geoadd: {
152
- key: { path: ['resource', '_id'] },
158
+ key: { path: ["resource", "_id"] },
153
159
  points: {
154
160
  map: (val, request) => {
155
161
  const result = [];
156
162
 
157
- kassert.assertBodyHasAttribute(request, 'points');
158
- kassert.assertBodyAttributeType(request, 'points', 'array');
163
+ kassert.assertBodyHasAttribute(request, "points");
164
+ kassert.assertBodyAttributeType(request, "points", "array");
159
165
 
160
166
  if (val.length === 0) {
161
- throw kerror.get('empty_argument', 'points');
167
+ throw kerror.get("empty_argument", "points");
162
168
  }
163
169
 
164
- val.forEach(v => {
165
- if (typeof v !== 'object' || ! v.lon || ! v.lat || ! v.name) {
166
- throw kerror.get('invalid_argument', 'points', '<array of geopoints>');
170
+ val.forEach((v) => {
171
+ if (typeof v !== "object" || !v.lon || !v.lat || !v.name) {
172
+ throw kerror.get(
173
+ "invalid_argument",
174
+ "points",
175
+ "<array of geopoints>"
176
+ );
167
177
  }
168
178
 
169
- assertFloat(request, 'lon', v.lon);
170
- assertFloat(request, 'lat', v.lat);
179
+ assertFloat(request, "lon", v.lon);
180
+ assertFloat(request, "lat", v.lat);
171
181
 
172
182
  result.push(v.lon, v.lat, v.name);
173
183
  });
174
184
 
175
185
  return result;
176
186
  },
177
- path: ['body', 'points'],
178
- merge: true
179
- }
187
+ path: ["body", "points"],
188
+ merge: true,
189
+ },
180
190
  },
181
191
  geodist: {
182
- key: ['resource', '_id'],
183
- member1: ['args', 'member1'],
184
- member2: ['args', 'member2'],
185
- unit: { skip: true, path: ['args', 'unit'] }
192
+ key: ["resource", "_id"],
193
+ member1: ["args", "member1"],
194
+ member2: ["args", "member2"],
195
+ unit: { skip: true, path: ["args", "unit"] },
186
196
  },
187
197
  geohash: {
188
- key: ['resource', '_id'],
198
+ key: ["resource", "_id"],
189
199
  members: {
190
200
  merge: true,
191
- map: val => toArray(val),
192
- path: ['args', 'members']
193
- }
201
+ map: (val) => toArray(val),
202
+ path: ["args", "members"],
203
+ },
194
204
  },
195
205
  georadius: {
196
- key: ['resource', '_id'],
197
- lon: ['args', 'lon'],
198
- lat: ['args', 'lat'],
199
- distance: ['args', 'distance'],
200
- unit: ['args', 'unit'],
206
+ key: ["resource", "_id"],
207
+ lon: ["args", "lon"],
208
+ lat: ["args", "lat"],
209
+ distance: ["args", "distance"],
210
+ unit: ["args", "unit"],
201
211
  options: {
202
212
  skip: true,
203
213
  merge: true,
204
- map: val => sanitizeArrayArgument(val),
205
- path: ['args', 'options']
206
- }
214
+ map: (val) => sanitizeArrayArgument(val),
215
+ path: ["args", "options"],
216
+ },
207
217
  },
208
218
  georadiusbymember: {
209
- key: ['resource', '_id'],
210
- member: ['args', 'member'],
211
- distance: ['args', 'distance'],
212
- unit: ['args', 'unit'],
219
+ key: ["resource", "_id"],
220
+ member: ["args", "member"],
221
+ distance: ["args", "distance"],
222
+ unit: ["args", "unit"],
213
223
  options: {
214
224
  skip: true,
215
225
  merge: true,
216
- map: val => sanitizeArrayArgument(val),
217
- path: ['args', 'options']
218
- }
226
+ map: (val) => sanitizeArrayArgument(val),
227
+ path: ["args", "options"],
228
+ },
219
229
  },
220
230
  getbit: {
221
- key: ['resource', '_id'],
222
- offset: ['args', 'offset']
231
+ key: ["resource", "_id"],
232
+ offset: ["args", "offset"],
223
233
  },
224
234
  getrange: {
225
- key: ['resource', '_id'],
226
- start: ['args', 'start'],
227
- end: ['args', 'end']
235
+ key: ["resource", "_id"],
236
+ start: ["args", "start"],
237
+ end: ["args", "end"],
228
238
  },
229
239
  hdel: {
230
- key: ['resource', '_id'],
231
- fields: { skip: true, merge: true, path: ['body', 'fields'] }
240
+ key: ["resource", "_id"],
241
+ fields: { skip: true, merge: true, path: ["body", "fields"] },
232
242
  },
233
243
  hmget: {
234
- key: ['resource', '_id'],
244
+ key: ["resource", "_id"],
235
245
  fields: {
236
246
  merge: true,
237
- map: val => toArray(val),
238
- path: ['args', 'fields']
239
- }
247
+ map: (val) => toArray(val),
248
+ path: ["args", "fields"],
249
+ },
240
250
  },
241
251
  hexists: {
242
- key: ['resource', '_id'],
243
- field: ['args', 'field']
252
+ key: ["resource", "_id"],
253
+ field: ["args", "field"],
244
254
  },
245
255
  hincrby: {
246
- key: ['resource', '_id'],
247
- field: ['body', 'field'],
248
- value: ['body', 'value']
256
+ key: ["resource", "_id"],
257
+ field: ["body", "field"],
258
+ value: ["body", "value"],
249
259
  },
250
260
  hmset: {
251
- key: ['resource', '_id'],
261
+ key: ["resource", "_id"],
252
262
  entries: {
253
263
  map: (val, request) => {
254
264
  const result = [];
255
265
 
256
- kassert.assertBodyHasAttribute(request, 'entries');
257
- kassert.assertBodyAttributeType(request, 'entries', 'array');
266
+ kassert.assertBodyHasAttribute(request, "entries");
267
+ kassert.assertBodyAttributeType(request, "entries", "array");
258
268
 
259
- val.forEach(v => {
260
- if (typeof v !== 'object' || ! v.field || ! v.value) {
261
- throw kerror.get('invalid_argument', 'entries', '<array of object>');
269
+ val.forEach((v) => {
270
+ if (typeof v !== "object" || !v.field || !v.value) {
271
+ throw kerror.get(
272
+ "invalid_argument",
273
+ "entries",
274
+ "<array of object>"
275
+ );
262
276
  }
263
277
 
264
278
  result.push(v.field, v.value);
@@ -266,76 +280,80 @@ function initMapping () {
266
280
 
267
281
  return result;
268
282
  },
269
- path: ['body', 'entries'],
270
- merge: true
271
- }
283
+ path: ["body", "entries"],
284
+ merge: true,
285
+ },
272
286
  },
273
287
  hset: {
274
- key: ['resource', '_id'],
275
- field: ['body', 'field'],
276
- value: ['body', 'value']
288
+ key: ["resource", "_id"],
289
+ field: ["body", "field"],
290
+ value: ["body", "value"],
277
291
  },
278
292
  hstrlen: {
279
- key: ['resource', '_id'],
280
- field: ['args', 'field']
293
+ key: ["resource", "_id"],
294
+ field: ["args", "field"],
281
295
  },
282
296
  keys: {
283
- pattern: ['args', 'pattern']
297
+ pattern: ["args", "pattern"],
284
298
  },
285
299
  lindex: {
286
- key: ['resource', '_id'],
287
- index: ['args', 'idx']
300
+ key: ["resource", "_id"],
301
+ index: ["args", "idx"],
288
302
  },
289
303
  linsert: {
290
- key: ['resource', '_id'],
291
- position: ['body', 'position'],
292
- pivot: ['body', 'pivot'],
293
- value: ['body', 'value']
304
+ key: ["resource", "_id"],
305
+ position: ["body", "position"],
306
+ pivot: ["body", "pivot"],
307
+ value: ["body", "value"],
294
308
  },
295
309
  lpush: {
296
- key: ['resource', '_id'],
297
- values: { skip: true, merge: true, path: ['body', 'values'] }
310
+ key: ["resource", "_id"],
311
+ values: { skip: true, merge: true, path: ["body", "values"] },
298
312
  },
299
313
  lrange: {
300
- key: ['resource', '_id'],
301
- start: ['args', 'start'],
302
- stop: ['args', 'stop']
314
+ key: ["resource", "_id"],
315
+ start: ["args", "start"],
316
+ stop: ["args", "stop"],
303
317
  },
304
318
  lrem: {
305
- key: ['resource', '_id'],
306
- count: ['body', 'count'],
307
- value: ['body', 'value']
319
+ key: ["resource", "_id"],
320
+ count: ["body", "count"],
321
+ value: ["body", "value"],
308
322
  },
309
323
  lset: {
310
- key: ['resource', '_id'],
311
- index: ['body', 'index'],
312
- value: ['body', 'value']
324
+ key: ["resource", "_id"],
325
+ index: ["body", "index"],
326
+ value: ["body", "value"],
313
327
  },
314
328
  ltrim: {
315
- key: ['resource', '_id'],
316
- start: ['body', 'start'],
317
- stop: ['body', 'stop']
329
+ key: ["resource", "_id"],
330
+ start: ["body", "start"],
331
+ stop: ["body", "stop"],
318
332
  },
319
333
  mget: {
320
334
  keys: {
321
335
  merge: true,
322
- map: val => toArray(val),
323
- path: ['args', 'keys']
324
- }
336
+ map: (val) => toArray(val),
337
+ path: ["args", "keys"],
338
+ },
325
339
  },
326
340
  mexecute: {
327
- actions: ['body', 'actions']
341
+ actions: ["body", "actions"],
328
342
  },
329
343
  mset: {
330
344
  entries: {
331
345
  map: (val, request) => {
332
346
  const result = [];
333
347
 
334
- kassert.assertBodyHasAttribute(request, 'entries');
335
- kassert.assertBodyAttributeType(request, 'entries', 'array');
336
- val.forEach(entry => {
337
- if (typeof entry !== 'object' || ! entry.key || ! entry.value) {
338
- throw kerror.get('invalid_argument', 'entries', '<array of objects>');
348
+ kassert.assertBodyHasAttribute(request, "entries");
349
+ kassert.assertBodyAttributeType(request, "entries", "array");
350
+ val.forEach((entry) => {
351
+ if (typeof entry !== "object" || !entry.key || !entry.value) {
352
+ throw kerror.get(
353
+ "invalid_argument",
354
+ "entries",
355
+ "<array of objects>"
356
+ );
339
357
  }
340
358
 
341
359
  result.push(entry.key, entry.value);
@@ -343,229 +361,247 @@ function initMapping () {
343
361
 
344
362
  return result;
345
363
  },
346
- path: ['body', 'entries'],
347
- merge: true
348
- }
364
+ path: ["body", "entries"],
365
+ merge: true,
366
+ },
349
367
  },
350
368
  object: {
351
- subcommand: ['args', 'subcommand'],
352
- key: ['resource', '_id']
369
+ subcommand: ["args", "subcommand"],
370
+ key: ["resource", "_id"],
353
371
  },
354
372
  pexpire: {
355
- key: ['resource', '_id'],
356
- milliseconds: ['body', 'milliseconds']
373
+ key: ["resource", "_id"],
374
+ milliseconds: ["body", "milliseconds"],
357
375
  },
358
376
  pexpireat: {
359
- key: ['resource', '_id'],
360
- timestamp: ['body', 'timestamp']
377
+ key: ["resource", "_id"],
378
+ timestamp: ["body", "timestamp"],
361
379
  },
362
380
  pfadd: {
363
- key: ['resource', '_id'],
364
- elements: { skip: true, merge: true, path: ['body', 'elements'] }
381
+ key: ["resource", "_id"],
382
+ elements: { skip: true, merge: true, path: ["body", "elements"] },
365
383
  },
366
384
  pfmerge: {
367
- key: ['resource', '_id'],
368
- sources: { skip: true, merge: true, path: ['body', 'sources'] }
385
+ key: ["resource", "_id"],
386
+ sources: { skip: true, merge: true, path: ["body", "sources"] },
369
387
  },
370
388
  ping: null,
371
389
  psetex: {
372
- key: ['resource', '_id'],
373
- milliseconds: ['body', 'milliseconds'],
374
- value: ['body', 'value']
390
+ key: ["resource", "_id"],
391
+ milliseconds: ["body", "milliseconds"],
392
+ value: ["body", "value"],
375
393
  },
376
394
  randomkey: null,
377
395
  rename: {
378
- key: ['resource', '_id'],
379
- newkey: ['body', 'newkey']
396
+ key: ["resource", "_id"],
397
+ newkey: ["body", "newkey"],
380
398
  },
381
399
  renamenx: {
382
- key: ['resource', '_id'],
383
- newkey: ['body', 'newkey']
400
+ key: ["resource", "_id"],
401
+ newkey: ["body", "newkey"],
384
402
  },
385
403
  rpoplpush: {
386
- source: ['body', 'source'],
387
- destination: ['body', 'destination']
404
+ source: ["body", "source"],
405
+ destination: ["body", "destination"],
388
406
  },
389
407
  sadd: {
390
- key: ['resource', '_id'],
391
- members: { skip: true, merge: true, path: ['body', 'members'] }
408
+ key: ["resource", "_id"],
409
+ members: { skip: true, merge: true, path: ["body", "members"] },
392
410
  },
393
411
  scan: {
394
- cursor: ['args', 'cursor'],
412
+ cursor: ["args", "cursor"],
395
413
  match: scanMatchProperty,
396
- count: scanCountProperty
414
+ count: scanCountProperty,
397
415
  },
398
416
  sdiff: {
399
- key: ['resource', '_id'],
417
+ key: ["resource", "_id"],
400
418
  keys: {
401
419
  merge: true,
402
- map: val => toArray(val),
403
- path: ['args', 'keys']
404
- }
420
+ map: (val) => toArray(val),
421
+ path: ["args", "keys"],
422
+ },
405
423
  },
406
424
  sdiffstore: {
407
- destination: ['body', 'destination'],
408
- key: ['resource', '_id'],
409
- keys: { merge: true, path: ['body', 'keys'] }
425
+ destination: ["body", "destination"],
426
+ key: ["resource", "_id"],
427
+ keys: { merge: true, path: ["body", "keys"] },
410
428
  },
411
429
  set: null, // handled by extractArgumentsFromRequestForSet
412
430
  setex: {
413
- key: ['resource', '_id'],
414
- seconds: ['body', 'seconds'],
415
- value: ['body', 'value']
431
+ key: ["resource", "_id"],
432
+ seconds: ["body", "seconds"],
433
+ value: ["body", "value"],
416
434
  },
417
435
  setnx: {
418
- key: ['resource', '_id'],
419
- value: ['body', 'value']
436
+ key: ["resource", "_id"],
437
+ value: ["body", "value"],
420
438
  },
421
439
  sinterstore: {
422
- destination: ['body', 'destination'],
423
- keys: { merge: true, path: ['body', 'keys'] }
440
+ destination: ["body", "destination"],
441
+ keys: { merge: true, path: ["body", "keys"] },
424
442
  },
425
443
  sismember: {
426
- key: ['resource', '_id'],
427
- member: ['args', 'member']
444
+ key: ["resource", "_id"],
445
+ member: ["args", "member"],
428
446
  },
429
447
  smove: {
430
- key: ['resource', '_id'],
431
- destination: ['body', 'destination'],
432
- member: ['body', 'member']
448
+ key: ["resource", "_id"],
449
+ destination: ["body", "destination"],
450
+ member: ["body", "member"],
433
451
  },
434
452
  sort: null, // handled by extractArgumentsFromRequestForSort
435
453
  spop: {
436
- key: ['resource', '_id'],
437
- count: { skip: true, path: ['body', 'count'] }
454
+ key: ["resource", "_id"],
455
+ count: { skip: true, path: ["body", "count"] },
438
456
  },
439
457
  srandmember: {
440
- key: ['resource', '_id'],
441
- count: { skip: true, path: ['args', 'count'] }
458
+ key: ["resource", "_id"],
459
+ count: { skip: true, path: ["args", "count"] },
442
460
  },
443
461
  srem: {
444
- key: ['resource', '_id'],
445
- members: { skip: true, merge: true, path: ['body', 'members'] }
462
+ key: ["resource", "_id"],
463
+ members: { skip: true, merge: true, path: ["body", "members"] },
446
464
  },
447
465
  sscan: {
448
- key: ['resource', '_id'],
449
- cursor: ['args', 'cursor'],
466
+ key: ["resource", "_id"],
467
+ cursor: ["args", "cursor"],
450
468
  match: scanMatchProperty,
451
- count: scanCountProperty
469
+ count: scanCountProperty,
452
470
  },
453
471
  sunion: {
454
472
  keys: {
455
473
  merge: true,
456
- map: val => toArray(val),
457
- path: ['args', 'keys']
458
- }
474
+ map: (val) => toArray(val),
475
+ path: ["args", "keys"],
476
+ },
459
477
  },
460
478
  sunionstore: {
461
- destination: ['body', 'destination'],
462
- keys: { merge: true, path: ['body', 'keys'] }
479
+ destination: ["body", "destination"],
480
+ keys: { merge: true, path: ["body", "keys"] },
463
481
  },
464
482
  time: null,
465
483
  touch: {
466
- keys: { merge: true, path: ['body', 'keys'] }
484
+ keys: { merge: true, path: ["body", "keys"] },
467
485
  },
468
486
  zadd: null, // handled by extractArgumentsFromRequestForZAdd
469
487
  zcount: {
470
- key: ['resource', '_id'],
471
- min: ['args', 'min'],
472
- max: ['args', 'max']
488
+ key: ["resource", "_id"],
489
+ min: ["args", "min"],
490
+ max: ["args", "max"],
473
491
  },
474
492
  zincrby: {
475
- key: ['resource', '_id'],
476
- value: ['body', 'value'],
477
- member: ['body', 'member']
493
+ key: ["resource", "_id"],
494
+ value: ["body", "value"],
495
+ member: ["body", "member"],
478
496
  },
479
497
  zinterstore: null, // handled by extractArgumentsFromRequestForZInterstore
480
498
  zlexcount: {
481
- key: ['resource', '_id'],
482
- min: ['args', 'min'],
483
- max: ['args', 'max']
499
+ key: ["resource", "_id"],
500
+ min: ["args", "min"],
501
+ max: ["args", "max"],
484
502
  },
485
503
  zrange: {
486
- key: ['resource', '_id'],
487
- start: ['args', 'start'],
488
- stop: ['args', 'stop'],
504
+ key: ["resource", "_id"],
505
+ start: ["args", "start"],
506
+ stop: ["args", "stop"],
489
507
  options: {
490
508
  skip: true,
491
509
  merge: true,
492
- map: val => sanitizeArrayArgument(val),
493
- path: ['args', 'options'] }
510
+ map: (val) => sanitizeArrayArgument(val),
511
+ path: ["args", "options"],
512
+ },
494
513
  },
495
514
  zrangebylex: {
496
- key: ['resource', '_id'],
497
- min: ['args', 'min'],
498
- max: ['args', 'max'],
515
+ key: ["resource", "_id"],
516
+ min: ["args", "min"],
517
+ max: ["args", "max"],
499
518
  limit: {
500
519
  skip: true,
501
520
  merge: true,
502
- map: val => processLimit(val),
503
- path: ['args', 'limit']
504
- }
521
+ map: (val) => processLimit(val),
522
+ path: ["args", "limit"],
523
+ },
505
524
  },
506
525
  zrangebyscore: {
507
- key: ['resource', '_id'],
508
- min: ['args', 'min'],
509
- max: ['args', 'max'],
526
+ key: ["resource", "_id"],
527
+ min: ["args", "min"],
528
+ max: ["args", "max"],
510
529
  options: zrangebyscoreOptionsProperty,
511
- limit: zrangebyscoreLimitProperty
530
+ limit: zrangebyscoreLimitProperty,
512
531
  },
513
532
  zrem: {
514
- key: ['resource', '_id'],
515
- members: { merge: true, path: ['body', 'members'] }
533
+ key: ["resource", "_id"],
534
+ members: { merge: true, path: ["body", "members"] },
516
535
  },
517
536
  zremrangebylex: {
518
- key: ['resource', '_id'],
519
- min: ['body', 'min'],
520
- max: ['body', 'max']
537
+ key: ["resource", "_id"],
538
+ min: ["body", "min"],
539
+ max: ["body", "max"],
521
540
  },
522
541
  zremrangebyrank: {
523
- key: ['resource', '_id'],
524
- min: ['body', 'start'],
525
- max: ['body', 'stop']
542
+ key: ["resource", "_id"],
543
+ min: ["body", "start"],
544
+ max: ["body", "stop"],
526
545
  },
527
546
  zremrangebyscore: {
528
- key: ['resource', '_id'],
529
- min: ['body', 'min'],
530
- max: ['body', 'max']
547
+ key: ["resource", "_id"],
548
+ min: ["body", "min"],
549
+ max: ["body", "max"],
531
550
  },
532
551
  zrevrangebylex: {
533
- key: ['resource', '_id'],
534
- max: ['args', 'max'],
535
- min: ['args', 'min'],
552
+ key: ["resource", "_id"],
553
+ max: ["args", "max"],
554
+ min: ["args", "min"],
536
555
  limit: {
537
556
  skip: true,
538
557
  merge: true,
539
- map: val => processLimit(val),
540
- path: ['args', 'limit']
541
- }
558
+ map: (val) => processLimit(val),
559
+ path: ["args", "limit"],
560
+ },
542
561
  },
543
562
  zrevrangebyscore: {
544
- key: ['resource', '_id'],
545
- max: ['args', 'max'],
546
- min: ['args', 'min'],
563
+ key: ["resource", "_id"],
564
+ max: ["args", "max"],
565
+ min: ["args", "min"],
547
566
  options: zrangebyscoreOptionsProperty,
548
- limit: zrangebyscoreLimitProperty
567
+ limit: zrangebyscoreLimitProperty,
549
568
  },
550
569
  zrevrank: {
551
- key: ['resource', '_id'],
552
- member: ['args', 'member']
570
+ key: ["resource", "_id"],
571
+ member: ["args", "member"],
553
572
  },
554
- zunionstore: null // handled by extractArgumentsFromRequestForZInterstore
573
+ zunionstore: null, // handled by extractArgumentsFromRequestForZInterstore
555
574
  };
556
575
 
557
576
  // unique argument key
558
- mapping.decr = mapping.get = mapping.hgetall = mapping.hkeys =
559
- mapping.hlen = mapping.hvals = mapping.incr = mapping.llen =
560
- mapping.lpop = mapping.persist = mapping.pttl = mapping.rpop =
561
- mapping.scard = mapping.smembers = mapping.strlen = mapping.ttl =
562
- mapping.type = mapping.zcard = { key: ['resource', '_id'] };
577
+ mapping.decr =
578
+ mapping.get =
579
+ mapping.hgetall =
580
+ mapping.hkeys =
581
+ mapping.hlen =
582
+ mapping.hvals =
583
+ mapping.incr =
584
+ mapping.llen =
585
+ mapping.lpop =
586
+ mapping.persist =
587
+ mapping.pttl =
588
+ mapping.rpop =
589
+ mapping.scard =
590
+ mapping.smembers =
591
+ mapping.strlen =
592
+ mapping.ttl =
593
+ mapping.type =
594
+ mapping.zcard =
595
+ { key: ["resource", "_id"] };
563
596
 
564
597
  // key value
565
- mapping.getset = mapping.lpushx = mapping.rpushx = {
566
- key: ['resource', '_id'],
567
- value: ['body', 'value']
568
- };
598
+ mapping.getset =
599
+ mapping.lpushx =
600
+ mapping.rpushx =
601
+ {
602
+ key: ["resource", "_id"],
603
+ value: ["body", "value"],
604
+ };
569
605
 
570
606
  mapping.pfcount = mapping.sinter = mapping.mget;
571
607
 
@@ -587,59 +623,62 @@ function initMapping () {
587
623
  * @param {Request} request
588
624
  * @returns {*}
589
625
  */
590
- function extractArgumentsFromRequest (command, request) {
626
+ function extractArgumentsFromRequest(command, request) {
591
627
  let args = [];
592
628
 
593
629
  // Dealing with exceptions
594
- if (command === 'set') {
630
+ if (command === "set") {
595
631
  return extractArgumentsFromRequestForSet(request);
596
632
  }
597
- if (command === 'sort') {
633
+ if (command === "sort") {
598
634
  return extractArgumentsFromRequestForSort(request);
599
635
  }
600
- if (command === 'zadd') {
636
+ if (command === "zadd") {
601
637
  return extractArgumentsFromRequestForZAdd(request);
602
638
  }
603
- if (command === 'zinterstore') {
639
+ if (command === "zinterstore") {
604
640
  return extractArgumentsFromRequestForZInterstore(request);
605
641
  }
606
- if (command === 'zunionstore') {
642
+ if (command === "zunionstore") {
607
643
  return extractArgumentsFromRequestForZInterstore(request);
608
644
  }
609
- if (command === 'mexecute') {
645
+ if (command === "mexecute") {
610
646
  return extractArgumentsFromRequestForMExecute(request);
611
647
  }
612
648
 
613
- if (! mapping[command]) {
649
+ if (!mapping[command]) {
614
650
  return [];
615
651
  }
616
652
 
617
- if (! request.input.body) {
653
+ if (!request.input.body) {
618
654
  request.input.body = {};
619
655
  }
620
656
 
621
- Object.keys(mapping[command]).forEach(key => {
657
+ Object.keys(mapping[command]).forEach((key) => {
622
658
  const data = mapping[command][key];
623
659
  const path = Array.isArray(data) ? data : data.path;
624
- const toMerge = ! Array.isArray(data) && data.merge === true;
625
- const map = ! Array.isArray(data) && data.map;
626
- const skip = ! Array.isArray(data) && data.skip === true;
660
+ const toMerge = !Array.isArray(data) && data.merge === true;
661
+ const map = !Array.isArray(data) && data.map;
662
+ const skip = !Array.isArray(data) && data.skip === true;
627
663
 
628
664
  let value = path.reduce(
629
665
  (previousValue, currentValue, currentIndex, array) => {
630
- if (previousValue[array[currentIndex]] !== undefined
631
- && previousValue[array[currentIndex]] !== null
666
+ if (
667
+ previousValue[array[currentIndex]] !== undefined &&
668
+ previousValue[array[currentIndex]] !== null
632
669
  ) {
633
670
  return previousValue[array[currentIndex]];
634
671
  }
635
672
  return undefined;
636
- }, request.input);
673
+ },
674
+ request.input
675
+ );
637
676
 
638
677
  if (value === undefined) {
639
678
  if (skip) {
640
679
  return;
641
680
  }
642
- throw kerror.get('missing_argument', key);
681
+ throw kerror.get("missing_argument", key);
643
682
  }
644
683
 
645
684
  if (map) {
@@ -649,8 +688,7 @@ function extractArgumentsFromRequest (command, request) {
649
688
  if (value !== undefined) {
650
689
  if (toMerge && Array.isArray(value)) {
651
690
  args = args.concat(value);
652
- }
653
- else {
691
+ } else {
654
692
  args.push(value);
655
693
  }
656
694
  }
@@ -663,40 +701,44 @@ function extractArgumentsFromRequest (command, request) {
663
701
  * @param {Request} request
664
702
  * @returns {*[]}
665
703
  */
666
- function extractArgumentsFromRequestForSet (request) {
704
+ function extractArgumentsFromRequestForSet(request) {
667
705
  const args = [request.input.args._id];
668
706
 
669
707
  kassert.assertHasId(request);
670
708
  kassert.assertHasBody(request);
671
709
 
672
- if (['undefined', 'boolean', 'object'].indexOf(typeof request.input.body.value) !== -1) {
673
- throw kerror.get('invalid_type', 'value', 'string, number');
710
+ if (
711
+ ["undefined", "boolean", "object"].indexOf(
712
+ typeof request.input.body.value
713
+ ) !== -1
714
+ ) {
715
+ throw kerror.get("invalid_type", "value", "string, number");
674
716
  }
675
717
 
676
718
  if (request.input.body.nx && request.input.body.xx) {
677
- throw kerror.get('mutually_exclusive', 'nx', 'xx');
719
+ throw kerror.get("mutually_exclusive", "nx", "xx");
678
720
  }
679
721
 
680
722
  if (request.input.body.ex && request.input.body.px) {
681
- throw kerror.get('mutually_exclusive', 'ex', 'px');
723
+ throw kerror.get("mutually_exclusive", "ex", "px");
682
724
  }
683
725
 
684
726
  args.push(request.input.body.value);
685
727
 
686
728
  if (request.input.body.ex !== undefined) {
687
- args.push('EX', request.input.body.ex);
729
+ args.push("EX", request.input.body.ex);
688
730
  }
689
731
 
690
732
  if (request.input.body.px !== undefined) {
691
- args.push('PX', request.input.body.px);
733
+ args.push("PX", request.input.body.px);
692
734
  }
693
735
 
694
736
  if (request.input.body.nx) {
695
- args.push('NX');
737
+ args.push("NX");
696
738
  }
697
739
 
698
740
  if (request.input.body.xx) {
699
- args.push('XX');
741
+ args.push("XX");
700
742
  }
701
743
 
702
744
  return args;
@@ -706,52 +748,53 @@ function extractArgumentsFromRequestForSet (request) {
706
748
  * @param {Request} request
707
749
  * @returns {*[]}
708
750
  */
709
- function extractArgumentsFromRequestForSort (request) {
751
+ function extractArgumentsFromRequestForSort(request) {
710
752
  const args = [request.input.args._id];
711
753
 
712
754
  kassert.assertHasId(request);
713
755
 
714
756
  if (request.input.body) {
715
757
  if (request.input.body.alpha) {
716
- args.push('ALPHA');
758
+ args.push("ALPHA");
717
759
  }
718
760
 
719
761
  if (request.input.body.direction !== undefined) {
720
762
  const direction = request.input.body.direction.toUpperCase();
721
763
 
722
- if (['ASC', 'DESC'].indexOf(direction) === -1) {
723
- throw kerror.get('invalid_argument', 'direction', '"ASC", "DESC"');
764
+ if (["ASC", "DESC"].indexOf(direction) === -1) {
765
+ throw kerror.get("invalid_argument", "direction", '"ASC", "DESC"');
724
766
  }
725
767
 
726
768
  args.push(direction);
727
769
  }
728
770
 
729
771
  if (request.input.body.by !== undefined) {
730
- args.push('BY', request.input.body.by);
772
+ args.push("BY", request.input.body.by);
731
773
  }
732
774
 
733
775
  if (request.input.body.limit !== undefined) {
734
- kassert.assertBodyAttributeType(request, 'limit', 'array');
735
- assertInt(request, 'limit.offset', request.input.body.limit[0]);
736
- assertInt(request, 'limit.count', request.input.body.limit[1]);
776
+ kassert.assertBodyAttributeType(request, "limit", "array");
777
+ assertInt(request, "limit.offset", request.input.body.limit[0]);
778
+ assertInt(request, "limit.count", request.input.body.limit[1]);
737
779
 
738
780
  args.push(
739
- 'LIMIT',
781
+ "LIMIT",
740
782
  request.input.body.limit[0],
741
- request.input.body.limit[1]);
783
+ request.input.body.limit[1]
784
+ );
742
785
  }
743
786
 
744
787
  if (request.input.body.get !== undefined) {
745
- kassert.assertBodyAttributeType(request, 'get', 'array');
788
+ kassert.assertBodyAttributeType(request, "get", "array");
746
789
 
747
- request.input.body.get.forEach(pattern => {
748
- args.push('GET');
790
+ request.input.body.get.forEach((pattern) => {
791
+ args.push("GET");
749
792
  args.push(pattern);
750
793
  });
751
794
  }
752
795
 
753
796
  if (request.input.body.store !== undefined) {
754
- args.push('STORE', request.input.body.store);
797
+ args.push("STORE", request.input.body.store);
755
798
  }
756
799
  }
757
800
 
@@ -762,31 +805,34 @@ function extractArgumentsFromRequestForSort (request) {
762
805
  * @param {Request} request
763
806
  * @returns {*[]}
764
807
  */
765
- function extractArgumentsFromRequestForMExecute (request) {
808
+ function extractArgumentsFromRequestForMExecute(request) {
766
809
  kassert.assertHasBody(request);
767
- kassert.assertBodyHasAttribute(request, 'actions');
768
- kassert.assertBodyAttributeType(request, 'actions', 'array');
810
+ kassert.assertBodyHasAttribute(request, "actions");
811
+ kassert.assertBodyAttributeType(request, "actions", "array");
769
812
 
770
813
  const actions = request.input.body.actions;
771
814
 
772
- return actions.map(command => {
773
- if (! has(command, 'action')) {
774
- throw kerror.get('missing_argument', 'action');
815
+ return actions.map((command) => {
816
+ if (!has(command, "action")) {
817
+ throw kerror.get("missing_argument", "action");
775
818
  }
776
- if (! has(command, 'args')) {
777
- throw kerror.get('missing_argument', 'args');
819
+ if (!has(command, "args")) {
820
+ throw kerror.get("missing_argument", "args");
778
821
  }
779
- if (! isPlainObject(command.args)) {
780
- throw kerror.get('invalid_type', 'args', 'object');
822
+ if (!isPlainObject(command.args)) {
823
+ throw kerror.get("invalid_type", "args", "object");
781
824
  }
782
- if (command.action === 'mexecute') {
783
- throw kerror.get('forbidden_argument', 'mexecute');
825
+ if (command.action === "mexecute") {
826
+ throw kerror.get("forbidden_argument", "mexecute");
784
827
  }
785
- if (! has(mapping, command.action)) {
786
- throw kerror.get('forbidden_argument', command.action);
828
+ if (!has(mapping, command.action)) {
829
+ throw kerror.get("forbidden_argument", command.action);
787
830
  }
788
831
  const subRequest = new Request(command.args);
789
- const extractedArguments = extractArgumentsFromRequest(command.action, subRequest);
832
+ const extractedArguments = extractArgumentsFromRequest(
833
+ command.action,
834
+ subRequest
835
+ );
790
836
 
791
837
  return [command.action, ...extractedArguments];
792
838
  });
@@ -796,52 +842,52 @@ function extractArgumentsFromRequestForMExecute (request) {
796
842
  * @param {Request} request
797
843
  * @returns {*[]}
798
844
  */
799
- function extractArgumentsFromRequestForZAdd (request) {
845
+ function extractArgumentsFromRequestForZAdd(request) {
800
846
  const args = [request.input.args._id];
801
847
 
802
848
  kassert.assertHasId(request);
803
849
  kassert.assertHasBody(request);
804
- kassert.assertBodyHasAttribute(request, 'elements');
805
- kassert.assertBodyAttributeType(request, 'elements', 'array');
850
+ kassert.assertBodyHasAttribute(request, "elements");
851
+ kassert.assertBodyAttributeType(request, "elements", "array");
806
852
 
807
853
  if (request.input.body.nx && request.input.body.xx) {
808
- throw kerror.get('mutually_exclusive', 'nx', 'xx');
854
+ throw kerror.get("mutually_exclusive", "nx", "xx");
809
855
  }
810
856
 
811
857
  if (request.input.body.nx) {
812
- args.push('NX');
858
+ args.push("NX");
813
859
  }
814
860
 
815
861
  if (request.input.body.xx) {
816
- args.push('XX');
862
+ args.push("XX");
817
863
  }
818
864
 
819
865
  if (request.input.body.ch) {
820
- args.push('CH');
866
+ args.push("CH");
821
867
  }
822
868
 
823
869
  if (request.input.body.incr) {
824
- args.push('INCR');
870
+ args.push("INCR");
825
871
  }
826
872
 
827
873
  if (request.input.body.elements.length === 0) {
828
- throw kerror.get('empty_argument', 'elements');
874
+ throw kerror.get("empty_argument", "elements");
829
875
  }
830
876
 
831
877
  if (request.input.body.incr && request.input.body.elements.length > 1) {
832
- throw kerror.get('too_many_arguments', 'elements');
878
+ throw kerror.get("too_many_arguments", "elements");
833
879
  }
834
880
 
835
881
  request.input.body.elements.forEach((element, index) => {
836
- if (! isPlainObject(element)) {
837
- throw kerror.get('invalid_argument', 'elements', '<array of objects>');
882
+ if (!isPlainObject(element)) {
883
+ throw kerror.get("invalid_argument", "elements", "<array of objects>");
838
884
  }
839
885
 
840
- if (! element.member) {
841
- throw kerror.get('missing_argument', `elements[${index}].member`);
886
+ if (!element.member) {
887
+ throw kerror.get("missing_argument", `elements[${index}].member`);
842
888
  }
843
889
 
844
- assertFloat(request, 'score', element.score);
890
+ assertFloat(request, "score", element.score);
845
891
 
846
892
  args.push(element.score);
847
893
  args.push(element.member);
@@ -854,40 +900,44 @@ function extractArgumentsFromRequestForZAdd (request) {
854
900
  * @param {Request} request
855
901
  * @returns {*[]}
856
902
  */
857
- function extractArgumentsFromRequestForZInterstore (request) {
903
+ function extractArgumentsFromRequestForZInterstore(request) {
858
904
  let args = [request.input.args._id];
859
905
 
860
906
  kassert.assertHasId(request);
861
907
  kassert.assertHasBody(request);
862
- kassert.assertBodyHasAttribute(request, 'keys');
863
- kassert.assertBodyAttributeType(request, 'keys', 'array');
908
+ kassert.assertBodyHasAttribute(request, "keys");
909
+ kassert.assertBodyAttributeType(request, "keys", "array");
864
910
 
865
911
  if (request.input.body.keys.length === 0) {
866
- throw kerror.get('empty_argument', 'keys');
912
+ throw kerror.get("empty_argument", "keys");
867
913
  }
868
914
 
869
915
  args.push(request.input.body.keys.length);
870
916
  args = args.concat(request.input.body.keys);
871
917
 
872
918
  if (request.input.body.weights) {
873
- kassert.assertBodyAttributeType(request, 'weights', 'array');
919
+ kassert.assertBodyAttributeType(request, "weights", "array");
874
920
 
875
921
  if (request.input.body.weights.length > 0) {
876
- args.push('WEIGHTS');
922
+ args.push("WEIGHTS");
877
923
  args = args.concat(request.input.body.weights);
878
924
  }
879
925
  }
880
926
 
881
927
  if (request.input.body.aggregate) {
882
- kassert.assertBodyAttributeType(request, 'aggregate', 'string');
928
+ kassert.assertBodyAttributeType(request, "aggregate", "string");
883
929
 
884
930
  const aggregate = request.input.body.aggregate.toUpperCase();
885
931
 
886
- if (['SUM', 'MIN', 'MAX'].indexOf(aggregate) === -1) {
887
- throw kerror.get('invalid_argument', 'aggregate', '"SUM", "MIN" or "MAX"');
932
+ if (["SUM", "MIN", "MAX"].indexOf(aggregate) === -1) {
933
+ throw kerror.get(
934
+ "invalid_argument",
935
+ "aggregate",
936
+ '"SUM", "MIN" or "MAX"'
937
+ );
888
938
  }
889
939
 
890
- args.push('AGGREGATE', aggregate);
940
+ args.push("AGGREGATE", aggregate);
891
941
  }
892
942
 
893
943
  return args;
@@ -902,10 +952,10 @@ function extractArgumentsFromRequestForZInterstore (request) {
902
952
  * @param {*} value of the tested parameter
903
953
  * @throws
904
954
  */
905
- function assertFloat (request, name, value) {
955
+ function assertFloat(request, name, value) {
906
956
  // Number.parseXxx computes the 1st member of an array if one is provided
907
957
  if (Array.isArray(value) || Number.isNaN(Number.parseFloat(value))) {
908
- throw kerror.get('invalid_type', name, 'number');
958
+ throw kerror.get("invalid_type", name, "number");
909
959
  }
910
960
  }
911
961
 
@@ -918,10 +968,10 @@ function assertFloat (request, name, value) {
918
968
  * @param {*} value of the tested parameter
919
969
  * @throws
920
970
  */
921
- function assertInt (request, name, value) {
971
+ function assertInt(request, name, value) {
922
972
  // Number.parseXxx computes the 1st member of an array if one is provided
923
973
  if (Array.isArray(value) || Number.isNaN(Number.parseInt(value))) {
924
- throw kerror.get('invalid_type', name, 'integer');
974
+ throw kerror.get("invalid_type", name, "integer");
925
975
  }
926
976
  }
927
977
 
@@ -931,8 +981,8 @@ function assertInt (request, name, value) {
931
981
  * @param {Array|String} arg
932
982
  * @returns {Array}
933
983
  */
934
- function toArray (arg) {
935
- return typeof arg === 'string' ? arg.split(',') : arg;
984
+ function toArray(arg) {
985
+ return typeof arg === "string" ? arg.split(",") : arg;
936
986
  }
937
987
 
938
988
  /**
@@ -940,10 +990,10 @@ function toArray (arg) {
940
990
  * @param {Array|String} arg
941
991
  * @returns {Array}
942
992
  */
943
- function sanitizeArrayArgument (arg) {
993
+ function sanitizeArrayArgument(arg) {
944
994
  const result = toArray(arg);
945
995
 
946
- return result.map(v => typeof v === 'string' ? v.toUpperCase() : v);
996
+ return result.map((v) => (typeof v === "string" ? v.toUpperCase() : v));
947
997
  }
948
998
 
949
999
  /**
@@ -951,14 +1001,14 @@ function sanitizeArrayArgument (arg) {
951
1001
  * @param {Array} arg
952
1002
  * @throws
953
1003
  */
954
- function processLimit (arg) {
955
- let result = ['LIMIT'];
1004
+ function processLimit(arg) {
1005
+ let result = ["LIMIT"];
956
1006
 
957
1007
  result = result.concat(toArray(arg));
958
1008
 
959
1009
  // "result" should contain LIMIT offset count
960
1010
  if (result.length !== 3) {
961
- throw kerror.get('invalid_argument', 'limit', '<offset, count>');
1011
+ throw kerror.get("invalid_argument", "limit", "<offset, count>");
962
1012
  }
963
1013
 
964
1014
  return result;