diff --git a/ratelimiter/ratelimiter-tests.ts b/ratelimiter/ratelimiter-tests.ts new file mode 100644 index 000000000..14d42422e --- /dev/null +++ b/ratelimiter/ratelimiter-tests.ts @@ -0,0 +1,17 @@ +/// +/// + +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; +}); diff --git a/ratelimiter/ratelimiter.d.ts b/ratelimiter/ratelimiter.d.ts new file mode 100644 index 000000000..6e9883dd5 --- /dev/null +++ b/ratelimiter/ratelimiter.d.ts @@ -0,0 +1,59 @@ +// Type definitions for ratelimiter 2.1.1 +// Project: https://github.com/tj/node-ratelimiter +// Definitions by: Aya Morisawa +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +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; +}