Entity / One domain declaration
How refusals map back to declarations
| Failure condition | Client sees | Origin | Recovery |
|---|---|---|---|
| Caller lacks permission | Forbidden | foldkit-guard | Unauthorized; keep hidden |
| Row is in wrong state | Unmet | Write from or when | Re-read updated row |
| Row revision changed | Conflict | Write expect | Re-read and retry |
| Resulting row breaks invariant | Invalid + message / path | Entity.invariant | Show error at path |
| Input fails schema validation | Field error | Field Schema | Fix input in form |
Four edge cases to expect:
- Stale client prediction: If another user reduced stock before your
Reservearrived, the server returnsInvalid, Remote discards the optimistic layer, andData.refusalsurfaces the reason. - Missing fields on client: When the client lacks
stock, it sendsReservedirectly and lets the server decide. - Cross-field form invariants: Form errors from multi-field invariants clear on any edit to the form, since editing another referenced field might satisfy the rule.
- Database
CHECKlimits: State invariants compile to SQLCHECKconstraints viacheckConstraints, whereas transition invariants (before+after) are enforced only by the server writer (which logsServerOnlyRulesonce at startup).
Use Law.check from foldkit-remote/testing to verify automatically that client predictions match server execution; see examples/writes.
Five rules that prevent drift
- Declare relations together: Pass all related Entities to one
Entity.relatecall. - Keep Selections declarative: Selections carry schemas and compile into Remote's requirement graph without fetching directly.
- Share predicates as values: One
Exprdrives SQL compilation, in-memoryevaluate, and browserJudge. - Bind the guarded descriptor: Add derived members and invariants to the Entity first, then pass the result of
Guards.attachto your server binding so guard rules are enforced at startup. - Map operation inputs via
Entity.input: Forms,Entity.selectFor, andEntity.valuesForall derive from that mapping.