import { Context, MiddlewareHandler } from 'hono'; import { C as ConcurrencyGuard, j as UnifiedAdmitter, k as UnifiedAxis } from './unified-BouIz5EX.js'; import { C as Clock, D as Decision } from './types-DKirIBQt.js'; import { a as CommonAdapterOptions, L as LimiterOrStrategy } from './core-DcpxT2lH.js'; import './store-CQjuAFM_.js'; /** * Hono v4 middleware adapter. Wraps a route with a rate-limit gate: on allow it sets the * rate-limit headers on the context and forwards to `next()`; on deny it short-circuits with a * `429` JSON response carrying the same headers plus `Retry-After`. Store outages resolve via the * explicit fail policy (a fail-closed outage returns `503`). The limit key derives from the raw * Web `Request` (`c.req.raw`): `cf-connecting-ip` → `x-forwarded-for` → `"anon"`. See * THROTTLEKIT.md §§14,15. * * Also exposes {@link honoUnifiedAdmission} and {@link honoAdaptiveConcurrency} (0.9.2, * TK-1326) using the try/finally wrap pattern: `release` fires with `dropped = thrown`. */ type HonoRateLimitOptions = LimiterOrStrategy & CommonAdapterOptions & { /** Cost of a request in limiter units. A function computes it per request. Default 1. */ cost?: number | ((c: Context) => number); /** Derive the limit key from the context. Default: `cf-connecting-ip` → `x-forwarded-for` → `"anon"`. */ key?: (c: Context) => string; /** Observability hook fired on every denial. */ onLimited?: (c: Context, decision: Decision) => void; /** Observability hook fired when the store throws (before the fail policy is applied). */ onError?: (c: Context, err: unknown) => void; /** Custom 429 responder. When provided, it fully owns the denial response. */ handler?: (c: Context, decision: Decision) => Response | Promise; }; /** * Build Hono middleware that rate-limits requests reaching the routes it guards. * * @example * import { Hono } from "hono"; * import { honoRateLimit } from "throttlekit/hono"; * import { gcra } from "throttlekit"; * * const app = new Hono(); * app.use("*", honoRateLimit({ strategy: gcra({ limit: 30, periodMs: 10_000 }) })); * app.get("/", (c) => c.text("ok")); */ declare function honoRateLimit(options: HonoRateLimitOptions): MiddlewareHandler; /** Per-axis Decision snapshot from `admitter.lastDecisions()`. */ type AxisSnapshot = Readonly>>; /** Options for {@link honoUnifiedAdmission}. */ type HonoUnifiedAdmissionOptions = Pick & { admitter: UnifiedAdmitter; cost?: number | ((c: Context) => number); key?: (c: Context) => string; clock?: Clock; /** Treat 5xx responses as `dropped: true`. Default `false` (DESIGN.md §5). */ dropOn5xx?: boolean; onLimited?: (c: Context, decision: Decision, axes: AxisSnapshot) => void; onError?: (c: Context, err: unknown) => void; handler?: (c: Context, decision: Decision, axes: AxisSnapshot) => Response | Promise; }; /** * Hono middleware enforcing a {@link UnifiedAdmitter}. On admit it forwards to `next()` inside * a try/finally; on a thrown handler, `release({ dropped: true })`; on a clean return, * `release({ dropped: false })` (or `true` if `dropOn5xx` and the response status is 5xx). * * @example * app.use("*", honoUnifiedAdmission({ admitter })); */ declare function honoUnifiedAdmission(options: HonoUnifiedAdmissionOptions): MiddlewareHandler; /** Options for {@link honoAdaptiveConcurrency}. */ type HonoAdaptiveConcurrencyOptions = Pick & { guard: ConcurrencyGuard; clock?: Clock; dropOn5xx?: boolean; onLimited?: (c: Context, decision: Decision) => void; handler?: (c: Context, decision: Decision) => Response | Promise; }; /** Hono middleware enforcing an adaptive {@link ConcurrencyGuard}. */ declare function honoAdaptiveConcurrency(options: HonoAdaptiveConcurrencyOptions): MiddlewareHandler; export { CommonAdapterOptions, type HonoAdaptiveConcurrencyOptions, type HonoRateLimitOptions, type HonoUnifiedAdmissionOptions, LimiterOrStrategy, honoAdaptiveConcurrency, honoRateLimit, honoUnifiedAdmission };