UNPKG

ts-valid8

Version:

A next-generation TypeScript validation library with advanced features

43 lines 1.57 kB
/** * Core type definitions for Valid8 validation library */ export type ValidationResult<T> = { success: boolean; value: T; errors?: ValidationError[]; }; export type ValidationError = { path: string[]; message: string; code: string; params?: Record<string, any>; }; export type ValidationContext = { path: string[]; parent?: unknown; root?: unknown; siblings?: Record<string, unknown>; [key: string]: any; }; export type ValidatorFn<T> = (value: unknown, context?: ValidationContext) => ValidationResult<T>; export interface Schema<T> { _type: string; _validators: Array<(value: unknown, context: ValidationContext) => ValidationError | null>; validate: (value: unknown, context?: ValidationContext) => ValidationResult<T>; optional: () => Schema<T | undefined>; nullable: () => Schema<T | null>; default: (value: T | (() => T)) => Schema<T>; required: (message?: string) => Schema<T>; refine: (refinement: (value: T, context?: ValidationContext) => boolean | Promise<boolean>, message: string | ((value: T) => string)) => Schema<T>; transform: (fn: (value: T) => T) => Schema<T>; use?: <U>(plugin: SchemaPlugin<T, U>) => Schema<U>; } export type SchemaPlugin<T, U = T> = { (schema: Schema<T>): Schema<U>; }; export type ErrorCreator = (code: string, message: string, path: string[], params?: Record<string, any>) => ValidationError; export interface BaseValidator<T> { _type: string; validate(value: unknown): ValidationResult<T>; } //# sourceMappingURL=types.d.ts.map