cs-element
Version:
Advanced reactive data management library with state machines, blueprints, persistence, compression, networking, and multithreading support
116 lines • 3.66 kB
TypeScript
import { ICSElement, ValidationRule, ValidationResult, ValidationError } from '../types/interfaces';
import * as Joi from 'joi';
/**
* Расширенные типы валидации
*/
export declare enum ValidationType {
REQUIRED = "required",
TYPE = "type",
RANGE = "range",
CUSTOM = "custom",
SCHEMA = "schema",
ASYNC = "async",
PATTERN = "pattern",
ENUM = "enum",
ARRAY = "array",
OBJECT = "object"
}
/**
* Результат асинхронной валидации
*/
export interface AsyncValidationResult {
isValid: boolean;
errors: ValidationError[];
warnings?: ValidationError[];
performance?: {
executionTime: number;
rulesExecuted: number;
};
}
/**
* Расширенное правило валидации
*/
export interface ExtendedValidationRule extends ValidationRule {
type: ValidationType;
schema?: Joi.Schema;
async?: boolean;
severity?: 'error' | 'warning' | 'info';
dependencies?: string[];
condition?: (element: ICSElement) => boolean;
}
/**
* Система валидации для CSElement
*/
export declare class ElementValidator {
private rules;
private schemaCache;
private globalSchemas;
/**
* Добавляет правило валидации
*/
addRule(elementType: string, rule: ExtendedValidationRule): void;
/**
* Добавляет схему Joi для типа элемента
*/
addSchema(elementType: string, schema: Joi.Schema): void;
/**
* Удаляет все правила для типа элемента
*/
clearRules(elementType: string): void;
/**
* Валидирует элемент (синхронно)
*/
validate(element: ICSElement, elementType?: string): ValidationResult;
/**
* Асинхронная валидация элемента
*/
validateAsync(element: ICSElement, elementType?: string): Promise<AsyncValidationResult>;
/**
* Валидация с использованием Joi схемы
*/
private validateWithJoi;
/**
* Сериализует элемент для валидации
*/
private serializeElementForValidation;
/**
* Валидирует одно правило (синхронно)
*/
private validateRule;
/**
* Валидирует одно правило (асинхронно)
*/
private validateRuleAsync;
/**
* Получает значение поля элемента
*/
private getFieldValue;
/**
* Создает стандартные правила валидации
*/
static createStandardRules(): ElementValidator;
/**
* Создает расширенные правила валидации для типизированных элементов
*/
static createTypedElementRules(): ElementValidator;
}
/**
* Глобальный валидатор по умолчанию
*/
export declare const defaultValidator: ElementValidator;
/**
* Валидатор для типизированных элементов
*/
export declare const typedElementValidator: ElementValidator;
/**
* Утилиты для создания схем Joi
*/
export declare class ValidationSchemaBuilder {
static createElementSchema(options?: {
requiredFields?: string[];
optionalFields?: string[];
customValidators?: Record<string, Joi.Schema>;
}): Joi.Schema;
static createDataSchema(dataStructure: Record<string, any>): Joi.Schema;
}
//# sourceMappingURL=Validator.d.ts.map