import { n as SDKError } from "./index-BFYASYJk.js"; //#region src/resilience/circuit-breaker.d.ts type CircuitState = "closed" | "open" | "half-open"; interface CircuitBreakerConfig { /** Number of failures before opening circuit */ failureThreshold: number; /** Time in ms to wait before testing recovery (half-open) */ resetTimeoutMs: number; /** Number of successes in half-open state to close circuit */ successThreshold: number; /** Optional: Only count these error types as failures */ failureFilter?: (error: unknown) => boolean; } interface CircuitBreakerStats { state: CircuitState; failures: number; successes: number; lastFailureTime: number | null; totalFailures: number; totalSuccesses: number; totalRejected: number; } declare class CircuitOpenError extends SDKError { readonly circuitName: string; readonly resetAfterMs: number; constructor(name: string, resetAfterMs: number); } declare class CircuitBreaker { private readonly name; private readonly config; private state; private failures; private successes; private lastFailureTime; private totalFailures; private totalSuccesses; private totalRejected; constructor(name: string, config: CircuitBreakerConfig); /** * Execute a function through the circuit breaker. * Throws CircuitOpenError if circuit is open. */ execute(fn: () => Promise): Promise; private onSuccess; private onFailure; /** Get current circuit state */ getState(): CircuitState; /** Get circuit statistics */ getStats(): CircuitBreakerStats; /** Check if circuit is allowing requests */ isAllowingRequests(): boolean; /** Manually reset the circuit to closed state */ reset(): void; /** Manually open the circuit */ open(): void; } //#endregion //#region src/resilience/protection.d.ts interface ProtectionOptions { /** Timeout in milliseconds (0 or undefined = no timeout) */ timeoutMs?: number; /** Circuit breaker instance (optional) */ breaker?: CircuitBreaker; /** Operation name for error messages */ operationName?: string; } /** * Execute a function with timeout and circuit breaker protection. * * Order of execution: * 1. Circuit breaker check (fail fast if open) * 2. Timeout wrapper * 3. Execute function * 4. Update circuit breaker state */ declare function withProtection(fn: () => Promise, options?: ProtectionOptions): Promise; /** * Create a protected function that always applies the same protection options. */ declare function createProtectedFn(fn: (...args: TArgs) => Promise, options: ProtectionOptions): (...args: TArgs) => Promise; //#endregion //#region src/resilience/timeout.d.ts declare class TimeoutError extends SDKError { readonly timeoutMs: number; constructor(message: string, timeoutMs: number); } /** * Wrap a promise with a timeout. * Rejects with TimeoutError if the promise doesn't resolve in time. */ declare function withTimeout(promise: Promise, timeoutMs: number, message?: string): Promise; /** * Create an AbortController that auto-aborts after a timeout. * Returns the controller and a cleanup function. */ declare function createTimeoutController(timeoutMs: number): { controller: AbortController; cleanup: () => void; }; /** * Sleep for a specified duration. * Optionally accepts an AbortSignal for cancellation. */ declare function sleep(ms: number, signal?: AbortSignal): Promise; //#endregion export { ProtectionOptions as a, CircuitBreaker as c, CircuitOpenError as d, CircuitState as f, withTimeout as i, CircuitBreakerConfig as l, createTimeoutController as n, createProtectedFn as o, sleep as r, withProtection as s, TimeoutError as t, CircuitBreakerStats as u }; //# sourceMappingURL=index-CKDeaS7l.d.ts.map