Live galleries fill themselves from their event (picks, or every ready photo) while the match is on; photos taken out by hand stay out. Clients mark favourites and comment (approved by the photographer); the app shows the selection, exports CSV, copies file names and labels the favourites in the library. Orders download as one ZIP, and free galleries get "download all". Fixes PATCH on galleries, sites and print events resetting fields to their defaults (a title change made a private gallery public). Claude-Session: https://claude.ai/code/session_01HT6iXLYUUp9pJz5Kza9xCW
17 lines
771 B
TypeScript
17 lines
771 B
TypeScript
import { z } from "zod";
|
|
|
|
type Undefaulted<T> = T extends z.ZodDefault<infer Inner> ? 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<Shape extends z.ZodRawShape>(schema: z.ZodObject<Shape>) {
|
|
const shape: Record<string, z.ZodType> = {};
|
|
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<Undefaulted<Shape[K]>> }>;
|
|
}
|