The TypeScript type inferred from the Zod schema
A message definition object with type information and schemas
import { defineMessage, z } from '@xtr-dev/zodiac';
// Define a user message type
const userMessage = defineMessage('user-message', z.object({
name: z.string().min(1),
message: z.string().max(500),
timestamp: z.number().optional()
}));
// The returned definition has full type inference
channel.on(userMessage, (data) => {
// data.name is string
// data.message is string
// data.timestamp is number | undefined
});
Creates a type-safe message definition with validation schema.
This is the core function for defining message types in Zodiac. It creates a message definition that includes both the data schema and the complete message schema with metadata fields.