ts-valid8
Version:
A next-generation TypeScript validation library with advanced features
63 lines • 2.37 kB
TypeScript
import { BaseSchema } from '../core/schema';
import { Schema, ValidationContext, ValidationResult } from '../core/types';
type ObjectShape = Record<string, Schema<any>>;
/**
* ObjectSchema - Advanced object validation with cross-field validation support
*/
export declare class ObjectSchema<T extends ObjectShape> extends BaseSchema<{
[K in keyof T]: ReturnType<T[K]['validate']>['value'];
}> {
_type: string;
private shape;
private _crossFieldValidators;
private _strict;
constructor(shape: T);
protected validateType(value: unknown, context: ValidationContext): ValidationResult<{
[K in keyof T]: ReturnType<T[K]['validate']>['value'];
}>;
protected clone(): ObjectSchema<T>;
/**
* Add a validation rule that depends on multiple fields
*/
crossField(validator: (values: {
[K in keyof T]: any;
}) => boolean | Promise<boolean>, message: string | ((values: {
[K in keyof T]: any;
}) => string), affectedFields?: (keyof T)[]): ObjectSchema<T>;
/**
* Add password matching validation between two fields
*/
passwordsMatch(passwordField: keyof T & string, confirmField: keyof T & string, message?: string): ObjectSchema<T>;
/**
* Enable strict mode (unknown fields will cause validation to fail)
*/
strict(enabled?: boolean): ObjectSchema<T>;
/**
* Allow unknown fields (passthrough mode)
*/
passthrough(): ObjectSchema<T>;
/**
* Define a validation rule that depends on a condition from another field
*/
when<K extends keyof T>(field: K, condition: (value: any) => boolean, then: (schema: ObjectSchema<T>) => ObjectSchema<T>): ObjectSchema<T>;
/**
* Pick a subset of fields from this schema to create a new schema
*/
pick<K extends keyof T>(keys: K[]): ObjectSchema<Pick<T, K>>;
/**
* Omit fields from this schema to create a new schema
*/
omit<K extends keyof T>(keys: K[]): ObjectSchema<Omit<T, K>>;
/**
* Create a partial version of the schema where all properties are optional
*/
partial(): ObjectSchema<{
[K in keyof T]: T[K];
}>;
/**
* Extend this schema with additional fields or override existing ones
*/
extend<U extends ObjectShape>(shape: U): ObjectSchema<T & U>;
}
export {};
//# sourceMappingURL=object.d.ts.map