@nestjs/common 11.1.15 → 12.0.0-alpha.0
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/constants.js +35 -38
- package/decorators/core/apply-decorators.js +1 -4
- package/decorators/core/bind.decorator.js +1 -4
- package/decorators/core/catch.decorator.d.ts +1 -1
- package/decorators/core/catch.decorator.js +4 -7
- package/decorators/core/controller.decorator.d.ts +1 -1
- package/decorators/core/controller.decorator.js +10 -13
- package/decorators/core/dependencies.decorator.js +4 -9
- package/decorators/core/exception-filters.decorator.d.ts +1 -1
- package/decorators/core/exception-filters.decorator.js +10 -14
- package/decorators/core/index.d.ts +14 -14
- package/decorators/core/index.js +14 -17
- package/decorators/core/inject.decorator.d.ts +1 -1
- package/decorators/core/inject.decorator.js +9 -12
- package/decorators/core/injectable.decorator.d.ts +2 -2
- package/decorators/core/injectable.decorator.js +7 -11
- package/decorators/core/optional.decorator.js +8 -11
- package/decorators/core/set-metadata.decorator.js +1 -5
- package/decorators/core/use-guards.decorator.d.ts +1 -1
- package/decorators/core/use-guards.decorator.js +10 -13
- package/decorators/core/use-interceptors.decorator.d.ts +1 -1
- package/decorators/core/use-interceptors.decorator.js +10 -13
- package/decorators/core/use-pipes.decorator.d.ts +1 -1
- package/decorators/core/use-pipes.decorator.js +9 -12
- package/decorators/core/version.decorator.d.ts +1 -1
- package/decorators/core/version.decorator.js +3 -6
- package/decorators/http/create-route-param-metadata.decorator.d.ts +6 -5
- package/decorators/http/create-route-param-metadata.decorator.js +48 -16
- package/decorators/http/header.decorator.js +4 -7
- package/decorators/http/http-code.decorator.js +3 -6
- package/decorators/http/index.d.ts +8 -8
- package/decorators/http/index.js +8 -11
- package/decorators/http/redirect.decorator.js +3 -6
- package/decorators/http/render.decorator.js +3 -6
- package/decorators/http/request-mapping.decorator.d.ts +1 -1
- package/decorators/http/request-mapping.decorator.js +28 -32
- package/decorators/http/route-params.decorator.d.ts +153 -3
- package/decorators/http/route-params.decorator.js +124 -49
- package/decorators/http/sse.decorator.d.ts +2 -2
- package/decorators/http/sse.decorator.js +7 -10
- package/decorators/index.d.ts +3 -3
- package/decorators/index.js +3 -6
- package/decorators/modules/global.decorator.js +3 -6
- package/decorators/modules/index.d.ts +2 -2
- package/decorators/modules/index.js +2 -5
- package/decorators/modules/module.decorator.d.ts +1 -1
- package/decorators/modules/module.decorator.js +3 -6
- package/enums/http-status.enum.js +2 -5
- package/enums/index.d.ts +4 -4
- package/enums/index.js +4 -7
- package/enums/request-method.enum.js +2 -5
- package/enums/route-paramtypes.enum.js +2 -5
- package/enums/shutdown-signal.enum.js +2 -5
- package/enums/version-type.enum.js +2 -5
- package/exceptions/bad-gateway.exception.d.ts +1 -1
- package/exceptions/bad-gateway.exception.js +5 -9
- package/exceptions/bad-request.exception.d.ts +1 -1
- package/exceptions/bad-request.exception.js +5 -9
- package/exceptions/conflict.exception.d.ts +1 -1
- package/exceptions/conflict.exception.js +5 -9
- package/exceptions/forbidden.exception.d.ts +1 -1
- package/exceptions/forbidden.exception.js +5 -9
- package/exceptions/gateway-timeout.exception.d.ts +1 -1
- package/exceptions/gateway-timeout.exception.js +5 -9
- package/exceptions/gone.exception.d.ts +1 -1
- package/exceptions/gone.exception.js +5 -9
- package/exceptions/http-version-not-supported.exception.d.ts +1 -1
- package/exceptions/http-version-not-supported.exception.js +5 -9
- package/exceptions/http.exception.d.ts +6 -2
- package/exceptions/http.exception.js +36 -17
- package/exceptions/im-a-teapot.exception.d.ts +1 -1
- package/exceptions/im-a-teapot.exception.js +5 -9
- package/exceptions/index.d.ts +23 -23
- package/exceptions/index.js +23 -26
- package/exceptions/internal-server-error.exception.d.ts +1 -1
- package/exceptions/internal-server-error.exception.js +5 -9
- package/exceptions/intrinsic.exception.js +1 -5
- package/exceptions/method-not-allowed.exception.d.ts +1 -1
- package/exceptions/method-not-allowed.exception.js +5 -9
- package/exceptions/misdirected.exception.d.ts +1 -1
- package/exceptions/misdirected.exception.js +5 -9
- package/exceptions/not-acceptable.exception.d.ts +1 -1
- package/exceptions/not-acceptable.exception.js +5 -9
- package/exceptions/not-found.exception.d.ts +1 -1
- package/exceptions/not-found.exception.js +5 -9
- package/exceptions/not-implemented.exception.d.ts +1 -1
- package/exceptions/not-implemented.exception.js +5 -9
- package/exceptions/payload-too-large.exception.d.ts +1 -1
- package/exceptions/payload-too-large.exception.js +5 -9
- package/exceptions/precondition-failed.exception.d.ts +1 -1
- package/exceptions/precondition-failed.exception.js +5 -9
- package/exceptions/request-timeout.exception.d.ts +1 -1
- package/exceptions/request-timeout.exception.js +5 -9
- package/exceptions/service-unavailable.exception.d.ts +1 -1
- package/exceptions/service-unavailable.exception.js +5 -9
- package/exceptions/unauthorized.exception.d.ts +1 -1
- package/exceptions/unauthorized.exception.js +5 -9
- package/exceptions/unprocessable-entity.exception.d.ts +1 -1
- package/exceptions/unprocessable-entity.exception.js +5 -9
- package/exceptions/unsupported-media-type.exception.d.ts +1 -1
- package/exceptions/unsupported-media-type.exception.js +5 -9
- package/file-stream/index.d.ts +1 -1
- package/file-stream/index.js +1 -4
- package/file-stream/interfaces/index.d.ts +2 -2
- package/file-stream/interfaces/index.js +2 -5
- package/file-stream/interfaces/streamable-handler-response.interface.js +1 -2
- package/file-stream/interfaces/streamable-options.interface.js +1 -2
- package/file-stream/streamable-file.d.ts +2 -2
- package/file-stream/streamable-file.js +26 -28
- package/index.d.ts +10 -10
- package/index.js +11 -17
- package/interfaces/abstract.interface.js +1 -2
- package/interfaces/controllers/controller-metadata.interface.js +1 -2
- package/interfaces/controllers/controller.interface.js +1 -2
- package/interfaces/controllers/index.d.ts +2 -2
- package/interfaces/controllers/index.js +2 -5
- package/interfaces/exceptions/exception-filter-metadata.interface.d.ts +2 -2
- package/interfaces/exceptions/exception-filter-metadata.interface.js +1 -2
- package/interfaces/exceptions/exception-filter.interface.d.ts +1 -1
- package/interfaces/exceptions/exception-filter.interface.js +1 -2
- package/interfaces/exceptions/index.d.ts +5 -5
- package/interfaces/exceptions/index.js +5 -8
- package/interfaces/exceptions/rpc-exception-filter-metadata.interface.d.ts +2 -2
- package/interfaces/exceptions/rpc-exception-filter-metadata.interface.js +1 -2
- package/interfaces/exceptions/rpc-exception-filter.interface.d.ts +1 -1
- package/interfaces/exceptions/rpc-exception-filter.interface.js +1 -2
- package/interfaces/exceptions/ws-exception-filter.interface.d.ts +1 -1
- package/interfaces/exceptions/ws-exception-filter.interface.js +1 -2
- package/interfaces/external/class-transform-options.interface.js +1 -2
- package/interfaces/external/cors-options.interface.js +1 -2
- package/interfaces/external/https-options.interface.js +1 -2
- package/interfaces/external/transformer-package.interface.d.ts +2 -2
- package/interfaces/external/transformer-package.interface.js +1 -2
- package/interfaces/external/validation-error.interface.js +1 -2
- package/interfaces/external/validator-options.interface.js +1 -2
- package/interfaces/external/validator-package.interface.d.ts +2 -2
- package/interfaces/external/validator-package.interface.js +1 -2
- package/interfaces/features/arguments-host.interface.js +1 -2
- package/interfaces/features/can-activate.interface.d.ts +1 -1
- package/interfaces/features/can-activate.interface.js +1 -2
- package/interfaces/features/custom-route-param-factory.interface.d.ts +1 -1
- package/interfaces/features/custom-route-param-factory.interface.js +1 -2
- package/interfaces/features/execution-context.interface.d.ts +2 -2
- package/interfaces/features/execution-context.interface.js +1 -2
- package/interfaces/features/nest-interceptor.interface.d.ts +1 -1
- package/interfaces/features/nest-interceptor.interface.js +1 -2
- package/interfaces/features/paramtype.interface.js +1 -2
- package/interfaces/features/pipe-transform.interface.d.ts +10 -4
- package/interfaces/features/pipe-transform.interface.js +1 -2
- package/interfaces/global-prefix-options.interface.d.ts +1 -1
- package/interfaces/global-prefix-options.interface.js +1 -2
- package/interfaces/hooks/before-application-shutdown.interface.js +1 -2
- package/interfaces/hooks/index.d.ts +5 -5
- package/interfaces/hooks/index.js +5 -8
- package/interfaces/hooks/on-application-bootstrap.interface.js +1 -2
- package/interfaces/hooks/on-application-shutdown.interface.js +1 -2
- package/interfaces/hooks/on-destroy.interface.js +1 -2
- package/interfaces/hooks/on-init.interface.js +1 -2
- package/interfaces/http/http-exception-body.interface.d.ts +2 -1
- package/interfaces/http/http-exception-body.interface.js +1 -2
- package/interfaces/http/http-redirect-response.interface.d.ts +1 -1
- package/interfaces/http/http-redirect-response.interface.js +1 -2
- package/interfaces/http/http-server.interface.d.ts +4 -3
- package/interfaces/http/http-server.interface.js +1 -2
- package/interfaces/http/index.d.ts +5 -5
- package/interfaces/http/index.js +5 -8
- package/interfaces/http/message-event.interface.js +1 -2
- package/interfaces/http/raw-body-request.interface.js +1 -2
- package/interfaces/index.d.ts +31 -30
- package/interfaces/index.js +31 -33
- package/interfaces/injectable.interface.js +1 -2
- package/interfaces/microservices/nest-hybrid-application-options.interface.js +1 -2
- package/interfaces/microservices/nest-microservice-options.interface.d.ts +1 -1
- package/interfaces/microservices/nest-microservice-options.interface.js +1 -2
- package/interfaces/microservices/pre-request-hook.interface.d.ts +22 -0
- package/interfaces/microservices/pre-request-hook.interface.js +1 -0
- package/interfaces/middleware/index.d.ts +4 -4
- package/interfaces/middleware/index.js +4 -7
- package/interfaces/middleware/middleware-config-proxy.interface.d.ts +3 -3
- package/interfaces/middleware/middleware-config-proxy.interface.js +1 -2
- package/interfaces/middleware/middleware-configuration.interface.d.ts +3 -3
- package/interfaces/middleware/middleware-configuration.interface.js +1 -2
- package/interfaces/middleware/middleware-consumer.interface.d.ts +2 -2
- package/interfaces/middleware/middleware-consumer.interface.js +1 -2
- package/interfaces/middleware/nest-middleware.interface.js +1 -2
- package/interfaces/modules/dynamic-module.interface.d.ts +2 -2
- package/interfaces/modules/dynamic-module.interface.js +1 -2
- package/interfaces/modules/forward-reference.interface.js +1 -2
- package/interfaces/modules/index.d.ts +8 -8
- package/interfaces/modules/index.js +8 -11
- package/interfaces/modules/injection-token.interface.d.ts +2 -2
- package/interfaces/modules/injection-token.interface.js +1 -2
- package/interfaces/modules/introspection-result.interface.d.ts +1 -1
- package/interfaces/modules/introspection-result.interface.js +1 -2
- package/interfaces/modules/module-metadata.interface.d.ts +5 -5
- package/interfaces/modules/module-metadata.interface.js +1 -2
- package/interfaces/modules/nest-module.interface.d.ts +1 -1
- package/interfaces/modules/nest-module.interface.js +1 -2
- package/interfaces/modules/optional-factory-dependency.interface.d.ts +1 -1
- package/interfaces/modules/optional-factory-dependency.interface.js +1 -2
- package/interfaces/modules/provider.interface.d.ts +4 -4
- package/interfaces/modules/provider.interface.js +1 -2
- package/interfaces/nest-application-context-options.interface.d.ts +1 -1
- package/interfaces/nest-application-context-options.interface.js +55 -5
- package/interfaces/nest-application-context.interface.d.ts +6 -6
- package/interfaces/nest-application-context.interface.js +1 -2
- package/interfaces/nest-application-options.interface.d.ts +9 -3
- package/interfaces/nest-application-options.interface.js +1 -2
- package/interfaces/nest-application.interface.d.ts +8 -8
- package/interfaces/nest-application.interface.js +1 -2
- package/interfaces/nest-microservice.interface.d.ts +15 -6
- package/interfaces/nest-microservice.interface.js +1 -2
- package/interfaces/scope-options.interface.js +2 -5
- package/interfaces/shutdown-hooks-options.interface.js +1 -2
- package/interfaces/type.interface.js +1 -2
- package/interfaces/version-options.interface.d.ts +1 -1
- package/interfaces/version-options.interface.js +1 -4
- package/interfaces/websockets/web-socket-adapter.interface.js +1 -2
- package/internal.d.ts +30 -0
- package/internal.js +19 -0
- package/module-utils/configurable-module.builder.d.ts +4 -4
- package/module-utils/configurable-module.builder.js +21 -20
- package/module-utils/constants.js +5 -8
- package/module-utils/index.d.ts +2 -2
- package/module-utils/index.js +2 -5
- package/module-utils/interfaces/configurable-module-async-options.interface.d.ts +2 -2
- package/module-utils/interfaces/configurable-module-async-options.interface.js +1 -2
- package/module-utils/interfaces/configurable-module-cls.interface.d.ts +3 -3
- package/module-utils/interfaces/configurable-module-cls.interface.js +1 -2
- package/module-utils/interfaces/configurable-module-host.interface.d.ts +2 -2
- package/module-utils/interfaces/configurable-module-host.interface.js +1 -2
- package/module-utils/interfaces/index.d.ts +3 -3
- package/module-utils/interfaces/index.js +3 -6
- package/module-utils/utils/generate-options-injection-token.util.js +3 -6
- package/module-utils/utils/get-injection-providers.util.d.ts +1 -1
- package/module-utils/utils/get-injection-providers.util.js +4 -7
- package/module-utils/utils/index.d.ts +2 -2
- package/module-utils/utils/index.js +2 -5
- package/package.json +35 -2
- package/pipes/default-value.pipe.d.ts +1 -1
- package/pipes/default-value.pipe.js +10 -12
- package/pipes/file/file-type.validator.d.ts +3 -3
- package/pipes/file/file-type.validator.js +5 -19
- package/pipes/file/file-validator-context.interface.d.ts +1 -1
- package/pipes/file/file-validator-context.interface.js +1 -2
- package/pipes/file/file-validator.interface.d.ts +1 -1
- package/pipes/file/file-validator.interface.js +2 -5
- package/pipes/file/index.d.ts +6 -6
- package/pipes/file/index.js +6 -9
- package/pipes/file/interfaces/file.interface.js +1 -2
- package/pipes/file/interfaces/index.d.ts +1 -1
- package/pipes/file/interfaces/index.js +1 -4
- package/pipes/file/max-file-size.validator.d.ts +3 -3
- package/pipes/file/max-file-size.validator.js +2 -6
- package/pipes/file/parse-file-options.interface.d.ts +2 -2
- package/pipes/file/parse-file-options.interface.js +1 -2
- package/pipes/file/parse-file-pipe.builder.d.ts +5 -5
- package/pipes/file/parse-file-pipe.builder.js +8 -14
- package/pipes/file/parse-file.pipe.d.ts +7 -7
- package/pipes/file/parse-file.pipe.js +17 -18
- package/pipes/index.d.ts +11 -10
- package/pipes/index.js +11 -13
- package/pipes/parse-array.pipe.d.ts +4 -4
- package/pipes/parse-array.pipe.js +23 -23
- package/pipes/parse-bool.pipe.d.ts +6 -6
- package/pipes/parse-bool.pipe.js +16 -17
- package/pipes/parse-date.pipe.d.ts +4 -4
- package/pipes/parse-date.pipe.js +17 -16
- package/pipes/parse-enum.pipe.d.ts +5 -5
- package/pipes/parse-enum.pipe.js +16 -16
- package/pipes/parse-float.pipe.d.ts +6 -6
- package/pipes/parse-float.pipe.js +17 -18
- package/pipes/parse-int.pipe.d.ts +5 -5
- package/pipes/parse-int.pipe.js +18 -19
- package/pipes/parse-uuid.pipe.d.ts +4 -4
- package/pipes/parse-uuid.pipe.js +27 -26
- package/pipes/standard-schema-validation.pipe.d.ts +86 -0
- package/pipes/standard-schema-validation.pipe.js +120 -0
- package/pipes/validation.pipe.d.ts +32 -14
- package/pipes/validation.pipe.js +60 -30
- package/serializer/class-serializer.constants.js +1 -4
- package/serializer/class-serializer.interceptor.d.ts +5 -5
- package/serializer/class-serializer.interceptor.js +21 -24
- package/serializer/class-serializer.interfaces.d.ts +2 -2
- package/serializer/class-serializer.interfaces.js +1 -2
- package/serializer/decorators/index.d.ts +1 -1
- package/serializer/decorators/index.js +1 -4
- package/serializer/decorators/serialize-options.decorator.d.ts +3 -2
- package/serializer/decorators/serialize-options.decorator.js +3 -7
- package/serializer/index.d.ts +5 -3
- package/serializer/index.js +5 -6
- package/serializer/standard-schema-serializer.interceptor.d.ts +50 -0
- package/serializer/standard-schema-serializer.interceptor.js +75 -0
- package/serializer/standard-schema-serializer.interfaces.d.ts +18 -0
- package/serializer/standard-schema-serializer.interfaces.js +1 -0
- package/services/console-logger.service.d.ts +22 -3
- package/services/console-logger.service.js +132 -66
- package/services/index.d.ts +3 -3
- package/services/index.js +3 -6
- package/services/logger.service.js +86 -83
- package/services/utils/filter-log-levels.util.d.ts +1 -1
- package/services/utils/filter-log-levels.util.js +7 -10
- package/services/utils/index.d.ts +3 -3
- package/services/utils/index.js +3 -6
- package/services/utils/is-log-level-enabled.util.d.ts +1 -1
- package/services/utils/is-log-level-enabled.util.js +1 -4
- package/services/utils/is-log-level.util.d.ts +1 -1
- package/services/utils/is-log-level.util.js +3 -6
- package/tsconfig.build.json +1 -2
- package/utils/assign-custom-metadata.util.d.ts +5 -4
- package/utils/assign-custom-metadata.util.js +4 -6
- package/utils/cli-colors.util.js +4 -8
- package/utils/extend-metadata.util.js +1 -4
- package/utils/forward-ref.util.d.ts +1 -1
- package/utils/forward-ref.util.js +1 -5
- package/utils/http-error-by-code.util.d.ts +2 -2
- package/utils/http-error-by-code.util.js +22 -25
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -4
- package/utils/load-package.util.d.ts +21 -1
- package/utils/load-package.util.js +62 -8
- package/utils/merge-with-values.util.js +1 -5
- package/utils/random-string-generator.util.js +2 -6
- package/utils/select-exception-filter-metadata.util.d.ts +1 -1
- package/utils/select-exception-filter-metadata.util.js +1 -5
- package/utils/shared.utils.d.ts +11 -10
- package/utils/shared.utils.js +28 -30
- package/utils/validate-each.util.js +3 -7
- package/utils/validate-module-keys.util.js +8 -13
package/pipes/parse-uuid.pipe.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var ParseUUIDPipe_1;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
10
|
-
const shared_utils_1 = require("../utils/shared.utils");
|
|
2
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
3
|
+
import { Injectable } from '../decorators/core/injectable.decorator.js';
|
|
4
|
+
import { Optional } from '../decorators/core/optional.decorator.js';
|
|
5
|
+
import { HttpStatus } from '../enums/http-status.enum.js';
|
|
6
|
+
import { HttpErrorByCode, } from '../utils/http-error-by-code.util.js';
|
|
7
|
+
import { isNil, isString } from '../utils/shared.utils.js';
|
|
11
8
|
/**
|
|
12
9
|
* Defines the built-in ParseUUID Pipe
|
|
13
10
|
*
|
|
@@ -15,18 +12,29 @@ const shared_utils_1 = require("../utils/shared.utils");
|
|
|
15
12
|
*
|
|
16
13
|
* @publicApi
|
|
17
14
|
*/
|
|
18
|
-
let ParseUUIDPipe =
|
|
15
|
+
let ParseUUIDPipe = class ParseUUIDPipe {
|
|
16
|
+
static { ParseUUIDPipe_1 = this; }
|
|
17
|
+
options;
|
|
18
|
+
static uuidRegExps = {
|
|
19
|
+
3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
20
|
+
4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
21
|
+
5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
22
|
+
7: /^[0-9A-F]{8}-[0-9A-F]{4}-7[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
23
|
+
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
24
|
+
};
|
|
25
|
+
version;
|
|
26
|
+
exceptionFactory;
|
|
19
27
|
constructor(options) {
|
|
20
28
|
this.options = options;
|
|
21
29
|
options = options || {};
|
|
22
|
-
const { exceptionFactory, errorHttpStatusCode =
|
|
30
|
+
const { exceptionFactory, errorHttpStatusCode = HttpStatus.BAD_REQUEST, version, } = options;
|
|
23
31
|
this.version = version;
|
|
24
32
|
this.exceptionFactory =
|
|
25
33
|
exceptionFactory ||
|
|
26
|
-
(error => new
|
|
34
|
+
(error => new HttpErrorByCode[errorHttpStatusCode](error));
|
|
27
35
|
}
|
|
28
36
|
async transform(value, metadata) {
|
|
29
|
-
if (
|
|
37
|
+
if (isNil(value) && this.options?.optional) {
|
|
30
38
|
return value;
|
|
31
39
|
}
|
|
32
40
|
if (!this.isUUID(value, this.version)) {
|
|
@@ -35,23 +43,16 @@ let ParseUUIDPipe = ParseUUIDPipe_1 = class ParseUUIDPipe {
|
|
|
35
43
|
return value;
|
|
36
44
|
}
|
|
37
45
|
isUUID(str, version = 'all') {
|
|
38
|
-
if (!
|
|
46
|
+
if (!isString(str)) {
|
|
39
47
|
throw this.exceptionFactory('The value passed as UUID is not a string');
|
|
40
48
|
}
|
|
41
49
|
const pattern = ParseUUIDPipe_1.uuidRegExps[version];
|
|
42
50
|
return pattern?.test(str);
|
|
43
51
|
}
|
|
44
52
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
50
|
-
7: /^[0-9A-F]{8}-[0-9A-F]{4}-7[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
51
|
-
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
52
|
-
};
|
|
53
|
-
exports.ParseUUIDPipe = ParseUUIDPipe = ParseUUIDPipe_1 = tslib_1.__decorate([
|
|
54
|
-
(0, injectable_decorator_1.Injectable)(),
|
|
55
|
-
tslib_1.__param(0, (0, optional_decorator_1.Optional)()),
|
|
56
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
53
|
+
ParseUUIDPipe = ParseUUIDPipe_1 = __decorate([
|
|
54
|
+
Injectable(),
|
|
55
|
+
__param(0, Optional()),
|
|
56
|
+
__metadata("design:paramtypes", [Object])
|
|
57
57
|
], ParseUUIDPipe);
|
|
58
|
+
export { ParseUUIDPipe };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
3
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util.js';
|
|
4
|
+
/**
|
|
5
|
+
* @publicApi
|
|
6
|
+
*/
|
|
7
|
+
export interface StandardSchemaValidationPipeOptions {
|
|
8
|
+
/**
|
|
9
|
+
* If true, the pipe will return the value produced by the schema
|
|
10
|
+
* (which may differ from the input if the schema coerces/transforms values).
|
|
11
|
+
* If false, the original input value is returned after successful validation.
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
transform?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* If true, the pipe will also validate parameters decorated with custom decorators
|
|
17
|
+
* (created with `createParamDecorator`). When false, custom parameters are skipped.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
validateCustomDecorators?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Options to pass to the standard schema `validate` function.
|
|
23
|
+
* These options are forwarded as the second argument to the schema's `~standard.validate` method.
|
|
24
|
+
*/
|
|
25
|
+
validateOptions?: Record<string, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* The HTTP status code to be used in the response when the validation fails.
|
|
28
|
+
* @default HttpStatus.BAD_REQUEST
|
|
29
|
+
*/
|
|
30
|
+
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
31
|
+
/**
|
|
32
|
+
* A factory function that returns an exception object to be thrown
|
|
33
|
+
* if validation fails.
|
|
34
|
+
* @param issues The issues returned by the standard schema validation
|
|
35
|
+
* @returns The exception object
|
|
36
|
+
*/
|
|
37
|
+
exceptionFactory?: (issues: readonly StandardSchemaV1.Issue[]) => any;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Defines the built-in StandardSchemaValidation Pipe.
|
|
41
|
+
*
|
|
42
|
+
* Uses a standard schema object (conforming to the Standard Schema spec)
|
|
43
|
+
* attached to the parameter metadata to validate incoming values.
|
|
44
|
+
*
|
|
45
|
+
* @see [Standard Schema](https://github.com/standard-schema/standard-schema)
|
|
46
|
+
*
|
|
47
|
+
* @publicApi
|
|
48
|
+
*/
|
|
49
|
+
export declare class StandardSchemaValidationPipe implements PipeTransform {
|
|
50
|
+
protected readonly options?: StandardSchemaValidationPipeOptions | undefined;
|
|
51
|
+
protected isTransformEnabled: boolean;
|
|
52
|
+
protected validateCustomDecorators: boolean;
|
|
53
|
+
protected validateOptions: Record<string, unknown> | undefined;
|
|
54
|
+
protected exceptionFactory: (issues: readonly StandardSchemaV1.Issue[]) => any;
|
|
55
|
+
constructor(options?: StandardSchemaValidationPipeOptions | undefined);
|
|
56
|
+
/**
|
|
57
|
+
* Method that validates the incoming value against the standard schema
|
|
58
|
+
* provided in the parameter metadata.
|
|
59
|
+
*
|
|
60
|
+
* @param value currently processed route argument
|
|
61
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
62
|
+
*/
|
|
63
|
+
transform<T = any>(value: T, metadata: ArgumentMetadata): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* Determines whether validation should be performed for the given metadata.
|
|
66
|
+
* Skips validation for custom decorators unless `validateCustomDecorators` is enabled.
|
|
67
|
+
*
|
|
68
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
69
|
+
* @returns `true` if validation should be performed
|
|
70
|
+
*/
|
|
71
|
+
protected toValidate(metadata: ArgumentMetadata): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Validates a value against a standard schema.
|
|
74
|
+
* Can be overridden to customize validation behavior.
|
|
75
|
+
*
|
|
76
|
+
* @param value The value to validate
|
|
77
|
+
* @param schema The standard schema to validate against
|
|
78
|
+
* @param options Optional options forwarded to the schema's validate method
|
|
79
|
+
* @returns The validation result
|
|
80
|
+
*/
|
|
81
|
+
protected validate<T = unknown>(value: unknown, schema: StandardSchemaV1, options?: Record<string, unknown>): Promise<StandardSchemaV1.Result<T>> | StandardSchemaV1.Result<T>;
|
|
82
|
+
/**
|
|
83
|
+
* Strips dangerous prototype pollution keys from an object.
|
|
84
|
+
*/
|
|
85
|
+
protected stripProtoKeys(value: any): void;
|
|
86
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { types } from 'util';
|
|
3
|
+
import { Injectable } from '../decorators/core/injectable.decorator.js';
|
|
4
|
+
import { Optional } from '../decorators/core/optional.decorator.js';
|
|
5
|
+
import { HttpStatus } from '../enums/http-status.enum.js';
|
|
6
|
+
import { HttpErrorByCode, } from '../utils/http-error-by-code.util.js';
|
|
7
|
+
/**
|
|
8
|
+
* Built-in JavaScript types that should be excluded from prototype stripping
|
|
9
|
+
* to avoid conflicts with test frameworks like Jest's useFakeTimers
|
|
10
|
+
*/
|
|
11
|
+
const BUILT_IN_TYPES = [Date, RegExp, Error, Map, Set, WeakMap, WeakSet];
|
|
12
|
+
/**
|
|
13
|
+
* Defines the built-in StandardSchemaValidation Pipe.
|
|
14
|
+
*
|
|
15
|
+
* Uses a standard schema object (conforming to the Standard Schema spec)
|
|
16
|
+
* attached to the parameter metadata to validate incoming values.
|
|
17
|
+
*
|
|
18
|
+
* @see [Standard Schema](https://github.com/standard-schema/standard-schema)
|
|
19
|
+
*
|
|
20
|
+
* @publicApi
|
|
21
|
+
*/
|
|
22
|
+
let StandardSchemaValidationPipe = class StandardSchemaValidationPipe {
|
|
23
|
+
options;
|
|
24
|
+
isTransformEnabled;
|
|
25
|
+
validateCustomDecorators;
|
|
26
|
+
validateOptions;
|
|
27
|
+
exceptionFactory;
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.options = options;
|
|
30
|
+
const { transform = true, validateCustomDecorators = false, validateOptions, exceptionFactory, errorHttpStatusCode = HttpStatus.BAD_REQUEST, } = options || {};
|
|
31
|
+
this.isTransformEnabled = transform;
|
|
32
|
+
this.validateCustomDecorators = validateCustomDecorators;
|
|
33
|
+
this.validateOptions = validateOptions;
|
|
34
|
+
this.exceptionFactory =
|
|
35
|
+
exceptionFactory ||
|
|
36
|
+
(issues => {
|
|
37
|
+
const messages = issues.map(issue => issue.message);
|
|
38
|
+
return new HttpErrorByCode[errorHttpStatusCode](messages);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Method that validates the incoming value against the standard schema
|
|
43
|
+
* provided in the parameter metadata.
|
|
44
|
+
*
|
|
45
|
+
* @param value currently processed route argument
|
|
46
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
47
|
+
*/
|
|
48
|
+
async transform(value, metadata) {
|
|
49
|
+
const schema = metadata.schema;
|
|
50
|
+
if (!schema || !this.toValidate(metadata)) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
this.stripProtoKeys(value);
|
|
54
|
+
const result = await this.validate(value, schema, this.validateOptions);
|
|
55
|
+
if (result.issues) {
|
|
56
|
+
throw this.exceptionFactory(result.issues);
|
|
57
|
+
}
|
|
58
|
+
return this.isTransformEnabled ? result.value : value;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Determines whether validation should be performed for the given metadata.
|
|
62
|
+
* Skips validation for custom decorators unless `validateCustomDecorators` is enabled.
|
|
63
|
+
*
|
|
64
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
65
|
+
* @returns `true` if validation should be performed
|
|
66
|
+
*/
|
|
67
|
+
toValidate(metadata) {
|
|
68
|
+
const { type } = metadata;
|
|
69
|
+
if (type === 'custom' && !this.validateCustomDecorators) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Validates a value against a standard schema.
|
|
76
|
+
* Can be overridden to customize validation behavior.
|
|
77
|
+
*
|
|
78
|
+
* @param value The value to validate
|
|
79
|
+
* @param schema The standard schema to validate against
|
|
80
|
+
* @param options Optional options forwarded to the schema's validate method
|
|
81
|
+
* @returns The validation result
|
|
82
|
+
*/
|
|
83
|
+
validate(value, schema, options) {
|
|
84
|
+
return schema['~standard'].validate(value, options);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Strips dangerous prototype pollution keys from an object.
|
|
88
|
+
*/
|
|
89
|
+
stripProtoKeys(value) {
|
|
90
|
+
if (value == null ||
|
|
91
|
+
typeof value !== 'object' ||
|
|
92
|
+
types.isTypedArray(value)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (BUILT_IN_TYPES.some(type => value instanceof type)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(value)) {
|
|
99
|
+
for (const v of value) {
|
|
100
|
+
this.stripProtoKeys(v);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
delete value.__proto__;
|
|
105
|
+
delete value.prototype;
|
|
106
|
+
const constructorType = value?.constructor;
|
|
107
|
+
if (constructorType && !BUILT_IN_TYPES.includes(constructorType)) {
|
|
108
|
+
delete value.constructor;
|
|
109
|
+
}
|
|
110
|
+
for (const key in value) {
|
|
111
|
+
this.stripProtoKeys(value[key]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
StandardSchemaValidationPipe = __decorate([
|
|
116
|
+
Injectable(),
|
|
117
|
+
__param(0, Optional()),
|
|
118
|
+
__metadata("design:paramtypes", [Object])
|
|
119
|
+
], StandardSchemaValidationPipe);
|
|
120
|
+
export { StandardSchemaValidationPipe };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { ClassTransformOptions } from '../interfaces/external/class-transform-options.interface';
|
|
2
|
-
import { TransformerPackage } from '../interfaces/external/transformer-package.interface';
|
|
3
|
-
import { ValidationError } from '../interfaces/external/validation-error.interface';
|
|
4
|
-
import { ValidatorOptions } from '../interfaces/external/validator-options.interface';
|
|
5
|
-
import { ValidatorPackage } from '../interfaces/external/validator-package.interface';
|
|
6
|
-
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
7
|
-
import { Type } from '../interfaces/type.interface';
|
|
8
|
-
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
1
|
+
import { ClassTransformOptions } from '../interfaces/external/class-transform-options.interface.js';
|
|
2
|
+
import { TransformerPackage } from '../interfaces/external/transformer-package.interface.js';
|
|
3
|
+
import { ValidationError } from '../interfaces/external/validation-error.interface.js';
|
|
4
|
+
import { ValidatorOptions } from '../interfaces/external/validator-options.interface.js';
|
|
5
|
+
import { ValidatorPackage } from '../interfaces/external/validator-package.interface.js';
|
|
6
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
7
|
+
import { Type } from '../interfaces/type.interface.js';
|
|
8
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util.js';
|
|
9
|
+
/**
|
|
10
|
+
* @publicApi
|
|
11
|
+
*/
|
|
12
|
+
export type ValidationErrorFormat = 'list' | 'grouped';
|
|
9
13
|
/**
|
|
10
14
|
* @publicApi
|
|
11
15
|
*/
|
|
@@ -19,13 +23,25 @@ export interface ValidationPipeOptions extends ValidatorOptions {
|
|
|
19
23
|
expectedType?: Type<any>;
|
|
20
24
|
validatorPackage?: ValidatorPackage;
|
|
21
25
|
transformerPackage?: TransformerPackage;
|
|
26
|
+
/**
|
|
27
|
+
* Specifies the format of validation error messages.
|
|
28
|
+
* - 'list': Returns an array of error message strings (default). The response message is `string[]`.
|
|
29
|
+
* - 'grouped': Returns an object with property paths as keys and arrays of unmodified error messages as values.
|
|
30
|
+
* The response message is `Record<string, string[]>`. Custom messages defined in validation decorators
|
|
31
|
+
* (e.g., `@IsNotEmpty({ message: 'Name is required' })`) are preserved without parent path prefixes.
|
|
32
|
+
*
|
|
33
|
+
* @remarks
|
|
34
|
+
* When using 'grouped', the `message` property in the error response changes from `string[]` to `Record<string, string[]>`.
|
|
35
|
+
* If you have exception filters or interceptors that assume `message` is always an array, they will need to be updated.
|
|
36
|
+
*/
|
|
37
|
+
errorFormat?: ValidationErrorFormat;
|
|
22
38
|
}
|
|
23
39
|
/**
|
|
24
40
|
* @see [Validation](https://docs.nestjs.com/techniques/validation)
|
|
25
41
|
*
|
|
26
42
|
* @publicApi
|
|
27
43
|
*/
|
|
28
|
-
export declare class ValidationPipe implements PipeTransform
|
|
44
|
+
export declare class ValidationPipe implements PipeTransform {
|
|
29
45
|
protected isTransformEnabled: boolean;
|
|
30
46
|
protected isDetailedOutputDisabled?: boolean;
|
|
31
47
|
protected validatorOptions: ValidatorOptions;
|
|
@@ -34,18 +50,20 @@ export declare class ValidationPipe implements PipeTransform<any> {
|
|
|
34
50
|
protected expectedType: Type<any> | undefined;
|
|
35
51
|
protected exceptionFactory: (errors: ValidationError[]) => any;
|
|
36
52
|
protected validateCustomDecorators: boolean;
|
|
53
|
+
protected errorFormat: ValidationErrorFormat;
|
|
37
54
|
constructor(options?: ValidationPipeOptions);
|
|
38
|
-
protected loadValidator(validatorPackage?: ValidatorPackage): ValidatorPackage
|
|
39
|
-
protected loadTransformer(transformerPackage?: TransformerPackage): TransformerPackage
|
|
40
|
-
transform(value:
|
|
55
|
+
protected loadValidator(validatorPackage?: ValidatorPackage): ValidatorPackage | Promise<ValidatorPackage>;
|
|
56
|
+
protected loadTransformer(transformerPackage?: TransformerPackage): TransformerPackage | Promise<TransformerPackage>;
|
|
57
|
+
transform(value: unknown, metadata: ArgumentMetadata): Promise<any>;
|
|
41
58
|
createExceptionFactory(): (validationErrors?: ValidationError[]) => unknown;
|
|
42
59
|
protected toValidate(metadata: ArgumentMetadata): boolean;
|
|
43
|
-
protected transformPrimitive(value:
|
|
44
|
-
protected toEmptyIfNil<T = any, R = T>(value:
|
|
60
|
+
protected transformPrimitive(value: unknown, metadata: ArgumentMetadata): unknown;
|
|
61
|
+
protected toEmptyIfNil<T = any, R = T>(value: unknown, metatype: Type<unknown> | object): R | object | string;
|
|
45
62
|
protected stripProtoKeys(value: any): void;
|
|
46
63
|
protected isPrimitive(value: unknown): boolean;
|
|
47
64
|
protected validate(object: object, validatorOptions?: ValidatorOptions): Promise<ValidationError[]> | ValidationError[];
|
|
48
65
|
protected flattenValidationErrors(validationErrors: ValidationError[]): string[];
|
|
66
|
+
protected groupValidationErrors(validationErrors: ValidationError[], parentPath?: string): Record<string, string[]>;
|
|
49
67
|
protected mapChildrenToValidationErrors(error: ValidationError, parentPath?: string): ValidationError[];
|
|
50
68
|
protected prependConstraintsWithParentProp(parentPath: string, error: ValidationError): ValidationError;
|
|
51
69
|
}
|
package/pipes/validation.pipe.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
11
|
-
const load_package_util_1 = require("../utils/load-package.util");
|
|
12
|
-
const shared_utils_1 = require("../utils/shared.utils");
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { iterate } from 'iterare';
|
|
3
|
+
import { types } from 'util';
|
|
4
|
+
import { Injectable } from '../decorators/core/index.js';
|
|
5
|
+
import { Optional } from '../decorators/index.js';
|
|
6
|
+
import { HttpStatus } from '../enums/http-status.enum.js';
|
|
7
|
+
import { HttpErrorByCode, } from '../utils/http-error-by-code.util.js';
|
|
8
|
+
import { loadPackage } from '../utils/load-package.util.js';
|
|
9
|
+
import { isNil, isUndefined } from '../utils/shared.utils.js';
|
|
13
10
|
let classValidator = {};
|
|
14
11
|
let classTransformer = {};
|
|
15
12
|
/**
|
|
@@ -23,17 +20,27 @@ const BUILT_IN_TYPES = [Date, RegExp, Error, Map, Set, WeakMap, WeakSet];
|
|
|
23
20
|
* @publicApi
|
|
24
21
|
*/
|
|
25
22
|
let ValidationPipe = class ValidationPipe {
|
|
23
|
+
isTransformEnabled;
|
|
24
|
+
isDetailedOutputDisabled;
|
|
25
|
+
validatorOptions;
|
|
26
|
+
transformOptions;
|
|
27
|
+
errorHttpStatusCode;
|
|
28
|
+
expectedType;
|
|
29
|
+
exceptionFactory;
|
|
30
|
+
validateCustomDecorators;
|
|
31
|
+
errorFormat;
|
|
26
32
|
constructor(options) {
|
|
27
33
|
options = options || {};
|
|
28
|
-
const { transform, disableErrorMessages, errorHttpStatusCode, expectedType, transformOptions, validateCustomDecorators, ...validatorOptions } = options;
|
|
34
|
+
const { transform, disableErrorMessages, errorHttpStatusCode, expectedType, transformOptions, validateCustomDecorators, errorFormat, ...validatorOptions } = options;
|
|
29
35
|
// @see [https://github.com/nestjs/nest/issues/10683#issuecomment-1413690508](https://github.com/nestjs/nest/issues/10683#issuecomment-1413690508)
|
|
30
36
|
this.validatorOptions = { forbidUnknownValues: false, ...validatorOptions };
|
|
31
37
|
this.isTransformEnabled = !!transform;
|
|
32
38
|
this.transformOptions = transformOptions;
|
|
33
39
|
this.isDetailedOutputDisabled = disableErrorMessages;
|
|
34
40
|
this.validateCustomDecorators = validateCustomDecorators || false;
|
|
35
|
-
this.errorHttpStatusCode = errorHttpStatusCode ||
|
|
41
|
+
this.errorHttpStatusCode = errorHttpStatusCode || HttpStatus.BAD_REQUEST;
|
|
36
42
|
this.expectedType = expectedType;
|
|
43
|
+
this.errorFormat = errorFormat || 'list';
|
|
37
44
|
this.exceptionFactory =
|
|
38
45
|
options.exceptionFactory || this.createExceptionFactory();
|
|
39
46
|
classValidator = this.loadValidator(options.validatorPackage);
|
|
@@ -41,11 +48,11 @@ let ValidationPipe = class ValidationPipe {
|
|
|
41
48
|
}
|
|
42
49
|
loadValidator(validatorPackage) {
|
|
43
50
|
return (validatorPackage ??
|
|
44
|
-
|
|
51
|
+
loadPackage('class-validator', 'ValidationPipe', () => import('class-validator')));
|
|
45
52
|
}
|
|
46
53
|
loadTransformer(transformerPackage) {
|
|
47
54
|
return (transformerPackage ??
|
|
48
|
-
|
|
55
|
+
loadPackage('class-transformer', 'ValidationPipe', () => import('class-transformer')));
|
|
49
56
|
}
|
|
50
57
|
async transform(value, metadata) {
|
|
51
58
|
if (this.expectedType) {
|
|
@@ -57,6 +64,8 @@ let ValidationPipe = class ValidationPipe {
|
|
|
57
64
|
? this.transformPrimitive(value, metadata)
|
|
58
65
|
: value;
|
|
59
66
|
}
|
|
67
|
+
classValidator = (await classValidator);
|
|
68
|
+
classTransformer = (await classTransformer);
|
|
60
69
|
const originalValue = value;
|
|
61
70
|
value = this.toEmptyIfNil(value, metatype);
|
|
62
71
|
const isNil = value !== originalValue;
|
|
@@ -106,10 +115,16 @@ let ValidationPipe = class ValidationPipe {
|
|
|
106
115
|
createExceptionFactory() {
|
|
107
116
|
return (validationErrors = []) => {
|
|
108
117
|
if (this.isDetailedOutputDisabled) {
|
|
109
|
-
return new
|
|
118
|
+
return new HttpErrorByCode[this.errorHttpStatusCode]();
|
|
119
|
+
}
|
|
120
|
+
if (this.errorFormat === 'grouped') {
|
|
121
|
+
const errors = this.groupValidationErrors(validationErrors);
|
|
122
|
+
return new HttpErrorByCode[this.errorHttpStatusCode]({
|
|
123
|
+
message: errors,
|
|
124
|
+
});
|
|
110
125
|
}
|
|
111
126
|
const errors = this.flattenValidationErrors(validationErrors);
|
|
112
|
-
return new
|
|
127
|
+
return new HttpErrorByCode[this.errorHttpStatusCode](errors);
|
|
113
128
|
};
|
|
114
129
|
}
|
|
115
130
|
toValidate(metadata) {
|
|
@@ -118,7 +133,7 @@ let ValidationPipe = class ValidationPipe {
|
|
|
118
133
|
return false;
|
|
119
134
|
}
|
|
120
135
|
const types = [String, Boolean, Number, Array, Object, Buffer, Date];
|
|
121
|
-
return !types.some(t => metatype === t) && !
|
|
136
|
+
return !types.some(t => metatype === t) && !isNil(metatype);
|
|
122
137
|
}
|
|
123
138
|
transformPrimitive(value, metadata) {
|
|
124
139
|
if (!metadata.data) {
|
|
@@ -130,7 +145,7 @@ let ValidationPipe = class ValidationPipe {
|
|
|
130
145
|
return value;
|
|
131
146
|
}
|
|
132
147
|
if (metatype === Boolean) {
|
|
133
|
-
if (
|
|
148
|
+
if (isUndefined(value)) {
|
|
134
149
|
// This is an workaround to deal with optional boolean values since
|
|
135
150
|
// optional booleans shouldn't be parsed to a valid boolean when
|
|
136
151
|
// they were not defined
|
|
@@ -140,7 +155,7 @@ let ValidationPipe = class ValidationPipe {
|
|
|
140
155
|
return value === true || value === 'true';
|
|
141
156
|
}
|
|
142
157
|
if (metatype === Number) {
|
|
143
|
-
if (
|
|
158
|
+
if (isUndefined(value)) {
|
|
144
159
|
// This is a workaround to deal with optional numeric values since
|
|
145
160
|
// optional numerics shouldn't be parsed to a valid number when
|
|
146
161
|
// they were not defined
|
|
@@ -148,13 +163,13 @@ let ValidationPipe = class ValidationPipe {
|
|
|
148
163
|
}
|
|
149
164
|
return +value;
|
|
150
165
|
}
|
|
151
|
-
if (metatype === String && !
|
|
166
|
+
if (metatype === String && !isUndefined(value)) {
|
|
152
167
|
return String(value);
|
|
153
168
|
}
|
|
154
169
|
return value;
|
|
155
170
|
}
|
|
156
171
|
toEmptyIfNil(value, metatype) {
|
|
157
|
-
if (!
|
|
172
|
+
if (!isNil(value)) {
|
|
158
173
|
return value;
|
|
159
174
|
}
|
|
160
175
|
if (typeof metatype === 'function' ||
|
|
@@ -170,7 +185,7 @@ let ValidationPipe = class ValidationPipe {
|
|
|
170
185
|
stripProtoKeys(value) {
|
|
171
186
|
if (value == null ||
|
|
172
187
|
typeof value !== 'object' ||
|
|
173
|
-
|
|
188
|
+
types.isTypedArray(value)) {
|
|
174
189
|
return;
|
|
175
190
|
}
|
|
176
191
|
// Skip built-in JavaScript primitives to avoid Jest useFakeTimers conflicts
|
|
@@ -202,7 +217,7 @@ let ValidationPipe = class ValidationPipe {
|
|
|
202
217
|
return classValidator.validate(object, validatorOptions);
|
|
203
218
|
}
|
|
204
219
|
flattenValidationErrors(validationErrors) {
|
|
205
|
-
return
|
|
220
|
+
return iterate(validationErrors)
|
|
206
221
|
.map(error => this.mapChildrenToValidationErrors(error))
|
|
207
222
|
.flatten()
|
|
208
223
|
.filter(item => !!item.constraints)
|
|
@@ -210,6 +225,21 @@ let ValidationPipe = class ValidationPipe {
|
|
|
210
225
|
.flatten()
|
|
211
226
|
.toArray();
|
|
212
227
|
}
|
|
228
|
+
groupValidationErrors(validationErrors, parentPath) {
|
|
229
|
+
const result = {};
|
|
230
|
+
for (const error of validationErrors) {
|
|
231
|
+
const path = parentPath
|
|
232
|
+
? `${parentPath}.${error.property}`
|
|
233
|
+
: error.property;
|
|
234
|
+
if (error.constraints) {
|
|
235
|
+
result[path] = Object.values(error.constraints);
|
|
236
|
+
}
|
|
237
|
+
if (error.children && error.children.length) {
|
|
238
|
+
Object.assign(result, this.groupValidationErrors(error.children, path));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
213
243
|
mapChildrenToValidationErrors(error, parentPath) {
|
|
214
244
|
if (!(error.children && error.children.length)) {
|
|
215
245
|
return [error];
|
|
@@ -237,9 +267,9 @@ let ValidationPipe = class ValidationPipe {
|
|
|
237
267
|
};
|
|
238
268
|
}
|
|
239
269
|
};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
(0,
|
|
243
|
-
|
|
244
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
270
|
+
ValidationPipe = __decorate([
|
|
271
|
+
Injectable(),
|
|
272
|
+
__param(0, Optional()),
|
|
273
|
+
__metadata("design:paramtypes", [Object])
|
|
245
274
|
], ValidationPipe);
|
|
275
|
+
export { ValidationPipe };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ClassSerializerContextOptions } from './class-serializer.interfaces';
|
|
2
1
|
import { Observable } from 'rxjs';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { ClassTransformOptions } from '../interfaces/external/class-transform-options.interface.js';
|
|
3
|
+
import { TransformerPackage } from '../interfaces/external/transformer-package.interface.js';
|
|
4
|
+
import { CallHandler, ExecutionContext, NestInterceptor } from '../interfaces/index.js';
|
|
5
|
+
import { ClassSerializerContextOptions } from './class-serializer.interfaces.js';
|
|
6
6
|
export interface PlainLiteralObject {
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
}
|
|
@@ -19,7 +19,7 @@ export declare class ClassSerializerInterceptor implements NestInterceptor {
|
|
|
19
19
|
protected readonly reflector: any;
|
|
20
20
|
protected readonly defaultOptions: ClassSerializerInterceptorOptions;
|
|
21
21
|
constructor(reflector: any, defaultOptions?: ClassSerializerInterceptorOptions);
|
|
22
|
-
intercept(context: ExecutionContext, next: CallHandler): Observable<any
|
|
22
|
+
intercept(context: ExecutionContext, next: CallHandler): Promise<Observable<any>>;
|
|
23
23
|
/**
|
|
24
24
|
* Serializes responses that are non-null objects nor streamable files.
|
|
25
25
|
*/
|