/** * Base Channel Controller * * Abstract base class for channel event handlers. * Each controller manages a specific scope of channels (e.g., 'upload:', 'generate:', 'system'). * * @example * ```typescript * class FilesChannelController extends BaseChannelController { * constructor() { * super({ * scope: 'files', * patterns: ['upload:', 'uploads', 'generate:'], * }); * } * * initialize(broadcaster: StreamBroadcasterInterface): void { * this.unsubscribers.push( * CoreEventManager.on('files:upload:progress', event => { * broadcaster.broadcastToChannel(`upload:${event.data.fileId}`, { * event: 'progress', * data: this.createResponse(event.data, `upload:${event.data.fileId}`), * }); * }) * ); * } * } * ``` */ import { CoreLogger } from '@plyaz/logger'; import type { ChannelControllerConfig, StreamBroadcasterInterface, StreamResponse, StreamErrorEvent } from '@plyaz/types/core'; /** * BaseChannelController - Abstract base for channel event handlers * * Features: * - Pattern matching for channels * - Response formatting helpers (consistent with API patterns) * - Subscription management with automatic cleanup * - Error response using standard ErrorResponse format */ export declare abstract class BaseChannelController { /** Channel scope (e.g., 'upload', 'generate', 'system') */ readonly scope: string; /** Channel patterns this controller handles */ readonly patterns: string[]; /** Whether controller is enabled */ readonly enabled: boolean; /** Logger instance */ protected readonly logger: CoreLogger; /** Unsubscribe functions for cleanup */ protected unsubscribers: Array<() => void>; constructor(config: ChannelControllerConfig); /** * Initialize event subscriptions. * Called when the controller is registered with the broadcaster. * * @param broadcaster - The broadcaster to send messages through */ abstract initialize(broadcaster: StreamBroadcasterInterface): void; /** * Check if this controller handles a given channel. * * @param channel - Channel name to check * @returns true if this controller handles the channel */ handlesChannel(channel: string): boolean; /** * Get all patterns this controller handles. */ getPatterns(): string[]; /** * Create a success response. * * @param data - Response data payload * @param channel - Channel this response is for * @param message - Human-readable message (default: 'Success') * @returns Formatted StreamResponse */ protected createResponse(data: T, channel: string, message?: string): StreamResponse; /** * Create an error response using standard ErrorResponse format. * * @param errors - Array of error details * @param channel - Channel this error occurred on * @returns Formatted StreamErrorEvent */ protected createErrorResponse(errors: Array<{ errorCode: string; message: string; field?: string; }>, channel: string): StreamErrorEvent; /** * Create a single error response. * * @param errorCode - Error code * @param message - Error message * @param channel - Channel this error occurred on * @param field - Optional field that caused the error * @returns Formatted StreamErrorEvent */ protected createSingleError(errorCode: string, message: string, channel: string, field?: string): StreamErrorEvent; /** * Dispose controller and cleanup subscriptions. */ dispose(): void; /** * Add an unsubscribe function to be called on dispose. * * @param unsub - Unsubscribe function */ protected addUnsubscriber(unsub: () => void): void; } //# sourceMappingURL=BaseChannelController.d.ts.map