require-branded-id-schema
Brand Zod identifier schemas so validated identifiers retain their domain.
Why
Validating the format of a scenario ID or session ID still produces a plain string. Distinct brands let TypeScript catch swaps between roles that use the same primitive representation.
Fix
Apply a distinct Zod brand to each identifier domain at its parse boundary. Derive the TypeScript ID type with z.output or z.infer, and reuse its schema in objects that carry the ID.
Examples
import { z } from "zod";export const RecordingSchema = z.strictObject({ takeId: z.uuid(), sessionId: z.uuid(),});import { z } from "zod";const TakeIdSchema = z.uuid().brand<"TakeId">();const SessionIdSchema = z.uuid().brand<"SessionId">();export const RecordingSchema = z.strictObject({ takeId: TakeIdSchema, sessionId: SessionIdSchema,});