From 022d14370e357d53dc735b301e26be8e7c6cdb8d Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Sat, 10 Jan 2026 15:09:42 -0300 Subject: [PATCH 1/2] fix: adjust types --- src/types/RateLimitRetryCtx.ts | 2 +- src/types/RateLimiterOptions.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/types/RateLimitRetryCtx.ts b/src/types/RateLimitRetryCtx.ts index e54f32f..212ab8a 100644 --- a/src/types/RateLimitRetryCtx.ts +++ b/src/types/RateLimitRetryCtx.ts @@ -7,7 +7,7 @@ * file that was distributed with this source code. */ -import type { RateLimitTarget } from '#src/types' +import type { RateLimitTarget } from '#src/ratelimiter/RateLimitTarget' export type RateLimitRetryCtx = { /** diff --git a/src/types/RateLimiterOptions.ts b/src/types/RateLimiterOptions.ts index 239f5ea..ba1ebc1 100644 --- a/src/types/RateLimiterOptions.ts +++ b/src/types/RateLimiterOptions.ts @@ -9,10 +9,11 @@ import type { RateLimitRule, - RateLimitTarget, RateLimitRetryClosure } from '#src/types' + import type { RateLimitStore } from '#src/ratelimiter/RateLimitStore' +import type { RateLimitTarget } from '#src/ratelimiter/RateLimitTarget' export type RateLimiterOptions = { /** From fa2f2d1018cc32bd7ad5e114e95223f490fe192f Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Sat, 10 Jan 2026 16:08:49 -0300 Subject: [PATCH 2/2] feat: lock setTimeout delay to 1d --- package-lock.json | 4 ++-- package.json | 2 +- src/ratelimiter/RateLimiterBuilder.ts | 15 +++++++++++++-- src/types/RateLimiterOptions.ts | 5 +---- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index f66355c..aa7788e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/ratelimiter", - "version": "5.6.0", + "version": "5.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/ratelimiter", - "version": "5.6.0", + "version": "5.7.0", "license": "MIT", "devDependencies": { "@athenna/cache": "^5.2.0", diff --git a/package.json b/package.json index 88d1a1d..d93375a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/ratelimiter", - "version": "5.6.0", + "version": "5.7.0", "description": "Respect the rate limit rules of API's you need to consume.", "license": "MIT", "author": "João Lenon ", diff --git a/src/ratelimiter/RateLimiterBuilder.ts b/src/ratelimiter/RateLimiterBuilder.ts index af42744..fdb9c16 100644 --- a/src/ratelimiter/RateLimiterBuilder.ts +++ b/src/ratelimiter/RateLimiterBuilder.ts @@ -21,7 +21,7 @@ import type { } from '#src/types' import { debug } from '#src/debug' -import { Macroable, Options } from '@athenna/common' +import { Macroable, Options, Parser } from '@athenna/common' import { RateLimitStore } from '#src/ratelimiter/RateLimitStore' import { RateLimitTarget } from '#src/ratelimiter/RateLimitTarget' import { MissingKeyException } from '#src/exceptions/MissingKeyException' @@ -806,7 +806,7 @@ export class RateLimiterBuilder extends Macroable { await this.tryToRunQueueItem() } - this.timer = setTimeout(fire, options.delay) + this.timer = setTimeout(fire, this.getDelay(options.delay)) } /** @@ -979,6 +979,17 @@ export class RateLimiterBuilder extends Macroable { } } + /** + * Locks the delay to 1 day to avoid big set timeout instances. + */ + private getDelay(delay: number) { + if (delay > Parser.timeToMs('1d')) { + return Parser.timeToMs('1d') + } + + return delay + } + /** * Run the pending closure defined by user. */ diff --git a/src/types/RateLimiterOptions.ts b/src/types/RateLimiterOptions.ts index ba1ebc1..c43ece9 100644 --- a/src/types/RateLimiterOptions.ts +++ b/src/types/RateLimiterOptions.ts @@ -7,10 +7,7 @@ * file that was distributed with this source code. */ -import type { - RateLimitRule, - RateLimitRetryClosure -} from '#src/types' +import type { RateLimitRule, RateLimitRetryClosure } from '#src/types' import type { RateLimitStore } from '#src/ratelimiter/RateLimitStore' import type { RateLimitTarget } from '#src/ratelimiter/RateLimitTarget'