zod 3.25.68-beta.1 → 3.25.68

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.
Files changed (98) hide show
  1. package/README.md +2 -2
  2. package/package.json +1 -1
  3. package/v3/ZodError.cjs +8 -0
  4. package/v3/ZodError.js +8 -0
  5. package/v3/helpers/errorUtil.cjs +1 -0
  6. package/v3/helpers/errorUtil.js +1 -0
  7. package/v3/helpers/parseUtil.cjs +4 -4
  8. package/v3/helpers/parseUtil.js +4 -4
  9. package/v3/helpers/util.cjs +4 -4
  10. package/v3/helpers/util.js +4 -4
  11. package/v3/standard-schema.d.cts +69 -0
  12. package/v3/standard-schema.d.ts +69 -0
  13. package/v3/types.cjs +217 -5
  14. package/v3/types.d.cts +39 -1
  15. package/v3/types.d.ts +39 -1
  16. package/v3/types.js +217 -5
  17. package/v4/classic/compat.cjs +6 -0
  18. package/v4/classic/compat.d.cts +21 -2
  19. package/v4/classic/compat.d.ts +21 -2
  20. package/v4/classic/compat.js +6 -0
  21. package/v4/classic/errors.cjs +12 -0
  22. package/v4/classic/errors.d.cts +15 -1
  23. package/v4/classic/errors.d.ts +15 -1
  24. package/v4/classic/errors.js +12 -0
  25. package/v4/classic/external.cjs +4 -0
  26. package/v4/classic/external.js +4 -0
  27. package/v4/classic/iso.js +4 -4
  28. package/v4/classic/parse.js +4 -4
  29. package/v4/classic/schemas.cjs +59 -1
  30. package/v4/classic/schemas.d.cts +97 -2
  31. package/v4/classic/schemas.d.ts +97 -2
  32. package/v4/classic/schemas.js +123 -65
  33. package/v4/core/api.cjs +42 -1
  34. package/v4/core/api.d.cts +21 -3
  35. package/v4/core/api.d.ts +21 -3
  36. package/v4/core/api.js +48 -3
  37. package/v4/core/checks.cjs +27 -3
  38. package/v4/core/checks.d.cts +2 -0
  39. package/v4/core/checks.d.ts +2 -0
  40. package/v4/core/checks.js +48 -24
  41. package/v4/core/core.cjs +3 -0
  42. package/v4/core/core.d.cts +3 -0
  43. package/v4/core/core.d.ts +3 -0
  44. package/v4/core/core.js +4 -1
  45. package/v4/core/doc.cjs +1 -0
  46. package/v4/core/doc.js +1 -0
  47. package/v4/core/errors.cjs +37 -0
  48. package/v4/core/errors.d.cts +35 -0
  49. package/v4/core/errors.d.ts +35 -0
  50. package/v4/core/errors.js +37 -0
  51. package/v4/core/function.d.cts +1 -0
  52. package/v4/core/function.d.ts +1 -0
  53. package/v4/core/parse.js +4 -4
  54. package/v4/core/regexes.cjs +20 -0
  55. package/v4/core/regexes.d.cts +10 -0
  56. package/v4/core/regexes.d.ts +10 -0
  57. package/v4/core/regexes.js +24 -4
  58. package/v4/core/registries.cjs +4 -1
  59. package/v4/core/registries.js +5 -2
  60. package/v4/core/schemas.cjs +54 -10
  61. package/v4/core/schemas.d.cts +53 -3
  62. package/v4/core/schemas.d.ts +53 -3
  63. package/v4/core/schemas.js +120 -76
  64. package/v4/core/standard-schema.d.cts +23 -0
  65. package/v4/core/standard-schema.d.ts +23 -0
  66. package/v4/core/to-json-schema.cjs +67 -6
  67. package/v4/core/to-json-schema.d.cts +20 -0
  68. package/v4/core/to-json-schema.d.ts +20 -0
  69. package/v4/core/to-json-schema.js +67 -6
  70. package/v4/core/util.cjs +23 -8
  71. package/v4/core/util.js +23 -8
  72. package/v4/locales/ca.cjs +2 -1
  73. package/v4/locales/ca.js +2 -1
  74. package/v4/locales/es.cjs +1 -0
  75. package/v4/locales/es.js +1 -0
  76. package/v4/locales/he.cjs +1 -0
  77. package/v4/locales/he.js +1 -0
  78. package/v4/locales/hu.cjs +1 -0
  79. package/v4/locales/hu.js +1 -0
  80. package/v4/locales/it.cjs +1 -0
  81. package/v4/locales/it.js +1 -0
  82. package/v4/locales/mk.cjs +1 -0
  83. package/v4/locales/mk.js +1 -0
  84. package/v4/locales/ota.cjs +1 -0
  85. package/v4/locales/ota.js +1 -0
  86. package/v4/locales/ta.cjs +1 -1
  87. package/v4/locales/ta.js +1 -1
  88. package/v4/locales/ua.cjs +1 -0
  89. package/v4/locales/ua.js +1 -0
  90. package/v4/mini/external.cjs +4 -0
  91. package/v4/mini/external.d.cts +1 -0
  92. package/v4/mini/external.d.ts +1 -0
  93. package/v4/mini/external.js +4 -0
  94. package/v4/mini/iso.js +4 -4
  95. package/v4/mini/schemas.cjs +39 -1
  96. package/v4/mini/schemas.d.cts +11 -1
  97. package/v4/mini/schemas.d.ts +11 -1
  98. package/v4/mini/schemas.js +102 -64
package/README.md CHANGED
@@ -58,7 +58,7 @@
58
58
  Zod is a TypeScript-first validation library. Define a schema and parse some data with it. You'll get back a strongly typed, validated result.
59
59
 
60
60
  ```ts
61
- import { z } from "zod/v4";
61
+ import * as z from "zod/v4";
62
62
 
63
63
  const User = z.object({
64
64
  name: z.string(),
@@ -104,7 +104,7 @@ npm install zod
104
104
  Before you can do anything else, you need to define a schema. For the purposes of this guide, we'll use a simple object schema.
105
105
 
106
106
  ```ts
107
- import { z } from "zod/v4";
107
+ import * as z from "zod/v4";
108
108
 
109
109
  const Player = z.object({
110
110
  username: z.string(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.25.68-beta.1",
3
+ "version": "3.25.68",
4
4
  "type": "module",
5
5
  "author": "Colin McDonnell <zod@colinhacks.com>",
6
6
  "description": "TypeScript-first schema declaration and validation library with static type inference",
package/v3/ZodError.cjs CHANGED
@@ -40,6 +40,7 @@ class ZodError extends Error {
40
40
  };
41
41
  const actualProto = new.target.prototype;
42
42
  if (Object.setPrototypeOf) {
43
+ // eslint-disable-next-line ban/ban
43
44
  Object.setPrototypeOf(this, actualProto);
44
45
  }
45
46
  else {
@@ -76,6 +77,13 @@ class ZodError extends Error {
76
77
  const terminal = i === issue.path.length - 1;
77
78
  if (!terminal) {
78
79
  curr[el] = curr[el] || { _errors: [] };
80
+ // if (typeof el === "string") {
81
+ // curr[el] = curr[el] || { _errors: [] };
82
+ // } else if (typeof el === "number") {
83
+ // const errorArray: any = [];
84
+ // errorArray._errors = [];
85
+ // curr[el] = curr[el] || errorArray;
86
+ // }
79
87
  }
80
88
  else {
81
89
  curr[el] = curr[el] || { _errors: [] };
package/v3/ZodError.js CHANGED
@@ -36,6 +36,7 @@ export class ZodError extends Error {
36
36
  };
37
37
  const actualProto = new.target.prototype;
38
38
  if (Object.setPrototypeOf) {
39
+ // eslint-disable-next-line ban/ban
39
40
  Object.setPrototypeOf(this, actualProto);
40
41
  }
41
42
  else {
@@ -72,6 +73,13 @@ export class ZodError extends Error {
72
73
  const terminal = i === issue.path.length - 1;
73
74
  if (!terminal) {
74
75
  curr[el] = curr[el] || { _errors: [] };
76
+ // if (typeof el === "string") {
77
+ // curr[el] = curr[el] || { _errors: [] };
78
+ // } else if (typeof el === "number") {
79
+ // const errorArray: any = [];
80
+ // errorArray._errors = [];
81
+ // curr[el] = curr[el] || errorArray;
82
+ // }
75
83
  }
76
84
  else {
77
85
  curr[el] = curr[el] || { _errors: [] };
@@ -4,5 +4,6 @@ exports.errorUtil = void 0;
4
4
  var errorUtil;
5
5
  (function (errorUtil) {
6
6
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
7
+ // biome-ignore lint:
7
8
  errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
8
9
  })(errorUtil || (exports.errorUtil = errorUtil = {}));
@@ -1,5 +1,6 @@
1
1
  export var errorUtil;
2
2
  (function (errorUtil) {
3
3
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
4
+ // biome-ignore lint:
4
5
  errorUtil.toString = (message) => typeof message === "string" ? message : message?.message;
5
6
  })(errorUtil || (errorUtil = {}));
@@ -44,10 +44,10 @@ function addIssueToContext(ctx, issueData) {
44
44
  data: ctx.data,
45
45
  path: ctx.path,
46
46
  errorMaps: [
47
- ctx.common.contextualErrorMap,
48
- ctx.schemaErrorMap,
49
- overrideMap,
50
- overrideMap === en_js_1.default ? undefined : en_js_1.default,
47
+ ctx.common.contextualErrorMap, // contextual error map is first priority
48
+ ctx.schemaErrorMap, // then schema-bound map if available
49
+ overrideMap, // then global override map
50
+ overrideMap === en_js_1.default ? undefined : en_js_1.default, // then global default map
51
51
  ].filter((x) => !!x),
52
52
  });
53
53
  ctx.common.issues.push(issue);
@@ -36,10 +36,10 @@ export function addIssueToContext(ctx, issueData) {
36
36
  data: ctx.data,
37
37
  path: ctx.path,
38
38
  errorMaps: [
39
- ctx.common.contextualErrorMap,
40
- ctx.schemaErrorMap,
41
- overrideMap,
42
- overrideMap === defaultErrorMap ? undefined : defaultErrorMap,
39
+ ctx.common.contextualErrorMap, // contextual error map is first priority
40
+ ctx.schemaErrorMap, // then schema-bound map if available
41
+ overrideMap, // then global override map
42
+ overrideMap === defaultErrorMap ? undefined : defaultErrorMap, // then global default map
43
43
  ].filter((x) => !!x),
44
44
  });
45
45
  ctx.common.issues.push(issue);
@@ -30,8 +30,8 @@ var util;
30
30
  return obj[e];
31
31
  });
32
32
  };
33
- util.objectKeys = typeof Object.keys === "function"
34
- ? (obj) => Object.keys(obj)
33
+ util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
34
+ ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
35
35
  : (object) => {
36
36
  const keys = [];
37
37
  for (const key in object) {
@@ -49,7 +49,7 @@ var util;
49
49
  return undefined;
50
50
  };
51
51
  util.isInteger = typeof Number.isInteger === "function"
52
- ? (val) => Number.isInteger(val)
52
+ ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
53
53
  : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
54
54
  function joinValues(array, separator = " | ") {
55
55
  return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
@@ -67,7 +67,7 @@ var objectUtil;
67
67
  objectUtil.mergeShapes = (first, second) => {
68
68
  return {
69
69
  ...first,
70
- ...second,
70
+ ...second, // second overwrites first
71
71
  };
72
72
  };
73
73
  })(objectUtil || (exports.objectUtil = objectUtil = {}));
@@ -27,8 +27,8 @@ export var util;
27
27
  return obj[e];
28
28
  });
29
29
  };
30
- util.objectKeys = typeof Object.keys === "function"
31
- ? (obj) => Object.keys(obj)
30
+ util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
31
+ ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
32
32
  : (object) => {
33
33
  const keys = [];
34
34
  for (const key in object) {
@@ -46,7 +46,7 @@ export var util;
46
46
  return undefined;
47
47
  };
48
48
  util.isInteger = typeof Number.isInteger === "function"
49
- ? (val) => Number.isInteger(val)
49
+ ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
50
50
  : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
51
51
  function joinValues(array, separator = " | ") {
52
52
  return array.map((val) => (typeof val === "string" ? `'${val}'` : val)).join(separator);
@@ -64,7 +64,7 @@ export var objectUtil;
64
64
  objectUtil.mergeShapes = (first, second) => {
65
65
  return {
66
66
  ...first,
67
- ...second,
67
+ ...second, // second overwrites first
68
68
  };
69
69
  };
70
70
  })(objectUtil || (objectUtil = {}));
@@ -1,33 +1,102 @@
1
+ /**
2
+ * The Standard Schema interface.
3
+ */
1
4
  export type StandardSchemaV1<Input = unknown, Output = Input> = {
5
+ /**
6
+ * The Standard Schema properties.
7
+ */
2
8
  readonly "~standard": StandardSchemaV1.Props<Input, Output>;
3
9
  };
4
10
  export declare namespace StandardSchemaV1 {
11
+ /**
12
+ * The Standard Schema properties interface.
13
+ */
5
14
  export interface Props<Input = unknown, Output = Input> {
15
+ /**
16
+ * The version number of the standard.
17
+ */
6
18
  readonly version: 1;
19
+ /**
20
+ * The vendor name of the schema library.
21
+ */
7
22
  readonly vendor: string;
23
+ /**
24
+ * Validates unknown input values.
25
+ */
8
26
  readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
27
+ /**
28
+ * Inferred types associated with the schema.
29
+ */
9
30
  readonly types?: Types<Input, Output> | undefined;
10
31
  }
32
+ /**
33
+ * The result interface of the validate function.
34
+ */
11
35
  export type Result<Output> = SuccessResult<Output> | FailureResult;
36
+ /**
37
+ * The result interface if validation succeeds.
38
+ */
12
39
  export interface SuccessResult<Output> {
40
+ /**
41
+ * The typed output value.
42
+ */
13
43
  readonly value: Output;
44
+ /**
45
+ * The non-existent issues.
46
+ */
14
47
  readonly issues?: undefined;
15
48
  }
49
+ /**
50
+ * The result interface if validation fails.
51
+ */
16
52
  export interface FailureResult {
53
+ /**
54
+ * The issues of failed validation.
55
+ */
17
56
  readonly issues: ReadonlyArray<Issue>;
18
57
  }
58
+ /**
59
+ * The issue interface of the failure output.
60
+ */
19
61
  export interface Issue {
62
+ /**
63
+ * The error message of the issue.
64
+ */
20
65
  readonly message: string;
66
+ /**
67
+ * The path of the issue, if any.
68
+ */
21
69
  readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
22
70
  }
71
+ /**
72
+ * The path segment interface of the issue.
73
+ */
23
74
  export interface PathSegment {
75
+ /**
76
+ * The key representing a path segment.
77
+ */
24
78
  readonly key: PropertyKey;
25
79
  }
80
+ /**
81
+ * The Standard Schema types interface.
82
+ */
26
83
  export interface Types<Input = unknown, Output = Input> {
84
+ /**
85
+ * The input type of the schema.
86
+ */
27
87
  readonly input: Input;
88
+ /**
89
+ * The output type of the schema.
90
+ */
28
91
  readonly output: Output;
29
92
  }
93
+ /**
94
+ * Infers the input type of a Standard Schema.
95
+ */
30
96
  export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
97
+ /**
98
+ * Infers the output type of a Standard Schema.
99
+ */
31
100
  export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
32
101
  export {};
33
102
  }
@@ -1,33 +1,102 @@
1
+ /**
2
+ * The Standard Schema interface.
3
+ */
1
4
  export type StandardSchemaV1<Input = unknown, Output = Input> = {
5
+ /**
6
+ * The Standard Schema properties.
7
+ */
2
8
  readonly "~standard": StandardSchemaV1.Props<Input, Output>;
3
9
  };
4
10
  export declare namespace StandardSchemaV1 {
11
+ /**
12
+ * The Standard Schema properties interface.
13
+ */
5
14
  export interface Props<Input = unknown, Output = Input> {
15
+ /**
16
+ * The version number of the standard.
17
+ */
6
18
  readonly version: 1;
19
+ /**
20
+ * The vendor name of the schema library.
21
+ */
7
22
  readonly vendor: string;
23
+ /**
24
+ * Validates unknown input values.
25
+ */
8
26
  readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
27
+ /**
28
+ * Inferred types associated with the schema.
29
+ */
9
30
  readonly types?: Types<Input, Output> | undefined;
10
31
  }
32
+ /**
33
+ * The result interface of the validate function.
34
+ */
11
35
  export type Result<Output> = SuccessResult<Output> | FailureResult;
36
+ /**
37
+ * The result interface if validation succeeds.
38
+ */
12
39
  export interface SuccessResult<Output> {
40
+ /**
41
+ * The typed output value.
42
+ */
13
43
  readonly value: Output;
44
+ /**
45
+ * The non-existent issues.
46
+ */
14
47
  readonly issues?: undefined;
15
48
  }
49
+ /**
50
+ * The result interface if validation fails.
51
+ */
16
52
  export interface FailureResult {
53
+ /**
54
+ * The issues of failed validation.
55
+ */
17
56
  readonly issues: ReadonlyArray<Issue>;
18
57
  }
58
+ /**
59
+ * The issue interface of the failure output.
60
+ */
19
61
  export interface Issue {
62
+ /**
63
+ * The error message of the issue.
64
+ */
20
65
  readonly message: string;
66
+ /**
67
+ * The path of the issue, if any.
68
+ */
21
69
  readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
22
70
  }
71
+ /**
72
+ * The path segment interface of the issue.
73
+ */
23
74
  export interface PathSegment {
75
+ /**
76
+ * The key representing a path segment.
77
+ */
24
78
  readonly key: PropertyKey;
25
79
  }
80
+ /**
81
+ * The Standard Schema types interface.
82
+ */
26
83
  export interface Types<Input = unknown, Output = Input> {
84
+ /**
85
+ * The input type of the schema.
86
+ */
27
87
  readonly input: Input;
88
+ /**
89
+ * The output type of the schema.
90
+ */
28
91
  readonly output: Output;
29
92
  }
93
+ /**
94
+ * Infers the input type of a Standard Schema.
95
+ */
30
96
  export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
97
+ /**
98
+ * Infers the output type of a Standard Schema.
99
+ */
31
100
  export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
32
101
  export {};
33
102
  }