guardz-event
Version:
Type-safe event handling with runtime validation using guardz for unsafe data from 3rd parties
37 lines • 1.23 kB
TypeScript
import type { TypeGuardFn } from 'guardz';
import type { ErrorContext } from '../../utils/safe-event-never-throws';
/**
* Configuration for Guardz validation
*/
export interface GuardzValidationConfig {
/** Enable tolerance mode (default: false) */
tolerance?: boolean;
/** Identifier for error context */
identifier?: string;
/** Error callback for tolerance mode */
onError?: (error: string, context: ErrorContext) => void;
/** Event type for context */
eventType?: string;
}
/**
* Guardz-specific validation service
*/
export declare class GuardzValidator {
/**
* Validate data using a type guard with optional tolerance mode
*/
static validate<T>(data: unknown, guard: TypeGuardFn<T>, config?: GuardzValidationConfig): {
isValid: boolean;
data?: T;
error?: string;
};
/**
* Create a validation function with pre-configured settings
*/
static createValidator<T>(guard: TypeGuardFn<T>, defaultConfig?: GuardzValidationConfig): (data: unknown, config?: Partial<GuardzValidationConfig>) => {
isValid: boolean;
data?: T | undefined;
error?: string;
};
}
//# sourceMappingURL=GuardzValidator.d.ts.map