zod 3.25.4 → 3.25.5

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 (42) hide show
  1. package/dist/commonjs/v4/classic/errors.d.ts +1 -1
  2. package/dist/commonjs/v4/classic/errors.js +1 -0
  3. package/dist/commonjs/v4/classic/parse.d.ts +1 -1
  4. package/dist/commonjs/v4/classic/parse.js +2 -2
  5. package/dist/commonjs/v4/core/errors.d.ts +1 -1
  6. package/dist/commonjs/v4/core/errors.js +44 -0
  7. package/dist/commonjs/v4/core/parse.js +2 -2
  8. package/dist/esm/v4/classic/errors.d.ts +1 -1
  9. package/dist/esm/v4/classic/errors.js +1 -0
  10. package/dist/esm/v4/classic/parse.d.ts +1 -1
  11. package/dist/esm/v4/classic/parse.js +3 -3
  12. package/dist/esm/v4/core/errors.d.ts +1 -1
  13. package/dist/esm/v4/core/errors.js +11 -0
  14. package/dist/esm/v4/core/parse.js +2 -2
  15. package/package.json +1 -1
  16. package/src/v4/classic/errors.ts +2 -1
  17. package/src/v4/classic/parse.ts +3 -3
  18. package/src/v4/classic/tests/array.test.ts +42 -46
  19. package/src/v4/classic/tests/async-refinements.test.ts +14 -18
  20. package/src/v4/classic/tests/catch.test.ts +10 -12
  21. package/src/v4/classic/tests/discriminated-unions.test.ts +77 -87
  22. package/src/v4/classic/tests/enum.test.ts +33 -39
  23. package/src/v4/classic/tests/error-utils.test.ts +25 -27
  24. package/src/v4/classic/tests/error.test.ts +115 -128
  25. package/src/v4/classic/tests/literal.test.ts +10 -12
  26. package/src/v4/classic/tests/map.test.ts +60 -68
  27. package/src/v4/classic/tests/nested-refine.test.ts +68 -72
  28. package/src/v4/classic/tests/nonoptional.test.ts +36 -44
  29. package/src/v4/classic/tests/number.test.ts +36 -44
  30. package/src/v4/classic/tests/pipe.test.ts +18 -22
  31. package/src/v4/classic/tests/preprocess.test.ts +91 -107
  32. package/src/v4/classic/tests/primitive.test.ts +9 -11
  33. package/src/v4/classic/tests/record.test.ts +101 -121
  34. package/src/v4/classic/tests/set.test.ts +30 -36
  35. package/src/v4/classic/tests/string.test.ts +50 -60
  36. package/src/v4/classic/tests/template-literal.test.ts +45 -55
  37. package/src/v4/classic/tests/transform.test.ts +36 -46
  38. package/src/v4/classic/tests/tuple.test.ts +54 -66
  39. package/src/v4/core/errors.ts +12 -1
  40. package/src/v4/core/parse.ts +2 -2
  41. package/src/v4/core/tests/index.test.ts +42 -1
  42. package/src/v4/mini/tests/error.test.ts +1 -1
@@ -32,24 +32,22 @@ test("valid parse async", async () => {
32
32
  const result = await asyncMap.safeParseAsync(new Map([["first", "foo"]]));
33
33
  expect(result.success).toEqual(false);
34
34
  expect(result.error).toMatchInlineSnapshot(`
35
- ZodError {
36
- "issues": [
37
- {
38
- "code": "custom",
39
- "message": "bad key",
40
- "path": [
41
- "first",
42
- ],
43
- },
44
- {
45
- "code": "custom",
46
- "message": "bad value",
47
- "path": [
48
- "first",
49
- ],
50
- },
51
- ],
52
- }
35
+ [ZodError: [
36
+ {
37
+ "code": "custom",
38
+ "path": [
39
+ "first"
40
+ ],
41
+ "message": "bad key"
42
+ },
43
+ {
44
+ "code": "custom",
45
+ "path": [
46
+ "first"
47
+ ],
48
+ "message": "bad value"
49
+ }
50
+ ]]
53
51
  `);
54
52
  });
55
53
 
@@ -68,26 +66,24 @@ test("throws when the given map has invalid key and invalid input", () => {
68
66
  if (result.success === false) {
69
67
  expect(result.error.issues.length).toEqual(2);
70
68
  expect(result.error).toMatchInlineSnapshot(`
71
- ZodError {
72
- "issues": [
73
- {
74
- "code": "invalid_type",
75
- "expected": "string",
76
- "message": "Invalid input: expected string, received number",
77
- "path": [
78
- 42,
79
- ],
80
- },
81
- {
82
- "code": "invalid_type",
83
- "expected": "string",
84
- "message": "Invalid input: expected string, received symbol",
85
- "path": [
86
- 42,
87
- ],
88
- },
89
- ],
90
- }
69
+ [ZodError: [
70
+ {
71
+ "expected": "string",
72
+ "code": "invalid_type",
73
+ "path": [
74
+ 42
75
+ ],
76
+ "message": "Invalid input: expected string, received number"
77
+ },
78
+ {
79
+ "expected": "string",
80
+ "code": "invalid_type",
81
+ "path": [
82
+ 42
83
+ ],
84
+ "message": "Invalid input: expected string, received symbol"
85
+ }
86
+ ]]
91
87
  `);
92
88
  }
93
89
  });
@@ -146,24 +142,22 @@ test("dirty", async () => {
146
142
  if (!result.success) {
147
143
  expect(result.error.issues.length).toEqual(2);
148
144
  expect(result.error).toMatchInlineSnapshot(`
149
- ZodError {
150
- "issues": [
151
- {
152
- "code": "custom",
153
- "message": "Keys must be uppercase",
154
- "path": [
155
- "first",
156
- ],
157
- },
158
- {
159
- "code": "custom",
160
- "message": "Keys must be uppercase",
161
- "path": [
162
- "second",
163
- ],
164
- },
165
- ],
166
- }
145
+ [ZodError: [
146
+ {
147
+ "code": "custom",
148
+ "path": [
149
+ "first"
150
+ ],
151
+ "message": "Keys must be uppercase"
152
+ },
153
+ {
154
+ "code": "custom",
155
+ "path": [
156
+ "second"
157
+ ],
158
+ "message": "Keys must be uppercase"
159
+ }
160
+ ]]
167
161
  `);
168
162
  }
169
163
  });
@@ -188,17 +182,15 @@ test("map with object keys", () => {
188
182
  const badResult = map.safeParse(badData);
189
183
  expect(badResult.success).toEqual(false);
190
184
  expect(badResult.error).toMatchInlineSnapshot(`
191
- ZodError {
192
- "issues": [
193
- {
194
- "code": "invalid_type",
195
- "expected": "object",
196
- "message": "Invalid input: expected object, received string",
197
- "path": [
198
- "bad",
199
- ],
200
- },
201
- ],
202
- }
185
+ [ZodError: [
186
+ {
187
+ "expected": "object",
188
+ "code": "invalid_type",
189
+ "path": [
190
+ "bad"
191
+ ],
192
+ "message": "Invalid input: expected object, received string"
193
+ }
194
+ ]]
203
195
  `);
204
196
  });
@@ -40,88 +40,84 @@ test("nested refinements", () => {
40
40
  };
41
41
  expect(zodSchema.safeParse(DATA)).toMatchInlineSnapshot(`
42
42
  {
43
- "error": ZodError {
44
- "issues": [
45
- {
46
- "code": "too_small",
47
- "message": "Too small: expected string to have >1 characters",
48
- "minimum": 1,
49
- "origin": "string",
50
- "path": [
51
- "nested",
52
- "confirm",
53
- ],
54
- },
55
- {
56
- "code": "custom",
57
- "message": "Confirm length should be > 2",
58
- "path": [
59
- "nested",
60
- "confirm",
61
- ],
62
- },
63
- {
64
- "code": "custom",
65
- "message": "Value must be "bar"",
66
- "path": [
67
- "nested",
68
- "confirm",
69
- ],
70
- },
71
- {
72
- "code": "custom",
73
- "message": "Password and confirm must match",
74
- "path": [
75
- "nested",
76
- "confirm",
77
- ],
78
- },
43
+ "error": [ZodError: [
44
+ {
45
+ "origin": "string",
46
+ "code": "too_small",
47
+ "minimum": 1,
48
+ "path": [
49
+ "nested",
50
+ "confirm"
79
51
  ],
52
+ "message": "Too small: expected string to have >1 characters"
80
53
  },
54
+ {
55
+ "code": "custom",
56
+ "path": [
57
+ "nested",
58
+ "confirm"
59
+ ],
60
+ "message": "Confirm length should be > 2"
61
+ },
62
+ {
63
+ "code": "custom",
64
+ "path": [
65
+ "nested",
66
+ "confirm"
67
+ ],
68
+ "message": "Value must be \\"bar\\""
69
+ },
70
+ {
71
+ "code": "custom",
72
+ "path": [
73
+ "nested",
74
+ "confirm"
75
+ ],
76
+ "message": "Password and confirm must match"
77
+ }
78
+ ]],
81
79
  "success": false,
82
80
  }
83
81
  `);
84
82
 
85
83
  expect(zodSchema.safeParse(DATA, { jitless: true })).toMatchInlineSnapshot(`
86
84
  {
87
- "error": ZodError {
88
- "issues": [
89
- {
90
- "code": "too_small",
91
- "message": "Too small: expected string to have >1 characters",
92
- "minimum": 1,
93
- "origin": "string",
94
- "path": [
95
- "nested",
96
- "confirm",
97
- ],
98
- },
99
- {
100
- "code": "custom",
101
- "message": "Confirm length should be > 2",
102
- "path": [
103
- "nested",
104
- "confirm",
105
- ],
106
- },
107
- {
108
- "code": "custom",
109
- "message": "Value must be "bar"",
110
- "path": [
111
- "nested",
112
- "confirm",
113
- ],
114
- },
115
- {
116
- "code": "custom",
117
- "message": "Password and confirm must match",
118
- "path": [
119
- "nested",
120
- "confirm",
121
- ],
122
- },
85
+ "error": [ZodError: [
86
+ {
87
+ "origin": "string",
88
+ "code": "too_small",
89
+ "minimum": 1,
90
+ "path": [
91
+ "nested",
92
+ "confirm"
123
93
  ],
94
+ "message": "Too small: expected string to have >1 characters"
124
95
  },
96
+ {
97
+ "code": "custom",
98
+ "path": [
99
+ "nested",
100
+ "confirm"
101
+ ],
102
+ "message": "Confirm length should be > 2"
103
+ },
104
+ {
105
+ "code": "custom",
106
+ "path": [
107
+ "nested",
108
+ "confirm"
109
+ ],
110
+ "message": "Value must be \\"bar\\""
111
+ },
112
+ {
113
+ "code": "custom",
114
+ "path": [
115
+ "nested",
116
+ "confirm"
117
+ ],
118
+ "message": "Password and confirm must match"
119
+ }
120
+ ]],
125
121
  "success": false,
126
122
  }
127
123
  `);
@@ -10,16 +10,14 @@ test("nonoptional", () => {
10
10
  expect(result.success).toBe(false);
11
11
  expect(result).toMatchInlineSnapshot(`
12
12
  {
13
- "error": ZodError {
14
- "issues": [
15
- {
16
- "code": "invalid_type",
17
- "expected": "string",
18
- "message": "Invalid input: expected string, received undefined",
19
- "path": [],
20
- },
21
- ],
22
- },
13
+ "error": [ZodError: [
14
+ {
15
+ "expected": "string",
16
+ "code": "invalid_type",
17
+ "path": [],
18
+ "message": "Invalid input: expected string, received undefined"
19
+ }
20
+ ]],
23
21
  "success": false,
24
22
  }
25
23
  `);
@@ -34,16 +32,14 @@ test("nonoptional with default", () => {
34
32
  expect(result.success).toBe(false);
35
33
  expect(result).toMatchInlineSnapshot(`
36
34
  {
37
- "error": ZodError {
38
- "issues": [
39
- {
40
- "code": "invalid_type",
41
- "expected": "nonoptional",
42
- "message": "Invalid input: expected nonoptional, received undefined",
43
- "path": [],
44
- },
45
- ],
46
- },
35
+ "error": [ZodError: [
36
+ {
37
+ "code": "invalid_type",
38
+ "expected": "nonoptional",
39
+ "path": [],
40
+ "message": "Invalid input: expected nonoptional, received undefined"
41
+ }
42
+ ]],
47
43
  "success": false,
48
44
  }
49
45
  `);
@@ -61,34 +57,30 @@ test("nonoptional in object", () => {
61
57
  // expect(schema.safeParse({ hi: undefined }).success).toEqual(false);
62
58
  expect(r2.success).toEqual(false);
63
59
  expect(r2.error).toMatchInlineSnapshot(`
64
- ZodError {
65
- "issues": [
66
- {
67
- "code": "invalid_type",
68
- "expected": "nonoptional",
69
- "message": "Invalid input: expected nonoptional, received undefined",
70
- "path": [
71
- "hi",
72
- ],
73
- },
74
- ],
75
- }
60
+ [ZodError: [
61
+ {
62
+ "code": "invalid_type",
63
+ "expected": "nonoptional",
64
+ "path": [
65
+ "hi"
66
+ ],
67
+ "message": "Invalid input: expected nonoptional, received undefined"
68
+ }
69
+ ]]
76
70
  `);
77
71
 
78
72
  const r3 = schema.safeParse({});
79
73
  expect(r3.success).toEqual(false);
80
74
  expect(r3.error).toMatchInlineSnapshot(`
81
- ZodError {
82
- "issues": [
83
- {
84
- "code": "invalid_type",
85
- "expected": "nonoptional",
86
- "message": "Invalid input: expected nonoptional, received undefined",
87
- "path": [
88
- "hi",
89
- ],
90
- },
91
- ],
92
- }
75
+ [ZodError: [
76
+ {
77
+ "code": "invalid_type",
78
+ "expected": "nonoptional",
79
+ "path": [
80
+ "hi"
81
+ ],
82
+ "message": "Invalid input: expected nonoptional, received undefined"
83
+ }
84
+ ]]
93
85
  `);
94
86
  });
@@ -16,33 +16,29 @@ test("Infinity validation", () => {
16
16
  const schema = z.number();
17
17
  expect(schema.safeParse(Number.POSITIVE_INFINITY)).toMatchInlineSnapshot(`
18
18
  {
19
- "error": ZodError {
20
- "issues": [
21
- {
22
- "code": "invalid_type",
23
- "expected": "number",
24
- "message": "Invalid input: expected number, received number",
25
- "path": [],
26
- "received": "Infinity",
27
- },
28
- ],
29
- },
19
+ "error": [ZodError: [
20
+ {
21
+ "expected": "number",
22
+ "code": "invalid_type",
23
+ "received": "Infinity",
24
+ "path": [],
25
+ "message": "Invalid input: expected number, received number"
26
+ }
27
+ ]],
30
28
  "success": false,
31
29
  }
32
30
  `);
33
31
  expect(schema.safeParse(Number.NEGATIVE_INFINITY)).toMatchInlineSnapshot(`
34
32
  {
35
- "error": ZodError {
36
- "issues": [
37
- {
38
- "code": "invalid_type",
39
- "expected": "number",
40
- "message": "Invalid input: expected number, received number",
41
- "path": [],
42
- "received": "Infinity",
43
- },
44
- ],
45
- },
33
+ "error": [ZodError: [
34
+ {
35
+ "expected": "number",
36
+ "code": "invalid_type",
37
+ "received": "Infinity",
38
+ "path": [],
39
+ "message": "Invalid input: expected number, received number"
40
+ }
41
+ ]],
46
42
  "success": false,
47
43
  }
48
44
  `);
@@ -153,33 +149,29 @@ test(".finite() validation", () => {
153
149
  expect(schema.parse(123)).toEqual(123);
154
150
  expect(schema.safeParse(Number.POSITIVE_INFINITY)).toMatchInlineSnapshot(`
155
151
  {
156
- "error": ZodError {
157
- "issues": [
158
- {
159
- "code": "invalid_type",
160
- "expected": "number",
161
- "message": "Invalid input: expected number, received number",
162
- "path": [],
163
- "received": "Infinity",
164
- },
165
- ],
166
- },
152
+ "error": [ZodError: [
153
+ {
154
+ "expected": "number",
155
+ "code": "invalid_type",
156
+ "received": "Infinity",
157
+ "path": [],
158
+ "message": "Invalid input: expected number, received number"
159
+ }
160
+ ]],
167
161
  "success": false,
168
162
  }
169
163
  `);
170
164
  expect(schema.safeParse(Number.NEGATIVE_INFINITY)).toMatchInlineSnapshot(`
171
165
  {
172
- "error": ZodError {
173
- "issues": [
174
- {
175
- "code": "invalid_type",
176
- "expected": "number",
177
- "message": "Invalid input: expected number, received number",
178
- "path": [],
179
- "received": "Infinity",
180
- },
181
- ],
182
- },
166
+ "error": [ZodError: [
167
+ {
168
+ "expected": "number",
169
+ "code": "invalid_type",
170
+ "received": "Infinity",
171
+ "path": [],
172
+ "message": "Invalid input: expected number, received number"
173
+ }
174
+ ]],
183
175
  "success": false,
184
176
  }
185
177
  `);
@@ -40,20 +40,18 @@ test("continue on non-fatal errors", () => {
40
40
 
41
41
  expect(schema.safeParse("4321")).toMatchInlineSnapshot(`
42
42
  {
43
- "error": ZodError {
44
- "issues": [
45
- {
46
- "code": "custom",
47
- "message": "A",
48
- "path": [],
49
- },
50
- {
51
- "code": "custom",
52
- "message": "B",
53
- "path": [],
54
- },
55
- ],
43
+ "error": [ZodError: [
44
+ {
45
+ "code": "custom",
46
+ "path": [],
47
+ "message": "A"
56
48
  },
49
+ {
50
+ "code": "custom",
51
+ "path": [],
52
+ "message": "B"
53
+ }
54
+ ]],
57
55
  "success": false,
58
56
  }
59
57
  `);
@@ -70,15 +68,13 @@ test("break on fatal errors", () => {
70
68
 
71
69
  expect(schema.safeParse("4321")).toMatchInlineSnapshot(`
72
70
  {
73
- "error": ZodError {
74
- "issues": [
75
- {
76
- "code": "custom",
77
- "message": "A",
78
- "path": [],
79
- },
80
- ],
81
- },
71
+ "error": [ZodError: [
72
+ {
73
+ "code": "custom",
74
+ "path": [],
75
+ "message": "A"
76
+ }
77
+ ]],
82
78
  "success": false,
83
79
  }
84
80
  `);