UNPKG

@nestjs/common

Version:

Decorators, pipes, exceptions and utilities for NestJS applications: @Controller(), @Injectable(), @Body(), ValidationPipe, HttpException and more.

82 lines (81 loc) • 3.27 kB
import { Type } from '../interfaces/index.js'; import { ArgumentMetadata, PipeTransform } from '../interfaces/features/pipe-transform.interface.js'; import { ValidationPipe, ValidationPipeOptions } from './validation.pipe.js'; /** * @publicApi */ export interface ParseArrayPipeOptions extends Omit<ValidationPipeOptions, 'transform' | 'validateCustomDecorators' | 'exceptionFactory'> { /** * Type for items to be converted into */ items?: Type<unknown>; /** * Items separator to split string by * @default ',' */ separator?: string; /** * If true, the pipe will return null or undefined if the value is not provided * @default false */ optional?: boolean; /** * Maximum total length, in characters, of the messages in an error response * of the built-in exception factory. With `stopAtFirstError: false`, the * messages of all the invalid items count together: once they reach it, * the next invalid item ends the validation, the items after it are not * validated, and a last message says that errors were left out. Set it to * `Infinity` to lift the limit. * * @default 1_000_000 */ maxErrorMessagesLength?: number; /** * A factory function that returns an exception object to be thrown * if validation fails. * @param error Error message or object * @returns The exception object */ exceptionFactory?: (error: any) => any; } /** @deprecated Use `ParseArrayPipeOptions` instead. */ export type ParseArrayOptions = ParseArrayPipeOptions; /** * Defines the built-in ParseArray Pipe * * @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes) * * @publicApi */ export declare class ParseArrayPipe implements PipeTransform { protected readonly options: ParseArrayPipeOptions; protected readonly validationPipe: ValidationPipe; protected exceptionFactory: (error: string) => any; /** * The exceptions created by a custom exception factory. Such an exception * can be an `Error` that is not an `HttpException` (e.g. an `RpcException` * or a `WsException`), and it is told apart this way from an error thrown * by the code that validates an item. */ private readonly createdExceptions; constructor(options?: ParseArrayPipeOptions); /** * Method that accesses and performs optional transformation on argument for * in-flight requests. * * @param value currently processed route argument * @param metadata contains metadata about the currently processed route argument */ transform(value: unknown, metadata: ArgumentMetadata): Promise<any>; private trackCreatedException; /** * The messages of an exception that a custom exception factory created and * that is not an `HttpException`: the errors it holds when they are a list * (e.g. `new RpcException(errors)` for the validation errors of an item, * whose message is only "Rpc Exception"), or else its message. */ private getCreatedExceptionMessages; protected isExpectedTypePrimitive(): boolean; protected validatePrimitive(originalValue: any, index?: number): any; protected isNumeric(value: unknown): boolean; }