Repository navigation
feat: zodResolver carries arrays, coerced numbers and password rules - #17
Closed
mertcanaltin wants to merge 2 commits into
Closed
mertcanaltin wants to merge 2 commits into
mertcanaltin wants to merge 2 commits into
Conversation
… checks on one field
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.
Stacked on #16; the diff here is the one commit on top of it.
Three more things forms are written with, each found by running the scan of #16 over the corpus of 150 public files and reading its reasons.
Arrays.
z.array(...)of anything carried, withmin,max,lengthandnonempty. What had to be matched, each found by the differential and now held by it:capSizein zod's source), so their issues are dropped;In the tables an item is a
*segment, and an instance path is mapped to its pattern on the way down.z.coerce.number(). zod takesNumber(value)of whatever came before it checks, so""is 0 and"abc"is NaN. The same is done to a copy of the document before the compiled check runs (the mechanismtrimuses), an optional one left alone when it is not there. Coercion to a string or a boolean is refused: a missing key becomes"undefined"orfalsethere, which a JSON Schema has no way to say.Several
regexchecks on one field, the usual way to write a password rule. The plan could not tell them apart when it asked zod about each; it now matches the issue by its pattern.Also: the refusals that read like internals now say what the developer wrote (
a field that takes a missing value without being optional,the build has no sample value that passes this field's rules), and the build-time check has more sample values (a name starting with@, a password, digits).Reach on the corpus (156 calls, each file alone in a directory): 52 replaced before this, 56 after. Of the 100 left: 64 import the schema from a module the one-file setup does not have, 12 declare it inside the component, 10 have a function in it (a refine, mostly), 4 use
url, and 10 others.Size: the run-time code that maps paths and orders issues is written into every file with a replaced call, with or without an array in it. The five-field form of #12 is 15,312 B under Turbopack and 15,837 B under webpack, 189 and 195 B more than before this. One code path was kept on purpose: it is the one the build-time check and the differential run, and a second one for forms without arrays would be held by neither.
Tests: arrays, coerced numbers and password rules in the generated forms; a fixed case for coerced numbers; a build with arrays of strings and of objects; seven ways of breaking the new run-time code, each caught.
npm test: 264 tests, 262 pass, 2 skipped.Not covered: an array of optional items, two length checks of one kind on an array, a tuple, a set.