@nestjs/common 11.1.16 → 12.0.0-alpha.1
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 +29 -1
- package/utils/load-package.util.js +84 -9
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Type } from '../interfaces';
|
|
2
|
-
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
3
|
-
import { ValidationPipe, ValidationPipeOptions } from './validation.pipe';
|
|
1
|
+
import { Type } from '../interfaces/index.js';
|
|
2
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
3
|
+
import { ValidationPipe, ValidationPipeOptions } from './validation.pipe.js';
|
|
4
4
|
/**
|
|
5
5
|
* @publicApi
|
|
6
6
|
*/
|
|
@@ -46,7 +46,7 @@ export declare class ParseArrayPipe implements PipeTransform {
|
|
|
46
46
|
* @param value currently processed route argument
|
|
47
47
|
* @param metadata contains metadata about the currently processed route argument
|
|
48
48
|
*/
|
|
49
|
-
transform(value:
|
|
49
|
+
transform(value: unknown, metadata: ArgumentMetadata): Promise<any>;
|
|
50
50
|
protected isExpectedTypePrimitive(): boolean;
|
|
51
51
|
protected validatePrimitive(originalValue: any, index?: number): any;
|
|
52
52
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
9
|
-
const shared_utils_1 = require("../utils/shared.utils");
|
|
10
|
-
const validation_pipe_1 = require("./validation.pipe");
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Injectable } from '../decorators/core/injectable.decorator.js';
|
|
3
|
+
import { Optional } from '../decorators/core/optional.decorator.js';
|
|
4
|
+
import { HttpStatus } from '../enums/http-status.enum.js';
|
|
5
|
+
import { HttpErrorByCode } from '../utils/http-error-by-code.util.js';
|
|
6
|
+
import { isNil, isString, isUndefined } from '../utils/shared.utils.js';
|
|
7
|
+
import { ValidationPipe } from './validation.pipe.js';
|
|
11
8
|
const VALIDATION_ERROR_MESSAGE = 'Validation failed (parsable array expected)';
|
|
12
9
|
const DEFAULT_ARRAY_SEPARATOR = ',';
|
|
13
10
|
/**
|
|
@@ -18,17 +15,20 @@ const DEFAULT_ARRAY_SEPARATOR = ',';
|
|
|
18
15
|
* @publicApi
|
|
19
16
|
*/
|
|
20
17
|
let ParseArrayPipe = class ParseArrayPipe {
|
|
18
|
+
options;
|
|
19
|
+
validationPipe;
|
|
20
|
+
exceptionFactory;
|
|
21
21
|
constructor(options = {}) {
|
|
22
22
|
this.options = options;
|
|
23
|
-
this.validationPipe = new
|
|
23
|
+
this.validationPipe = new ValidationPipe({
|
|
24
24
|
transform: true,
|
|
25
25
|
validateCustomDecorators: true,
|
|
26
26
|
...options,
|
|
27
27
|
});
|
|
28
|
-
const { exceptionFactory, errorHttpStatusCode =
|
|
28
|
+
const { exceptionFactory, errorHttpStatusCode = HttpStatus.BAD_REQUEST } = options;
|
|
29
29
|
this.exceptionFactory =
|
|
30
30
|
exceptionFactory ||
|
|
31
|
-
(error => new
|
|
31
|
+
(error => new HttpErrorByCode[errorHttpStatusCode](error));
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Method that accesses and performs optional transformation on argument for
|
|
@@ -41,11 +41,11 @@ let ParseArrayPipe = class ParseArrayPipe {
|
|
|
41
41
|
if (!value && !this.options.optional) {
|
|
42
42
|
throw this.exceptionFactory(VALIDATION_ERROR_MESSAGE);
|
|
43
43
|
}
|
|
44
|
-
else if (
|
|
44
|
+
else if (isNil(value) && this.options.optional) {
|
|
45
45
|
return value;
|
|
46
46
|
}
|
|
47
47
|
if (!Array.isArray(value)) {
|
|
48
|
-
if (!
|
|
48
|
+
if (!isString(value)) {
|
|
49
49
|
throw this.exceptionFactory(VALIDATION_ERROR_MESSAGE);
|
|
50
50
|
}
|
|
51
51
|
else {
|
|
@@ -123,26 +123,26 @@ let ParseArrayPipe = class ParseArrayPipe {
|
|
|
123
123
|
if (this.options.items === Number) {
|
|
124
124
|
const value = originalValue !== null && originalValue !== '' ? +originalValue : NaN;
|
|
125
125
|
if (isNaN(value)) {
|
|
126
|
-
throw this.exceptionFactory(`${
|
|
126
|
+
throw this.exceptionFactory(`${isUndefined(index) ? '' : `[${index}] `}item must be a number`);
|
|
127
127
|
}
|
|
128
128
|
return value;
|
|
129
129
|
}
|
|
130
130
|
else if (this.options.items === String) {
|
|
131
|
-
if (!
|
|
131
|
+
if (!isString(originalValue)) {
|
|
132
132
|
return `${originalValue}`;
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
else if (this.options.items === Boolean) {
|
|
136
136
|
if (typeof originalValue !== 'boolean') {
|
|
137
|
-
throw this.exceptionFactory(`${
|
|
137
|
+
throw this.exceptionFactory(`${isUndefined(index) ? '' : `[${index}] `}item must be a boolean value`);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
return originalValue;
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
(0,
|
|
146
|
-
|
|
147
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
143
|
+
ParseArrayPipe = __decorate([
|
|
144
|
+
Injectable(),
|
|
145
|
+
__param(0, Optional()),
|
|
146
|
+
__metadata("design:paramtypes", [Object])
|
|
148
147
|
], ParseArrayPipe);
|
|
148
|
+
export { ParseArrayPipe };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
2
|
-
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
1
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
2
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util.js';
|
|
3
3
|
/**
|
|
4
4
|
* @publicApi
|
|
5
5
|
*/
|
|
@@ -28,7 +28,7 @@ export interface ParseBoolPipeOptions {
|
|
|
28
28
|
*
|
|
29
29
|
* @publicApi
|
|
30
30
|
*/
|
|
31
|
-
export declare class ParseBoolPipe implements PipeTransform
|
|
31
|
+
export declare class ParseBoolPipe implements PipeTransform {
|
|
32
32
|
protected readonly options?: ParseBoolPipeOptions | undefined;
|
|
33
33
|
protected exceptionFactory: (error: string) => any;
|
|
34
34
|
constructor(options?: ParseBoolPipeOptions | undefined);
|
|
@@ -39,17 +39,17 @@ export declare class ParseBoolPipe implements PipeTransform<string | boolean, Pr
|
|
|
39
39
|
* @param value currently processed route argument
|
|
40
40
|
* @param metadata contains metadata about the currently processed route argument
|
|
41
41
|
*/
|
|
42
|
-
transform(value:
|
|
42
|
+
transform(value: unknown, metadata: ArgumentMetadata): Promise<boolean | undefined | null>;
|
|
43
43
|
/**
|
|
44
44
|
* @param value currently processed route argument
|
|
45
45
|
* @returns `true` if `value` is said 'true', ie., if it is equal to the boolean
|
|
46
46
|
* `true` or the string `"true"`
|
|
47
47
|
*/
|
|
48
|
-
protected isTrue(value:
|
|
48
|
+
protected isTrue(value: unknown): boolean;
|
|
49
49
|
/**
|
|
50
50
|
* @param value currently processed route argument
|
|
51
51
|
* @returns `true` if `value` is said 'false', ie., if it is equal to the boolean
|
|
52
52
|
* `false` or the string `"false"`
|
|
53
53
|
*/
|
|
54
|
-
protected isFalse(value:
|
|
54
|
+
protected isFalse(value: unknown): boolean;
|
|
55
55
|
}
|
package/pipes/parse-bool.pipe.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const http_status_enum_1 = require("../enums/http-status.enum");
|
|
8
|
-
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
9
|
-
const shared_utils_1 = require("../utils/shared.utils");
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Injectable } from '../decorators/core/injectable.decorator.js';
|
|
3
|
+
import { Optional } from '../decorators/core/optional.decorator.js';
|
|
4
|
+
import { HttpStatus } from '../enums/http-status.enum.js';
|
|
5
|
+
import { HttpErrorByCode, } from '../utils/http-error-by-code.util.js';
|
|
6
|
+
import { isNil } from '../utils/shared.utils.js';
|
|
10
7
|
/**
|
|
11
8
|
* Defines the built-in ParseBool Pipe
|
|
12
9
|
*
|
|
@@ -15,13 +12,15 @@ const shared_utils_1 = require("../utils/shared.utils");
|
|
|
15
12
|
* @publicApi
|
|
16
13
|
*/
|
|
17
14
|
let ParseBoolPipe = class ParseBoolPipe {
|
|
15
|
+
options;
|
|
16
|
+
exceptionFactory;
|
|
18
17
|
constructor(options) {
|
|
19
18
|
this.options = options;
|
|
20
19
|
options = options || {};
|
|
21
|
-
const { exceptionFactory, errorHttpStatusCode =
|
|
20
|
+
const { exceptionFactory, errorHttpStatusCode = HttpStatus.BAD_REQUEST } = options;
|
|
22
21
|
this.exceptionFactory =
|
|
23
22
|
exceptionFactory ||
|
|
24
|
-
(error => new
|
|
23
|
+
(error => new HttpErrorByCode[errorHttpStatusCode](error));
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
26
|
* Method that accesses and performs optional transformation on argument for
|
|
@@ -31,7 +30,7 @@ let ParseBoolPipe = class ParseBoolPipe {
|
|
|
31
30
|
* @param metadata contains metadata about the currently processed route argument
|
|
32
31
|
*/
|
|
33
32
|
async transform(value, metadata) {
|
|
34
|
-
if (
|
|
33
|
+
if (isNil(value) && this.options?.optional) {
|
|
35
34
|
return value;
|
|
36
35
|
}
|
|
37
36
|
if (this.isTrue(value)) {
|
|
@@ -59,9 +58,9 @@ let ParseBoolPipe = class ParseBoolPipe {
|
|
|
59
58
|
return value === false || value === 'false';
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
(0,
|
|
65
|
-
|
|
66
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
61
|
+
ParseBoolPipe = __decorate([
|
|
62
|
+
Injectable(),
|
|
63
|
+
__param(0, Optional()),
|
|
64
|
+
__metadata("design:paramtypes", [Object])
|
|
67
65
|
], ParseBoolPipe);
|
|
66
|
+
export { ParseBoolPipe };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
2
|
-
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
1
|
+
import { PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
2
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util.js';
|
|
3
3
|
export interface ParseDatePipeOptions {
|
|
4
4
|
/**
|
|
5
5
|
* If true, the pipe will return null or undefined if the value is not provided
|
|
@@ -22,7 +22,7 @@ export interface ParseDatePipeOptions {
|
|
|
22
22
|
*/
|
|
23
23
|
exceptionFactory?: (error: string) => any;
|
|
24
24
|
}
|
|
25
|
-
export declare class ParseDatePipe implements PipeTransform
|
|
25
|
+
export declare class ParseDatePipe implements PipeTransform {
|
|
26
26
|
private readonly options;
|
|
27
27
|
protected exceptionFactory: (error: string) => any;
|
|
28
28
|
constructor(options?: ParseDatePipeOptions);
|
|
@@ -33,5 +33,5 @@ export declare class ParseDatePipe implements PipeTransform<string | number | un
|
|
|
33
33
|
* @param value currently processed route argument
|
|
34
34
|
* @param metadata contains metadata about the currently processed route argument
|
|
35
35
|
*/
|
|
36
|
-
transform(value:
|
|
36
|
+
transform(value: unknown): Date | null | undefined;
|
|
37
37
|
}
|
package/pipes/parse-date.pipe.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const http_status_enum_1 = require("../enums/http-status.enum");
|
|
7
|
-
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
8
|
-
const shared_utils_1 = require("../utils/shared.utils");
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Injectable } from '../decorators/core/injectable.decorator.js';
|
|
3
|
+
import { HttpStatus } from '../enums/http-status.enum.js';
|
|
4
|
+
import { HttpErrorByCode, } from '../utils/http-error-by-code.util.js';
|
|
5
|
+
import { isNil, isNumber, isString } from '../utils/shared.utils.js';
|
|
9
6
|
let ParseDatePipe = class ParseDatePipe {
|
|
7
|
+
options;
|
|
8
|
+
exceptionFactory;
|
|
10
9
|
constructor(options = {}) {
|
|
11
10
|
this.options = options;
|
|
12
|
-
const { exceptionFactory, errorHttpStatusCode =
|
|
11
|
+
const { exceptionFactory, errorHttpStatusCode = HttpStatus.BAD_REQUEST } = options;
|
|
13
12
|
this.exceptionFactory =
|
|
14
13
|
exceptionFactory ||
|
|
15
|
-
(error => new
|
|
14
|
+
(error => new HttpErrorByCode[errorHttpStatusCode](error));
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
17
|
* Method that accesses and performs optional transformation on argument for
|
|
@@ -22,21 +21,23 @@ let ParseDatePipe = class ParseDatePipe {
|
|
|
22
21
|
* @param metadata contains metadata about the currently processed route argument
|
|
23
22
|
*/
|
|
24
23
|
transform(value) {
|
|
25
|
-
if (this.options.optional &&
|
|
24
|
+
if (this.options.optional && isNil(value)) {
|
|
26
25
|
return this.options.default ? this.options.default() : value;
|
|
27
26
|
}
|
|
28
27
|
if (!value) {
|
|
29
28
|
throw this.exceptionFactory('Validation failed (no Date provided)');
|
|
30
29
|
}
|
|
31
|
-
const transformedValue =
|
|
30
|
+
const transformedValue = isString(value) || isNumber(value) || value instanceof Date
|
|
31
|
+
? new Date(value)
|
|
32
|
+
: new Date(NaN);
|
|
32
33
|
if (isNaN(transformedValue.getTime())) {
|
|
33
34
|
throw this.exceptionFactory('Validation failed (invalid date format)');
|
|
34
35
|
}
|
|
35
36
|
return transformedValue;
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
(
|
|
41
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
39
|
+
ParseDatePipe = __decorate([
|
|
40
|
+
Injectable(),
|
|
41
|
+
__metadata("design:paramtypes", [Object])
|
|
42
42
|
], ParseDatePipe);
|
|
43
|
+
export { ParseDatePipe };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArgumentMetadata } from '../index';
|
|
2
|
-
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
3
|
-
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
1
|
+
import { ArgumentMetadata } from '../index.js';
|
|
2
|
+
import { PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
3
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util.js';
|
|
4
4
|
/**
|
|
5
5
|
* @publicApi
|
|
6
6
|
*/
|
|
@@ -41,6 +41,6 @@ export declare class ParseEnumPipe<T = any> implements PipeTransform<T> {
|
|
|
41
41
|
* @param value currently processed route argument
|
|
42
42
|
* @param metadata contains metadata about the currently processed route argument
|
|
43
43
|
*/
|
|
44
|
-
transform(value:
|
|
45
|
-
protected isEnum(value:
|
|
44
|
+
transform(value: unknown, metadata: ArgumentMetadata): Promise<T | undefined | null>;
|
|
45
|
+
protected isEnum(value: unknown): boolean;
|
|
46
46
|
}
|
package/pipes/parse-enum.pipe.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const index_1 = require("../index");
|
|
7
|
-
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
8
|
-
const shared_utils_1 = require("../utils/shared.utils");
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Injectable, Optional } from '../decorators/core/index.js';
|
|
3
|
+
import { HttpStatus } from '../index.js';
|
|
4
|
+
import { HttpErrorByCode, } from '../utils/http-error-by-code.util.js';
|
|
5
|
+
import { isNil } from '../utils/shared.utils.js';
|
|
9
6
|
/**
|
|
10
7
|
* Defines the built-in ParseEnum Pipe
|
|
11
8
|
*
|
|
@@ -14,6 +11,9 @@ const shared_utils_1 = require("../utils/shared.utils");
|
|
|
14
11
|
* @publicApi
|
|
15
12
|
*/
|
|
16
13
|
let ParseEnumPipe = class ParseEnumPipe {
|
|
14
|
+
enumType;
|
|
15
|
+
options;
|
|
16
|
+
exceptionFactory;
|
|
17
17
|
constructor(enumType, options) {
|
|
18
18
|
this.enumType = enumType;
|
|
19
19
|
this.options = options;
|
|
@@ -21,10 +21,10 @@ let ParseEnumPipe = class ParseEnumPipe {
|
|
|
21
21
|
throw new Error(`"ParseEnumPipe" requires "enumType" argument specified (to validate input values).`);
|
|
22
22
|
}
|
|
23
23
|
options = options || {};
|
|
24
|
-
const { exceptionFactory, errorHttpStatusCode =
|
|
24
|
+
const { exceptionFactory, errorHttpStatusCode = HttpStatus.BAD_REQUEST } = options;
|
|
25
25
|
this.exceptionFactory =
|
|
26
26
|
exceptionFactory ||
|
|
27
|
-
(error => new
|
|
27
|
+
(error => new HttpErrorByCode[errorHttpStatusCode](error));
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Method that accesses and performs optional transformation on argument for
|
|
@@ -34,7 +34,7 @@ let ParseEnumPipe = class ParseEnumPipe {
|
|
|
34
34
|
* @param metadata contains metadata about the currently processed route argument
|
|
35
35
|
*/
|
|
36
36
|
async transform(value, metadata) {
|
|
37
|
-
if (
|
|
37
|
+
if (isNil(value) && this.options?.optional) {
|
|
38
38
|
return value;
|
|
39
39
|
}
|
|
40
40
|
if (!this.isEnum(value)) {
|
|
@@ -47,9 +47,9 @@ let ParseEnumPipe = class ParseEnumPipe {
|
|
|
47
47
|
return enumValues.includes(value);
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
(
|
|
53
|
-
|
|
54
|
-
tslib_1.__metadata("design:paramtypes", [Object, Object])
|
|
50
|
+
ParseEnumPipe = __decorate([
|
|
51
|
+
Injectable(),
|
|
52
|
+
__param(1, Optional()),
|
|
53
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
55
54
|
], ParseEnumPipe);
|
|
55
|
+
export { ParseEnumPipe };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArgumentMetadata } from '../index';
|
|
2
|
-
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
3
|
-
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
1
|
+
import { ArgumentMetadata } from '../index.js';
|
|
2
|
+
import { PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
3
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util.js';
|
|
4
4
|
/**
|
|
5
5
|
* @publicApi
|
|
6
6
|
*/
|
|
@@ -29,7 +29,7 @@ export interface ParseFloatPipeOptions {
|
|
|
29
29
|
*
|
|
30
30
|
* @publicApi
|
|
31
31
|
*/
|
|
32
|
-
export declare class ParseFloatPipe implements PipeTransform
|
|
32
|
+
export declare class ParseFloatPipe implements PipeTransform {
|
|
33
33
|
protected readonly options?: ParseFloatPipeOptions | undefined;
|
|
34
34
|
protected exceptionFactory: (error: string) => any;
|
|
35
35
|
constructor(options?: ParseFloatPipeOptions | undefined);
|
|
@@ -40,10 +40,10 @@ export declare class ParseFloatPipe implements PipeTransform<string> {
|
|
|
40
40
|
* @param value currently processed route argument
|
|
41
41
|
* @param metadata contains metadata about the currently processed route argument
|
|
42
42
|
*/
|
|
43
|
-
transform(value:
|
|
43
|
+
transform(value: unknown, metadata: ArgumentMetadata): Promise<number | undefined | null>;
|
|
44
44
|
/**
|
|
45
45
|
* @param value currently processed route argument
|
|
46
46
|
* @returns `true` if `value` is a valid float number
|
|
47
47
|
*/
|
|
48
|
-
protected isNumeric(value:
|
|
48
|
+
protected isNumeric(value: unknown): boolean;
|
|
49
49
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const index_1 = require("../index");
|
|
7
|
-
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
8
|
-
const shared_utils_1 = require("../utils/shared.utils");
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Injectable, Optional } from '../decorators/core/index.js';
|
|
3
|
+
import { HttpStatus } from '../index.js';
|
|
4
|
+
import { HttpErrorByCode, } from '../utils/http-error-by-code.util.js';
|
|
5
|
+
import { isNil } from '../utils/shared.utils.js';
|
|
9
6
|
/**
|
|
10
7
|
* Defines the built-in ParseFloat Pipe
|
|
11
8
|
*
|
|
@@ -14,13 +11,15 @@ const shared_utils_1 = require("../utils/shared.utils");
|
|
|
14
11
|
* @publicApi
|
|
15
12
|
*/
|
|
16
13
|
let ParseFloatPipe = class ParseFloatPipe {
|
|
14
|
+
options;
|
|
15
|
+
exceptionFactory;
|
|
17
16
|
constructor(options) {
|
|
18
17
|
this.options = options;
|
|
19
18
|
options = options || {};
|
|
20
|
-
const { exceptionFactory, errorHttpStatusCode =
|
|
19
|
+
const { exceptionFactory, errorHttpStatusCode = HttpStatus.BAD_REQUEST } = options;
|
|
21
20
|
this.exceptionFactory =
|
|
22
21
|
exceptionFactory ||
|
|
23
|
-
(error => new
|
|
22
|
+
(error => new HttpErrorByCode[errorHttpStatusCode](error));
|
|
24
23
|
}
|
|
25
24
|
/**
|
|
26
25
|
* Method that accesses and performs optional transformation on argument for
|
|
@@ -30,13 +29,13 @@ let ParseFloatPipe = class ParseFloatPipe {
|
|
|
30
29
|
* @param metadata contains metadata about the currently processed route argument
|
|
31
30
|
*/
|
|
32
31
|
async transform(value, metadata) {
|
|
33
|
-
if (
|
|
32
|
+
if (isNil(value) && this.options?.optional) {
|
|
34
33
|
return value;
|
|
35
34
|
}
|
|
36
35
|
if (!this.isNumeric(value)) {
|
|
37
36
|
throw this.exceptionFactory('Validation failed (numeric string is expected)');
|
|
38
37
|
}
|
|
39
|
-
return parseFloat(value);
|
|
38
|
+
return parseFloat(String(value));
|
|
40
39
|
}
|
|
41
40
|
/**
|
|
42
41
|
* @param value currently processed route argument
|
|
@@ -44,13 +43,13 @@ let ParseFloatPipe = class ParseFloatPipe {
|
|
|
44
43
|
*/
|
|
45
44
|
isNumeric(value) {
|
|
46
45
|
return (['string', 'number'].includes(typeof value) &&
|
|
47
|
-
!isNaN(parseFloat(value)) &&
|
|
46
|
+
!isNaN(parseFloat(String(value))) &&
|
|
48
47
|
isFinite(value));
|
|
49
48
|
}
|
|
50
49
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
(0,
|
|
54
|
-
|
|
55
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
50
|
+
ParseFloatPipe = __decorate([
|
|
51
|
+
Injectable(),
|
|
52
|
+
__param(0, Optional()),
|
|
53
|
+
__metadata("design:paramtypes", [Object])
|
|
56
54
|
], ParseFloatPipe);
|
|
55
|
+
export { ParseFloatPipe };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
2
|
-
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
1
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
2
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util.js';
|
|
3
3
|
/**
|
|
4
4
|
* @publicApi
|
|
5
5
|
*/
|
|
@@ -28,7 +28,7 @@ export interface ParseIntPipeOptions {
|
|
|
28
28
|
*
|
|
29
29
|
* @publicApi
|
|
30
30
|
*/
|
|
31
|
-
export declare class ParseIntPipe implements PipeTransform
|
|
31
|
+
export declare class ParseIntPipe implements PipeTransform {
|
|
32
32
|
protected readonly options?: ParseIntPipeOptions | undefined;
|
|
33
33
|
protected exceptionFactory: (error: string) => any;
|
|
34
34
|
constructor(options?: ParseIntPipeOptions | undefined);
|
|
@@ -39,10 +39,10 @@ export declare class ParseIntPipe implements PipeTransform<string> {
|
|
|
39
39
|
* @param value currently processed route argument
|
|
40
40
|
* @param metadata contains metadata about the currently processed route argument
|
|
41
41
|
*/
|
|
42
|
-
transform(value:
|
|
42
|
+
transform(value: unknown, metadata: ArgumentMetadata): Promise<number | undefined | null>;
|
|
43
43
|
/**
|
|
44
44
|
* @param value currently processed route argument
|
|
45
45
|
* @returns `true` if `value` is a valid integer number
|
|
46
46
|
*/
|
|
47
|
-
protected isNumeric(value:
|
|
47
|
+
protected isNumeric(value: unknown): boolean;
|
|
48
48
|
}
|
package/pipes/parse-int.pipe.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const http_status_enum_1 = require("../enums/http-status.enum");
|
|
8
|
-
const http_error_by_code_util_1 = require("../utils/http-error-by-code.util");
|
|
9
|
-
const shared_utils_1 = require("../utils/shared.utils");
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Injectable } from '../decorators/core/injectable.decorator.js';
|
|
3
|
+
import { Optional } from '../decorators/core/optional.decorator.js';
|
|
4
|
+
import { HttpStatus } from '../enums/http-status.enum.js';
|
|
5
|
+
import { HttpErrorByCode, } from '../utils/http-error-by-code.util.js';
|
|
6
|
+
import { isNil } from '../utils/shared.utils.js';
|
|
10
7
|
/**
|
|
11
8
|
* Defines the built-in ParseInt Pipe
|
|
12
9
|
*
|
|
@@ -15,13 +12,15 @@ const shared_utils_1 = require("../utils/shared.utils");
|
|
|
15
12
|
* @publicApi
|
|
16
13
|
*/
|
|
17
14
|
let ParseIntPipe = class ParseIntPipe {
|
|
15
|
+
options;
|
|
16
|
+
exceptionFactory;
|
|
18
17
|
constructor(options) {
|
|
19
18
|
this.options = options;
|
|
20
19
|
options = options || {};
|
|
21
|
-
const { exceptionFactory, errorHttpStatusCode =
|
|
20
|
+
const { exceptionFactory, errorHttpStatusCode = HttpStatus.BAD_REQUEST } = options;
|
|
22
21
|
this.exceptionFactory =
|
|
23
22
|
exceptionFactory ||
|
|
24
|
-
(error => new
|
|
23
|
+
(error => new HttpErrorByCode[errorHttpStatusCode](error));
|
|
25
24
|
}
|
|
26
25
|
/**
|
|
27
26
|
* Method that accesses and performs optional transformation on argument for
|
|
@@ -31,13 +30,13 @@ let ParseIntPipe = class ParseIntPipe {
|
|
|
31
30
|
* @param metadata contains metadata about the currently processed route argument
|
|
32
31
|
*/
|
|
33
32
|
async transform(value, metadata) {
|
|
34
|
-
if (
|
|
33
|
+
if (isNil(value) && this.options?.optional) {
|
|
35
34
|
return value;
|
|
36
35
|
}
|
|
37
36
|
if (!this.isNumeric(value)) {
|
|
38
37
|
throw this.exceptionFactory('Validation failed (numeric string is expected)');
|
|
39
38
|
}
|
|
40
|
-
return parseInt(value, 10);
|
|
39
|
+
return parseInt(String(value), 10);
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* @param value currently processed route argument
|
|
@@ -45,13 +44,13 @@ let ParseIntPipe = class ParseIntPipe {
|
|
|
45
44
|
*/
|
|
46
45
|
isNumeric(value) {
|
|
47
46
|
return (['string', 'number'].includes(typeof value) &&
|
|
48
|
-
/^-?\d+$/.test(value) &&
|
|
47
|
+
/^-?\d+$/.test(String(value)) &&
|
|
49
48
|
isFinite(value));
|
|
50
49
|
}
|
|
51
50
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
(0,
|
|
55
|
-
|
|
56
|
-
tslib_1.__metadata("design:paramtypes", [Object])
|
|
51
|
+
ParseIntPipe = __decorate([
|
|
52
|
+
Injectable(),
|
|
53
|
+
__param(0, Optional()),
|
|
54
|
+
__metadata("design:paramtypes", [Object])
|
|
57
55
|
], ParseIntPipe);
|
|
56
|
+
export { ParseIntPipe };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
2
|
-
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
1
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface.js';
|
|
2
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util.js';
|
|
3
3
|
/**
|
|
4
4
|
* @publicApi
|
|
5
5
|
*/
|
|
@@ -32,7 +32,7 @@ export interface ParseUUIDPipeOptions {
|
|
|
32
32
|
*
|
|
33
33
|
* @publicApi
|
|
34
34
|
*/
|
|
35
|
-
export declare class ParseUUIDPipe implements PipeTransform
|
|
35
|
+
export declare class ParseUUIDPipe implements PipeTransform {
|
|
36
36
|
protected readonly options?: ParseUUIDPipeOptions | undefined;
|
|
37
37
|
protected static uuidRegExps: {
|
|
38
38
|
3: RegExp;
|
|
@@ -44,6 +44,6 @@ export declare class ParseUUIDPipe implements PipeTransform<string> {
|
|
|
44
44
|
private readonly version;
|
|
45
45
|
protected exceptionFactory: (errors: string) => any;
|
|
46
46
|
constructor(options?: ParseUUIDPipeOptions | undefined);
|
|
47
|
-
transform(value:
|
|
47
|
+
transform(value: unknown, metadata: ArgumentMetadata): Promise<string | undefined | null>;
|
|
48
48
|
protected isUUID(str: unknown, version?: string): any;
|
|
49
49
|
}
|