UNPKG

bun-ws-router

Version:

Lightweight client/server WebSocket router for Bun with type-safe Zod/Valibot validation.

44 lines 1.6 kB
// SPDX-FileCopyrightText: 2025-present Kriasoft // SPDX-License-Identifier: MIT /** * Typed WebSocket client adapter for Valibot schemas. * * Provides full type inference for message handlers via type override pattern (ADR-002). * Zero runtime overhead - pure type-level wrapper around generic client. * * @see specs/adrs.md#ADR-002 - Type override rationale * @see specs/client.md - Client API specification */ import { createClient as createGenericClient } from "../client/index.js"; // Re-export base types and error classes export * from "../client/types.js"; /** * Create typed WebSocket client with Valibot schema inference. * * Pure type cast - zero runtime overhead compared to generic client. * All type safety is compile-time only via TypeScript inference. * * @example * ```typescript * import * as v from "valibot"; * import { createMessageSchema } from "bun-ws-router/valibot"; * import { createClient } from "bun-ws-router/valibot/client"; * * const { messageSchema } = createMessageSchema(v); * const HelloOk = messageSchema("HELLO_OK", { text: v.string() }); * * const client = createClient({ url: "wss://api.example.com" }); * * client.on(HelloOk, (msg) => { * // ✅ msg fully typed: { type: "HELLO_OK", meta: {...}, payload: { text: string } } * console.log(msg.payload.text.toUpperCase()); * }); * ``` * * @see specs/client.md - Full client API documentation * @see specs/adrs.md#ADR-002 - Type override implementation details */ export function createClient(opts) { return createGenericClient(opts); } //# sourceMappingURL=client.js.map