@depup/nestjs__common 11.1.16-depup.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/LICENSE +22 -0
- package/PACKAGE.md +1 -0
- package/Readme.md +31 -0
- package/changes.json +10 -0
- package/constants.d.ts +42 -0
- package/constants.js +44 -0
- package/decorators/core/apply-decorators.d.ts +10 -0
- package/decorators/core/apply-decorators.js +23 -0
- package/decorators/core/bind.decorator.d.ts +11 -0
- package/decorators/core/bind.decorator.js +19 -0
- package/decorators/core/catch.decorator.d.ts +19 -0
- package/decorators/core/catch.decorator.js +27 -0
- package/decorators/core/controller.decorator.d.ts +102 -0
- package/decorators/core/controller.decorator.js +61 -0
- package/decorators/core/dependencies.decorator.d.ts +7 -0
- package/decorators/core/dependencies.decorator.js +23 -0
- package/decorators/core/exception-filters.decorator.d.ts +23 -0
- package/decorators/core/exception-filters.decorator.js +43 -0
- package/decorators/core/index.d.ts +14 -0
- package/decorators/core/index.js +17 -0
- package/decorators/core/inject.decorator.d.ts +31 -0
- package/decorators/core/inject.decorator.js +53 -0
- package/decorators/core/injectable.decorator.d.ts +43 -0
- package/decorators/core/injectable.decorator.js +50 -0
- package/decorators/core/optional.decorator.d.ts +14 -0
- package/decorators/core/optional.decorator.js +29 -0
- package/decorators/core/set-metadata.decorator.d.ts +20 -0
- package/decorators/core/set-metadata.decorator.js +32 -0
- package/decorators/core/use-guards.decorator.d.ts +23 -0
- package/decorators/core/use-guards.decorator.js +41 -0
- package/decorators/core/use-interceptors.decorator.d.ts +23 -0
- package/decorators/core/use-interceptors.decorator.js +42 -0
- package/decorators/core/use-pipes.decorator.d.ts +23 -0
- package/decorators/core/use-pipes.decorator.js +40 -0
- package/decorators/core/version.decorator.d.ts +7 -0
- package/decorators/core/version.decorator.js +19 -0
- package/decorators/http/create-route-param-metadata.decorator.d.ts +13 -0
- package/decorators/http/create-route-param-metadata.decorator.js +32 -0
- package/decorators/http/header.decorator.d.ts +15 -0
- package/decorators/http/header.decorator.js +25 -0
- package/decorators/http/http-code.decorator.d.ts +11 -0
- package/decorators/http/http-code.decorator.js +20 -0
- package/decorators/http/index.d.ts +8 -0
- package/decorators/http/index.js +11 -0
- package/decorators/http/redirect.decorator.d.ts +6 -0
- package/decorators/http/redirect.decorator.js +15 -0
- package/decorators/http/render.decorator.d.ts +12 -0
- package/decorators/http/render.decorator.js +21 -0
- package/decorators/http/request-mapping.decorator.d.ts +134 -0
- package/decorators/http/request-mapping.decorator.js +154 -0
- package/decorators/http/route-params.decorator.d.ts +445 -0
- package/decorators/http/route-params.decorator.js +265 -0
- package/decorators/http/sse.decorator.d.ts +10 -0
- package/decorators/http/sse.decorator.js +21 -0
- package/decorators/index.d.ts +3 -0
- package/decorators/index.js +6 -0
- package/decorators/modules/global.decorator.d.ts +12 -0
- package/decorators/modules/global.decorator.js +20 -0
- package/decorators/modules/index.d.ts +2 -0
- package/decorators/modules/index.js +5 -0
- package/decorators/modules/module.decorator.d.ts +16 -0
- package/decorators/modules/module.decorator.js +29 -0
- package/enums/http-status.enum.d.ts +60 -0
- package/enums/http-status.enum.js +64 -0
- package/enums/index.d.ts +4 -0
- package/enums/index.js +7 -0
- package/enums/request-method.enum.d.ts +18 -0
- package/enums/request-method.enum.js +22 -0
- package/enums/route-paramtypes.enum.d.ts +16 -0
- package/enums/route-paramtypes.enum.js +20 -0
- package/enums/shutdown-signal.enum.d.ts +16 -0
- package/enums/shutdown-signal.enum.js +20 -0
- package/enums/version-type.enum.d.ts +9 -0
- package/enums/version-type.enum.js +13 -0
- package/exceptions/bad-gateway.exception.d.ts +35 -0
- package/exceptions/bad-gateway.exception.js +43 -0
- package/exceptions/bad-request.exception.d.ts +35 -0
- package/exceptions/bad-request.exception.js +43 -0
- package/exceptions/conflict.exception.d.ts +35 -0
- package/exceptions/conflict.exception.js +43 -0
- package/exceptions/forbidden.exception.d.ts +35 -0
- package/exceptions/forbidden.exception.js +43 -0
- package/exceptions/gateway-timeout.exception.d.ts +35 -0
- package/exceptions/gateway-timeout.exception.js +43 -0
- package/exceptions/gone.exception.d.ts +35 -0
- package/exceptions/gone.exception.js +43 -0
- package/exceptions/http-version-not-supported.exception.d.ts +35 -0
- package/exceptions/http-version-not-supported.exception.js +43 -0
- package/exceptions/http.exception.d.ts +85 -0
- package/exceptions/http.exception.js +133 -0
- package/exceptions/im-a-teapot.exception.d.ts +38 -0
- package/exceptions/im-a-teapot.exception.js +46 -0
- package/exceptions/index.d.ts +23 -0
- package/exceptions/index.js +26 -0
- package/exceptions/internal-server-error.exception.d.ts +35 -0
- package/exceptions/internal-server-error.exception.js +43 -0
- package/exceptions/intrinsic.exception.d.ts +8 -0
- package/exceptions/intrinsic.exception.js +12 -0
- package/exceptions/method-not-allowed.exception.d.ts +35 -0
- package/exceptions/method-not-allowed.exception.js +43 -0
- package/exceptions/misdirected.exception.d.ts +35 -0
- package/exceptions/misdirected.exception.js +43 -0
- package/exceptions/not-acceptable.exception.d.ts +35 -0
- package/exceptions/not-acceptable.exception.js +43 -0
- package/exceptions/not-found.exception.d.ts +35 -0
- package/exceptions/not-found.exception.js +43 -0
- package/exceptions/not-implemented.exception.d.ts +35 -0
- package/exceptions/not-implemented.exception.js +43 -0
- package/exceptions/payload-too-large.exception.d.ts +35 -0
- package/exceptions/payload-too-large.exception.js +43 -0
- package/exceptions/precondition-failed.exception.d.ts +35 -0
- package/exceptions/precondition-failed.exception.js +43 -0
- package/exceptions/request-timeout.exception.d.ts +35 -0
- package/exceptions/request-timeout.exception.js +43 -0
- package/exceptions/service-unavailable.exception.d.ts +35 -0
- package/exceptions/service-unavailable.exception.js +43 -0
- package/exceptions/unauthorized.exception.d.ts +35 -0
- package/exceptions/unauthorized.exception.js +43 -0
- package/exceptions/unprocessable-entity.exception.d.ts +35 -0
- package/exceptions/unprocessable-entity.exception.js +43 -0
- package/exceptions/unsupported-media-type.exception.d.ts +35 -0
- package/exceptions/unsupported-media-type.exception.js +43 -0
- package/file-stream/index.d.ts +1 -0
- package/file-stream/index.js +4 -0
- package/file-stream/interfaces/index.d.ts +2 -0
- package/file-stream/interfaces/index.js +5 -0
- package/file-stream/interfaces/streamable-handler-response.interface.d.ts +12 -0
- package/file-stream/interfaces/streamable-handler-response.interface.js +2 -0
- package/file-stream/interfaces/streamable-options.interface.d.ts +22 -0
- package/file-stream/interfaces/streamable-options.interface.js +2 -0
- package/file-stream/streamable-file.d.ts +27 -0
- package/file-stream/streamable-file.js +68 -0
- package/index.d.ts +11 -0
- package/index.js +23 -0
- package/interfaces/abstract.interface.d.ts +3 -0
- package/interfaces/abstract.interface.js +2 -0
- package/interfaces/controllers/controller-metadata.interface.d.ts +3 -0
- package/interfaces/controllers/controller-metadata.interface.js +2 -0
- package/interfaces/controllers/controller.interface.d.ts +1 -0
- package/interfaces/controllers/controller.interface.js +2 -0
- package/interfaces/controllers/index.d.ts +2 -0
- package/interfaces/controllers/index.js +5 -0
- package/interfaces/exceptions/exception-filter-metadata.interface.d.ts +6 -0
- package/interfaces/exceptions/exception-filter-metadata.interface.js +2 -0
- package/interfaces/exceptions/exception-filter.interface.d.ts +18 -0
- package/interfaces/exceptions/exception-filter.interface.js +2 -0
- package/interfaces/exceptions/index.d.ts +5 -0
- package/interfaces/exceptions/index.js +8 -0
- package/interfaces/exceptions/rpc-exception-filter-metadata.interface.d.ts +6 -0
- package/interfaces/exceptions/rpc-exception-filter-metadata.interface.js +2 -0
- package/interfaces/exceptions/rpc-exception-filter.interface.d.ts +19 -0
- package/interfaces/exceptions/rpc-exception-filter.interface.js +2 -0
- package/interfaces/exceptions/ws-exception-filter.interface.d.ts +18 -0
- package/interfaces/exceptions/ws-exception-filter.interface.js +2 -0
- package/interfaces/external/class-transform-options.interface.d.ts +65 -0
- package/interfaces/external/class-transform-options.interface.js +2 -0
- package/interfaces/external/cors-options.interface.d.ts +58 -0
- package/interfaces/external/cors-options.interface.js +2 -0
- package/interfaces/external/https-options.interface.d.ts +105 -0
- package/interfaces/external/https-options.interface.js +2 -0
- package/interfaces/external/transformer-package.interface.d.ts +6 -0
- package/interfaces/external/transformer-package.interface.js +2 -0
- package/interfaces/external/validation-error.interface.d.ts +42 -0
- package/interfaces/external/validation-error.interface.js +2 -0
- package/interfaces/external/validator-options.interface.d.ts +76 -0
- package/interfaces/external/validator-options.interface.js +2 -0
- package/interfaces/external/validator-package.interface.d.ts +5 -0
- package/interfaces/external/validator-package.interface.js +2 -0
- package/interfaces/features/arguments-host.interface.d.ts +88 -0
- package/interfaces/features/arguments-host.interface.js +2 -0
- package/interfaces/features/can-activate.interface.d.ts +22 -0
- package/interfaces/features/can-activate.interface.js +2 -0
- package/interfaces/features/custom-route-param-factory.interface.d.ts +5 -0
- package/interfaces/features/custom-route-param-factory.interface.js +2 -0
- package/interfaces/features/execution-context.interface.d.ts +20 -0
- package/interfaces/features/execution-context.interface.js +2 -0
- package/interfaces/features/nest-interceptor.interface.d.ts +34 -0
- package/interfaces/features/nest-interceptor.interface.js +2 -0
- package/interfaces/features/paramtype.interface.d.ts +4 -0
- package/interfaces/features/paramtype.interface.js +2 -0
- package/interfaces/features/pipe-transform.interface.d.ts +42 -0
- package/interfaces/features/pipe-transform.interface.js +2 -0
- package/interfaces/global-prefix-options.interface.d.ts +7 -0
- package/interfaces/global-prefix-options.interface.js +2 -0
- package/interfaces/hooks/before-application-shutdown.interface.d.ts +3 -0
- package/interfaces/hooks/before-application-shutdown.interface.js +2 -0
- package/interfaces/hooks/index.d.ts +5 -0
- package/interfaces/hooks/index.js +8 -0
- package/interfaces/hooks/on-application-bootstrap.interface.d.ts +11 -0
- package/interfaces/hooks/on-application-bootstrap.interface.js +2 -0
- package/interfaces/hooks/on-application-shutdown.interface.d.ts +11 -0
- package/interfaces/hooks/on-application-shutdown.interface.js +2 -0
- package/interfaces/hooks/on-destroy.interface.d.ts +12 -0
- package/interfaces/hooks/on-destroy.interface.js +2 -0
- package/interfaces/hooks/on-init.interface.d.ts +10 -0
- package/interfaces/hooks/on-init.interface.js +2 -0
- package/interfaces/http/http-exception-body.interface.d.ts +6 -0
- package/interfaces/http/http-exception-body.interface.js +2 -0
- package/interfaces/http/http-redirect-response.interface.d.ts +5 -0
- package/interfaces/http/http-redirect-response.interface.js +2 -0
- package/interfaces/http/http-server.interface.d.ts +70 -0
- package/interfaces/http/http-server.interface.js +2 -0
- package/interfaces/http/index.d.ts +5 -0
- package/interfaces/http/index.js +8 -0
- package/interfaces/http/message-event.interface.d.ts +6 -0
- package/interfaces/http/message-event.interface.js +2 -0
- package/interfaces/http/raw-body-request.interface.d.ts +6 -0
- package/interfaces/http/raw-body-request.interface.js +2 -0
- package/interfaces/index.d.ts +30 -0
- package/interfaces/index.js +33 -0
- package/interfaces/injectable.interface.d.ts +1 -0
- package/interfaces/injectable.interface.js +2 -0
- package/interfaces/microservices/nest-hybrid-application-options.interface.d.ts +7 -0
- package/interfaces/microservices/nest-hybrid-application-options.interface.js +2 -0
- package/interfaces/microservices/nest-microservice-options.interface.d.ts +5 -0
- package/interfaces/microservices/nest-microservice-options.interface.js +2 -0
- package/interfaces/middleware/index.d.ts +4 -0
- package/interfaces/middleware/index.js +7 -0
- package/interfaces/middleware/middleware-config-proxy.interface.d.ts +24 -0
- package/interfaces/middleware/middleware-config-proxy.interface.js +2 -0
- package/interfaces/middleware/middleware-configuration.interface.d.ts +12 -0
- package/interfaces/middleware/middleware-configuration.interface.js +2 -0
- package/interfaces/middleware/middleware-consumer.interface.d.ts +18 -0
- package/interfaces/middleware/middleware-consumer.interface.js +2 -0
- package/interfaces/middleware/nest-middleware.interface.d.ts +8 -0
- package/interfaces/middleware/nest-middleware.interface.js +2 -0
- package/interfaces/modules/dynamic-module.interface.d.ts +25 -0
- package/interfaces/modules/dynamic-module.interface.js +2 -0
- package/interfaces/modules/forward-reference.interface.d.ts +3 -0
- package/interfaces/modules/forward-reference.interface.js +2 -0
- package/interfaces/modules/index.d.ts +8 -0
- package/interfaces/modules/index.js +11 -0
- package/interfaces/modules/injection-token.interface.d.ts +6 -0
- package/interfaces/modules/injection-token.interface.js +2 -0
- package/interfaces/modules/introspection-result.interface.d.ts +10 -0
- package/interfaces/modules/introspection-result.interface.js +2 -0
- package/interfaces/modules/module-metadata.interface.d.ts +34 -0
- package/interfaces/modules/module-metadata.interface.js +2 -0
- package/interfaces/modules/nest-module.interface.d.ts +7 -0
- package/interfaces/modules/nest-module.interface.js +2 -0
- package/interfaces/modules/optional-factory-dependency.interface.d.ts +8 -0
- package/interfaces/modules/optional-factory-dependency.interface.js +2 -0
- package/interfaces/modules/provider.interface.d.ts +156 -0
- package/interfaces/modules/provider.interface.js +2 -0
- package/interfaces/nest-application-context-options.interface.d.ts +68 -0
- package/interfaces/nest-application-context-options.interface.js +9 -0
- package/interfaces/nest-application-context.interface.d.ts +139 -0
- package/interfaces/nest-application-context.interface.js +2 -0
- package/interfaces/nest-application-options.interface.d.ts +29 -0
- package/interfaces/nest-application-options.interface.js +2 -0
- package/interfaces/nest-application.interface.d.ts +135 -0
- package/interfaces/nest-application.interface.js +2 -0
- package/interfaces/nest-microservice.interface.d.ts +75 -0
- package/interfaces/nest-microservice.interface.js +2 -0
- package/interfaces/scope-options.interface.d.ts +37 -0
- package/interfaces/scope-options.interface.js +23 -0
- package/interfaces/shutdown-hooks-options.interface.d.ts +21 -0
- package/interfaces/shutdown-hooks-options.interface.js +2 -0
- package/interfaces/type.interface.d.ts +3 -0
- package/interfaces/type.interface.js +2 -0
- package/interfaces/version-options.interface.d.ts +92 -0
- package/interfaces/version-options.interface.js +9 -0
- package/interfaces/websockets/web-socket-adapter.interface.d.ts +19 -0
- package/interfaces/websockets/web-socket-adapter.interface.js +2 -0
- package/module-utils/configurable-module.builder.d.ts +93 -0
- package/module-utils/configurable-module.builder.js +219 -0
- package/module-utils/constants.d.ts +9 -0
- package/module-utils/constants.js +19 -0
- package/module-utils/index.d.ts +2 -0
- package/module-utils/index.js +5 -0
- package/module-utils/interfaces/configurable-module-async-options.interface.d.ts +42 -0
- package/module-utils/interfaces/configurable-module-async-options.interface.js +2 -0
- package/module-utils/interfaces/configurable-module-cls.interface.d.ts +13 -0
- package/module-utils/interfaces/configurable-module-cls.interface.js +2 -0
- package/module-utils/interfaces/configurable-module-host.interface.d.ts +62 -0
- package/module-utils/interfaces/configurable-module-host.interface.js +2 -0
- package/module-utils/interfaces/index.d.ts +3 -0
- package/module-utils/interfaces/index.js +6 -0
- package/module-utils/utils/generate-options-injection-token.util.d.ts +1 -0
- package/module-utils/utils/generate-options-injection-token.util.js +8 -0
- package/module-utils/utils/get-injection-providers.util.d.ts +8 -0
- package/module-utils/utils/get-injection-providers.util.js +35 -0
- package/module-utils/utils/index.d.ts +2 -0
- package/module-utils/utils/index.js +5 -0
- package/package.json +61 -0
- package/pipes/default-value.pipe.d.ts +13 -0
- package/pipes/default-value.pipe.js +30 -0
- package/pipes/file/file-type.validator.d.ts +62 -0
- package/pipes/file/file-type.validator.js +102 -0
- package/pipes/file/file-validator-context.interface.d.ts +5 -0
- package/pipes/file/file-validator-context.interface.js +2 -0
- package/pipes/file/file-validator.interface.d.ts +21 -0
- package/pipes/file/file-validator.interface.js +15 -0
- package/pipes/file/index.d.ts +6 -0
- package/pipes/file/index.js +9 -0
- package/pipes/file/interfaces/file.interface.d.ts +5 -0
- package/pipes/file/interfaces/file.interface.js +2 -0
- package/pipes/file/interfaces/index.d.ts +1 -0
- package/pipes/file/interfaces/index.js +4 -0
- package/pipes/file/max-file-size.validator.d.ts +44 -0
- package/pipes/file/max-file-size.validator.js +37 -0
- package/pipes/file/parse-file-options.interface.d.ts +15 -0
- package/pipes/file/parse-file-options.interface.js +2 -0
- package/pipes/file/parse-file-pipe.builder.d.ts +15 -0
- package/pipes/file/parse-file-pipe.builder.js +33 -0
- package/pipes/file/parse-file.pipe.d.ts +28 -0
- package/pipes/file/parse-file.pipe.js +76 -0
- package/pipes/index.d.ts +10 -0
- package/pipes/index.js +13 -0
- package/pipes/parse-array.pipe.d.ts +52 -0
- package/pipes/parse-array.pipe.js +148 -0
- package/pipes/parse-bool.pipe.d.ts +55 -0
- package/pipes/parse-bool.pipe.js +67 -0
- package/pipes/parse-date.pipe.d.ts +37 -0
- package/pipes/parse-date.pipe.js +42 -0
- package/pipes/parse-enum.pipe.d.ts +46 -0
- package/pipes/parse-enum.pipe.js +55 -0
- package/pipes/parse-float.pipe.d.ts +49 -0
- package/pipes/parse-float.pipe.js +56 -0
- package/pipes/parse-int.pipe.d.ts +48 -0
- package/pipes/parse-int.pipe.js +57 -0
- package/pipes/parse-uuid.pipe.d.ts +49 -0
- package/pipes/parse-uuid.pipe.js +57 -0
- package/pipes/validation.pipe.d.ts +51 -0
- package/pipes/validation.pipe.js +245 -0
- package/serializer/class-serializer.constants.d.ts +1 -0
- package/serializer/class-serializer.constants.js +4 -0
- package/serializer/class-serializer.interceptor.d.ts +29 -0
- package/serializer/class-serializer.interceptor.js +77 -0
- package/serializer/class-serializer.interfaces.d.ts +8 -0
- package/serializer/class-serializer.interfaces.js +2 -0
- package/serializer/decorators/index.d.ts +1 -0
- package/serializer/decorators/index.js +4 -0
- package/serializer/decorators/serialize-options.decorator.d.ts +5 -0
- package/serializer/decorators/serialize-options.decorator.js +10 -0
- package/serializer/index.d.ts +3 -0
- package/serializer/index.js +6 -0
- package/services/console-logger.service.d.ts +202 -0
- package/services/console-logger.service.js +379 -0
- package/services/index.d.ts +3 -0
- package/services/index.js +6 -0
- package/services/logger.service.d.ts +152 -0
- package/services/logger.service.js +251 -0
- package/services/utils/filter-log-levels.util.d.ts +5 -0
- package/services/utils/filter-log-levels.util.js +23 -0
- package/services/utils/index.d.ts +3 -0
- package/services/utils/index.js +6 -0
- package/services/utils/is-log-level-enabled.util.d.ts +7 -0
- package/services/utils/is-log-level-enabled.util.js +32 -0
- package/services/utils/is-log-level.util.d.ts +5 -0
- package/services/utils/is-log-level.util.js +10 -0
- package/tsconfig.build.json +10 -0
- package/utils/assign-custom-metadata.util.d.ts +4 -0
- package/utils/assign-custom-metadata.util.js +15 -0
- package/utils/cli-colors.util.d.ts +10 -0
- package/utils/cli-colors.util.js +15 -0
- package/utils/extend-metadata.util.d.ts +1 -0
- package/utils/extend-metadata.util.js +8 -0
- package/utils/forward-ref.util.d.ts +5 -0
- package/utils/forward-ref.util.js +10 -0
- package/utils/http-error-by-code.util.d.ts +4 -0
- package/utils/http-error-by-code.util.js +26 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +4 -0
- package/utils/load-package.util.d.ts +1 -0
- package/utils/load-package.util.js +16 -0
- package/utils/merge-with-values.util.d.ts +4 -0
- package/utils/merge-with-values.util.js +18 -0
- package/utils/random-string-generator.util.d.ts +1 -0
- package/utils/random-string-generator.util.js +6 -0
- package/utils/select-exception-filter-metadata.util.d.ts +2 -0
- package/utils/select-exception-filter-metadata.util.js +6 -0
- package/utils/shared.utils.d.ts +13 -0
- package/utils/shared.utils.js +51 -0
- package/utils/validate-each.util.d.ts +8 -0
- package/utils/validate-each.util.js +25 -0
- package/utils/validate-module-keys.util.d.ts +2 -0
- package/utils/validate-module-keys.util.js +22 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseArrayPipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const injectable_decorator_1 = require("../decorators/core/injectable.decorator");
|
|
6
|
+
const optional_decorator_1 = require("../decorators/core/optional.decorator");
|
|
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");
|
|
10
|
+
const validation_pipe_1 = require("./validation.pipe");
|
|
11
|
+
const VALIDATION_ERROR_MESSAGE = 'Validation failed (parsable array expected)';
|
|
12
|
+
const DEFAULT_ARRAY_SEPARATOR = ',';
|
|
13
|
+
/**
|
|
14
|
+
* Defines the built-in ParseArray Pipe
|
|
15
|
+
*
|
|
16
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
17
|
+
*
|
|
18
|
+
* @publicApi
|
|
19
|
+
*/
|
|
20
|
+
let ParseArrayPipe = class ParseArrayPipe {
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.validationPipe = new validation_pipe_1.ValidationPipe({
|
|
24
|
+
transform: true,
|
|
25
|
+
validateCustomDecorators: true,
|
|
26
|
+
...options,
|
|
27
|
+
});
|
|
28
|
+
const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST } = options;
|
|
29
|
+
this.exceptionFactory =
|
|
30
|
+
exceptionFactory ||
|
|
31
|
+
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Method that accesses and performs optional transformation on argument for
|
|
35
|
+
* in-flight requests.
|
|
36
|
+
*
|
|
37
|
+
* @param value currently processed route argument
|
|
38
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
39
|
+
*/
|
|
40
|
+
async transform(value, metadata) {
|
|
41
|
+
if (!value && !this.options.optional) {
|
|
42
|
+
throw this.exceptionFactory(VALIDATION_ERROR_MESSAGE);
|
|
43
|
+
}
|
|
44
|
+
else if ((0, shared_utils_1.isNil)(value) && this.options.optional) {
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
47
|
+
if (!Array.isArray(value)) {
|
|
48
|
+
if (!(0, shared_utils_1.isString)(value)) {
|
|
49
|
+
throw this.exceptionFactory(VALIDATION_ERROR_MESSAGE);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
try {
|
|
53
|
+
value = value
|
|
54
|
+
.trim()
|
|
55
|
+
.split(this.options.separator || DEFAULT_ARRAY_SEPARATOR);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
throw this.exceptionFactory(VALIDATION_ERROR_MESSAGE);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (this.options.items) {
|
|
63
|
+
const validationMetadata = {
|
|
64
|
+
metatype: this.options.items,
|
|
65
|
+
type: 'query',
|
|
66
|
+
};
|
|
67
|
+
const isExpectedTypePrimitive = this.isExpectedTypePrimitive();
|
|
68
|
+
const toClassInstance = (item, index) => {
|
|
69
|
+
if (this.options.items !== String) {
|
|
70
|
+
try {
|
|
71
|
+
item = JSON.parse(item);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Do nothing
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (isExpectedTypePrimitive) {
|
|
78
|
+
return this.validatePrimitive(item, index);
|
|
79
|
+
}
|
|
80
|
+
return this.validationPipe.transform(item, validationMetadata);
|
|
81
|
+
};
|
|
82
|
+
if (this.options.stopAtFirstError === false) {
|
|
83
|
+
// strict compare to "false" to make sure
|
|
84
|
+
// that this option is disabled by default
|
|
85
|
+
let errors = [];
|
|
86
|
+
const targetArray = value;
|
|
87
|
+
for (let i = 0; i < targetArray.length; i++) {
|
|
88
|
+
try {
|
|
89
|
+
targetArray[i] = await toClassInstance(targetArray[i]);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
let message;
|
|
93
|
+
if (err.getResponse) {
|
|
94
|
+
const response = err.getResponse();
|
|
95
|
+
if (Array.isArray(response.message)) {
|
|
96
|
+
message = response.message.map((item) => `[${i}] ${item}`);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
message = `[${i}] ${response.message}`;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
message = err;
|
|
104
|
+
}
|
|
105
|
+
errors = errors.concat(message);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (errors.length > 0) {
|
|
109
|
+
throw this.exceptionFactory(errors);
|
|
110
|
+
}
|
|
111
|
+
return targetArray;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
value = await Promise.all(value.map(toClassInstance));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
isExpectedTypePrimitive() {
|
|
120
|
+
return [Boolean, Number, String].includes(this.options.items);
|
|
121
|
+
}
|
|
122
|
+
validatePrimitive(originalValue, index) {
|
|
123
|
+
if (this.options.items === Number) {
|
|
124
|
+
const value = originalValue !== null && originalValue !== '' ? +originalValue : NaN;
|
|
125
|
+
if (isNaN(value)) {
|
|
126
|
+
throw this.exceptionFactory(`${(0, shared_utils_1.isUndefined)(index) ? '' : `[${index}] `}item must be a number`);
|
|
127
|
+
}
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
else if (this.options.items === String) {
|
|
131
|
+
if (!(0, shared_utils_1.isString)(originalValue)) {
|
|
132
|
+
return `${originalValue}`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (this.options.items === Boolean) {
|
|
136
|
+
if (typeof originalValue !== 'boolean') {
|
|
137
|
+
throw this.exceptionFactory(`${(0, shared_utils_1.isUndefined)(index) ? '' : `[${index}] `}item must be a boolean value`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return originalValue;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
exports.ParseArrayPipe = ParseArrayPipe;
|
|
144
|
+
exports.ParseArrayPipe = ParseArrayPipe = tslib_1.__decorate([
|
|
145
|
+
(0, injectable_decorator_1.Injectable)(),
|
|
146
|
+
tslib_1.__param(0, (0, optional_decorator_1.Optional)()),
|
|
147
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
148
|
+
], ParseArrayPipe);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
2
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
3
|
+
/**
|
|
4
|
+
* @publicApi
|
|
5
|
+
*/
|
|
6
|
+
export interface ParseBoolPipeOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The HTTP status code to be used in the response when the validation fails.
|
|
9
|
+
*/
|
|
10
|
+
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
11
|
+
/**
|
|
12
|
+
* A factory function that returns an exception object to be thrown
|
|
13
|
+
* if validation fails.
|
|
14
|
+
* @param error Error message
|
|
15
|
+
* @returns The exception object
|
|
16
|
+
*/
|
|
17
|
+
exceptionFactory?: (error: string) => any;
|
|
18
|
+
/**
|
|
19
|
+
* If true, the pipe will return null or undefined if the value is not provided
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
optional?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Defines the built-in ParseBool Pipe
|
|
26
|
+
*
|
|
27
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
28
|
+
*
|
|
29
|
+
* @publicApi
|
|
30
|
+
*/
|
|
31
|
+
export declare class ParseBoolPipe implements PipeTransform<string | boolean, Promise<boolean>> {
|
|
32
|
+
protected readonly options?: ParseBoolPipeOptions | undefined;
|
|
33
|
+
protected exceptionFactory: (error: string) => any;
|
|
34
|
+
constructor(options?: ParseBoolPipeOptions | undefined);
|
|
35
|
+
/**
|
|
36
|
+
* Method that accesses and performs optional transformation on argument for
|
|
37
|
+
* in-flight requests.
|
|
38
|
+
*
|
|
39
|
+
* @param value currently processed route argument
|
|
40
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
41
|
+
*/
|
|
42
|
+
transform(value: string | boolean, metadata: ArgumentMetadata): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* @param value currently processed route argument
|
|
45
|
+
* @returns `true` if `value` is said 'true', ie., if it is equal to the boolean
|
|
46
|
+
* `true` or the string `"true"`
|
|
47
|
+
*/
|
|
48
|
+
protected isTrue(value: string | boolean): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* @param value currently processed route argument
|
|
51
|
+
* @returns `true` if `value` is said 'false', ie., if it is equal to the boolean
|
|
52
|
+
* `false` or the string `"false"`
|
|
53
|
+
*/
|
|
54
|
+
protected isFalse(value: string | boolean): boolean;
|
|
55
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseBoolPipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const injectable_decorator_1 = require("../decorators/core/injectable.decorator");
|
|
6
|
+
const optional_decorator_1 = require("../decorators/core/optional.decorator");
|
|
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");
|
|
10
|
+
/**
|
|
11
|
+
* Defines the built-in ParseBool Pipe
|
|
12
|
+
*
|
|
13
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
14
|
+
*
|
|
15
|
+
* @publicApi
|
|
16
|
+
*/
|
|
17
|
+
let ParseBoolPipe = class ParseBoolPipe {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.options = options;
|
|
20
|
+
options = options || {};
|
|
21
|
+
const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST } = options;
|
|
22
|
+
this.exceptionFactory =
|
|
23
|
+
exceptionFactory ||
|
|
24
|
+
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Method that accesses and performs optional transformation on argument for
|
|
28
|
+
* in-flight requests.
|
|
29
|
+
*
|
|
30
|
+
* @param value currently processed route argument
|
|
31
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
32
|
+
*/
|
|
33
|
+
async transform(value, metadata) {
|
|
34
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
if (this.isTrue(value)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (this.isFalse(value)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
throw this.exceptionFactory('Validation failed (boolean string is expected)');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @param value currently processed route argument
|
|
47
|
+
* @returns `true` if `value` is said 'true', ie., if it is equal to the boolean
|
|
48
|
+
* `true` or the string `"true"`
|
|
49
|
+
*/
|
|
50
|
+
isTrue(value) {
|
|
51
|
+
return value === true || value === 'true';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @param value currently processed route argument
|
|
55
|
+
* @returns `true` if `value` is said 'false', ie., if it is equal to the boolean
|
|
56
|
+
* `false` or the string `"false"`
|
|
57
|
+
*/
|
|
58
|
+
isFalse(value) {
|
|
59
|
+
return value === false || value === 'false';
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.ParseBoolPipe = ParseBoolPipe;
|
|
63
|
+
exports.ParseBoolPipe = ParseBoolPipe = tslib_1.__decorate([
|
|
64
|
+
(0, injectable_decorator_1.Injectable)(),
|
|
65
|
+
tslib_1.__param(0, (0, optional_decorator_1.Optional)()),
|
|
66
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
67
|
+
], ParseBoolPipe);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
2
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
3
|
+
export interface ParseDatePipeOptions {
|
|
4
|
+
/**
|
|
5
|
+
* If true, the pipe will return null or undefined if the value is not provided
|
|
6
|
+
* @default false
|
|
7
|
+
*/
|
|
8
|
+
optional?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Default value for the date
|
|
11
|
+
*/
|
|
12
|
+
default?: () => Date;
|
|
13
|
+
/**
|
|
14
|
+
* The HTTP status code to be used in the response when the validation fails.
|
|
15
|
+
*/
|
|
16
|
+
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
17
|
+
/**
|
|
18
|
+
* A factory function that returns an exception object to be thrown
|
|
19
|
+
* if validation fails.
|
|
20
|
+
* @param error Error message
|
|
21
|
+
* @returns The exception object
|
|
22
|
+
*/
|
|
23
|
+
exceptionFactory?: (error: string) => any;
|
|
24
|
+
}
|
|
25
|
+
export declare class ParseDatePipe implements PipeTransform<string | number | undefined | null> {
|
|
26
|
+
private readonly options;
|
|
27
|
+
protected exceptionFactory: (error: string) => any;
|
|
28
|
+
constructor(options?: ParseDatePipeOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Method that accesses and performs optional transformation on argument for
|
|
31
|
+
* in-flight requests.
|
|
32
|
+
*
|
|
33
|
+
* @param value currently processed route argument
|
|
34
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
35
|
+
*/
|
|
36
|
+
transform(value: string | number | undefined | null): Date | null | undefined;
|
|
37
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseDatePipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const injectable_decorator_1 = require("../decorators/core/injectable.decorator");
|
|
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");
|
|
9
|
+
let ParseDatePipe = class ParseDatePipe {
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
this.options = options;
|
|
12
|
+
const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST } = options;
|
|
13
|
+
this.exceptionFactory =
|
|
14
|
+
exceptionFactory ||
|
|
15
|
+
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Method that accesses and performs optional transformation on argument for
|
|
19
|
+
* in-flight requests.
|
|
20
|
+
*
|
|
21
|
+
* @param value currently processed route argument
|
|
22
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
23
|
+
*/
|
|
24
|
+
transform(value) {
|
|
25
|
+
if (this.options.optional && (0, shared_utils_1.isNil)(value)) {
|
|
26
|
+
return this.options.default ? this.options.default() : value;
|
|
27
|
+
}
|
|
28
|
+
if (!value) {
|
|
29
|
+
throw this.exceptionFactory('Validation failed (no Date provided)');
|
|
30
|
+
}
|
|
31
|
+
const transformedValue = new Date(value);
|
|
32
|
+
if (isNaN(transformedValue.getTime())) {
|
|
33
|
+
throw this.exceptionFactory('Validation failed (invalid date format)');
|
|
34
|
+
}
|
|
35
|
+
return transformedValue;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.ParseDatePipe = ParseDatePipe;
|
|
39
|
+
exports.ParseDatePipe = ParseDatePipe = tslib_1.__decorate([
|
|
40
|
+
(0, injectable_decorator_1.Injectable)(),
|
|
41
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
42
|
+
], ParseDatePipe);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ArgumentMetadata } from '../index';
|
|
2
|
+
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
3
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
4
|
+
/**
|
|
5
|
+
* @publicApi
|
|
6
|
+
*/
|
|
7
|
+
export interface ParseEnumPipeOptions {
|
|
8
|
+
/**
|
|
9
|
+
* If true, the pipe will return null or undefined if the value is not provided
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
optional?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The HTTP status code to be used in the response when the validation fails.
|
|
15
|
+
*/
|
|
16
|
+
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
17
|
+
/**
|
|
18
|
+
* A factory function that returns an exception object to be thrown
|
|
19
|
+
* if validation fails.
|
|
20
|
+
* @param error Error message
|
|
21
|
+
* @returns The exception object
|
|
22
|
+
*/
|
|
23
|
+
exceptionFactory?: (error: string) => any;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Defines the built-in ParseEnum Pipe
|
|
27
|
+
*
|
|
28
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
29
|
+
*
|
|
30
|
+
* @publicApi
|
|
31
|
+
*/
|
|
32
|
+
export declare class ParseEnumPipe<T = any> implements PipeTransform<T> {
|
|
33
|
+
protected readonly enumType: T;
|
|
34
|
+
protected readonly options?: ParseEnumPipeOptions | undefined;
|
|
35
|
+
protected exceptionFactory: (error: string) => any;
|
|
36
|
+
constructor(enumType: T, options?: ParseEnumPipeOptions | undefined);
|
|
37
|
+
/**
|
|
38
|
+
* Method that accesses and performs optional transformation on argument for
|
|
39
|
+
* in-flight requests.
|
|
40
|
+
*
|
|
41
|
+
* @param value currently processed route argument
|
|
42
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
43
|
+
*/
|
|
44
|
+
transform(value: T, metadata: ArgumentMetadata): Promise<T>;
|
|
45
|
+
protected isEnum(value: T): boolean;
|
|
46
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseEnumPipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("../decorators/core");
|
|
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");
|
|
9
|
+
/**
|
|
10
|
+
* Defines the built-in ParseEnum Pipe
|
|
11
|
+
*
|
|
12
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
13
|
+
*
|
|
14
|
+
* @publicApi
|
|
15
|
+
*/
|
|
16
|
+
let ParseEnumPipe = class ParseEnumPipe {
|
|
17
|
+
constructor(enumType, options) {
|
|
18
|
+
this.enumType = enumType;
|
|
19
|
+
this.options = options;
|
|
20
|
+
if (!enumType) {
|
|
21
|
+
throw new Error(`"ParseEnumPipe" requires "enumType" argument specified (to validate input values).`);
|
|
22
|
+
}
|
|
23
|
+
options = options || {};
|
|
24
|
+
const { exceptionFactory, errorHttpStatusCode = index_1.HttpStatus.BAD_REQUEST } = options;
|
|
25
|
+
this.exceptionFactory =
|
|
26
|
+
exceptionFactory ||
|
|
27
|
+
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Method that accesses and performs optional transformation on argument for
|
|
31
|
+
* in-flight requests.
|
|
32
|
+
*
|
|
33
|
+
* @param value currently processed route argument
|
|
34
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
35
|
+
*/
|
|
36
|
+
async transform(value, metadata) {
|
|
37
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
if (!this.isEnum(value)) {
|
|
41
|
+
throw this.exceptionFactory('Validation failed (enum string is expected)');
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
isEnum(value) {
|
|
46
|
+
const enumValues = Object.keys(this.enumType).map(item => this.enumType[item]);
|
|
47
|
+
return enumValues.includes(value);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.ParseEnumPipe = ParseEnumPipe;
|
|
51
|
+
exports.ParseEnumPipe = ParseEnumPipe = tslib_1.__decorate([
|
|
52
|
+
(0, core_1.Injectable)(),
|
|
53
|
+
tslib_1.__param(1, (0, core_1.Optional)()),
|
|
54
|
+
tslib_1.__metadata("design:paramtypes", [Object, Object])
|
|
55
|
+
], ParseEnumPipe);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ArgumentMetadata } from '../index';
|
|
2
|
+
import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
3
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
4
|
+
/**
|
|
5
|
+
* @publicApi
|
|
6
|
+
*/
|
|
7
|
+
export interface ParseFloatPipeOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The HTTP status code to be used in the response when the validation fails.
|
|
10
|
+
*/
|
|
11
|
+
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
12
|
+
/**
|
|
13
|
+
* A factory function that returns an exception object to be thrown
|
|
14
|
+
* if validation fails.
|
|
15
|
+
* @param error Error message
|
|
16
|
+
* @returns The exception object
|
|
17
|
+
*/
|
|
18
|
+
exceptionFactory?: (error: string) => any;
|
|
19
|
+
/**
|
|
20
|
+
* If true, the pipe will return null or undefined if the value is not provided
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
optional?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Defines the built-in ParseFloat Pipe
|
|
27
|
+
*
|
|
28
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
29
|
+
*
|
|
30
|
+
* @publicApi
|
|
31
|
+
*/
|
|
32
|
+
export declare class ParseFloatPipe implements PipeTransform<string> {
|
|
33
|
+
protected readonly options?: ParseFloatPipeOptions | undefined;
|
|
34
|
+
protected exceptionFactory: (error: string) => any;
|
|
35
|
+
constructor(options?: ParseFloatPipeOptions | undefined);
|
|
36
|
+
/**
|
|
37
|
+
* Method that accesses and performs optional transformation on argument for
|
|
38
|
+
* in-flight requests.
|
|
39
|
+
*
|
|
40
|
+
* @param value currently processed route argument
|
|
41
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
42
|
+
*/
|
|
43
|
+
transform(value: string, metadata: ArgumentMetadata): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* @param value currently processed route argument
|
|
46
|
+
* @returns `true` if `value` is a valid float number
|
|
47
|
+
*/
|
|
48
|
+
protected isNumeric(value: string): boolean;
|
|
49
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseFloatPipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("../decorators/core");
|
|
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");
|
|
9
|
+
/**
|
|
10
|
+
* Defines the built-in ParseFloat Pipe
|
|
11
|
+
*
|
|
12
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
13
|
+
*
|
|
14
|
+
* @publicApi
|
|
15
|
+
*/
|
|
16
|
+
let ParseFloatPipe = class ParseFloatPipe {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
this.options = options;
|
|
19
|
+
options = options || {};
|
|
20
|
+
const { exceptionFactory, errorHttpStatusCode = index_1.HttpStatus.BAD_REQUEST } = options;
|
|
21
|
+
this.exceptionFactory =
|
|
22
|
+
exceptionFactory ||
|
|
23
|
+
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Method that accesses and performs optional transformation on argument for
|
|
27
|
+
* in-flight requests.
|
|
28
|
+
*
|
|
29
|
+
* @param value currently processed route argument
|
|
30
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
31
|
+
*/
|
|
32
|
+
async transform(value, metadata) {
|
|
33
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
if (!this.isNumeric(value)) {
|
|
37
|
+
throw this.exceptionFactory('Validation failed (numeric string is expected)');
|
|
38
|
+
}
|
|
39
|
+
return parseFloat(value);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @param value currently processed route argument
|
|
43
|
+
* @returns `true` if `value` is a valid float number
|
|
44
|
+
*/
|
|
45
|
+
isNumeric(value) {
|
|
46
|
+
return (['string', 'number'].includes(typeof value) &&
|
|
47
|
+
!isNaN(parseFloat(value)) &&
|
|
48
|
+
isFinite(value));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
exports.ParseFloatPipe = ParseFloatPipe;
|
|
52
|
+
exports.ParseFloatPipe = ParseFloatPipe = tslib_1.__decorate([
|
|
53
|
+
(0, core_1.Injectable)(),
|
|
54
|
+
tslib_1.__param(0, (0, core_1.Optional)()),
|
|
55
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
56
|
+
], ParseFloatPipe);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
2
|
+
import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
|
|
3
|
+
/**
|
|
4
|
+
* @publicApi
|
|
5
|
+
*/
|
|
6
|
+
export interface ParseIntPipeOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The HTTP status code to be used in the response when the validation fails.
|
|
9
|
+
*/
|
|
10
|
+
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
11
|
+
/**
|
|
12
|
+
* A factory function that returns an exception object to be thrown
|
|
13
|
+
* if validation fails.
|
|
14
|
+
* @param error Error message
|
|
15
|
+
* @returns The exception object
|
|
16
|
+
*/
|
|
17
|
+
exceptionFactory?: (error: string) => any;
|
|
18
|
+
/**
|
|
19
|
+
* If true, the pipe will return null or undefined if the value is not provided
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
optional?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Defines the built-in ParseInt Pipe
|
|
26
|
+
*
|
|
27
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
28
|
+
*
|
|
29
|
+
* @publicApi
|
|
30
|
+
*/
|
|
31
|
+
export declare class ParseIntPipe implements PipeTransform<string> {
|
|
32
|
+
protected readonly options?: ParseIntPipeOptions | undefined;
|
|
33
|
+
protected exceptionFactory: (error: string) => any;
|
|
34
|
+
constructor(options?: ParseIntPipeOptions | undefined);
|
|
35
|
+
/**
|
|
36
|
+
* Method that accesses and performs optional transformation on argument for
|
|
37
|
+
* in-flight requests.
|
|
38
|
+
*
|
|
39
|
+
* @param value currently processed route argument
|
|
40
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
41
|
+
*/
|
|
42
|
+
transform(value: string, metadata: ArgumentMetadata): Promise<number>;
|
|
43
|
+
/**
|
|
44
|
+
* @param value currently processed route argument
|
|
45
|
+
* @returns `true` if `value` is a valid integer number
|
|
46
|
+
*/
|
|
47
|
+
protected isNumeric(value: string): boolean;
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseIntPipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const injectable_decorator_1 = require("../decorators/core/injectable.decorator");
|
|
6
|
+
const optional_decorator_1 = require("../decorators/core/optional.decorator");
|
|
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");
|
|
10
|
+
/**
|
|
11
|
+
* Defines the built-in ParseInt Pipe
|
|
12
|
+
*
|
|
13
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
14
|
+
*
|
|
15
|
+
* @publicApi
|
|
16
|
+
*/
|
|
17
|
+
let ParseIntPipe = class ParseIntPipe {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.options = options;
|
|
20
|
+
options = options || {};
|
|
21
|
+
const { exceptionFactory, errorHttpStatusCode = http_status_enum_1.HttpStatus.BAD_REQUEST } = options;
|
|
22
|
+
this.exceptionFactory =
|
|
23
|
+
exceptionFactory ||
|
|
24
|
+
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Method that accesses and performs optional transformation on argument for
|
|
28
|
+
* in-flight requests.
|
|
29
|
+
*
|
|
30
|
+
* @param value currently processed route argument
|
|
31
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
32
|
+
*/
|
|
33
|
+
async transform(value, metadata) {
|
|
34
|
+
if ((0, shared_utils_1.isNil)(value) && this.options?.optional) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
if (!this.isNumeric(value)) {
|
|
38
|
+
throw this.exceptionFactory('Validation failed (numeric string is expected)');
|
|
39
|
+
}
|
|
40
|
+
return parseInt(value, 10);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @param value currently processed route argument
|
|
44
|
+
* @returns `true` if `value` is a valid integer number
|
|
45
|
+
*/
|
|
46
|
+
isNumeric(value) {
|
|
47
|
+
return (['string', 'number'].includes(typeof value) &&
|
|
48
|
+
/^-?\d+$/.test(value) &&
|
|
49
|
+
isFinite(value));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
exports.ParseIntPipe = ParseIntPipe;
|
|
53
|
+
exports.ParseIntPipe = ParseIntPipe = 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])
|
|
57
|
+
], ParseIntPipe);
|