/** * Core Event Manager * * Type-safe event system for the Plyaz ecosystem. * Services emit events → Store, API cache, and UI subscribe independently. * * @example * ```typescript * import { CoreEventManager, CORE_EVENTS } from '@plyaz/core/events'; * * // Type-safe emission (using CORE_EVENTS constants) * CoreEventManager.emit(CORE_EVENTS.API.REQUEST_ERROR, { * method: 'GET', * url: '/api/users', * requestId: '123', * error: new Error('Failed'), * duration: 500, * }); * * // Type-safe subscription * CoreEventManager.on(CORE_EVENTS.AUTH.LOGIN, (event) => { * console.log(event.data.userId); // Typed! * }); * * // Custom events (with generic type) * CoreEventManager.emit('custom:event', { custom: 'data' }); * ``` */ import type { CoreEventPayloadMap, CoreEventScopeType, CoreEvent } from '@plyaz/types/core'; declare class CoreEventManagerClass { private emitter; private subscriptions; constructor(); /** * Emit an event * * @param eventType - Event type from CORE_EVENTS or custom string * @param data - Event payload (type-safe when using CORE_EVENTS) * * @example * ```typescript * // Type-safe with CORE_EVENTS * CoreEventManager.emit(CORE_EVENTS.AUTH.LOGIN, { userId: '123', method: 'email' }); * * // Custom event * CoreEventManager.emit('custom:event', { custom: 'data' }); * ``` */ emit(eventType: T, data: CoreEventPayloadMap[T]): boolean; emit(eventType: string, data?: TData): boolean; /** * Subscribe to an event * * @param eventType - Event type from CORE_EVENTS or custom string * @param handler - Event handler (type-safe when using CORE_EVENTS) * @returns Unsubscribe function * * @example * ```typescript * // Type-safe with CORE_EVENTS * const unsub = CoreEventManager.on(CORE_EVENTS.AUTH.LOGIN, (event) => { * console.log(event.data.userId); // Typed! * }); * * // Custom event * CoreEventManager.on('custom:event', (event) => { * console.log(event.data.custom); * }); * ``` */ on(eventType: T, handler: (event: CoreEvent) => void): () => void; on(eventType: string, handler: (event: CoreEvent) => void): () => void; /** * Subscribe once to an event * * @param eventType - Event type from CORE_EVENTS or custom string * @param handler - Event handler * @returns Unsubscribe function */ once(eventType: T, handler: (event: CoreEvent) => void): () => void; once(eventType: string, handler: (event: CoreEvent) => void): () => void; /** * Subscribe to all events in a scope * * @param scope - Event scope to listen to (e.g., CoreEventScope.AUTH) * @param handler - Event handler * @returns Unsubscribe function * * @example * ```typescript * CoreEventManager.onScope(CoreEventScope.AUTH, (event) => { * // Handles auth:login, auth:logout, auth:tokenRefresh, etc. * console.log(`Auth event: ${event.type}`, event.data); * }); * ``` */ onScope(scope: TScope, handler: (event: CoreEvent) => void): () => void; /** * Remove a specific handler from an event * * @param eventType - Event type * @param handler - Handler to remove */ off(eventType: string, handler: (event: CoreEvent) => void): void; /** * Dispose all subscriptions */ dispose(): void; /** * Generate correlation ID for event tracing */ private getCorrelationId; } export declare const CoreEventManager: CoreEventManagerClass; export {}; //# sourceMappingURL=CoreEventManager.d.ts.map