Add ratelimtier.d.ts

This commit is contained in:
Aya Morisawa
2015-11-28 02:42:35 +09:00
parent fb2b3b1e06
commit ad6c1fad6c
2 changed files with 76 additions and 0 deletions
+17
View File
@@ -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;
});
+59
View File
@@ -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;
}