Skip to content
This repository was archived by the owner on Apr 15, 2025. It is now read-only.

Commit c22a3e2

Browse files
author
williamd5
committed
generated .d.ts files
1 parent 1b4985a commit c22a3e2

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

lib/AttemptResult.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { RateLimit } from "./RateLimit";
2+
/**
3+
* The result from a rate limit attempt
4+
* @interface
5+
*/
6+
export interface AttemptResult {
7+
/**
8+
* The number of requests this rate limit allows per time window
9+
*/
10+
limit: number;
11+
/**
12+
* The number of requests remaining in the current time window
13+
*/
14+
remaining: number;
15+
/**
16+
* The number of seconds until the current time window resets
17+
*/
18+
reset: number;
19+
/**
20+
* The rate limit that this attempt was made on
21+
*/
22+
rateLimit: RateLimit;
23+
/**
24+
* Whether this attempt should be allowed to proceed. If false, the attempt is rate limited.
25+
*/
26+
allow: boolean;
27+
}
28+
//# sourceMappingURL=AttemptResult.d.ts.map

lib/AttemptResult.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/RateLimit.d.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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

lib/RateLimit.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)