$ show tsrpc/tsrpc
TSRPC is a TypeScript RPC framework designed for building type-safe, high-performance client-server applications. It provides both HTTP and WebSocket transports with optional JSON compatibility. The framework is built on a custom binary serialization algorithm (TSBuffer) that supports advanced TypeScript type features like union types, intersection types, and mapped types, eliminating the need for external IDL languages. TSRPC includes a rich middleware system called Flows, allowing interception and transformation of data at various stages of request/response processing. The core architecture is abstract and extensible: BaseServer, BaseConnection, and BaseCall form the foundation, with concrete implementations for HTTP (HttpServer, HttpConnection, ApiCallHttp) and WebSocket (WsServer, WsConnection, ApiCallWs). The client side mirrors this with HttpClient and WsClient that handle protocol encoding/decoding, timeouts, and automatic request aborting. The framework also supports server-to-client messages, broadcasting, heartbeat management, and graceful shutdown. With over 1900 GitHub stars and an active maintenance history (latest version 3.4.21), the codebase demonstrates solid engineering practices: comprehensive test coverage across multiple transport modes (HTTP, HTTPS, WS, WSS, both binary and JSON), clean separation of concerns, and robust error handling. The repository includes benchmarking tools and integration tests that verify correctness under various conditions.
The LLM identified 2 files worth highlighting for reuse:
A generic, reusable object pool class that allows creation and recycling of objects to reduce garbage collection pressure. It supports enabling/disabling the pool, and lifecycle hooks (reuse and unuse) for resetting state. The implementation is self-contained, relying only on a simple PoolItem interface, and can be extracted into any TypeScript project needing object pooling.
A logger decorator that prepends dynamic prefixes (strings or functions) to every log message. It implements the standard Logger interface (debug, log, warn, error) and delegates to an underlying logger. This pattern is cleanly isolated and can be reused in any application that needs contextual logging without modifying existing logger implementations.