Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions skills/objectstack-data/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,13 @@ export const Invoice = ObjectSchema.create({
- Use `requiredWhen` for conditional requiredness; the ObjectQL validator
enforces it on submit. The `conditionalRequired` alias was REMOVED in
protocol 17 — emitting it is a parse error.
- **Choose by intent — invariant or transition gate.** A fact that must hold for
*every stored record* is an invariant: express it in `validations[]`. A
condition on a *transition* ("required once the record reaches `paid`") is
`requiredWhen` / field bounds, which let already-stored rows through. A
transition gate written as an invariant bricks existing data; an invariant
written as a transition gate never enforces itself.
- **Choose by intent — invariant or transition gate.** A fact true of *every
stored record* is an invariant: a `validations[]` `script` rule. A row that
violates it is refused on any edit until repaired. A *transition* condition
("required once the record reaches `paid`") is `requiredWhen` / field bounds,
which judge the write, not the stored row. "Required when X" reads like an
invariant and is not one; an invariant written as a gate never enforces
itself.
- For inline `master_detail` grids, predicates are evaluated row-by-row against
the child row's `record`, so line-item rules should live on child fields.
- For complex predicates, load **objectstack-formula** and emit CEL via
Expand Down
9 changes: 9 additions & 0 deletions skills/objectstack-data/rules/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ the **failure** condition — validation **fails** when it evaluates to `true`.

## Script Validation

**Tool choice — this is the invariant tool.** `script` and `cross_field`
are judged against the *merged* record on every write, with no pre-state
exemption, so a row that already violates the rule is refused on any edit until
a repairing write lands (frozen, not bricked). A condition that must hold only
from a transition onward is not this tool: use `requiredWhen` or a field bound
(`min` / `max` / `minLength` / `maxLength`), which judge the write, not the
stored row (see **Choose by intent — invariant or transition gate** in
`SKILL.md`).

```typescript
import { P } from '@objectstack/spec';

Expand Down
Loading