UNPKG

@hono-rate-limiter/cloudflare

Version:

Cloudflare stores and helper functions for hono-rate-limiter.

68 lines (67 loc) 2.44 kB
/// <reference types="@cloudflare/workers-types/2023-07-01" /> import type { ClientRateLimitInfo, ConfigType as RateLimitConfiguration, Store } from "hono-rate-limiter"; import type { Env, Input } from "hono/types"; import type { Options } from "../types"; import type { DurableObjectRateLimiter } from "./DurableObjectClass"; export declare class DurableObjectStore<E extends Env = Env, P extends string = string, I extends Input = Input> implements Store<E, P, I> { /** * The text to prepend to the key in Redis. */ prefix: string; /** * The Durable Object namespace to use. */ namespace: DurableObjectNamespace<DurableObjectRateLimiter>; /** * The number of milliseconds to remember that user's requests. */ windowMs: number; /** * @constructor for `DurableObjectStore`. * * @param options {Options} - The configuration options for the store. */ constructor(options: Options<DurableObjectNamespace<DurableObjectRateLimiter>>); /** * Method to prefix the keys with the given text and return a `DurableObjectId`. * * @param key {string} - The key. * * @returns {DurableObjectId} - The text + the key. */ prefixKey(key: string): DurableObjectId; /** * Method that actually initializes the store. * * @param options {RateLimitConfiguration} - The options used to setup the middleware. */ init(options: RateLimitConfiguration<E, P, I>): void; /** * Method to fetch a client's hit count and reset time. * * @param key {string} - The identifier for a client. * * @returns {ClientRateLimitInfo | undefined} - The number of hits and reset time for that client. */ get(key: string): Promise<ClientRateLimitInfo | undefined>; /** * Method to increment a client's hit counter. * * @param key {string} - The identifier for a client * * @returns {ClientRateLimitInfo} - The number of hits and reset time for that client */ increment(key: string): Promise<ClientRateLimitInfo>; /** * Method to decrement a client's hit counter. * * @param key {string} - The identifier for a client */ decrement(key: string): Promise<void>; /** * Method to reset a client's hit counter. * * @param key {string} - The identifier for a client */ resetKey(key: string): Promise<void>; }