UNPKG

@pod-protocol/sdk

Version:

TypeScript SDK for PoD Protocol - AI agent communication on Solana

121 lines 3.67 kB
/** * Retry logic with exponential backoff for PoD Protocol SDK * Handles network failures and RPC errors with intelligent retry strategies */ export interface RetryOptions { maxAttempts?: number; baseDelay?: number; maxDelay?: number; backoffFactor?: number; jitter?: boolean; retryCondition?: (error: unknown, attempt: number) => boolean; onRetry?: (error: unknown, attempt: number) => void; timeout?: number; } export interface RetryResult<T> { result: T; attempts: number; totalTime: number; lastError?: unknown; } /** * Default retry configuration for different operation types */ export declare const RetryConfig: { readonly fast: { readonly maxAttempts: 3; readonly baseDelay: 500; readonly maxDelay: 2000; readonly backoffFactor: 2; readonly jitter: true; readonly timeout: 10000; }; readonly medium: { readonly maxAttempts: 3; readonly baseDelay: 1000; readonly maxDelay: 5000; readonly backoffFactor: 2; readonly jitter: true; readonly timeout: 30000; }; readonly slow: { readonly maxAttempts: 2; readonly baseDelay: 2000; readonly maxDelay: 10000; readonly backoffFactor: 2; readonly jitter: true; readonly timeout: 60000; }; readonly critical: { readonly maxAttempts: 5; readonly baseDelay: 1000; readonly maxDelay: 8000; readonly backoffFactor: 1.5; readonly jitter: true; readonly timeout: 120000; }; }; /** * Retry a function with exponential backoff */ export declare function retry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>; /** * Retry with predefined configuration */ export declare function retryWithConfig<T>(fn: () => Promise<T>, configName: keyof typeof RetryConfig, additionalOptions?: Partial<RetryOptions>): Promise<T>; /** * Default retry condition - determines if an error should trigger a retry */ export declare function defaultRetryCondition(error: unknown, attempt: number): boolean; /** * Conservative retry condition for critical operations */ export declare function conservativeRetryCondition(error: unknown, attempt: number): boolean; /** * Aggressive retry condition for non-critical operations */ export declare function aggressiveRetryCondition(error: unknown, attempt: number): boolean; /** * Retry decorator for class methods */ export declare function retryable(options?: RetryOptions): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor; /** * Retry with circuit breaker pattern */ export declare class CircuitBreaker<T> { private threshold; private resetTime; private failures; private lastFailureTime; private state; constructor(threshold?: number, resetTime?: number); execute(fn: () => Promise<T>, retryOptions?: RetryOptions): Promise<T>; reset(): void; getState(): { state: string; failures: number; lastFailureTime: number; }; } /** * Utility functions for specific retry scenarios */ export declare const RetryUtils: { /** * Retry RPC calls with appropriate backoff */ rpcCall: <T>(fn: () => Promise<T>) => Promise<T>; /** * Retry account fetching operations */ accountFetch: <T>(fn: () => Promise<T>) => Promise<T>; /** * Retry analytics calculations */ analytics: <T>(fn: () => Promise<T>) => Promise<T>; /** * Retry transaction operations */ transaction: <T>(fn: () => Promise<T>) => Promise<T>; }; //# sourceMappingURL=retry.d.ts.map