import { PublicState } from "./public-state"; /** * WebSocket Protocol Definitions * * This file defines the complete WebSocket message protocol for real-time * poker game communication. All messages are strongly typed discriminated unions. */ /** * Join a table's real-time updates */ export interface JoinTableMessage { readonly type: "JOIN"; readonly tableId: string; readonly requestId?: string; } /** Leave a table's real-time updates. */ export interface LeaveTableMessage { readonly type: "LEAVE"; readonly tableId: string; readonly requestId?: string; } /** * Application-level heartbeat (in addition to WebSocket ping/pong) * Useful for detecting issues at application layer */ export interface PingMessage { readonly type: "PING"; readonly requestId: string; readonly timestamp?: number; } /** * Union of all client-to-server messages */ export type ClientMessage = JoinTableMessage | LeaveTableMessage | PingMessage; /** * State snapshot sent when client joins a table * or when requested via REST API */ export interface SnapshotMessage { readonly type: "SNAPSHOT"; readonly tableId: string; readonly state: PublicState; readonly version: number; readonly timestamp: number; } /** * Lightweight notification that state has changed * Client should fetch full state via REST if needed */ export interface StateUpdateMessage { readonly type: "STATE_UPDATE"; readonly tableId: string; readonly version: number; readonly timestamp: number; } /** * Error message */ export interface ErrorMessage { readonly type: "ERROR"; readonly code: string; readonly message: string; readonly requestId?: string; /** Additional error context. */ readonly context?: Record; } /** * Acknowledgment of successful operation */ export interface AckMessage { readonly type: "ACK"; readonly requestId: string; readonly message?: string; } /** * Pong response to client PING */ export interface PongMessage { readonly type: "PONG"; readonly requestId: string; readonly timestamp: number; } /** * Player action notification (informational only) * Not required for state sync, but useful for animations/UX */ export interface ActionNotificationMessage { readonly type: "ACTION"; readonly tableId: string; readonly playerId: string; readonly actionType: string; readonly amount?: number; readonly timestamp: number; } /** * Union of all server-to-client messages */ export type ServerMessage = SnapshotMessage | StateUpdateMessage | ErrorMessage | AckMessage | PongMessage | ActionNotificationMessage; export declare function isClientMessage(msg: unknown): msg is ClientMessage; export declare function isJoinMessage(msg: ClientMessage): msg is JoinTableMessage; export declare function isLeaveMessage(msg: ClientMessage): msg is LeaveTableMessage; export declare function isPingMessage(msg: ClientMessage): msg is PingMessage; export declare function isServerMessage(msg: unknown): msg is ServerMessage; import { z } from "zod"; export declare const JoinTableMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"JOIN">; tableId: z.ZodString; requestId: z.ZodOptional; }, z.core.$strip>; export declare const LeaveTableMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"LEAVE">; tableId: z.ZodString; requestId: z.ZodOptional; }, z.core.$strip>; export declare const PingMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"PING">; requestId: z.ZodString; timestamp: z.ZodOptional; }, z.core.$strip>; export declare const ClientMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodLiteral<"JOIN">; tableId: z.ZodString; requestId: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"LEAVE">; tableId: z.ZodString; requestId: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"PING">; requestId: z.ZodString; timestamp: z.ZodOptional; }, z.core.$strip>], "type">; /** * Utility to parse and validate a client message */ export declare function parseClientMessage(data: unknown): ClientMessage; /** * Safe parser that returns result object instead of throwing */ export declare function safeParseClientMessage(data: unknown): { success: true; data: ClientMessage; } | { success: false; error: z.ZodError; }; export declare const SnapshotMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"SNAPSHOT">; tableId: z.ZodString; state: z.ZodRecord; version: z.ZodNumber; timestamp: z.ZodNumber; }, z.core.$strip>; export declare const StateUpdateMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"STATE_UPDATE">; tableId: z.ZodString; version: z.ZodNumber; timestamp: z.ZodNumber; }, z.core.$strip>; export declare const ErrorMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"ERROR">; code: z.ZodString; message: z.ZodString; requestId: z.ZodOptional; context: z.ZodOptional>; }, z.core.$strip>; export declare const AckMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"ACK">; requestId: z.ZodString; message: z.ZodOptional; }, z.core.$strip>; export declare const PongMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"PONG">; requestId: z.ZodString; timestamp: z.ZodNumber; }, z.core.$strip>; export declare const ActionNotificationMessageSchema: z.ZodObject<{ type: z.ZodLiteral<"ACTION">; tableId: z.ZodString; playerId: z.ZodString; actionType: z.ZodString; amount: z.ZodOptional; timestamp: z.ZodNumber; }, z.core.$strip>; export declare const ServerMessageSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ type: z.ZodLiteral<"SNAPSHOT">; tableId: z.ZodString; state: z.ZodRecord; version: z.ZodNumber; timestamp: z.ZodNumber; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"STATE_UPDATE">; tableId: z.ZodString; version: z.ZodNumber; timestamp: z.ZodNumber; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"ERROR">; code: z.ZodString; message: z.ZodString; requestId: z.ZodOptional; context: z.ZodOptional>; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"ACK">; requestId: z.ZodString; message: z.ZodOptional; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"PONG">; requestId: z.ZodString; timestamp: z.ZodNumber; }, z.core.$strip>, z.ZodObject<{ type: z.ZodLiteral<"ACTION">; tableId: z.ZodString; playerId: z.ZodString; actionType: z.ZodString; amount: z.ZodOptional; timestamp: z.ZodNumber; }, z.core.$strip>], "type">; /** * Parse and validate a server message (throws on invalid) */ export declare function parseServerMessage(data: unknown): ServerMessage; /** * Safe parser for server messages */ export declare function safeParseServerMessage(data: unknown): { success: true; data: ServerMessage; } | { success: false; error: z.ZodError; };