You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Audited writes: generated mutations that record an audit row in the same transaction, with in-transaction hooks #572
The libraries design names "audit history" as a future library. This is the case for building it, with a working prototype.
An application that must log every state change cannot use the generated create, update and delete routes, because they offer no place to write the audit row in the same transaction. In one downstream application that single fact means no entity uses a generated write: every generated route it mounts is read-only. Each write is a hand-written store instead: 159 audit insert sites across the application, and about 1,300 lines of pattern code for its most recent ten-entity module.
A prototype generator of 273 lines closes most of that. It reads three marks on an entity (an audit name, the allowed writes, and per field whether its value may appear in the log) and emits one function per write. Each validates strictly, opens a transaction, writes the row, runs optional before and after hooks inside the transaction, and writes one audit row. The hooks matter: real writes cascade, and the cascade must commit or roll back with the row and its audit record. Field values are logged by name only unless marked, so a rule like "an amount never reaches the log" holds by construction.
This fits the library model the same way the ai library does: a base audit entity with its requirements, and a generator the library implies.
A hook seam in the generated mutation helpers: before and after, inside the transaction
An audit library: base audit entity, requirements (same transaction, append-only, values logged only when marked)
A way to mark an entity as audited and name which writes exist, decided against the rule that libraries add no vocabulary
A per-field mark for "value may be logged", defaulting to no
A generated test per write: exactly one audit row, no unmarked value
Safety-relevant generators default to overwriting hand edits
Activity
feat(metadata): add business-rules operations and lifecycles (#610)