UNPKG

@payfit/unity-components

Version:

61 lines (60 loc) 1.49 kB
import { z as e } from "zod/v3"; import { z as t } from "zod/v4"; //#region src/adapters/zodAdapter.ts var n = class { constructor(e) { this.zodSchema = e; } getField(t) { try { if (!this.zodSchema) return null; let n = t.split("."), r = this.zodSchema.shape, i; for (let t = 0; t < n.length; t++) { let a = n[t]; if (i = r[a], !i) return null; if (t < n.length - 1) { let t = i instanceof e.ZodOptional ? i._def.innerType.shape : i.shape; if (!t) return null; r = t; } } let a = i instanceof e.ZodOptional, o = a ? i._def.innerType : i; return { isOptional: a, type: o._def?.typeName || "unknown", shape: o instanceof e.ZodObject ? o.shape : void 0 }; } catch { return null; } } }, r = class { constructor(e) { this.zodSchema = e; } getField(e) { try { if (!this.zodSchema) return null; let n = e.split("."), r = this.zodSchema.shape, i; for (let e = 0; e < n.length; e++) { let a = n[e]; if (i = r[a], !i) return null; if (e < n.length - 1) { let e = i instanceof t.ZodOptional ? i.def.innerType.shape : i.shape; if (!e) return null; r = e; } } let a = i instanceof t.ZodOptional, o = a ? i.def.innerType : i; return { isOptional: a, type: o.def?.typeName || "unknown", shape: o instanceof t.ZodObject ? o.shape : void 0 }; } catch { return null; } } }; //#endregion export { n as ZodV3SchemaAdapter, r as ZodV4SchemaAdapter };