Documentation / @super-line/core / RelayCollectionStore
Interface: RelayCollectionStore
Defined in: packages/core/src/collections.ts:100
A node-local replica. Core relays each batch across nodes over the Adapter and re-ingests remote batches through RelayCollectionStore.apply, so every node converges to the same rows.
Extends
CollectionStoreBase
Properties
clustering
readonlyclustering:"relay"
Defined in: packages/core/src/collections.ts:101
coordination
readonlycoordination:"local"
Defined in: packages/core/src/collections.ts:102
Methods
apply()
apply(
ops,origin):RowChange[]
Defined in: packages/core/src/collections.ts:118
See CollectionStore for the shared atomicity / error / timestamp contract. In relay mode apply also fires onChange once per resulting change before returning, and returns those changes.
The non-void return type is load-bearing — do not "simplify" it to void. It is the only thing making an async implementation a compile error, and that is the invariant which keeps a relayed write from echo-storming the cluster: the relay ingress fires-and-forgets (void apply(...)) so it can absorb a cross-node race in a try/catch, and the CRDT sibling clears a re-publish guard in finally. An async apply escapes that catch and clears that guard before the change is ever emitted. TypeScript's void-return rule accepts a function returning anything where void is declared, so apply(): void would silently permit async apply() again. RowChange[] does not.
(collections-crdt-libsql had to discover this constraint on its own — sync hot path, debounced onChange persistence — back when it lived only in prose. Now the compiler holds it.)
Parameters
ops
origin
string
Returns
close()?
optionalclose():Awaitable<void>
Defined in: packages/core/src/collections.ts:93
Release any resources held by the backend.
Returns
Awaitable<void>
Inherited from
CollectionStoreBase.close
conditionalApply()
conditionalApply(
conditions,ops,origin):boolean
Defined in: packages/core/src/collections.ts:120
Atomically check every condition and apply ops; returns false without changing anything when one is stale.
Parameters
conditions
ops
origin
string
Returns
boolean
count()?
optionalcount(n,filter):Awaitable<number>
Defined in: packages/core/src/collections.ts:67
Rows of n matching filter (all rows when undefined), without materializing them. Absent ⇒ the server counts a snapshot.
Parameters
n
string
filter
Expr | undefined
Returns
Awaitable<number>
Inherited from
CollectionStoreBase.count
countBy()?
optionalcountBy(n,field,filter):Awaitable<ValueCount[]>
Defined in: packages/core/src/collections.ts:69
Every group of field over filter, unordered, as core's countValues forms them. Absent ⇒ the server groups a snapshot.
Parameters
n
string
field
string
filter
Expr | undefined
Returns
Awaitable<ValueCount[]>
Inherited from
CollectionStoreBase.countBy
fixedFields()?
optionalfixedFields(n): readonlystring[]
Defined in: packages/core/src/collections.ts:83
Fields of collection n whose value never changes for a key. An update without prev otherwise reaches every subscriber, a non-matching one as a data-less delete; the server skips a subscriber whose filter rules the new row out on these fields, since no version of the row ever matched it. Absent ⇒ none.
Parameters
n
string
Returns
readonly string[]
Inherited from
CollectionStoreBase.fixedFields
onChange()
onChange(
cb): () =>void
Defined in: packages/core/src/collections.ts:91
Subscribe to every applied row change across all collections — core's single fan-out source. Returns an unsubscribe fn. Who fires it depends on the mode: a RelayCollectionStore fires it from apply; a SelfCollectionStore fires it from its replication feed instead. That difference is the one thing this seam cannot state in its types (the signature is identical either way), so it is stated here and pinned by the conformance suite.
Parameters
cb
(change) => void
Returns
() => void
Inherited from
CollectionStoreBase.onChange
read()
read(
n,id):unknown
Defined in: packages/core/src/collections.ts:71
Read one row by primary key — for write-policy prev and advisory FK checks. Undefined if absent.
Parameters
n
string
id
string
Returns
unknown
Inherited from
CollectionStoreBase.read
rowMeta()?
optionalrowMeta(n,ids):Awaitable<Record<string,RowTimestamps>>
Defined in: packages/core/src/collections.ts:77
Inspector-only: per-row RowTimestamps keyed by row id, for ids in collection n. The client subscribe path never sees these (rows stay exactly your schema) — timestamps are surfaced solely by the Control Center. Absent ⇒ the backend doesn't track row timestamps; the inspector shows no created/updated.
Parameters
n
string
ids
string[]
Returns
Awaitable<Record<string, RowTimestamps>>
Inherited from
CollectionStoreBase.rowMeta
snapshot()
snapshot(
n,query):Awaitable<unknown[]>
Defined in: packages/core/src/collections.ts:65
Materialize a collection's snapshot for the initial subscribe: filter → sort → offset/limit (core injects the policy filter).
Parameters
n
string
query
Returns
Awaitable<unknown[]>
Inherited from
CollectionStoreBase.snapshot