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({6 platform: platformNode(),7})8 // When event "SEND_MESSAGE" is sent by the frontend and received9 // on the server10 .event("SEND_MESSAGE", {11 // Define a zod validation schema for the input12 input: z.object({13 message: z.string(),14 }),15 // Emit a "MESSAGE_RECEIVED" from the server to the client16 resolver: ({ message }) => ({ MESSAGE_RECEIVED: { message } }),17 })18 .event("EMIT_EMOJI", {19 input: z.object({20 emojiCode: z.number(),21 }),22 resolver: ({ emojiCode }) => ({ EMOJI_RECEIVED: { emojiCode } }),23 });2425// Export the io type instance of the io itself26export type AppPluvIO = typeof io;