veffect
Version:
powerful TypeScript validation library built on the robust foundation of Effect combining exceptional type safety, high performance, and developer experience. Taking inspiration from Effect's functional principles, VEffect delivers a balanced approach tha
34 lines (33 loc) • 1.29 kB
TypeScript
/**
* Pattern Schema implementation for ad-hoc validation based on runtime value inspection
*/
import { Schema } from '../types';
export interface PatternSchema<T> extends Schema<T> {
readonly _tag: 'PatternSchema';
}
/**
* Creates a schema that validates the input based on a pattern matching function
* The pattern function can return different schemas based on runtime inspection of the input
*
* @param patternFn A function that takes the input and returns an appropriate schema
* @returns A schema that validates using dynamic schema selection based on input
*
* @example
* const responseSchema = pattern(input => {
* if (input.status === 'success') return object({ status: literal('success'), data: any() });
* if (input.status === 'error') return object({ status: literal('error'), message: string() });
* return invalid('Unknown response type');
* });
*/
export declare function pattern<T>(patternFn: (input: unknown) => Schema<T> | InvalidResult): PatternSchema<T>;
/**
* Interface for invalid results in pattern matching
*/
export interface InvalidResult {
readonly _type: 'invalid';
readonly message: string;
}
/**
* Helper to create an invalid result with custom message
*/
export declare function invalid(message: string): InvalidResult;