/** * @module CircuitBreaker */ import { type HalfOpenTransitions, type CircuitBreakerTrackSettings, type CircuitBreakerTrackState, type ICircuitBreakerPolicy, type ClosedTransitions } from "../../../../circuit-breaker/contracts/_module.js"; /** * Tracks in-memory failure and success counts for the consecutive circuit breaker. * * IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/policies"` * @group Policies */ export type ConsecutiveBreakerState = { failureCount: number; successCount: number; }; /** * Configuration for the consecutive-failures circuit breaker policy. * Opens the circuit when `failureThreshold` consecutive failures occur, * and closes it again after `successThreshold` consecutive successes in half-open state. * * IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/policies"` * @group Policies */ export type ConsecutiveBreakerSettings = { /** * Amount of consecutive failures before going from closed -> open. * * @default 5 */ failureThreshold?: number; /** * Amount of consecutive success before going from half-open -> closed. * * @default settings.failureThreshold */ successThreshold?: number; }; /** * @internal */ export declare function resolveConsecutiveBreakerSettings(settings: ConsecutiveBreakerSettings): Required; /** * The `ConsecutiveBreaker` breaks after n requests in a row fail. * * IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/policies"` * @group Policies */ export declare class ConsecutiveBreaker implements ICircuitBreakerPolicy { private readonly failureThreshold; private readonly successThreshold; constructor(settings?: ConsecutiveBreakerSettings); initialMetrics(): ConsecutiveBreakerState; whenClosed(currentMetrics: ConsecutiveBreakerState, _currentDate: Date): ClosedTransitions; whenHalfOpened(currentMetrics: ConsecutiveBreakerState, _currentDate: Date): HalfOpenTransitions; trackFailure(currentState: CircuitBreakerTrackState, _settings: CircuitBreakerTrackSettings): ConsecutiveBreakerState; trackSuccess(currentState: CircuitBreakerTrackState, settings: CircuitBreakerTrackSettings): ConsecutiveBreakerState; isEqual(metricsA: ConsecutiveBreakerState, metricsB: ConsecutiveBreakerState): boolean; }