import { z } from "zod"; type Undefaulted = T extends z.ZodDefault ? Inner : T; /** * The schema for a PATCH: every field optional and no defaults. zod's `.partial()` keeps `.default()`s, so a * PATCH that leaves a field out would reset it (a private gallery would turn public on a title change). */ export function patchOf(schema: z.ZodObject) { const shape: Record = {}; for (const [key, field] of Object.entries(schema.shape)) { const inner = field instanceof z.ZodDefault ? (field.unwrap() as z.ZodType) : (field as z.ZodType); shape[key] = inner.optional(); } return z.object(shape) as unknown as z.ZodObject<{ [K in keyof Shape]: z.ZodOptional> }>; }