Adds IRateLimit, RateLimitBudget, RateLimitDecision to a new rate-limit sub-module; adds RateLimited<F> brand and isRateLimited predicate following the Captured/ConsentChecked pattern; extends UseCaseManifest with rateLimit?: readonly RateLimitBudget[] so features can declare rate-limit gates in their manifests. Exports new types from @repo/core-shared/rate-limit and @repo/core-shared/conformance. Blocks stories 02, 03, and 04. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { describe, it, expectTypeOf } from "vitest";
|
|
import type {
|
|
IRateLimit,
|
|
RateLimitBudget,
|
|
RateLimitDecision,
|
|
} from "@/rate-limit/rate-limit.interface";
|
|
|
|
describe("rate-limit types", () => {
|
|
it("RateLimitBudget has the expected shape", () => {
|
|
expectTypeOf<RateLimitBudget>().toMatchTypeOf<{
|
|
name: string;
|
|
window: string;
|
|
budget: number;
|
|
}>();
|
|
});
|
|
|
|
it("RateLimitDecision has the expected shape", () => {
|
|
expectTypeOf<RateLimitDecision>().toMatchTypeOf<{
|
|
allowed: boolean;
|
|
remaining: number;
|
|
resetAt: Date;
|
|
}>();
|
|
});
|
|
|
|
it("IRateLimit.consume returns Promise<RateLimitDecision>", () => {
|
|
expectTypeOf<
|
|
IRateLimit["consume"]
|
|
>().returns.resolves.toEqualTypeOf<RateLimitDecision>();
|
|
});
|
|
|
|
it("IRateLimit.consume accepts optional weight", () => {
|
|
type ConsumeParams = Parameters<IRateLimit["consume"]>;
|
|
expectTypeOf<ConsumeParams[0]>().toEqualTypeOf<string>();
|
|
expectTypeOf<ConsumeParams[1]>().toEqualTypeOf<string>();
|
|
expectTypeOf<ConsumeParams[2]>().toEqualTypeOf<number | undefined>();
|
|
});
|
|
|
|
it("IRateLimit.reset returns Promise<void>", () => {
|
|
expectTypeOf<IRateLimit["reset"]>().returns.resolves.toEqualTypeOf<void>();
|
|
});
|
|
});
|