Update dependency zod to v4.1.11 #326

Open
bustikiller wants to merge 1 commits from renovate/zod-4.x-lockfile into main
Owner

This PR contains the following updates:

Package Type Update Change
zod (source) dependencies minor 4.0.10 -> 4.1.11

Release Notes

colinhacks/zod (zod)

v4.1.11

Compare Source

Commits:

v4.1.10

Compare Source

Commits:

v4.1.9

Compare Source

Commits:

v4.1.8

Compare Source

Commits:

v4.1.7

Compare Source

Commits:

v4.1.6

Compare Source

v4.1.5

Compare Source

Commits:

v4.1.4

Compare Source

Commits:

  • 3291c61 fix(v4): toJSONSchema - wrong tuple with null output when targeting openapi-3.0 (#​5156)
  • 23f41c7 test(v4): toJSONSchema - use validateOpenAPI30Schema in all relevant scenarios (#​5163)
  • 0a09fd2 Update installation instructions
  • 4ea5fec 4.1.4

v4.1.3

Compare Source

Commits:

  • 98ff675 Drop stringToBoolean
  • a410616 Fix typo
  • 0cf4589 fix(v4): toJSONSchema - add missing oneOf inside items in tuple conversion (#​5146)
  • 8bf0c16 fix(v4): toJSONSchema tuple path handling for draft-7 with metadata IDs (#​5152)
  • 5c5fa90 fix(v4): toJSONSchema - wrong record output when targeting openapi-3.0 (#​5141)
  • 87b97cc docs(codecs): update example to use payloadSchema (#​5150)
  • 309f358 fix(v4): toJSONSchema - output numbers with exclusive range correctly when targeting openapi-3.0 (#​5139)
  • 1e71ca9 docs: fix refine fn to encode works properly (#​5148)
  • a85ec3c fix(docs): correct example to use LooseDog instead of Dog (#​5136)
  • 3e98274 4.1.3

v4.1.2

Compare Source

Commits:

v4.1.1

Compare Source

Commits:

v4.1.0

Compare Source

The first minor version since the introduction of Zod 4 back in May. This version contains a number of features that barely missed the cut for the 4.0 release. With Zod 4 stable and widely adopted, there's more time to resume feature development.

Codecs

This is the flagship feature of this release. Codecs are a new API & schema type that encapsulates a bi-directional transformation. It's a huge missing piece in Zod that's finally filled, and it unlocks some totally new ways to use Zod.

const stringToDate = z.codec(
  z.iso.datetime(),  // input schema: ISO date string
  z.date(),          // output schema: Date object
  {
    decode: (isoString) => new Date(isoString), 
    encode: (date) => date.toISOString(),
  }
);

New top-level functions are added for processing inputs in the forward direction ("decoding") and backward direction ("encoding").

stringToDate.decode("2025-08-21T20:59:45.500Z")
// => Date

stringToDate.encode(new Date())
// => "2025-08-21T20:59:45.500Z"

Note

 — For bundle size reasons, these new methods have not added to Zod Mini schemas. Instead, this functionality is available via equivalent top-level functions.

// equivalent at runtime
z.decode(stringToDate, "2024-01-15T10:30:00.000Z");
z.encode(stringToDate, new Date());
.parse() vs .decode()

Both .parse() and decode() process data in the "forward" direction. They behave identically at runtime.

stringToDate.parse("2025-08-21T20:59:45.500Z");
stringToDate.decode("2025-08-21T20:59:45.500Z");

There is an important difference however. While .parse() accepts any input, .decode() expects a strongly typed input. That is, it expects an input of type string, whereas .parse() accepts unknown.

stringToDate.parse(Symbol('not-a-string'));
// => fails at runtime, but no TypeScript error

stringToDate.decode(Symbol("not-a-string"));
//                     ^ ❌ Argument of type 'symbol' is not assignable to parameter of type 'Date'. ts(2345)

This is a highly requested feature unto itself:

Encoding

You can use any Zod schema with .encode(). The vast majority of Zod schemas are non-transforming (the input and output types are identical) so .decode() and .encode() behave identically. Only certain schema types change their behavior:

  • Codecs — runs from B->A and executes the encode transform during encoding
  • Pipes — these execute B->A instead of A->B
  • Defaults and prefaults — Only applied in the forward direction
  • Catch — Only applied in the forward direction

Note

— To avoid increasing bundle size unnecessarily, these new methods are not available on Zod Mini schemas. For those schemas, equivalent top-level functions are provided.

The usual async and safe variants exist as well:

// decode methods
stringToDate.decode("2024-01-15T10:30:00.000Z")
await stringToDate.decodeAsync("2024-01-15T10:30:00.000Z")
stringToDate.safeDecode("2024-01-15T10:30:00.000Z")
await stringToDate.safeDecodeAsync("2024-01-15T10:30:00.000Z")

// encode methods
stringToDate.encode(new Date())
await stringToDate.encodeAsync(new Date())
stringToDate.safeEncode(new Date())
await stringToDate.safeEncodeAsync(new Date())
Example codecs

Below are some "worked examples" for some commonly-needed codecs. These examples are all tested internally for correctness. Just copy/paste them into your project as needed. There is a more comprehensive set available at zod.dev/codecs.

stringToBigInt

Converts bigint into a serializable form.

const stringToBigInt = z.codec(z.string(), z.bigint(), {
  decode: (str) => BigInt(str),
  encode: (bigint) => bigint.toString(),
});

stringToBigInt.decode("12345");  // => 12345n
stringToBigInt.encode(12345n);   // => "12345"
json

Parses/stringifies JSON data.

const jsonCodec = z.codec(z.string(), z.json(), {
  decode: (jsonString, ctx) => {
    try {
      return JSON.parse(jsonString);
    } catch (err: any) {
      ctx.issues.push({
        code: "invalid_format",
        format: "json_string",
        input: jsonString,
        message: err.message,
      });
      return z.NEVER;
    }
  },
  encode: (value) => JSON.stringify(value),
});

To further validate the data, .pipe() the result of this codec into another schema.

const Params = z.object({ name: z.string(), age: z.number() });
const JsonToParams = jsonCodec.pipe(Params);

JsonToParams.decode('{"name":"Alice","age":30}');  // => { name: "Alice", age: 30 }
JsonToParams.encode({ name: "Bob", age: 25 });     // => '{"name":"Bob","age":25}'
Further reading

For more examples and a technical breakdown of how encoding works, reads theannouncement blog post and new Codecs docs page. The docs page contains implementations for several other commonly-needed codecs:

.safeExtend()

The existing way to add additional fields to an object is to use .extend().

const A = z.object({ a: z.string() })
const B = A.extend({ b: z.string() })

Unfortunately this is a bit of a misnomer, as it allows you to overwrite existing fields. This means the result of .extend() may not literally extend the original type (in the TypeScript sense).

const A = z.object({ a: z.string() }) // { a: string }
const B = A.extend({ a: z.number() }) // { a: number }

To enforce true extends logic, Zod 4.1 introduces a new .safeExtend() method. This statically enforces that the newly added properties conform to the existing ones.

z.object({ a: z.string() }).safeExtend({ a: z.number().min(5) }); // ✅
z.object({ a: z.string() }).safeExtend({ a: z.any() }); // ✅
z.object({ a: z.string() }).safeExtend({ a: z.number() });
//                                       ^  ❌ ZodNumber is not assignable 

Importantly, this new API allows you to safely extend objects containing refinements.

const AB = z.object({ a: z.string(), b: z.string() }).refine(val => val.a === val.b);
const ABC = AB.safeExtend({ c: z.string() });
// ABC includes the refinements defined on AB

Previously (in Zod 4.x) any refinements attached to the base schema were dropped in the extended result. This was too unexpected. It now throws an error. (Zod 3 did not support extension of refined objects either.)

z.hash()

A new top-level string format for validating hashes produced using various common algorithms & encodings.

const md5Schema = z.hash("md5");          
// => ZodCustomStringFormat<"md5_hex">

const sha256Base64 = z.hash("sha256", { enc: "base64" }); 
// => ZodCustomStringFormat<"sha256_base64">

The following hash algorithms and encodings are supported. Each cell provides information about the expected number of characters/padding.

Algorithm / Encoding "hex" "base64" "base64url"
"md5" 32 24 (22 + "==") 22
"sha1" 40 28 (27 + "=") 27
"sha256" 64 44 (43 + "=") 43
"sha384" 96 64 (no padding) 64
"sha512" 128 88 (86 + "==") 86

z.hex()

To validate hexadecimal strings of any length.

const hexSchema = z.hex();

hexSchema.parse("123abc");    // ✅ "123abc"
hexSchema.parse("DEADBEEF");  // ✅ "DEADBEEF" 
hexSchema.parse("xyz");       // ❌ ZodError

Additional changes

  1. z.uuid() now supports the "Max UUID" (FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF) per the RFC
  2. $ZodFunction is now a subtype of $ZodType

Commits

v4.0.17

Compare Source

Commits:

v4.0.16

Compare Source

Commits:

v4.0.15

Compare Source

Commits:

v4.0.14

Compare Source

Commits:

v4.0.13

Compare Source

Commits:

v4.0.12

Compare Source

Commits:

v4.0.11

Compare Source

Commits:


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Renovate Bot.

This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [zod](https://zod.dev) ([source](https://github.com/colinhacks/zod)) | dependencies | minor | [`4.0.10` -> `4.1.11`](https://renovatebot.com/diffs/npm/zod/4.0.10/4.1.11) | --- ### Release Notes <details> <summary>colinhacks/zod (zod)</summary> ### [`v4.1.11`](https://github.com/colinhacks/zod/releases/tag/v4.1.11) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.10...v4.1.11) #### Commits: - [`2bed4b3`](https://github.com/colinhacks/zod/commit/2bed4b39760d8e4d678203b5c8fcaf24c182fc9f) 4.1.11 ### [`v4.1.10`](https://github.com/colinhacks/zod/releases/tag/v4.1.10) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.9...v4.1.10) #### Commits: - [`7ffedd0`](https://github.com/colinhacks/zod/commit/7ffedd00169d8dc2e7cb7c6d878f29b03e05b3a3) Fix shape caching ([#&#8203;5263](https://github.com/colinhacks/zod/issues/5263)) - [`82cd717`](https://github.com/colinhacks/zod/commit/82cd717a0e7ee4e1737a783c7be278fa93fd8104) v4.1.10 ### [`v4.1.9`](https://github.com/colinhacks/zod/releases/tag/v4.1.9) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.8...v4.1.9) #### Commits: - [`a78716d`](https://github.com/colinhacks/zod/commit/a78716d91da7649a61016b81c27f49fd9e79a81e) Update zshy ([#&#8203;5249](https://github.com/colinhacks/zod/issues/5249)) - [`923af80`](https://github.com/colinhacks/zod/commit/923af801fde9f033cfd7e0e753b421a554fe3be8) Publish zod\@&#8203;4.1.9 ### [`v4.1.8`](https://github.com/colinhacks/zod/releases/tag/v4.1.8) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.7...v4.1.8) #### Commits: - [`36c4ee3`](https://github.com/colinhacks/zod/commit/36c4ee354d0c1f47b7311e49f6dd4b7a11de04f5) Switch back to weakmap - [`a1726d5`](https://github.com/colinhacks/zod/commit/a1726d53172ba52ecf90999df73778cf416264fd) 4.1.8 ### [`v4.1.7`](https://github.com/colinhacks/zod/releases/tag/v4.1.7) [Compare Source](https://github.com/colinhacks/zod/compare/976b43657d4aff6d47c73c1c86125623ea08752d...v4.1.7) #### Commits: - [`0cca351`](https://github.com/colinhacks/zod/commit/0cca351c8b152d7c4113ab7c2a44675efb060677) Fix variable name inconsistency in coercion documentation ([#&#8203;5188](https://github.com/colinhacks/zod/issues/5188)) - [`aa78c27`](https://github.com/colinhacks/zod/commit/aa78c270f1b43f4665339f4b61e7cb88037b8c84) Add copy/edit buttons - [`76452d4`](https://github.com/colinhacks/zod/commit/76452d4119d800a722b692755c1168627bc95f0f) Update button txt - [`937f73c`](https://github.com/colinhacks/zod/commit/937f73c90cac90bd3b99b12c792c289b50416510) Fix tsconfig issue in bench - [`976b436`](https://github.com/colinhacks/zod/commit/976b43657d4aff6d47c73c1c86125623ea08752d) v4.1.6 ([#&#8203;5222](https://github.com/colinhacks/zod/issues/5222)) - [`4309c61`](https://github.com/colinhacks/zod/commit/4309c61304daf40aab2124b5f513abe2b4df8637) Fix cidrv6 validation - cidrv6 should reject invalid strings with multiple slashes ([#&#8203;5196](https://github.com/colinhacks/zod/issues/5196)) - [`ef95a73`](https://github.com/colinhacks/zod/commit/ef95a73b6d33299743e5ff4f0645b98c1b0d6f72) feat(locales): Add Lithuanian (lt) locale ([#&#8203;5210](https://github.com/colinhacks/zod/issues/5210)) - [`3803f3f`](https://github.com/colinhacks/zod/commit/3803f3f37168212f2178e8b8deceb7bad78ed904) docs: update wrong contents in codeblocks in `api.mdx` ([#&#8203;5209](https://github.com/colinhacks/zod/issues/5209)) - [`8a47d5c`](https://github.com/colinhacks/zod/commit/8a47d5c6ba8e4fe2f934a8e55d0cba4d81d821de) docs: update coerce example in `api.mdx` ([#&#8203;5207](https://github.com/colinhacks/zod/issues/5207)) - [`e87db13`](https://github.com/colinhacks/zod/commit/e87db1322f11ff6907e1789da28933d258ab75fd) feat(locales): Add Georgian (ka) locale ([#&#8203;5203](https://github.com/colinhacks/zod/issues/5203)) - [`c54b123`](https://github.com/colinhacks/zod/commit/c54b123e399a6ab266504eb1389c724af31d5998) docs: adds `@traversable/zod` and `@traversable/zod-test` to v4 ecosystem ([#&#8203;5194](https://github.com/colinhacks/zod/issues/5194)) - [`c27a294`](https://github.com/colinhacks/zod/commit/c27a294f5b792f47b8e9dbb293a8ff8cfb287a3a) Fix two tiny grammatical errors in the docs. ([#&#8203;5193](https://github.com/colinhacks/zod/issues/5193)) - [`23a2d66`](https://github.com/colinhacks/zod/commit/23a2d6692398e3dd1ad1cdb0491b271a9f989380) docs: fix broken links in async refinements and transforms references ([#&#8203;5190](https://github.com/colinhacks/zod/issues/5190)) - [`845a230`](https://github.com/colinhacks/zod/commit/845a230bb06bff679b5f00e10153f4dbbd50d2b6) fix(locales): Add type name translations to Spanish locale ([#&#8203;5187](https://github.com/colinhacks/zod/issues/5187)) - [`27f13d6`](https://github.com/colinhacks/zod/commit/27f13d62b98cf5c501b828ba8837ff73cd6263d2) Improve regex precision and eliminate duplicates in regexes.ts ([#&#8203;5181](https://github.com/colinhacks/zod/issues/5181)) - [`a8a52b3`](https://github.com/colinhacks/zod/commit/a8a52b3ba370b761be76953fa3986aa43c4172a4) fix(v4): fix Khmer and Ukrainian locales ([#&#8203;5177](https://github.com/colinhacks/zod/issues/5177)) - [`887e37c`](https://github.com/colinhacks/zod/commit/887e37cd7568219c54f9c2f71bbfe0300ce48376) Update slugs - [`e1f1948`](https://github.com/colinhacks/zod/commit/e1f19482bbed3fbaa563a0d8e09f1a577cc58ac7) fix(v4): ensure array defaults are shallow-cloned ([#&#8203;5173](https://github.com/colinhacks/zod/issues/5173)) - [`9f65038`](https://github.com/colinhacks/zod/commit/9f650385644ae319f806a965b83f79ebd252e497) docs(ecosystem): add DRZL; fix Prisma Zod Generator placement ([#&#8203;5215](https://github.com/colinhacks/zod/issues/5215)) - [`aa6f0f0`](https://github.com/colinhacks/zod/commit/aa6f0f02c2a92a266ff1495a8d2541ae46012fcb) More fixes ([#&#8203;5223](https://github.com/colinhacks/zod/issues/5223)) - [`aab3356`](https://github.com/colinhacks/zod/commit/aab33566bdb44a651cc3e27fde729285e4312419) 4.1.7 ### [`v4.1.6`](https://github.com/colinhacks/zod/compare/v4.1.5...976b43657d4aff6d47c73c1c86125623ea08752d) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.5...976b43657d4aff6d47c73c1c86125623ea08752d) ### [`v4.1.5`](https://github.com/colinhacks/zod/releases/tag/v4.1.5) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.4...v4.1.5) #### Commits: - [`530415f`](https://github.com/colinhacks/zod/commit/530415f927a8f7fa474c96b667efdad6e771ce4d) Update docs - [`b7b081d`](https://github.com/colinhacks/zod/commit/b7b081d5cfd6fc19aeb71f9dc1b07bb333c37f9d) Update z.function() type to support array input ([#&#8203;5170](https://github.com/colinhacks/zod/issues/5170)) - [`780cf57`](https://github.com/colinhacks/zod/commit/780cf57167cbf3902efab68f19fa21ca09cb9dd6) 4.1.5 ### [`v4.1.4`](https://github.com/colinhacks/zod/releases/tag/v4.1.4) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.3...v4.1.4) #### Commits: - [`3291c61`](https://github.com/colinhacks/zod/commit/3291c61fe4bc893901027ea5d50dfc6274e49caa) fix(v4): toJSONSchema - wrong tuple with `null` output when targeting `openapi-3.0` ([#&#8203;5156](https://github.com/colinhacks/zod/issues/5156)) - [`23f41c7`](https://github.com/colinhacks/zod/commit/23f41c7e0af107026bb1732af6b4c368d82be8d2) test(v4): toJSONSchema - use `validateOpenAPI30Schema` in all relevant scenarios ([#&#8203;5163](https://github.com/colinhacks/zod/issues/5163)) - [`0a09fd2`](https://github.com/colinhacks/zod/commit/0a09fd21336202e50565a3e22baaab9a7047fcc9) Update installation instructions - [`4ea5fec`](https://github.com/colinhacks/zod/commit/4ea5fec6988eb7260bc63e0eb8b4a6a0b238c414) 4.1.4 ### [`v4.1.3`](https://github.com/colinhacks/zod/releases/tag/v4.1.3) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.2...v4.1.3) #### Commits: - [`98ff675`](https://github.com/colinhacks/zod/commit/98ff675c313c15d3fa18b2bd01f844b1e817ee79) Drop stringToBoolean - [`a410616`](https://github.com/colinhacks/zod/commit/a410616b39eedf3b4654c0c791b0ab1868996bfb) Fix typo - [`0cf4589`](https://github.com/colinhacks/zod/commit/0cf45896edf8728b57c8e7f2b5a56536760afac1) fix(v4): toJSONSchema - add missing oneOf inside items in tuple conversion ([#&#8203;5146](https://github.com/colinhacks/zod/issues/5146)) - [`8bf0c16`](https://github.com/colinhacks/zod/commit/8bf0c1639f0d3700f01fa8aaee2d8fa5d0abbe10) fix(v4): toJSONSchema tuple path handling for draft-7 with metadata IDs ([#&#8203;5152](https://github.com/colinhacks/zod/issues/5152)) - [`5c5fa90`](https://github.com/colinhacks/zod/commit/5c5fa90e47df934acf6051a3ec30516baeef2eac) fix(v4): toJSONSchema - wrong record output when targeting `openapi-3.0` ([#&#8203;5141](https://github.com/colinhacks/zod/issues/5141)) - [`87b97cc`](https://github.com/colinhacks/zod/commit/87b97ccd556e6d8dc6b4f4455762cc7405b0abc9) docs(codecs): update example to use payloadSchema ([#&#8203;5150](https://github.com/colinhacks/zod/issues/5150)) - [`309f358`](https://github.com/colinhacks/zod/commit/309f3584fd9a3856c3e0c813196210ba4b11d2a9) fix(v4): toJSONSchema - output numbers with exclusive range correctly when targeting `openapi-3.0` ([#&#8203;5139](https://github.com/colinhacks/zod/issues/5139)) - [`1e71ca9`](https://github.com/colinhacks/zod/commit/1e71ca99b92b94aac8ca45694f28864ae1654135) docs: fix refine fn to encode works properly ([#&#8203;5148](https://github.com/colinhacks/zod/issues/5148)) - [`a85ec3c`](https://github.com/colinhacks/zod/commit/a85ec3c73c6a98a496f5dd3b6fb19ebe07e227f9) fix(docs): correct example to use `LooseDog` instead of `Dog` ([#&#8203;5136](https://github.com/colinhacks/zod/issues/5136)) - [`3e98274`](https://github.com/colinhacks/zod/commit/3e982743f3abba6a421abb899670f70e49284af4) 4.1.3 ### [`v4.1.2`](https://github.com/colinhacks/zod/releases/tag/v4.1.2) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.1...v4.1.2) #### Commits: - [`e45e61b`](https://github.com/colinhacks/zod/commit/e45e61b675baf055f4a3ef2ddead21715a1e4fe3) Improve codec docs - [`25a4c37`](https://github.com/colinhacks/zod/commit/25a4c376834db90d3bb3e70d4154e3eb6d4feb7a) fix(v4): toJSONSchema - wrong record tuple output when targeting `openapi-3.0` ([#&#8203;5145](https://github.com/colinhacks/zod/issues/5145)) - [`0fa4f46`](https://github.com/colinhacks/zod/commit/0fa4f464e0e679d71b183e8811ef1e4f30aaa06a) Use method form in codecs.mdx - [`940383d`](https://github.com/colinhacks/zod/commit/940383d0523da41c4e2422b76455da39dddd6c4f) Update JSON codec and docs - [`3009fa8`](https://github.com/colinhacks/zod/commit/3009fa8aeb90e00bfc35c7124f3e6f8cad11d290) 4.1.2 ### [`v4.1.1`](https://github.com/colinhacks/zod/releases/tag/v4.1.1) [Compare Source](https://github.com/colinhacks/zod/compare/v4.1.0...v4.1.1) #### Commits: - [`648eb43`](https://github.com/colinhacks/zod/commit/648eb43c23e31f7d69ef09baba46aef4e9493b13) Remove codecs from sidebare - [`7e39a99`](https://github.com/colinhacks/zod/commit/7e39a99a88a9b7f0c9c3d5fd40fbbab494365c9a) Improve codec docs - [`e5085be`](https://github.com/colinhacks/zod/commit/e5085beb2653f1d05a14c07c79b6f3707daf09f6) Add images - [`028b289`](https://github.com/colinhacks/zod/commit/028b289a48f5589dca58b0b813a5a9f9e363a40b) Add methods - [`10cc994`](https://github.com/colinhacks/zod/commit/10cc9941daeb28b6be5be7327e034c3388d8e60b) 4.1.1 ### [`v4.1.0`](https://github.com/colinhacks/zod/releases/tag/v4.1.0) [Compare Source](https://github.com/colinhacks/zod/compare/v4.0.17...v4.1.0) The first minor version since the introduction of Zod 4 back in May. This version contains a number of features that barely missed the cut for the 4.0 release. With Zod 4 stable and widely adopted, there's more time to resume feature development. #### Codecs This is the flagship feature of this release. Codecs are a new API & schema type that encapsulates a *bi-directional transformation*. It's a huge missing piece in Zod that's finally filled, and it unlocks some totally new ways to use Zod. ```ts const stringToDate = z.codec( z.iso.datetime(), // input schema: ISO date string z.date(), // output schema: Date object { decode: (isoString) => new Date(isoString), encode: (date) => date.toISOString(), } ); ``` New top-level functions are added for processing inputs in the *forward* direction ("decoding") and *backward* direction ("encoding"). ```ts stringToDate.decode("2025-08-21T20:59:45.500Z") // => Date stringToDate.encode(new Date()) // => "2025-08-21T20:59:45.500Z" ``` > **Note** — For bundle size reasons, these new methods have not added to Zod Mini schemas. Instead, this functionality is available via equivalent top-level functions. > > ```ts > // equivalent at runtime > z.decode(stringToDate, "2024-01-15T10:30:00.000Z"); > z.encode(stringToDate, new Date()); > ``` ##### `.parse()` vs `.decode()` Both `.parse()` and `decode()` process data in the "forward" direction. They behave identically at runtime. ```ts stringToDate.parse("2025-08-21T20:59:45.500Z"); stringToDate.decode("2025-08-21T20:59:45.500Z"); ``` There is an important difference however. While `.parse()` accepts any input, `.decode()` expects a *strongly typed* input. That is, it expects an input of type `string`, whereas `.parse()` accepts `unknown`. ```ts stringToDate.parse(Symbol('not-a-string')); // => fails at runtime, but no TypeScript error stringToDate.decode(Symbol("not-a-string")); // ^ ❌ Argument of type 'symbol' is not assignable to parameter of type 'Date'. ts(2345) ``` > This is a highly requested feature unto itself: > > - [#&#8203;3860](https://github.com/colinhacks/zod/issues/3860) > - [#&#8203;1748](https://github.com/colinhacks/zod/issues/1748) > - [#&#8203;3978](https://github.com/colinhacks/zod/issues/3978) > - [#&#8203;1892](https://github.com/colinhacks/zod/issues/1892) ##### Encoding You can use any Zod schema with `.encode()`. The vast majority of Zod schemas are *non-transforming* (the input and output types are identical) so `.decode()` and `.encode()` behave identically. Only certain schema types change their behavior: - **Codecs** — runs from `B->A` and executes the `encode` transform during encoding - **Pipes** — these execute `B->A` instead of `A->B` - **Defaults and prefaults** — Only applied in the forward direction - **Catch** — Only applied in the forward direction > **Note** — To avoid increasing bundle size unnecessarily, these new methods are not available on Zod Mini schemas. For those schemas, equivalent top-level functions are provided. The usual *async* and *safe* variants exist as well: ```ts // decode methods stringToDate.decode("2024-01-15T10:30:00.000Z") await stringToDate.decodeAsync("2024-01-15T10:30:00.000Z") stringToDate.safeDecode("2024-01-15T10:30:00.000Z") await stringToDate.safeDecodeAsync("2024-01-15T10:30:00.000Z") // encode methods stringToDate.encode(new Date()) await stringToDate.encodeAsync(new Date()) stringToDate.safeEncode(new Date()) await stringToDate.safeEncodeAsync(new Date()) ``` ##### Example codecs Below are some "worked examples" for some commonly-needed codecs. These examples are all tested internally for correctness. Just copy/paste them into your project as needed. There is a more comprehensive set available at [zod.dev/codecs](https://zod.dev/codecs). ##### `stringToBigInt` Converts `bigint` into a serializable form. ``` const stringToBigInt = z.codec(z.string(), z.bigint(), { decode: (str) => BigInt(str), encode: (bigint) => bigint.toString(), }); stringToBigInt.decode("12345"); // => 12345n stringToBigInt.encode(12345n); // => "12345" ``` ##### `json` Parses/stringifies JSON data. ```ts const jsonCodec = z.codec(z.string(), z.json(), { decode: (jsonString, ctx) => { try { return JSON.parse(jsonString); } catch (err: any) { ctx.issues.push({ code: "invalid_format", format: "json_string", input: jsonString, message: err.message, }); return z.NEVER; } }, encode: (value) => JSON.stringify(value), }); ``` To further validate the data, `.pipe()` the result of this codec into another schema. ```ts const Params = z.object({ name: z.string(), age: z.number() }); const JsonToParams = jsonCodec.pipe(Params); JsonToParams.decode('{"name":"Alice","age":30}'); // => { name: "Alice", age: 30 } JsonToParams.encode({ name: "Bob", age: 25 }); // => '{"name":"Bob","age":25}' ``` ##### Further reading **For more examples and a technical breakdown of how encoding works, reads the[announcement blog post](https://colinhacks.com/essays/introducing-zod-codecs) and [new Codecs docs page](https://zod.dev/codecs)**. The docs page contains implementations for several other commonly-needed codecs: - [`stringToNumber`](https://zod.dev/codecs?id=stringtonumber) - [`stringToInt`](https://zod.dev/codecs?id=stringtoint) - [`stringToBigInt`](https://zod.dev/codecs?id=stringtobigint) - [`numberToBigInt`](https://zod.dev/codecs?id=numbertobigint) - [`isoDatetimeToDate`](https://zod.dev/codecs?id=isodatetimetodate) - [`epochSecondsToDate`](https://zod.dev/codecs?id=epochsecondstodate) - [`epochMillisToDate`](https://zod.dev/codecs?id=epochmillistodate) - [`jsonCodec`](https://zod.dev/codecs?id=jsoncodec) - [`utf8ToBytes`](https://zod.dev/codecs?id=utf8tobytes) - [`bytesToUtf8`](https://zod.dev/codecs?id=bytestoutf8) - [`base64ToBytes`](https://zod.dev/codecs?id=base64tobytes) - [`base64urlToBytes`](https://zod.dev/codecs?id=base64urltobytes) - [`hexToBytes`](https://zod.dev/codecs?id=hextobytes) - [`stringToURL`](https://zod.dev/codecs?id=stringtourl) - [`stringToHttpURL`](https://zod.dev/codecs?id=stringtohttpurl) - [`uriComponent`](https://zod.dev/codecs?id=uricomponent) - [`stringToBoolean`](https://zod.dev/codecs?id=stringtoboolean) #### `.safeExtend()` The existing way to add additional fields to an object is to use `.extend()`. ```ts const A = z.object({ a: z.string() }) const B = A.extend({ b: z.string() }) ``` Unfortunately this is a bit of a misnomer, as it allows you to overwrite existing fields. This means the result of `.extend()` may not literally `extend` the original type (in the TypeScript sense). ```ts const A = z.object({ a: z.string() }) // { a: string } const B = A.extend({ a: z.number() }) // { a: number } ``` To enforce true `extends` logic, Zod 4.1 introduces a new `.safeExtend()` method. This statically enforces that the newly added properties conform to the existing ones. ```ts z.object({ a: z.string() }).safeExtend({ a: z.number().min(5) }); // ✅ z.object({ a: z.string() }).safeExtend({ a: z.any() }); // ✅ z.object({ a: z.string() }).safeExtend({ a: z.number() }); // ^ ❌ ZodNumber is not assignable ``` Importantly, this new API allows you to safely extend objects containing refinements. ```ts const AB = z.object({ a: z.string(), b: z.string() }).refine(val => val.a === val.b); const ABC = AB.safeExtend({ c: z.string() }); // ABC includes the refinements defined on AB ``` Previously (in Zod 4.x) any refinements attached to the base schema were dropped in the extended result. This was too unexpected. It now throws an error. (Zod 3 did not support extension of refined objects either.) #### `z.hash()` A new top-level string format for validating hashes produced using various common algorithms & encodings. ```ts const md5Schema = z.hash("md5"); // => ZodCustomStringFormat<"md5_hex"> const sha256Base64 = z.hash("sha256", { enc: "base64" }); // => ZodCustomStringFormat<"sha256_base64"> ``` The following hash algorithms and encodings are supported. Each cell provides information about the expected number of characters/padding. | Algorithm / Encoding | `"hex"` | `"base64"` | `"base64url"` | | -------------------- | ------- | --------------- | ------------- | | `"md5"` | 32 | 24 (22 + "==") | 22 | | `"sha1"` | 40 | 28 (27 + "=") | 27 | | `"sha256"` | 64 | 44 (43 + "=") | 43 | | `"sha384"` | 96 | 64 (no padding) | 64 | | `"sha512"` | 128 | 88 (86 + "==") | 86 | #### `z.hex()` To validate hexadecimal strings of any length. ```ts const hexSchema = z.hex(); hexSchema.parse("123abc"); // ✅ "123abc" hexSchema.parse("DEADBEEF"); // ✅ "DEADBEEF" hexSchema.parse("xyz"); // ❌ ZodError ``` #### Additional changes 1. **z.uuid()** now supports the "Max UUID" (`FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF`) per the [RFC](https://www.rfc-editor.org/rfc/rfc9562.html) 2. `$ZodFunction` is now a subtype of `$ZodType` *** #### Commits - [`edd4fea`](https://github.com/colinhacks/zod/commit/edd4feaa) - Closes [#&#8203;5127](https://github.com/colinhacks/zod/issues/5127) - [`5d4a315`](https://github.com/colinhacks/zod/commit/5d4a3159) - Closes [#&#8203;5116](https://github.com/colinhacks/zod/issues/5116) - [`f3f0955`](https://github.com/colinhacks/zod/commit/f3f09556) - Closes [#&#8203;5108](https://github.com/colinhacks/zod/issues/5108) - [`0114d5b`](https://github.com/colinhacks/zod/commit/0114d5bd) - [#&#8203;5122](https://github.com/colinhacks/zod/issues/5122) - [`3b077c3`](https://github.com/colinhacks/zod/commit/3b077c3a) - [#&#8203;5121](https://github.com/colinhacks/zod/issues/5121) - [`1e06af8`](https://github.com/colinhacks/zod/commit/1e06af8e) - [#&#8203;5113](https://github.com/colinhacks/zod/issues/5113) - [`b01b6f3`](https://github.com/colinhacks/zod/commit/b01b6f39) — [#&#8203;5052](https://github.com/colinhacks/zod/issues/5052) - [`571ab0c`](https://github.com/colinhacks/zod/commit/571ab0c3) — [#&#8203;5051](https://github.com/colinhacks/zod/issues/5051) - [`d3ea111`](https://github.com/colinhacks/zod/commit/d3ea1119) — [#&#8203;5049](https://github.com/colinhacks/zod/issues/5049) - [`b8e3f87`](https://github.com/colinhacks/zod/commit/b8e3f877) — [#&#8203;4865](https://github.com/colinhacks/zod/issues/4865) ### [`v4.0.17`](https://github.com/colinhacks/zod/releases/tag/v4.0.17) [Compare Source](https://github.com/colinhacks/zod/compare/v4.0.16...v4.0.17) #### Commits: - [`1cebf33`](https://github.com/colinhacks/zod/commit/1cebf336c560c87e6f806b9d02106fb623049f21) Add blog ([#&#8203;5074](https://github.com/colinhacks/zod/issues/5074)) - [`fc1e556`](https://github.com/colinhacks/zod/commit/fc1e556318159b4740ba3d6b37660e783d2a3cb7) Fixes [#&#8203;5073](https://github.com/colinhacks/zod/issues/5073) - [`cc63f95`](https://github.com/colinhacks/zod/commit/cc63f950158db212c5e9b75e7d22faca851ea624) v4.0.17 ### [`v4.0.16`](https://github.com/colinhacks/zod/releases/tag/v4.0.16) [Compare Source](https://github.com/colinhacks/zod/compare/v4.0.15...v4.0.16) #### Commits: - [`d589186`](https://github.com/colinhacks/zod/commit/d589186c20c3dc112f5a5fda23cccd4d1f74420e) fix: ensure keyof returns enum ([#&#8203;5045](https://github.com/colinhacks/zod/issues/5045)) - [`4975f3a`](https://github.com/colinhacks/zod/commit/4975f3a0e9c9f0b241499d936a02f1998c66dc01) feat: add discriminator generic ([#&#8203;5044](https://github.com/colinhacks/zod/issues/5044)) - [`0a463e3`](https://github.com/colinhacks/zod/commit/0a463e38e7f77b8036628ff911de515f9f9f6662) Update speakeasy files - [`12658af`](https://github.com/colinhacks/zod/commit/12658aff60349a87972a782b64802ec901c5ebf2) Fix Edit page buttons - [`47e6604`](https://github.com/colinhacks/zod/commit/47e6604a3555811115d05bf41e50de54192e2e14) fix: `edit this page` button, now redirects to correct url using the new path ([#&#8203;5056](https://github.com/colinhacks/zod/issues/5056)) - [`7207a2d`](https://github.com/colinhacks/zod/commit/7207a2df38caaae910551b7ecf04941b00fc10c8) Update Hey API link to Zod v3 plugin ([#&#8203;5060](https://github.com/colinhacks/zod/issues/5060)) - [`6887ff3`](https://github.com/colinhacks/zod/commit/6887ff34fb9bf5f6769152cf62ba9b69fa378aac) Update Hey API link to Zod plugin ([#&#8203;5059](https://github.com/colinhacks/zod/issues/5059)) - [`ffff1aa`](https://github.com/colinhacks/zod/commit/ffff1aac6a9a88fe6e7ad2659dbc7743275ea052) Clone POJO objects during defaulting/prefaulting - [`a227cb3`](https://github.com/colinhacks/zod/commit/a227cb3bd22aba48412a0129650b86277adc3545) v4.0.16 ### [`v4.0.15`](https://github.com/colinhacks/zod/releases/tag/v4.0.15) [Compare Source](https://github.com/colinhacks/zod/compare/v4.0.14...v4.0.15) #### Commits: - [`7e7e346`](https://github.com/colinhacks/zod/commit/7e7e3461aceecf3633e158df50d6bc852e7cdf45) Clean up docs - [`f2949a8`](https://github.com/colinhacks/zod/commit/f2949a81a06fe197c53e47c1fab024cebbd7f1f1) \[docs] Fix migration guide upgrade command ([#&#8203;5021](https://github.com/colinhacks/zod/issues/5021)) - [`d43cf19`](https://github.com/colinhacks/zod/commit/d43cf19d5cafd505f2f8e76f13e18564470f0696) Fix recursive object initialization errors with check() and other methods ([#&#8203;5018](https://github.com/colinhacks/zod/issues/5018)) - [`3de2b63`](https://github.com/colinhacks/zod/commit/3de2b6389a57a093f11ecf1820f31e5b4452c7e9) fix: remove redundant Required<> from input and output type definitions ([#&#8203;5033](https://github.com/colinhacks/zod/issues/5033)) - [`93553bd`](https://github.com/colinhacks/zod/commit/93553bd48aeac27fdeb7dcbee5b7e37628572aff) Add needs info - [`03cfa8d`](https://github.com/colinhacks/zod/commit/03cfa8d9367c56d8c29870a83af10edc91eba34a) 4.0.15 ### [`v4.0.14`](https://github.com/colinhacks/zod/releases/tag/v4.0.14) [Compare Source](https://github.com/colinhacks/zod/compare/v4.0.13...v4.0.14) #### Commits: - [`99391a8`](https://github.com/colinhacks/zod/commit/99391a844271558e0f1736c9550375e82e630bbd) Docs: Fix typo ([#&#8203;5005](https://github.com/colinhacks/zod/issues/5005)) - [`e25303e`](https://github.com/colinhacks/zod/commit/e25303e98c8d13ea96c3296507c564011f403ffe) Docs: fix typo ([#&#8203;5008](https://github.com/colinhacks/zod/issues/5008)) - [`dbb05ef`](https://github.com/colinhacks/zod/commit/dbb05ef990c86ec6b1f6eac11b91ec7572e29c89) Add JSON Schema draft-04 output ([#&#8203;4811](https://github.com/colinhacks/zod/issues/4811)) - [`b8257d7`](https://github.com/colinhacks/zod/commit/b8257d7d1f51dd3cb4033a58271bb6ac8e3678c7) Improve tuple recursive inference. - [`9bdbc2f`](https://github.com/colinhacks/zod/commit/9bdbc2f10d466050421a8e28c4b95a8a5776d150) Avoid infinite loops in defineLazy. Fixes [#&#8203;4994](https://github.com/colinhacks/zod/issues/4994). - [`af96ad4`](https://github.com/colinhacks/zod/commit/af96ad4700879b0d6e390a0c65ded4e700049cb9) 4.0.14 ### [`v4.0.13`](https://github.com/colinhacks/zod/releases/tag/v4.0.13) [Compare Source](https://github.com/colinhacks/zod/compare/v4.0.12...v4.0.13) #### Commits: - [`362eb33`](https://github.com/colinhacks/zod/commit/362eb33093e9c5f306eeec95e36985a99aba8fc7) Fix optional + pipe handling. Closes [#&#8203;5002](https://github.com/colinhacks/zod/issues/5002). v4.0.13 ### [`v4.0.12`](https://github.com/colinhacks/zod/releases/tag/v4.0.12) [Compare Source](https://github.com/colinhacks/zod/compare/v4.0.11...v4.0.12) #### Commits: - [`ff83fc9`](https://github.com/colinhacks/zod/commit/ff83fc916ec2b35c0008a48782fa14f84293149d) Add eslint-plugin-import-zod ([#&#8203;4848](https://github.com/colinhacks/zod/issues/4848)) - [`7c9ce38`](https://github.com/colinhacks/zod/commit/7c9ce388ae39b2324c5ad05420ecf4732ebca6fe) Update docs for z.property check ([#&#8203;4863](https://github.com/colinhacks/zod/issues/4863)) - [`c432577`](https://github.com/colinhacks/zod/commit/c432577ad1a7201631ae0a4d80e945fc4937bcc9) docs: add jwt schema docs ([#&#8203;4867](https://github.com/colinhacks/zod/issues/4867)) - [`35e6a6f`](https://github.com/colinhacks/zod/commit/35e6a6f6d64d7d5ba58c4cb8c80105759b977c9b) Add llms.txt ([#&#8203;4915](https://github.com/colinhacks/zod/issues/4915)) - [`3ac7bf0`](https://github.com/colinhacks/zod/commit/3ac7bf00d0d924d1afa1031b798bdd72b59117db) Clean up Edit this Page - [`60a9372`](https://github.com/colinhacks/zod/commit/60a9372414955094b84aae2f30b491a039780b7c) Implement `llms-full.txt` ([#&#8203;5004](https://github.com/colinhacks/zod/issues/5004)) - [`73a1970`](https://github.com/colinhacks/zod/commit/73a1970e7fd0cdcb2ffac3f6f7db85da849ee3d8) 4.0.12 ### [`v4.0.11`](https://github.com/colinhacks/zod/releases/tag/v4.0.11) [Compare Source](https://github.com/colinhacks/zod/compare/v4.0.10...v4.0.11) #### Commits: - [`8e6a5f8`](https://github.com/colinhacks/zod/commit/8e6a5f8e48837fb403deb4025935e97a758ad6ca) Fix “Edit on Github” link ([#&#8203;4997](https://github.com/colinhacks/zod/issues/4997)) - [`930a2f6`](https://github.com/colinhacks/zod/commit/930a2f68d799889df4c1f662dfe61934db84fdd1) Fix number of errors in doc ([#&#8203;4993](https://github.com/colinhacks/zod/issues/4993)) - [`c762dbb`](https://github.com/colinhacks/zod/commit/c762dbb4fdb249cfddccdd69812da3f4b659df67) feat(locale): Add Yoruba (yo) locale ([#&#8203;4996](https://github.com/colinhacks/zod/issues/4996)) - [`9a34a3a`](https://github.com/colinhacks/zod/commit/9a34a3a60d92c44f695b08e4c665209aa7160e24) Zod 4.0.11 ([#&#8203;4981](https://github.com/colinhacks/zod/issues/4981)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS40My43IiwidXBkYXRlZEluVmVyIjoiNDEuMTIxLjMiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbImRlcGVuZGVuY2llcyJdfQ==-->
bustikiller added 1 commit 2025-07-29 02:06:40 +00:00
Update dependency zod to v4.0.11
Some checks failed
Build Nginx-based docker image / build-static-assets (push) Has been cancelled
Add copyright notice / copyright_notice (pull_request) Successful in 1m33s
Check usage of free licenses / build-static-assets (pull_request) Successful in 51s
Playwright Tests / test (pull_request) Successful in 34m39s
12b5d63294
bustikiller force-pushed renovate/zod-4.x-lockfile from 12b5d63294 to 10ebc4bc8f 2025-07-29 02:07:12 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.0.11 to Update dependency zod to v4.0.13 2025-07-30 02:05:33 +00:00
bustikiller force-pushed renovate/zod-4.x-lockfile from 10ebc4bc8f to 66a0ea1042 2025-07-30 02:05:33 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.0.13 to Update dependency zod to v4.0.14 2025-07-31 02:06:27 +00:00
bustikiller force-pushed renovate/zod-4.x-lockfile from 66a0ea1042 to b7fc25d1af 2025-07-31 02:06:27 +00:00 Compare
bustikiller force-pushed renovate/zod-4.x-lockfile from b7fc25d1af to eda1bf7ba3 2025-08-06 02:06:01 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.0.14 to Update dependency zod to v4.0.15 2025-08-06 02:06:02 +00:00
bustikiller force-pushed renovate/zod-4.x-lockfile from eda1bf7ba3 to de7f3f5285 2025-08-09 02:06:56 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.0.15 to Update dependency zod to v4.0.16 2025-08-09 02:06:57 +00:00
bustikiller force-pushed renovate/zod-4.x-lockfile from de7f3f5285 to 164e360d34 2025-08-10 02:09:41 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.0.16 to Update dependency zod to v4.0.17 2025-08-10 02:09:43 +00:00
bustikiller changed title from Update dependency zod to v4.0.17 to Update dependency zod to v4.1.5 2025-09-04 15:04:41 +00:00
bustikiller force-pushed renovate/zod-4.x-lockfile from 164e360d34 to 7a4be69baf 2025-09-04 15:04:41 +00:00 Compare
bustikiller force-pushed renovate/zod-4.x-lockfile from 7a4be69baf to 36f657870c 2025-09-11 14:15:41 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.1.5 to Update dependency zod to v4.1.7 2025-09-11 14:15:44 +00:00
bustikiller force-pushed renovate/zod-4.x-lockfile from 36f657870c to acc38d13b4 2025-09-15 21:58:55 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.1.7 to Update dependency zod to v4.1.8 2025-09-15 21:58:57 +00:00
bustikiller force-pushed renovate/zod-4.x-lockfile from acc38d13b4 to 57f427845c 2025-09-16 22:21:16 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.1.8 to Update dependency zod to v4.1.9 2025-09-16 22:21:21 +00:00
bustikiller force-pushed renovate/zod-4.x-lockfile from 57f427845c to 4c87abd36f 2025-09-20 22:09:17 +00:00 Compare
bustikiller changed title from Update dependency zod to v4.1.9 to Update dependency zod to v4.1.11 2025-09-20 22:09:18 +00:00
Some checks failed
Add copyright notice / copyright_notice (pull_request) Successful in 54s
Required
Details
Check usage of free licenses / build-static-assets (pull_request) Successful in 1m16s
Required
Details
Build Nginx-based docker image / build-static-assets (push) Failing after 5m53s
Required
Details
Playwright Tests / test (pull_request) Failing after 5m53s
Required
Details
Some required checks were not successful.
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin renovate/zod-4.x-lockfile:renovate/zod-4.x-lockfile
git checkout renovate/zod-4.x-lockfile
Sign in to join this conversation.
No Reviewers
No Label
No Milestone
No project
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bustikiller/wedding-planner-frontend#326
No description provided.