Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: aishek/axios-rate-limit
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.3.3
Choose a base ref
...
head repository: aishek/axios-rate-limit
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 8 commits
  • 8 files changed
  • 3 contributors

Commits on May 29, 2024

  1. Fix npm publish CI warnings

    Alexandr Borisov authored and aishek committed May 29, 2024
    Copy the full SHA
    d3cbf78 View commit details

Commits on May 30, 2024

  1. expose queue

    Megapixel99 authored and aishek committed May 30, 2024
    Copy the full SHA
    560485e View commit details
  2. Add types for getQueue

    Alexandr Borisov committed May 30, 2024
    Copy the full SHA
    111bb0d View commit details
  3. Bump version number to 1.4.0

    Alexandr Borisov committed May 30, 2024
    Copy the full SHA
    534c9ae View commit details

Commits on Jun 3, 2024

  1. Create FUNDING.yml

    aishek authored Jun 3, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    1379d61 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c61ec87 View commit details

Commits on Jun 4, 2024

  1. Update README.md [ci skip]

    Add getQueue() usage example
    aishek authored Jun 4, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    12f431d View commit details

Commits on Jun 10, 2024

  1. Add getQueue() tests

    Alexandr Borisov authored and aishek committed Jun 10, 2024
    Copy the full SHA
    4d2fed8 View commit details
Showing with 42 additions and 12 deletions.
  1. +14 −0 .github/FUNDING.yml
  2. +2 −2 .github/workflows/npm-publish.yml
  3. +3 −0 CHANGELOG.md
  4. +1 −0 README.md
  5. +2 −0 __tests__/index.js
  6. +1 −1 package.json
  7. +5 −0 src/index.js
  8. +14 −9 typings/index.d.ts
14 changes: 14 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# These are supported funding model platforms

github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
polar: # Replace with a single Polar username
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
custom: ['https://link.trustwallet.com/send?address=0x0f6E6CDBB3E1631722A28B012eDa9Ea6229CF013&asset=c60_t0xc3761EB917CD790B30dAD99f6Cc5b4Ff93C4F9eA', 'https://link.trustwallet.com/send?asset=c195_tTR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t&address=TWcdNRFeo8MrP992q1SxfbBYPKf6dCT7d6']
4 changes: 2 additions & 2 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
node-version: 20
- run: npm ci
- run: npm test

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).

## 1.4.0
* Expose requests queue via getQueue (see https://github.com/aishek/axios-rate-limit/pull/62)

## 1.3.3
* Fix axios dependency specification

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ const http = rateLimit(axios.create(), { maxRequests: 2, perMilliseconds: 1000,
http.getMaxRPS() // 2
http.get('https://example.com/api/v1/users.json?page=1') // will perform immediately
http.get('https://example.com/api/v1/users.json?page=2') // will perform immediately
http.getQueue() // [{...}]
http.get('https://example.com/api/v1/users.json?page=3') // will perform after 1 second from the first one

// options hot-reloading also available
2 changes: 2 additions & 0 deletions __tests__/index.js
Original file line number Diff line number Diff line change
@@ -81,10 +81,12 @@ it('support dynamic options', async function () {
}
await delay(90)
expect(onSuccess.callCount).toEqual(2)
expect(http.getQueue().length).toEqual(1)

await Promise.all(requests)
var end = Date.now()
expect(onSuccess.callCount).toEqual(3)
expect(http.getQueue().length).toEqual(0)
expect(end - start).toBeGreaterThan(100)
await delay(110)

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "axios-rate-limit",
"description": "Rate limit for axios.",
"version": "1.3.3",
"version": "1.4.0",
"license": "MIT",
"bugs": {
"url": "https://github.com/aishek/axios-rate-limit/issues"
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -18,6 +18,10 @@ AxiosRateLimit.prototype.getMaxRPS = function () {
return this.maxRequests / perSeconds
}

AxiosRateLimit.prototype.getQueue = function () {
return this.queue
}

AxiosRateLimit.prototype.setMaxRPS = function (rps) {
this.setRateLimitOptions({
maxRequests: rps,
@@ -155,6 +159,7 @@ function axiosRateLimit (axios, options) {
var rateLimitInstance = new AxiosRateLimit(axios)
rateLimitInstance.setRateLimitOptions(options)

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
23 changes: 14 additions & 9 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -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 = {