writeonce/docs/examples/porch/middleware/store.wo
shoney.arickathil 192d451f5e feat(porch-store): store tables for rate limit + idempotency (Phase A)
(cherry picked from commit 519d4117fd0d6d0bd7d51f80bcb20de4d6294503)
2026-09-15 01:15:30 +02:00

24 lines
No EOL
881 B
Text

-- porch/middleware/store.wo — store-backed middleware tables.
-- Two purpose-shaped @table classes for rate limiting and idempotency.
-- Iteration 1 of the porch track.
-- Rate limiter: fixed-window counter.
-- Key format: "ip:192.168.1.1" or "principal:alice"
-- Window = start of current window in time.ticks (µs monotonic)
@table(name: "rate_limit_counters", index: [key])
class RateLimitCounter {
key: Text @unique
count: Int
window: Int
}
-- Idempotency: stored response for replay.
-- Key format: "idem:keyheader" or "idem:keyheader:sha256(method|path|body)"
-- Response = JSON-encoded Resp {status, headers, body} (allowlist: status, body, content-type)
-- created_at = time.ticks when stored (µs monotonic) for lazy expiry
@table(name: "idempotency_keys", index: [key])
class IdempotencyKey {
key: Text @unique
response: Text
created_at: Int
}