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.

66 lines (65 loc) 2.32 kB
/** * @module CircuitBreaker */ import { type BackoffPolicy } from "../../../../backoff-policies/_module.js"; import { CIRCUIT_BREAKER_STATE, type ICircuitBreakerPolicy } from "../../../../circuit-breaker/contracts/_module.js"; /** * @internal */ export type BackoffPolicySettings = { currentDate: Date; backoffPolicy: BackoffPolicy; }; /** * @internal */ export type OpenedState = { type: typeof CIRCUIT_BREAKER_STATE.OPEN; attempt: number; /** * Unix timestamp in miliseconds */ startedAt: number; }; /** * @internal */ export type HalfOpenedState<TMetrics = unknown> = { type: typeof CIRCUIT_BREAKER_STATE.HALF_OPEN; attempt: number; metrics: TMetrics; }; /** * @internal */ export type ClosedState<TMetrics = unknown> = { type: typeof CIRCUIT_BREAKER_STATE.CLOSED; metrics: TMetrics; }; /** * @internal */ export type IsolatedState = { type: typeof CIRCUIT_BREAKER_STATE.ISOLATED; }; /** * @internal */ export type AllCircuitBreakerState<TMetrics = unknown> = ClosedState<TMetrics> | OpenedState | HalfOpenedState<TMetrics> | IsolatedState; /** * @internal */ export declare class CircuitBreakerPolicy<TMetrics = unknown> { private readonly circuitBreakerPolicy; constructor(circuitBreakerPolicy: ICircuitBreakerPolicy<TMetrics>); private isMetricsEqual; isEqual(stateA: AllCircuitBreakerState<TMetrics>, stateB: AllCircuitBreakerState<TMetrics>): boolean; initialState(): ClosedState<TMetrics>; whenClosed(currentState: ClosedState<TMetrics>, currentDate: Date): ClosedState<TMetrics> | OpenedState; whenOpened(currentState: OpenedState, settings: BackoffPolicySettings): OpenedState | HalfOpenedState<TMetrics>; whenHalfOpened(currentState: HalfOpenedState<TMetrics>, currentDate: Date): ClosedState<TMetrics> | OpenedState | HalfOpenedState<TMetrics>; trackSuccessWhenClosed(currentState: ClosedState<TMetrics>, currentDate: Date): ClosedState<TMetrics>; trackFailureWhenClosed(currentState: ClosedState<TMetrics>, currentDate: Date): ClosedState<TMetrics>; trackSuccessWhenHalfOpened(currentState: HalfOpenedState<TMetrics>, currentDate: Date): HalfOpenedState<TMetrics>; trackFailureWhenHalfOpened(currentState: HalfOpenedState<TMetrics>, currentDate: Date): HalfOpenedState<TMetrics>; }