UNPKG

@bramato/openrouter-mock-generator

Version:

AI-powered mock data generator using OpenRouter API with JSON mode support

259 lines 8.19 kB
"use strict"; /** * ProgressManager - Gestore centralizzato per le progress bar * * Fornisce progress bar visive per diverse operazioni: * - Generazione dati mock * - Processing immagini * - Upload su cloud storage * - Operazioni batch */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgressManager = void 0; const cliProgress = __importStar(require("cli-progress")); class ProgressManager { constructor() { this.bars = new Map(); this.multiBar = null; this.isMultiMode = false; } /** * Crea una progress bar singola */ createSingleBar(config) { const format = config.format || `${config.title} |{bar}| {percentage}% | {value}/{total} | ETA: {eta}s`; const bar = new cliProgress.SingleBar({ format, hideCursor: config.hideCursor ?? true, clearOnComplete: config.clearOnComplete ?? false, stopOnComplete: config.stopOnComplete ?? true, barCompleteChar: '█', barIncompleteChar: '░', barsize: 30, }, cliProgress.Presets.shades_classic); bar.start(config.total, 0); return bar; } /** * Inizializza modalità multi-bar per operazioni parallele */ initMultiBar() { this.multiBar = new cliProgress.MultiBar({ hideCursor: true, clearOnComplete: false, format: '{title} |{bar}| {percentage}% | {value}/{total} | {status}', barCompleteChar: '█', barIncompleteChar: '░', barsize: 25, }, cliProgress.Presets.shades_classic); this.isMultiMode = true; } /** * Aggiunge una progress bar al multi-bar */ addBar(id, config) { if (!this.multiBar) { console.warn('MultiBar not initialized. Call initMultiBar() first.'); return null; } const bar = this.multiBar.create(config.total, 0, { title: config.title.padEnd(20), status: 'Avvio...', }); this.bars.set(id, bar); return bar; } /** * Aggiorna progress di una specifica bar */ updateBar(id, value, payload) { const bar = this.bars.get(id); if (bar) { bar.update(value, payload); } } /** * Incrementa progress di una specifica bar */ incrementBar(id, increment = 1, payload) { const bar = this.bars.get(id); if (bar) { bar.increment(increment, payload); } } /** * Imposta una bar come completata */ completeBar(id, successMessage) { const bar = this.bars.get(id); if (bar) { bar.update(bar.getTotal(), { status: successMessage || '✅ Completato', }); } } /** * Imposta una bar come fallita */ failBar(id, errorMessage) { const bar = this.bars.get(id); if (bar) { bar.update(bar.value || 0, { status: `❌ ${errorMessage || 'Errore'}`, }); } } /** * Ferma tutte le progress bar */ stopAll() { if (this.multiBar) { this.multiBar.stop(); this.multiBar = null; } this.bars.clear(); this.isMultiMode = false; } /** * Progress bar per generazione mock data */ createMockGenerationBar(total) { return this.createSingleBar({ title: '🎲 Generando dati mock', total, format: '🎲 Generando dati mock |{bar}| {percentage}% | {value}/{total} items | Tempo: {duration}s | ETA: {eta}s', }); } /** * Progress bar per processing immagini */ createImageProcessingBar(total) { return this.createSingleBar({ title: '🖼️ Processing immagini', total, format: '🖼️ Processing immagini |{bar}| {percentage}% | {value}/{total} immagini | {status}', }); } /** * Progress bar per upload cloud */ createUploadBar(total) { return this.createSingleBar({ title: '☁️ Upload immagini', total, format: '☁️ Upload immagini |{bar}| {percentage}% | {value}/{total} | Velocità: {speed}', }); } /** * Setup completo per pipeline di processing */ setupProcessingPipeline(mockCount, imageCount) { this.initMultiBar(); const mockBar = mockCount > 0 ? this.addBar('mock', { title: '🎲 Dati Mock', total: mockCount, }) : null; const imageBar = imageCount > 0 ? this.addBar('images', { title: '🖼️ Immagini AI', total: imageCount, }) : null; const uploadBar = imageCount > 0 ? this.addBar('upload', { title: '☁️ Upload Cloud', total: imageCount, }) : null; return { mockBar, imageBar, uploadBar }; } /** * Utility per mostrare progress con callback */ static async withProgress(config, operation) { const manager = new ProgressManager(); const bar = manager.createSingleBar(config); try { const updateProgress = (value, payload) => { bar.update(value, payload); }; const result = await operation(updateProgress); bar.stop(); return result; } catch (error) { bar.stop(); throw error; } } /** * Progress bar animata per operazioni indeterminate */ createSpinner(title) { const spinner = new cliProgress.SingleBar({ format: `${title} {spinner} | {duration}s`, hideCursor: true, barCompleteChar: '█', barIncompleteChar: '░', }, cliProgress.Presets.shades_classic); let step = 0; const spinnerChars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; spinner.start(100, 0); const interval = setInterval(() => { spinner.update(step % 100, { spinner: spinnerChars[step % spinnerChars.length], }); step++; }, 100); // Store interval per cleanup spinner._interval = interval; return spinner; } /** * Ferma spinner animato */ stopSpinner(spinner) { if (spinner._interval) { clearInterval(spinner._interval); } spinner.stop(); } } exports.ProgressManager = ProgressManager; exports.default = ProgressManager; //# sourceMappingURL=progress-manager.js.map