ts-valid8
Version:
A next-generation TypeScript validation library with advanced features
67 lines • 2.32 kB
TypeScript
/**
* Validator Builder - A fluent API for building validation schemas
* Simplifies the creation of complex validation logic with a chainable interface
*/
import { StringSchema } from '../validators/string';
import { NumberSchema } from '../validators/number';
import { BooleanSchema } from '../validators/boolean';
import { ObjectSchema } from '../validators/object';
import { ArraySchema } from '../validators/array';
import { DateSchema } from '../validators/date';
import { Schema, SchemaPlugin } from '../core/types';
/**
* ValidatorBuilder - The main entry point for creating validation schemas
*/
export declare class ValidatorBuilder {
/**
* Create a string validation schema
*/
string(): StringSchema;
/**
* Create a number validation schema
*/
number(): NumberSchema;
/**
* Create a boolean validation schema
*/
boolean(): BooleanSchema;
/**
* Create an object validation schema
*/
object<T extends Record<string, Schema<any>>>(shape: T): ObjectSchema<T>;
/**
* Create an array validation schema
*/
array<T>(elementSchema: Schema<T>): ArraySchema<T>;
/**
* Create a date validation schema
*/
date(): DateSchema;
/**
* Create a validation schema that only passes if one of the given schemas passes
* Similar to a union type or OR condition
*/
oneOf<T>(schemas: Array<Schema<T>>): Schema<T>;
/**
* Create a validation schema that requires all the given schemas to pass
* Like an AND condition between schemas
*/
allOf<T>(schemas: Array<Schema<T>>): Schema<T>;
/**
* Create a lazy schema for handling recursive/circular structures
*/
lazy<T>(schemaFn: () => Schema<T>): Schema<T>;
}
export declare const builder: ValidatorBuilder;
export declare function createValidationContext(data?: Record<string, any>): {
path: never[];
};
/**
* Safely applies a plugin to a schema, checking if the use method exists
* @param schema The schema to apply the plugin to
* @param plugin The plugin to apply
* @returns The schema with the plugin applied
* @throws If the schema does not support plugins
*/
export declare function applyPlugin<T, U>(schema: Schema<T>, plugin: SchemaPlugin<T, U>): Schema<U>;
//# sourceMappingURL=builder.d.ts.map