Skip to content

Documentation / @super-line/server / PluginContext

Interface: PluginContext ​

Defined in: index.ts:455

The capabilities handed to a plugin's setup/handlers: the server's public surface minus the footguns (implement/close), plus a privileged block — a plugin-private adapter PluginChannel, node identity, the serializer, a read-only conns view, and the raw contract for reflection. Sized to the inspector's audited needs; grows case-by-case.

Properties ​

cluster ​

readonly cluster: ClusterView

Defined in: index.ts:484

Cluster-wide presence introspection (rejects without a presence-capable adapter).


collectionCoordination? ​

readonly optional collectionCoordination?: "local" | "cluster"

Defined in: index.ts:510

Whether conditional collection writes are serialized locally or cluster-wide.


conns ​

readonly conns: readonly Conn<Record<string, ServerMessageDef>, unknown, string, unknown, unknown>[]

Defined in: index.ts:480

Connections accepted on THIS node (read-only snapshot; excludes reserved conns).


contract ​

readonly contract: Contract

Defined in: index.ts:472

The raw contract, for reflection (e.g. classifyContract).


instanceId ​

readonly instanceId: string

Defined in: index.ts:468

Alias of PluginContext.nodeId — the per-process instance id used to tag cluster fan-out.


local ​

readonly local: LocalView

Defined in: index.ts:482

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


nodeId ​

readonly nodeId: string

Defined in: index.ts:457

This node's stable id (equals srv.nodeId).


nodeKey? ​

readonly optional nodeKey?: string

Defined in: index.ts:461

Stable replica identity supplied by the host, if configured.


nodeName ​

readonly nodeName: string

Defined in: index.ts:459

This node's friendly name (equals srv.nodeName).


plugins ​

readonly plugins: readonly string[]

Defined in: index.ts:478

Names of every plugin registered on this server, in registration order — including this one, and including plugins that contribute no contract fragment. Distinct from contract.plugins, which is the contract-time half (ADR-0016).


ready ​

readonly ready: Promise<void>

Defined in: index.ts:466

Resolves once every transport has started (equals srv.ready). A transport that resumes connections across restarts (ADR-0027) has taken back every surviving one by then, so PluginContext.conns is complete.


serializer ​

readonly serializer: Serializer

Defined in: index.ts:470

The wire serializer configured on the server.

Methods ​

batch() ​

batch(ops): Promise<void>

Defined in: index.ts:506

Apply one atomic, schema-validated server batch across row collections.

Parameters ​

ops ​

ServerCollectionOp[]

Returns ​

Promise<void>


channel() ​

channel(name): PluginChannel

Defined in: index.ts:518

A plugin-private, cluster-wide adapter channel under the reserved x:<plugin>: prefix.

Parameters ​

name ​

string

Returns ​

PluginChannel


collection() ​

collection(name): ServerCollectionHandle

Defined in: index.ts:504

Server-authoritative handle for a contract collection (loosely typed here as the LWW row handle — the surface plugins/inspector use); throws if none is configured.

Parameters ​

name ​

string

Returns ​

ServerCollectionHandle


collectionInfos() ​

collectionInfos(): object[]

Defined in: index.ts:512

Declared collections (name + key + advisory references) for the schema graph.

Returns ​

object[]


conditionalBatch() ​

conditionalBatch(conditions, ops): Promise<boolean>

Defined in: index.ts:508

Atomically apply a server batch only while every stored row still matches its predicate.

Parameters ​

conditions ​

ServerRowCondition[]

ops ​

ServerCollectionOp[]

Returns ​

Promise<boolean>


connectionById() ​

connectionById(id): Promise<ConnDescriptor | undefined>

Defined in: index.ts:516

A connection's descriptor anywhere in the cluster (rejects without presence support); undefined if absent.

Parameters ​

id ​

string

Returns ​

Promise<ConnDescriptor | undefined>


describe() ​

describe(conn): ConnDescriptor

Defined in: index.ts:514

Full cluster descriptor for a local connection (identity + rooms + describeConn extras).

Parameters ​

conn ​

Conn

Returns ​

ConnDescriptor


hold() ​

hold(): () => void

Defined in: index.ts:523

Busy token: declare work in flight on this node that only lives in memory (an open stream, say). A transport whose host can hibernate keeps it awake until every hold is released. Returns the release (idempotent).

Returns ​

() => void


isOnline() ​

isOnline(userId): Promise<boolean>

Defined in: index.ts:486

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

Parameters ​

userId ​

string

Returns ​

Promise<boolean>


publish() ​

publish(topic, data): void

Defined in: index.ts:488

Publish a shared topic (server-only publish).

Parameters ​

topic ​

string

data ​

unknown

Returns ​

void


room() ​

room(name): object

Defined in: index.ts:496

Server-controlled room membership + broadcast (loosely typed, mirroring toConn/toUser).

Parameters ​

name ​

string

Returns ​

object

connections ​

readonly connections: readonly Conn<Record<string, ServerMessageDef>, unknown, string, unknown, unknown>[]

size ​

readonly size: number

add() ​

add(conn): void | Promise<void>

Parameters ​
conn ​

Conn

Returns ​

void | Promise<void>

broadcast() ​

broadcast(event, data): void

Parameters ​
event ​

string

data ​

unknown

Returns ​

void

remove() ​

remove(conn): void

Parameters ​
conn ​

Conn

Returns ​

void


subscribe() ​

subscribe(topic, handler): Unsubscribe

Defined in: index.ts:490

Subscribe server-side to a shared topic, cluster-wide (local echo). Await .ready before publishing from elsewhere.

Parameters ​

topic ​

string

handler ​

(data, meta) => void

Returns ​

Unsubscribe


toConn() ​

toConn(id): object

Defined in: index.ts:492

Target a single connection by id, on whatever node holds it.

Parameters ​

id ​

string

Returns ​

object

close() ​

close(): void

Returns ​

void

emit() ​

emit(event, data): void

Parameters ​
event ​

string

data ​

unknown

Returns ​

void

setEnv() ​

setEnv(env): void

Parameters ​
env ​

unknown

Returns ​

void


toUser() ​

toUser(userId): object

Defined in: index.ts:494

Target all of a user's connections across nodes.

Parameters ​

userId ​

string

Returns ​

object

disconnect() ​

disconnect(): void

Returns ​

void

emit() ​

emit(event, data): void

Parameters ​
event ​

string

data ​

unknown

Returns ​

void

setEnv() ​

setEnv(env): void

Parameters ​
env ​

unknown

Returns ​

void

Released under the MIT License.