feat: field conditional rules (CEL) — spec + server enforcement (B2)#1649
Merged
Conversation
…quiredWhen (CEL) Add three CEL-predicate field props (over `record`) for field-level conditional behavior, designed for dual-side evaluation: the client form toggles visibility/read-only/required live, the server enforces them. `requiredWhen` is the canonical name; `conditionalRequired` stays as a back-compat alias. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…es (B2) Server-side enforcement for the conditional field rules: - evaluateValidationRules now also enforces field `requiredWhen`/ `conditionalRequired` (CEL over the merged record) → a 'required' error when the predicate is TRUE and the value is missing. Can't be bypassed by a direct API write. - stripReadonlyWhenFields drops update-payload fields whose `readonlyWhen` is TRUE for the record's state (keeps the persisted value); wired into engine.update. - needsPriorRecord accounts for conditional fields so the prior record is fetched on update (predicates over unchanged fields evaluate correctly). 46 rule-validator tests pass (requiredWhen, alias, readonly-strip, prior-fetch). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
B2 — field-level conditional visibility / read-only / validation. Before: spec had only
conditionalRequired(CEL) and it wasn't enforced; no conditional visibility/read-only. Goal: a CEL-unified trio evaluated on both sides (client UX in a follow-up; server enforcement here so rules can't be bypassed).What
Spec (
@objectstack/spec) — three CEL-predicate field props overrecord:visibleWhen— shown only when TRUE.readonlyWhen— read-only when TRUE (e.g.record.status == 'paid').requiredWhen— required when TRUE (canonical;conditionalRequiredkept as alias).Server (
@objectstack/objectql) — enforcement so the rules aren't decoration:evaluateValidationRulesnow also enforces fieldrequiredWhen/conditionalRequiredover the merged record → arequirederror when the predicate is TRUE and the value is missing.stripReadonlyWhenFieldsdrops update-payload fields whosereadonlyWhenis TRUE for the record's state (keeps the persisted value); wired intoengine.update.needsPriorRecordaccounts for conditional fields so the prior record is fetched on update (predicates over unchanged fields evaluate correctly). Broken predicates fail-open (logged, skipped).Verification
field.test.ts115 pass (props normalize to the CEL envelope).rule-validator.test.ts46 pass (requiredWhen insert/update-merged,conditionalRequiredalias, readonly-strip true/false/no-op, needsPriorRecord).Next: PR objectui client CEL evaluator → ObjectForm dynamic visible/readonly/required (same engine = client/server parity); then showcase + live e2e + docs.
🤖 Generated with Claude Code