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.
- package/lib/api/controllers/adminController.js +94 -80
- package/lib/api/controllers/authController.js +239 -212
- package/lib/api/controllers/baseController.js +89 -51
- package/lib/api/controllers/bulkController.js +62 -49
- package/lib/api/controllers/clusterController.js +6 -8
- package/lib/api/controllers/collectionController.js +140 -129
- package/lib/api/controllers/debugController.d.ts +2 -2
- package/lib/api/controllers/debugController.js +33 -31
- package/lib/api/controllers/documentController.js +365 -274
- package/lib/api/controllers/index.js +13 -13
- package/lib/api/controllers/indexController.js +46 -50
- package/lib/api/controllers/memoryStorageController.js +410 -360
- package/lib/api/controllers/realtimeController.js +37 -36
- package/lib/api/controllers/securityController.js +553 -412
- package/lib/api/controllers/serverController.js +111 -104
- package/lib/api/documentExtractor.js +75 -68
- package/lib/api/funnel.js +411 -312
- package/lib/api/httpRoutes.js +1493 -324
- package/lib/api/openapi/OpenApiManager.d.ts +1 -1
- package/lib/api/openapi/OpenApiManager.js +22 -22
- package/lib/api/openapi/components/document/count.yaml +1 -1
- package/lib/api/openapi/components/document/create.yaml +2 -2
- package/lib/api/openapi/components/document/delete.yaml +1 -1
- package/lib/api/openapi/components/document/deleteByQuery.yaml +1 -1
- package/lib/api/openapi/components/document/exists.yaml +1 -1
- package/lib/api/openapi/components/document/get.yaml +2 -2
- package/lib/api/openapi/components/document/index.js +12 -12
- package/lib/api/openapi/components/document/replace.yaml +1 -1
- package/lib/api/openapi/components/document/scroll.yaml +1 -1
- package/lib/api/openapi/components/document/validate.yaml +1 -1
- package/lib/api/openapi/components/index.d.ts +2 -2
- package/lib/api/openapi/components/index.js +1 -1
- package/lib/api/openapi/components/security/index.js +1 -1
- package/lib/api/openapi/components/security/upsertUser.yaml +2 -3
- package/lib/api/openapi/index.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.js +7 -7
- package/lib/api/rateLimiter.js +12 -13
- package/lib/api/request/index.d.ts +4 -4
- package/lib/api/request/kuzzleRequest.d.ts +9 -9
- package/lib/api/request/kuzzleRequest.js +89 -87
- package/lib/api/request/requestContext.d.ts +2 -2
- package/lib/api/request/requestContext.js +17 -17
- package/lib/api/request/requestInput.d.ts +1 -1
- package/lib/api/request/requestInput.js +19 -19
- package/lib/api/request/requestResponse.d.ts +4 -4
- package/lib/api/request/requestResponse.js +31 -33
- package/lib/cluster/command.js +48 -44
- package/lib/cluster/idCardHandler.d.ts +1 -1
- package/lib/cluster/idCardHandler.js +15 -15
- package/lib/cluster/index.js +2 -2
- package/lib/cluster/node.js +301 -269
- package/lib/cluster/publisher.js +45 -46
- package/lib/cluster/state.d.ts +5 -5
- package/lib/cluster/state.js +8 -8
- package/lib/cluster/subscriber.js +163 -113
- package/lib/cluster/workers/IDCardRenewer.js +33 -32
- package/lib/config/default.config.d.ts +1 -1
- package/lib/config/default.config.js +212 -171
- package/lib/config/documentEventAliases.js +6 -6
- package/lib/config/index.js +161 -98
- package/lib/config/sdkCompatibility.json +8 -8
- package/lib/core/auth/formatProcessing.js +7 -7
- package/lib/core/auth/passportResponse.js +7 -7
- package/lib/core/auth/passportWrapper.js +34 -30
- package/lib/core/auth/tokenManager.d.ts +2 -2
- package/lib/core/auth/tokenManager.js +11 -10
- package/lib/core/backend/applicationManager.d.ts +1 -1
- package/lib/core/backend/applicationManager.js +2 -2
- package/lib/core/backend/backend.d.ts +3 -3
- package/lib/core/backend/backend.js +34 -31
- package/lib/core/backend/backendCluster.d.ts +2 -2
- package/lib/core/backend/backendCluster.js +5 -5
- package/lib/core/backend/backendConfig.d.ts +2 -2
- package/lib/core/backend/backendConfig.js +3 -3
- package/lib/core/backend/backendController.d.ts +2 -2
- package/lib/core/backend/backendController.js +9 -10
- package/lib/core/backend/backendErrors.d.ts +3 -3
- package/lib/core/backend/backendErrors.js +2 -1
- package/lib/core/backend/backendHook.d.ts +2 -2
- package/lib/core/backend/backendHook.js +5 -5
- package/lib/core/backend/backendImport.d.ts +3 -3
- package/lib/core/backend/backendImport.js +23 -23
- package/lib/core/backend/backendOpenApi.d.ts +2 -2
- package/lib/core/backend/backendOpenApi.js +16 -16
- package/lib/core/backend/backendPipe.d.ts +2 -2
- package/lib/core/backend/backendPipe.js +6 -6
- package/lib/core/backend/backendPlugin.d.ts +4 -4
- package/lib/core/backend/backendPlugin.js +14 -14
- package/lib/core/backend/backendStorage.d.ts +2 -2
- package/lib/core/backend/backendStorage.js +1 -2
- package/lib/core/backend/backendVault.d.ts +2 -2
- package/lib/core/backend/backendVault.js +3 -3
- package/lib/core/backend/index.d.ts +14 -14
- package/lib/core/backend/internalLogger.d.ts +1 -1
- package/lib/core/backend/internalLogger.js +5 -5
- package/lib/core/cache/cacheDbEnum.js +4 -4
- package/lib/core/cache/cacheEngine.js +79 -85
- package/lib/core/network/accessLogger.js +126 -120
- package/lib/core/network/clientConnection.js +5 -5
- package/lib/core/network/context.js +8 -8
- package/lib/core/network/entryPoint.js +100 -85
- package/lib/core/network/httpRouter/index.js +63 -60
- package/lib/core/network/httpRouter/routeHandler.js +18 -19
- package/lib/core/network/httpRouter/routePart.js +23 -19
- package/lib/core/network/protocolManifest.js +3 -3
- package/lib/core/network/protocols/httpMessage.js +8 -10
- package/lib/core/network/protocols/httpwsProtocol.js +305 -250
- package/lib/core/network/protocols/internalProtocol.js +27 -24
- package/lib/core/network/protocols/mqttProtocol.js +106 -96
- package/lib/core/network/protocols/protocol.js +20 -17
- package/lib/core/network/router.js +56 -46
- package/lib/core/plugin/plugin.js +151 -120
- package/lib/core/plugin/pluginContext.d.ts +7 -7
- package/lib/core/plugin/pluginContext.js +48 -44
- package/lib/core/plugin/pluginManifest.js +13 -12
- package/lib/core/plugin/pluginRepository.js +26 -27
- package/lib/core/plugin/pluginsManager.js +425 -304
- package/lib/core/plugin/privilegedContext.js +3 -3
- package/lib/core/realtime/actionEnum.js +1 -1
- package/lib/core/realtime/channel.d.ts +1 -1
- package/lib/core/realtime/channel.js +22 -22
- package/lib/core/realtime/connectionRooms.d.ts +1 -1
- package/lib/core/realtime/hotelClerk.d.ts +2 -2
- package/lib/core/realtime/hotelClerk.js +53 -50
- package/lib/core/realtime/index.js +5 -5
- package/lib/core/realtime/notification/document.js +25 -25
- package/lib/core/realtime/notification/index.js +4 -4
- package/lib/core/realtime/notification/server.js +3 -3
- package/lib/core/realtime/notification/user.js +4 -4
- package/lib/core/realtime/notifier.js +113 -75
- package/lib/core/realtime/room.d.ts +1 -1
- package/lib/core/realtime/subscription.d.ts +1 -1
- package/lib/core/realtime/subscription.js +1 -1
- package/lib/core/security/index.js +8 -8
- package/lib/core/security/profileRepository.d.ts +6 -6
- package/lib/core/security/profileRepository.js +48 -45
- package/lib/core/security/roleRepository.js +127 -115
- package/lib/core/security/securityLoader.js +70 -63
- package/lib/core/security/tokenRepository.js +132 -118
- package/lib/core/security/userRepository.js +104 -88
- package/lib/core/shared/KoncordeWrapper.d.ts +1 -1
- package/lib/core/shared/KoncordeWrapper.js +3 -1
- package/lib/core/shared/abstractManifest.js +22 -23
- package/lib/core/shared/repository.js +69 -67
- package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
- package/lib/core/shared/sdk/embeddedSdk.js +36 -32
- package/lib/core/shared/sdk/funnelProtocol.d.ts +1 -1
- package/lib/core/shared/sdk/funnelProtocol.js +11 -11
- package/lib/core/shared/sdk/impersonatedSdk.js +19 -18
- package/lib/core/shared/store.js +127 -32
- package/lib/core/statistics/index.js +2 -2
- package/lib/core/statistics/statistics.js +99 -85
- package/lib/core/storage/clientAdapter.js +219 -136
- package/lib/core/storage/indexCache.js +3 -3
- package/lib/core/storage/storageEngine.js +10 -13
- package/lib/core/storage/storeScopeEnum.js +3 -3
- package/lib/core/validation/baseType.js +12 -10
- package/lib/core/validation/index.js +2 -2
- package/lib/core/validation/types/anything.js +4 -4
- package/lib/core/validation/types/boolean.js +7 -7
- package/lib/core/validation/types/date.js +165 -131
- package/lib/core/validation/types/email.js +18 -21
- package/lib/core/validation/types/enum.js +34 -21
- package/lib/core/validation/types/geoPoint.js +7 -7
- package/lib/core/validation/types/geoShape.js +148 -125
- package/lib/core/validation/types/integer.js +9 -9
- package/lib/core/validation/types/ipAddress.js +17 -19
- package/lib/core/validation/types/numeric.js +36 -29
- package/lib/core/validation/types/object.js +19 -19
- package/lib/core/validation/types/string.js +36 -29
- package/lib/core/validation/types/url.js +17 -19
- package/lib/core/validation/validation.js +422 -378
- package/lib/kerror/codes/1-services.json +7 -1
- package/lib/kerror/codes/4-plugin.json +2 -2
- package/lib/kerror/codes/index.js +85 -63
- package/lib/kerror/errors/badRequestError.d.ts +1 -1
- package/lib/kerror/errors/externalServiceError.d.ts +1 -1
- package/lib/kerror/errors/forbiddenError.d.ts +1 -1
- package/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
- package/lib/kerror/errors/index.d.ts +15 -15
- package/lib/kerror/errors/internalError.d.ts +1 -1
- package/lib/kerror/errors/kuzzleError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.js +1 -1
- package/lib/kerror/errors/notFoundError.d.ts +1 -1
- package/lib/kerror/errors/partialError.d.ts +1 -1
- package/lib/kerror/errors/partialError.js +1 -1
- package/lib/kerror/errors/pluginImplementationError.d.ts +1 -1
- package/lib/kerror/errors/pluginImplementationError.js +2 -1
- package/lib/kerror/errors/preconditionError.d.ts +1 -1
- package/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
- package/lib/kerror/errors/sizeLimitError.d.ts +1 -1
- package/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
- package/lib/kerror/errors/unauthorizedError.d.ts +1 -1
- package/lib/kerror/index.d.ts +3 -3
- package/lib/kerror/index.js +17 -16
- package/lib/kuzzle/dumpGenerator.js +130 -114
- package/lib/kuzzle/event/kuzzleEventEmitter.js +96 -70
- package/lib/kuzzle/event/pipeRunner.js +25 -24
- package/lib/kuzzle/event/waterfall.js +13 -15
- package/lib/kuzzle/index.js +2 -2
- package/lib/kuzzle/internalIndexHandler.js +80 -59
- package/lib/kuzzle/kuzzle.js +99 -99
- package/lib/kuzzle/kuzzleStateEnum.js +1 -1
- package/lib/kuzzle/log.js +23 -18
- package/lib/kuzzle/vault.js +34 -19
- package/lib/model/security/profile.d.ts +3 -3
- package/lib/model/security/profile.js +38 -37
- package/lib/model/security/rights.js +5 -5
- package/lib/model/security/role.d.ts +3 -3
- package/lib/model/security/role.js +25 -26
- package/lib/model/security/token.d.ts +1 -1
- package/lib/model/security/token.js +4 -4
- package/lib/model/security/user.d.ts +2 -2
- package/lib/model/security/user.js +9 -9
- package/lib/model/storage/apiKey.js +43 -33
- package/lib/model/storage/baseModel.js +49 -45
- package/lib/service/cache/redis.js +60 -55
- package/lib/service/service.js +17 -17
- package/lib/service/storage/elasticsearch.js +839 -755
- package/lib/service/storage/esWrapper.js +103 -86
- package/lib/service/storage/queryTranslator.js +52 -59
- package/lib/types/Controller.d.ts +3 -3
- package/lib/types/ControllerDefinition.d.ts +3 -3
- package/lib/types/DebugModule.d.ts +2 -2
- package/lib/types/DebugModule.js +1 -1
- package/lib/types/Global.d.ts +1 -1
- package/lib/types/HttpStream.d.ts +2 -1
- package/lib/types/HttpStream.js +7 -5
- package/lib/types/Kuzzle.d.ts +1 -1
- package/lib/types/KuzzleDocument.d.ts +1 -1
- package/lib/types/OpenApiDefinition.d.ts +1 -1
- package/lib/types/PasswordPolicy.d.ts +1 -1
- package/lib/types/Plugin.d.ts +6 -6
- package/lib/types/Plugin.js +2 -2
- package/lib/types/Policy.d.ts +1 -1
- package/lib/types/RequestPayload.d.ts +1 -1
- package/lib/types/ResponsePayload.d.ts +1 -1
- package/lib/types/Token.d.ts +1 -1
- package/lib/types/User.d.ts +1 -1
- package/lib/types/config/DumpConfiguration.d.ts +8 -8
- package/lib/types/config/HttpConfiguration.d.ts +1 -1
- package/lib/types/config/KuzzleConfiguration.d.ts +1 -1
- package/lib/types/config/LimitsConfiguration.d.ts +8 -8
- package/lib/types/config/PluginsConfiguration.d.ts +4 -4
- package/lib/types/config/SecurityConfiguration.d.ts +62 -62
- package/lib/types/config/ServerConfiguration.d.ts +55 -55
- package/lib/types/config/ServicesConfiguration.d.ts +2 -2
- package/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +10 -10
- package/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +3 -3
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +194 -110
- package/lib/types/errors/ErrorDefinition.d.ts +1 -1
- package/lib/types/errors/ErrorDomains.d.ts +1 -1
- package/lib/types/index.d.ts +38 -38
- package/lib/types/realtime/RealtimeScope.d.ts +1 -1
- package/lib/types/realtime/RealtimeUsers.d.ts +1 -1
- package/lib/util/assertType.js +13 -11
- package/lib/util/async.d.ts +1 -0
- package/lib/util/async.js +61 -0
- package/lib/util/asyncStore.js +19 -21
- package/lib/util/bufferedPassThrough.d.ts +2 -2
- package/lib/util/bufferedPassThrough.js +4 -4
- package/lib/util/bytes.js +9 -13
- package/lib/util/crypto.js +1 -1
- package/lib/util/debug.js +5 -5
- package/lib/util/deprecate.js +24 -21
- package/lib/util/didYouMean.js +7 -7
- package/lib/util/dump-collection.d.ts +2 -2
- package/lib/util/dump-collection.js +26 -26
- package/lib/util/esRequest.d.ts +1 -0
- package/lib/util/esRequest.js +62 -0
- package/lib/util/extractFields.js +24 -25
- package/lib/util/inflector.js +5 -5
- package/lib/util/koncordeCompat.d.ts +2 -2
- package/lib/util/koncordeCompat.js +5 -5
- package/lib/util/memoize.js +3 -5
- package/lib/util/mutex.d.ts +19 -1
- package/lib/util/mutex.js +39 -12
- package/lib/util/name-generator.js +1331 -1331
- package/lib/util/promback.js +8 -10
- package/lib/util/readYamlFile.d.ts +1 -1
- package/lib/util/readYamlFile.js +1 -1
- package/lib/util/requestAssertions.js +34 -34
- package/lib/util/safeObject.js +5 -5
- package/lib/util/stackTrace.js +20 -22
- package/lib/util/wildcard.js +15 -15
- package/package.json +6 -6
- package/npm-shrinkwrap.json +0 -19422
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
|
|
22
22
|
/* eslint sort-keys: 0 */
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
"use strict";
|
|
25
25
|
|
|
26
|
-
const kerror = require(
|
|
26
|
+
const kerror = require("../../kerror").wrap("api", "assert");
|
|
27
27
|
|
|
28
|
-
const { Request } = require(
|
|
29
|
-
const { NativeController } = require(
|
|
30
|
-
const kassert = require(
|
|
31
|
-
const { isPlainObject, has } = require(
|
|
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 ===
|
|
46
|
-
return async request =>
|
|
47
|
-
|
|
48
|
-
|
|
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 = [
|
|
53
|
+
const largeCommands = ["mset", "mget", "msetnx"];
|
|
52
54
|
|
|
53
55
|
if (largeCommands.includes(command)) {
|
|
54
|
-
return async request =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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 =>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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: [
|
|
79
|
-
map: val => {
|
|
80
|
-
if (typeof val !==
|
|
81
|
-
throw kerror.get(
|
|
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 [
|
|
85
|
-
}
|
|
90
|
+
return ["MATCH", val];
|
|
91
|
+
},
|
|
86
92
|
};
|
|
87
93
|
|
|
88
94
|
const scanCountProperty = {
|
|
89
95
|
skip: true,
|
|
90
96
|
merge: true,
|
|
91
|
-
path: [
|
|
97
|
+
path: ["args", "count"],
|
|
92
98
|
map: (val, request) => {
|
|
93
|
-
assertInt(request,
|
|
94
|
-
return [
|
|
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: [
|
|
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: [
|
|
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: [
|
|
116
|
-
value: [
|
|
121
|
+
key: ["resource", "_id"],
|
|
122
|
+
value: ["body", "value"],
|
|
117
123
|
},
|
|
118
124
|
bitcount: {
|
|
119
|
-
key: [
|
|
120
|
-
start: { skip: true, path: [
|
|
121
|
-
end: { skip: true, path: [
|
|
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: [
|
|
125
|
-
destkey: [
|
|
126
|
-
keys: { merge: true, path: [
|
|
130
|
+
operation: ["body", "operation"],
|
|
131
|
+
destkey: ["resource", "_id"],
|
|
132
|
+
keys: { merge: true, path: ["body", "keys"] },
|
|
127
133
|
},
|
|
128
134
|
bitpos: {
|
|
129
|
-
key: [
|
|
130
|
-
bit: [
|
|
131
|
-
start: { skip: true, path: [
|
|
132
|
-
end: { skip: true, path: [
|
|
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: [
|
|
137
|
-
value: [
|
|
142
|
+
key: ["resource", "_id"],
|
|
143
|
+
value: ["body", "value"],
|
|
138
144
|
},
|
|
139
145
|
del: {
|
|
140
|
-
keys: [
|
|
146
|
+
keys: ["body", "keys"],
|
|
141
147
|
},
|
|
142
148
|
expire: {
|
|
143
|
-
key: [
|
|
144
|
-
seconds: [
|
|
149
|
+
key: ["resource", "_id"],
|
|
150
|
+
seconds: ["body", "seconds"],
|
|
145
151
|
},
|
|
146
152
|
expireat: {
|
|
147
|
-
key: [
|
|
148
|
-
timestamp: [
|
|
153
|
+
key: ["resource", "_id"],
|
|
154
|
+
timestamp: ["body", "timestamp"],
|
|
149
155
|
},
|
|
150
156
|
flushdb: null,
|
|
151
157
|
geoadd: {
|
|
152
|
-
key: { path: [
|
|
158
|
+
key: { path: ["resource", "_id"] },
|
|
153
159
|
points: {
|
|
154
160
|
map: (val, request) => {
|
|
155
161
|
const result = [];
|
|
156
162
|
|
|
157
|
-
kassert.assertBodyHasAttribute(request,
|
|
158
|
-
kassert.assertBodyAttributeType(request,
|
|
163
|
+
kassert.assertBodyHasAttribute(request, "points");
|
|
164
|
+
kassert.assertBodyAttributeType(request, "points", "array");
|
|
159
165
|
|
|
160
166
|
if (val.length === 0) {
|
|
161
|
-
throw kerror.get(
|
|
167
|
+
throw kerror.get("empty_argument", "points");
|
|
162
168
|
}
|
|
163
169
|
|
|
164
|
-
val.forEach(v => {
|
|
165
|
-
if (typeof v !==
|
|
166
|
-
throw kerror.get(
|
|
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,
|
|
170
|
-
assertFloat(request,
|
|
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: [
|
|
178
|
-
merge: true
|
|
179
|
-
}
|
|
187
|
+
path: ["body", "points"],
|
|
188
|
+
merge: true,
|
|
189
|
+
},
|
|
180
190
|
},
|
|
181
191
|
geodist: {
|
|
182
|
-
key: [
|
|
183
|
-
member1: [
|
|
184
|
-
member2: [
|
|
185
|
-
unit: { skip: true, path: [
|
|
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: [
|
|
198
|
+
key: ["resource", "_id"],
|
|
189
199
|
members: {
|
|
190
200
|
merge: true,
|
|
191
|
-
map: val => toArray(val),
|
|
192
|
-
path: [
|
|
193
|
-
}
|
|
201
|
+
map: (val) => toArray(val),
|
|
202
|
+
path: ["args", "members"],
|
|
203
|
+
},
|
|
194
204
|
},
|
|
195
205
|
georadius: {
|
|
196
|
-
key: [
|
|
197
|
-
lon: [
|
|
198
|
-
lat: [
|
|
199
|
-
distance: [
|
|
200
|
-
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: [
|
|
206
|
-
}
|
|
214
|
+
map: (val) => sanitizeArrayArgument(val),
|
|
215
|
+
path: ["args", "options"],
|
|
216
|
+
},
|
|
207
217
|
},
|
|
208
218
|
georadiusbymember: {
|
|
209
|
-
key: [
|
|
210
|
-
member: [
|
|
211
|
-
distance: [
|
|
212
|
-
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: [
|
|
218
|
-
}
|
|
226
|
+
map: (val) => sanitizeArrayArgument(val),
|
|
227
|
+
path: ["args", "options"],
|
|
228
|
+
},
|
|
219
229
|
},
|
|
220
230
|
getbit: {
|
|
221
|
-
key: [
|
|
222
|
-
offset: [
|
|
231
|
+
key: ["resource", "_id"],
|
|
232
|
+
offset: ["args", "offset"],
|
|
223
233
|
},
|
|
224
234
|
getrange: {
|
|
225
|
-
key: [
|
|
226
|
-
start: [
|
|
227
|
-
end: [
|
|
235
|
+
key: ["resource", "_id"],
|
|
236
|
+
start: ["args", "start"],
|
|
237
|
+
end: ["args", "end"],
|
|
228
238
|
},
|
|
229
239
|
hdel: {
|
|
230
|
-
key: [
|
|
231
|
-
fields: { skip: true, merge: true, path: [
|
|
240
|
+
key: ["resource", "_id"],
|
|
241
|
+
fields: { skip: true, merge: true, path: ["body", "fields"] },
|
|
232
242
|
},
|
|
233
243
|
hmget: {
|
|
234
|
-
key: [
|
|
244
|
+
key: ["resource", "_id"],
|
|
235
245
|
fields: {
|
|
236
246
|
merge: true,
|
|
237
|
-
map: val => toArray(val),
|
|
238
|
-
path: [
|
|
239
|
-
}
|
|
247
|
+
map: (val) => toArray(val),
|
|
248
|
+
path: ["args", "fields"],
|
|
249
|
+
},
|
|
240
250
|
},
|
|
241
251
|
hexists: {
|
|
242
|
-
key: [
|
|
243
|
-
field: [
|
|
252
|
+
key: ["resource", "_id"],
|
|
253
|
+
field: ["args", "field"],
|
|
244
254
|
},
|
|
245
255
|
hincrby: {
|
|
246
|
-
key: [
|
|
247
|
-
field: [
|
|
248
|
-
value: [
|
|
256
|
+
key: ["resource", "_id"],
|
|
257
|
+
field: ["body", "field"],
|
|
258
|
+
value: ["body", "value"],
|
|
249
259
|
},
|
|
250
260
|
hmset: {
|
|
251
|
-
key: [
|
|
261
|
+
key: ["resource", "_id"],
|
|
252
262
|
entries: {
|
|
253
263
|
map: (val, request) => {
|
|
254
264
|
const result = [];
|
|
255
265
|
|
|
256
|
-
kassert.assertBodyHasAttribute(request,
|
|
257
|
-
kassert.assertBodyAttributeType(request,
|
|
266
|
+
kassert.assertBodyHasAttribute(request, "entries");
|
|
267
|
+
kassert.assertBodyAttributeType(request, "entries", "array");
|
|
258
268
|
|
|
259
|
-
val.forEach(v => {
|
|
260
|
-
if (typeof v !==
|
|
261
|
-
throw kerror.get(
|
|
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: [
|
|
270
|
-
merge: true
|
|
271
|
-
}
|
|
283
|
+
path: ["body", "entries"],
|
|
284
|
+
merge: true,
|
|
285
|
+
},
|
|
272
286
|
},
|
|
273
287
|
hset: {
|
|
274
|
-
key: [
|
|
275
|
-
field: [
|
|
276
|
-
value: [
|
|
288
|
+
key: ["resource", "_id"],
|
|
289
|
+
field: ["body", "field"],
|
|
290
|
+
value: ["body", "value"],
|
|
277
291
|
},
|
|
278
292
|
hstrlen: {
|
|
279
|
-
key: [
|
|
280
|
-
field: [
|
|
293
|
+
key: ["resource", "_id"],
|
|
294
|
+
field: ["args", "field"],
|
|
281
295
|
},
|
|
282
296
|
keys: {
|
|
283
|
-
pattern: [
|
|
297
|
+
pattern: ["args", "pattern"],
|
|
284
298
|
},
|
|
285
299
|
lindex: {
|
|
286
|
-
key: [
|
|
287
|
-
index: [
|
|
300
|
+
key: ["resource", "_id"],
|
|
301
|
+
index: ["args", "idx"],
|
|
288
302
|
},
|
|
289
303
|
linsert: {
|
|
290
|
-
key: [
|
|
291
|
-
position: [
|
|
292
|
-
pivot: [
|
|
293
|
-
value: [
|
|
304
|
+
key: ["resource", "_id"],
|
|
305
|
+
position: ["body", "position"],
|
|
306
|
+
pivot: ["body", "pivot"],
|
|
307
|
+
value: ["body", "value"],
|
|
294
308
|
},
|
|
295
309
|
lpush: {
|
|
296
|
-
key: [
|
|
297
|
-
values: { skip: true, merge: true, path: [
|
|
310
|
+
key: ["resource", "_id"],
|
|
311
|
+
values: { skip: true, merge: true, path: ["body", "values"] },
|
|
298
312
|
},
|
|
299
313
|
lrange: {
|
|
300
|
-
key: [
|
|
301
|
-
start: [
|
|
302
|
-
stop: [
|
|
314
|
+
key: ["resource", "_id"],
|
|
315
|
+
start: ["args", "start"],
|
|
316
|
+
stop: ["args", "stop"],
|
|
303
317
|
},
|
|
304
318
|
lrem: {
|
|
305
|
-
key: [
|
|
306
|
-
count: [
|
|
307
|
-
value: [
|
|
319
|
+
key: ["resource", "_id"],
|
|
320
|
+
count: ["body", "count"],
|
|
321
|
+
value: ["body", "value"],
|
|
308
322
|
},
|
|
309
323
|
lset: {
|
|
310
|
-
key: [
|
|
311
|
-
index: [
|
|
312
|
-
value: [
|
|
324
|
+
key: ["resource", "_id"],
|
|
325
|
+
index: ["body", "index"],
|
|
326
|
+
value: ["body", "value"],
|
|
313
327
|
},
|
|
314
328
|
ltrim: {
|
|
315
|
-
key: [
|
|
316
|
-
start: [
|
|
317
|
-
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: [
|
|
324
|
-
}
|
|
336
|
+
map: (val) => toArray(val),
|
|
337
|
+
path: ["args", "keys"],
|
|
338
|
+
},
|
|
325
339
|
},
|
|
326
340
|
mexecute: {
|
|
327
|
-
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,
|
|
335
|
-
kassert.assertBodyAttributeType(request,
|
|
336
|
-
val.forEach(entry => {
|
|
337
|
-
if (typeof entry !==
|
|
338
|
-
throw kerror.get(
|
|
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: [
|
|
347
|
-
merge: true
|
|
348
|
-
}
|
|
364
|
+
path: ["body", "entries"],
|
|
365
|
+
merge: true,
|
|
366
|
+
},
|
|
349
367
|
},
|
|
350
368
|
object: {
|
|
351
|
-
subcommand: [
|
|
352
|
-
key: [
|
|
369
|
+
subcommand: ["args", "subcommand"],
|
|
370
|
+
key: ["resource", "_id"],
|
|
353
371
|
},
|
|
354
372
|
pexpire: {
|
|
355
|
-
key: [
|
|
356
|
-
milliseconds: [
|
|
373
|
+
key: ["resource", "_id"],
|
|
374
|
+
milliseconds: ["body", "milliseconds"],
|
|
357
375
|
},
|
|
358
376
|
pexpireat: {
|
|
359
|
-
key: [
|
|
360
|
-
timestamp: [
|
|
377
|
+
key: ["resource", "_id"],
|
|
378
|
+
timestamp: ["body", "timestamp"],
|
|
361
379
|
},
|
|
362
380
|
pfadd: {
|
|
363
|
-
key: [
|
|
364
|
-
elements: { skip: true, merge: true, path: [
|
|
381
|
+
key: ["resource", "_id"],
|
|
382
|
+
elements: { skip: true, merge: true, path: ["body", "elements"] },
|
|
365
383
|
},
|
|
366
384
|
pfmerge: {
|
|
367
|
-
key: [
|
|
368
|
-
sources: { skip: true, merge: true, path: [
|
|
385
|
+
key: ["resource", "_id"],
|
|
386
|
+
sources: { skip: true, merge: true, path: ["body", "sources"] },
|
|
369
387
|
},
|
|
370
388
|
ping: null,
|
|
371
389
|
psetex: {
|
|
372
|
-
key: [
|
|
373
|
-
milliseconds: [
|
|
374
|
-
value: [
|
|
390
|
+
key: ["resource", "_id"],
|
|
391
|
+
milliseconds: ["body", "milliseconds"],
|
|
392
|
+
value: ["body", "value"],
|
|
375
393
|
},
|
|
376
394
|
randomkey: null,
|
|
377
395
|
rename: {
|
|
378
|
-
key: [
|
|
379
|
-
newkey: [
|
|
396
|
+
key: ["resource", "_id"],
|
|
397
|
+
newkey: ["body", "newkey"],
|
|
380
398
|
},
|
|
381
399
|
renamenx: {
|
|
382
|
-
key: [
|
|
383
|
-
newkey: [
|
|
400
|
+
key: ["resource", "_id"],
|
|
401
|
+
newkey: ["body", "newkey"],
|
|
384
402
|
},
|
|
385
403
|
rpoplpush: {
|
|
386
|
-
source: [
|
|
387
|
-
destination: [
|
|
404
|
+
source: ["body", "source"],
|
|
405
|
+
destination: ["body", "destination"],
|
|
388
406
|
},
|
|
389
407
|
sadd: {
|
|
390
|
-
key: [
|
|
391
|
-
members: { skip: true, merge: true, path: [
|
|
408
|
+
key: ["resource", "_id"],
|
|
409
|
+
members: { skip: true, merge: true, path: ["body", "members"] },
|
|
392
410
|
},
|
|
393
411
|
scan: {
|
|
394
|
-
cursor: [
|
|
412
|
+
cursor: ["args", "cursor"],
|
|
395
413
|
match: scanMatchProperty,
|
|
396
|
-
count: scanCountProperty
|
|
414
|
+
count: scanCountProperty,
|
|
397
415
|
},
|
|
398
416
|
sdiff: {
|
|
399
|
-
key: [
|
|
417
|
+
key: ["resource", "_id"],
|
|
400
418
|
keys: {
|
|
401
419
|
merge: true,
|
|
402
|
-
map: val => toArray(val),
|
|
403
|
-
path: [
|
|
404
|
-
}
|
|
420
|
+
map: (val) => toArray(val),
|
|
421
|
+
path: ["args", "keys"],
|
|
422
|
+
},
|
|
405
423
|
},
|
|
406
424
|
sdiffstore: {
|
|
407
|
-
destination: [
|
|
408
|
-
key: [
|
|
409
|
-
keys: { merge: true, path: [
|
|
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: [
|
|
414
|
-
seconds: [
|
|
415
|
-
value: [
|
|
431
|
+
key: ["resource", "_id"],
|
|
432
|
+
seconds: ["body", "seconds"],
|
|
433
|
+
value: ["body", "value"],
|
|
416
434
|
},
|
|
417
435
|
setnx: {
|
|
418
|
-
key: [
|
|
419
|
-
value: [
|
|
436
|
+
key: ["resource", "_id"],
|
|
437
|
+
value: ["body", "value"],
|
|
420
438
|
},
|
|
421
439
|
sinterstore: {
|
|
422
|
-
destination: [
|
|
423
|
-
keys: { merge: true, path: [
|
|
440
|
+
destination: ["body", "destination"],
|
|
441
|
+
keys: { merge: true, path: ["body", "keys"] },
|
|
424
442
|
},
|
|
425
443
|
sismember: {
|
|
426
|
-
key: [
|
|
427
|
-
member: [
|
|
444
|
+
key: ["resource", "_id"],
|
|
445
|
+
member: ["args", "member"],
|
|
428
446
|
},
|
|
429
447
|
smove: {
|
|
430
|
-
key: [
|
|
431
|
-
destination: [
|
|
432
|
-
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: [
|
|
437
|
-
count: { skip: true, path: [
|
|
454
|
+
key: ["resource", "_id"],
|
|
455
|
+
count: { skip: true, path: ["body", "count"] },
|
|
438
456
|
},
|
|
439
457
|
srandmember: {
|
|
440
|
-
key: [
|
|
441
|
-
count: { skip: true, path: [
|
|
458
|
+
key: ["resource", "_id"],
|
|
459
|
+
count: { skip: true, path: ["args", "count"] },
|
|
442
460
|
},
|
|
443
461
|
srem: {
|
|
444
|
-
key: [
|
|
445
|
-
members: { skip: true, merge: true, path: [
|
|
462
|
+
key: ["resource", "_id"],
|
|
463
|
+
members: { skip: true, merge: true, path: ["body", "members"] },
|
|
446
464
|
},
|
|
447
465
|
sscan: {
|
|
448
|
-
key: [
|
|
449
|
-
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: [
|
|
458
|
-
}
|
|
474
|
+
map: (val) => toArray(val),
|
|
475
|
+
path: ["args", "keys"],
|
|
476
|
+
},
|
|
459
477
|
},
|
|
460
478
|
sunionstore: {
|
|
461
|
-
destination: [
|
|
462
|
-
keys: { merge: true, path: [
|
|
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: [
|
|
484
|
+
keys: { merge: true, path: ["body", "keys"] },
|
|
467
485
|
},
|
|
468
486
|
zadd: null, // handled by extractArgumentsFromRequestForZAdd
|
|
469
487
|
zcount: {
|
|
470
|
-
key: [
|
|
471
|
-
min: [
|
|
472
|
-
max: [
|
|
488
|
+
key: ["resource", "_id"],
|
|
489
|
+
min: ["args", "min"],
|
|
490
|
+
max: ["args", "max"],
|
|
473
491
|
},
|
|
474
492
|
zincrby: {
|
|
475
|
-
key: [
|
|
476
|
-
value: [
|
|
477
|
-
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: [
|
|
482
|
-
min: [
|
|
483
|
-
max: [
|
|
499
|
+
key: ["resource", "_id"],
|
|
500
|
+
min: ["args", "min"],
|
|
501
|
+
max: ["args", "max"],
|
|
484
502
|
},
|
|
485
503
|
zrange: {
|
|
486
|
-
key: [
|
|
487
|
-
start: [
|
|
488
|
-
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: [
|
|
510
|
+
map: (val) => sanitizeArrayArgument(val),
|
|
511
|
+
path: ["args", "options"],
|
|
512
|
+
},
|
|
494
513
|
},
|
|
495
514
|
zrangebylex: {
|
|
496
|
-
key: [
|
|
497
|
-
min: [
|
|
498
|
-
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: [
|
|
504
|
-
}
|
|
521
|
+
map: (val) => processLimit(val),
|
|
522
|
+
path: ["args", "limit"],
|
|
523
|
+
},
|
|
505
524
|
},
|
|
506
525
|
zrangebyscore: {
|
|
507
|
-
key: [
|
|
508
|
-
min: [
|
|
509
|
-
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: [
|
|
515
|
-
members: { merge: true, path: [
|
|
533
|
+
key: ["resource", "_id"],
|
|
534
|
+
members: { merge: true, path: ["body", "members"] },
|
|
516
535
|
},
|
|
517
536
|
zremrangebylex: {
|
|
518
|
-
key: [
|
|
519
|
-
min: [
|
|
520
|
-
max: [
|
|
537
|
+
key: ["resource", "_id"],
|
|
538
|
+
min: ["body", "min"],
|
|
539
|
+
max: ["body", "max"],
|
|
521
540
|
},
|
|
522
541
|
zremrangebyrank: {
|
|
523
|
-
key: [
|
|
524
|
-
min: [
|
|
525
|
-
max: [
|
|
542
|
+
key: ["resource", "_id"],
|
|
543
|
+
min: ["body", "start"],
|
|
544
|
+
max: ["body", "stop"],
|
|
526
545
|
},
|
|
527
546
|
zremrangebyscore: {
|
|
528
|
-
key: [
|
|
529
|
-
min: [
|
|
530
|
-
max: [
|
|
547
|
+
key: ["resource", "_id"],
|
|
548
|
+
min: ["body", "min"],
|
|
549
|
+
max: ["body", "max"],
|
|
531
550
|
},
|
|
532
551
|
zrevrangebylex: {
|
|
533
|
-
key: [
|
|
534
|
-
max: [
|
|
535
|
-
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: [
|
|
541
|
-
}
|
|
558
|
+
map: (val) => processLimit(val),
|
|
559
|
+
path: ["args", "limit"],
|
|
560
|
+
},
|
|
542
561
|
},
|
|
543
562
|
zrevrangebyscore: {
|
|
544
|
-
key: [
|
|
545
|
-
max: [
|
|
546
|
-
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: [
|
|
552
|
-
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 =
|
|
559
|
-
mapping.
|
|
560
|
-
mapping.
|
|
561
|
-
mapping.
|
|
562
|
-
mapping.
|
|
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 =
|
|
566
|
-
|
|
567
|
-
|
|
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
|
|
626
|
+
function extractArgumentsFromRequest(command, request) {
|
|
591
627
|
let args = [];
|
|
592
628
|
|
|
593
629
|
// Dealing with exceptions
|
|
594
|
-
if (command ===
|
|
630
|
+
if (command === "set") {
|
|
595
631
|
return extractArgumentsFromRequestForSet(request);
|
|
596
632
|
}
|
|
597
|
-
if (command ===
|
|
633
|
+
if (command === "sort") {
|
|
598
634
|
return extractArgumentsFromRequestForSort(request);
|
|
599
635
|
}
|
|
600
|
-
if (command ===
|
|
636
|
+
if (command === "zadd") {
|
|
601
637
|
return extractArgumentsFromRequestForZAdd(request);
|
|
602
638
|
}
|
|
603
|
-
if (command ===
|
|
639
|
+
if (command === "zinterstore") {
|
|
604
640
|
return extractArgumentsFromRequestForZInterstore(request);
|
|
605
641
|
}
|
|
606
|
-
if (command ===
|
|
642
|
+
if (command === "zunionstore") {
|
|
607
643
|
return extractArgumentsFromRequestForZInterstore(request);
|
|
608
644
|
}
|
|
609
|
-
if (command ===
|
|
645
|
+
if (command === "mexecute") {
|
|
610
646
|
return extractArgumentsFromRequestForMExecute(request);
|
|
611
647
|
}
|
|
612
648
|
|
|
613
|
-
if (!
|
|
649
|
+
if (!mapping[command]) {
|
|
614
650
|
return [];
|
|
615
651
|
}
|
|
616
652
|
|
|
617
|
-
if (!
|
|
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 = !
|
|
625
|
-
const map = !
|
|
626
|
-
const skip = !
|
|
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 (
|
|
631
|
-
|
|
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
|
-
},
|
|
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(
|
|
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
|
|
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 (
|
|
673
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
729
|
+
args.push("EX", request.input.body.ex);
|
|
688
730
|
}
|
|
689
731
|
|
|
690
732
|
if (request.input.body.px !== undefined) {
|
|
691
|
-
args.push(
|
|
733
|
+
args.push("PX", request.input.body.px);
|
|
692
734
|
}
|
|
693
735
|
|
|
694
736
|
if (request.input.body.nx) {
|
|
695
|
-
args.push(
|
|
737
|
+
args.push("NX");
|
|
696
738
|
}
|
|
697
739
|
|
|
698
740
|
if (request.input.body.xx) {
|
|
699
|
-
args.push(
|
|
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
|
|
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(
|
|
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 ([
|
|
723
|
-
throw kerror.get(
|
|
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(
|
|
772
|
+
args.push("BY", request.input.body.by);
|
|
731
773
|
}
|
|
732
774
|
|
|
733
775
|
if (request.input.body.limit !== undefined) {
|
|
734
|
-
kassert.assertBodyAttributeType(request,
|
|
735
|
-
assertInt(request,
|
|
736
|
-
assertInt(request,
|
|
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
|
-
|
|
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,
|
|
788
|
+
kassert.assertBodyAttributeType(request, "get", "array");
|
|
746
789
|
|
|
747
|
-
request.input.body.get.forEach(pattern => {
|
|
748
|
-
args.push(
|
|
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(
|
|
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
|
|
808
|
+
function extractArgumentsFromRequestForMExecute(request) {
|
|
766
809
|
kassert.assertHasBody(request);
|
|
767
|
-
kassert.assertBodyHasAttribute(request,
|
|
768
|
-
kassert.assertBodyAttributeType(request,
|
|
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 (!
|
|
774
|
-
throw kerror.get(
|
|
815
|
+
return actions.map((command) => {
|
|
816
|
+
if (!has(command, "action")) {
|
|
817
|
+
throw kerror.get("missing_argument", "action");
|
|
775
818
|
}
|
|
776
|
-
if (!
|
|
777
|
-
throw kerror.get(
|
|
819
|
+
if (!has(command, "args")) {
|
|
820
|
+
throw kerror.get("missing_argument", "args");
|
|
778
821
|
}
|
|
779
|
-
if (!
|
|
780
|
-
throw kerror.get(
|
|
822
|
+
if (!isPlainObject(command.args)) {
|
|
823
|
+
throw kerror.get("invalid_type", "args", "object");
|
|
781
824
|
}
|
|
782
|
-
if (command.action ===
|
|
783
|
-
throw kerror.get(
|
|
825
|
+
if (command.action === "mexecute") {
|
|
826
|
+
throw kerror.get("forbidden_argument", "mexecute");
|
|
784
827
|
}
|
|
785
|
-
if (!
|
|
786
|
-
throw kerror.get(
|
|
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(
|
|
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
|
|
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,
|
|
805
|
-
kassert.assertBodyAttributeType(request,
|
|
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(
|
|
854
|
+
throw kerror.get("mutually_exclusive", "nx", "xx");
|
|
809
855
|
}
|
|
810
856
|
|
|
811
857
|
if (request.input.body.nx) {
|
|
812
|
-
args.push(
|
|
858
|
+
args.push("NX");
|
|
813
859
|
}
|
|
814
860
|
|
|
815
861
|
if (request.input.body.xx) {
|
|
816
|
-
args.push(
|
|
862
|
+
args.push("XX");
|
|
817
863
|
}
|
|
818
864
|
|
|
819
865
|
if (request.input.body.ch) {
|
|
820
|
-
args.push(
|
|
866
|
+
args.push("CH");
|
|
821
867
|
}
|
|
822
868
|
|
|
823
869
|
if (request.input.body.incr) {
|
|
824
|
-
args.push(
|
|
870
|
+
args.push("INCR");
|
|
825
871
|
}
|
|
826
872
|
|
|
827
873
|
if (request.input.body.elements.length === 0) {
|
|
828
|
-
throw kerror.get(
|
|
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(
|
|
878
|
+
throw kerror.get("too_many_arguments", "elements");
|
|
833
879
|
}
|
|
834
880
|
|
|
835
881
|
request.input.body.elements.forEach((element, index) => {
|
|
836
|
-
if (!
|
|
837
|
-
throw kerror.get(
|
|
882
|
+
if (!isPlainObject(element)) {
|
|
883
|
+
throw kerror.get("invalid_argument", "elements", "<array of objects>");
|
|
838
884
|
}
|
|
839
885
|
|
|
840
|
-
if (!
|
|
841
|
-
throw kerror.get(
|
|
886
|
+
if (!element.member) {
|
|
887
|
+
throw kerror.get("missing_argument", `elements[${index}].member`);
|
|
842
888
|
}
|
|
843
889
|
|
|
844
|
-
assertFloat(request,
|
|
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
|
|
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,
|
|
863
|
-
kassert.assertBodyAttributeType(request,
|
|
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(
|
|
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,
|
|
919
|
+
kassert.assertBodyAttributeType(request, "weights", "array");
|
|
874
920
|
|
|
875
921
|
if (request.input.body.weights.length > 0) {
|
|
876
|
-
args.push(
|
|
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,
|
|
928
|
+
kassert.assertBodyAttributeType(request, "aggregate", "string");
|
|
883
929
|
|
|
884
930
|
const aggregate = request.input.body.aggregate.toUpperCase();
|
|
885
931
|
|
|
886
|
-
if ([
|
|
887
|
-
throw kerror.get(
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
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(
|
|
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
|
|
935
|
-
return typeof 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
|
|
993
|
+
function sanitizeArrayArgument(arg) {
|
|
944
994
|
const result = toArray(arg);
|
|
945
995
|
|
|
946
|
-
return result.map(v => typeof 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
|
|
955
|
-
let result = [
|
|
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(
|
|
1011
|
+
throw kerror.get("invalid_argument", "limit", "<offset, count>");
|
|
962
1012
|
}
|
|
963
1013
|
|
|
964
1014
|
return result;
|