/** * Fixed-window rate limiter, keyed by principal (falls back to client IP). * * In-memory and per-instance: the effective global limit is `limit × #instances`. For a hard global * cap, back this with a shared store (Redis); for protecting one instance from a hot caller this is * enough. `limit <= 0` disables it. */ export interface RateDecision { allowed: boolean; retryAfterSec: number; remaining: number; } /** [ref] 批1:限额的**值换代**入参(六实现类同一形)。语义定案([ref] §5):窗口内计数**不清零**, * 新限额即时用于比较 —— 调小 = 窗内立刻更严(可能当场 429,符合运营意图),调大 = 立刻放宽。 */ export interface RateLimits { /** 每窗请求上限;`<= 0` = **关断哨兵**(恒放行、不记账、SQL 腿不起刷新环)。 */ rateLimitPerMin: number; } /** The surface the HTTP layer uses — satisfied by the in-memory {@link RateLimiter} (single replica) * and the cross-replica {@link import("../plugins/tidb-rate-limiter.js").TiDBRateLimiter}. */ export interface RateGate { check(key: string): RateDecision; sweep(now?: number): void; /** [ref]:值换代座位。**接口级**声明(不是各类自选):新实现漏掉它 = 编译红,而不是热更新在那条腿上静默失效。 */ setLimits(next: RateLimits): void; } export declare class RateLimiter implements RateGate { private readonly windowMs; private readonly windows; /** 🔴 不再 `readonly`:限额是**比较参数**,不是窗表状态 —— 换代只动它,窗内已计的数一个不动(§5)。 */ private limit; constructor(limit: number, windowMs?: number); check(key: string): RateDecision; setLimits(next: RateLimits): void; /** Drop expired windows (call periodically). */ sweep(now?: number): void; } //# sourceMappingURL=rate-limit.d.ts.map