UNPKG

rsocket-browser

Version:

Browser-first RSocket client over WebSocket or WebTransport with reconnect and Resume.

39 lines 2.32 kB
/** Browser constructor option adaptation for the shared client facade. */ import { RSocket as ClientRSocket } from "rsocket-client-ts"; /** Client options inferred from the canonical requester constructor. */ type ClientOptions<D, M> = ConstructorParameters<typeof ClientRSocket<D, M>>[0]; /** SETUP options accepted by the canonical requester constructor. */ type ClientSetup<D, M> = NonNullable<ClientOptions<D, M>["setup"]>; /** WebSocket branch of the canonical requester transport union. */ type WebSocketOptions<D, M> = Extract<ClientOptions<D, M>["transport"], { readonly type: "websocket"; }>; /** WebTransport branch of the canonical requester transport union. */ type WebTransportOptions<D, M> = Extract<ClientOptions<D, M>["transport"], { readonly type: "webtransport"; }>; /** Browser-specific SETUP options add a convenient WebSocket factory. */ type BrowserSetup<D, M> = ClientSetup<D, M> & { /** Optional WebSocket subprotocol or ordered preference list. */ readonly protocols?: WebSocketOptions<D, M>["protocols"]; /** Optional `(url, protocols) => WebSocketLike` factory. */ readonly transport?: WebSocketOptions<D, M>["factory"]; }; /** Browser WebSocket factory used by tests and internal constructor adaptation. */ export type RSocketTransportFactory = NonNullable<BrowserSetup<unknown, unknown>["transport"]>; /** User-facing options for `new RSocket(url, options)`. */ export type RSocketOptions<D = unknown, M = unknown> = Omit<ClientOptions<D, M>, "transport" | "setup"> & { /** SETUP frame parameters plus WebSocket-only constructor options. */ readonly setup?: BrowserSetup<D, M>; /** Optional mapping controls used only when the URL selects WebTransport. */ readonly webTransport?: Omit<WebTransportOptions<D, M>, "type" | "url">; }; /** Single-object browser constructor form. */ export type RSocketConstructorOptions<D = unknown, M = unknown> = RSocketOptions<D, M> & { /** WebSocket or WebTransport endpoint URL. */ readonly url: string | URL; }; /** Resolves both browser constructor forms into canonical client options. */ export declare function browserClientOptions<D, M>(urlOrOptions: string | URL | RSocketConstructorOptions<D, M>, fallback: RSocketOptions<D, M>): ClientOptions<D, M>; export {}; //# sourceMappingURL=options.d.ts.map