3.4.6 • Published 6 months ago

@types/ratelimiter v3.4.6

Weekly downloads
6,665
License
MIT
Repository
github
Last release
6 months ago

Installation

npm install --save @types/ratelimiter

Summary

This package contains type definitions for ratelimiter (https://github.com/tj/node-ratelimiter).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ratelimiter.

index.d.ts

// Type definitions for ratelimiter 3.4
// Project: https://github.com/tj/node-ratelimiter
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
//                 Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

interface RedisClient {
    multi(operations: any[][]): { exec(cb: (err: any, res: any) => unknown): void };
}

declare class Limiter {
    constructor(opts: Limiter.LimiterOption);

    /**
     * Inspect implementation
     */
    inspect(): string;

    /**
     * Get values and header / status code and invoke `fn(err, info)`.
     */
    get(fn: (err: any, info: Limiter.LimiterInfo) => void): void;
}

declare namespace Limiter {
    interface LimiterOption {
        /**
         * The identifier to limit against (typically a user id)
         */
        id: string;

        /**
         * Redis connection instance
         */
        db: RedisClient;

        /**
         * Max requests within duration
         * @default 2500
         */
        max?: number | undefined;

        /**
         * Duration of limit in milliseconds
         * @default 3600000
         */
        duration?: number | undefined;
    }

    /**
     * Result Object
     */
    interface LimiterInfo {
        /**
         * `max` value
         */
        total: number;

        /**
         * number of calls left in current `duration` without decreasing current `get`
         */
        remaining: number;

        /**
         * time since epoch in seconds at which the rate limiting period will end (or already ended)
         */
        reset: number;

        /**
         * time since epoch in milliseconds at which the rate limiting period will end (or already ended)
         */
        resetMs: number;
    }
}

export = Limiter;

Additional Details

  • Last updated: Thu, 09 Dec 2021 09:01:25 GMT
  • Dependencies: none
  • Global values: none

Credits

These definitions were written by Aya Morisawa, and Piotr Błażejewicz.

3.4.6

6 months ago

3.4.5

7 months ago

3.4.4

2 years ago

3.4.3

2 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.4.0

4 years ago

2.1.28

8 years ago

2.1.27

8 years ago

2.1.26-alpha

8 years ago

2.1.25-alpha

8 years ago

2.1.24-alpha

8 years ago

2.1.23-alpha

8 years ago

2.1.22-alpha

8 years ago

2.1.21-alpha

8 years ago

2.1.20-alpha

8 years ago

2.1.15-alpha

8 years ago

2.1.14-alpha

8 years ago