Skip to content

feat!: consolidate form constraint validation on shared rx ASTs - #132

Merged
pinetops merged 1 commit into
mainfrom
feat/validation-on-rx-path
Aug 21, 2026
Merged

pinetops merged 1 commit into
mainfrom
feat/validation-on-rx-path

Conversation

@pinetops

Copy link
Copy Markdown
Member

Closes #125 — the big consolidation from the duplication audit.

Three implementations → one source

Form constraint validation existed three times: hand-written JS strings (ValidationJs), hand-written Elixir closures (ExpandFields), and a dead rx-AST generator (ConstraintTranspiler.build_valid_expression — built for exactly this, never wired). The audit found six drifts between them.

Now ConstraintTranspiler.field_checks/3 is THE source: per-field fire-ASTs ({fires-when, message}), with valid_ast/1 derived from the same checks — so _valid == (errors == []) by construction. The server compiles the ASTs via Lavash.Rx.Cache (Lavash.Rx.transform_at_refs/1 now public); the client transpiles the identical ASTs. form_checks/4 unifies field selection + skip_constraints for both consumers.

Net: ValidationJs 357 → 122 lines; ~150 lines of closure checkers deleted from ExpandFields; new Lavash.Form.Validation.parse_int/1 with a matching JS transpiler mapping.

Unified semantics (the ! — breaking where the sides disagreed, always toward the most-correct side)

  1. match: constraints actually test the value (client _valid was inverted — bug: client _valid stuck false for any match: constraint (inverted regex call) #124's bug family)
  2. Integer parsing is strict full-string on both sides (client parseInt-ed "18abc" → 18)
  3. String matches run on the TRIMMED value everywhere (server _errors matched untrimmed, _valid trimmed)
  4. Only action-ACCEPTED fields get derives (server generated junk _valid/_errors for timestamps/FKs — visible in every form's client state)
  5. skip_constraints applies on both sides (was client-only)
  6. Empty required fields show only "is required" (client piled constraint messages on top); extend_errors customs no longer empty-gated client-side (server parity — visibility belongs to the touched tracker)

Guard

The #124 agreement suite is now three-way: server-compiled AST vs Deno-executed transpiled JS vs expected truth, with cases pinning every drift point above.

924 root tests (incl. browser e2e through the demo forms) + 83 demo tests green; full hook chain passed.

🤖 Generated with Claude Code

#125)

Form constraint validation was implemented three times — hand-written
JS strings (ValidationJs), hand-written Elixir closures
(ExpandFields), and a dead rx-AST generator (ConstraintTranspiler)
built for exactly this and never wired. The audit found them drifted
in six ways; this makes drift structurally impossible.

ConstraintTranspiler.field_checks/3 is now THE source: per-field
fire-ASTs ({fires-when, message}) plus valid_ast/1 derived from the
same checks, so _valid == (errors == []) by construction. The server
compiles the ASTs via Lavash.Rx.Cache (Lavash.Rx.transform_at_refs/1
is now public for @-form ASTs built outside the rx macro); the
client transpiles the SAME ASTs via the Transpiler. form_checks/4
unifies field selection and skip handling for both consumers.
ValidationJs shrinks 357 -> 122 lines; ~150 lines of closure
checkers leave ExpandFields.

Unified semantics (BREAKING where the sides used to disagree —
in each case toward the server/most-correct behavior):

- match: constraints test the value (the client _valid had the regex
  call inverted — permanently false; fixed ahead in #124)
- integer parsing is strict full-string on both sides via the new
  Lavash.Form.Validation.parse_int/1 + its JS mapping (client used
  to parseInt "18abc" -> 18; server required a full parse)
- string matches run on the TRIMMED value everywhere (server _errors
  used to match untrimmed while _valid matched trimmed)
- only fields ACCEPTED by the create action get derives (the server
  used to generate junk _valid/_errors for timestamps/foreign keys)
- skip_constraints applies on BOTH sides (was client-only)
- empty required fields show ONLY "is required" (the client used to
  pile constraint messages on top); extend_errors customs are no
  longer empty-gated on the client (server parity — visibility is
  the touched-tracker's job)

The agreement suite is now three-way: server-compiled AST vs
Deno-executed transpiled JS vs expected truth, pinning every unified
drift point.
@pinetops
pinetops merged commit 333bafb into main Aug 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

consolidate: form validation is implemented three times; wire the rx path

1 participant