arvox-backend
Version:
Un framework backend moderne et modulaire basé sur Hono, TypeScript et l'architecture hexagonale avec authentification Better Auth + Drizzle intégrée
139 lines • 5.03 kB
TypeScript
import { z } from 'zod';
/**
* Utility class for common validation patterns and schemas
*/
export declare class ValidationUtil {
/**
* Common UUID validation schema
*/
static readonly uuidSchema: z.ZodString;
/**
* Common email validation schema
*/
static readonly emailSchema: z.ZodString;
/**
* Common password validation schema
*/
static readonly passwordSchema: z.ZodString;
/**
* Common URL validation schema
*/
static readonly urlSchema: z.ZodString;
/**
* Common phone validation schema
*/
static readonly phoneSchema: z.ZodString;
/**
* Pagination parameters validation schema
*/
static readonly paginationSchema: z.ZodObject<{
page: z.ZodDefault<z.ZodNumber>;
limit: z.ZodDefault<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
page: number;
limit: number;
}, {
page?: number | undefined;
limit?: number | undefined;
}>;
/**
* Common date validation schemas
*/
static readonly dateSchema: z.ZodDate;
static readonly dateStringSchema: z.ZodString;
static readonly futureDateSchema: z.ZodEffects<z.ZodDate, Date, Date>;
static readonly pastDateSchema: z.ZodEffects<z.ZodDate, Date, Date>;
/**
* File validation schemas
*/
static readonly imageFileSchema: z.ZodObject<{
type: z.ZodEffects<z.ZodString, string, string>;
size: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
type: string;
size: number;
}, {
type: string;
size: number;
}>;
static readonly documentFileSchema: z.ZodObject<{
type: z.ZodEffects<z.ZodString, string, string>;
size: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
type: string;
size: number;
}, {
type: string;
size: number;
}>;
/**
* Create a custom file validation schema
* @param allowedTypes - Array of allowed MIME types
* @param maxSize - Maximum file size in bytes
* @returns Zod schema for file validation
*/
static createFileSchema(allowedTypes: string[], maxSize: number): z.ZodObject<{
type: z.ZodEffects<z.ZodString, string, string>;
size: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
type: string;
size: number;
}, {
type: string;
size: number;
}>;
/**
* Validate and parse data with a schema
* @param data - Data to validate
* @param schema - Zod schema
* @returns Parsed and validated data
* @throws Error with formatted validation message
*/
static validate<T>(data: any, schema: z.ZodSchema<T>): T;
/**
* Safely validate data without throwing
* @param data - Data to validate
* @param schema - Zod schema
* @returns Result object with success status and data or errors
*/
static safeValidate<T>(data: any, schema: z.ZodSchema<T>): {
success: true;
data: T;
} | {
success: false;
errors: Array<{
path: string;
message: string;
}>;
};
/**
* Create a schema for array validation with optional constraints
* @param itemSchema - Schema for individual items
* @param minItems - Minimum number of items
* @param maxItems - Maximum number of items
* @returns Array validation schema
*/
static createArraySchema<T>(itemSchema: z.ZodSchema<T>, minItems?: number, maxItems?: number): z.ZodArray<z.ZodType<T, z.ZodTypeDef, T>, "many">;
/**
* Create a conditional schema based on another field
* @param conditionField - Field to check
* @param conditionValue - Value to match
* @param trueSchema - Schema to use if condition is true
* @param falseSchema - Schema to use if condition is false
* @returns Conditional validation schema
*/
static createConditionalSchema<T>(conditionField: string, conditionValue: any, trueSchema: z.ZodSchema<T>, falseSchema: z.ZodSchema<T>): z.ZodEffects<z.ZodUnion<[z.ZodType<T, z.ZodTypeDef, T>, z.ZodType<T, z.ZodTypeDef, T>]>, T, T>;
/**
* Create a schema for partial updates (all fields optional)
* @param baseSchema - Base schema to make partial
* @returns Partial schema
*/
static createPartialSchema<T extends z.ZodRawShape>(baseSchema: z.ZodObject<T>): z.ZodObject<{ [k in keyof T]: z.ZodOptional<T[k]>; }, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<{ [k in keyof T]: z.ZodOptional<T[k]>; }>, any> extends infer T_1 ? { [k_1 in keyof T_1]: T_1[k_1]; } : never, z.baseObjectInputType<{ [k in keyof T]: z.ZodOptional<T[k]>; }> extends infer T_2 ? { [k_2 in keyof T_2]: T_2[k_2]; } : never>;
/**
* Merge multiple schemas
* @param schemas - Array of schemas to merge
* @returns Merged schema
*/
static mergeSchemas<T extends z.ZodObject<any>[]>(...schemas: T): z.ZodObject<any>;
}
//# sourceMappingURL=validation.util.d.ts.map