From 111bb0d69ee8ea029f608c7f6d4d1b58aabafaef Mon Sep 17 00:00:00 2001 From: Alexandr Borisov Date: Thu, 30 May 2024 21:59:26 +0300 Subject: [PATCH] Add types for getQueue --- CHANGELOG.md | 3 +++ src/index.js | 2 +- typings/index.d.ts | 23 ++++++++++++++--------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b948af..69dad29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log This project adheres to [Semantic Versioning](http://semver.org/). +## Unreleased +* Expose requests queue via getQueue (see https://github.com/aishek/axios-rate-limit/pull/62) + ## 1.3.3 * Fix axios dependency specification diff --git a/src/index.js b/src/index.js index 543e92a..0b20c52 100644 --- a/src/index.js +++ b/src/index.js @@ -159,8 +159,8 @@ function axiosRateLimit (axios, options) { var rateLimitInstance = new AxiosRateLimit(axios) rateLimitInstance.setRateLimitOptions(options) - axios.getMaxRPS = AxiosRateLimit.prototype.getMaxRPS.bind(rateLimitInstance) axios.getQueue = AxiosRateLimit.prototype.getQueue.bind(rateLimitInstance) + axios.getMaxRPS = AxiosRateLimit.prototype.getMaxRPS.bind(rateLimitInstance) axios.setMaxRPS = AxiosRateLimit.prototype.setMaxRPS.bind(rateLimitInstance) axios.setRateLimitOptions = AxiosRateLimit.prototype.setRateLimitOptions .bind(rateLimitInstance) diff --git a/typings/index.d.ts b/typings/index.d.ts index 8bad104..4ef593e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,15 +1,20 @@ import { AxiosInstance } from 'axios'; +export type RateLimitRequestHandler = { + resolve: () => boolean +} + export interface RateLimitedAxiosInstance extends AxiosInstance { - getMaxRPS: () => number, - setMaxRPS: (rps: number) => void, - setRateLimitOptions: (options: rateLimitOptions) => void, - // enable(axios: any): void, - // handleRequest(request:any):any, - // handleResponse(response: any): any, - // push(requestHandler:any):any, - // shiftInitial():any, - // shift():any + getQueue: () => RateLimitRequestHandler[], + getMaxRPS: () => number, + setMaxRPS: (rps: number) => void, + setRateLimitOptions: (options: rateLimitOptions) => void, + // enable(axios: any): void, + // handleRequest(request:any):any, + // handleResponse(response: any): any, + // push(requestHandler:any):any, + // shiftInitial():any, + // shift():any } export type rateLimitOptions = {