zod 4.2.0-canary.20250921T171445 → 4.2.0-canary.20251001T172710
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 +1 -1
- package/src/v4/core/errors.ts +6 -16
- package/v4/core/errors.cjs +2 -10
- package/v4/core/errors.js +2 -10
package/package.json
CHANGED
package/src/v4/core/errors.ts
CHANGED
|
@@ -226,9 +226,9 @@ type _FlattenedError<T, U = string> = {
|
|
|
226
226
|
|
|
227
227
|
export function flattenError<T>(error: $ZodError<T>): _FlattenedError<T>;
|
|
228
228
|
export function flattenError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): _FlattenedError<T, U>;
|
|
229
|
-
export function flattenError(error: $ZodError
|
|
230
|
-
const fieldErrors: any = {};
|
|
231
|
-
const formErrors:
|
|
229
|
+
export function flattenError<T, U>(error: $ZodError<T>, mapper = (issue: $ZodIssue) => issue.message as U) {
|
|
230
|
+
const fieldErrors: Record<PropertyKey, any> = {};
|
|
231
|
+
const formErrors: U[] = [];
|
|
232
232
|
for (const sub of error.issues) {
|
|
233
233
|
if (sub.path.length > 0) {
|
|
234
234
|
fieldErrors[sub.path[0]!] = fieldErrors[sub.path[0]!] || [];
|
|
@@ -254,12 +254,7 @@ export type $ZodFormattedError<T, U = string> = {
|
|
|
254
254
|
|
|
255
255
|
export function formatError<T>(error: $ZodError<T>): $ZodFormattedError<T>;
|
|
256
256
|
export function formatError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodFormattedError<T, U>;
|
|
257
|
-
export function formatError<T>(error: $ZodError
|
|
258
|
-
const mapper: (issue: $ZodIssue) => any =
|
|
259
|
-
_mapper ||
|
|
260
|
-
function (issue: $ZodIssue) {
|
|
261
|
-
return issue.message;
|
|
262
|
-
};
|
|
257
|
+
export function formatError<T, U>(error: $ZodError<T>, mapper = (issue: $ZodIssue) => issue.message as U) {
|
|
263
258
|
const fieldErrors: $ZodFormattedError<T> = { _errors: [] } as any;
|
|
264
259
|
const processError = (error: { issues: $ZodIssue[] }) => {
|
|
265
260
|
for (const issue of error.issues) {
|
|
@@ -307,13 +302,8 @@ export type $ZodErrorTree<T, U = string> = T extends util.Primitive
|
|
|
307
302
|
|
|
308
303
|
export function treeifyError<T>(error: $ZodError<T>): $ZodErrorTree<T>;
|
|
309
304
|
export function treeifyError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodErrorTree<T, U>;
|
|
310
|
-
export function treeifyError<T>(error: $ZodError
|
|
311
|
-
const
|
|
312
|
-
_mapper ||
|
|
313
|
-
function (issue: $ZodIssue) {
|
|
314
|
-
return issue.message;
|
|
315
|
-
};
|
|
316
|
-
const result: $ZodErrorTree<T> = { errors: [] } as any;
|
|
305
|
+
export function treeifyError<T, U>(error: $ZodError<T>, mapper = (issue: $ZodIssue) => issue.message as U) {
|
|
306
|
+
const result: $ZodErrorTree<T, U> = { errors: [] } as any;
|
|
317
307
|
const processError = (error: { issues: $ZodIssue[] }, path: PropertyKey[] = []) => {
|
|
318
308
|
for (const issue of error.issues) {
|
|
319
309
|
if (issue.code === "invalid_union" && issue.errors.length) {
|
package/v4/core/errors.cjs
CHANGED
|
@@ -63,11 +63,7 @@ function flattenError(error, mapper = (issue) => issue.message) {
|
|
|
63
63
|
}
|
|
64
64
|
return { formErrors, fieldErrors };
|
|
65
65
|
}
|
|
66
|
-
function formatError(error,
|
|
67
|
-
const mapper = _mapper ||
|
|
68
|
-
function (issue) {
|
|
69
|
-
return issue.message;
|
|
70
|
-
};
|
|
66
|
+
function formatError(error, mapper = (issue) => issue.message) {
|
|
71
67
|
const fieldErrors = { _errors: [] };
|
|
72
68
|
const processError = (error) => {
|
|
73
69
|
for (const issue of error.issues) {
|
|
@@ -105,11 +101,7 @@ function formatError(error, _mapper) {
|
|
|
105
101
|
processError(error);
|
|
106
102
|
return fieldErrors;
|
|
107
103
|
}
|
|
108
|
-
function treeifyError(error,
|
|
109
|
-
const mapper = _mapper ||
|
|
110
|
-
function (issue) {
|
|
111
|
-
return issue.message;
|
|
112
|
-
};
|
|
104
|
+
function treeifyError(error, mapper = (issue) => issue.message) {
|
|
113
105
|
const result = { errors: [] };
|
|
114
106
|
const processError = (error, path = []) => {
|
|
115
107
|
var _a, _b;
|
package/v4/core/errors.js
CHANGED
|
@@ -32,11 +32,7 @@ export function flattenError(error, mapper = (issue) => issue.message) {
|
|
|
32
32
|
}
|
|
33
33
|
return { formErrors, fieldErrors };
|
|
34
34
|
}
|
|
35
|
-
export function formatError(error,
|
|
36
|
-
const mapper = _mapper ||
|
|
37
|
-
function (issue) {
|
|
38
|
-
return issue.message;
|
|
39
|
-
};
|
|
35
|
+
export function formatError(error, mapper = (issue) => issue.message) {
|
|
40
36
|
const fieldErrors = { _errors: [] };
|
|
41
37
|
const processError = (error) => {
|
|
42
38
|
for (const issue of error.issues) {
|
|
@@ -74,11 +70,7 @@ export function formatError(error, _mapper) {
|
|
|
74
70
|
processError(error);
|
|
75
71
|
return fieldErrors;
|
|
76
72
|
}
|
|
77
|
-
export function treeifyError(error,
|
|
78
|
-
const mapper = _mapper ||
|
|
79
|
-
function (issue) {
|
|
80
|
-
return issue.message;
|
|
81
|
-
};
|
|
73
|
+
export function treeifyError(error, mapper = (issue) => issue.message) {
|
|
82
74
|
const result = { errors: [] };
|
|
83
75
|
const processError = (error, path = []) => {
|
|
84
76
|
var _a, _b;
|