tero
Version:
tero is a JSON document Manager, with ACID complaint and backup recovery mechanism.
62 lines (61 loc) • 1.79 kB
TypeScript
export interface SchemaField {
type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'date' | 'any';
required?: boolean;
min?: number;
max?: number;
format?: 'email' | 'url' | 'uuid' | 'date' | 'time' | 'datetime' | 'phone' | 'ip';
pattern?: string;
enum?: any[];
default?: any;
properties?: {
[key: string]: SchemaField;
};
items?: SchemaField;
custom?: (value: any) => boolean | string;
}
export interface DocumentSchema {
[fieldName: string]: SchemaField;
}
export interface ValidationError {
field: string;
message: string;
value?: any;
expected?: string;
}
export interface ValidationResult {
valid: boolean;
errors: ValidationError[];
data?: any;
}
export declare class SchemaValidator {
private schemas;
setSchema(collectionName: string, schema: DocumentSchema): void;
getSchema(collectionName: string): DocumentSchema | undefined;
removeSchema(collectionName: string): boolean;
hasSchema(collectionName: string): boolean;
listSchemas(): string[];
private validateSchemaDefinition;
validate(collectionName: string, data: any): ValidationResult;
private validateAndSanitizeData;
private validateField;
private validateType;
private validateString;
private validateNumber;
private validateBoolean;
private validateDate;
private validateArray;
private validateObject;
private validateFormat;
getSchemaStats(): {
totalSchemas: number;
schemaNames: string[];
totalFields: number;
};
exportSchemas(): {
[collectionName: string]: DocumentSchema;
};
importSchemas(schemas: {
[collectionName: string]: DocumentSchema;
}): void;
clearAllSchemas(): void;
}