@clov-std/elysia-ratelimit 5.0.0-rc.1 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -37,10 +37,10 @@ var consumeRateLimit = async (store, { set, request, path, route }, { policy, ke
|
|
|
37
37
|
if (counted.has(storeKey))
|
|
38
38
|
return;
|
|
39
39
|
countedRequests.set(request, counted.add(storeKey));
|
|
40
|
-
const count = await store.increment(storeKey);
|
|
41
|
-
if (
|
|
40
|
+
const [count, ttl] = await Promise.all([store.increment(storeKey), store.ttl(storeKey)]);
|
|
41
|
+
if (ttl < 0)
|
|
42
42
|
await store.expire(storeKey, window);
|
|
43
|
-
const reset =
|
|
43
|
+
const reset = ttl < 0 ? window : ttl;
|
|
44
44
|
appendHeader(set.headers, "RateLimit-Policy", `"${policy}";q=${limit};w=${window}`);
|
|
45
45
|
appendHeader(set.headers, "RateLimit", `"${policy}";r=${Math.max(0, limit - count)};t=${reset}`);
|
|
46
46
|
if (count <= limit)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clov-std/elysia-ratelimit",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Rate limiting for Elysia as a route macro, with RFC 9457 429 responses and pluggable storage.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"elysia",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"@clov-std/kv-store": "^2.0.5"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/bun": "^1.4.
|
|
43
|
-
"oxfmt": "0.
|
|
44
|
-
"oxlint": "1.
|
|
45
|
-
"oxlint-tsgolint": "7.0.
|
|
42
|
+
"@types/bun": "^1.4.4",
|
|
43
|
+
"oxfmt": "0.75.0",
|
|
44
|
+
"oxlint": "1.90.0",
|
|
45
|
+
"oxlint-tsgolint": "7.0.2005",
|
|
46
46
|
"typescript": "^7.0.2"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|