/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ import type { QueryObserverResult } from "@tanstack/react-query"; /** The most a view waits before it tries a read again after its first * failure; each failure in a row doubles it, up to {@link RECOVERY_MAX_MS}. */ export declare const RECOVERY_FIRST_MS = 1000; /** The most a view waits before it tries a read again. */ export declare const RECOVERY_MAX_MS = 30000; /** * How long a view waits before it tries a failed read again. * * @remarks * The wait backs off: at most 1 s after the first failure in a row, doubling * with each failure after it, up to 30 s. It is a random point in the second * half of that: 0.5–1 s after the first failure, 1–2 s after the second, and * 15–30 s from the sixth on. So views that failed together try again apart, * and none tries again sooner than half its backoff. * * @param failures - How many times in a row the read has failed, from 1 * @param random - A draw from [0, 1); `Math.random` unless a test gives one * @returns The wait, in milliseconds */ export declare function recoveryDelay(failures: number, random?: () => number): number; /** What {@link useQueryRecovery} reads of a query, as `useQuery` returns it. */ export type RecoveringQuery = Pick, "error" | "errorUpdatedAt" | "dataUpdatedAt" | "fetchStatus" | "refetch">; /** * Tries a failed query again by itself, for as long as the view is mounted, * and gives the failure to show meanwhile. * * @remarks * A query that failed fetches again only when the window regains focus or the * view mounts again, so a view on a screen no one touches would stay on the * failure. This fetches it again after {@link recoveryDelay}'s wait for each * failure in a row, once the query has stopped fetching. * * TanStack clears the error of a query that holds no data while it fetches * again, so a view that showed the query's error would go back to loading at * every try. The failure this gives stands until a fetch reads: the latest, * through each try. * * @param query - The query to keep trying while it fails * @returns The failure to show, or `null` while the query has not failed since * it last read */ export declare function useQueryRecovery(query: RecoveringQuery): Error | null; //# sourceMappingURL=recovery.d.ts.map