WS event Zod schemas in packages/shared #38

Open
opened 2026-04-19 07:23:38 +00:00 by forgejo-lila · 0 comments
Owner

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.ts
  • packages/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 list
  • lobby:error { type, message }
  • game:question { type, question, questionNumber, totalQuestions }
  • game:answer_result { type, result } — per-round result with scores
  • game: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

  • All message types have Zod schemas
  • Client-to-server and server-to-client use separate discriminated unions
  • TypeScript types derived and exported
  • Importable from @lila/shared
  • Consistent naming: WsLobbyJoinSchema, WsGameAnswerSchema, etc.

Notes

Reference: packages/shared/src/schemas/game.ts. Game mode-specific messages can be added incrementally.

## 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.ts` - `packages/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 list - `lobby:error { type, message }` - `game:question { type, question, questionNumber, totalQuestions }` - `game:answer_result { type, result }` — per-round result with scores - `game: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 - All message types have Zod schemas - Client-to-server and server-to-client use separate discriminated unions - TypeScript types derived and exported - Importable from `@lila/shared` - Consistent naming: `WsLobbyJoinSchema`, `WsGameAnswerSchema`, etc. ## Notes Reference: `packages/shared/src/schemas/game.ts`. Game mode-specific messages can be added incrementally.
forgejo-lila added the
multiplayer
label 2026-04-19 07:23:38 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: forgejo-lila/lila#38
No description provided.