Fix websocket data type for room and client storage

Add WsData interface to properly type the websocket data object that
stores room name and client reference. This fixes type errors where
ws.data was previously untyped and causing compilation failures.
This commit is contained in:
Jared Miller 2026-01-27 21:03:19 -05:00
parent 100cd67823
commit 0235b2c3e6
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 13 additions and 3 deletions

View file

@ -1,5 +1,10 @@
import { decode } from "./protocol"; import { decode } from "./protocol";
import { type Client, getOrCreateSession, getSession } from "./session"; import {
type Client,
type WsData,
getOrCreateSession,
getSession,
} from "./session";
const PORT = Number(process.env.PORT) || 4040; const PORT = Number(process.env.PORT) || 4040;
@ -9,7 +14,7 @@ function isValidRoomName(name: unknown): name is string {
return /^[a-zA-Z0-9_-]+$/.test(name); return /^[a-zA-Z0-9_-]+$/.test(name);
} }
Bun.serve({ Bun.serve<WsData>({
port: PORT, port: PORT,
fetch(req, server) { fetch(req, server) {
const url = new URL(req.url); const url = new URL(req.url);

View file

@ -2,8 +2,13 @@ import type { ServerWebSocket } from "bun";
import * as Y from "yjs"; import * as Y from "yjs";
import { encode } from "./protocol"; import { encode } from "./protocol";
export interface WsData {
room: string | null;
client: Client | null;
}
export interface Client { export interface Client {
ws: ServerWebSocket<{ room: string | null }>; ws: ServerWebSocket<WsData>;
} }
export class Session { export class Session {