@bernierllc/retry-policy
Version:
Atomic retry policy utilities with exponential backoff and jitter
78 lines • 2.57 kB
TypeScript
import { RetryPolicyOptions, RetryPolicyResult, JitterConfig, BackoffConfig } from './types';
/**
* Default retry policy options
*/
export declare const DEFAULT_RETRY_OPTIONS: Required<RetryPolicyOptions>;
/**
* Default jitter configuration
*/
export declare const DEFAULT_JITTER_CONFIG: JitterConfig;
/**
* Default backoff configuration
*/
export declare const DEFAULT_BACKOFF_CONFIG: BackoffConfig;
/**
* Core retry policy class that provides atomic retry utilities with optional runtime configuration
*/
export declare class RetryPolicy {
private options;
private backoffConfig;
constructor(options?: Partial<RetryPolicyOptions>, backoffConfig?: Partial<BackoffConfig>);
/**
* Evaluate whether an operation should be retried based on current attempt and error
*/
evaluateRetry(attempt: number, error: any): RetryPolicyResult;
/**
* Calculate the delay for the next retry attempt
*/
calculateDelay(attempt: number): number;
/**
* Calculate exponential backoff delay
*/
private calculateExponentialDelay;
/**
* Calculate linear backoff delay
*/
private calculateLinearDelay;
/**
* Apply jitter to a delay value
*/
private applyJitter;
/**
* Determine if an operation should be retried based on attempt count and error
*/
private shouldRetry;
/**
* Get the current retry policy options
*/
getOptions(): Required<RetryPolicyOptions>;
/**
* Get the current backoff configuration
*/
getBackoffConfig(): BackoffConfig;
/**
* Update retry policy options
*/
updateOptions(options: Partial<RetryPolicyOptions>): void;
/**
* Update backoff configuration
*/
updateBackoffConfig(config: Partial<BackoffConfig>): void;
/**
* Get configuration sources for transparency
*/
getConfigurationSources(): any[];
}
/**
* Factory function to create a retry policy with default options
*/
export declare function createRetryPolicy(options?: Partial<RetryPolicyOptions>, backoffConfig?: Partial<BackoffConfig>): RetryPolicy;
/**
* Utility function to calculate delay for a specific attempt
*/
export declare function calculateRetryDelay(attempt: number, options?: Partial<RetryPolicyOptions>, backoffConfig?: Partial<BackoffConfig>): number;
/**
* Utility function to determine if an error should trigger a retry
*/
export declare function shouldRetry(attempt: number, error: any, options?: Partial<RetryPolicyOptions>): boolean;
//# sourceMappingURL=retry-policy.d.ts.map