@dbs-portal/tool-mock
Version:
API mocking toolkit using MSW for DBS Portal development workflows
127 lines • 3.29 kB
TypeScript
/**
* Validation utilities for mock data
*/
import type { ValidationResult, ValidationRule, FieldValidation, SchemaValidation } from './types';
/**
* Validate data against a schema
*/
export declare function validateSchema<T = any>(data: T, schema: SchemaValidation<T>): ValidationResult;
/**
* Common validation rules
*/
export declare const validationRules: {
/**
* Email validation rule
*/
email: () => ValidationRule;
/**
* Minimum length validation rule
*/
minLength: (min: number) => ValidationRule;
/**
* Maximum length validation rule
*/
maxLength: (max: number) => ValidationRule;
/**
* Minimum value validation rule
*/
min: (min: number) => ValidationRule;
/**
* Maximum value validation rule
*/
max: (max: number) => ValidationRule;
/**
* Pattern validation rule
*/
pattern: (pattern: RegExp, message?: string) => ValidationRule;
/**
* URL validation rule
*/
url: () => ValidationRule;
/**
* Phone number validation rule
*/
phone: () => ValidationRule;
/**
* Date validation rule
*/
date: () => ValidationRule;
/**
* Future date validation rule
*/
futureDate: () => ValidationRule;
/**
* Past date validation rule
*/
pastDate: () => ValidationRule;
/**
* One of validation rule
*/
oneOf: (values: any[]) => ValidationRule;
/**
* Array validation rule
*/
array: (minLength?: number, maxLength?: number) => ValidationRule;
/**
* Object validation rule
*/
object: () => ValidationRule;
/**
* Number validation rule
*/
number: () => ValidationRule;
/**
* Integer validation rule
*/
integer: () => ValidationRule;
/**
* Boolean validation rule
*/
boolean: () => ValidationRule;
/**
* String validation rule
*/
string: () => ValidationRule;
/**
* Custom validation rule
*/
custom: (validator: (value: any, data: any) => boolean | string, message?: string) => ValidationRule;
};
/**
* Create a field validation configuration
*/
export declare function createFieldValidation<T = any>(field: keyof T, rules: ValidationRule<T>[], required?: boolean, requiredMessage?: string): FieldValidation<T>;
/**
* Create a schema validation configuration
*/
export declare function createSchemaValidation<T = any>(fields: FieldValidation<T>[], customValidation?: (data: T) => string[] | null): SchemaValidation<T>;
/**
* Quick validation for common data types
*/
export declare const quickValidation: {
/**
* Validate user data
*/
user: (data: any) => ValidationResult;
/**
* Validate product data
*/
product: (data: any) => ValidationResult;
/**
* Validate order data
*/
order: (data: any) => ValidationResult;
/**
* Validate address data
*/
address: (data: any) => ValidationResult;
};
/**
* Validate and sanitize input data
*/
export declare function validateAndSanitize<T = any>(data: any, schema: SchemaValidation<T>, sanitizers?: Record<keyof T, (value: any) => any>): {
valid: boolean;
data: T;
errors: string[];
};
//# sourceMappingURL=validation.d.ts.map