UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

52 lines (51 loc) 2.11 kB
/** * @module CircuitBreaker */ import { type HalfOpenTransitions, type CircuitBreakerTrackSettings, type CircuitBreakerTrackState, type ICircuitBreakerPolicy, type ClosedTransitions } from "../../../../circuit-breaker/contracts/_module.js"; /** * IMPORT_PATH: `"@daiso-tech/core/circuit-breaker/policies"` * @group Policies */ export type ConsecutiveBreakerState = { failureCount: number; successCount: number; }; /** * 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<ConsecutiveBreakerSettings>; /** * 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<ConsecutiveBreakerState> { 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<ConsecutiveBreakerState>, _settings: CircuitBreakerTrackSettings<ConsecutiveBreakerState>): ConsecutiveBreakerState; trackSuccess(currentState: CircuitBreakerTrackState<ConsecutiveBreakerState>, settings: CircuitBreakerTrackSettings<ConsecutiveBreakerState>): ConsecutiveBreakerState; isEqual(metricsA: ConsecutiveBreakerState, metricsB: ConsecutiveBreakerState): boolean; }