import { ZodError, ZodTypeAny, z, ZodEffects, ZodObject, ZodType, ZodSchema } from 'zod'; import { Observable } from 'rxjs'; import * as _nestjs_swagger_dist_interfaces_open_api_spec_interface_js from '@nestjs/swagger/dist/interfaces/open-api-spec.interface.js'; import { PipeTransform, ArgumentMetadata, DynamicModule, INestApplication, ModuleMetadata } from '@nestjs/common'; import { OpenAPIRegistry } from '@asteasolutions/zod-to-openapi'; import { OpenAPIObject, SwaggerCustomOptions } from '@nestjs/swagger'; declare abstract class SmpAbstractZodDto { static smpMapError?: (error: ZodError) => unknown; static zodSchema: ZodTypeAny; static fromPlain>>(this: T, input: U): InstanceType; static fromPlain$>>(this: T, input: U): Observable>; static isSmpZodDto(): this is SmpAbstractZodDto; /** * A dynamic class generator. You can either use the returned value or extend if you want to override the dynamic name * @example * */ static toGenericResponseDto(this: T): { new (): {}; smpMapError?: ((error: ZodError) => unknown) | undefined; fromPlain: typeof SmpAbstractZodDto.fromPlain; fromPlain$: typeof SmpAbstractZodDto.fromPlain$; isSmpZodDto: typeof SmpAbstractZodDto.isSmpZodDto; toGenericResponseDto: typeof SmpAbstractZodDto.toGenericResponseDto; zodSchema: z.ZodObject<{ messages: z.ZodTypeAny; } & { data: T["zodSchema"]; }, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks, any> extends infer T_1 ? { [k in keyof T_1]: z.objectUtil.addQuestionMarks, any>[k]; } : never, z.baseObjectInputType<{ messages: z.ZodTypeAny; } & { data: T["zodSchema"]; }> extends infer T_2 ? { [k_1 in keyof T_2]: z.baseObjectInputType<{ messages: z.ZodTypeAny; } & { data: T["zodSchema"]; }>[k_1]; } : never>; }; toPlain(): any; toString(): string; } interface SmpZodValidationSchemas { body: typeof SmpAbstractZodDto | ZodTypeAny | Record; query: typeof SmpAbstractZodDto | ZodEffects> | ZodObject | Record; param: typeof SmpAbstractZodDto | ZodEffects> | ZodObject | Record; } /** * Use this if you want just to validate your request and get the parsed items in your standard NestJS entities: @Body, @Param, @Query * while ALSO managing @nestjs/swagger document creation. * If you just want the validation, just use @SmpUseZodValidationPipe * @example * @SmpZodApi({body: someZodSchema}) */ declare const SmpZodApi: (schemas: Partial, opts?: { validate?: boolean; }) => (target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor) => void; /** * Attach a DTO-specific Zod error mapper. * Useful when a global SmpZodValidationPipe is active but one DTO needs a custom error shape. */ declare function SmpZodMapError(mapError: (error: ZodError) => unknown): (target: T) => void; type SmpGeneratedZodDto = Omit & { zodSchema: T; } & (new () => z.infer & Omit & { toPlain: () => z.output; }); /** * A dynamic class generator. * Suggested usage: extend! Don't use the returned class as is for the best experience * @example * ```ts * const fooSchema = z.object({ * firstName: z.string(), * lastName: z.string(), * age: z.number().optional() * }); * * class SmpFooDto extends smpGenerateSmpZodDto(fooSchema) { * foo: string = "foo"; * } * * class MyController { * someMethod(body: SmpFooDto) { * body.firstName // works * body.foo // works * } * } * ``` * @param schema */ declare function smpGenerateSmpZodDto(schema: T): SmpGeneratedZodDto; interface SmpZodValidationPipeOptions { mapError?: (error: ZodError) => any; } /** * Use this if you want just to validate your request and get the parsed items in your standard NestJS entities: @Body, @Param, @Query */ declare function SmpUseZodValidationPipe(schemas: Partial, options?: SmpZodValidationPipeOptions): (target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor) => void; declare class SmpZodOpenApiUtils { static getDefaultSchemaName(schema: ZodTypeAny, fallback?: string): string; static getDescription(schema: ZodTypeAny): string | undefined; static getOpenApiRefId(schema: ZodTypeAny): string | undefined; static isZodEffects(input: ZodTypeAny): input is ZodEffects; static toZodObject(input: SmpZodValidationSchemas["param"] | SmpZodValidationSchemas["body"] | SmpZodValidationSchemas["query"]): ZodType; static unwrap(schema: ZodType): ZodType; static unwrapEffects(schema: ZodType): ZodType; protected static _getOpenApiRefId(schema: ZodTypeAny): string | undefined; protected static _hash(input: string): string; } declare function smpZodToOpenApiRef(schema: ZodSchema, name?: string): { $ref: string; }; declare function smpZodToOpenApi(schema: ZodSchema, name?: string): Record; /** * Use this if you want just to validate your request and get the parsed items in your standard NestJS entities: @Body, @Param, @Query * You can use SmpUseZodValidationPipe, but you can also use this in combination of @UsePipe * @example * @UsePipe(new SmpZodValidationPipe({body: someZodSchema})) */ declare class SmpZodValidationPipe implements PipeTransform { protected readonly _schemas?: Partial | undefined; protected readonly _mapError?: (error: ZodError) => any; constructor(_schemas?: Partial | undefined, options?: SmpZodValidationPipeOptions); transform(value: any, metadata: ArgumentMetadata): Promise; protected _getMapError(metadata: ArgumentMetadata): ((error: ZodError) => unknown) | undefined; protected _validate(value: any, metadata: ArgumentMetadata, selectedSchemas: Partial[keyof SmpZodValidationSchemas]): Promise; } declare const smpZodOpenApiModuleFeatures: { SmpZodValidationPipe: { providers: { provide: string; useFactory: () => SmpZodValidationPipe; }[]; }; }; interface SmpZodOpenApiModuleOpts { features?: (keyof typeof smpZodOpenApiModuleFeatures)[]; } type SmpZodOpenApiSwaggerOptions = Pick & { path?: string; }; interface SmpGenerateOpenApiDocOptions { contact?: { name: string; url: string; email: string; }; description?: string; externalDoc?: OpenAPIObject["externalDocs"]; servers?: OpenAPIObject["servers"]; title?: string; version?: string; } declare class SmpZodOpenApiModule { static get REGISTRY(): Readonly; private static _initialized; private static _registry; private static _zodPatched; constructor(); static forRoot(config?: Partial): DynamicModule; static forRootAsync(factory: () => Promise>): Promise; static generateOpenApiDoc(app: INestApplication, opts?: SmpGenerateOpenApiDocOptions): OpenAPIObject; static patchZodWithOpenApi(): void; static setupSwaggerUi(app: INestApplication, openApiDoc: OpenAPIObject, opts?: SmpZodOpenApiSwaggerOptions): void; protected static _getDynamicConfig(features: (keyof typeof smpZodOpenApiModuleFeatures)[]): ModuleMetadata; } export { SmpAbstractZodDto, SmpUseZodValidationPipe, SmpZodApi, SmpZodMapError, SmpZodOpenApiModule, SmpZodOpenApiUtils, SmpZodValidationPipe, type SmpZodValidationPipeOptions, type SmpZodValidationSchemas, smpGenerateSmpZodDto, smpZodToOpenApi, smpZodToOpenApiRef };