UNPKG

@sailboat-computer/event-bus

Version:

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

94 lines 2.54 kB
/** * Base adapter for event bus implementations */ import { EventAdapter, AdapterConfig, EventHandler, EventEnvelope, Subscription } from '../types'; /** * Base adapter implementation */ export declare abstract class BaseAdapter implements EventAdapter { /** * Adapter configuration */ protected config: AdapterConfig; /** * Whether the adapter is initialized */ protected initialized: boolean; /** * Whether the adapter is connected */ protected connected: boolean; /** * Subscriptions by event type */ protected subscriptions: Map<string, Map<string, EventHandler>>; /** * Create a new base adapter */ constructor(); /** * Initialize the adapter * * @param config - Adapter configuration */ initialize(config: AdapterConfig): Promise<void>; /** * Shutdown the adapter */ shutdown(): Promise<void>; /** * Publish an event * * @param event - Event envelope * @returns Event ID */ abstract publish<T>(event: EventEnvelope): 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>; /** * Unsubscribe from a specific subscription * * @param subscriptionId - Subscription ID * @param eventType - Event type */ protected unsubscribeById(subscriptionId: string, eventType: string): Promise<void>; /** * Unsubscribe from all handlers for an event type * * @param eventType - Event type to unsubscribe from */ unsubscribe(eventType: string): Promise<void>; /** * Acknowledge an event * * @param eventId - Event ID * @param eventType - Event type */ abstract acknowledgeEvent(eventId: string, eventType: string): Promise<void>; /** * Check if the adapter is connected * * @returns True if connected */ isConnected(): boolean; /** * Ensure the adapter is initialized * * @throws NotInitializedError if not initialized */ protected ensureInitialized(): void; /** * Validate adapter configuration * * @param config - Adapter configuration * @throws ConfigurationError if configuration is invalid */ protected validateConfig(config: AdapterConfig): void; } //# sourceMappingURL=base-adapter.d.ts.map