UNPKG

@casoon/auditmysite

Version:

Professional website analysis suite with robust accessibility testing, Core Web Vitals performance monitoring, SEO analysis, and content optimization insights. Features isolated browser contexts, retry mechanisms, and comprehensive API endpoints for profe

257 lines (256 loc) • 10.7 kB
"use strict"; /** * šŸ”„ EVENT SYSTEM ADAPTERS * * Provides backward compatibility for existing event systems while * internally using the unified PageAnalysisEmitter system. * * šŸŽÆ CONSOLIDATES: * - TestOptions.eventCallbacks -> UnifiedEventCallbacks * - EventDrivenQueueOptions.eventCallbacks -> UnifiedEventCallbacks * - ParallelTestManager callbacks -> UnifiedEventCallbacks * - Direct callback patterns -> UnifiedEventCallbacks * * 🚨 DEPRECATION STRATEGY: * - Mark old systems as @deprecated * - Provide migration guides in comments * - Log deprecation warnings when old systems are used * - Maintain full functionality during transition period */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DeprecationManager = exports.UnifiedEventAdapterFactory = exports.ParallelTestManagerAdapter = exports.EventDrivenQueueAdapter = exports.TestOptionsEventAdapter = void 0; const page_analysis_emitter_1 = require("./page-analysis-emitter"); /** * šŸ”„ TestOptions Event Callbacks Adapter * * Converts existing TestOptions.eventCallbacks to UnifiedEventCallbacks * * @deprecated This adapter maintains compatibility but will be removed in v3.0.0 * Use UnifiedEventCallbacks directly instead. */ class TestOptionsEventAdapter { /** * Convert TestOptions.eventCallbacks to UnifiedEventCallbacks */ static adaptTestOptionsCallbacks(options) { if (!options.eventCallbacks) { return {}; } // Use centralized deprecation manager DeprecationManager.warnOnce('TestOptions.eventCallbacks', 'TestOptions.eventCallbacks is deprecated.\n' + 'Use AccessibilityChecker.setUnifiedEventCallbacks() instead for better performance and consistency.\n' + 'Your existing callbacks will continue to work via compatibility adapter.'); const unified = {}; // Map existing callbacks to unified interface if (options.eventCallbacks.onUrlStarted) { unified.onUrlStarted = options.eventCallbacks.onUrlStarted; } if (options.eventCallbacks.onUrlCompleted) { unified.onUrlCompleted = options.eventCallbacks.onUrlCompleted; } if (options.eventCallbacks.onUrlFailed) { unified.onUrlFailed = options.eventCallbacks.onUrlFailed; } if (options.eventCallbacks.onProgressUpdate) { unified.onProgressUpdate = (stats) => { // Adapt ProgressStats to the format expected by TestOptions const adaptedStats = { total: stats.total, completed: stats.completed, failed: stats.failed, progress: stats.progress, memoryUsage: stats.memoryUsage, activeWorkers: stats.activeWorkers }; options.eventCallbacks.onProgressUpdate(adaptedStats); }; } if (options.eventCallbacks.onQueueEmpty) { unified.onQueueEmpty = options.eventCallbacks.onQueueEmpty; } return unified; } } exports.TestOptionsEventAdapter = TestOptionsEventAdapter; class EventDrivenQueueAdapter { /** * Convert EventDrivenQueue callbacks to UnifiedEventCallbacks * * @deprecated This adapter will be removed in v3.0.0 */ static adaptEventDrivenQueueCallbacks(callbacks) { // Use centralized deprecation manager DeprecationManager.warnOnce('EventDrivenQueue', 'EventDrivenQueue callback pattern is deprecated.\n' + 'Replace EventDrivenQueue with PageAnalysisEmitter.\n' + 'Use unified callback interface instead of separate queue system.'); const unified = {}; // Direct mappings (these interfaces are mostly compatible) if (callbacks.onUrlAdded) { unified.onUrlAdded = (url, priority) => { callbacks.onUrlAdded(url, priority || 0); }; } if (callbacks.onUrlStarted) unified.onUrlStarted = callbacks.onUrlStarted; if (callbacks.onUrlCompleted) unified.onUrlCompleted = callbacks.onUrlCompleted; if (callbacks.onUrlFailed) unified.onUrlFailed = callbacks.onUrlFailed; if (callbacks.onUrlRetrying) unified.onUrlRetrying = callbacks.onUrlRetrying; if (callbacks.onQueueEmpty) unified.onQueueEmpty = callbacks.onQueueEmpty; if (callbacks.onProgressUpdate) { unified.onProgressUpdate = callbacks.onProgressUpdate; } if (callbacks.onError) unified.onError = callbacks.onError; if (callbacks.onShortStatus) unified.onShortStatus = callbacks.onShortStatus; if (callbacks.onBackpressureActivated) unified.onBackpressureActivated = callbacks.onBackpressureActivated; if (callbacks.onBackpressureDeactivated) unified.onBackpressureDeactivated = callbacks.onBackpressureDeactivated; if (callbacks.onResourceWarning) { unified.onResourceWarning = (usage, limit, type) => { callbacks.onResourceWarning(usage, limit); }; } if (callbacks.onResourceCritical) { unified.onResourceCritical = (usage, limit, type) => { callbacks.onResourceCritical(usage, limit); }; } if (callbacks.onGarbageCollection) unified.onGarbageCollection = callbacks.onGarbageCollection; return unified; } } exports.EventDrivenQueueAdapter = EventDrivenQueueAdapter; class ParallelTestManagerAdapter { /** * Convert ParallelTestManager callbacks to UnifiedEventCallbacks * * @deprecated This adapter will be removed in v3.0.0 */ static adaptParallelTestManagerCallbacks(callbacks) { // Use centralized deprecation manager DeprecationManager.warnOnce('ParallelTestManager', 'ParallelTestManager callback pattern is deprecated.\n' + 'Replace ParallelTestManager with PageAnalysisEmitter.\n' + 'Use unified event system for better performance and consistency.'); const unified = {}; if (callbacks.onTestStart) unified.onUrlStarted = callbacks.onTestStart; if (callbacks.onTestComplete) { unified.onUrlCompleted = (url, result, duration) => { callbacks.onTestComplete(url, result); }; } if (callbacks.onTestError) { unified.onUrlFailed = (url, error, attempts) => { callbacks.onTestError(url, error); }; } if (callbacks.onProgressUpdate) unified.onProgressUpdate = callbacks.onProgressUpdate; if (callbacks.onQueueEmpty) unified.onQueueEmpty = callbacks.onQueueEmpty; return unified; } } exports.ParallelTestManagerAdapter = ParallelTestManagerAdapter; /** * šŸŽÆ UNIFIED ADAPTER FACTORY * * Central factory for creating unified event callbacks from any legacy system */ class UnifiedEventAdapterFactory { /** * Create unified callbacks from various legacy sources * * BACKWARD COMPATIBLE: Supports all existing callback patterns */ static createUnifiedCallbacks(sources) { let unified = {}; // Merge callbacks from all sources (later sources override earlier ones) if (sources.testOptions) { const testOptionsCallbacks = TestOptionsEventAdapter.adaptTestOptionsCallbacks(sources.testOptions); unified = { ...unified, ...testOptionsCallbacks }; } if (sources.eventDrivenQueue) { const queueCallbacks = EventDrivenQueueAdapter.adaptEventDrivenQueueCallbacks(sources.eventDrivenQueue); unified = { ...unified, ...queueCallbacks }; } if (sources.parallelTestManager) { const managerCallbacks = ParallelTestManagerAdapter.adaptParallelTestManagerCallbacks(sources.parallelTestManager); unified = { ...unified, ...managerCallbacks }; } if (sources.direct) { unified = { ...unified, ...sources.direct }; } return unified; } /** * Create unified emitter with legacy compatibility * * This is the main factory method that should be used throughout the codebase */ static createUnifiedEmitter(options = {}) { // Create unified callbacks from test options const callbacks = options.testOptions ? TestOptionsEventAdapter.adaptTestOptionsCallbacks(options.testOptions) : {}; // Create emitter with unified configuration const emitter = new page_analysis_emitter_1.PageAnalysisEmitter({ verbose: options.verbose || options.testOptions?.verbose || false, enableResourceMonitoring: options.enableResourceMonitoring ?? true, enableBackpressure: options.enableBackpressure ?? true, maxConcurrent: options.maxConcurrent || options.testOptions?.maxConcurrent || 3, maxRetries: options.maxRetries || options.testOptions?.maxRetries || 3, callbacks }); return emitter; } } exports.UnifiedEventAdapterFactory = UnifiedEventAdapterFactory; /** * 🚨 DEPRECATION UTILITIES * * Utilities for managing deprecation warnings and migration guides */ class DeprecationManager { /** * Show deprecation warning once per system per session */ static warnOnce(systemName, message) { // Check if deprecation warnings should be suppressed const suppressWarnings = process.env.NODE_ENV === 'test' || process.env.CI === 'true' || process.env.NODE_ENV === 'production' || process.env.AUDITMYSITE_SUPPRESS_DEPRECATIONS === 'true'; if (!this.warnedSystems.has(systemName) && !suppressWarnings) { console.warn(` 🚨 DEPRECATION WARNING: ${systemName} ${message} šŸ“š Documentation: https://auditmysite.com/docs/v2-migration 🚫 Migration Guide: https://auditmysite.com/docs/unified-events `); this.warnedSystems.add(systemName); } } /** * Get list of systems that have shown deprecation warnings */ static getWarnings() { return Array.from(this.warnedSystems); } /** * Clear warning cache (useful for tests) */ static clearWarnings() { this.warnedSystems.clear(); } } exports.DeprecationManager = DeprecationManager; DeprecationManager.warnedSystems = new Set(); //# sourceMappingURL=event-system-adapters.js.map