UNPKG

1.61 kBTypeScriptView Raw
1import { ArgumentMetadata } from '../index';
2import { PipeTransform } from '../interfaces/features/pipe-transform.interface';
3import { ErrorHttpStatusCode } from '../utils/http-error-by-code.util';
4/**
5 * @publicApi
6 */
7export interface ParseEnumPipeOptions {
8 /**
9 * If true, the pipe will return null or undefined if the value is not provided
10 * @default false
11 */
12 optional?: boolean;
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/**
26 * Defines the built-in ParseEnum Pipe
27 *
28 * @see [Built-in Pipes](https://docs.nestjs.com/pipes#built-in-pipes)
29 *
30 * @publicApi
31 */
32export declare class ParseEnumPipe<T = any> implements PipeTransform<T> {
33 protected readonly enumType: T;
34 protected readonly options?: ParseEnumPipeOptions | undefined;
35 protected exceptionFactory: (error: string) => any;
36 constructor(enumType: T, options?: ParseEnumPipeOptions | undefined);
37 /**
38 * Method that accesses and performs optional transformation on argument for
39 * in-flight requests.
40 *
41 * @param value currently processed route argument
42 * @param metadata contains metadata about the currently processed route argument
43 */
44 transform(value: T, metadata: ArgumentMetadata): Promise<T>;
45 protected isEnum(value: T): boolean;
46}