Define Events
In pluv.io, you can define custom events with an input validation schema and resolver, and have them be automatically type-safe without having to manage your own types.
Usage example
1import { createIO } from "@pluv/io";2import { platformNode } from "@pluv/platform-node";3import { z } from "zod";45export const io = createIO({ platform: platformNode() })6 // When event "SEND_MESSAGE" is sent by the frontend and received7 // on the server8 .event("SEND_MESSAGE", {9 // Define a zod validation schema for the input10 input: z.object({11 message: z.string(),12 }),13 // Emit a "MESSAGE_RECEIVED" from the server to the client14 resolver: ({ message }) => ({ MESSAGE_RECEIVED: { message } }),15 })16 .event("EMIT_EMOJI", {17 input: z.object({18 emojiCode: z.number(),19 }),20 resolver: ({ emojiCode }) => ({ EMOJI_RECEIVED: { emojiCode } }),21 });2223// Export the io type instance of the io itself24export type AppPluvIO = typeof io;