How undefinedofficial/u-connect-client-ts works
Project Type and Purpose
• This is a client SDK library (u-connect/client-ts) for performing RPC over WebSockets using MessagePack.
• It exposes a UConnectClient facade to your app, supports four RPC modes (Unary, ServerStream, ClientStream, DuplexStream), and is shipped as an npm package.
File Structure
Top-level:
• config & tooling: .eslintrc.cjs, .prettierrc.json, tsconfig*.json, vite.config.ts
• build output: dist/ (contains compiled JS and type declarations)
• example/: a Vue 3 sample app consuming the library
• u-connect/: core TypeScript modules
Inside u-connect/:
• Interfaces: IConnection.ts, ILogger.ts, ISerializer.ts, IUConnectClient.ts, IUniqueIdProvider.ts
• Core classes: ClientStream.ts, ServerStream.ts, Emitter.ts, PromiceValue.ts, Service.ts, UConnectClient (index.ts)
• Supporting modules: DataType.ts, Exceptions.ts, Status.ts
Others:
• env.d.ts, example shims, package.json and lock files
Extract Key Architecture Insights from README
• The “UConnectClient” is the main entrypoint—composes a Connection + Logger + Serializer.
• RPC modes map to four stream types, each with a well-defined interface.
• Default transport is WebSocket, default serialization is MessagePack.
• The example demonstrates integration in a Vue SPA.
Main Components
a. Client Application
b. UConnectClient Facade
c. Connection Layer (IConnection implementation, e.g. WebSocketConnection)
d. Serializer Layer (MessagePack via ISerializer)
e. Logger (ConsoleLogger implementing ILogger)
f. Service Facade (Service.ts, exposes .unary(), .serverStream(), etc.)
g. Stream Handlers:
– UnaryRequest / UnaryResponse
– ServerStream
– ClientStream
– DuplexStream
h. Internal Utilities:
– Emitter (event bus)
– PromiceValue (promise wrapper)
– UniqueIdProvider (message IDs)
i. External Service: u-connect Server (not in repo, shown as external)
Relationships & Data Flow
• The App invokes UConnectClient.service("ServiceName") → returns a Service proxy.
• Service methods (unary/serverStream/…) call into Service.ts, which:
1) Generates a unique request ID (IUniqueIdProvider)
2) Serializes method name, params via ISerializer
3) Dispatches payload to IConnection.send()
4) Uses Emitter to route incoming messages back to the correct Stream handler or Promise
• IConnection maintains an open WebSocket, handles reconnect logic
• Streams push data to the App via callbacks (.onMessage, .onError, .onEnd)
Architectural Patterns & Principles
• Facade: UConnectClient & Service.ts hide complex stream logic
• Adapter: IConnection allows swapping WebSocket implementations
• Strategy: ISerializer lets you choose MessagePack or a custom serializer
• Observer/Event-Emitter: internal Emitter dispatches messages to handlers
• Promise-based & event-driven concurrency
Technologies & Frameworks
• TypeScript (source in u-connect/, builds to dist/)
• WebSocket API (browser or ws in Node.js)
• MessagePack binary protocol (default serializer)
• Example Vue 3 SPA