Skip to content

Documentation / @super-line/server / SuperLineServer

Interface: SuperLineServer<C, A, HK>

Defined in: index.ts:587

A running super-line server, returned by createSuperLineServer.

Type Parameters

C

C extends Contract

A

A extends AuthResult<C>

HK

HK extends string = never

Properties

cluster

readonly cluster: ClusterView

Defined in: index.ts:597

Asynchronous, cluster-wide introspection backed by the adapter's presence directory.


local

readonly local: LocalView

Defined in: index.ts:595

Synchronous, node-local introspection (connections, rooms, topics on this process).


nodeId

readonly nodeId: string

Defined in: index.ts:589

This node's stable id (unique per server process).


nodeKey?

readonly optional nodeKey?: string

Defined in: index.ts:593

Stable replica identity supplied by the host, if configured.


nodeName

readonly nodeName: string

Defined in: index.ts:591

This node's friendly name (from nodeName/SUPER_LINE_NODE_NAME, else a short nodeId slice).


ready

readonly ready: Promise<void>

Defined in: index.ts:640

Resolves once everything construction started has landed: the reply channel is subscribed and every transport has finished start(). Rejects if one of them failed.

createSuperLineServer is synchronous, so a node can be handed back before it is listening — which is real for a transport whose start is async (libp2p awaits node.handle), and harmless for one where the host owns the socket (a WebSocket transport over your own http.Server). Await this before dialing a server you just built.

Methods

close()

close(): Promise<void>

Defined in: index.ts:641

Returns

Promise<void>


collection()

collection<N>(name): N extends CrdtCollectionName<C> ? ServerCrdtCollectionHandle<DocOf<C, N>> : ServerCollectionHandle<RowOf<C, N>>

Defined in: index.ts:628

Server-authoritative handle for a contract collection, typed by the contract: an LWW row collection gives ServerCollectionHandle (insert/update/delete), a CRDT document collection gives ServerCrdtCollectionHandle (create/open). Throws NOT_FOUND if no matching backend is configured or the name isn't declared.

Type Parameters

N

N extends string

Parameters

name

N

Returns

N extends CrdtCollectionName<C> ? ServerCrdtCollectionHandle<DocOf<C, N>> : ServerCollectionHandle<RowOf<C, N>>


forRole()

forRole<R>(role): RoleLens<C, R>

Defined in: index.ts:621

Lens for role-scoped sends, e.g. forRole('user').publish('feed', data).

Type Parameters

R

R extends string

Parameters

role

R

Returns

RoleLens<C, R>


implement()

implement(handlers): SuperLineServer<C, A, HK>

Defined in: index.ts:605

Register handlers for shared + per-role requests (chainable). Keys handled by a plugin (HK) are subtracted.

Parameters

handlers

SubtractHandlers<Handlers<C, A>, HK>

Returns

SuperLineServer<C, A, HK>


isOnline()

isOnline(userId): Promise<boolean>

Defined in: index.ts:599

Whether a user (by identify key) has at least one live connection anywhere.

Parameters

userId

string

Returns

Promise<boolean>


publish()

publish<T>(topic, data): void

Defined in: index.ts:609

Publish a SHARED topic to all subscribers (server-only publish).

Type Parameters

T

T extends string | number | symbol

Parameters

topic

T

data

EmitData<TopicsOf<StcOf<C["shared"]>>[T]>

Returns

void


room()

room(name): Room<C>

Defined in: index.ts:607

Mixed-role connection group; broadcast() sends a shared contract event to members.

Parameters

name

string

Returns

Room<C>


subscribe()

subscribe<T>(topic, handler): Unsubscribe

Defined in: index.ts:616

Subscribe SERVER-side to a shared topic, cluster-wide. The callback fires for a publish from any node — including this one (local echo, delivered in-process with no round-trip). meta.from is the publishing node; self-exclude with if (meta.from === srv.nodeId) return. Returns an unsubscribe fn.

Type Parameters

T

T extends string | number | symbol

Parameters

topic

T

handler

(data, meta) => void

Returns

Unsubscribe


toConn()

toConn(id): ConnTarget<C>

Defined in: index.ts:601

Target a single connection by id, on whatever node holds it (cross-node emit/close).

Parameters

id

string

Returns

ConnTarget<C>


toUser()

toUser(userId): UserTarget<C>

Defined in: index.ts:603

Target all of a user's connections (by identify key) across nodes (emit/disconnect).

Parameters

userId

string

Returns

UserTarget<C>

Released under the MIT License.