UNPKG

docudb

Version:

Document-based NoSQL database for NodeJS

44 lines 1.7 kB
/** * Schema module for data validation * Allows defining structure and validating documents */ import { SchemaDefinition, SchemaOptions, Schema as SchemaInterface, DocumentStructure } from '../types/index.js'; declare class Schema implements SchemaInterface { /** Schema definition */ definition: SchemaDefinition; /** Schema options */ options: SchemaOptions; /** * Creates a new schema for document validation * @param definition - Schema definition with field types and validation rules * @param options - Additional schema options */ constructor(definition: SchemaDefinition, options?: SchemaOptions); /** * Validates a document against the schema * @param document - Document to validate * @returns Validated and normalized document * @throws {DocuDBError} - If the document does not comply with the schema */ validate(document: DocumentStructure): DocumentStructure; /** * Validates the type of a value * @param {*} value - Value to validate * @param {string|Function} type - Expected type * @returns {boolean} - Indicates if the value is of the expected type * @private */ private _validateType; /** * Executes custom validators * @param {*} value - Value to validate * @param {Function|Array|Object} validators - Validators to execute * @param {string} field - Field name being validated * @param {DocumentStructure} document - The complete document being validated * @returns {void} - Throws an error if validation fails * @private */ private _runValidators; } export default Schema; //# sourceMappingURL=schema.d.ts.map