1
- import {
2
- type ZodErrorMap ,
3
- type ZodType ,
4
- type ZodTypeDef ,
5
- } from 'zod' ;
1
+ import { type ZodErrorMap , type ZodType , type ZodTypeDef } from 'zod' ;
6
2
import type { JSONSchema7 } from 'json-schema' ;
7
3
import {
8
4
type AdapterOptions ,
@@ -28,10 +24,13 @@ export const zodToJSONSchema = (...params: Parameters<typeof zodToJson>) => {
28
24
return zodToJson ( ...params ) as JSONSchema7 ;
29
25
} ;
30
26
31
-
32
27
// allows for any object schema
33
28
// allows `undefined` in the input type to account for ZodDefault
34
- export type ZodObjectType = ZodType < Record < string , unknown > , ZodTypeDef , Record < string , unknown > | undefined > ;
29
+ export type ZodObjectType = ZodType <
30
+ Record < string , unknown > ,
31
+ ZodTypeDef ,
32
+ Record < string , unknown > | undefined
33
+ > ;
35
34
export type ZodObjectTypes = ZodObjectType ;
36
35
37
36
// left in for compatibility reasons
@@ -43,11 +42,11 @@ async function validate<T extends ZodValidation>(
43
42
schema : T ,
44
43
data : unknown ,
45
44
errorMap : ZodErrorMap | undefined
46
- ) : Promise < ValidationResult < Infer < T , " zod" > > > {
45
+ ) : Promise < ValidationResult < Infer < T , ' zod' > > > {
47
46
const result = await schema . safeParseAsync ( data , { errorMap } ) ;
48
47
if ( result . success ) {
49
48
return {
50
- data : result . data as Infer < T , " zod" > ,
49
+ data : result . data as Infer < T , ' zod' > ,
51
50
success : true
52
51
} ;
53
52
}
@@ -60,23 +59,23 @@ async function validate<T extends ZodValidation>(
60
59
61
60
function _zod < T extends ZodValidation > (
62
61
schema : T ,
63
- options ?: AdapterOptions < Infer < T , " zod" > > & { errorMap ?: ZodErrorMap ; config ?: Partial < Options > }
64
- ) : ValidationAdapter < Infer < T , " zod" > , InferIn < T , " zod" > > {
62
+ options ?: AdapterOptions < Infer < T , ' zod' > > & { errorMap ?: ZodErrorMap ; config ?: Partial < Options > }
63
+ ) : ValidationAdapter < Infer < T , ' zod' > , InferIn < T , ' zod' > > {
65
64
return createAdapter ( {
66
- superFormValidationLibrary : " zod" ,
67
- async validate ( data ) {
65
+ superFormValidationLibrary : ' zod' ,
66
+ async validate ( data ) {
68
67
// options?.defaults
69
- return validate ( schema , data , options ?. errorMap )
68
+ return validate ( schema , data , options ?. errorMap ) ;
70
69
} ,
71
70
jsonSchema : options ?. jsonSchema ?? zodToJSONSchema ( schema , options ?. config ) ,
72
- defaults : options ?. defaults ,
71
+ defaults : options ?. defaults
73
72
} ) ;
74
73
}
75
74
76
75
function _zodClient < T extends ZodValidation > (
77
76
schema : T ,
78
77
options ?: { errorMap ?: ZodErrorMap }
79
- ) : ClientValidationAdapter < Infer < T , " zod" > , InferIn < T , " zod" > > {
78
+ ) : ClientValidationAdapter < Infer < T , ' zod' > , InferIn < T , ' zod' > > {
80
79
return {
81
80
superFormValidationLibrary : 'zod' ,
82
81
validate : async ( data ) => validate ( schema , data , options ?. errorMap )
0 commit comments