feat(core-shared): add NoopRateLimit and InMemoryRateLimit implementations
NoopRateLimit always allows with Infinity remaining — zero-overhead default for apps without a wired rate-limit impl. InMemoryRateLimit uses a Map-backed fixed-window with check-at-read expiry and an injected clock for testability. Both exported from the core-shared barrel. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
15
packages/core-shared/src/rate-limit/noop-rate-limit.ts
Normal file
15
packages/core-shared/src/rate-limit/noop-rate-limit.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import type { IRateLimit, RateLimitDecision } from "./rate-limit.interface";
|
||||
|
||||
const EPOCH = new Date(0);
|
||||
|
||||
export class NoopRateLimit implements IRateLimit {
|
||||
async consume(
|
||||
_budgetName: string,
|
||||
_key: string,
|
||||
_weight?: number,
|
||||
): Promise<RateLimitDecision> {
|
||||
return { allowed: true, remaining: Infinity, resetAt: EPOCH };
|
||||
}
|
||||
|
||||
async reset(_budgetName: string, _key: string): Promise<void> {}
|
||||
}
|
||||
Reference in New Issue
Block a user