Packages
@surfjs/zod
Zod schema integration for Surf commands
@surfjs/zod#
Use Zod schemas for command parameters instead of the manual ParamSchema format. @surfjs/zod automatically converts Zod types to Surf's native schema format and provides full type inference in handlers.
bash
pnpm add @surfjs/zod zodtypescript
import { z } from 'zod'import { createSurf } from '@surfjs/core'import { defineZodCommand } from '@surfjs/zod'ย const search = defineZodCommand({ description: 'Search products', params: z.object({ query: z.string().describe('Search term'), limit: z.number().int().min(1).max(100).default(10), inStock: z.boolean().optional(), }), run({ query, limit, inStock }) { // All params are fully typed from the Zod schema // query โ string // limit โ number (default 10) // inStock โ boolean | undefined return db.products.search({ query, limit, inStock }) },})ย const surf = await createSurf({ name: 'My Store', commands: { search },})๐ก Tip: Zod validators run automatically at request time โ invalid params return a structured
INVALID_PARAMSerror with field-level messages before your handler is called.
The Zod schema is converted to Surf's ParamSchema at startup โ no runtime Zod dependency is shipped to clients. Enum constraints, defaults, descriptions, and nested objects are all preserved in the manifest.