fix(adapters): Attach WebSocket peer to typedRouter request localData and add ws dependency

This commit is contained in:
2025-12-03 23:47:46 +00:00
parent 7b8a4ba68c
commit b3c77eb675
7 changed files with 18 additions and 2 deletions

View File

@@ -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

View File

@@ -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": {

3
pnpm-lock.yaml generated
View File

@@ -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

View File

@@ -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'
}

View File

@@ -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));

View File

@@ -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));

View File

@@ -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));