rate-limit-mongo
rate-limit-mongo copied to clipboard
Use new `Store` interface from `express-rate-limit` v6
Hi @okv,
I recently helped out with a Typescript rewrite for the express-rate-limit
package, which also introduced a couple of changes to the Store
interface:
- Added the
init
method for stores to set themselves up using options passed to the middleware. - Rename the
incr
method toincrement
. - Allow the
increment
,decrement
,resetKey
andresetAll
methods to return a promise. - Old stores will automatically be promisified and used.
As the external tests show, the store still works (without any changes) with v6 of express-rate-limit
. However, implementing the newer Store
interface allows for the following:
- The users do not need to pass
expireTimeMs
/windowMs
twice (once to the middleware and once to the store) with the introduction of theinit
method. - Since all functions can now return Promises, it removes the need for the numerous callbacks used in the code.
I would be happy to open/help out with a PR that implements the new Store
interface.
Also, I see that #27 is still open and there is no @types/rate-limit-mongo
package. Would you like this PR to also:
- Rewrite the library in Typescript, OR
- Add a type definition file (
index.d.ts
like what @gtmsingh has suggested in https://github.com/2do2go/rate-limit-mongo/issues/27#issuecomment-855444547) so that Typescript users don't encounter errors while using this library.
Please let me know your thoughts on the above.
Thanks, Vedant
// cc @nfriedly
Hey @gamemaker1, to be honest I'm not a big TypeScript fan. But everything except it sounds awesome :smiley:
I would keep the code in JS, but index.d.ts
could be useful. Any assistance with reviewing #28 is highly appreciated.
I will try to take a closer look at all this next weekend.
Great, I'll start working on a PR this weekend! I'll also take a look at #28.
Is this issue stale? Not to necrobump but it would be nice to support v6 👍
@FxllenCode yes, this issue is stale since I have not gotten the time to convert the store to by yet :(
Although ypu could send in a PR as per the discussion above.