/** * @module RateLimiter */ import { type BackoffPolicy } from "../../../../backoff-policies/contracts/_module.js"; import { RATE_LIMITER_STATE, type IRateLimiterPolicy } from "../../../../rate-limiter/contracts/_module.js"; /** * @internal */ export type AllowedState = { type: (typeof RATE_LIMITER_STATE)["ALLOWED"]; metrics: TMetrics; }; /** * @internal */ export type BlockedState = { type: (typeof RATE_LIMITER_STATE)["BLOCKED"]; /** * Unix timestamp in miliseconds */ startedAt: number; attempt: number; }; /** * @internal */ export type AllRateLimiterState = AllowedState | BlockedState; /** * @internal */ export type BackoffPolicySettings = { currentDate: Date; backoffPolicy: BackoffPolicy; }; /** * @internal */ export declare class InternalRateLimiterPolicy { private readonly rateLimiterPolicy; constructor(rateLimiterPolicy: IRateLimiterPolicy); initialState(currentDate: Date): AllowedState; whenAllowed(currentState: AllowedState, limit: number, currentDate: Date): AllRateLimiterState; whenBlocked(currentState: BlockedState, settings: BackoffPolicySettings): AllRateLimiterState; trackWhenAllowed(currentState: AllowedState, currentDate: Date): AllowedState; trackWhenBlocked(currentState: BlockedState): BlockedState; getExpiration(currentState: AllRateLimiterState, settings: BackoffPolicySettings): Date; getAttempts(currentState: AllRateLimiterState, currentDate: Date): number; }