Documentation / @super-line/core
@super-line/core
Shared core for super-line — a strictly-typed realtime data bus for TypeScript: one contract for every pattern on the wire (requests · events · subscriptions · synced state). This package holds the pieces both ends import: defineContract, runtime validation, the SuperLineError model, the wire Frame protocol, the Serializer / Adapter interfaces, and the transport and Store seams the rest of the ecosystem plugs into.
pnpm add @super-line/core zodimport * as z from 'zod'
import { defineContract } from '@super-line/core'
export const api = defineContract({
shared: {
serverToClient: { message: { payload: z.object({ text: z.string() }) } },
},
roles: {
user: {
clientToServer: {
send: { input: z.object({ text: z.string() }), output: z.object({ id: z.string() }) },
},
},
},
})The contract is split by direction (clientToServer / serverToClient) and scoped by role, then implemented by @super-line/server and called by @super-line/client.
Transport seam
The client↔server wire is a pluggable transport — WebSocket is just the default. Core owns the Frame protocol and serializer; a transport only carries opaque bytes over a logical connection and hides physical churn (reconnects, SSE's dual channel, libp2p signaling). The interfaces live here so every transport package implements the same contract:
RawConn— a live logical connection (send/writable/onMessage/onClose/onDrain/close/terminate); symmetric across server and client.Handshake— the normalized connect payload handed toauthenticate(transport,headers,query, optionalpeer,rawescape hatch), replacing the rawIncomingMessage.ServerTransport—start({ authenticate, onConnection })/stop(); authenticates at its native moment and surfaces only accepted connections.ClientTransport—connect(handshakeParams, hooks)→RawConn.
Implementations: @super-line/transport-websocket (default), /transport-http (SSE / long-poll), /transport-libp2p, and /transport-loopback (in-memory, for tests).
Persisted state — collections
Persisted, synced state ships as collections — declared on the contract and validated on every write: typed rows (CollectionStore: /collections-memory, /collections-sqlite, /collections-pglite) and CRDT documents (CrdtCollectionStore: /collections-crdt-memory, /collections-crdt-libsql, /collections-crdt-pglite). Collections retired the legacy off-contract store(n) family.
Core retains three small primitives the CRDT client DocHandle reuses:
StoreChange— the opaque change envelope core relays between the doc replica halves without parsing ({ id, update, origin }).ResourceReplica— the reactive local-replica shape (set/update/delete(path)/applyRemote/seed/reset/applyDelete).removeAtPath(root, path)— surgical, merge-friendly key removal.📖 Docs: https://super-line.dogar.biz/
📚 The contract model: https://super-line.dogar.biz/concepts/the-contract
🧩 Source: https://github.com/mertdogar/super-line
MIT © Mert
Classes
Interfaces
- Adapter
- CBatchFrame
- CChangeFrame
- CDChangeFrame
- CDCloseFrame
- CDDeleteFrame
- CDOpenFrame
- CDWriteFrame
- ClientTapRecord
- ClientTransport
- CollectionInfo
- CollectionQuery
- ColumnPlan
- ColumnSpec
- ConnDescriptor
- ConnView
- Contract
- ContractFragment
- ContractPlugin
- CrdtCollectionClient
- CrdtCollectionDef
- CrdtCollectionStore
- CrdtServerReplica
- CSubFrame
- CUnsubFrame
- Directional
- DocChange
- DocListOpts
- DocOptions
- DocSummary
- EnableLoggingOptions
- EnvFrame
- ErrFrame
- EvtFrame
- Handshake
- InspectedContract
- InspectedContribution
- InspectedDirectional
- InspectedMessage
- InspectedPlugin
- InspectorEnvelope
- LwwCollectionDef
- MessageError
- NodeStat
- NodeView
- OrderBy
- PingFrame
- PongFrame
- PresenceStore
- PubFrame
- RawConn
- RelayCollectionStore
- ReqFrame
- RequestDef
- ReservedConnection
- ResFrame
- ResourceReplica
- RoleBlock
- RowChange
- RowCondition
- RowTimestamps
- SelfCollectionStore
- Serializer
- SErrFrame
- ServerMessageDef
- ServerRequestDef
- ServerTransport
- SReqFrame
- SResFrame
- StoreChange
- SubFrame
- UnsubFrame
Type Aliases
- AnyData
- AnyEnv
- AuthOutcome
- ClientFrame
- ClientInput
- ClientTapEvent
- CollectionDef
- CollectionName
- CollectionRow
- CollectionRowInput
- CollectionsOf
- CollectionStore
- ColumnKind
- ConnPhase
- CrdtCollectionName
- CtsOf
- DataOf
- DocOf
- EmitData
- EnvOf
- ErrorCode
- EventData
- Events
- Expr
- Frame
- FrameDirection
- InferIn
- InferOut
- InspectorEvent
- LwwCollectionName
- MessageFlavor
- Output
- RequestDropReason
- Requests
- ResolveContract
- ResolvedRowOp
- RoleOf
- RoleRequests
- RoleTopics
- RouteDecision
- RowInputOf
- RowOf
- RowOp
- Scalar
- Schema
- SchemaConverter
- ServerEntry
- ServerFrame
- ServerInput
- ServerMessages
- ServerRequests
- SharedEvents
- SharedRequests
- SharedServerRequests
- SharedTopics
- SuperLineErrorCode
- TapEvent
- Topics
Variables
- DEGENERATE_DATA_COLUMN
- INSPECTOR_ROLE
- INSPECTOR_SUBPROTOCOL
- InspectorContract
- jsonSerializer
- LOG_ROOT
- PROTOCOL
- ROW_CREATED_AT
- ROW_UPDATED_AT
- SUPER_LINE_REDACT_FIELDS
- VERSION