mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #34481 from JorgenVatle/master
[fast-ratelimit] Add type definitions for fast-ratelimit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { FastRateLimit } from 'fast-ratelimit';
|
||||
|
||||
const limit = new FastRateLimit({ // $type: FastRateLimit
|
||||
threshold: 20,
|
||||
ttl: 60,
|
||||
});
|
||||
|
||||
const someNamespace = 'some-namespace';
|
||||
|
||||
const consume = limit.consume(someNamespace); // $type: Promise<void>
|
||||
consume.then(() => {}); // User can send message.
|
||||
consume.catch(() => {}); // Use cannot send message.
|
||||
|
||||
const hasToken = limit.hasToken(someNamespace); // $type: Promise<void>
|
||||
hasToken.then(() => {}); // User has remaining token.
|
||||
hasToken.catch(() => {}); // User does not have remaining token.
|
||||
|
||||
// Synchronously check if user is allowed to send message.
|
||||
const consumeSync = limit.consumeSync(someNamespace); // $type: boolean
|
||||
|
||||
// Synchronously check if user has remaining token.
|
||||
const hasTokenSync = limit.hasTokenSync(someNamespace); // $type: boolean
|
||||
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
// Type definitions for fast-ratelimit 2.2
|
||||
// Project: https://github.com/valeriansaliou/node-fast-ratelimit
|
||||
// Definitions by: Jørgen Vatle <https://github.com/JorgenVatle>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Constructor options for fast-ratelimit.
|
||||
* {@link https://github.com/valeriansaliou/node-fast-ratelimit#1-create-the-rate-limiter}
|
||||
*/
|
||||
export interface FastRateLimitOptions {
|
||||
threshold: number; // available tokens over timespan
|
||||
ttl: number; // time-to-live value of token bucket (in seconds)
|
||||
}
|
||||
|
||||
export class FastRateLimit {
|
||||
/**
|
||||
* FastRateLimit constructor
|
||||
* @param options
|
||||
*/
|
||||
constructor(options: FastRateLimitOptions);
|
||||
|
||||
/**
|
||||
* FastRateLimit.prototype.consumeSync
|
||||
*/
|
||||
consumeSync(namespace: string): boolean;
|
||||
|
||||
/**
|
||||
* FastRateLimit.prototype.hasTokenSync
|
||||
*/
|
||||
hasTokenSync(namespace: string): boolean;
|
||||
|
||||
/**
|
||||
* FastRateLimit.prototype.consume
|
||||
*/
|
||||
consume(namespace: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* FastRateLimit.prototype.hasToken
|
||||
*/
|
||||
hasToken(namespace: string): Promise<void>;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"fast-ratelimit-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user