8000 [Zod 4] RFC: `ZodIssue` formats by colinhacks · Pull Request #3713 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Zod 4] RFC: ZodIssue formats #3713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 73 commits into
base: main
Choose a base branch
from
Draft

[Zod 4] RFC: ZodIssue formats #3713

wants to merge 73 commits into from

Conversation

colinhacks
Copy link
Owner
@colinhacks colinhacks commented Aug 16, 2024

Old formats:
https://github.com/colinhacks/zod/blob/v4-rfc-issues/rfcs/v4-issue-formats/old_formats.ts

export type ZodIssue =
  | ZodInvalidTypeIssue
  | ZodInvalidLiteralIssue
  | ZodUnrecognizedKeysIssue
  | ZodInvalidUnionIssue
  | ZodInvalidUnionDiscriminatorIssue
  | ZodInvalidEnumValueIssue
  | ZodInvalidArgumentsIssue
  | ZodInvalidReturnTypeIssue
  | ZodInvalidDateIssue
  | ZodInvalidStringIssue
  | ZodTooSmallIssue
  | ZodTooBigIssue
  | ZodInvalidIntersectionTypesIssue
  | ZodNotMultipleOfIssue
  | ZodNotFiniteIssue
  | ZodCustomIssue;

New formats: https://github.com/colinhacks/zod/blob/v4-rfc-issues/rfcs/v4-issue-formats/new_formats.ts

export type ZodIssue =
  | ZodInvalidTypeIssue
  | ZodInvalidStringIssue
  | ZodInvalidNumberIssue
  | ZodInvalidBigIntIssue
  | ZodInvalidDateIssue
  | ZodInvalidArrayIssue
  | ZodInvalidSetIssue
  | ZodInvalidObjectIssue
  | ZodInvalidFileIssue
  | ZodCustomIssue;

Conceptually speaking these are the major changes:

  1. ZodIssue is a 2-level discriminated union. The first level discriminates on code: invalid_type, invalid_stringm etc. For each code, there are sub-issues that are discriminated with the check field.
  2. Merges invalid_union, invalid_literal, invalid_enum_value into invalid_type
  3. Splits up too_big and too_small across the specific types for which they are defined: invalid_string, invalid_array, etc.
  4. Within each of the type-specific error code (e.g. invalid_string) there is an additional layer of discrimination using the check key. Instead of a top-level ZodNotMultipleOfIssue, this is now a check: "multiple_of" within code: "invalid_string".
  5. Drops invalid_arguments, invalid_return_type, invalid_discriminator_value as these issues are specific to types that will be removed in Zod 4.

morgs32 and others added 30 commits May 2, 2024 17:57
* feat: supports optional tuple elements

* fix: adds type assertions for optional elements in tuple

* fix: minItems equals num elements before only optionals

* fix: adds findMinItems() for tuple.minItems

* Build deno

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* feat: implement primitive array uniqueness

* chore: update yarn.lock

* feat: implement array of complex objects uniqueness

* chore: rollback yarn.lock

* refactor: minor update _arrayUnique

* chore: minor change yarn.lock

* feat: implement custom message support

* feat: add showDuplicates param

* chore: TS types update

* chore: TS types II

* refactor: ArrayMessageFunction

* refactor: simplify array uniqueness implementation

* docs: add documentation for array uniqueness

* Regen lock

* Fix readme

---------

Co-authored-by: Frederic Woelffel <hello@fwoelffel.me>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* feat(string): add jwt validator type

Validate string in JWT format. NOT validate signature

* test(string): add tests to validate jwt parse

Validate all possibilities for validation function

* docs(main): update main README

Add z.string().jwt() to String validations list

* fix(types): remove forgotten console.log

* refactor(types-string): replace Buffer.from method for atob into JWT validation

atob method is compatible with Node and modern browsers

* fix(types-string): header property was misspelled

Property is 'typ' and not 'type'

* feat(types-string): add algorithm option to jwt

Can pass a algorithm option to jwt method to check the algorithm of token. If not pass, no check is done for alg.

* test(string): update tests to check jwt method

Fix tests with false positive and add tests to check algorithm validation

* docs(README): update readme.md

Add info that jwt method accepts algorithm as option

* Tweak API and docs

* Fix tests

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* Add test for stricter UUID

* Add test for stricter UUID (mirror in Deno tests)

* Add test for separate guid string validator

* Update UUID to follow RFC4122 strictly

* Add guid string validator

* Change test.each to array.forEach for automatic deno build

* Add isGUID method

* Add other uuid regexes

* Update tests

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* fix: tree shake named exports

* docs: explain why wrapper functions

* fix: make coerce tree shakeable

* fix: make util tree shakeable

* Fix merge conflicts

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* feat: Allow passing custom message to literal
Fixes #2974

Uses a message key instead of "invalid_xx" key - because those are only used for required and invalid type
using a message key is more in line with other checks

* Remove lib

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* Add z.string().json(...) helper

* use parseAsync + await expect(...).rejects

* make it work in deno

* Add overload

---------

Co-authored-by: Misha Kaletsky <mmkal@users.noreply.github.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* Add `@web-std/file` dev dependency

* Add ZodFile

* Use fallback interfaces

* Fix test

* Fix tests

* .accept() -> .type()

* .filename -> .name

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* feat: add support for KSUIDs

* chore: remove yarn lock from pr

* chore: add yarn lock from current master
* Allow undefined values in record, similar to object.

* Clean unnecessary logic

* Update `mergeObjectAsync` to support `alwaysSet` like `mergeObjectSync`

* Use existing type

* Update tests

* Clean up

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* Update README_ZH.md (#3433)

fix Demo -> Deno

* Clean up code, fix build/test

* Write docs

* Fix rollup build

* Fix setup-deno

* Add types field

* Fix types

* Use globalThis check

* Add _tag to ZodError

* Comments

* Add better tests

* suggestions for effect plugin (#3449)

* Updates

* Move to .effect.parse()

* Bind this in getter

* Clean up

---------

Co-authored-by: sdshaoda <21106848+sdshaoda@users.noreply.github.com>
Co-authored-by: Tim <hello@timsmart.co>
)

* Fix inferFlattenedErrors type

* Update yarn.lock

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* v3.23.6

* Add copper

* Create fa.ts

* Update ERROR_HANDLING.md

* Rebase

* Update readme

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* `ZodTemplateLiteral` initial commit.

* `ZodTemplateLiteral` regex building & parsing.

* add `ZodTemplateLiteral` @ firstparty.test.

* some inference test cases for `ZodTemplateLiteral`.

* append to regexString instead of rebuild @ `ZodTemplateLiteral.addPart`.

* initial parse tests for `ZodTemplateLiteral`.

* "internalize" `addPart`, add `addLiteral` & `addInterpolatedPosition`.

* move `ZodTemplateLiteral` unit test cases and minor fixes.

* minor fixes, more tests.

* minor fixes, more tests pt. 2.

* more tests pt. 3.

* more tests pt. 4.

* add `ZodTemplateLiteral` README.md section.

* add a simpler example @ ZodTemplateLiteral docs.

* add regex limitations remark.

* allow coercion to ZodTemplateLiteral.

* minor readability pass on number stuff @ ZodTemplateLiteral.

* add ZodBranded support @ ZodTemplateLiteral.

* support ZodAny @ ZodTemplateLiteral.

* support ZodAny @ ZodTemplateLiteral.

* minor README.md changes.

* add ZodTemplateLiteral coerce test.

* add ZodTemplateLiteral custom errors for unsupported stuff.

* add ZodTemplateLiteral custom errors for unsupported stuff. pt. 2.

* add ZodTemplateLiteral custom errors for unsupported stuff pt. 3.

Co-authored-by: Max Arturo <5713763+maxArturo@users.noreply.github.com>

* use official MDN way of escaping for regex.

Co-authored-by: Max Arturo <5713763+maxArturo@users.noreply.github.com>

* explicitly state exponent notation is not supported @ ZodTemplateLiteral

Co-authored-by: Max Arturo <5713763+maxArturo@users.noreply.github.com>

* add missing `.toThrow()` @ ZodTemplateLiteral tests.

Co-authored-by: Max Arturo <5713763+maxArturo@users.noreply.github.com>

* explicitly state `.trim()` is not supported @ ZodTemplateLiteral.

Co-authored-by: Max Arturo <5713763+maxArturo@users.noreply.github.com>

* fix mongodb connection string example and tests.

* add measurment example from README to ZodTemplateLiteral tests.

* extract ZodTemplateLiteral errors to ZodError.ts

Co-authored-by: Max Arturo <5713763+maxArturo@users.noreply.github.com>

* add `z.string().cuid2()` support.

* add support for new regex based string checks.

* rename to `.interpolated` & `.literal`.

* rename to `.interpolated` & `.literal` pt. 2.

* handle case insensitive regexes.

* prettier the readme.

* Update cuid2 test

* Switch to z.literal.template, update tests, update eslint, bump TS to 5.0+

* Empty

* Update readme

* Update readme

* Clean up types

---------

Co-authored-by: Max Arturo <5713763+maxArturo@users.noreply.github.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
…3487)

* wip

* INVALID -> ZodFailure, fix input issue

* Add new benchmarks

* Switch away from Ok<T> wrapper

* ZodString optimizations

* playground.mts

* Remove ZodString opt, update benchmarks

* Detect promises in parsing instead of using ctx.async

* Fix tests

* Switch benchmarks to tinybench

* Update benchmarks

* Updates

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* Added e164 validation

* cleanup and missing files

* added documentation

* Build deno

* Fix tests

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
colinhacks and others added 12 commits July 3, 2024 17:19
* separate typecheck from runtime testing

* Fix tests

* Fix typechecking

* Remove failures

* Test on latest and next TS only

---------

Co-authored-by: Misha Kaletsky <mmkal@users.noreply.github.com>
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* 3.23.5

* Experiments

* WIP

* WIP

* Ignore tshy

* Fix type errors

* Fix tsconfigs
* Switch to tshy

* Switch to tshy

* Switch to tshy

* Fix vitest issue

* Remove tsc-perf

* Format packagejsons

* Tweak

* Format package jsons

* Update biome settings

* Remove source dialects
* Update benchmarks to ESM

* Undo packagejson changes
* WIP

* Add condition

* Fix formatting

* Format

* Build
@colinhacks colinhacks marked this pull request as draft August 16, 2024 22:16
@colinhacks colinhacks changed the title V4 rfc issues [Zod 4] RFC: ZodIssue format Aug 16, 2024
Copy link
netlify bot commented Aug 16, 2024

Deploy Preview for guileless-rolypoly-866f8a ready!

Name Link
🔨 Latest commit 8bf2cc1
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/66bfcffdecd444000843d905
😎 Deploy Preview https://deploy-preview-3713--guileless-rolypoly-866f8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@colinhacks colinhacks changed the title [Zod 4] RFC: ZodIssue format [Zod 4] RFC: ZodIssue formats Aug 16, 2024
@colinhacks colinhacks changed the base branch from main to v4 August 16, 2024 22:17
@colinhacks colinhacks marked this pull request as ready for review August 19, 2024 08:26
@colinhacks colinhacks marked this pull request as draft September 3, 2024 22:50
Base automatically changed from v4 to main May 19, 2025 13:07
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.

0