import { TSchema, TypeBoxError, TObject } from '@sinclair/typebox'; import { TypeCheck } from '@sinclair/typebox/compiler'; import { ValueErrorIterator } from '@sinclair/typebox/errors'; import { ValueError, TransformDecodeCheckError, TransformEncodeCheckError } from '@sinclair/typebox/value'; import * as rxjs from 'rxjs'; import { NestInterceptor, ExecutionContext, CallHandler, PipeTransform, ArgumentMetadata } from '@nestjs/common'; /** * Thrown when a validation check fails from either validation pipe or * response interceptor. * * It provides the same properties as the underlying decode and encode errors, * except it also provide access to the compiled `Errors` iterator. */ declare class TypeBoxValidationError extends TypeBoxError { readonly schema: TSchema; readonly value: unknown; readonly error: ValueError; readonly errors: ValueErrorIterator; readonly cause: TransformDecodeCheckError | TransformEncodeCheckError; readonly type: string; readonly param?: string; constructor(err: TransformDecodeCheckError | TransformEncodeCheckError, compiler: TypeCheck, type: "query" | "body" | "response" | "param", param?: string); } /** * Thrown during validation when a schema is missing from the options object. */ declare class TypeBoxMissingSchemaError extends TypeBoxError { readonly type: string; readonly param?: string | undefined; constructor(type: string, param?: string | undefined); } type TypeBoxOpts = { /** * Provide a summary for the endpoint. */ summary?: string; /** * Provide a description for the endpoint. */ description?: string; /** * Provide a schema for the query. * * Query will be cleaned, defaulted, converted, validated and decoded. */ query?: TObject; /** * Provide a schema for the request body. * * Body will be cleaned, validated and decoded. */ body?: TSchema; /** * Provide a schema for the response. * * Response will be cleaned, validated and encoded. */ response?: TSchema; /** * Provide schemas for path params. * * You can provide a single schema for all path params or a schema for each path param. * * Path params will be converted, validated and decoded. */ params?: Record; /** * Downgrade typebox JSON schema to an openapi 3.0 compatible schema, as well as * this improves compatibility with most openapi schema renderers. * * This is only done on the schema provided to the openapi docs, the actual validation schema, * is not mutated. * * This option will be ignored if `transformSchema` is provided. * * See the `downgradeSchema` function for more information on what transformations are made. * * @default true */ downgradeSchema?: boolean; /** * Disable response validation * * Can improve performance if you are confident in the response schema. * * @default true */ validateResponse?: boolean; /** * Define which schemas are required. * * If a schema is marked as required but missing during validation, it will * throw a `TypeBoxMissingSchemaError`. * * You likely don't want to throw errors in production as users could provide values for schemas that * you don't use, and you still want the endpoint to function correctly, even if they provide query * params for an endpoint that doesn't use query params. However, in development this is likely an * endpoint that is missing a schema. * * For example a GET request missing a `query` schema will throw an error if it receives a non-empty * query params object. */ required?: { query?: boolean; body?: boolean; response?: boolean; params?: boolean; /** * Provide a custom error factory for the required schema errors. * * Should return an error to be thrown, or a falsy value to ignore the error. */ errorFactory?: (error: TypeBoxMissingSchemaError) => Error | undefined; }; /** * Provide a custom error factory for the validation pipe. * * Should return an error to be thrown, or a falsy value to ignore the error. */ errorFactory?: (error: TypeBoxValidationError) => Error | undefined; /** * Apply custom transformations to the schema that is provided to the openapi docs. * * The returned value is only used for the openapi docs, and does not replace the * schema used for validation. * * You can however mutate the schema in place, as it is a reference to the original schema. * However, this is not recommended as it can lead to unexpected behaviour. * * This will override the `downgradeSchema` option, if you want to downgrade the schema * you will need to do it manually in this function. E.g. * * ```ts * transformSchema: (type, schema) => downgradeSchema(schema); * ``` */ transformSchema?: (type: "query" | "body" | "response" | "param", schema: TSchema) => TSchema; }; declare const createRequestMethods: (defaultOptions?: TypeBoxOpts) => { Post: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; Get: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; Delete: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; Put: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; Patch: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; Options: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; Head: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; All: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; Search: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; }; declare const TypeBoxPost: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare const TypeBoxGet: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare const TypeBoxDelete: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare const TypeBoxPut: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare const TypeBoxPatch: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare const TypeBoxOptions: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare const TypeBoxHead: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare const TypeBoxAll: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare const TypeBoxSearch: (pathOrOptions?: string | string[] | TypeBoxOpts, options?: TypeBoxOpts) => MethodDecorator; declare class TypeBoxInterceptor implements NestInterceptor { private readonly options; constructor(options: TypeBoxOpts); intercept(_: ExecutionContext, next: CallHandler): rxjs.Observable; } declare class TypeboxPipe implements PipeTransform { private readonly options; constructor(options: TypeBoxOpts); transform(value: unknown, metadata: ArgumentMetadata): unknown; } export { TypeBoxAll as All, TypeBoxDelete as Delete, TypeBoxGet as Get, TypeBoxHead as Head, TypeBoxOptions as Options, TypeBoxPatch as Patch, TypeBoxPost as Post, TypeBoxPut as Put, TypeBoxSearch as Search, TypeBoxAll, TypeBoxDelete, TypeBoxGet, TypeBoxHead, TypeBoxInterceptor, TypeBoxMissingSchemaError, TypeBoxOptions, type TypeBoxOpts, TypeBoxPatch, TypeBoxPost, TypeBoxPut, TypeBoxSearch, TypeBoxValidationError, TypeboxPipe, createRequestMethods };