1+ import { AttemptResult } from "./AttemptResult" ;
2+ /**
3+ * Rate limit
4+ * @class
5+ */
6+ export declare class RateLimit {
7+ #private;
8+ /**
9+ * The number of requests allowed per time window
10+ */
11+ limit : number ;
12+ /**
13+ * The time window in seconds (e.g. 60)
14+ */
15+ timeWindow : number ;
16+ /**
17+ * Create a new rate limit
18+ * @param {string } name - The name of the rate limit
19+ * @param {number } limit - The number of requests allowed per time window (e.g. 60)
20+ * @param {number } timeWindow - The time window in seconds (e.g. 60)
21+ * @throws {Error } - If the rate limit already exists
22+ */
23+ constructor ( name : string , limit : number , timeWindow : number ) ;
24+ /**
25+ * Check the attempt state for a source ID without decrementing the remaining attempts
26+ * @param {string } source - Unique source identifier (e.g. username, IP, etc.)
27+ */
28+ check ( source : string ) : AttemptResult ;
29+ /**
30+ * Make an attempt with a source ID
31+ * @param {string } source - Unique source identifier (e.g. username, IP, etc.)
32+ * @param {number } [attempts=1] - The number of attempts to make
33+ */
34+ attempt ( source : string , attempts ?: number ) : AttemptResult ;
35+ /**
36+ * Reset limit for a source ID. The storage entry will be deleted and a new one will be created on the next attempt.
37+ * @param {string } source - Unique source identifier (e.g. username, IP, etc.)
38+ */
39+ reset ( source : string ) : void ;
40+ /**
41+ * Set the remaining attempts for a source ID.
42+ * > **Warning**: This is not recommended as the remaining attempts depend on the limit of the instance.
43+ * @param {string } source - Unique source identifier (e.g. username, IP, etc.)
44+ * @param {number } remaining - The number of remaining attempts
45+ */
46+ setRemaining ( source : string , remaining : number ) : void ;
47+ /**
48+ * Clear rate limit attempts storage. This is equivalent to resetting all rate limits.
49+ */
50+ clear ( ) : void ;
51+ /**
52+ * Delete the rate limit instance. After it is deleted, it should not be used any further without constructing a new instance.
53+ */
54+ delete ( ) : void ;
55+ /**
56+ * Get a rate limit instance
57+ * @param {string } name - The name of the rate limit
58+ * @static
59+ */
60+ static get ( name : string ) : RateLimit | null ;
61+ /**
62+ * Check the attempt state for a source ID without decrementing the remaining attempts
63+ * @param {string } name - The name of the rate limit
64+ * @param {string } source - Unique source identifier (e.g. username, IP, etc.)
65+ * @throws {Error } - If the rate limit does not exist
66+ * @static
67+ */
68+ static check ( name : string , source : string ) : AttemptResult ;
69+ /**
70+ * Make an attempt with a source ID
71+ * @param {string } name - The name of the rate limit
72+ * @param {string } source - Unique source identifier (e.g. username, IP, etc.)
73+ * @param {number } [attempts=1] - The number of attempts to make
74+ * @throws {Error } - If the rate limit does not exist
75+ * @static
76+ */
77+ static attempt ( name : string , source : string , attempts ?: number ) : AttemptResult ;
78+ /**
79+ * Reset limit for a source ID. The storage entry will be deleted and a new one will be created on the next attempt.
80+ * @param {string } name - The name of the rate limit
81+ * @param {string } source - Unique source identifier (e.g. username, IP, etc.)
82+ * @throws {Error } - If the rate limit does not exist
83+ * @static
84+ */
85+ static reset ( name : string , source : string ) : void ;
86+ /**
87+ * Set the remaining attempts for a source ID.
88+ * > **Warning**: This is not recommended as the remaining attempts depend on the limit of the instance.
89+ * @param {string } name - The name of the rate limit
90+ * @param {string } source - Unique source identifier (e.g. username, IP, etc.)
91+ * @param {number } remaining - The number of remaining attempts
92+ * @throws {Error } - If the rate limit does not exist
93+ * @static
94+ */
95+ static setRemaining ( name : string , source : string , remaining : number ) : void ;
96+ /**
97+ * Clear rate limit attempts storage. This is equivalent to resetting all rate limits.
98+ * @param {string } name - The name of the rate limit
99+ * @throws {Error } - If the rate limit does not exist
100+ * @static
101+ */
102+ static clear ( name : string ) : void ;
103+ /**
104+ * Delete the rate limit instance. After it is deleted, it should not be used any further without constructing a new instance.
105+ * @param {string } name - The name of the rate limit
106+ * @throws {Error } - If the rate limit does not exist
107+ * @static
108+ */
109+ static delete ( name : string ) : void ;
110+ /**
111+ * Create a new rate limit
112+ * @param {string } name - The name of the rate limit
113+ * @param {number } limit - The number of attempts allowed per time window (e.g. 60)
114+ * @param {number } timeWindow - The time window in seconds (e.g. 60)
115+ * @static
116+ */
117+ static create ( name : string , limit : number , timeWindow : number ) : RateLimit ;
118+ }
119+ //# sourceMappingURL=RateLimit.d.ts.map
0 commit comments