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
|
@@ -45,7 +45,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.IndexCache = void 0;
|
|
47
47
|
const kerror = __importStar(require("../../kerror"));
|
|
48
|
-
const storageError = kerror.wrap(
|
|
48
|
+
const storageError = kerror.wrap("services", "storage");
|
|
49
49
|
class IndexCache {
|
|
50
50
|
constructor() {
|
|
51
51
|
/**
|
|
@@ -129,7 +129,7 @@ class IndexCache {
|
|
|
129
129
|
*/
|
|
130
130
|
assertIndexExists(index) {
|
|
131
131
|
if (!this.indexes.has(index)) {
|
|
132
|
-
throw storageError.get(
|
|
132
|
+
throw storageError.get("unknown_index", index);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
@@ -138,7 +138,7 @@ class IndexCache {
|
|
|
138
138
|
assertCollectionExists(index, collection) {
|
|
139
139
|
this.assertIndexExists(index);
|
|
140
140
|
if (!this.indexes.get(index).has(collection)) {
|
|
141
|
-
throw storageError.get(
|
|
141
|
+
throw storageError.get("unknown_collection", index, collection);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
}
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const Bluebird = require(
|
|
24
|
+
const Bluebird = require("bluebird");
|
|
25
25
|
|
|
26
|
-
const kerror = require(
|
|
27
|
-
const ClientAdapter = require(
|
|
28
|
-
const scopeEnum = require(
|
|
26
|
+
const kerror = require("../../kerror").wrap("services", "storage");
|
|
27
|
+
const ClientAdapter = require("./clientAdapter");
|
|
28
|
+
const scopeEnum = require("./storeScopeEnum");
|
|
29
29
|
|
|
30
30
|
class StorageEngine {
|
|
31
|
-
constructor
|
|
31
|
+
constructor() {
|
|
32
32
|
// Storage client for public indexes only
|
|
33
33
|
this.public = new ClientAdapter(scopeEnum.PUBLIC);
|
|
34
34
|
|
|
@@ -41,21 +41,18 @@ class StorageEngine {
|
|
|
41
41
|
*
|
|
42
42
|
* @returns {Promise}
|
|
43
43
|
*/
|
|
44
|
-
async init
|
|
45
|
-
await Bluebird.all([
|
|
46
|
-
this.public.init(),
|
|
47
|
-
this.private.init(),
|
|
48
|
-
]);
|
|
44
|
+
async init() {
|
|
45
|
+
await Bluebird.all([this.public.init(), this.private.init()]);
|
|
49
46
|
|
|
50
47
|
const privateIndexes = await this.private.cache.listIndexes();
|
|
51
48
|
|
|
52
49
|
for (const publicIndex of await this.public.cache.listIndexes()) {
|
|
53
50
|
if (privateIndexes.includes(publicIndex)) {
|
|
54
|
-
throw kerror.get(
|
|
51
|
+
throw kerror.get("index_already_exists", "public", publicIndex);
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
global.kuzzle.log.info(
|
|
55
|
+
global.kuzzle.log.info("[✔] Storage initialized");
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @typedef {string} storeScopeEnum
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
* @enum {storeScopeEnum}
|
|
33
33
|
*/
|
|
34
34
|
const storeScopeEnum = Object.freeze({
|
|
35
|
-
PRIVATE:
|
|
36
|
-
PUBLIC:
|
|
35
|
+
PRIVATE: "private",
|
|
36
|
+
PUBLIC: "public",
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
module.exports = storeScopeEnum;
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @class BaseType
|
|
@@ -33,7 +33,7 @@ class BaseType {
|
|
|
33
33
|
* @param {string[]} errorMessages
|
|
34
34
|
* @returns {boolean}
|
|
35
35
|
*/
|
|
36
|
-
validate
|
|
36
|
+
validate() {
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -44,7 +44,7 @@ class BaseType {
|
|
|
44
44
|
* @returns {TypeOptions}
|
|
45
45
|
* @throws {KuzzleError}
|
|
46
46
|
*/
|
|
47
|
-
validateFieldSpecification
|
|
47
|
+
validateFieldSpecification(opts) {
|
|
48
48
|
return opts;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -53,16 +53,18 @@ class BaseType {
|
|
|
53
53
|
* @param {string[]} allowedProperties
|
|
54
54
|
* @returns {boolean}
|
|
55
55
|
*/
|
|
56
|
-
checkAllowedProperties
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
checkAllowedProperties(object, allowedProperties) {
|
|
57
|
+
if (
|
|
58
|
+
typeof object !== "object" ||
|
|
59
|
+
Array.isArray(object) ||
|
|
60
|
+
object === null
|
|
60
61
|
) {
|
|
61
62
|
return false;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
return !
|
|
65
|
-
propertyName => allowedProperties.indexOf(propertyName) === -1
|
|
65
|
+
return !Object.keys(object).some(
|
|
66
|
+
(propertyName) => allowedProperties.indexOf(propertyName) === -1
|
|
67
|
+
);
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
/**
|
|
@@ -70,7 +72,7 @@ class BaseType {
|
|
|
70
72
|
* @param {boolean} parentStrictness
|
|
71
73
|
* @returns {boolean}
|
|
72
74
|
*/
|
|
73
|
-
getStrictness
|
|
75
|
+
getStrictness(fieldSpec, parentStrictness) {
|
|
74
76
|
return parentStrictness;
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const BaseType = require(
|
|
24
|
+
const BaseType = require("../baseType");
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @class AnythingType
|
|
28
28
|
*/
|
|
29
29
|
class AnythingType extends BaseType {
|
|
30
|
-
constructor
|
|
30
|
+
constructor() {
|
|
31
31
|
super();
|
|
32
|
-
this.typeName =
|
|
32
|
+
this.typeName = "anything";
|
|
33
33
|
this.allowChildren = false;
|
|
34
34
|
this.allowedTypeOptions = [];
|
|
35
35
|
}
|
|
@@ -19,17 +19,17 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const BaseType = require(
|
|
24
|
+
const BaseType = require("../baseType");
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @class BooleanType
|
|
28
28
|
*/
|
|
29
29
|
class BooleanType extends BaseType {
|
|
30
|
-
constructor
|
|
30
|
+
constructor() {
|
|
31
31
|
super();
|
|
32
|
-
this.typeName =
|
|
32
|
+
this.typeName = "boolean";
|
|
33
33
|
this.allowChildren = false;
|
|
34
34
|
this.allowedTypeOptions = [];
|
|
35
35
|
}
|
|
@@ -39,9 +39,9 @@ class BooleanType extends BaseType {
|
|
|
39
39
|
* @param {*} fieldValue
|
|
40
40
|
* @param {string[]} errorMessages
|
|
41
41
|
*/
|
|
42
|
-
validate
|
|
43
|
-
if (typeof fieldValue !==
|
|
44
|
-
errorMessages.push(
|
|
42
|
+
validate(typeOptions, fieldValue, errorMessages) {
|
|
43
|
+
if (typeof fieldValue !== "boolean") {
|
|
44
|
+
errorMessages.push("The field must be of type boolean.");
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -19,106 +19,138 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
moment = require('moment'),
|
|
24
|
+
const kerror = require("../../../kerror"),
|
|
25
|
+
{ has, isPlainObject } = require("../../../util/safeObject"),
|
|
26
|
+
BaseType = require("../baseType"),
|
|
27
|
+
moment = require("moment"),
|
|
29
28
|
formatMap = {
|
|
30
|
-
basic_date: date => moment.utc(date,
|
|
31
|
-
basic_date_time: date => moment.utc(date,
|
|
32
|
-
basic_date_time_no_millis: date =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
29
|
+
basic_date: (date) => moment.utc(date, "YYYYMMDD", true),
|
|
30
|
+
basic_date_time: (date) => moment.utc(date, "YYYYMMDD\\THHmmss.SSSZ", true),
|
|
31
|
+
basic_date_time_no_millis: (date) =>
|
|
32
|
+
moment.utc(date, "YYYYMMDD\\THHmmssZ", true),
|
|
33
|
+
basic_ordinal_date: (date) => moment.utc(date, "YYYYDDD", true),
|
|
34
|
+
basic_ordinal_date_time: (date) =>
|
|
35
|
+
moment.utc(date, "YYYYDDD\\THHmmss.SSSZ", true),
|
|
36
|
+
basic_ordinal_date_time_no_millis: (date) =>
|
|
37
|
+
moment.utc(date, "YYYYDDD\\THHmmssZ", true),
|
|
38
|
+
basic_t_time: (date) => moment.utc(date, "\\THHmmss.SSSZ", true),
|
|
39
|
+
basic_t_time_no_millis: (date) => moment.utc(date, "\\THHmmssZ", true),
|
|
40
|
+
basic_time: (date) => moment.utc(date, "HHmmss.SSSZ", true),
|
|
41
|
+
basic_time_no_millis: (date) => moment.utc(date, "HHmmssZ", true),
|
|
42
|
+
basic_week_date: (date) => moment.utc(date, "gggg\\Wwwe", false),
|
|
43
|
+
basic_week_date_time: (date) =>
|
|
44
|
+
moment.utc(date, "gggg\\Wwwe\\THHmmss.SSSZ", false),
|
|
45
|
+
basic_week_date_time_no_millis: (date) =>
|
|
46
|
+
moment.utc(date, "gggg\\Wwwe\\THHmmssZ", false),
|
|
47
|
+
date: (date) => moment.utc(date, "YYYY-MM-DD", false),
|
|
48
|
+
date_hour: (date) => moment.utc(date, "YYYY-MM-DD\\THH", false),
|
|
49
|
+
date_hour_minute: (date) => moment.utc(date, "YYYY-MM-DD\\THH:mm", false),
|
|
50
|
+
date_hour_minute_second: (date) =>
|
|
51
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ss", false),
|
|
52
|
+
date_hour_minute_second_fraction: (date) =>
|
|
53
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ss.SSS", false),
|
|
54
|
+
date_hour_minute_second_millis: (date) =>
|
|
55
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ss.SSS", false),
|
|
56
|
+
date_time: (date) => moment.utc(date, "YYYY-MM-DD\\THH:mm:ss.SSSZZ", false),
|
|
57
|
+
date_time_no_millis: (date) =>
|
|
58
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ssZZ", false),
|
|
59
|
+
epoch_millis: (date) =>
|
|
60
|
+
typeof date === "number" ? moment.utc(date) : moment.invalid(),
|
|
61
|
+
epoch_second: (date) =>
|
|
62
|
+
typeof date === "number"
|
|
63
|
+
? moment.utc(moment.unix(date))
|
|
64
|
+
: moment.invalid(),
|
|
65
|
+
hour: (date) => moment.utc(date, "HH", false),
|
|
66
|
+
hour_minute: (date) => moment.utc(date, "HH:mm", false),
|
|
67
|
+
hour_minute_second: (date) => moment.utc(date, "HH:mm:ss", false),
|
|
68
|
+
hour_minute_second_fraction: (date) =>
|
|
69
|
+
moment.utc(date, "HH:mm:ss.SSS", false),
|
|
70
|
+
hour_minute_second_millis: (date) =>
|
|
71
|
+
moment.utc(date, "HH:mm:ss.SSS", false),
|
|
72
|
+
ordinal_date: (date) => moment.utc(date, "YYYY-DDD", false),
|
|
73
|
+
ordinal_date_time: (date) =>
|
|
74
|
+
moment.utc(date, "YYYY-DDD\\THH:mm:ss.SSSZZ", false),
|
|
75
|
+
ordinal_date_time_no_millis: (date) =>
|
|
76
|
+
moment.utc(date, "YYYY-DDD\\THH:mm:ssZZ", false),
|
|
77
|
+
strict_basic_week_date: (date) => moment.utc(date, "gggg\\Wwwe", true),
|
|
78
|
+
strict_basic_week_date_time: (date) =>
|
|
79
|
+
moment.utc(date, "gggg\\Wwwe\\THHmmss.SSSZ", true),
|
|
80
|
+
strict_basic_week_date_time_no_millis: (date) =>
|
|
81
|
+
moment.utc(date, "gggg\\Wwwe\\THHmmssZ", true),
|
|
82
|
+
strict_date: (date) => moment.utc(date, "YYYY-MM-DD", true),
|
|
83
|
+
strict_date_hour: (date) => moment.utc(date, "YYYY-MM-DD\\THH", true),
|
|
84
|
+
strict_date_hour_minute: (date) =>
|
|
85
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm", true),
|
|
86
|
+
strict_date_hour_minute_second: (date) =>
|
|
87
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ss", true),
|
|
88
|
+
strict_date_hour_minute_second_fraction: (date) =>
|
|
89
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ss.SSS", true),
|
|
90
|
+
strict_date_hour_minute_second_millis: (date) =>
|
|
91
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ss.SSS", true),
|
|
92
|
+
strict_date_optional_time: (date) =>
|
|
93
|
+
moment.utc(date, moment.ISO_8601, true),
|
|
94
|
+
strict_date_time: (date) =>
|
|
95
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ss.SSSZZ", true),
|
|
96
|
+
strict_date_time_no_millis: (date) =>
|
|
97
|
+
moment.utc(date, "YYYY-MM-DD\\THH:mm:ssZZ", true),
|
|
98
|
+
strict_hour: (date) => moment.utc(date, "HH", true),
|
|
99
|
+
strict_hour_minute: (date) => moment.utc(date, "HH:mm", true),
|
|
100
|
+
strict_hour_minute_second: (date) => moment.utc(date, "HH:mm:ss", true),
|
|
101
|
+
strict_hour_minute_second_fraction: (date) =>
|
|
102
|
+
moment.utc(date, "HH:mm:ss.SSS", true),
|
|
103
|
+
strict_hour_minute_second_millis: (date) =>
|
|
104
|
+
moment.utc(date, "HH:mm:ss.SSS", true),
|
|
105
|
+
strict_ordinal_date: (date) => moment.utc(date, "YYYY-DDD", true),
|
|
106
|
+
strict_ordinal_date_time: (date) =>
|
|
107
|
+
moment.utc(date, "YYYY-DDD\\THH:mm:ss.SSSZZ", true),
|
|
108
|
+
strict_ordinal_date_time_no_millis: (date) =>
|
|
109
|
+
moment.utc(date, "YYYY-DDD\\THH:mm:ssZZ", true),
|
|
110
|
+
strict_t_time: (date) => moment.utc(date, "\\THH:mm:ss.SSSZZ", true),
|
|
111
|
+
strict_t_time_no_millis: (date) => moment.utc(date, "\\THH:mm:ssZZ", true),
|
|
112
|
+
strict_time: (date) => moment.utc(date, "HH:mm:ss.SSSZZ", true),
|
|
113
|
+
strict_time_no_millis: (date) => moment.utc(date, "HH:mm:ssZZ", true),
|
|
114
|
+
strict_week_date: (date) => moment.utc(date, "gggg-\\Www-e", true),
|
|
115
|
+
strict_week_date_time: (date) =>
|
|
116
|
+
moment.utc(date, "gggg-\\Www-e\\THH:mm:ss.SSSZZ", true),
|
|
117
|
+
strict_week_date_time_no_millis: (date) =>
|
|
118
|
+
moment.utc(date, "gggg-\\Www-e\\THH:mm:ssZZ", true),
|
|
119
|
+
strict_weekyear: (date) => moment.utc(date, "gggg", true),
|
|
120
|
+
strict_weekyear_week: (date) => moment.utc(date, "ggggww", true),
|
|
121
|
+
strict_weekyear_week_day: (date) => moment.utc(date, "ggggwwe", true),
|
|
122
|
+
strict_year: (date) => moment.utc(date, "YYYY", true),
|
|
123
|
+
strict_year_month: (date) => moment.utc(date, "YYYYMM", true),
|
|
124
|
+
strict_year_month_day: (date) => moment.utc(date, "YYYYMMDD", true),
|
|
125
|
+
t_time: (date) => moment.utc(date, "\\THH:mm:ss.SSSZZ", false),
|
|
126
|
+
t_time_no_millis: (date) => moment.utc(date, "\\THH:mm:ssZZ", false),
|
|
127
|
+
time: (date) => moment.utc(date, "HH:mm:ss.SSSZZ", false),
|
|
128
|
+
time_no_millis: (date) => moment.utc(date, "HH:mm:ssZZ", false),
|
|
129
|
+
week_date: (date) => moment.utc(date, "gggg-\\Www-e", false),
|
|
130
|
+
week_date_time: (date) =>
|
|
131
|
+
moment.utc(date, "gggg-\\Www-e\\THH:mm:ss.SSSZZ", false),
|
|
132
|
+
week_date_time_no_millis: (date) =>
|
|
133
|
+
moment.utc(date, "gggg-\\Www-e\\THH:mm:ssZZ", false),
|
|
134
|
+
weekyear: (date) => moment.utc(date, "gggg", false),
|
|
135
|
+
weekyear_week: (date) => moment.utc(date, "ggggww", false),
|
|
136
|
+
weekyear_week_day: (date) => moment.utc(date, "ggggwwe", false),
|
|
137
|
+
year: (date) => moment.utc(date, "YYYY", false),
|
|
138
|
+
year_month: (date) => moment.utc(date, "YYYYMM", false),
|
|
139
|
+
year_month_day: (date) => moment.utc(date, "YYYYMMDD", false),
|
|
107
140
|
};
|
|
108
141
|
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
typeError = kerror.wrap('validation', 'types');
|
|
142
|
+
const assertionError = kerror.wrap("validation", "assert"),
|
|
143
|
+
typeError = kerror.wrap("validation", "types");
|
|
112
144
|
|
|
113
145
|
/**
|
|
114
146
|
* @class DateType
|
|
115
147
|
*/
|
|
116
148
|
class DateType extends BaseType {
|
|
117
|
-
constructor
|
|
149
|
+
constructor() {
|
|
118
150
|
super();
|
|
119
|
-
this.typeName =
|
|
151
|
+
this.typeName = "date";
|
|
120
152
|
this.allowChildren = false;
|
|
121
|
-
this.allowedTypeOptions = [
|
|
153
|
+
this.allowedTypeOptions = ["range", "formats"];
|
|
122
154
|
}
|
|
123
155
|
|
|
124
156
|
/**
|
|
@@ -127,7 +159,7 @@ class DateType extends BaseType {
|
|
|
127
159
|
* @param {string[]} errorMessages
|
|
128
160
|
* @returns {boolean}
|
|
129
161
|
*/
|
|
130
|
-
validate
|
|
162
|
+
validate(typeOptions, fieldValue, errorMessages) {
|
|
131
163
|
let momentDate = null;
|
|
132
164
|
|
|
133
165
|
for (const formatOpt of typeOptions.formats) {
|
|
@@ -138,30 +170,34 @@ class DateType extends BaseType {
|
|
|
138
170
|
}
|
|
139
171
|
}
|
|
140
172
|
|
|
141
|
-
if (momentDate === null || !
|
|
142
|
-
errorMessages.push(
|
|
173
|
+
if (momentDate === null || !momentDate.isValid()) {
|
|
174
|
+
errorMessages.push("The date format is invalid.");
|
|
143
175
|
return false;
|
|
144
176
|
}
|
|
145
177
|
|
|
146
178
|
if (isPlainObject(typeOptions.range)) {
|
|
147
179
|
if (typeOptions.range.min) {
|
|
148
|
-
const min =
|
|
149
|
-
|
|
150
|
-
|
|
180
|
+
const min =
|
|
181
|
+
typeOptions.range.min === "NOW"
|
|
182
|
+
? moment.utc()
|
|
183
|
+
: typeOptions.range.min;
|
|
151
184
|
|
|
152
185
|
if (momentDate.isBefore(min)) {
|
|
153
|
-
errorMessages.push(
|
|
186
|
+
errorMessages.push(
|
|
187
|
+
"The provided date is before the defined minimum."
|
|
188
|
+
);
|
|
154
189
|
return false;
|
|
155
190
|
}
|
|
156
191
|
}
|
|
157
192
|
|
|
158
193
|
if (typeOptions.range.max) {
|
|
159
|
-
const max =
|
|
160
|
-
|
|
161
|
-
|
|
194
|
+
const max =
|
|
195
|
+
typeOptions.range.max === "NOW"
|
|
196
|
+
? moment.utc()
|
|
197
|
+
: typeOptions.range.max;
|
|
162
198
|
|
|
163
199
|
if (max.isBefore(momentDate)) {
|
|
164
|
-
errorMessages.push(
|
|
200
|
+
errorMessages.push("The provided date is after the defined maximum.");
|
|
165
201
|
return false;
|
|
166
202
|
}
|
|
167
203
|
}
|
|
@@ -175,51 +211,50 @@ class DateType extends BaseType {
|
|
|
175
211
|
* @returns {TypeOptions}
|
|
176
212
|
* @throws {PreconditionError}
|
|
177
213
|
*/
|
|
178
|
-
validateFieldSpecification
|
|
179
|
-
if (has(typeOptions,
|
|
180
|
-
if (
|
|
181
|
-
|
|
214
|
+
validateFieldSpecification(typeOptions) {
|
|
215
|
+
if (has(typeOptions, "formats")) {
|
|
216
|
+
if (
|
|
217
|
+
!Array.isArray(typeOptions.formats) ||
|
|
218
|
+
typeOptions.formats.length === 0
|
|
182
219
|
) {
|
|
183
|
-
throw assertionError.get(
|
|
220
|
+
throw assertionError.get("invalid_type", "formats", "non-empty array");
|
|
184
221
|
}
|
|
185
222
|
|
|
186
|
-
const unrecognized = typeOptions.formats.filter(f => !
|
|
223
|
+
const unrecognized = typeOptions.formats.filter((f) => !formatMap[f]);
|
|
187
224
|
if (unrecognized.length > 0) {
|
|
188
|
-
throw typeError.get(
|
|
225
|
+
throw typeError.get("invalid_date_format", unrecognized.join(", "));
|
|
189
226
|
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
typeOptions.formats = ['epoch_millis'];
|
|
227
|
+
} else {
|
|
228
|
+
typeOptions.formats = ["epoch_millis"];
|
|
193
229
|
}
|
|
194
230
|
|
|
195
|
-
if (has(typeOptions,
|
|
196
|
-
let
|
|
197
|
-
min = null,
|
|
231
|
+
if (has(typeOptions, "range")) {
|
|
232
|
+
let min = null,
|
|
198
233
|
max = null;
|
|
199
234
|
|
|
200
|
-
if (!
|
|
201
|
-
throw assertionError.get(
|
|
235
|
+
if (!this.checkAllowedProperties(typeOptions.range, ["min", "max"])) {
|
|
236
|
+
throw assertionError.get("unexpected_properties", "range", "min, max");
|
|
202
237
|
}
|
|
203
238
|
|
|
204
|
-
if (has(typeOptions.range,
|
|
205
|
-
min = convertRangeValue(
|
|
239
|
+
if (has(typeOptions.range, "min")) {
|
|
240
|
+
min = convertRangeValue("min", typeOptions.range.min);
|
|
206
241
|
}
|
|
207
242
|
|
|
208
|
-
if (has(typeOptions.range,
|
|
209
|
-
max = convertRangeValue(
|
|
243
|
+
if (has(typeOptions.range, "max")) {
|
|
244
|
+
max = convertRangeValue("max", typeOptions.range.max);
|
|
210
245
|
}
|
|
211
246
|
|
|
212
247
|
if (min && max && max.isBefore(min)) {
|
|
213
|
-
throw assertionError.get(
|
|
248
|
+
throw assertionError.get("invalid_range", "range", "min", "max");
|
|
214
249
|
}
|
|
215
250
|
|
|
216
251
|
// We want to keep NOW as a special value, else we would keep the time
|
|
217
252
|
// of the launch
|
|
218
|
-
if (min && typeOptions.range.min !==
|
|
253
|
+
if (min && typeOptions.range.min !== "NOW") {
|
|
219
254
|
typeOptions.range.min = min;
|
|
220
255
|
}
|
|
221
256
|
|
|
222
|
-
if (max && typeOptions.range.max !==
|
|
257
|
+
if (max && typeOptions.range.max !== "NOW") {
|
|
223
258
|
typeOptions.range.max = max;
|
|
224
259
|
}
|
|
225
260
|
}
|
|
@@ -228,20 +263,19 @@ class DateType extends BaseType {
|
|
|
228
263
|
}
|
|
229
264
|
}
|
|
230
265
|
|
|
231
|
-
function convertRangeValue
|
|
266
|
+
function convertRangeValue(name, value) {
|
|
232
267
|
let converted;
|
|
233
268
|
|
|
234
|
-
if (typeof value ===
|
|
235
|
-
converted =
|
|
236
|
-
? moment.utc()
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
else if (typeof value === 'number') { // epoch or epoch-millis
|
|
269
|
+
if (typeof value === "string") {
|
|
270
|
+
converted =
|
|
271
|
+
value === "NOW" ? moment.utc() : moment.utc(value, moment.ISO_8601);
|
|
272
|
+
} else if (typeof value === "number") {
|
|
273
|
+
// epoch or epoch-millis
|
|
240
274
|
converted = moment.utc(value);
|
|
241
275
|
}
|
|
242
276
|
|
|
243
|
-
if (!
|
|
244
|
-
throw typeError.get(
|
|
277
|
+
if (!converted || !converted.isValid()) {
|
|
278
|
+
throw typeError.get("invalid_date", value);
|
|
245
279
|
}
|
|
246
280
|
|
|
247
281
|
return converted;
|