/** * ValidationRule - Individual validation rule * * Represents a single validation rule with its configuration. */ export class ValidationRule { constructor(name, validator, options = {}) { this.name = name; this.validator = validator; this.options = options; } /** * Validate a value against this rule */ async validate(value) { if (typeof this.validator === 'function') { const result = await this.validator(value, this.options); return result === true ? true : (result || this.options.message || 'Validation failed'); } return true; } /** * Get rule name */ getName() { return this.name; } /** * Get rule options */ getOptions() { return { ...this.options }; } /** * Create a validation rule */ static create(name, validator, options = {}) { return new ValidationRule(name, validator, options); } }