/** * @module CircuitBreaker */ import { type HalfOpenTransitions, type CircuitBreakerTrackSettings, type CircuitBreakerTrackState, type ICircuitBreakerPolicy, type ClosedTransitions } from "../../../../circuit-breaker/contracts/_module.js"; /** * Configuration for the count-based sliding-window circuit breaker policy. * Tracks requests over a fixed-size window and opens the circuit when the failure * percentage exceeds `failureThreshold`. * * IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/policies"` * @group Policies */ export type CountBreakerSettings = { /** * Percentage (from 0 to 1) failures before going from closed -> open. * * @default 0.2 */ failureThreshold?: number; /** * Percentage (from 0 to 1) successes before going from half-open -> closed. * * @default * ```ts * 1 - settings.failureThreshold * ``` */ successThreshold?: number; /** * Size of the count based sliding window. * * @default 20 */ size?: number; /** * The minimum number of calls to go from closed -> open, half-opened -> closed or half-opened -> open. * * @default * ```ts * settings.size * ``` */ minimumNumberOfCalls?: number; }; /** * @internal */ export declare function resolveCountBreakerSettings(settings: CountBreakerSettings): Required; /** * In-memory sample window used by the count-based circuit breaker. * Each boolean entry represents whether a single call succeeded (`true`) or failed (`false`). * * IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/policies"` * @group Policies */ export type CountBreakerState = { samples: Array; }; /** * The `CountBreaker` breaks after a proportion of requests in a count based sliding window fail. * * IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/policies"` * @group Policies */ export declare class CountBreaker implements ICircuitBreakerPolicy { private readonly failureThreshold; private readonly successThreshold; private readonly minimumNumberOfCalls; private readonly size; constructor(settings?: CountBreakerSettings); initialMetrics(): CountBreakerState; private static failureCount; private static successCount; private isMinimumNotMet; whenClosed(currentMetrics: CountBreakerState, _currentDate: Date): ClosedTransitions; whenHalfOpened(currentMetrics: CountBreakerState, _currentDate: Date): HalfOpenTransitions; private track; trackFailure(currentState: CircuitBreakerTrackState, _settings: CircuitBreakerTrackSettings): CountBreakerState; trackSuccess(currentState: CircuitBreakerTrackState, _settings: CircuitBreakerTrackSettings): CountBreakerState; isEqual(metricsA: CountBreakerState, metricsB: CountBreakerState): boolean; }