guardz-axios
Version:
Type-safe HTTP client built on top of Axios with runtime validation using guardz. Part of the guardz ecosystem for comprehensive TypeScript type safety.
82 lines • 3.35 kB
TypeScript
/**
* Retry Utilities - Pure functions for retry logic
* Following Functional Programming (FP) principles
*/
import { RetryConfig } from "../domain/types";
/**
* Calculates delay for retry attempts with improved performance
* Pure function - no side effects, deterministic output
*
* @param attempt - Current attempt number (1-based)
* @param baseDelay - Base delay in milliseconds
* @param backoff - Backoff strategy ('linear' or 'exponential')
* @returns Calculated delay in milliseconds
*/
export declare function calculateRetryDelay(attempt: number, baseDelay: number, backoff: "linear" | "exponential"): number;
/**
* Checks if retry should be attempted with improved logic
* Pure function - no side effects, deterministic output
*
* @param attempt - Current attempt number
* @param maxAttempts - Maximum number of attempts
* @param error - Error that occurred
* @param retryOn - Custom retry condition function
* @returns Whether retry should be attempted
*/
export declare function shouldRetry(attempt: number, maxAttempts: number, error: unknown, retryOn?: (error: unknown) => boolean): boolean;
/**
* Determines if an error is retryable with comprehensive error detection
* Pure function - no side effects, deterministic output
*
* @param error - Error to check
* @returns Whether the error is retryable
*/
export declare function isRetryableError(error: unknown): boolean;
/**
* Determines if an error is a validation error that should not be retried
* Pure function - no side effects, deterministic output
*
* @param error - Error to check
* @returns Whether the error is a validation error
*/
export declare function isRetryableValidationError(error: unknown): boolean;
/**
* Creates retry configuration with defaults and validation
* Pure function - no side effects, deterministic output
*
* @param attempts - Number of retry attempts
* @param delay - Base delay in milliseconds
* @param backoff - Backoff strategy
* @param retryOn - Custom retry condition function
* @returns Retry configuration object
*/
export declare function createRetryConfig(attempts?: number, delay?: number, backoff?: "linear" | "exponential", retryOn?: (error: unknown) => boolean): RetryConfig;
/**
* Validates retry configuration with comprehensive checks
* Pure function - no side effects, deterministic output
*
* @param config - Retry configuration to validate
* @returns Error message if invalid, null if valid
*/
export declare function validateRetryConfig(config: RetryConfig): string | null;
/**
* Merges retry configurations with validation
* Pure function - no side effects, deterministic output
*
* @param base - Base retry configuration
* @param override - Override configuration
* @returns Merged retry configuration
*/
export declare function mergeRetryConfigs(base: RetryConfig, override: Partial<RetryConfig>): RetryConfig;
/**
* Creates a retry strategy function with memoization for performance
* Pure function - no side effects, deterministic output
*
* @param config - Retry configuration
* @returns Retry strategy object with shouldRetry and getDelay methods
*/
export declare function createRetryStrategy(config: RetryConfig): {
shouldRetry: (attempt: number, error: unknown) => boolean;
getDelay: (attempt: number) => number;
};
//# sourceMappingURL=retry-utils.d.ts.map