Skip to content

Documentation / @super-line/server / PluginContext

Interface: PluginContext

Defined in: index.ts:450

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:474

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


collectionCoordination?

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

Defined in: index.ts:500

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:470

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


contract

readonly contract: Contract

Defined in: index.ts:462

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


instanceId

readonly instanceId: string

Defined in: index.ts:458

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


local

readonly local: LocalView

Defined in: index.ts:472

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


nodeId

readonly nodeId: string

Defined in: index.ts:452

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


nodeKey?

readonly optional nodeKey?: string

Defined in: index.ts:456

Stable replica identity supplied by the host, if configured.


nodeName

readonly nodeName: string

Defined in: index.ts:454

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


plugins

readonly plugins: readonly string[]

Defined in: index.ts:468

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).


serializer

readonly serializer: Serializer

Defined in: index.ts:460

The wire serializer configured on the server.

Methods

batch()

batch(ops): Promise<void>

Defined in: index.ts:496

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

Parameters

ops

ServerCollectionOp[]

Returns

Promise<void>


channel()

channel(name): PluginChannel

Defined in: index.ts:508

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:494

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:502

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

Returns

object[]


conditionalBatch()

conditionalBatch(conditions, ops): Promise<boolean>

Defined in: index.ts:498

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:506

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:504

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

Parameters

conn

Conn

Returns

ConnDescriptor


isOnline()

isOnline(userId): Promise<boolean>

Defined in: index.ts:476

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:478

Publish a shared topic (server-only publish).

Parameters

topic

string

data

unknown

Returns

void


room()

room(name): object

Defined in: index.ts:486

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:480

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:482

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:484

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.