#356 fix do not require points and duration options in wrappers#357
Conversation
There was a problem hiding this comment.
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
RLWrapperTimeoutsto supply defaultpoints/durationwhen calling the parent constructor. - Refined TypeScript declarations for
RLWrapperBlackAndWhite(no longer typed as extendingRateLimiterAbstract) and adjusted wrapper option typing forRLWrapperTimeouts.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 fullRateLimiterAbstractinterface to integrate seamlessly with existing features likeRateLimiterUnionandRLWrapperTimeouts. 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
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)isRateLimiterCompatiblehelper to check if an object is an instance of eitherRateLimiterAbstractorRateLimiterCompatibleAbstract. RefactoredRateLimiterUnion,RLWrapperTimeouts, andRateLimiterInsuredAbstractto 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
RLWrapperBlackAndWhiteto extendRateLimiterCompatibleAbstractand 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
RateLimiterCompatibleAbstractfromindex.jsfor public use. (index.js) [1] [2]RateLimiterStoreAbstractwhere thesetmethod incorrectly called_blockinstead of_set, and added the_setmethod to support the new interface. (lib/RateLimiterStoreAbstract.js) [1] [2]RateLimiterAbstractfor correct key parsing whenkeyPrefixis 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.