Extracted from patitas-peludas onto the object contract. The node now takes the
name it provides — the original registered 'rate-limit' while providing
'rateLimit', so two instances shared a node name and rule 2 could not hold.
onShutdown closes the store this plugin built. One passed in owns its own
lifecycle, and is closed only if it offers a close().
Every test that builds an app closes it, through a helper that says why: the
sweep timer is deliberately not unref'ed, so an app left open keeps the test
runner alive after its assertions have passed. That is the same behaviour the
exit test measures, so these exercise the shutdown path in passing.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The original extended core's HttpError, which is a value import and makes the
published plugin need core at run time. The brand is a registry-wide symbol, so
core renders the 429 without this package depending on it, and it survives two
copies of core in one tree where instanceof would not.
The fields asserted here are exactly the ones HttpErrorLike declares. That core
really renders them is proven end to end in the limiter's own tests, which read
a 429 and its Retry-After back out of app.fetch.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
hit() called evictExpired on every new or expired key, which is a full walk of
the map — O(N^2) over N callers, and a client rotating addresses drives it on
purpose. A timer armed on the first hit does the same work off the hot path.
It is not unref'ed, deliberately: the timer holds the process open so that
failing to release it fails the exit test rather than leaking quietly.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>