From 560cd84b529e38db9c9a5a4a4c833e1bfbeb9ae0 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 22 Apr 2021 10:24:01 +0200 Subject: [PATCH] chore: release 2.0 --- CHANGELOG.md | 6 ------ README.md | 14 ++++++++++++++ package.json | 4 ++-- src/index.ts | 28 ---------------------------- yarn.lock | 7 +++++++ 5 files changed, 23 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cb6a93..c71e0e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,3 @@ -# Fork -this is a fork of https://github.com/aishek/axios-rate-limit which has following changes in it: -* rewrite in Typescript -* allows passing in an redis instance, to use it as queue storage. this allows global rate limits accros - different processes. - # Change Log This project adheres to [Semantic Versioning](http://semver.org/). diff --git a/README.md b/README.md index 1390e2c..f6e6cd5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ +# Fork +this is a fork of https://github.com/aishek/axios-rate-limit which has following changes in it: +* rewrite in Typescript +* allows passing in a custom store, to share the state between instances/servers. + +Note: this module does not share state with other processes/servers by default. Use a redis or Memcached Store for shared states. + +### Stores +this fork uses the stores avaialble from express rate limiting. Therefore easy extendable :) + +- Memory Store _(default, built-in)_ - stores hits in-memory in the Node.js process. Does not share state with other servers or processes. +- [Redis Store](https://npmjs.com/package/rate-limit-redis) +- [Memcached Store](https://npmjs.org/package/rate-limit-memcached) + # axios-rate-limit [![npm version](https://img.shields.io/npm/v/axios-rate-limit.svg?style=flat-square)](https://www.npmjs.com/package/axios-rate-limit) diff --git a/package.json b/package.json index 1fc8aa8..69c0d12 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "axios-rate-limit", + "name": "@hokify/axios-rate-limit", "description": "Rate limit for axios.", - "version": "1.3.0", + "version": "2.0.0", "license": "MIT", "bugs": { "url": "https://github.com/aishek/axios-rate-limit/issues" diff --git a/src/index.ts b/src/index.ts index 4d65f26..bae84c6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -155,34 +155,6 @@ export class AxiosRateLimit { queued.resolve(); }); } - - private shiftOLD() { - if (!this.queue.length) return; - if (this.timeslotRequests === this.maxRequests) { - if (this.timeoutId && typeof this.timeoutId.ref === 'function') { - this.timeoutId.ref(); - } - - return; - } - - const queued = this.queue.shift(); - // queued redis - queued?.resolve(); - - if (this.timeslotRequests === 0) { - this.timeoutId = setTimeout(() => { - this.timeslotRequests = 0; - this.shift(); - }, this.perMilliseconds); - - if (typeof this.timeoutId.unref === 'function') { - if (this.queue.length === 0) this.timeoutId.unref(); - } - } - - this.timeslotRequests += 1; - } } /** diff --git a/yarn.lock b/yarn.lock index 4d15694..bf4e2d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -659,6 +659,13 @@ dependencies: "@types/node" "*" +"@types/ioredis@^4.22.3": + "integrity" "sha512-V23g0XZUmkm0Hp/GsQYV5Wz12ynm6h6lyi5v/o63iyqFV7+8t3k5YxCnFWVWFEjO6mvRI7V6f7YxNVxIjPsSUw==" + "resolved" "https://registry.npmjs.org/@types/ioredis/-/ioredis-4.22.3.tgz" + "version" "4.22.3" + dependencies: + "@types/node" "*" + "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1": "integrity" "sha512-sz7iLqvVUg1gIedBOvlkxPlc8/uVzyS5OwGz1cKjXzkl3FpL3al0crU8YGU1WoHkxn0Wxbw5tyi6hvzJKNzFsw==" "resolved" "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz"