-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtypes.ts
83 lines (72 loc) · 1.59 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { NextFunction, Request, Response } from 'express';
import Client from 'ioredis';
import Redlock from 'redlock';
/**
* This is a generic interface that a Rate limiter has to implement.
*
* @export
* @interface RateLimiter
*/
export interface RateLimiter {
handleRequest(req: Request, res: Response, next: NextFunction): void;
cleanup(): void;
}
export type TokenBucketArgs = {
/**
* Represents the maximum number of tokens allowed in a single bucket.
*
* @type {number}
*/
capacity: number;
/**
* The interval period after which 1 token will be added to all the buckets.
*
* @type {number}
*/
timePeriodInMs: number;
};
export type FixedWindowCounterArgs = {
/**
* The maximum number of requests allowed in a second.
*
* @type {number}
*/
threshold: number;
};
export type SlidingWindowLogArgs = {
/**
* Maximum length of logs (requests) allowed for a single IP per second.
*
* @type {number}
*/
logThreshold: number;
};
export type SlidingWindowCounterArgs = {
/**
* The maximum number of requests allowed in a second.
*
* @type {number}
*/
threshold: number;
};
export type RedisSlidingWindowCounterArgs = {
/**
* The maximum number of requests allowed in a second.
*
* @type {number}
*/
threshold: number;
client: Client.Redis;
/**
* Used for locking data in Redis server.
*
* @type {Redlock}
*/
redlock: Redlock;
};
export type RateLimiterArgs =
| TokenBucketArgs
| FixedWindowCounterArgs
| SlidingWindowLogArgs
| SlidingWindowCounterArgs
| RedisSlidingWindowCounterArgs;