@nestjs/common 10.4.11 → 10.4.13

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.
@@ -302,6 +302,26 @@ export declare function Body(property: string, ...pipes: (Type<PipeTransform> |
302
302
  * @publicApi
303
303
  */
304
304
  export declare function RawBody(): ParameterDecorator;
305
+ /**
306
+ * Route handler parameter decorator. Extracts the `rawBody` Buffer
307
+ * property from the `req` object and populates the decorated parameter with that value.
308
+ * Also applies pipes to the bound rawBody parameter.
309
+ *
310
+ * For example:
311
+ * ```typescript
312
+ * async create(@RawBody(new ValidationPipe()) rawBody: Buffer)
313
+ * ```
314
+ *
315
+ * @param pipes one or more pipes - either instances or classes - to apply to
316
+ * the bound body parameter.
317
+ *
318
+ * @see [Request object](https://docs.nestjs.com/controllers#request-object)
319
+ * @see [Raw body](https://docs.nestjs.com/faq/raw-body)
320
+ * @see [Working with pipes](https://docs.nestjs.com/custom-decorators#working-with-pipes)
321
+ *
322
+ * @publicApi
323
+ */
324
+ export declare function RawBody(...pipes: (Type<PipeTransform<Buffer | undefined>> | PipeTransform<Buffer | undefined>)[]): ParameterDecorator;
305
325
  /**
306
326
  * Route handler parameter decorator. Extracts the `params`
307
327
  * property from the `req` object and populates the decorated
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/common",
3
- "version": "10.4.11",
3
+ "version": "10.4.13",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@common)",
5
5
  "author": "Kamil Mysliwiec",
6
6
  "homepage": "https://nestjs.com",
@@ -19,7 +19,7 @@
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
21
  "iterare": "1.2.1",
22
- "tslib": "2.7.0",
22
+ "tslib": "2.8.1",
23
23
  "uid": "2.0.2"
24
24
  },
25
25
  "peerDependencies": {
@@ -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);
@@ -131,6 +131,9 @@ let ValidationPipe = class ValidationPipe {
131
131
  if (metatype === Number) {
132
132
  return +value;
133
133
  }
134
+ if (metatype === String && !(0, shared_utils_1.isUndefined)(value)) {
135
+ return String(value);
136
+ }
134
137
  return value;
135
138
  }
136
139
  toEmptyIfNil(value, metatype) {