Skip to content

Documentation / @super-line/client / SuperLineClient

Type Alias: SuperLineClient<C, R> ​

SuperLineClient<C, R> = ClientMethods<C, R> & object

Defined in: index.ts:104

A typed client proxy, narrowed to role R's effective surface (shared ∪ R). Call requests as methods; listen with on; subscribe to topics with subscribe.

Type Declaration ​

connected ​

readonly connected: boolean

Whether the socket is currently open.

env ​

readonly env: EnvHandle<EnvOf<C, R> | null>

The server-vended, client-visible per-connection env (ADR-0012): a reactive handle over the state the server pushed to THIS connection. current is the latest value (null until the first push, or for a role that declares no env); ready resolves after the first push (await it before reading); subscribe fires on every update (rotation, re-scope). Code-only — an agent's runtime reads it and wires the creds into its tool implementations; never expose it to an LLM.

role ​

readonly role: R

This client's role.

close() ​

close(): void

Close the connection and stop reconnecting.

Returns ​

void

collection() ​

collection<N>(name): N extends CrdtCollectionName<C> ? CrdtCollectionHandle<DocOf<C, N>> : CollectionHandle<RowOf<C, N>>

Client-side handle for a contract collection, typed by the contract: an LWW row collection gives a CollectionHandle (subscribe/insert/batch), a CRDT document collection gives a CrdtCollectionHandle (open(id) → reactive doc).

Type Parameters ​

N ​

N extends string

Parameters ​

name ​

N

Returns ​

N extends CrdtCollectionName<C> ? CrdtCollectionHandle<DocOf<C, N>> : CollectionHandle<RowOf<C, N>>

implement() ​

implement(handlers): void

Register handlers answering server→client requests. Throw a SuperLineError for a typed failure.

Parameters ​

handlers ​

ServerHandlers<C, R>

Returns ​

void

on() ​

on<E>(event, handler): () => void

Listen for a server-pushed event. Returns an unsubscribe function.

Type Parameters ​

E ​

E extends string | number | symbol

Parameters ​

event ​

E

handler ​

(data) => void

Returns ​

() => void

onReconnect() ​

onReconnect(cb): () => void

Register a listener fired on each successful reconnect (after the first connect). Post-hoc counterpart of the onReconnect OPTION — for wrapper libraries over an existing client (e.g. plugin-chat's chatClient) whose server-side state is connection-scoped (rooms) and must be re-established after a reconnect. Returns an unregister fn.

Parameters ​

cb ​

() => void

Returns ​

() => void

subscribe() ​

subscribe<T>(topic, handler): Subscription

Subscribe to a topic (auto re-subscribes on reconnect). Await .ready to confirm.

Type Parameters ​

T ​

T extends string | number | symbol

Parameters ​

topic ​

T

handler ​

(data) => void

Returns ​

Subscription

Type Parameters ​

C ​

C extends Contract

R ​

R extends RoleOf<C>

Released under the MIT License.