Skip to content

feat: field conditional rules (CEL) — spec + server enforcement (B2)#1649

Merged
xuyushun441-sys merged 2 commits into
mainfrom
feat/b2-conditional-field-spec
Jun 7, 2026
Merged

feat: field conditional rules (CEL) — spec + server enforcement (B2)#1649
xuyushun441-sys merged 2 commits into
mainfrom
feat/b2-conditional-field-spec

Conversation

@xuyushun441-sys
Copy link
Copy Markdown
Contributor

@xuyushun441-sys xuyushun441-sys commented Jun 7, 2026

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 over record:

  • visibleWhen — shown only when TRUE.
  • readonlyWhen — read-only when TRUE (e.g. record.status == 'paid').
  • requiredWhen — required when TRUE (canonical; conditionalRequired kept as alias).

Server (@objectstack/objectql) — enforcement so the rules aren't decoration:

  • evaluateValidationRules now also enforces field requiredWhen/conditionalRequired over the merged record → a required error when the predicate is TRUE and the value is missing.
  • 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). Broken predicates fail-open (logged, skipped).

Verification

  • field.test.ts 115 pass (props normalize to the CEL envelope).
  • rule-validator.test.ts 46 pass (requiredWhen insert/update-merged, conditionalRequired alias, readonly-strip true/false/no-op, needsPriorRecord).
  • spec + objectql build clean.

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

…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>
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Ready Ready Preview, Comment Jun 7, 2026 11:55am

Request Review

…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>
@xuyushun441-sys xuyushun441-sys changed the title feat(spec): field conditional rules — visibleWhen / readonlyWhen / requiredWhen (CEL) feat: field conditional rules (CEL) — spec + server enforcement (B2) Jun 7, 2026
@github-actions github-actions Bot added size/m and removed size/s labels Jun 7, 2026
@xuyushun441-sys xuyushun441-sys merged commit 99111ec into main Jun 7, 2026
12 checks passed
@xuyushun441-sys xuyushun441-sys deleted the feat/b2-conditional-field-spec branch June 7, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation protocol:data size/m tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants