UNPKG

svelte-firebase-upload

Version:

Enterprise-grade file upload manager for Svelte with Firebase Storage integration, featuring concurrent uploads, resumable transfers, validation, health monitoring, and plugin system

83 lines (82 loc) 2.71 kB
import type { NetworkMonitor, RetryConfig } from '../types.js'; /** * Network monitoring and retry management utility. * * Features: * - Real-time network status monitoring * - Intelligent retry logic with exponential backoff * - Network quality assessment * - Adaptive retry delays based on connection quality * - Circuit breaker pattern for failed operations * * @example * ```typescript * const networkManager = new NetworkManager({ * maxAttempts: 5, * baseDelay: 1000, * backoffMultiplier: 2 * }); * * networkManager.onOffline(() => console.log('Connection lost')); * networkManager.onOnline(() => console.log('Connection restored')); * * // Retry an operation with intelligent backoff * await networkManager.retryWithBackoff( * () => uploadFile(data), * 'file-upload' * ); * ``` */ export declare class NetworkManager implements NetworkMonitor { isOnline: boolean; connectionType?: string; effectiveType?: string; downlink?: number; private _onlineCallbacks; private _offlineCallbacks; private _connection; private _retryConfig; private _boundHandlers; constructor(retryConfig?: Partial<RetryConfig>); onOnline(callback: () => void): void; onOffline(callback: () => void): void; disconnect(): void; calculateRetryDelay(attempts: number): number; /** * Execute an operation with intelligent retry and backoff logic. * * Features circuit breaker pattern, network-aware delays, and automatic * offline handling. * * @param operation - Async operation to retry * @param context - Context string for logging (default: 'unknown') * @returns Promise resolving to operation result * @throws {Error} When all retry attempts are exhausted * * @example * ```typescript * const result = await networkManager.retryWithBackoff( * async () => { * const response = await fetch('/api/upload', { method: 'POST', body }); * if (!response.ok) throw new Error('Upload failed'); * return response.json(); * }, * 'file-upload' * ); * ``` */ retryWithBackoff<T>(operation: () => Promise<T>, context?: string): Promise<T>; shouldRetry(attempts: number, error?: Error): boolean; getNetworkQuality(): 'excellent' | 'good' | 'poor' | 'unknown'; getRecommendedSettings(): { maxConcurrent: number; chunkSize: number; timeout: number; }; waitForNetwork(timeout?: number): Promise<boolean>; private _initializeNetworkMonitoring; private _handleOnline; private _handleOffline; private _handleConnectionChange; private _updateConnectionInfo; }