@nestjs/common 10.4.11 → 11.0.0-next.2

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.
Files changed (81) hide show
  1. package/decorators/core/exception-filters.decorator.js +1 -3
  2. package/decorators/core/inject.decorator.d.ts +2 -1
  3. package/decorators/core/use-guards.decorator.js +1 -3
  4. package/decorators/core/use-interceptors.decorator.js +1 -2
  5. package/decorators/core/use-pipes.decorator.js +1 -2
  6. package/decorators/http/create-route-param-metadata.decorator.d.ts +1 -1
  7. package/decorators/http/create-route-param-metadata.decorator.js +2 -1
  8. package/decorators/http/request-mapping.decorator.d.ts +56 -0
  9. package/decorators/http/request-mapping.decorator.js +57 -1
  10. package/decorators/http/route-params.decorator.d.ts +1 -1
  11. package/decorators/http/route-params.decorator.js +2 -1
  12. package/decorators/modules/module.decorator.js +1 -1
  13. package/enums/http-status.enum.d.ts +8 -1
  14. package/enums/http-status.enum.js +7 -0
  15. package/enums/request-method.enum.d.ts +8 -1
  16. package/enums/request-method.enum.js +7 -0
  17. package/exceptions/bad-gateway.exception.d.ts +1 -1
  18. package/exceptions/bad-request.exception.d.ts +1 -1
  19. package/exceptions/conflict.exception.d.ts +1 -1
  20. package/exceptions/forbidden.exception.d.ts +1 -1
  21. package/exceptions/gateway-timeout.exception.d.ts +1 -1
  22. package/exceptions/gone.exception.d.ts +1 -1
  23. package/exceptions/http-version-not-supported.exception.d.ts +1 -1
  24. package/exceptions/http.exception.d.ts +8 -3
  25. package/exceptions/http.exception.js +4 -4
  26. package/exceptions/im-a-teapot.exception.d.ts +1 -1
  27. package/exceptions/index.d.ts +17 -16
  28. package/exceptions/index.js +17 -16
  29. package/exceptions/internal-server-error.exception.d.ts +1 -1
  30. package/exceptions/intrinsic.exception.d.ts +8 -0
  31. package/exceptions/intrinsic.exception.js +12 -0
  32. package/exceptions/method-not-allowed.exception.d.ts +1 -1
  33. package/exceptions/misdirected.exception.d.ts +1 -1
  34. package/exceptions/not-acceptable.exception.d.ts +1 -1
  35. package/exceptions/not-found.exception.d.ts +1 -1
  36. package/exceptions/not-implemented.exception.d.ts +1 -1
  37. package/exceptions/payload-too-large.exception.d.ts +1 -1
  38. package/exceptions/precondition-failed.exception.d.ts +1 -1
  39. package/exceptions/request-timeout.exception.d.ts +1 -1
  40. package/exceptions/service-unavailable.exception.d.ts +1 -1
  41. package/exceptions/unauthorized.exception.d.ts +1 -1
  42. package/exceptions/unprocessable-entity.exception.d.ts +1 -1
  43. package/exceptions/unsupported-media-type.exception.d.ts +1 -1
  44. package/file-stream/streamable-file.d.ts +3 -3
  45. package/file-stream/streamable-file.js +2 -2
  46. package/interfaces/external/transformer-package.interface.d.ts +1 -1
  47. package/interfaces/features/custom-route-param-factory.interface.d.ts +2 -1
  48. package/interfaces/http/http-exception-body.interface.d.ts +1 -1
  49. package/interfaces/http/http-server.interface.d.ts +15 -0
  50. package/interfaces/middleware/nest-middleware.interface.d.ts +1 -1
  51. package/interfaces/modules/module-metadata.interface.d.ts +1 -1
  52. package/interfaces/nest-application-context-options.interface.d.ts +8 -0
  53. package/interfaces/nest-application-context.interface.d.ts +3 -1
  54. package/interfaces/nest-microservice.interface.d.ts +25 -7
  55. package/module-utils/configurable-module.builder.js +4 -3
  56. package/module-utils/utils/get-injection-providers.util.d.ts +1 -1
  57. package/package.json +1 -1
  58. package/pipes/file/file-type.validator.d.ts +1 -1
  59. package/pipes/file/file-type.validator.js +4 -1
  60. package/pipes/file/max-file-size.validator.d.ts +1 -1
  61. package/pipes/file/max-file-size.validator.js +4 -1
  62. package/pipes/index.d.ts +4 -3
  63. package/pipes/index.js +4 -3
  64. package/pipes/parse-array.pipe.d.ts +17 -0
  65. package/pipes/parse-array.pipe.js +3 -1
  66. package/pipes/parse-bool.pipe.d.ts +15 -2
  67. package/pipes/parse-date.pipe.d.ts +37 -0
  68. package/pipes/parse-date.pipe.js +42 -0
  69. package/pipes/parse-enum.pipe.d.ts +15 -2
  70. package/pipes/parse-float.pipe.d.ts +15 -2
  71. package/pipes/parse-int.pipe.d.ts +15 -2
  72. package/pipes/parse-uuid.pipe.d.ts +18 -2
  73. package/pipes/validation.pipe.d.ts +3 -3
  74. package/pipes/validation.pipe.js +7 -1
  75. package/serializer/class-serializer.interceptor.js +1 -1
  76. package/services/console-logger.service.d.ts +95 -4
  77. package/services/console-logger.service.js +111 -16
  78. package/services/logger.service.d.ts +1 -1
  79. package/services/logger.service.js +2 -2
  80. package/utils/merge-with-values.util.js +1 -0
  81. package/utils/shared.utils.js +0 -1
@@ -31,5 +31,5 @@ export declare class PreconditionFailedException extends HttpException {
31
31
  * @param objectOrError string or object describing the error condition.
32
32
  * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
34
+ constructor(objectOrError?: any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -31,5 +31,5 @@ export declare class RequestTimeoutException extends HttpException {
31
31
  * @param objectOrError string or object describing the error condition.
32
32
  * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
34
+ constructor(objectOrError?: any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -31,5 +31,5 @@ export declare class ServiceUnavailableException extends HttpException {
31
31
  * @param objectOrError string or object describing the error condition.
32
32
  * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
34
+ constructor(objectOrError?: any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -31,5 +31,5 @@ export declare class UnauthorizedException extends HttpException {
31
31
  * @param objectOrError string or object describing the error condition.
32
32
  * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
34
+ constructor(objectOrError?: any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -31,5 +31,5 @@ export declare class UnprocessableEntityException extends HttpException {
31
31
  * @param objectOrError string or object describing the error condition.
32
32
  * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
34
+ constructor(objectOrError?: any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -31,5 +31,5 @@ export declare class UnsupportedMediaTypeException extends HttpException {
31
31
  * @param objectOrError string or object describing the error condition.
32
32
  * @param descriptionOrOptions either a short description of the HTTP error or an options object used to provide an underlying error cause
33
33
  */
34
- constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
34
+ constructor(objectOrError?: any, descriptionOrOptions?: string | HttpExceptionOptions);
35
35
  }
@@ -1,6 +1,6 @@
1
1
  import { Readable } from 'stream';
2
- import { StreamableFileOptions, StreamableHandlerResponse } from './interfaces';
3
2
  import { Logger } from '../services';
3
+ import { StreamableFileOptions, StreamableHandlerResponse } from './interfaces';
4
4
  /**
5
5
  * @see [Streaming files](https://docs.nestjs.com/techniques/streaming-files)
6
6
  *
@@ -17,8 +17,8 @@ export declare class StreamableFile {
17
17
  getStream(): Readable;
18
18
  getHeaders(): {
19
19
  type: string;
20
- disposition: string;
21
- length: number;
20
+ disposition: string | undefined;
21
+ length: number | undefined;
22
22
  };
23
23
  get errorHandler(): (err: Error, response: StreamableHandlerResponse) => void;
24
24
  setErrorHandler(handler: (err: Error, response: StreamableHandlerResponse) => void): this;
@@ -4,8 +4,8 @@ exports.StreamableFile = void 0;
4
4
  const stream_1 = require("stream");
5
5
  const util_1 = require("util");
6
6
  const enums_1 = require("../enums");
7
- const shared_utils_1 = require("../utils/shared.utils");
8
7
  const services_1 = require("../services");
8
+ const shared_utils_1 = require("../utils/shared.utils");
9
9
  /**
10
10
  * @see [Streaming files](https://docs.nestjs.com/techniques/streaming-files)
11
11
  *
@@ -27,7 +27,7 @@ class StreamableFile {
27
27
  res.send(err.message);
28
28
  };
29
29
  this.logError = (err) => {
30
- this.logger.error(err.message, err.stack);
30
+ this.logger.error(err);
31
31
  };
32
32
  if (util_1.types.isUint8Array(bufferOrReadStream)) {
33
33
  this.stream = new stream_1.Readable();
@@ -1,6 +1,6 @@
1
1
  import { Type } from '../type.interface';
2
2
  import { ClassTransformOptions } from './class-transform-options.interface';
3
3
  export interface TransformerPackage {
4
- plainToClass<T>(cls: Type<T>, plain: unknown, options?: ClassTransformOptions): T | T[];
4
+ plainToInstance<T>(cls: Type<T>, plain: unknown, options?: ClassTransformOptions): T | T[];
5
5
  classToPlain(object: unknown, options?: ClassTransformOptions): Record<string, any> | Record<string, any>[];
6
6
  }
@@ -1,4 +1,5 @@
1
+ import { ExecutionContext } from './execution-context.interface';
1
2
  /**
2
3
  * @publicApi
3
4
  */
4
- export type CustomParamFactory<TData = any, TInput = any, TOutput = any> = (data: TData, input: TInput) => TOutput;
5
+ export type CustomParamFactory<TData = any, TOutput = any> = (data: TData, context: ExecutionContext) => TOutput;
@@ -1,4 +1,4 @@
1
- export type HttpExceptionBodyMessage = string | string[];
1
+ export type HttpExceptionBodyMessage = string | string[] | number;
2
2
  export interface HttpExceptionBody {
3
3
  message: HttpExceptionBodyMessage;
4
4
  error?: string;
@@ -20,6 +20,20 @@ export interface HttpServer<TRequest = any, TResponse = any, ServerInstance = an
20
20
  put(path: string, handler: RequestHandler<TRequest, TResponse>): any;
21
21
  patch(handler: RequestHandler<TRequest, TResponse>): any;
22
22
  patch(path: string, handler: RequestHandler<TRequest, TResponse>): any;
23
+ propfind?(handler: RequestHandler<TRequest, TResponse>): any;
24
+ propfind?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
25
+ proppatch?(handler: RequestHandler<TRequest, TResponse>): any;
26
+ proppatch?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
27
+ mkcol?(handler: RequestHandler<TRequest, TResponse>): any;
28
+ mkcol?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
29
+ copy?(handler: RequestHandler<TRequest, TResponse>): any;
30
+ copy?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
31
+ move?(handler: RequestHandler<TRequest, TResponse>): any;
32
+ move?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
33
+ lock?(handler: RequestHandler<TRequest, TResponse>): any;
34
+ lock?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
35
+ unlock?(handler: RequestHandler<TRequest, TResponse>): any;
36
+ unlock?(path: string, handler: RequestHandler<TRequest, TResponse>): any;
23
37
  all(path: string, handler: RequestHandler<TRequest, TResponse>): any;
24
38
  all(handler: RequestHandler<TRequest, TResponse>): any;
25
39
  options(handler: RequestHandler<TRequest, TResponse>): any;
@@ -53,4 +67,5 @@ export interface HttpServer<TRequest = any, TResponse = any, ServerInstance = an
53
67
  getType(): string;
54
68
  init?(): Promise<void>;
55
69
  applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): (req: TRequest, res: TResponse, next: () => void) => Function;
70
+ normalizePath?(path: string): string;
56
71
  }
@@ -4,5 +4,5 @@
4
4
  * @publicApi
5
5
  */
6
6
  export interface NestMiddleware<TRequest = any, TResponse = any> {
7
- use(req: TRequest, res: TResponse, next: (error?: Error | any) => void): any;
7
+ use(req: TRequest, res: TResponse, next: (error?: any) => void): any;
8
8
  }
@@ -30,5 +30,5 @@ export interface ModuleMetadata {
30
30
  * Optional list of the subset of providers that are provided by this module
31
31
  * and should be available in other modules which import this module.
32
32
  */
33
- exports?: Array<DynamicModule | Promise<DynamicModule> | string | symbol | Provider | ForwardReference | Abstract<any> | Function>;
33
+ exports?: Array<DynamicModule | string | symbol | Provider | ForwardReference | Abstract<any> | Function>;
34
34
  }
@@ -38,4 +38,12 @@ export declare class NestApplicationContextOptions {
38
38
  * @default false
39
39
  */
40
40
  snapshot?: boolean;
41
+ /**
42
+ * Determines what algorithm use to generate module ids.
43
+ * When set to `deep-hash`, the module id is generated based on the serialized module definition.
44
+ * When set to `reference`, each module obtains a unique id based on its reference.
45
+ *
46
+ * @default 'reference'
47
+ */
48
+ moduleIdGeneratorAlgorithm?: 'deep-hash' | 'reference';
41
49
  }
@@ -1,7 +1,9 @@
1
1
  import { ShutdownSignal } from '../enums/shutdown-signal.enum';
2
2
  import { LoggerService, LogLevel } from '../services/logger.service';
3
3
  import { DynamicModule } from './modules';
4
+ import { NestApplicationContextOptions } from './nest-application-context-options.interface';
4
5
  import { Type } from './type.interface';
6
+ export type SelectOptions = Pick<NestApplicationContextOptions, 'abortOnError'>;
5
7
  export interface GetOrResolveOptions {
6
8
  /**
7
9
  * If enabled, lookup will only be performed in the host module.
@@ -25,7 +27,7 @@ export interface INestApplicationContext {
25
27
  * Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
26
28
  * @returns {INestApplicationContext}
27
29
  */
28
- select<T>(module: Type<T> | DynamicModule): INestApplicationContext;
30
+ select<T>(module: Type<T> | DynamicModule, options?: SelectOptions): INestApplicationContext;
29
31
  /**
30
32
  * Retrieves an instance of either injectable or controller, otherwise, throws exception.
31
33
  * @returns {TResult}
@@ -1,3 +1,4 @@
1
+ import { Observable } from 'rxjs';
1
2
  import { ExceptionFilter } from './exceptions/exception-filter.interface';
2
3
  import { CanActivate } from './features/can-activate.interface';
3
4
  import { NestInterceptor } from './features/nest-interceptor.interface';
@@ -17,41 +18,58 @@ export interface INestMicroservice extends INestApplicationContext {
17
18
  */
18
19
  listen(): Promise<any>;
19
20
  /**
20
- * Register Ws Adapter which will be used inside Gateways.
21
- * Use when you want to override default `socket.io` library.
21
+ * Registers a web socket adapter that will be used for Gateways.
22
+ * Use to override the default `socket.io` library.
22
23
  *
23
24
  * @param {WebSocketAdapter} adapter
24
25
  * @returns {this}
25
26
  */
26
27
  useWebSocketAdapter(adapter: WebSocketAdapter): this;
27
28
  /**
28
- * Registers exception filters as global filters (will be used within every message pattern handler)
29
+ * Registers global exception filters (will be used for every pattern handler).
29
30
  *
30
31
  * @param {...ExceptionFilter} filters
31
32
  */
32
33
  useGlobalFilters(...filters: ExceptionFilter[]): this;
33
34
  /**
34
- * Registers pipes as global pipes (will be used within every message pattern handler)
35
+ * Registers global pipes (will be used for every pattern handler).
35
36
  *
36
37
  * @param {...PipeTransform} pipes
37
38
  */
38
39
  useGlobalPipes(...pipes: PipeTransform<any>[]): this;
39
40
  /**
40
- * Registers interceptors as global interceptors (will be used within every message pattern handler)
41
+ * Registers global interceptors (will be used for every pattern handler).
41
42
  *
42
43
  * @param {...NestInterceptor} interceptors
43
44
  */
44
45
  useGlobalInterceptors(...interceptors: NestInterceptor[]): this;
45
46
  /**
46
- * Registers guards as global guards (will be used within every message pattern handler)
47
+ * Registers global guards (will be used for every pattern handler).
47
48
  *
48
49
  * @param {...CanActivate} guards
49
50
  */
50
51
  useGlobalGuards(...guards: CanActivate[]): this;
51
52
  /**
52
- * Terminates the application
53
+ * Terminates the application.
53
54
  *
54
55
  * @returns {Promise<void>}
55
56
  */
56
57
  close(): Promise<void>;
58
+ /**
59
+ * Returns an observable that emits status changes.
60
+ *
61
+ * @returns {Observable<string>}
62
+ */
63
+ status: Observable<string>;
64
+ /**
65
+ * Registers an event listener for the given event.
66
+ * @param event Event name
67
+ * @param callback Callback to be executed when the event is emitted
68
+ */
69
+ on<EventsMap extends Record<string, Function> = Record<string, Function>, EventKey extends keyof EventsMap = keyof EventsMap, EventCallback extends EventsMap[EventKey] = EventsMap[EventKey]>(event: EventKey, callback: EventCallback): void;
70
+ /**
71
+ * Returns an instance of the underlying server/broker instance,
72
+ * or a group of servers if there are more than one.
73
+ */
74
+ unwrap<T>(): T;
57
75
  }
@@ -19,7 +19,8 @@ class ConfigurableModuleBuilder {
19
19
  this.staticMethodKey = parentBuilder.staticMethodKey;
20
20
  this.factoryClassMethodKey =
21
21
  parentBuilder.factoryClassMethodKey;
22
- this.transformModuleDefinition = parentBuilder.transformModuleDefinition;
22
+ this.transformModuleDefinition =
23
+ parentBuilder.transformModuleDefinition;
23
24
  this.extras = parentBuilder.extras;
24
25
  }
25
26
  }
@@ -96,8 +97,8 @@ class ConfigurableModuleBuilder {
96
97
  };
97
98
  }
98
99
  constructInjectionTokenString() {
99
- const moduleNameInSnakeCase = this.options.moduleName
100
- .trim()
100
+ const moduleNameInSnakeCase = this.options
101
+ .moduleName.trim()
101
102
  .split(/(?=[A-Z])/)
102
103
  .join('_')
103
104
  .toUpperCase();
@@ -1,4 +1,4 @@
1
- import { Provider, FactoryProvider } from '../../interfaces';
1
+ import { FactoryProvider, Provider } from '../../interfaces';
2
2
  /**
3
3
  *
4
4
  * @param providers List of a module's providers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "10.4.11",
3
+ "version": "11.0.0-next.2",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -15,6 +15,6 @@ export type FileTypeValidatorOptions = {
15
15
  * @publicApi
16
16
  */
17
17
  export declare class FileTypeValidator extends FileValidator<FileTypeValidatorOptions, IFile> {
18
- buildErrorMessage(): string;
18
+ buildErrorMessage(file?: IFile): string;
19
19
  isValid(file?: IFile): boolean;
20
20
  }
@@ -14,7 +14,10 @@ const file_validator_interface_1 = require("./file-validator.interface");
14
14
  * @publicApi
15
15
  */
16
16
  class FileTypeValidator extends file_validator_interface_1.FileValidator {
17
- buildErrorMessage() {
17
+ buildErrorMessage(file) {
18
+ if (file?.mimetype) {
19
+ return `Validation failed (current file type is ${file.mimetype}, expected type is ${this.validationOptions.fileType})`;
20
+ }
18
21
  return `Validation failed (expected type is ${this.validationOptions.fileType})`;
19
22
  }
20
23
  isValid(file) {
@@ -12,6 +12,6 @@ export type MaxFileSizeValidatorOptions = {
12
12
  * @publicApi
13
13
  */
14
14
  export declare class MaxFileSizeValidator extends FileValidator<MaxFileSizeValidatorOptions, IFile> {
15
- buildErrorMessage(): string;
15
+ buildErrorMessage(file?: IFile): string;
16
16
  isValid(file?: IFile): boolean;
17
17
  }
@@ -10,13 +10,16 @@ const file_validator_interface_1 = require("./file-validator.interface");
10
10
  * @publicApi
11
11
  */
12
12
  class MaxFileSizeValidator extends file_validator_interface_1.FileValidator {
13
- buildErrorMessage() {
13
+ buildErrorMessage(file) {
14
14
  if ('message' in this.validationOptions) {
15
15
  if (typeof this.validationOptions.message === 'function') {
16
16
  return this.validationOptions.message(this.validationOptions.maxSize);
17
17
  }
18
18
  return this.validationOptions.message;
19
19
  }
20
+ if (file?.size) {
21
+ return `Validation failed (current file size is ${file.size}, expected size is less than ${this.validationOptions.maxSize})`;
22
+ }
20
23
  return `Validation failed (expected size is less than ${this.validationOptions.maxSize})`;
21
24
  }
22
25
  isValid(file) {
package/pipes/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  export * from './default-value.pipe';
2
+ export * from './file';
2
3
  export * from './parse-array.pipe';
3
4
  export * from './parse-bool.pipe';
4
- export * from './parse-int.pipe';
5
- export * from './parse-float.pipe';
5
+ export * from './parse-date.pipe';
6
6
  export * from './parse-enum.pipe';
7
+ export * from './parse-float.pipe';
8
+ export * from './parse-int.pipe';
7
9
  export * from './parse-uuid.pipe';
8
10
  export * from './validation.pipe';
9
- export * from './file';
package/pipes/index.js CHANGED
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./default-value.pipe"), exports);
5
+ tslib_1.__exportStar(require("./file"), exports);
5
6
  tslib_1.__exportStar(require("./parse-array.pipe"), exports);
6
7
  tslib_1.__exportStar(require("./parse-bool.pipe"), exports);
7
- tslib_1.__exportStar(require("./parse-int.pipe"), exports);
8
- tslib_1.__exportStar(require("./parse-float.pipe"), exports);
8
+ tslib_1.__exportStar(require("./parse-date.pipe"), exports);
9
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);
10
12
  tslib_1.__exportStar(require("./parse-uuid.pipe"), exports);
11
13
  tslib_1.__exportStar(require("./validation.pipe"), exports);
12
- tslib_1.__exportStar(require("./file"), exports);
@@ -5,9 +5,26 @@ import { ValidationPipe, ValidationPipeOptions } from './validation.pipe';
5
5
  * @publicApi
6
6
  */
7
7
  export interface ParseArrayOptions extends Omit<ValidationPipeOptions, 'transform' | 'validateCustomDecorators' | 'exceptionFactory'> {
8
+ /**
9
+ * Type for items to be converted into
10
+ */
8
11
  items?: Type<unknown>;
12
+ /**
13
+ * Items separator to split string by
14
+ * @default ','
15
+ */
9
16
  separator?: string;
17
+ /**
18
+ * If true, the pipe will return null or undefined if the value is not provided
19
+ * @default false
20
+ */
10
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
+ */
11
28
  exceptionFactory?: (error: any) => any;
12
29
  }
13
30
  /**
@@ -70,7 +70,9 @@ let ParseArrayPipe = class ParseArrayPipe {
70
70
  try {
71
71
  item = JSON.parse(item);
72
72
  }
73
- catch { }
73
+ catch {
74
+ // Do nothing
75
+ }
74
76
  }
75
77
  if (isExpectedTypePrimitive) {
76
78
  return this.validatePrimitive(item, index);
@@ -4,8 +4,21 @@ import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
4
4
  * @publicApi
5
5
  */
6
6
  export interface ParseBoolPipeOptions {
7
+ /**
8
+ * The HTTP status code to be used in the response when the validation fails.
9
+ */
7
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
+ */
8
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
+ */
9
22
  optional?: boolean;
10
23
  }
11
24
  /**
@@ -16,9 +29,9 @@ export interface ParseBoolPipeOptions {
16
29
  * @publicApi
17
30
  */
18
31
  export declare class ParseBoolPipe implements PipeTransform<string | boolean, Promise<boolean>> {
19
- protected readonly options?: ParseBoolPipeOptions;
32
+ protected readonly options?: ParseBoolPipeOptions | undefined;
20
33
  protected exceptionFactory: (error: string) => any;
21
- constructor(options?: ParseBoolPipeOptions);
34
+ constructor(options?: ParseBoolPipeOptions | undefined);
22
35
  /**
23
36
  * Method that accesses and performs optional transformation on argument for
24
37
  * in-flight requests.
@@ -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);
@@ -5,8 +5,21 @@ import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
5
5
  * @publicApi
6
6
  */
7
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
+ */
8
12
  optional?: boolean;
13
+ /**
14
+ * The HTTP status code to be used in the response when the validation fails.
15
+ */
9
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
+ */
10
23
  exceptionFactory?: (error: string) => any;
11
24
  }
12
25
  /**
@@ -18,9 +31,9 @@ export interface ParseEnumPipeOptions {
18
31
  */
19
32
  export declare class ParseEnumPipe<T = any> implements PipeTransform<T> {
20
33
  protected readonly enumType: T;
21
- protected readonly options?: ParseEnumPipeOptions;
34
+ protected readonly options?: ParseEnumPipeOptions | undefined;
22
35
  protected exceptionFactory: (error: string) => any;
23
- constructor(enumType: T, options?: ParseEnumPipeOptions);
36
+ constructor(enumType: T, options?: ParseEnumPipeOptions | undefined);
24
37
  /**
25
38
  * Method that accesses and performs optional transformation on argument for
26
39
  * in-flight requests.
@@ -5,8 +5,21 @@ import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
5
5
  * @publicApi
6
6
  */
7
7
  export interface ParseFloatPipeOptions {
8
+ /**
9
+ * The HTTP status code to be used in the response when the validation fails.
10
+ */
8
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
+ */
9
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
+ */
10
23
  optional?: boolean;
11
24
  }
12
25
  /**
@@ -17,9 +30,9 @@ export interface ParseFloatPipeOptions {
17
30
  * @publicApi
18
31
  */
19
32
  export declare class ParseFloatPipe implements PipeTransform<string> {
20
- protected readonly options?: ParseFloatPipeOptions;
33
+ protected readonly options?: ParseFloatPipeOptions | undefined;
21
34
  protected exceptionFactory: (error: string) => any;
22
- constructor(options?: ParseFloatPipeOptions);
35
+ constructor(options?: ParseFloatPipeOptions | undefined);
23
36
  /**
24
37
  * Method that accesses and performs optional transformation on argument for
25
38
  * in-flight requests.
@@ -4,8 +4,21 @@ import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
4
4
  * @publicApi
5
5
  */
6
6
  export interface ParseIntPipeOptions {
7
+ /**
8
+ * The HTTP status code to be used in the response when the validation fails.
9
+ */
7
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
+ */
8
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
+ */
9
22
  optional?: boolean;
10
23
  }
11
24
  /**
@@ -16,9 +29,9 @@ export interface ParseIntPipeOptions {
16
29
  * @publicApi
17
30
  */
18
31
  export declare class ParseIntPipe implements PipeTransform<string> {
19
- protected readonly options?: ParseIntPipeOptions;
32
+ protected readonly options?: ParseIntPipeOptions | undefined;
20
33
  protected exceptionFactory: (error: string) => any;
21
- constructor(options?: ParseIntPipeOptions);
34
+ constructor(options?: ParseIntPipeOptions | undefined);
22
35
  /**
23
36
  * Method that accesses and performs optional transformation on argument for
24
37
  * in-flight requests.