From 0235b2c3e610eb859d45271568563e4210e35524 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Tue, 27 Jan 2026 21:03:19 -0500 Subject: [PATCH] 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. --- src/index.ts | 9 +++++++-- src/session.ts | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1e408ee..9b2978f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,10 @@ 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; @@ -9,7 +14,7 @@ function isValidRoomName(name: unknown): name is string { return /^[a-zA-Z0-9_-]+$/.test(name); } -Bun.serve({ +Bun.serve({ port: PORT, fetch(req, server) { const url = new URL(req.url); diff --git a/src/session.ts b/src/session.ts index 6b316eb..b68b8e0 100644 --- a/src/session.ts +++ b/src/session.ts @@ -2,8 +2,13 @@ import type { ServerWebSocket } from "bun"; import * as Y from "yjs"; import { encode } from "./protocol"; +export interface WsData { + room: string | null; + client: Client | null; +} + export interface Client { - ws: ServerWebSocket<{ room: string | null }>; + ws: ServerWebSocket; } export class Session {