@ws-kit/bun
Version:
Bun platform adapter for WS-Kit leveraging native WebSocket API with built-in pub/sub and low-latency message routing
28 lines • 1.3 kB
TypeScript
import type { ServerWebSocket } from "@ws-kit/core";
import type { ServerWebSocket as BunServerWebSocket } from "bun";
/**
* Adapts Bun's ServerWebSocket to conform to the core interface.
*
* Bun's ServerWebSocket already implements all required methods and properties,
* so this adapter is primarily for type safety and documentation.
*
* **Note**: This adapter has no runtime overhead—it's purely for TypeScript
* type checking. At runtime, we pass through to Bun's native WebSocket.
*
* This function is for Bun-specific application code. The router itself receives
* platform-specific WebSockets and handles the adaptation internally.
*
* @param ws - Bun's ServerWebSocket instance (can have generic TData)
* @returns The same WebSocket (no-op at runtime) cast to core's non-generic ServerWebSocket
*/
export declare function adaptBunWebSocket<TData = unknown>(ws: BunServerWebSocket<TData>): ServerWebSocket;
/**
* Type guard to check if an object is a Bun ServerWebSocket.
*
* Useful for platform detection or conditional logic.
*
* @param ws - Unknown WebSocket-like object
* @returns true if ws has Bun ServerWebSocket methods
*/
export declare function isBunWebSocket<TData = unknown>(ws: unknown): ws is BunServerWebSocket<TData>;
//# sourceMappingURL=websocket.d.ts.map