Validates IPC handler inputs and data schemas with Zod v4. Use when: defining IPC handler input schemas, validating checklist data structures, parsing imported file data, or creating type-safe validation for any data boundary.
This project uses Zod v4 (^4.2.1) for schema validation at IPC boundaries. Every oRPC handler that accepts input validates it through a Zod schema defined in a co-located schemas.ts file. Schemas also serve as the single source of truth for TypeScript types via z.infer<>.
// src/ipc/<domain>/schemas.ts
import z from "zod";
export const writeChecklistFileInputSchema = z.object({
filePath: z.string(),
content: z.string(),
});
// src/ipc/<domain>/handlers.ts
import { os } from "@orpc/server";
import { writeChecklistFileInputSchema } from "./schemas";
export const writeChecklistFile = os
.input(writeChecklistFileInputSchema)
.handler(async ({ input }) => {
// input is typed as { filePath: string; content: string }
});
// Default import — project convention
import z from "zod";
// Named import also works
import { z } from "zod";
Both are valid. Pick one per file and stay consistent. The project currently uses both — prefer import z from "zod" for new files.
| Concept | Usage | Example |
|---|---|---|
z.object() | Validate structured input | z.object({ name: z.string() }) |
z.enum() | Restrict to literal values | z.enum(["light", "dark", "system"]) |
z.infer<> | Extract TS type from schema | type Mode = z.infer<typeof modeSchema> |
z.url() | Validate URL strings (v4) | z.url() — replaces z.string().url() |
z.email() | Validate email (v4) | z.email() — replaces z.string().email() |
.optional() | Make field optional | z.string().optional() |
.default() | Provide default value | z.number().default(0) |
.parse() | Validate and throw on error | schema.parse(data) |
.safeParse() | Validate without throwing | schema.safeParse(data) |
When: Handler accepts one of a fixed set of values.
export const checklistFormatSchema = z.enum(["Ace", "Json", "Pdf"]);
type ChecklistFormat = z.infer<typeof checklistFormatSchema>;
// "Ace" | "Json" | "Pdf"
When: Handler accepts structured data with multiple fields.
export const exportFileInputSchema = z.object({
fileId: z.string(),
format: checklistFormatSchema,
outputPath: z.string(),
});
When: Validating common string formats. Use v4 top-level validators instead of chained methods.
// Zod v4 — preferred
z.url();
z.email();
z.uuid();
// Deprecated — avoid
z.string().url();
z.string().email();
z.string().uuid();
Fetch latest Zod v4 documentation with Context7.
How to use Context7:
mcp__context7__resolve-library-id to search for "zod"/websites/) over source code repositoriesmcp__context7__query-docs using the resolved library IDLibrary ID: /websites/zod_dev_v4
Recommended Queries: