@@ -71,6 +71,10 @@ function isZodEnumDef(def: AnyZodTypeDef): def is z.ZodEnumDef {
7171 return def . typeName === z . ZodFirstPartyTypeKind . ZodEnum ;
7272}
7373
74+ function isZodSetDef ( def : AnyZodTypeDef ) : def is z . ZodSetDef {
75+ return def . typeName === z . ZodFirstPartyTypeKind . ZodSet ;
76+ }
77+
7478function isZodArrayDef ( def : AnyZodTypeDef ) : def is z . ZodArrayDef {
7579 return def . typeName === 'ZodArray' ;
7680}
@@ -124,6 +128,7 @@ export function reformatInstrumentData({
124128
125129export function getZodTypeName ( schema : z . ZodTypeAny , isOptional ?: boolean ) : ZodTypeNameResult {
126130 const def : unknown = schema . _def ;
131+ console . log ( 'zod def' , def ) ;
127132 if ( isZodTypeDef ( def ) ) {
128133 if ( isZodOptionalDef ( def ) ) {
129134 return getZodTypeName ( def . innerType , true ) ;
@@ -136,7 +141,24 @@ export function getZodTypeName(schema: z.ZodTypeAny, isOptional?: boolean): ZodT
136141 } ;
137142 } else if ( isZodArrayDef ( def ) ) {
138143 return interpretZodArray ( schema , def . typeName , isOptional ) ;
144+ } else if ( isZodSetDef ( def ) ) {
145+ const innerDef : unknown = def . valueType . _def ;
146+
147+ if ( isZodTypeDef ( innerDef ) && isZodEnumDef ( innerDef ) ) {
148+ return {
149+ enumValues : innerDef . values ,
150+ isOptional : Boolean ( isOptional ) ,
151+ success : true ,
152+ typeName : def . typeName
153+ } ;
154+ } else {
155+ return {
156+ message : 'Invalid types with set definition' ,
157+ success : false
158+ } ;
159+ }
139160 }
161+
140162 return {
141163 isOptional : Boolean ( isOptional ) ,
142164 success : true ,
@@ -313,7 +335,18 @@ function generateSampleData({
313335 case 'ZodNumber' :
314336 return formatTypeInfo ( 'number' , isOptional ) ;
315337 case 'ZodSet' :
316- return formatTypeInfo ( 'SET(a,b,c)' , isOptional ) ;
338+ try {
339+ let possibleEnumOutputs = 'SET(' ;
340+ for ( const val of enumValues ! ) {
341+ possibleEnumOutputs += val + '/' ;
342+ }
343+ possibleEnumOutputs = possibleEnumOutputs . slice ( 0 , - 1 ) ;
344+ possibleEnumOutputs += ', ...)' ;
345+ return formatTypeInfo ( possibleEnumOutputs , isOptional ) ;
346+ } catch {
347+ throw new Error ( 'Invalid Enum error' ) ;
348+ }
349+
317350 case 'ZodString' :
318351 return formatTypeInfo ( 'string' , isOptional ) ;
319352 case 'ZodEnum' :
0 commit comments