Skip to content

Commit

Permalink
chore: release 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
simllll committed Apr 22, 2021
1 parent f421cf9 commit 560cd84
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 36 deletions.
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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/).

Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
28 changes: 0 additions & 28 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 560cd84

Please sign in to comment.