| 36 | * This will unpack optionals, refinements, etc. |
| 37 | */ |
| 38 | export function getBaseSchema< |
| 39 | ChildType extends z.ZodAny | z.AnyZodObject = z.ZodAny, |
| 40 | >(schema: ChildType | z.ZodEffects<ChildType>): ChildType | null { |
| 41 | if (!schema) return null; |
| 42 | if ("innerType" in schema._def) |
| 43 | return getBaseSchema(schema._def.innerType as ChildType); |
| 44 | |
| 45 | if ("schema" in schema._def) |
| 46 | return getBaseSchema(schema._def.schema as ChildType); |
| 47 | |
| 48 | return schema as ChildType; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Get the type name of the lowest level Zod type. |