ADR 0012 — Typed Actions via Standard Schema
Status: Accepted (★ deviation: siblings validate with valibot only and have no user-typed payloads)
Context
Section titled “Context”The mission asks for “a typed schema per action and validation”. Webhooks has an event-type catalog
with an optional JSON schema for documentation, but payloads are untyped JsonValue. Audit hosts
want audit.record({ action: "invoice.paid", metadata: { invoiceId, amount } }) to be type-checked
at compile time and validated at runtime, with whatever validator they already use.
Decision
Section titled “Decision”defineActions({ "invoice.paid": { metadata: schema, targets: ["invoice"], description } })accepts any Standard Schema v1 validator (valibot, zod, arktype, effect…) formetadata. The Standard Schema types are vendored (a few type-only lines; zero runtime dependency).createAuditCore({ actions })is generic over the action map:record()infers the action name union and each action’smetadatainput type; unknown actions are a type error and, withstrictActions: true(default whenactionsis given), a runtimeValidationError.- Runtime validation runs the schema’s
~standard.validateon the record path (async-capable); the validated output is what gets stored and hashed. - The catalog persisted in storage (for the UI: names, descriptions, groups, target types) is
synced from
actionsat startup and can be extended from the admin UI with descriptions only — schemas live in code (never authored through the UI). - Internal input validation (shapes of actor/targets/context, API bodies) stays on valibot, like the siblings.
Consequences
Section titled “Consequences”- No validator lock-in; type inference matches the host’s validator.
- Untyped mode still works: without
actions, anyactionstring matching the name pattern is accepted and metadata is any JSON object.