/**
 * Retry Utility for Network Operations
 *
 * Provides configurable retry logic with exponential/linear backoff
 * for handling transient failures in network operations.
 */
import { type Result } from "./result.js";
/**
 * Options for retry behavior
 */
export interface RetryOptions {
    /** Maximum number of attempts (default: 3) */
    maxAttempts?: number;
    /** Initial delay in milliseconds (default: 1000) */
    delayMs?: number;
    /** Backoff strategy (default: 'exponential') */
    backoff?: "linear" | "exponential" | "none";
    /** Maximum delay cap in milliseconds (default: 30000) */
    maxDelayMs?: number;
    /** Jitter factor 0-1 to randomize delays (default: 0.1) */
    jitter?: number;
    /** Callback on each retry attempt */
    onRetry?: (attempt: number, error: Error, nextDelayMs: number) => void;
    /** Optional predicate to determine if error is retryable */
    shouldRetry?: (error: Error) => boolean;
    /** AbortSignal for cancellation */
    signal?: AbortSignal;
}
/**
 * Retry a function with configurable backoff
 *
 * @example
 * ```typescript
 * // Basic usage
 * const result = await retry(() => fetch('/api/data'));
 *
 * // With options
 * const result = await retry(
 *   () => fetch('/api/data'),
 *   {
 *     maxAttempts: 5,
 *     delayMs: 2000,
 *     backoff: 'exponential',
 *     onRetry: (n, err) => console.log(`Attempt ${n} failed: ${err.message}`)
 *   }
 * );
 * ```
 */
export declare function retry<T>(fn: () => T | Promise<T>, options?: RetryOptions): Promise<T>;
/**
 * Retry a function, returning a Result instead of throwing
 *
 * @example
 * ```typescript
 * const result = await retryResult(() => fetch('/api/data'));
 * if (result.ok) {
 *   console.log('Success:', result.value);
 * } else {
 *   console.error('All retries failed:', result.error);
 * }
 * ```
 */
export declare function retryResult<T>(fn: () => T | Promise<T>, options?: RetryOptions): Promise<Result<T, Error>>;
/**
 * Create a retryable version of a function
 *
 * @example
 * ```typescript
 * const fetchWithRetry = withRetry(
 *   (url: string) => fetch(url),
 *   { maxAttempts: 3 }
 * );
 *
 * const response = await fetchWithRetry('/api/data');
 * ```
 */
export declare function withRetry<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn | Promise<TReturn>, options?: RetryOptions): (...args: TArgs) => Promise<TReturn>;
/**
 * Predefined retry conditions
 */
export declare const RetryConditions: {
    /**
     * Retry on network errors (fetch failures, timeouts)
     */
    networkErrors: (error: Error) => boolean;
    /**
     * Retry on specific HTTP status codes (from fetch Response)
     */
    httpRetryable: (error: Error & {
        status?: number;
    }) => boolean;
    /**
     * Retry on transient WebSocket errors
     */
    websocketErrors: (error: Error) => boolean;
    /**
     * Combine multiple conditions (retry if any match)
     */
    any: (...conditions: Array<(error: Error) => boolean>) => (error: Error) => boolean;
    /**
     * Combine multiple conditions (retry if all match)
     */
    all: (...conditions: Array<(error: Error) => boolean>) => (error: Error) => boolean;
};
/**
 * Preset configurations for common use cases
 */
export declare const RetryPresets: {
    /**
     * Aggressive retry for critical operations
     */
    aggressive: {
        maxAttempts: number;
        delayMs: number;
        backoff: "exponential";
        maxDelayMs: number;
        jitter: number;
    };
    /**
     * Conservative retry for non-critical operations
     */
    conservative: {
        maxAttempts: number;
        delayMs: number;
        backoff: "linear";
        maxDelayMs: number;
        jitter: number;
    };
    /**
     * Fast retry for local operations (short delays)
     */
    fast: {
        maxAttempts: number;
        delayMs: number;
        backoff: "exponential";
        maxDelayMs: number;
        jitter: number;
    };
    /**
     * WebSocket reconnection preset
     */
    websocket: {
        maxAttempts: number;
        delayMs: number;
        backoff: "exponential";
        maxDelayMs: number;
        jitter: number;
        shouldRetry: (error: Error) => boolean;
    };
};
