@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,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileTypeValidator = void 0;
|
|
4
|
+
const url_1 = require("url");
|
|
5
|
+
const logger_service_1 = require("../../services/logger.service");
|
|
6
|
+
const file_validator_interface_1 = require("./file-validator.interface");
|
|
7
|
+
const load_esm_1 = require("load-esm");
|
|
8
|
+
const logger = new logger_service_1.Logger('FileTypeValidator');
|
|
9
|
+
/**
|
|
10
|
+
* Defines the built-in FileTypeValidator. It validates incoming files by examining
|
|
11
|
+
* their magic numbers using the file-type package, providing more reliable file type validation
|
|
12
|
+
* than just checking the mimetype string.
|
|
13
|
+
*
|
|
14
|
+
* @see [File Validators](https://docs.nestjs.com/techniques/file-upload#validators)
|
|
15
|
+
*
|
|
16
|
+
* @publicApi
|
|
17
|
+
*/
|
|
18
|
+
class FileTypeValidator extends file_validator_interface_1.FileValidator {
|
|
19
|
+
buildErrorMessage(file) {
|
|
20
|
+
const { errorMessage, ...config } = this.validationOptions;
|
|
21
|
+
if (errorMessage) {
|
|
22
|
+
return typeof errorMessage === 'function'
|
|
23
|
+
? errorMessage({ file, config })
|
|
24
|
+
: errorMessage;
|
|
25
|
+
}
|
|
26
|
+
if (file?.mimetype) {
|
|
27
|
+
const baseMessage = `Validation failed (current file type is ${file.mimetype}, expected type is ${this.validationOptions.fileType})`;
|
|
28
|
+
/**
|
|
29
|
+
* If fallbackToMimetype is enabled, this means the validator failed to detect the file type
|
|
30
|
+
* via magic number inspection (e.g. due to an unknown or too short buffer),
|
|
31
|
+
* and instead used the mimetype string provided by the client as a fallback.
|
|
32
|
+
*
|
|
33
|
+
* This message clarifies that fallback logic was used, in case users rely on file signatures.
|
|
34
|
+
*/
|
|
35
|
+
if (this.validationOptions.fallbackToMimetype) {
|
|
36
|
+
return `${baseMessage} - magic number detection failed, used mimetype fallback`;
|
|
37
|
+
}
|
|
38
|
+
return baseMessage;
|
|
39
|
+
}
|
|
40
|
+
return `Validation failed (expected type is ${this.validationOptions.fileType})`;
|
|
41
|
+
}
|
|
42
|
+
async isValid(file) {
|
|
43
|
+
if (!this.validationOptions) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
const isFileValid = !!file && 'mimetype' in file;
|
|
47
|
+
// Skip magic number validation if set
|
|
48
|
+
if (this.validationOptions.skipMagicNumbersValidation) {
|
|
49
|
+
return (isFileValid && !!file.mimetype.match(this.validationOptions.fileType));
|
|
50
|
+
}
|
|
51
|
+
if (!isFileValid)
|
|
52
|
+
return false;
|
|
53
|
+
if (!file.buffer) {
|
|
54
|
+
if (this.validationOptions.fallbackToMimetype) {
|
|
55
|
+
return !!file.mimetype.match(this.validationOptions.fileType);
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
let fileTypeModule;
|
|
61
|
+
try {
|
|
62
|
+
const resolvedPath = require.resolve('file-type');
|
|
63
|
+
fileTypeModule = (0, url_1.pathToFileURL)(resolvedPath).href;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
fileTypeModule = 'file-type';
|
|
67
|
+
}
|
|
68
|
+
const { fileTypeFromBuffer } = await (0, load_esm_1.loadEsm)(fileTypeModule);
|
|
69
|
+
const fileType = await fileTypeFromBuffer(file.buffer);
|
|
70
|
+
if (fileType) {
|
|
71
|
+
// Match detected mime type against allowed type
|
|
72
|
+
return !!fileType.mime.match(this.validationOptions.fileType);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Fallback logic: If file-type cannot detect magic number (e.g. file too small),
|
|
76
|
+
* Optionally fall back to mimetype string for compatibility.
|
|
77
|
+
* This is useful for plain text, CSVs, or files without recognizable signatures.
|
|
78
|
+
*/
|
|
79
|
+
if (this.validationOptions.fallbackToMimetype) {
|
|
80
|
+
return !!file.mimetype.match(this.validationOptions.fileType);
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
86
|
+
// Check for common ESM loading issues
|
|
87
|
+
if (errorMessage.includes('ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING') ||
|
|
88
|
+
errorMessage.includes('Cannot find module') ||
|
|
89
|
+
errorMessage.includes('ERR_MODULE_NOT_FOUND')) {
|
|
90
|
+
logger.warn(`Failed to load the "file-type" package for magic number validation. ` +
|
|
91
|
+
`If you are using Jest, run it with NODE_OPTIONS="--experimental-vm-modules". ` +
|
|
92
|
+
`Error: ${errorMessage}`);
|
|
93
|
+
}
|
|
94
|
+
// Fallback to mimetype if enabled
|
|
95
|
+
if (this.validationOptions.fallbackToMimetype) {
|
|
96
|
+
return !!file.mimetype.match(this.validationOptions.fileType);
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.FileTypeValidator = FileTypeValidator;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IFile } from './interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Interface describing FileValidators, which can be added to a ParseFilePipe
|
|
4
|
+
*
|
|
5
|
+
* @see {ParseFilePipe}
|
|
6
|
+
* @publicApi
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class FileValidator<TValidationOptions = Record<string, any>, TFile extends IFile = IFile> {
|
|
9
|
+
protected readonly validationOptions: TValidationOptions;
|
|
10
|
+
constructor(validationOptions: TValidationOptions);
|
|
11
|
+
/**
|
|
12
|
+
* Indicates if this file should be considered valid, according to the options passed in the constructor.
|
|
13
|
+
* @param file the file from the request object
|
|
14
|
+
*/
|
|
15
|
+
abstract isValid(file?: TFile | TFile[] | Record<string, TFile[]>): boolean | Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Builds an error message in case the validation fails.
|
|
18
|
+
* @param file the file from the request object
|
|
19
|
+
*/
|
|
20
|
+
abstract buildErrorMessage(file: any): string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileValidator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Interface describing FileValidators, which can be added to a ParseFilePipe
|
|
6
|
+
*
|
|
7
|
+
* @see {ParseFilePipe}
|
|
8
|
+
* @publicApi
|
|
9
|
+
*/
|
|
10
|
+
class FileValidator {
|
|
11
|
+
constructor(validationOptions) {
|
|
12
|
+
this.validationOptions = validationOptions;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.FileValidator = FileValidator;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./file-type.validator"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./file-validator.interface"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./max-file-size.validator"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./parse-file-options.interface"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./parse-file.pipe"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./parse-file-pipe.builder"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './file.interface';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FileValidatorContext } from './file-validator-context.interface';
|
|
2
|
+
import { FileValidator } from './file-validator.interface';
|
|
3
|
+
import { IFile } from './interfaces';
|
|
4
|
+
type MaxFileSizeValidatorContext = FileValidatorContext<Omit<MaxFileSizeValidatorOptions, 'errorMessage' | 'message'>>;
|
|
5
|
+
export type MaxFileSizeValidatorOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Maximum allowed file size in bytes.
|
|
8
|
+
*/
|
|
9
|
+
maxSize: number;
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated Use `errorMessage` instead.
|
|
12
|
+
*/
|
|
13
|
+
message?: string | ((maxSize: number) => string);
|
|
14
|
+
/**
|
|
15
|
+
* Custom error message returned when file size validation fails.
|
|
16
|
+
* Can be provided as a static string, or as a factory function
|
|
17
|
+
* that receives the validation context (file and validator configuration)
|
|
18
|
+
* and returns a dynamic error message.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Static message
|
|
22
|
+
* new MaxFileSizeValidator({ maxSize: 1000, errorMessage: 'File size exceeds the limit' })
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Dynamic message based on file object and validator configuration
|
|
26
|
+
* new MaxFileSizeValidator({
|
|
27
|
+
* maxSize: 1000,
|
|
28
|
+
* errorMessage: ctx => `Received file size is ${ctx.file?.size}, but it must be smaller than ${ctx.config.maxSize}.`
|
|
29
|
+
* })
|
|
30
|
+
*/
|
|
31
|
+
errorMessage?: string | ((ctx: MaxFileSizeValidatorContext) => string);
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Defines the built-in MaxSize File Validator
|
|
35
|
+
*
|
|
36
|
+
* @see [File Validators](https://docs.nestjs.com/techniques/file-upload#file-validation)
|
|
37
|
+
*
|
|
38
|
+
* @publicApi
|
|
39
|
+
*/
|
|
40
|
+
export declare class MaxFileSizeValidator extends FileValidator<MaxFileSizeValidatorOptions, IFile> {
|
|
41
|
+
buildErrorMessage(file?: IFile): string;
|
|
42
|
+
isValid(file?: IFile): boolean;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MaxFileSizeValidator = void 0;
|
|
4
|
+
const file_validator_interface_1 = require("./file-validator.interface");
|
|
5
|
+
/**
|
|
6
|
+
* Defines the built-in MaxSize File Validator
|
|
7
|
+
*
|
|
8
|
+
* @see [File Validators](https://docs.nestjs.com/techniques/file-upload#file-validation)
|
|
9
|
+
*
|
|
10
|
+
* @publicApi
|
|
11
|
+
*/
|
|
12
|
+
class MaxFileSizeValidator extends file_validator_interface_1.FileValidator {
|
|
13
|
+
buildErrorMessage(file) {
|
|
14
|
+
const { errorMessage, message, ...config } = this.validationOptions;
|
|
15
|
+
if (errorMessage) {
|
|
16
|
+
return typeof errorMessage === 'function'
|
|
17
|
+
? errorMessage({ file, config })
|
|
18
|
+
: errorMessage;
|
|
19
|
+
}
|
|
20
|
+
if (message) {
|
|
21
|
+
return typeof message === 'function'
|
|
22
|
+
? message(this.validationOptions.maxSize)
|
|
23
|
+
: message;
|
|
24
|
+
}
|
|
25
|
+
if (file?.size) {
|
|
26
|
+
return `Validation failed (current file size is ${file.size}, expected size is less than ${this.validationOptions.maxSize})`;
|
|
27
|
+
}
|
|
28
|
+
return `Validation failed (expected size is less than ${this.validationOptions.maxSize})`;
|
|
29
|
+
}
|
|
30
|
+
isValid(file) {
|
|
31
|
+
if (!this.validationOptions || !file) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return 'size' in file && file.size < this.validationOptions.maxSize;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.MaxFileSizeValidator = MaxFileSizeValidator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ErrorHttpStatusCode } from '../../utils/http-error-by-code.util';
|
|
2
|
+
import { FileValidator } from './file-validator.interface';
|
|
3
|
+
/**
|
|
4
|
+
* @publicApi
|
|
5
|
+
*/
|
|
6
|
+
export interface ParseFileOptions {
|
|
7
|
+
validators?: FileValidator[];
|
|
8
|
+
errorHttpStatusCode?: ErrorHttpStatusCode;
|
|
9
|
+
exceptionFactory?: (error: string) => any;
|
|
10
|
+
/**
|
|
11
|
+
* Defines if file parameter is required.
|
|
12
|
+
* @default true
|
|
13
|
+
*/
|
|
14
|
+
fileIsRequired?: boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FileTypeValidatorOptions } from './file-type.validator';
|
|
2
|
+
import { FileValidator } from './file-validator.interface';
|
|
3
|
+
import { MaxFileSizeValidatorOptions } from './max-file-size.validator';
|
|
4
|
+
import { ParseFileOptions } from './parse-file-options.interface';
|
|
5
|
+
import { ParseFilePipe } from './parse-file.pipe';
|
|
6
|
+
/**
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
export declare class ParseFilePipeBuilder {
|
|
10
|
+
private validators;
|
|
11
|
+
addMaxSizeValidator(options: MaxFileSizeValidatorOptions): this;
|
|
12
|
+
addFileTypeValidator(options: FileTypeValidatorOptions): this;
|
|
13
|
+
addValidator(validator: FileValidator): this;
|
|
14
|
+
build(additionalOptions?: Omit<ParseFileOptions, 'validators'>): ParseFilePipe;
|
|
15
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseFilePipeBuilder = void 0;
|
|
4
|
+
const file_type_validator_1 = require("./file-type.validator");
|
|
5
|
+
const max_file_size_validator_1 = require("./max-file-size.validator");
|
|
6
|
+
const parse_file_pipe_1 = require("./parse-file.pipe");
|
|
7
|
+
/**
|
|
8
|
+
* @publicApi
|
|
9
|
+
*/
|
|
10
|
+
class ParseFilePipeBuilder {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.validators = [];
|
|
13
|
+
}
|
|
14
|
+
addMaxSizeValidator(options) {
|
|
15
|
+
return this.addValidator(new max_file_size_validator_1.MaxFileSizeValidator(options));
|
|
16
|
+
}
|
|
17
|
+
addFileTypeValidator(options) {
|
|
18
|
+
return this.addValidator(new file_type_validator_1.FileTypeValidator(options));
|
|
19
|
+
}
|
|
20
|
+
addValidator(validator) {
|
|
21
|
+
this.validators.push(validator);
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
build(additionalOptions) {
|
|
25
|
+
const parseFilePipe = new parse_file_pipe_1.ParseFilePipe({
|
|
26
|
+
...additionalOptions,
|
|
27
|
+
validators: this.validators,
|
|
28
|
+
});
|
|
29
|
+
this.validators = [];
|
|
30
|
+
return parseFilePipe;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ParseFilePipeBuilder = ParseFilePipeBuilder;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PipeTransform } from '../../interfaces/features/pipe-transform.interface';
|
|
2
|
+
import { FileValidator } from './file-validator.interface';
|
|
3
|
+
import { ParseFileOptions } from './parse-file-options.interface';
|
|
4
|
+
/**
|
|
5
|
+
* Defines the built-in ParseFile Pipe. This pipe can be used to validate incoming files
|
|
6
|
+
* with `@UploadedFile()` decorator. You can use either other specific built-in validators
|
|
7
|
+
* or provide one of your own, simply implementing it through FileValidator interface
|
|
8
|
+
* and adding it to ParseFilePipe's constructor.
|
|
9
|
+
*
|
|
10
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
11
|
+
*
|
|
12
|
+
* @publicApi
|
|
13
|
+
*/
|
|
14
|
+
export declare class ParseFilePipe implements PipeTransform<any> {
|
|
15
|
+
protected exceptionFactory: (error: string) => any;
|
|
16
|
+
private readonly validators;
|
|
17
|
+
private readonly fileIsRequired;
|
|
18
|
+
constructor(options?: ParseFileOptions);
|
|
19
|
+
transform(value: any): Promise<any>;
|
|
20
|
+
private validateFilesOrFile;
|
|
21
|
+
private thereAreNoFilesIn;
|
|
22
|
+
protected validate(file: any): Promise<any>;
|
|
23
|
+
private validateOrThrow;
|
|
24
|
+
/**
|
|
25
|
+
* @returns list of validators used in this pipe.
|
|
26
|
+
*/
|
|
27
|
+
getValidators(): FileValidator<Record<string, any>, import("./interfaces").IFile>[];
|
|
28
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParseFilePipe = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("../../decorators/core");
|
|
6
|
+
const enums_1 = require("../../enums");
|
|
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 ParseFile Pipe. This pipe can be used to validate incoming files
|
|
11
|
+
* with `@UploadedFile()` decorator. You can use either other specific built-in validators
|
|
12
|
+
* or provide one of your own, simply implementing it through FileValidator interface
|
|
13
|
+
* and adding it to ParseFilePipe's constructor.
|
|
14
|
+
*
|
|
15
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
16
|
+
*
|
|
17
|
+
* @publicApi
|
|
18
|
+
*/
|
|
19
|
+
let ParseFilePipe = class ParseFilePipe {
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
const { exceptionFactory, errorHttpStatusCode = enums_1.HttpStatus.BAD_REQUEST, validators = [], fileIsRequired, } = options;
|
|
22
|
+
this.exceptionFactory =
|
|
23
|
+
exceptionFactory ||
|
|
24
|
+
(error => new http_error_by_code_util_1.HttpErrorByCode[errorHttpStatusCode](error));
|
|
25
|
+
this.validators = validators;
|
|
26
|
+
this.fileIsRequired = fileIsRequired ?? true;
|
|
27
|
+
}
|
|
28
|
+
async transform(value) {
|
|
29
|
+
const areThereAnyFilesIn = this.thereAreNoFilesIn(value);
|
|
30
|
+
if (areThereAnyFilesIn && this.fileIsRequired) {
|
|
31
|
+
throw this.exceptionFactory('File is required');
|
|
32
|
+
}
|
|
33
|
+
if (!areThereAnyFilesIn && this.validators.length) {
|
|
34
|
+
await this.validateFilesOrFile(value);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
async validateFilesOrFile(value) {
|
|
39
|
+
if (Array.isArray(value)) {
|
|
40
|
+
await Promise.all(value.map(f => this.validate(f)));
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
await this.validate(value);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
thereAreNoFilesIn(value) {
|
|
47
|
+
const isEmptyArray = Array.isArray(value) && (0, shared_utils_1.isEmpty)(value);
|
|
48
|
+
const isEmptyObject = (0, shared_utils_1.isObject)(value) && (0, shared_utils_1.isEmpty)(Object.keys(value));
|
|
49
|
+
return (0, shared_utils_1.isUndefined)(value) || isEmptyArray || isEmptyObject;
|
|
50
|
+
}
|
|
51
|
+
async validate(file) {
|
|
52
|
+
for (const validator of this.validators) {
|
|
53
|
+
await this.validateOrThrow(file, validator);
|
|
54
|
+
}
|
|
55
|
+
return file;
|
|
56
|
+
}
|
|
57
|
+
async validateOrThrow(file, validator) {
|
|
58
|
+
const isValid = await validator.isValid(file);
|
|
59
|
+
if (!isValid) {
|
|
60
|
+
const errorMessage = validator.buildErrorMessage(file);
|
|
61
|
+
throw this.exceptionFactory(errorMessage);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @returns list of validators used in this pipe.
|
|
66
|
+
*/
|
|
67
|
+
getValidators() {
|
|
68
|
+
return this.validators;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.ParseFilePipe = ParseFilePipe;
|
|
72
|
+
exports.ParseFilePipe = ParseFilePipe = tslib_1.__decorate([
|
|
73
|
+
(0, core_1.Injectable)(),
|
|
74
|
+
tslib_1.__param(0, (0, core_1.Optional)()),
|
|
75
|
+
tslib_1.__metadata("design:paramtypes", [Object])
|
|
76
|
+
], ParseFilePipe);
|
package/pipes/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './default-value.pipe';
|
|
2
|
+
export * from './file';
|
|
3
|
+
export * from './parse-array.pipe';
|
|
4
|
+
export * from './parse-bool.pipe';
|
|
5
|
+
export * from './parse-date.pipe';
|
|
6
|
+
export * from './parse-enum.pipe';
|
|
7
|
+
export * from './parse-float.pipe';
|
|
8
|
+
export * from './parse-int.pipe';
|
|
9
|
+
export * from './parse-uuid.pipe';
|
|
10
|
+
export * from './validation.pipe';
|
package/pipes/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./default-value.pipe"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./file"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./parse-array.pipe"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./parse-bool.pipe"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./parse-date.pipe"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./parse-enum.pipe"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./parse-float.pipe"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./parse-int.pipe"), exports);
|
|
12
|
+
tslib_1.__exportStar(require("./parse-uuid.pipe"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./validation.pipe"), exports);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Type } from '../interfaces';
|
|
2
|
+
import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface';
|
|
3
|
+
import { ValidationPipe, ValidationPipeOptions } from './validation.pipe';
|
|
4
|
+
/**
|
|
5
|
+
* @publicApi
|
|
6
|
+
*/
|
|
7
|
+
export interface ParseArrayOptions extends Omit<ValidationPipeOptions, 'transform' | 'validateCustomDecorators' | 'exceptionFactory'> {
|
|
8
|
+
/**
|
|
9
|
+
* Type for items to be converted into
|
|
10
|
+
*/
|
|
11
|
+
items?: Type<unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Items separator to split string by
|
|
14
|
+
* @default ','
|
|
15
|
+
*/
|
|
16
|
+
separator?: string;
|
|
17
|
+
/**
|
|
18
|
+
* If true, the pipe will return null or undefined if the value is not provided
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
optional?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* A factory function that returns an exception object to be thrown
|
|
24
|
+
* if validation fails.
|
|
25
|
+
* @param error Error message or object
|
|
26
|
+
* @returns The exception object
|
|
27
|
+
*/
|
|
28
|
+
exceptionFactory?: (error: any) => any;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Defines the built-in ParseArray Pipe
|
|
32
|
+
*
|
|
33
|
+
* @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
|
|
34
|
+
*
|
|
35
|
+
* @publicApi
|
|
36
|
+
*/
|
|
37
|
+
export declare class ParseArrayPipe implements PipeTransform {
|
|
38
|
+
protected readonly options: ParseArrayOptions;
|
|
39
|
+
protected readonly validationPipe: ValidationPipe;
|
|
40
|
+
protected exceptionFactory: (error: string) => any;
|
|
41
|
+
constructor(options?: ParseArrayOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Method that accesses and performs optional transformation on argument for
|
|
44
|
+
* in-flight requests.
|
|
45
|
+
*
|
|
46
|
+
* @param value currently processed route argument
|
|
47
|
+
* @param metadata contains metadata about the currently processed route argument
|
|
48
|
+
*/
|
|
49
|
+
transform(value: any, metadata: ArgumentMetadata): Promise<any>;
|
|
50
|
+
protected isExpectedTypePrimitive(): boolean;
|
|
51
|
+
protected validatePrimitive(originalValue: any, index?: number): any;
|
|
52
|
+
}
|