UNPKG

@sailboat-computer/event-bus

Version:

Standardized event bus for sailboat computer v3 with resilience features and offline capabilities

211 lines 5.38 kB
/** * Event bus implementation */ import { EventBus, EventAdapter, EventBusConfig, EventHandler, Subscription, PublishOptions, EventBusMetrics, Alert, AlertHandler, AlertType } from './types'; /** * Event bus implementation */ export declare class EventBusImpl implements EventBus { /** * Event adapter */ private adapter; /** * Whether the event bus is initialized */ private initialized; /** * Offline buffer for events */ private offlineBuffer; /** * Service name */ private serviceName; /** * Metrics collector */ private metricsCollector; /** * Schema registry */ private schemaRegistry; /** * Dead letter queue manager */ private deadLetterQueue; /** * Alert manager */ private alertManager; /** * Monitoring interval */ private monitoringInterval; /** * Configuration */ private config; /** * Create a new event bus * * @param adapter - Event adapter */ constructor(adapter: EventAdapter); /** * Initialize the event bus * * @param config - Event bus configuration */ initialize(config: EventBusConfig): Promise<void>; /** * Shutdown the event bus */ shutdown(): Promise<void>; /** * Publish an event * * @param eventType - Event type * @param data - Event data * @param options - Publish options * @returns Event ID */ publish<T>(eventType: string, data: T, options?: PublishOptions): Promise<string>; /** * Subscribe to an event * * @param eventType - Event type * @param handler - Event handler * @returns Subscription */ subscribe<T>(eventType: string, handler: EventHandler<T>): Promise<Subscription>; /** * Get event bus metrics * * @returns Event bus metrics */ getMetrics(): EventBusMetrics; /** * Register a schema for an event type * * @param eventType - Event type * @param schema - JSON schema */ registerSchema<T>(eventType: string, schema: any): void; /** * 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): any; /** * Get events from the dead letter queue * * @param eventType - Optional event type to filter by * @param limit - Maximum number of events to return * @returns Dead letter queue events */ getDeadLetterEvents(eventType?: string, limit?: number): Promise<any[]>; /** * Republish an event from the dead letter queue * * @param eventId - ID of the event to republish * @returns New event ID */ republishDeadLetterEvent(eventId: string): Promise<string>; /** * Remove an event from the dead letter queue * * @param eventId - ID of the event to remove */ removeDeadLetterEvent(eventId: string): Promise<void>; /** * Clear the dead letter queue * * @param eventType - Optional event type to filter by */ clearDeadLetterQueue(eventType?: string): Promise<void>; /** * Register an alert handler * * @param handler - Alert handler * @returns Handler ID */ registerAlertHandler(handler: AlertHandler): string; /** * Unregister an alert handler * * @param handlerId - Handler ID */ unregisterAlertHandler(handlerId: string): void; /** * Get active alerts * * @param type - Optional alert type to filter by * @returns Active alerts */ getActiveAlerts(type?: AlertType): Alert[]; /** * Get alert history * * @param limit - Maximum number of alerts to return * @param type - Optional alert type to filter by * @returns Alert history */ getAlertHistory(limit?: number, type?: AlertType): Alert[]; /** * Clear alert history */ clearAlertHistory(): void; /** * Unsubscribe from all handlers for an event type * * @param eventType - Event type to unsubscribe from */ unsubscribe(eventType: string): Promise<void>; /** * Check if the event bus is healthy * * @returns True if the event bus is healthy */ isHealthy(): Promise<boolean>; /** * Buffer an event for later publishing * * @param eventType - Event type * @param data - Event data * @param options - Publish options */ private bufferEvent; /** * Process offline buffer */ private processOfflineBuffer; /** * Prune offline buffer when it's full */ private pruneOfflineBuffer; /** * Remove events by priority * * @param priority - Event priority * @returns True if an event was removed */ private removeEventsByPriority; } /** * Create a new event bus * * @param adapter - Event adapter * @returns Event bus */ export declare function createEventBusWithAdapter(adapter: EventAdapter): EventBus; //# sourceMappingURL=event-bus.d.ts.map