Repository navigation
feat!: consolidate form constraint validation on shared rx ASTs - #132
Merged
Merged
Conversation
#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.
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.
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/3is THE source: per-field fire-ASTs ({fires-when, message}), withvalid_ast/1derived from the same checks — so_valid == (errors == [])by construction. The server compiles the ASTs viaLavash.Rx.Cache(Lavash.Rx.transform_at_refs/1now public); the client transpiles the identical ASTs.form_checks/4unifies field selection +skip_constraintsfor both consumers.Net: ValidationJs 357 → 122 lines; ~150 lines of closure checkers deleted from ExpandFields; new
Lavash.Form.Validation.parse_int/1with a matching JS transpiler mapping.Unified semantics (the
!— breaking where the sides disagreed, always toward the most-correct side)match:constraints actually test the value (client_validwas inverted — bug: client _valid stuck false for any match: constraint (inverted regex call) #124's bug family)parseInt-ed"18abc"→ 18)_errorsmatched untrimmed,_validtrimmed)_valid/_errorsfor timestamps/FKs — visible in every form's client state)skip_constraintsapplies on both sides (was client-only)extend_errorscustoms 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