/** * AdapterRegistry - Manages storage adapters with health-based selection and failover * * Responsibilities: * - Register/unregister adapters with priority levels * - Select healthy adapters based on priority and health status * - Automatic failover to backup adapters on failure * - Health monitoring and status tracking * - Circuit breaker integration for failed adapters * * Selection Logic: * - Sort adapters by health status (healthy > degraded > unknown) * - Within same health tier, sort by priority (higher = preferred) * - Skip disabled or unhealthy adapters * - Throw error if no healthy adapters available * * @example * ```ts * const registry = new AdapterRegistry({ logger }); * registry.register(cloudflareAdapter); * registry.register(supabaseAdapter); * * const primary = await registry.selectHealthyAdapter(); * const fallback = await registry.getFallbackAdapter(primary.name); * ``` */ import type { StorageAdapterRegistryConfig } from '@plyaz/types/storage'; import type { BaseStorageAdapter } from '../adapters/base/BaseStorageAdapter'; import { ADAPTER_HEALTH_STATUS } from '@plyaz/types/storage'; /** * Adapter health information */ interface AdapterHealthInfo { status: ADAPTER_HEALTH_STATUS; lastCheck: Date; consecutiveFailures: number; lastError?: string; } /** * AdapterRegistry - Manages storage adapters with health-based selection */ export declare class AdapterRegistry { private readonly adapters; private readonly healthInfo; private readonly logger?; private readonly healthCheckInterval; private healthCheckTimer?; private readonly enableAutoHealthCheck; constructor(config?: StorageAdapterRegistryConfig); /** * Register a storage adapter * Initializes health tracking and runs initial health check */ register(adapter: BaseStorageAdapter): void; /** * Unregister a storage adapter */ unregister(adapterName: string): boolean; /** * Get adapter by name */ getAdapter(name: string): BaseStorageAdapter | undefined; /** * Get all registered adapters */ getAllAdapters(): BaseStorageAdapter[]; /** * Get adapter health information */ getAdapterHealth(name: string): AdapterHealthInfo | undefined; /** * Select the best available adapter based on health and priority * Returns the highest priority adapter that is healthy or degraded * * @throws StoragePackageError if no healthy adapters available */ selectHealthyAdapter(): Promise; /** * Get fallback adapter (next best after excluding specified adapter) * * @param excludeAdapterName - Adapter to exclude from selection * @returns Fallback adapter or undefined if none available */ getFallbackAdapter(excludeAdapterName: string): Promise; /** * Check health of a specific adapter */ private checkAdapterHealth; /** * Get sorted list of healthy adapters * Sorted by: health status (healthy > degraded > unknown), then priority (higher first) */ private getSortedHealthyAdapters; /** * Start automatic health checks */ private startHealthChecks; /** * Stop automatic health checks */ private stopHealthChecks; /** * Run health checks on all registered adapters */ private runHealthChecks; /** * Manually trigger health check for all adapters */ checkAllAdaptersHealth(): Promise; /** * Manually trigger health check for specific adapter */ checkSpecificAdapterHealth(adapterName: string): Promise; /** * Get health summary for all adapters */ getHealthSummary(): { total: number; healthy: number; degraded: number; unhealthy: number; unknown: number; adapters: Array<{ name: string; type: string; priority: number; enabled: boolean; status: ADAPTER_HEALTH_STATUS; lastCheck: Date; consecutiveFailures: number; lastError?: string; }>; }; /** * Cleanup resources */ destroy(): void; } export {};