Current collected state Current
Observed since 20 Oct, 22:00 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
@021.is/spine-ratelimit
Postgres-backed sliding-window rate limiter. Sliding-window per-key buckets. No Redis required.
Postgres-backed sliding-window rate limiter. Sliding-window per-key buckets. Multi-window in parallel (1m + 1h + 1d). No Redis required.
import { RateLimiter, makePrismaStore } from "@021.is/spine-ratelimit";
const limiter = new RateLimiter({ store: makePrismaStore(prisma) });
// On every API request:
await limiter.hit({
subject: `api-key:${keyId}`,
limits: [
{ window: "1m", max: 60 },
{ window: "1d", max: 100_000 },
],
}); // throws RateLimitedException → spine-errors maps to 429 + Retry-After
model RateLimitBucket {
subject String
window String
bucketStart DateTime
count Int @default(0)
@@id([subject, window, bucketStart])
}
UPSERT + increment per (subject, window, bucketStart). Postgres guarantees concurrency safety.hit() checks 1m AND 1d limits at once.RateLimitedException.retryAfterSec reflects the tightest window — the one that has the least time until reset.import { makeMemoryStore } from "@021.is/spine-ratelimit";
const limiter = new RateLimiter({ store: makeMemoryStore() });
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
@021.is/spine-errorsEnvironment{
"local_name": "@021.is/spine-errors",
"alias": false,
"peer_metadata": null
} | ^0.4.3 | runtime |
Source distribution
{
"integrity": "sha512-92Stx/iliJPTRTioIQ2/Wta4k6ZL/s0COnM9UzjysfZ0P0Q901OEZ3ImQmtnrULoREEaZNSEZPLKj61NS+LTNg==",
"shasum": "cbffe7a0519032f55b78ba3d9aeea055fe101d7b",
"tarball": "https://registry.npmjs.org/@021.is/spine-ratelimit/-/spine-ratelimit-0.4.3.tgz",
"fileCount": 5,
"unpackedSize": 9203,
"signatures": [
{
"keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U",
"sig": "MEYCIQC5GXKGvQ3aCDp7VN8qGc1CO2Qji3InIy7YvCwBoHuY1QIhAOqHE7r6CupBJVkpgc8XoNZdFeWxR89L9zQCqe4n6sYB"
}
]
}Observed since 20 Oct, 22:00 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:d54289e27eab6cc800aeee7a71eeac1ad0b04701b6a75fee1e111e1f20f42281