Limits how often something may happen, with token buckets kept in memory, which a restart empties. Logins, password reset requests and the chat's typing messages use it.

Functions

f
takeToken(
key: string,
limit: RateLimit
): boolean

Takes one token from key's bucket, or returns false when it is empty. The caller picks the key, such as typing:<userId>, and keys by user or account so that more tabs or parallel requests don't buy more tokens.

Interfaces

I
RateLimit

Passed to takeToken by each limited action, which declares its own as a constant.

Variables

v
rateLimitSweepJob: Job

Drops the buckets untouched for an hour, every minute. Every limit in use refills within the hour, so such a bucket is full and dropping it changes nothing. main.ts starts it.