mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Add ratelimtier.d.ts
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
/// <reference path="../redis/redis.d.ts" />
|
||||
/// <reference path="./ratelimiter.d.ts" />
|
||||
|
||||
import redis = require('redis');
|
||||
import Limiter = require('ratelimiter');
|
||||
|
||||
let id: string;
|
||||
let db: redis.RedisClient;
|
||||
let limit = new Limiter({ id: id, db: db });
|
||||
|
||||
const str: string = limit.inspect();
|
||||
|
||||
limit.get((err, limit): void => {
|
||||
const total: number = limit.total;
|
||||
const remaining: number = limit.remaining;
|
||||
const reset: number = limit.reset;
|
||||
});
|
||||
Vendored
+59
@@ -0,0 +1,59 @@
|
||||
// Type definitions for ratelimiter 2.1.1
|
||||
// Project: https://github.com/tj/node-ratelimiter
|
||||
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../redis/redis.d.ts" />
|
||||
|
||||
declare module "ratelimiter" {
|
||||
import { RedisClient } from 'redis';
|
||||
|
||||
interface LimiterOption {
|
||||
/**
|
||||
* The identifier to limit against (typically a user id)
|
||||
*/
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Redis connection instance
|
||||
*/
|
||||
db: RedisClient;
|
||||
|
||||
/**
|
||||
* Max requests within duration
|
||||
*/
|
||||
max?: number;
|
||||
|
||||
/**
|
||||
* Duration of limit in milliseconds
|
||||
*/
|
||||
duration?: number;
|
||||
}
|
||||
|
||||
interface LimiterInfo {
|
||||
/**
|
||||
* max value
|
||||
*/
|
||||
total: number;
|
||||
|
||||
/**
|
||||
* Number of calls left in current duration without decreasing current get
|
||||
*/
|
||||
remaining: number;
|
||||
|
||||
/**
|
||||
* Time in milliseconds until the end of current duration
|
||||
*/
|
||||
reset: number;
|
||||
}
|
||||
|
||||
class Limiter {
|
||||
constructor(opts: LimiterOption);
|
||||
|
||||
inspect(): string;
|
||||
|
||||
get(fn: (err: any, info: LimiterInfo) => void): void;
|
||||
}
|
||||
|
||||
export = Limiter;
|
||||
}
|
||||
Reference in New Issue
Block a user