/** * @file Coordination Event Bus * @module coordination/event-bus * @description Event bus for coordination module cross-component communication. * * Provides a typed event bus for lifecycle, state coordination, and feature bridge events. * * @author Agent 5 - PhD TypeScript Architect * @version 1.0.0 */ /** * Coordination event types and their payloads. */ export interface CoordinationEvents { 'lifecycle:phase-started': { phaseId: string; phaseName: string; order: number; }; 'lifecycle:phase-completed': { phaseId: string; phaseName: string; duration: number; }; 'lifecycle:library-initialized': { libraryId: string; duration: number; }; 'lifecycle:all-initialized': { totalDuration: number; libraryCount: number; }; 'lifecycle:shutdown-started': Record; 'lifecycle:shutdown-completed': { duration: number; }; 'state:changed': { sliceId: string; path?: string[]; previousValue: unknown; newValue: unknown; }; 'state:synced': { ruleId: string; sourceSlice: string; targetSlice: string; }; 'feature:registered': { featureId: string; name: string; capabilities: string[]; }; 'feature:loaded': { featureId: string; duration: number; }; 'feature:capability-invoked': { featureId: string; capability: string; duration: number; success: boolean; }; } /** * Event names for coordination. */ export type CoordinationEventName = keyof CoordinationEvents; /** * Event handler type. */ export type CoordinationEventHandler = (payload: CoordinationEvents[E]) => void; /** * Coordination event bus for typed pub/sub communication. */ export declare class CoordinationEventBus { /** Event listeners map */ private readonly listeners; /** Debug mode */ private debug; /** * Enables or disables debug logging. */ setDebug(enabled: boolean): void; /** * Subscribes to an event. * @param event - Event name * @param handler - Event handler * @returns Unsubscribe function */ subscribe(event: E, handler: CoordinationEventHandler): () => void; /** * Publishes an event. * @param event - Event name * @param payload - Event payload */ publish(event: E, payload: CoordinationEvents[E]): void; /** * Subscribes to an event once. * @param event - Event name * @param handler - Event handler * @returns Unsubscribe function */ once(event: E, handler: CoordinationEventHandler): () => void; /** * Removes all listeners for an event. * @param event - Event name (optional, clears all if not provided) */ clear(event?: CoordinationEventName): void; /** * Gets the number of listeners for an event. * @param event - Event name */ listenerCount(event: CoordinationEventName): number; /** * Subscribes to multiple event types. * @param events - Event names * @param handler - Event handler * @returns Array of unsubscribe functions */ subscribeMany(events: E[], handler: CoordinationEventHandler): (() => void)[]; /** * Request-response pattern. * @param requestEvent - Request event name * @param responseEvent - Response event name * @param payload - Request payload * @param timeout - Timeout in milliseconds * @returns Promise that resolves with the response payload */ request(requestEvent: TReq, responseEvent: TRes, payload: CoordinationEvents[TReq], timeout?: number): Promise; /** * Get event bus statistics. * @returns Event bus statistics */ getStats(): { totalPublished: number; totalDelivered: number; totalFailures: number; activeSubscriptions: number; }; /** * Disposes the event bus. */ dispose(): void; } /** * Gets the global coordination event bus. * @returns Coordination event bus instance */ export declare function getCoordinationEventBus(): CoordinationEventBus; /** * Sets the global coordination event bus. * @param bus - Event bus instance */ export declare function setCoordinationEventBus(bus: CoordinationEventBus): void; /** * Resets the global coordination event bus. */ export declare function resetCoordinationEventBus(): void; /** * Publishes an event to the global bus. */ export declare function publishEvent(event: E, payload: CoordinationEvents[E]): void; /** * Subscribes to an event on the global bus. */ export declare function subscribeToEvent(event: E, handler: CoordinationEventHandler): () => void; /** * Subscribes to an event once on the global bus. */ export declare function onceEvent(event: E, handler: CoordinationEventHandler): () => void;