From 439231ed61ccefe22c336adb6cf2cb0fb68116a1 Mon Sep 17 00:00:00 2001 From: sapenlei <2503404258gl@gmail.com> Date: Tue, 3 Dec 2024 09:15:06 +0800 Subject: [PATCH 1/2] chore(common): Add type declaration for RawBody decorator with pipes Closes #14254 --- .../decorators/http/route-params.decorator.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/packages/common/decorators/http/route-params.decorator.ts b/packages/common/decorators/http/route-params.decorator.ts index b14e63cee9d..340f496c67a 100644 --- a/packages/common/decorators/http/route-params.decorator.ts +++ b/packages/common/decorators/http/route-params.decorator.ts @@ -508,22 +508,6 @@ export function Body( ); } -/** - * Route handler parameter decorator. Extracts the `rawBody` Buffer - * property from the `req` object and populates the decorated parameter with that value. - * - * For example: - * ```typescript - * async create(@RawBody() rawBody: Buffer | undefined) - * ``` - * - * @see [Request object](https://docs.nestjs.com/controllers#request-object) - * @see [Raw body](https://docs.nestjs.com/faq/raw-body) - * - * @publicApi - */ -export function RawBody(): ParameterDecorator; - /** * Route handler parameter decorator. Extracts the `rawBody` Buffer * property from the `req` object and populates the decorated parameter with that value. From 59bf615d29524344bc62848ffbc87314d8b0580a Mon Sep 17 00:00:00 2001 From: sapenlei <2503404258gl@gmail.com> Date: Tue, 3 Dec 2024 17:53:30 +0800 Subject: [PATCH 2/2] refactor(common): Add type declaration for RawBody decorator with pipes --- .../decorators/http/route-params.decorator.ts | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/packages/common/decorators/http/route-params.decorator.ts b/packages/common/decorators/http/route-params.decorator.ts index 340f496c67a..4c11fc5ed25 100644 --- a/packages/common/decorators/http/route-params.decorator.ts +++ b/packages/common/decorators/http/route-params.decorator.ts @@ -508,6 +508,48 @@ export function Body( ); } +/** + * Route handler parameter decorator. Extracts the `rawBody` Buffer + * property from the `req` object and populates the decorated parameter with that value. + * + * For example: + * ```typescript + * async create(@RawBody() rawBody: Buffer | undefined) + * ``` + * + * @see [Request object](https://docs.nestjs.com/controllers#request-object) + * @see [Raw body](https://docs.nestjs.com/faq/raw-body) + * + * @publicApi + */ +export function RawBody(): ParameterDecorator; + +/** + * Route handler parameter decorator. Extracts the `rawBody` Buffer + * property from the `req` object and populates the decorated parameter with that value. + * Also applies pipes to the bound rawBody parameter. + * + * For example: + * ```typescript + * async create(@RawBody(new ValidationPipe()) rawBody: Buffer) + * ``` + * + * @param pipes one or more pipes - either instances or classes - to apply to + * the bound body parameter. + * + * @see [Request object](https://docs.nestjs.com/controllers#request-object) + * @see [Raw body](https://docs.nestjs.com/faq/raw-body) + * @see [Working with pipes](https://docs.nestjs.com/custom-decorators#working-with-pipes) + * + * @publicApi + */ +export function RawBody( + ...pipes: ( + | Type> + | PipeTransform + )[] +): ParameterDecorator; + /** * Route handler parameter decorator. Extracts the `rawBody` Buffer * property from the `req` object and populates the decorated parameter with that value.