UNPKG

ts-valid8

Version:

A next-generation TypeScript validation library with advanced features

58 lines 2.01 kB
import { Schema, ValidationContext, ValidationError, ValidationResult, SchemaPlugin } from './types'; export { Schema }; /** * BaseSchema - The foundation for all validation schemas * Provides common validation operations and chainable API */ export declare abstract class BaseSchema<T> implements Schema<T> { abstract _type: string; _validators: Array<(value: unknown, context?: ValidationContext) => ValidationError | null>; _isOptional: boolean; _isNullable: boolean; _defaultValue?: T | (() => T); /** * Validate a value against this schema */ validate(value: unknown, context?: ValidationContext): ValidationResult<T>; /** * Type-specific validation logic to be implemented by subclasses */ protected abstract validateType(value: unknown, context: ValidationContext): ValidationResult<T>; /** * Make this schema accept undefined values */ optional(): Schema<T | undefined>; /** * Make this schema accept null values */ nullable(): Schema<T | null>; /** * Set a default value for this schema */ default(value: T | (() => T)): Schema<T>; /** * Mark this field as required (not undefined) */ required(message?: string): Schema<T>; /** * Add a custom validation rule */ refine(refinement: (value: T, context?: ValidationContext) => boolean | Promise<boolean>, message: string | ((value: T) => string)): Schema<T>; /** * Apply a transformation function to the schema's value */ transform(fn: (value: T) => T): Schema<T>; /** * Create a copy of this schema */ protected abstract clone(): BaseSchema<T>; /** * Create validation error */ protected createError(code: string, message: string, context: ValidationContext, params?: Record<string, any>): ValidationError; /** * Use a plugin with this schema */ use<U>(plugin: SchemaPlugin<T, U>): Schema<U>; } //# sourceMappingURL=schema.d.ts.map