Zodiac API Documentation - v0.0.3
    Preparing search index...

    Interface MessageDefinition<T>

    const userMessage: MessageDefinition<{name: string}> = defineMessage(
    'user-message',
    z.object({ name: z.string() })
    );

    // Access the components
    console.log(userMessage.id); // 'user-message'
    userMessage.schema.parse({ name: 'Alice' }); // Validates just the data
    userMessage.messageSchema.parse({
    id: 'user-message',
    data: { name: 'Alice' },
    timestamp: Date.now()
    }); // Validates complete message
    interface MessageDefinition<T> {
        id: string;
        schema: ZodType<T>;
        messageSchema: ZodObject<
            {
                id: ZodLiteral<string>;
                data: ZodType<T>;
                timestamp: ZodOptional<ZodNumber>;
            },
        >;
    }

    Type Parameters

    • T

      The TypeScript type inferred from the Zod schema

    Index

    Properties

    id: string

    The unique message type identifier

    schema: ZodType<T>

    Zod schema for validating message data

    messageSchema: ZodObject<
        {
            id: ZodLiteral<string>;
            data: ZodType<T>;
            timestamp: ZodOptional<ZodNumber>;
        },
    >

    Zod schema for validating the complete message structure