/** * @file Prefetch Queue * @description Priority-based prefetch queue with rate limiting, deduplication, * and network-aware throttling. * * Features: * - Priority-based scheduling * - Rate limiting * - Deduplication * - Network-aware throttling * - Progress tracking * - Cancellation support */ /** * Prefetch priority levels */ export type PrefetchPriority = 'critical' | 'high' | 'normal' | 'low' | 'idle'; /** * Prefetch item status */ export type PrefetchStatus = 'pending' | 'loading' | 'completed' | 'failed' | 'cancelled'; /** * Prefetch item */ export interface PrefetchItem { id: string; url: string; type: 'document' | 'script' | 'style' | 'image' | 'font' | 'fetch'; priority: PrefetchPriority; status: PrefetchStatus; createdAt: number; startedAt?: number; completedAt?: number; size?: number; error?: Error; retryCount: number; metadata?: Record; } /** * Queue configuration */ export interface PrefetchQueueConfig { /** Maximum concurrent prefetches */ maxConcurrent: number; /** Maximum queue size */ maxQueueSize: number; /** Maximum retry attempts */ maxRetries: number; /** Retry delay in ms */ retryDelay: number; /** Enable network-aware throttling */ networkAware: boolean; /** Concurrent limits by network type */ concurrentByNetwork: Record; /** Enable deduplication */ deduplicate: boolean; /** Time-to-live for completed items in ms */ completedTTL: number; /** Enable priority boosting for aged items */ priorityBoost: boolean; /** Age threshold for priority boost in ms */ boostAgeThreshold: number; /** Debug mode */ debug: boolean; } /** * Queue statistics */ export interface QueueStats { pending: number; loading: number; completed: number; failed: number; cancelled: number; totalSize: number; averageLoadTime: number; } /** * Queue event types */ export type QueueEventType = 'enqueue' | 'start' | 'complete' | 'fail' | 'cancel' | 'drain'; /** * Queue event listener */ export type QueueEventListener = (type: QueueEventType, item: PrefetchItem) => void; /** * Priority-based prefetch queue */ export declare class PrefetchQueue { private config; private items; private activeCount; private listeners; private cleanupTimer; private idCounter; private paused; constructor(config?: Partial); /** * Enqueue a prefetch item */ enqueue(url: string, options?: { type?: PrefetchItem['type']; priority?: PrefetchPriority; metadata?: Record; }): string | null; /** * Enqueue multiple items */ enqueueMany(items: Array<{ url: string; type?: PrefetchItem['type']; priority?: PrefetchPriority; metadata?: Record; }>): string[]; /** * Cancel a prefetch item */ cancel(id: string): boolean; /** * Cancel all pending items */ cancelAll(): number; /** * Pause the queue */ pause(): void; /** * Resume the queue */ resume(): void; /** * Check if paused */ isPaused(): boolean; /** * Get item by ID */ getItem(id: string): PrefetchItem | undefined; /** * Get item by URL */ findByUrl(url: string): PrefetchItem | undefined; /** * Check if URL is queued or completed */ has(url: string): boolean; /** * Check if URL was successfully prefetched */ isPrefetched(url: string): boolean; /** * Get queue statistics */ getStats(): QueueStats; /** * Subscribe to queue events */ subscribe(listener: QueueEventListener): () => void; /** * Clear the queue */ clear(): void; /** * Destroy the queue */ destroy(): void; private processQueue; private getNextItem; private compareItems; private executeItem; private prefetch; private prefetchDocument; private prefetchScript; private prefetchStyle; private prefetchImage; private prefetchFont; private prefetchFetch; private getMaxConcurrent; private getNetworkInfo; private getPendingCount; private startCleanup; private cleanup; private notifyListeners; private generateId; private log; } /** * Get or create the global prefetch queue */ export declare function getPrefetchQueue(config?: Partial): PrefetchQueue; /** * Reset the queue instance */ export declare function resetPrefetchQueue(): void;