@hono-rate-limiter/cloudflare
Version:
Cloudflare stores and helper functions for hono-rate-limiter.
67 lines (66 loc) • 2.22 kB
TypeScript
/// <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";
export declare class WorkersKVStore<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 KV namespace to use.
*/
namespace: KVNamespace;
/**
* The number of milliseconds to remember that user's requests.
*/
windowMs: number;
/**
* @constructor for `WorkersKVStore`.
*
* @param options {Options} - The configuration options for the store.
*/
constructor(options: Options<KVNamespace>);
/**
* Method to prefix the keys with the given text.
*
* @param key {string} - The key.
*
* @returns {string} - The text + the key.
*/
prefixKey(key: string): string;
/**
* 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>;
}