@jay-js/system
Version:
A powerful and flexible TypeScript library for UI, state management, lazy loading, routing and managing draggable elements in modern web applications.
56 lines (55 loc) • 1.93 kB
TypeScript
import type { TQueryKey } from "./types.js";
/**
* Execute fetch with deduplication
* If same key is already fetching, return existing promise
*
* @param key Query key
* @param fetcher Function to fetch data
* @param onFinally Callback to run when fetch completes
* @returns Promise with fetched data
*/
export declare function executeFetch<TData>(key: string, fetcher: (signal: AbortSignal) => Promise<TData>, onFinally?: () => void): Promise<TData>;
/**
* Cancel in-flight request for a key
*
* @param key Query key
*/
export declare function cancelFetch(key: string): void;
/**
* Execute fetch with retry logic
*
* @param fetcher Function to fetch data
* @param retry Number of retries or boolean
* @param retryDelay Delay between retries in ms or function
* @param signal AbortSignal to cancel request
* @returns Promise with fetched data
*/
export declare function executeWithRetry<TData>(fetcher: (signal: AbortSignal) => Promise<TData>, retry: number | boolean, retryDelay: number | ((attempt: number) => number), signal: AbortSignal): Promise<TData>;
/**
* Default retry delay with exponential backoff
*
* @param attempt Current attempt number
* @returns Delay in milliseconds
*/
export declare function defaultRetryDelay(attempt: number): number;
/**
* Setup window focus refetch listener
*
* @param callback Function to call when window gains focus
* @returns Cleanup function to remove listener
*/
export declare function setupFocusRefetch(callback: () => void): () => void;
/**
* Setup reconnect refetch listener
*
* @param callback Function to call when network reconnects
* @returns Cleanup function to remove listener
*/
export declare function setupReconnectRefetch(callback: () => void): () => void;
/**
* Resolve query key (static or reactive)
*
* @param key Query key
* @returns Resolved string key
*/
export declare function resolveQueryKey(key: TQueryKey): string;