@sailboat-computer/event-bus
Version:
Standardized event bus for sailboat computer v3 with resilience features and offline capabilities
87 lines • 1.92 kB
TypeScript
/**
* Event schema validation
*/
import { EventEnvelope } from './types';
type JSONSchemaType<T> = {
type: string;
properties?: Record<string, any>;
required?: string[];
additionalProperties?: boolean;
[key: string]: any;
};
/**
* Schema registry for event validation
*/
export declare class SchemaRegistry {
/**
* Ajv instance
*/
private ajv;
/**
* Schema map
*/
private schemas;
/**
* Constructor
*/
constructor();
/**
* Register a schema for an event type
*
* @param eventType - Event type
* @param schema - JSON schema
*/
registerSchema<T>(eventType: string, schema: JSONSchemaType<T>): void;
/**
* Validate an event against its schema
*
* @param event - Event envelope
* @returns Validation result
*/
validate(event: EventEnvelope): ValidationResult;
/**
* Check if a schema is registered for an event type
*
* @param eventType - Event type
* @returns True if a schema is registered
*/
hasSchema(eventType: string): boolean;
/**
* Get a schema for an event type
*
* @param eventType - Event type
* @returns JSON schema or null if not found
*/
getSchema(eventType: string): JSONSchemaType<any> | null;
/**
* Remove a schema for an event type
*
* @param eventType - Event type
*/
removeSchema(eventType: string): void;
/**
* Clear all schemas
*/
clearSchemas(): void;
}
/**
* Validation result
*/
export interface ValidationResult {
/**
* Whether the validation passed
*/
valid: boolean;
/**
* Validation errors
*/
errors: any[] | null;
}
/**
* Create a schema registry
*
* @returns Schema registry
*/
export declare function createSchemaRegistry(): SchemaRegistry;
export {};
//# sourceMappingURL=validation.d.ts.map