/** * Retry-with-backoff for the statuses Neon documents as always safe to replay. The raw * layer does no retries; the ergonomic client opts in via `retries`. * * The scheduling decisions are pure functions so they can be tested directly, without * fake timers or a stopwatch: {@link parseRetryAfterMs} reads the header, * {@link backoffMs} picks a delay, and {@link nextRetryDelayMs} decides whether a retry * is worth waiting for at all. */ import { type Deadline } from "./deadline.js"; export interface RawOutcome { error?: unknown; response?: Response | undefined; } /** Ceiling on generated backoff, and on how long a `Retry-After` is worth honouring. */ export declare const MAX_RETRY_WAIT_MS = 10000; /** * Client-wide `retries`. `NaN` and `Infinity` make `attempt >= retries` always false, * so a 429 would poll forever; reject them here the way `requestTimeoutMs` is rejected. */ export declare function resolveRetries(retries: number | undefined): number; /** * `Retry-After` in milliseconds, or `undefined` when absent or unparseable. * * The header comes in two forms and only one of them is a number. Reading just the * numeric form leaves an HTTP-date parsing as `NaN`, which silently falls through to * generated backoff — retrying far sooner than the server asked. */ export declare function parseRetryAfterMs(header: string | null | undefined, now: number): number | undefined; /** Exponential backoff with full jitter: base 250ms, capped at {@link MAX_RETRY_WAIT_MS}. */ export declare function backoffMs(attempt: number, random?: () => number): number; /** * How long to wait before the next attempt, or `undefined` to stop retrying. * * `Retry-After` is the server's requested **minimum** delay, so it is never shortened — * retrying earlier than instructed is worse than not retrying at all. When honouring it * would cost more than {@link MAX_RETRY_WAIT_MS}, or more budget than the call has left, * the answer is to stop and let the caller see the real `423`/`429`/`503` rather than to * wait for minutes or to report a timeout that hides the status. */ export declare function nextRetryDelayMs(attempt: number, retryAfterMs: number | undefined, remainingMs: number, random?: () => number): number | undefined; /** * Run `exec` up to `retries + 1` times, retrying only on `423`, `429` and `503`. * Non-retryable errors and successes return immediately, as does a cancelled deadline — * the caller inspects {@link Deadline.source} to tell cancellation from the last result. */ export declare function withRetries(exec: () => Promise, retries: number, deadline: Deadline): Promise; //# sourceMappingURL=retry.d.ts.map