RateLimitStore.ts overview
Drizzle RateLimitStore, one row per key (a dialect’s Tables, or a table mapped with defineRateLimitTable). increment is two atomic statements, never a read-modify-write; on MySQL the count is read back, which can only refuse more. Rows of keys never seen again stay until purgeExpired.
Exports Grouped by Category
utils
PurgeExpiredOptions (interface)
Options for purgeExpired.
Signature
export interface PurgeExpiredOptions {
/**
* The most rows one call deletes, a positive integer; omitted, every
* spent row goes in one `DELETE`.
*/
readonly limit?: number
}
layer
RateLimitStore backed by drizzle, on top of DrizzleDatabase.
Signature
declare const layer: (
tables?: RateLimitTableInput
) => Layer.Layer<Auth.RateLimit.RateLimitStore, never, DrizzleDatabase>
make
Build a RateLimitStore over the ambient DrizzleDatabase.
Signature
declare const make: (
tables?: RateLimitTableInput
) => Effect.Effect<typeof Auth.RateLimit.RateLimitStore.Service, never, DrizzleDatabase>
purgeExpired
Delete the rate-limit rows whose window and block have both passed, in one DELETE over the ambient DrizzleDatabase.
The table holds one row per key, IP and identifier ever counted, and no store call deletes the row of a key that is never seen again, so without a purge it grows by one row per distinct caller. A row goes once its reset_at is not after now and its blocked_until is unset or not after now: the limiter then treats the key as one it has never seen, so the next request opens a fresh window either way. A row still inside its window or still blocked stays. Schedule it from the host (a cron trigger, a timer on a long-lived server); now is read from the Clock.
With options.limit the DELETE takes at most that many of those rows, chosen by key through a derived table, which PostgreSQL, SQLite and MySQL all accept (MySQL refuses a LIMIT directly inside IN): `DELETE … WHERE