@nestjs/common 10.4.8 → 10.4.10

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.
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Exception that represents an intrinsic error in the application.
3
+ * When thrown, the default exception filter will not log the error message.
4
+ *
5
+ * @publicApi
6
+ */
7
+ export declare class IntrinsicException extends Error {
8
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntrinsicException = void 0;
4
+ /**
5
+ * Exception that represents an intrinsic error in the application.
6
+ * When thrown, the default exception filter will not log the error message.
7
+ *
8
+ * @publicApi
9
+ */
10
+ class IntrinsicException extends Error {
11
+ }
12
+ exports.IntrinsicException = IntrinsicException;
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInjectionProviders = getInjectionProviders;
4
+ const shared_utils_1 = require("../../utils/shared.utils");
4
5
  /**
5
- * check if x is OptionalFactoryDependency, based on prototype presence
6
- * (to avoid classes with a static 'token' field)
7
- * @param x
8
- * @returns x is OptionalFactoryDependency
6
+ * @param value
7
+ * @returns `true` if value is `OptionalFactoryDependency`
9
8
  */
10
- function isOptionalFactoryDependency(x) {
11
- return !!(x?.token && !x?.prototype);
9
+ function isOptionalFactoryDependency(value) {
10
+ return (!(0, shared_utils_1.isUndefined)(value.token) &&
11
+ !(0, shared_utils_1.isUndefined)(value.optional) &&
12
+ !value.prototype);
12
13
  }
13
14
  const mapInjectToTokens = (t) => isOptionalFactoryDependency(t) ? t.token : t;
14
15
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "10.4.8",
3
+ "version": "10.4.10",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -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);
@@ -41,7 +41,7 @@ export declare class ValidationPipe implements PipeTransform<any> {
41
41
  createExceptionFactory(): (validationErrors?: ValidationError[]) => unknown;
42
42
  protected toValidate(metadata: ArgumentMetadata): boolean;
43
43
  protected transformPrimitive(value: any, metadata: ArgumentMetadata): any;
44
- protected toEmptyIfNil<T = any, R = any>(value: T): R | {};
44
+ protected toEmptyIfNil<T = any, R = any>(value: T, metatype: Type<unknown> | object): R | {};
45
45
  protected stripProtoKeys(value: any): void;
46
46
  protected isPrimitive(value: unknown): boolean;
47
47
  protected validate(object: object, validatorOptions?: ValidatorOptions): Promise<ValidationError[]> | ValidationError[];
@@ -53,7 +53,7 @@ let ValidationPipe = class ValidationPipe {
53
53
  : value;
54
54
  }
55
55
  const originalValue = value;
56
- value = this.toEmptyIfNil(value);
56
+ value = this.toEmptyIfNil(value, metatype);
57
57
  const isNil = value !== originalValue;
58
58
  const isPrimitive = this.isPrimitive(value);
59
59
  this.stripProtoKeys(value);
@@ -133,8 +133,19 @@ let ValidationPipe = class ValidationPipe {
133
133
  }
134
134
  return value;
135
135
  }
136
- toEmptyIfNil(value) {
137
- return (0, shared_utils_1.isNil)(value) ? {} : value;
136
+ toEmptyIfNil(value, metatype) {
137
+ if (!(0, shared_utils_1.isNil)(value)) {
138
+ return value;
139
+ }
140
+ if (typeof metatype === 'function' ||
141
+ (metatype && 'prototype' in metatype && metatype.prototype?.constructor)) {
142
+ return {};
143
+ }
144
+ // Builder like SWC require empty string to be returned instead of an empty object
145
+ // when the value is nil and the metatype is not a class instance, but a plain object (enum, for example).
146
+ // Otherwise, the error will be thrown.
147
+ // @see https://github.com/nestjs/nest/issues/12680
148
+ return '';
138
149
  }
139
150
  stripProtoKeys(value) {
140
151
  if (value == null ||