@@ -76,8 +76,9 @@ export function returnValidationErrors<S extends Schema>(
76
76
77
77
/**
78
78
* Transform default formatted validation errors into flattened structure.
79
- * `rootErrors` contains global errors, and `fieldErrors` contains errors for each field,
80
- * one level deep. It skips errors for nested fields.
79
+ * `formErrors` contains global errors, and `fieldErrors` contains errors for each field,
80
+ * one level deep. It discards errors for nested fields.
81
+ * Emulation of `zod`'s [`flatten`](https://zod.dev/ERROR_HANDLING?id=flattening-errors) function.
81
82
* @param {ValidationErrors } [validationErrors] Validation errors object
82
83
* @returns {FlattenedValidationErrors } Flattened validation errors
83
84
*/
@@ -86,7 +87,7 @@ export function flattenValidationErrors<
86
87
const VE extends ValidationErrors < S > ,
87
88
> ( validationErrors ?: VE ) {
88
89
const flattened : FlattenedValidationErrors < S , VE > = {
89
- rootErrors : [ ] ,
90
+ formErrors : [ ] ,
90
91
fieldErrors : { } ,
91
92
} ;
92
93
@@ -96,7 +97,7 @@ export function flattenValidationErrors<
96
97
97
98
for ( const [ key , value ] of Object . entries < string [ ] | { _errors : string [ ] } > ( validationErrors ) ) {
98
99
if ( key === "_errors" && Array . isArray ( value ) ) {
99
- flattened . rootErrors = [ ...value ] ;
100
+ flattened . formErrors = [ ...value ] ;
100
101
} else {
101
102
if ( "_errors" in value ) {
102
103
flattened . fieldErrors [ key as keyof Omit < VE , "_errors" > ] = [ ...value . _errors ] ;
0 commit comments