Skip to content

#356 fix do not require points and duration options in wrappers#357

Merged
animir merged 11 commits into
masterfrom
#356-fix-wrappers-require-opts
Apr 3, 2026
Merged

#356 fix do not require points and duration options in wrappers#357
animir merged 11 commits into
masterfrom
#356-fix-wrappers-require-opts

Conversation

@animir
Copy link
Copy Markdown
Owner

@animir animir commented Mar 24, 2026

This pull request introduces a new abstraction, RateLimiterCompatibleAbstract, to support lightweight, interface-compatible rate limiter wrappers and updates the codebase and documentation to reflect this addition. It enables wrappers that don't require the full RateLimiterAbstract interface to integrate seamlessly with existing features like RateLimiterUnion and RLWrapperTimeouts. The PR also refactors several classes and methods to accept either the original or compatible abstract classes, and updates documentation to describe the enhanced fixed window algorithm and new extensibility options.

Key changes:

Core Abstractions and Compatibility

  • Introduced RateLimiterCompatibleAbstract, a lightweight abstract class defining the minimal interface for compatible rate limiter wrappers. This enables custom wrappers to be used interchangeably with full-featured limiters in unions, wrappers, and as insurance limiters. (lib/RateLimiterCompatibleAbstract.js)
  • Added isRateLimiterCompatible helper to check if an object is an instance of either RateLimiterAbstract or RateLimiterCompatibleAbstract. Refactored RateLimiterUnion, RLWrapperTimeouts, and RateLimiterInsuredAbstract to use this helper, allowing them to accept both types. (lib/helper/isRateLimiterCompatible.js, lib/RateLimiterUnion.js, lib/RLWrapperTimeouts.js, lib/RateLimiterInsuredAbstract.js) [1] [2] [3] [4] [5] [6] [7]

Wrapper and API Refactoring

  • Refactored RLWrapperBlackAndWhite to extend RateLimiterCompatibleAbstract and implement the required interface, making it fully compatible with the new abstraction and simplifying its method logic. (lib/RLWrapperBlackAndWhite.js) [1] [2] [3]

Exports and Internal Fixes

  • Exported RateLimiterCompatibleAbstract from index.js for public use. (index.js) [1] [2]
  • Fixed a bug in RateLimiterStoreAbstract where the set method incorrectly called _block instead of _set, and added the _set method to support the new interface. (lib/RateLimiterStoreAbstract.js) [1] [2]
  • Minor fix in RateLimiterAbstract for correct key parsing when keyPrefix is empty. (lib/RateLimiterAbstract.js)

These changes improve the flexibility and extensibility of the rate limiter library, making it easier to implement and integrate custom wrappers while maintaining compatibility with existing features.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates wrapper implementations/types so callers don’t have to provide points and duration when constructing wrapper limiters, aligning wrapper ergonomics with their runtime intent.

Changes:

  • Updated RLWrapperTimeouts to supply default points/duration when calling the parent constructor.
  • Refined TypeScript declarations for RLWrapperBlackAndWhite (no longer typed as extending RateLimiterAbstract) and adjusted wrapper option typing for RLWrapperTimeouts.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.

File Description
types.d.ts Updates wrapper typings, including RLWrapperBlackAndWhite shape and RLWrapperTimeouts constructor options.
lib/RLWrapperTimeouts.js Changes constructor to pass default points/duration to the superclass.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/RLWrapperTimeouts.js
Comment thread lib/RLWrapperTimeouts.js
Copy link
Copy Markdown
Contributor

@florian-schunk florian-schunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/RLWrapperBlackAndWhite.js
Comment thread lib/RateLimiterUnion.js
Comment thread test/RateLimiterCompatibleAbstract.test.js
Comment thread lib/RateLimiterUnion.js
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 28 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/RLWrapperBlackAndWhite.js
@animir animir merged commit 16bd23a into master Apr 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants