From b3c77eb675ef763c63d5e10f5de403b76ab5361c Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Wed, 3 Dec 2025 23:47:46 +0000 Subject: [PATCH] fix(adapters): Attach WebSocket peer to typedRouter request localData and add ws dependency --- changelog.md | 6 ++++++ package.json | 3 ++- pnpm-lock.yaml | 3 +++ ts/00_commitinfo_data.ts | 2 +- ts/adapters/adapter.bun.ts | 2 ++ ts/adapters/adapter.deno.ts | 2 ++ ts/adapters/adapter.node.ts | 2 ++ 7 files changed, 18 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 1587290..5975030 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ # Changelog +## 2025-12-03 - 1.1.1 - fix(adapters) +Attach WebSocket peer to typedRouter request localData and add ws dependency + +- When routing incoming WebSocket messages through TypedRouter (node/deno/bun), the connection peer is now attached to requestObj.localData so typed handlers can access the active connection. +- Add runtime dependency on "ws" to enable WebSocket support in the Node adapter (used by dynamic import in the adapter). + ## 2025-12-02 - 1.1.0 - feat(websocket) Add TypedRouter WebSocket integration, connection registry, peer tagging and broadcast APIs diff --git a/package.json b/package.json index f2c77fc..2962bc4 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "@push.rocks/lik": "^6.2.2", "@push.rocks/smartenv": "^6.0.0", "@push.rocks/smartlog": "^3.1.10", - "@push.rocks/smartpath": "^6.0.0" + "@push.rocks/smartpath": "^6.0.0", + "ws": "^8.18.0" }, "packageManager": "pnpm@10.18.1+sha512.77a884a165cbba2d8d1c19e3b4880eee6d2fcabd0d879121e282196b80042351d5eb3ca0935fa599da1dc51265cc68816ad2bddd2a2de5ea9fdf92adbec7cd34", "repository": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a6b8539..c326379 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ importers: '@push.rocks/smartpath': specifier: ^6.0.0 version: 6.0.0 + ws: + specifier: ^8.18.0 + version: 8.18.3 devDependencies: '@git.zone/tsbuild': specifier: ^3.1.2 diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 7c4197c..c739440 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartserve', - version: '1.1.0', + version: '1.1.1', description: 'a cross platform server module for Node, Deno and Bun' } diff --git a/ts/adapters/adapter.bun.ts b/ts/adapters/adapter.bun.ts index 14d5f16..2a0c2d5 100644 --- a/ts/adapters/adapter.bun.ts +++ b/ts/adapters/adapter.bun.ts @@ -137,6 +137,8 @@ export class BunAdapter extends BaseAdapter { if (typedRouter && typeof message === 'string') { try { const requestObj = JSON.parse(message); + // Attach peer to localData so TypedHandlers can access the connection + requestObj.localData = { ...requestObj.localData, peer }; const response = await typedRouter.routeAndAddResponse(requestObj); if (response) { peer.send(JSON.stringify(response)); diff --git a/ts/adapters/adapter.deno.ts b/ts/adapters/adapter.deno.ts index 8942a2b..3e18270 100644 --- a/ts/adapters/adapter.deno.ts +++ b/ts/adapters/adapter.deno.ts @@ -115,6 +115,8 @@ export class DenoAdapter extends BaseAdapter { if (typedRouter && typeof event.data === 'string') { try { const requestObj = JSON.parse(event.data); + // Attach peer to localData so TypedHandlers can access the connection + requestObj.localData = { ...requestObj.localData, peer }; const response = await typedRouter.routeAndAddResponse(requestObj); if (response) { peer.send(JSON.stringify(response)); diff --git a/ts/adapters/adapter.node.ts b/ts/adapters/adapter.node.ts index a671bd2..7cb1115 100644 --- a/ts/adapters/adapter.node.ts +++ b/ts/adapters/adapter.node.ts @@ -283,6 +283,8 @@ export class NodeAdapter extends BaseAdapter { try { const messageText = typeof data === 'string' ? data : data.toString('utf8'); const requestObj = JSON.parse(messageText); + // Attach peer to localData so TypedHandlers can access the connection + requestObj.localData = { ...requestObj.localData, peer }; const response = await typedRouter.routeAndAddResponse(requestObj); if (response) { peer.send(JSON.stringify(response));