UNPKG

perfect-validator

Version:

A TypeScript-based validation library that supports both static and dynamic validation with serializable models.

57 lines (56 loc) 2.52 kB
import { PerfectValidator } from './types'; export declare class PV { private storage?; private static instance; constructor(storage?: PerfectValidator.IModelStorage); /** * Static validation with direct model and data */ validateStatic<T>(data: T, model: PerfectValidator.ValidationModel, allowUnknownFields?: boolean): PerfectValidator.ValidationResponse<T>; static getInstance(storage?: PerfectValidator.IModelStorage): PV; /** * Dynamic validation using stored model with optional collection */ validateDynamic<T>(data: T, modelName: string, version?: number, collection?: string, allowUnknownFields?: boolean): Promise<PerfectValidator.ValidationResponse<T>>; /** * Store model with validation and optional collection */ storeModel(modelName: string, model: PerfectValidator.ValidationModel, version?: number, collection?: string): Promise<PerfectValidator.ModelValidationResponse>; /** * Validate model structure */ validateModel(model: PerfectValidator.ValidationModel): PerfectValidator.ModelValidationResponse; private serializeModelSafely; private deserializeAndValidate; /** * Get all supported data types with descriptions */ getDataTypes(): Record<string, PerfectValidator.ValidationType>; /** * Get example model with different validation cases */ getModelExample(): PerfectValidator.ValidationModel; /** * Get example data matching the model example */ getDataExample(): Array<{ name: string; data: any; }>; getValidationTypeParams(type: PerfectValidator.ValidationType): PerfectValidator.IValidationTypeParams; getLatestModelVersion(modelName: string, collection?: string): Promise<PerfectValidator.ValidationModel | null>; /** * Get model of a specific version * @param modelName Name of the model * @param version Version number of the model * @returns The model version or null if not found */ getModelVersion(modelName: string, version: number, collection?: string): Promise<PerfectValidator.ValidationModel | null>; /** * Get list of all versions for a model * @param modelName Name of the model * @param collection Optional collection name * @returns Array of version numbers in descending order (newest first) */ listModelVersions(modelName: string, collection?: string): Promise<number[]>; }