Mutation Hooks
Mutation hooks live in use-<entity>-mutations.ts and provide the React hook interface for executing writes with safety enforcement.
What They Do
Section titled “What They Do”Mutation hooks are the authoritative write boundary of the entity system.
They:
- wrap raw mutations from
<entity>.mutations.ts - enforce hard invariants before writing
- convert runtime context into transactional writes and notifications
Import Pattern
Section titled “Import Pattern”There is currently no package-wide hooks/mutations barrel export.
Import mutation hooks from entity subpaths:
import { useWorkProjectMutations } from "@life-manager/db/entities/work/project";Safety
Section titled “Safety”If a business rule protects data integrity, it must be enforced here, not only in actions. The mutation hook is the last line of defense before data hits the local database.
Strong vs Weak Enforcement
Section titled “Strong vs Weak Enforcement”Strong
Section titled “Strong”- derive the required current-state facts internally before writing
- or require the validated guard input when that is the only practical source
- optional guard input that disables enforcement when omitted
The package is moving toward strong enforcement for all safety-relevant writes.
Good Current Examples
Section titled “Good Current Examples”finance/single-cashflowfinance/recurring-cashflowwork/time-entrywork/project