odesli.js 1.3.5 → 1.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,22 +27,23 @@ class RateLimiter {
27
27
  * Most efficient for burst handling
28
28
  */
29
29
  async tokenBucket() {
30
- const now = Date.now()
31
- const timePassed = now - this.lastRefill
32
- const tokensToAdd = Math.floor(timePassed / this.windowMs) * this.maxRequests
33
-
34
- this.tokens = Math.min(this.maxRequests, this.tokens + tokensToAdd)
35
- this.lastRefill = now
36
-
37
- if (this.tokens >= 1) {
38
- this.tokens--
39
- return true
30
+ while (true) {
31
+ const now = Date.now()
32
+ const timePassed = now - this.lastRefill
33
+ const tokensToAdd = Math.floor(timePassed / this.windowMs) * this.maxRequests
34
+
35
+ this.tokens = Math.min(this.maxRequests, this.tokens + tokensToAdd)
36
+ this.lastRefill = now
37
+
38
+ if (this.tokens >= 1) {
39
+ this.tokens--
40
+ return true
41
+ }
42
+
43
+ // Calculate wait time
44
+ const waitTime = this.windowMs - (timePassed % this.windowMs)
45
+ await new Promise(resolve => setTimeout(resolve, waitTime))
40
46
  }
41
-
42
- // Calculate wait time
43
- const waitTime = this.windowMs - (timePassed % this.windowMs)
44
- await new Promise(resolve => setTimeout(resolve, waitTime))
45
- return this.tokenBucket()
46
47
  }
47
48
 
48
49
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "odesli.js",
3
- "version": "1.3.5",
3
+ "version": "1.3.6",
4
4
  "description": "Node.js Client to query odesli.co (song.link/album.link) API",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.js",
@@ -10,6 +10,18 @@
10
10
  "types": "./lib/index.d.ts",
11
11
  "import": "./lib/index.js",
12
12
  "require": "./lib/index.js"
13
+ },
14
+ "./rate-limiter": {
15
+ "import": "./lib/rate-limiter.js",
16
+ "require": "./lib/rate-limiter.js"
17
+ },
18
+ "./metrics": {
19
+ "import": "./lib/metrics.js",
20
+ "require": "./lib/metrics.js"
21
+ },
22
+ "./plugin-system": {
23
+ "import": "./lib/plugin-system.js",
24
+ "require": "./lib/plugin-system.js"
13
25
  }
14
26
  },
15
27
  "engines": {