import { type DelayOptions } from './delay.js'; /** * Callback invoked when a retry wait begins. * @param determinedInterval - The actual wait time in milliseconds. * @param retryCount - The current retry attempt number (0-based). * @param label - The label identifying this retry operation (or method name for decorators). * @param error - The error that triggered this retry. */ export type RetryOnWaitCallback = (determinedInterval: number, retryCount: number, label: string, error: Error) => void; /** * Callback invoked when all retries are exhausted. * @param retryCount - The total number of retries attempted. * @param error - The first error that triggered retries. * @param label - The label identifying this retry operation (or method name for decorators). */ export type RetryOnGiveUpCallback = (retryCount: number, error: Error, label: string) => void; /** * Options for the standalone retry function. */ export type RetryCallOptions = { /** * Number of retries. * @default 5 */ retries?: number; /** * Time to next retry. * Can be a fixed number or a random range for variability. * @default 3000 */ interval?: number | DelayOptions; /** * With exponential backoff. * Increments the interval exponentially if set to true. * @default true */ withExponentialBackoff?: boolean; /** * Timeout duration for each retry attempt. */ timeout?: number; /** * Fallback value to use if all retries fail. */ fallback?: unknown; /** * Function to log messages during retry attempts. * @param message - The message to log. */ log?: (message: string) => void; /** * Label for identifying this retry operation in logs and callbacks. * @default "retryCall" */ label?: string; onWait?: RetryOnWaitCallback; onGiveUp?: RetryOnGiveUpCallback; }; /** * Options for the retry decorator. * * Extends {@link RetryCallOptions} but binds `this` in `onWait`/`onGiveUp` * to the decorated instance, and uses the method name as the label. */ export type RetryDecoratorOptions = Omit & { onWait?: RetryOnWaitCallback; onGiveUp?: RetryOnGiveUpCallback; }; /** * Retry an async function with exponential backoff. * * Standalone version of the {@link retry} decorator — use this when * you need per-call context (e.g., a progress callback) that cannot * be provided through a class instance. * @param fn - The async function to retry. * @param options - Retry configuration. * @returns The resolved value of `fn`. * @example * ```ts * const result = await retryCall(() => fetchDestination(url), { * retries: 3, * onWait: (interval, count, label) => update(`${label}: retry #${count + 1}`), * }); * ``` */ export declare function retryCall(fn: () => Promise, options?: RetryCallOptions): Promise; /** * Decorator factory that adds retry logic to a method. * @param options - The options for the retry decorator. * @returns A decorator function that can be applied to a method. */ export declare function retry(options?: RetryDecoratorOptions): (method: Function, context: ClassMethodDecoratorContext) => (this: C, ...args: unknown[]) => Promise; /** * Represents an error that occurs when a retry operation times out. */ export declare class RetryTimeoutError extends Error { name: string; }