1- import type { AnyZodObject , ZodDefault , ZodEffects , ZodType , ZodTypeDef , ZodUnion } from 'zod' ;
1+ import type {
2+ AnyZodObject ,
3+ ZodDefault ,
4+ ZodEffects ,
5+ ZodErrorMap ,
6+ ZodType ,
7+ ZodTypeDef ,
8+ ZodUnion
9+ } from 'zod' ;
210import type { JSONSchema7 } from 'json-schema' ;
311import {
412 type AdapterOptions ,
@@ -54,9 +62,10 @@ export type ZodValidation<T extends ZodObjectTypes> =
5462
5563async function validate < T extends ZodValidation < ZodObjectTypes > > (
5664 schema : T ,
57- data : unknown
65+ data : unknown ,
66+ errorMap : ZodErrorMap | undefined
5867) : Promise < ValidationResult < Infer < T > > > {
59- const result = await schema . safeParseAsync ( data ) ;
68+ const result = await schema . safeParseAsync ( data , { errorMap } ) ;
6069 if ( result . success ) {
6170 return {
6271 data : result . data as Infer < T > ,
@@ -71,22 +80,23 @@ async function validate<T extends ZodValidation<ZodObjectTypes>>(
7180
7281function _zod < T extends ZodValidation < ZodObjectTypes > > (
7382 schema : T ,
74- options ?: AdapterOptions < Infer < T > > & { config ?: Partial < Options > }
83+ options ?: AdapterOptions < Infer < T > > & { errorMap ?: ZodErrorMap ; config ?: Partial < Options > }
7584) : ValidationAdapter < Infer < T > , InferIn < T > > {
7685 return createAdapter ( {
7786 superFormValidationLibrary : 'zod' ,
78- validate : async ( data ) => validate ( schema , data ) ,
87+ validate : async ( data ) => validate ( schema , data , options ?. errorMap ) ,
7988 jsonSchema : options ?. jsonSchema ?? zodToJSONSchema ( schema , options ?. config ) ,
8089 defaults : options ?. defaults
8190 } ) ;
8291}
8392
8493function _zodClient < T extends ZodValidation < ZodObjectTypes > > (
85- schema : T
94+ schema : T ,
95+ options ?: { errorMap ?: ZodErrorMap }
8696) : ClientValidationAdapter < Infer < T > , InferIn < T > > {
8797 return {
8898 superFormValidationLibrary : 'zod' ,
89- validate : async ( data ) => validate ( schema , data )
99+ validate : async ( data ) => validate ( schema , data , options ?. errorMap )
90100 } ;
91101}
92102
0 commit comments