From 8dbc214e6f2a01cb23a772af025e4a1e6ccc18e5 Mon Sep 17 00:00:00 2001 From: nvms Date: Wed, 4 Sep 2024 10:49:32 -0400 Subject: [PATCH] allow typing on the callback return value for registerCommand --- packages/express-keepalive-ws/bun.lockb | Bin 78303 -> 78303 bytes packages/keepalive-ws/src/server/index.ts | 8 +++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/express-keepalive-ws/bun.lockb b/packages/express-keepalive-ws/bun.lockb index fcd346b2111630c6eb27167bac2b6bc6cb04c8c8..21fcf7d629cd6823088343c6b721c6bf46837de5 100755 GIT binary patch delta 152 zcmV;J0B8T-;{@O11duKuofT!yzsbfA-zOQvhPG12>Xv?oT~M@o17>WBkiKaO^SG4q)>7#n6pFb|%ySfpvw%%p|?I z4uJ9>@7?&whw7Xb#lx(vtPuz$H0ssI2000295ZEFd0XLJu_8+rS G^o>1dH%ylR delta 148 zcmV;F0Bir>;{@O11duKuX}oMcbUW`7^ITLRdv52Um1x6%v@!gBxproe-VSqCu}+E& zlh`pZvj`65KtMG^%W6_i9~HTiS-cvM)*QLQ*k_W6uX^0PvfUMzC1mvjzpN16s5ZEFd0XCDt_8+rS^o>24 Ch(yQ$ diff --git a/packages/keepalive-ws/src/server/index.ts b/packages/keepalive-ws/src/server/index.ts index c4a37c9..b939a6b 100644 --- a/packages/keepalive-ws/src/server/index.ts +++ b/packages/keepalive-ws/src/server/index.ts @@ -130,7 +130,9 @@ export type KeepAliveServerOptions = ServerOptions & { export class KeepAliveServer extends WebSocketServer { connections: { [id: string]: Connection } = {}; remoteAddressToConnections: { [address: string]: Connection[] } = {}; - commands: { [command: string]: (context: WSContext) => Promise } = {}; + commands: { + [command: string]: (context: WSContext) => Promise | any; + } = {}; globalMiddlewares: SocketMiddleware[] = []; middlewares: { [key: string]: SocketMiddleware[] } = {}; rooms: { [roomName: string]: Set } = {}; @@ -330,9 +332,9 @@ export class KeepAliveServer extends WebSocketServer { this.rooms[roomName] = new Set(); } - registerCommand( + registerCommand( command: string, - callback: SocketMiddleware, + callback: (context: WSContext) => Promise | T, middlewares: SocketMiddleware[] = [], ) { this.commands[command] = callback;