UNPKG

@simonecoelhosfo/optimizely-mcp-server

Version:

Optimizely MCP Server for AI assistants with integrated CLI tools

102 lines 2.78 kB
/** * Progress Event Emitter - Event-driven progress reporting system * @description Provides a robust event-based progress tracking system that replaces fragile callback mechanisms */ import { EventEmitter } from 'events'; export class ProgressEventEmitter extends EventEmitter { static instance = null; constructor() { super(); this.setMaxListeners(100); // Allow many listeners } /** * Get singleton instance */ static getInstance() { if (!this.instance) { this.instance = new ProgressEventEmitter(); } return this.instance; } /** * Emit entity start event */ emitEntityStart(entity, projectName) { this.emit('progress', { type: 'start', entity, phase: `project_${projectName}_${entity}`, current: 0, projectName }); } /** * Emit entity progress event with count */ emitEntityProgress(entity, count, countType = 'records', isOngoing = true, projectName, total) { this.emit('progress', { type: 'progress', entity, phase: `project_${projectName}_${entity}`, current: 0, // Will be calculated by receiver count, total, countType, isOngoing, projectName }); } /** * Emit entity completion event */ emitEntityComplete(entity, finalCount, countType = 'records', projectName) { this.emit('progress', { type: 'complete', entity, phase: `project_${projectName}_${entity}`, current: 100, total: 100, count: finalCount, countType, isOngoing: false, projectName }); } /** * Emit project start event */ emitProjectStart(projectName) { this.emit('progress', { type: 'start', entity: 'project', phase: 'projects', current: 0, message: `Syncing project: ${projectName}`, projectName }); } /** * Emit error event */ emitError(entity, error, projectName) { this.emit('progress', { type: 'error', entity, phase: `project_${projectName}_${entity}`, current: 0, error, projectName }); } /** * Reset singleton (useful for testing) */ static reset() { if (this.instance) { this.instance.removeAllListeners(); this.instance = null; } } } export default ProgressEventEmitter.getInstance(); //# sourceMappingURL=ProgressEventEmitter.js.map