| 182 | type SchemaRegistry = ReturnType<typeof z.registry<{ id: string }>>; |
| 183 | |
| 184 | function getSchemaId(schema: unknown, reg: SchemaRegistry): string | undefined { |
| 185 | // Check per-library registry first |
| 186 | try { |
| 187 | const meta = reg.get(schema as z.$ZodType) as { id?: string } | undefined; |
| 188 | if (meta?.id) return meta.id; |
| 189 | } catch { |
| 190 | // not registered — fall through |
| 191 | } |
| 192 | // Fallback: WeakMap tags from defineComponent / tagSchemaId |
| 193 | if (typeof schema === "object" && schema !== null) { |
| 194 | return schemaIdTags.get(schema); |
| 195 | } |
| 196 | return undefined; |
| 197 | } |
| 198 | |
| 199 | function getUnionOptions(schema: unknown): unknown[] | undefined { |
| 200 | const def = getZodDef(schema); |