/** * @file Smart Prefetching Utilities * @description Intelligent prefetching with network awareness and connection quality detection * for optimal performance. Pure TypeScript utilities without React dependencies. */ /** * Connection quality type based on Network Information API */ export type ConnectionType = '4g' | '3g' | '2g' | 'slow-2g' | 'unknown'; /** * Network information from the Navigator.connection API */ export interface NetworkInformation { effectiveType?: ConnectionType; downlink?: number; rtt?: number; saveData?: boolean; } /** * Configuration for a prefetch target */ export interface PrefetchTarget { /** Query key for data prefetching */ queryKey: readonly unknown[]; /** Data fetcher function */ queryFn: () => Promise; /** Route module loader for code splitting */ moduleLoader?: () => Promise; /** Priority (higher = more important, 0-10) */ priority?: number; /** Stale time for prefetched data (ms) */ staleTime?: number; } /** * Options for smart prefetch manager */ export interface SmartPrefetchOptions { /** Skip prefetch on slow connections or data saver mode */ respectDataSaver?: boolean; /** Max concurrent prefetches to avoid overwhelming network */ maxConcurrent?: number; /** Minimum connection quality required for prefetching */ minConnectionQuality?: ConnectionType; } /** * Get current network information */ export declare function getNetworkInfo(): NetworkInformation; /** * Check if current connection meets minimum quality requirement */ export declare function meetsMinimumQuality(current: ConnectionType, minimum: ConnectionType): boolean; /** * Check if prefetching should be allowed based on network conditions */ export declare function shouldAllowPrefetch(options?: { respectDataSaver?: boolean; minConnectionQuality?: ConnectionType; }): boolean; /** * Manages intelligent prefetching with network awareness and concurrency control */ export declare class SmartPrefetchManager { private prefetchedKeys; private activePrefetches; private options; constructor(options?: SmartPrefetchOptions); /** * Execute prefetch for a target */ prefetch(target: PrefetchTarget): Promise; /** * Prefetch multiple targets during idle time */ prefetchOnIdle(targets: PrefetchTarget[]): void; /** * Clear prefetch cache (for testing or reset) */ clearCache(): void; /** * Get current prefetch stats */ getStats(): { prefetchedCount: number; activeCount: number; maxConcurrent: number; }; /** * Check if prefetching should happen based on network and concurrency */ private shouldPrefetch; } /** * Helper to create type-safe prefetch configurations */ export declare function createPrefetchConfig(queryKey: readonly unknown[], queryFn: () => Promise, options?: Omit): PrefetchTarget; /** * Create a debounced prefetch function */ export declare function createDebouncedPrefetch(manager: SmartPrefetchManager, delay?: number): (target: PrefetchTarget) => void; /** * Monitor network quality changes */ export declare function monitorNetworkQuality(callback: (info: NetworkInformation) => void): () => void;