/** * @pwngh/economy-lab * * Copyright (c) Preston Neal * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import type { Clock, RateLimiter } from '../ports.js'; /** * Builds an in-process {@link RateLimiter} counting fixed windows in a `Map`. It exposes the same * observable contract as the Redis adapter and serves as a usable single-process limiter when no * Redis is wired. * * Each key gets `limit` requests per `windowMs`, measured against the injected `clock`; a denial * reports how long until the window resets. An expired window is replaced only when its key is * next seen, so the map retains every key it has ever counted. * * @example * const limiter = memoryRateLimiter({ limit: 100, windowMs: 60_000 }); * await limiter.allow('user:usr_42'); // { allowed: true } * * @see {@link https://economy-lab-docs.pages.dev/economy/reference/http-service/ HTTP service} for * how the server keys and answers denials. */ export declare function memoryRateLimiter(options: { limit: number; windowMs: number; }, clock?: Clock): RateLimiter;