/** * Configuration options for the retry policy */ export interface RetryPolicyConfig { /** Maximum number of retry attempts before giving up */ maxRetries: number; /** Base delay in milliseconds for exponential backoff */ baseDelayMs: number; /** Maximum delay in milliseconds (caps the exponential growth) */ maxDelayMs: number; /** Multiplier for exponential backoff (default: 2) */ backoffMultiplier?: number; /** Optional jitter factor (0-1) to add randomness to delays */ jitterFactor?: number; } /** * Result of a retry policy evaluation */ export interface RetryDecision { /** Whether a retry should be attempted */ shouldRetry: boolean; /** Delay in milliseconds before the next retry (0 if shouldRetry is false) */ delayMs: number; /** The retry attempt number (0-indexed) */ attemptNumber: number; } /** * Retry policy with exponential backoff support. * Determines whether and when to retry failed operations. */ export default class RetryPolicy { private readonly config; constructor(config: RetryPolicyConfig); /** * Create a retry policy with default configuration */ static default(): RetryPolicy; /** * Create a retry policy with no retries (fail immediately) */ static noRetry(): RetryPolicy; /** * Evaluate whether a retry should be attempted based on the current retry count * @param currentRetryCount The number of retries already attempted * @returns A RetryDecision indicating whether to retry and how long to wait */ evaluate(currentRetryCount: number): RetryDecision; /** * Calculate the delay for a given retry attempt using exponential backoff * @param retryCount The current retry count (0-indexed) * @returns Delay in milliseconds */ calculateDelay(retryCount: number): number; /** * Get the maximum number of retries allowed */ getMaxRetries(): number; /** * Check if retries are exhausted * @param retryCount The current retry count * @returns True if no more retries are allowed */ isExhausted(retryCount: number): boolean; }