Skip to content

Documentation / @super-line/server / composeCollections

Function: composeCollections() ​

composeCollections(backends): CollectionStore

Defined in: collections/compose.ts:46

Serve some collections from another backend: one CollectionStore over several, routed by collection name. snapshot/count/countBy/read/rowMeta/fixedFields go to the collection's backend (else default), onChange fans in from every backend, close closes them all. Atomicity is per backend, so a batch must stay inside one: a batch spanning two throws VALIDATION before anything is applied.

The composite is self only when every backend is — the server then never relays, which a node-local relay backend needs to converge. Any mix is relay, and its self collections are read-only through it (FORBIDDEN): a relay apply must be synchronous and return its changes, and the server re-applies every committed batch on every node, so a write into a backend that propagates itself would land once per node. Snapshots, reads and the backend's own feed need neither, so they route as usual.

Give each backend only the collections it serves. One that lays out storage per collection opens a table for every collection it is handed, so leave the routed ones out of default:

ts
const { storeRows: _, ...owned } = contract.collections
composeCollections({ default: cloudflareCollections(ctx.storage, owned), storeRows: remoteRows({ ... }) })

The server refuses to start when a name other than default is not a row collection on its contract.

Parameters ​

backends ​

ComposedCollections

Returns ​

CollectionStore

Released under the MIT License.