import type { TSchema } from '@sinclair/typebox'; import type { TypeCheck, ValueError, ValueErrorIterator } from '@sinclair/typebox/compiler'; import { StatusMap, InvertedStatusMap } from './utils'; import type { ElysiaTypeCheck } from './schema'; import { StandardSchemaV1Like } from './types'; export declare const ERROR_CODE: unique symbol; export type ERROR_CODE = typeof ERROR_CODE; export declare const isProduction: boolean; export type ElysiaErrors = InternalServerError | NotFoundError | ParseError | ValidationError | InvalidCookieSignature; type CheckExcessProps = 0 extends 1 & T ? T : U extends U ? Exclude extends never ? T : { [K in keyof U]: U[K]; } & { [K in Exclude]: never; } : never; export type SelectiveStatus = ], T extends Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never>(code: Code, response: CheckExcessProps) => ElysiaCustomStatusResponse; export declare class ElysiaCustomStatusResponse { code: Status; response: T; constructor(code: Code, response: T); } export declare const ElysiaStatus: typeof ElysiaCustomStatusResponse; export declare const status: (code: Code, response?: T) => ElysiaCustomStatusResponse; export declare class InternalServerError extends Error { code: string; status: number; constructor(message?: string); } export declare class NotFoundError extends Error { code: string; status: number; constructor(message?: string); } export declare class ParseError extends Error { code: string; status: number; constructor(cause?: Error); } export declare class InvalidCookieSignature extends Error { key: string; code: string; status: number; constructor(key: string, message?: string); } interface ValueErrorWithSummary extends ValueError { summary?: string; } export declare const mapValueError: (error: ValueError | undefined) => ValueErrorWithSummary | undefined; export declare class InvalidFileType extends Error { property: string; expected: string | string[]; message: string; code: string; status: number; constructor(property: string, expected: string | string[], message?: string); toResponse(headers?: Record): Response; } export declare class ValidationError extends Error { type: string; validator: TSchema | TypeCheck | ElysiaTypeCheck | StandardSchemaV1Like; /** * Input value */ value: unknown; private allowUnsafeValidationDetails; code: string; status: number; /** * An actual value of `message` * * Since `message` is string * use this instead of message */ valueError?: ValueError; /** * Alias of `valueError` */ get messageValue(): ValueError | undefined; /** * Expected value of the schema */ expected?: unknown; /** * Custom error if provided */ customError?: unknown; constructor(type: string, validator: TSchema | TypeCheck | ElysiaTypeCheck | StandardSchemaV1Like, /** * Input value */ value: unknown, allowUnsafeValidationDetails?: boolean, errors?: ValueErrorIterator); get all(): ValueErrorWithSummary[]; static simplifyModel(validator: TSchema | TypeCheck | ElysiaTypeCheck): any; get model(): any; toResponse(headers?: Record): Response; /** * Utility function to inherit add custom error and keep the original Validation error * * @since 1.3.14 * * @example * ```ts * new Elysia() * .onError(({ error, code }) => { * if (code === 'VALIDATION') return error.detail(error.message) * }) * .post('/', () => 'Hello World!', { * body: t.Object({ * x: t.Number({ * error: 'x must be a number' * }) * }) * }) * ``` */ detail(message: unknown, allowUnsafeValidatorDetails?: boolean): string | { type: string; on: string; found: unknown; message: unknown; property?: undefined; summary?: undefined; expected?: undefined; errors?: undefined; } | { type: string; on: string; property: string; message: unknown; summary: string | undefined; found: unknown; expected: unknown; errors: ValueErrorWithSummary[]; }; } export {};