* Unwrap optional, nullable, default effects
(schema: z.ZodTypeAny)
| 226 | * Unwrap optional, nullable, default effects |
| 227 | */ |
| 228 | function unwrapEffects(schema: z.ZodTypeAny): z.ZodTypeAny { |
| 229 | let current = schema; |
| 230 | |
| 231 | while (true) { |
| 232 | const def = (current as any)._def as ZodDef | undefined; |
| 233 | |
| 234 | if (!def) break; |
| 235 | |
| 236 | const typeName = getDefType(def); |
| 237 | |
| 238 | if (typeName === 'optional' || typeName === 'nullable' || typeName === 'default') { |
| 239 | current = def.innerType; |
| 240 | continue; |
| 241 | } |
| 242 | |
| 243 | if (typeName === 'effects') { |
| 244 | current = def.schema; |
| 245 | continue; |
| 246 | } |
| 247 | |
| 248 | if (typeName === 'pipe') { |
| 249 | current = def.out ?? def.schema ?? def.innerType ?? def.in ?? current; |
| 250 | if (current === schema) break; |
| 251 | continue; |
| 252 | } |
| 253 | |
| 254 | break; |
| 255 | } |
| 256 | |
| 257 | return current; |
| 258 | } |
| 259 | |
| 260 | function unwrapToObject( |
| 261 | schema: z.ZodTypeAny |
no test coverage detected