Entity / Laws

Where does a rule go

Pick the rule kind by what data it needs to read:

Rule readsKindDeclared withRefused as
One field's valueField schemaSchema on the fieldDecode failure
Variant-dependent fieldsCase shapeEntity.defineVariantsDecode failure or Invalid
Counts or lookups on other rowsDerived memberDerived.count, Derived.existsComputed, never stored
Row left by a writeState invariantEntity.invariant (after)Invalid
Row before and after a writeTransition invariantEntity.invariant (before, after)Invalid
Row before write and inputPreconditionWrite.update(..., { when })Unmet
Named start and end statesLifecycle statesEntity.refine + { from, becomes }Unmet or Invalid
Principal and target rowAuthorizationGuards.attachForbidden
Shared Sync snapshotDocument lawlaws on forApplication(...).makeInvalid

A write lands only when authorization, preconditions, and invariants (both state and transition) all hold. The same pattern applies to a Sync document: authorize and all document laws must pass together.

Authorization rules group alternatives within their own kind (for example, Update: [isOwner, isManager]). Invariants and preconditions apply to every caller unconditionally: an admin cannot bypass an invariant, and passing an invariant grants no authority. Their refusals reflect the difference: Forbidden means you lack permission, Unmet means the row is in the wrong state, and Invalid means the resulting row breaks a rule.

How one declaration reaches every checker

Each state has one authoritative writer that decides rules where state changes—the server writer for SQL rows, or the Sync journal for shared documents. Client Data.can, forms, and database CHECK constraints read the same Expr declarations to give early feedback or add defense in depth. When a client lacks a field a rule needs, it reports Undecided and defers to the server instead of guessing.

Every rule below uses the Expr language from Expressions; see One domain declaration to view all kinds together.