WS event Zod schemas in packages/shared #38
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
All WebSocket message types need Zod schemas shared between frontend and backend.
What to do
Define Zod schemas for all WebSocket messages as discriminated unions.
Files to create
packages/shared/src/schemas/ws.tspackages/shared/src/index.ts— export new schemas.Message types
Client -> Server:
lobby:join { type, code }lobby:leave { type, lobbyId }lobby:start { type, lobbyId }(host only)game:answer { type, lobbyId, questionId, selectedOptionId }game:buzz { type, lobbyId, questionId }(TV Quiz Show mode)Server -> Client:
lobby:state { type, lobby }— full state with player listlobby:error { type, message }game:question { type, question, questionNumber, totalQuestions }game:answer_result { type, result }— per-round result with scoresgame:finished { type, results, winner }game:eliminated { type, userId }(Elimination mode)game:turn { type, userId }(Chain Link mode)game:buzz_result { type, userId, canAnswer }(TV Quiz Show mode)Acceptance criteria
@lila/sharedWsLobbyJoinSchema,WsGameAnswerSchema, etc.Notes
Reference:
packages/shared/src/schemas/game.ts. Game mode-specific messages can be added incrementally.