/** * QA360 Retry Module * * P0: Auto-retry logic for failed actions * - Configurable retry attempts and delays * - Exponential backoff support * - Jitter for avoiding thundering herd * - Retry condition predicates * - Timeout support */ /** * Retry options */ export interface RetryOptions { /** Maximum number of retry attempts (default: 3) */ maxAttempts?: number; /** Initial delay between retries in ms (default: 1000) */ delay?: number; /** Multiplier for exponential backoff (default: 2) */ backoffMultiplier?: number; /** Maximum delay between retries in ms (default: 30000) */ maxDelay?: number; /** Whether to add jitter to delay (default: true) */ jitter?: boolean; /** Function to determine if error is retryable (default: retry all errors) */ retryIf?: (error: unknown) => boolean; /** Function to call before each retry */ onRetry?: (error: unknown, attempt: number) => void | Promise; /** Overall timeout in ms (default: no timeout) */ timeout?: number; /** Whether to throw last error or aggregate (default: throw last) */ throwLast?: boolean; } /** * Retry result */ export interface RetryResult { /** Whether the operation succeeded */ success: boolean; /** The result value if successful */ value?: T; /** The error if failed */ error?: Error; /** Number of attempts made */ attempts: number; /** Total time elapsed in ms */ elapsed: number; } /** * Aggregate error from multiple retry attempts */ export declare class RetryError extends Error { errors: Error[]; constructor(errors: Error[], message?: string); /** * Get all error messages */ get messages(): string[]; /** * Get formatted error summary */ get summary(): string; } /** * Retry Helper */ export declare class Retry { /** * Retry an async function with configurable options */ static try(fn: () => Promise, options?: RetryOptions): Promise; /** * Retry with result returned */ static withResult(fn: () => Promise, options?: RetryOptions): Promise>; /** * Retry until a condition is met */ static until(condition: () => boolean | Promise, options?: RetryOptions): Promise; /** * Retry while a condition is true */ static while(condition: () => boolean | Promise, fn: () => Promise, options?: RetryOptions): Promise; /** * Add jitter to delay (±25%) */ private static addJitter; /** * Sleep utility */ private static sleep; /** * Add timeout to a promise */ private static withTimeout; } /** * Convenience function for retry */ export declare function retry(fn: () => Promise, options?: RetryOptions): Promise; /** * Common retry predicates */ export declare const RetryIf: { /** Retry on network errors */ networkError: (error: unknown) => boolean; /** Retry on 5xx errors */ serverError: (error: unknown) => boolean; /** Retry on specific error messages */ message: (...messages: string[]) => (error: unknown) => boolean; /** Retry on specific error types */ errorType: (...types: Array Error>) => (error: unknown) => boolean; }; /** * Common retry configurations */ export declare const RetryConfig: { /** Quick retries for transient failures */ quick: { maxAttempts: number; delay: number; backoffMultiplier: number; }; /** Standard retries */ standard: { maxAttempts: number; delay: number; backoffMultiplier: number; }; /** Persistent retries for resilient operations */ persistent: { maxAttempts: number; delay: number; backoffMultiplier: number; maxDelay: number; }; /** Network retries with exponential backoff */ network: { maxAttempts: number; delay: number; backoffMultiplier: number; maxDelay: number; retryIf: (error: unknown) => boolean; }; };