/** * EventManager - Internal event system for storage operations * * Manages event callbacks and emission for all storage operations. * This is an internal component - applications register callbacks via * StorageService config, which passes them to EventManager. * * Features: * - Register callbacks for storage events * - Emit events with rich payloads * - Async callback execution * - Error handling for callback failures (don't break main flow) * - Support for multiple callbacks per event type * - Event buffering for bulk operations * * @example * ```ts * const eventManager = new EventManager({ logger }); * * // Register callbacks * eventManager.on(STORAGE_EVENT_TYPE.FileUploaded, async (payload) => { * await saveToDatabase(payload.metadata); * }); * * // Emit events * await eventManager.emit(STORAGE_EVENT_TYPE.FileUploaded, { * type: STORAGE_EVENT_TYPE.FileUploaded, * timestamp: new Date(), * metadata: fileMetadata, * }); * ``` */ import type { StorageEventManagerConfig, StorageEventPayload, STORAGE_EVENT_TYPE, StorageEventCallback } from '@plyaz/types/storage'; /** * EventManager - Internal event system for storage operations */ export declare class EventManager { private readonly callbacks; private readonly logger?; private readonly enableBuffering; private readonly bufferFlushInterval; private eventBuffer; private bufferTimer?; constructor(config?: StorageEventManagerConfig); /** * Register a callback for an event type * Multiple callbacks can be registered for the same event * * @param eventType - The event type to listen for * @param callback - The callback to execute * @returns Unsubscribe function */ on(eventType: STORAGE_EVENT_TYPE, callback: StorageEventCallback): () => void; /** * Unregister a callback for an event type * * @param eventType - The event type * @param callback - The callback to remove */ off(eventType: STORAGE_EVENT_TYPE, callback: StorageEventCallback): void; /** * Emit an event and execute all registered callbacks * Callbacks are executed asynchronously and errors are caught * * @param eventType - The event type to emit * @param payload - The event payload */ emit(eventType: STORAGE_EVENT_TYPE, payload: StorageEventPayload): Promise; /** * Emit multiple events at once (for bulk operations) * * @param payloads - Array of event payloads */ emitBatch(payloads: StorageEventPayload[]): Promise; /** * Execute all callbacks for an event type */ private executeCallbacks; /** * Get count of registered callbacks for an event type */ getCallbackCount(eventType: STORAGE_EVENT_TYPE): number; /** * Get total number of registered callbacks across all event types */ getTotalCallbackCount(): number; /** * Check if any callbacks are registered for an event type */ hasCallbacks(eventType: STORAGE_EVENT_TYPE): boolean; /** * Remove all callbacks for an event type */ removeAllCallbacks(eventType: STORAGE_EVENT_TYPE): void; /** * Remove all callbacks for all event types */ removeAllEventCallbacks(): void; /** * Start buffer flushing timer */ private startBufferFlushing; /** * Stop buffer flushing timer */ private stopBufferFlushing; /** * Flush buffered events */ private flushBuffer; /** * Manually flush the event buffer */ flush(): Promise; /** * Get current buffer size */ getBufferSize(): number; /** * Get event statistics */ getStatistics(): { totalCallbacks: number; eventTypes: number; bufferSize: number; callbacksByType: Record; }; /** * Cleanup resources and flush remaining events */ destroy(): Promise; }