UNPKG

bun-ws-router

Version:

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

44 lines 1.58 kB
// SPDX-FileCopyrightText: 2025-present Kriasoft // SPDX-License-Identifier: MIT /** * Typed WebSocket client adapter for Zod 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 Zod 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 { z } from "zod"; * import { createMessageSchema } from "bun-ws-router/zod"; * import { createClient } from "bun-ws-router/zod/client"; * * const { messageSchema } = createMessageSchema(z); * const HelloOk = messageSchema("HELLO_OK", { text: z.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