Open MentalGear opened 3 months ago
Built without sensitive environment variables
Name | Link |
---|---|
Latest commit | 60f0a9e93e0c436fdfa573b755529566f5105f55 |
Latest deploy log | https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/66a5126f84399b0008568006 |
Deploy Preview | https://deploy-preview-3677--guileless-rolypoly-866f8a.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
Hey @colinhacks: it would be great if you could take a look at the PR/RFC (and th x for your time and work on zod).
.upgrade()
Necessity
Zod currently has no method to allow "append-only" additions of constraints to a
z.object
.Use Case
One major case is "upgrading" (ie adding constraints on) pre-existing schemas that can't be manually edited.
Example: a Zod Schema is generated automatically each time a database schema changes. Obviously one can't change the generated file without having all edits overwritten on re-generation.
Alternatives considered
Using .shape && .extend is verbose and open for unintended changes.
.shape is illegibly verbose as it needs to be accesed via repeated object-dot-notion-access-chaining reference calls to the original object each time. This compounds linearly to how deep the object is.
.extend: overwrites the fields instead of appending on it. Extend could potentially add new objects or even overwrite existing ones complettely.
.shape
&.extend
version.upgrade
versionAdvantages
Intuitive Interface
.upgrade
is shorter, idomatic and safe in scope.Type-Safety
Append-only
.upgrade
prevents the unintended addition of fields. Example:Protection
Field Protection
.upgrade prevents the unintended overwriting of fields.
Constraint Protection
Trying to overwrite constraints will not work.
Naming
augment
was alreaady being used by the API (deprecated)update
makes it seems like you can change any prop of the original fieldupgrade
indicates that you can only go "upwards" from the original definitionTests
An extensive test suite has been added. Please let me know whether you consider it a wide enough coverage.
Open issues
There seems to be still some issues with the types that I hope some Zod maintainer could help me with!