UNPKG

@nestjs/websockets

Version:

Nest - modern, fast, powerful node.js web framework (@websockets)

72 lines (71 loc) 2.53 kB
import type { ParameterDecoratorOptions, PipeTransform, Type } from '@nestjs/common'; /** * WebSockets message body parameter decorator. * * @publicApi */ export declare function MessageBody(): ParameterDecorator; /** * WebSockets message body parameter decorator. * * Example: * ```typescript * create(@MessageBody(new ValidationPipe()) createDto: CreateCatDto) * ``` * @param pipes one or more pipes - either instances or classes - to apply to * the bound parameter. * * @publicApi */ export declare function MessageBody(...pipes: (Type<PipeTransform> | PipeTransform)[]): ParameterDecorator; /** * WebSockets message body parameter decorator. Extracts a property from the * message payload object. May also apply pipes to the bound parameter. * * For example, extracting all params: * ```typescript * findMany(@MessageBody() ids: string[]) * ``` * * For example, extracting a single param: * ```typescript * create(@MessageBody('data') createDto: { data: string }) * ``` * * For example, extracting a single param with pipe: * ```typescript * create(@MessageBody('data', new ValidationPipe()) createDto: { data: string }) * ``` * @param propertyKey name of single property to extract from the message payload * @param pipes one or more pipes - either instances or classes - to apply to * the bound parameter. * * @publicApi */ export declare function MessageBody(propertyKey: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): ParameterDecorator; /** * WebSockets message body parameter decorator. Extracts a property from the * message payload object with additional options. * * For example, extracting a single param with schema: * ```typescript * create(@MessageBody('data', { schema: z.string() }) data: string) * ``` * @param propertyKey name of single property to extract from the message payload * @param options options object containing additional configuration for the decorator, such as pipes and schema * * @publicApi */ export declare function MessageBody(propertyKey: string, options: ParameterDecoratorOptions): ParameterDecorator; /** * WebSockets message body parameter decorator. * * For example, passing schema as options: * ```typescript * create(@MessageBody({ schema: z.object({ data: z.string() }) }) body) * ``` * @param options options object containing additional configuration for the decorator, such as pipes and schema * * @publicApi */ export declare function MessageBody(options: ParameterDecoratorOptions): ParameterDecorator;