zod 4.2.0-canary.20251118T055142 → 4.2.0-canary.20251118T062010

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.2.0-canary.20251118T055142",
3
+ "version": "4.2.0-canary.20251118T062010",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -208,7 +208,7 @@ test("continuability", () => {
208
208
  "message": "Invalid MAC address",
209
209
  "origin": "string",
210
210
  "path": [],
211
- "pattern": "/^(([0-9A-F]{2}(:)[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(:)[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$/",
211
+ "pattern": "/^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/",
212
212
  },
213
213
  {
214
214
  "code": "custom",
@@ -574,7 +574,7 @@ test("regexes", () => {
574
574
  `"^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$"`
575
575
  );
576
576
  expect(mac._zod.pattern.source).toMatchInlineSnapshot(
577
- `"^(([0-9A-F]{2}(:)[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(:)[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$"`
577
+ `"^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$"`
578
578
  );
579
579
  expect(ulid._zod.pattern.source).toMatchInlineSnapshot(`"^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$"`);
580
580
  expect(uuid._zod.pattern.source).toMatchInlineSnapshot(
@@ -136,7 +136,7 @@ describe("toJSONSchema", () => {
136
136
  {
137
137
  "$schema": "https://json-schema.org/draft/2020-12/schema",
138
138
  "format": "mac",
139
- "pattern": "^(([0-9A-F]{2}(:)[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(:)[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$",
139
+ "pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
140
140
  "type": "string",
141
141
  }
142
142
  `);
@@ -144,7 +144,7 @@ describe("toJSONSchema", () => {
144
144
  {
145
145
  "$schema": "https://json-schema.org/draft/2020-12/schema",
146
146
  "format": "mac",
147
- "pattern": "^(([0-9A-F]{2}(:)[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(:)[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$",
147
+ "pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
148
148
  "type": "string",
149
149
  }
150
150
  `);
@@ -152,7 +152,7 @@ describe("toJSONSchema", () => {
152
152
  {
153
153
  "$schema": "https://json-schema.org/draft/2020-12/schema",
154
154
  "format": "mac",
155
- "pattern": "^(([0-9A-F]{2}(-)[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(-)[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$",
155
+ "pattern": "^(?:[0-9A-F]{2}-){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}-){5}[0-9a-f]{2}$",
156
156
  "type": "string",
157
157
  }
158
158
  `);
@@ -385,7 +385,7 @@ describe("toJSONSchema", () => {
385
385
  {
386
386
  "$schema": "https://json-schema.org/draft/2020-12/schema",
387
387
  "format": "mac",
388
- "pattern": "^(([0-9A-F]{2}(:)[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(:)[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$",
388
+ "pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
389
389
  "type": "string",
390
390
  }
391
391
  `);
@@ -393,7 +393,7 @@ describe("toJSONSchema", () => {
393
393
  {
394
394
  "$schema": "https://json-schema.org/draft/2020-12/schema",
395
395
  "format": "mac",
396
- "pattern": "^(([0-9A-F]{2}(:)[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(:)[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$",
396
+ "pattern": "^(?:[0-9A-F]{2}:){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$",
397
397
  "type": "string",
398
398
  }
399
399
  `);
@@ -401,7 +401,7 @@ describe("toJSONSchema", () => {
401
401
  {
402
402
  "$schema": "https://json-schema.org/draft/2020-12/schema",
403
403
  "format": "mac",
404
- "pattern": "^(([0-9A-F]{2}(-)[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(-)[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$",
404
+ "pattern": "^(?:[0-9A-F]{2}-){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}-){5}[0-9a-f]{2}$",
405
405
  "type": "string",
406
406
  }
407
407
  `);
@@ -63,9 +63,7 @@ export const ipv6: RegExp =
63
63
  /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
64
64
  export const mac = (delimiter?: string): RegExp => {
65
65
  const escapedDelim = util.escapeRegex(delimiter ?? ":");
66
- return new RegExp(
67
- `^(([0-9A-F]{2}(${escapedDelim})[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(${escapedDelim})[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$`
68
- );
66
+ return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
69
67
  };
70
68
  export const cidrv4: RegExp =
71
69
  /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
@@ -3793,8 +3793,8 @@ export const $ZodReadonly: core.$constructor<$ZodReadonly> = /*@__PURE__*/ core.
3793
3793
  $ZodType.init(inst, def);
3794
3794
  util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
3795
3795
  util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
3796
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
3797
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
3796
+ util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
3797
+ util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
3798
3798
 
3799
3799
  inst._zod.parse = (payload, ctx) => {
3800
3800
  if (ctx.direction === "backward") {
@@ -4186,10 +4186,10 @@ export const $ZodLazy: core.$constructor<$ZodLazy> = /*@__PURE__*/ core.$constru
4186
4186
  // return () => _innerType;
4187
4187
  // });
4188
4188
  util.defineLazy(inst._zod, "innerType", () => def.getter() as $ZodType);
4189
- util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod.pattern);
4190
- util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod.propValues);
4191
- util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod.optin ?? undefined);
4192
- util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod.optout ?? undefined);
4189
+ util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
4190
+ util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
4191
+ util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
4192
+ util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
4193
4193
  inst._zod.parse = (payload, ctx) => {
4194
4194
  const inner = inst._zod.innerType;
4195
4195
  return inner._zod.run(payload, ctx);
@@ -0,0 +1,45 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import * as z from "zod/v4";
3
+
4
+ describe("Recursive Tuples Regression #5089", () => {
5
+ it("creates recursive tuple without crash", () => {
6
+ expect(() => {
7
+ const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
8
+ }).not.toThrow();
9
+ });
10
+
11
+ it("parses recursive tuple data correctly", () => {
12
+ const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
13
+
14
+ // Base case
15
+ expect(y.parse("hello")).toBe("hello");
16
+
17
+ // Recursive cases
18
+ expect(() => y.parse(["a", "b"])).not.toThrow();
19
+ expect(() => y.parse(["a", ["b", "c"]])).not.toThrow();
20
+ });
21
+
22
+ it("matches #5089 expected behavior", () => {
23
+ // Exact code from the issue
24
+ expect(() => {
25
+ const y = z.lazy((): any => z.tuple([y, y]).or(z.string()));
26
+ y.parse(["a", ["b", "c"]]);
27
+ }).not.toThrow();
28
+ });
29
+
30
+ it("handles workaround pattern", () => {
31
+ // Alternative pattern from issue discussion
32
+ expect(() => {
33
+ const y = z.lazy((): any => z.string().or(z.lazy(() => z.tuple([y, y]))));
34
+ y.parse(["a", ["b", "c"]]);
35
+ }).not.toThrow();
36
+ });
37
+
38
+ it("recursive arrays still work (comparison)", () => {
39
+ const y = z.lazy((): any => z.array(y).or(z.string()));
40
+
41
+ expect(y.parse("hello")).toBe("hello");
42
+ expect(y.parse(["hello", "world"])).toEqual(["hello", "world"]);
43
+ expect(y.parse(["a", ["b", "c"]])).toEqual(["a", ["b", "c"]]);
44
+ });
45
+ });
@@ -72,7 +72,7 @@ exports.ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?
72
72
  exports.ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
73
73
  const mac = (delimiter) => {
74
74
  const escapedDelim = util.escapeRegex(delimiter ?? ":");
75
- return new RegExp(`^(([0-9A-F]{2}(${escapedDelim})[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(${escapedDelim})[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$`);
75
+ return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
76
76
  };
77
77
  exports.mac = mac;
78
78
  exports.cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
@@ -41,7 +41,7 @@ export const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.)
41
41
  export const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
42
42
  export const mac = (delimiter) => {
43
43
  const escapedDelim = util.escapeRegex(delimiter ?? ":");
44
- return new RegExp(`^(([0-9A-F]{2}(${escapedDelim})[0-9A-F]{2}(\\3[0-9A-F]{2}){4})|([0-9a-f]{2}(${escapedDelim})[0-9a-f]{2}(\\6[0-9a-f]{2}){4}))$`);
44
+ return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
45
45
  };
46
46
  export const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
47
47
  export const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
@@ -1780,8 +1780,8 @@ exports.$ZodReadonly = core.$constructor("$ZodReadonly", (inst, def) => {
1780
1780
  exports.$ZodType.init(inst, def);
1781
1781
  util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1782
1782
  util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1783
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1784
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1783
+ util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
1784
+ util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
1785
1785
  inst._zod.parse = (payload, ctx) => {
1786
1786
  if (ctx.direction === "backward") {
1787
1787
  return def.innerType._zod.run(payload, ctx);
@@ -1941,10 +1941,10 @@ exports.$ZodLazy = core.$constructor("$ZodLazy", (inst, def) => {
1941
1941
  // return () => _innerType;
1942
1942
  // });
1943
1943
  util.defineLazy(inst._zod, "innerType", () => def.getter());
1944
- util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod.pattern);
1945
- util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod.propValues);
1946
- util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod.optin ?? undefined);
1947
- util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod.optout ?? undefined);
1944
+ util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
1945
+ util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
1946
+ util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
1947
+ util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
1948
1948
  inst._zod.parse = (payload, ctx) => {
1949
1949
  const inner = inst._zod.innerType;
1950
1950
  return inner._zod.run(payload, ctx);
@@ -1749,8 +1749,8 @@ export const $ZodReadonly = /*@__PURE__*/ core.$constructor("$ZodReadonly", (ins
1749
1749
  $ZodType.init(inst, def);
1750
1750
  util.defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
1751
1751
  util.defineLazy(inst._zod, "values", () => def.innerType._zod.values);
1752
- util.defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
1753
- util.defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
1752
+ util.defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
1753
+ util.defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
1754
1754
  inst._zod.parse = (payload, ctx) => {
1755
1755
  if (ctx.direction === "backward") {
1756
1756
  return def.innerType._zod.run(payload, ctx);
@@ -1910,10 +1910,10 @@ export const $ZodLazy = /*@__PURE__*/ core.$constructor("$ZodLazy", (inst, def)
1910
1910
  // return () => _innerType;
1911
1911
  // });
1912
1912
  util.defineLazy(inst._zod, "innerType", () => def.getter());
1913
- util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod.pattern);
1914
- util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod.propValues);
1915
- util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod.optin ?? undefined);
1916
- util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod.optout ?? undefined);
1913
+ util.defineLazy(inst._zod, "pattern", () => inst._zod.innerType?._zod?.pattern);
1914
+ util.defineLazy(inst._zod, "propValues", () => inst._zod.innerType?._zod?.propValues);
1915
+ util.defineLazy(inst._zod, "optin", () => inst._zod.innerType?._zod?.optin ?? undefined);
1916
+ util.defineLazy(inst._zod, "optout", () => inst._zod.innerType?._zod?.optout ?? undefined);
1917
1917
  inst._zod.parse = (payload, ctx) => {
1918
1918
  const inner = inst._zod.innerType;
1919
1919
  return inner._zod.run(payload, ctx);