SyncState
Defined in: packages/@livestore/common/dist/sync/syncstate.d.ts:92
SyncState represents the current sync state of a sync node relative to an upstream node. Events flow from local to upstream, with each state maintaining its own event head.
Example:
+------------------------+ | PENDING EVENTS | +------------------------+ ▼ ▼ Upstream Head Local Head e1 e1.1, e1.2, e2Pending Events: Events awaiting acknowledgment from the upstream.
- Can be confirmed or rejected by the upstream.
- Subject to rebase if rejected.
Payloads:
PayloadUpstreamRebase: Upstream has performed a rebase, so downstream must roll back to the specified event and rebase the pending events on top of the new events.PayloadUpstreamAdvance: Upstream has advanced, so downstream must rebase the pending events on top of the new events.PayloadLocalPush: Local push payload
Invariants:
- Chain Continuity: Each event must reference its immediate parent.
- Head Ordering: Upstream Head ≤ Local Head.
- Event number sequence: Must follow the pattern e1→e1.1→e1.2→e2.
A few further notes to help form an intuition:
- The goal is to keep the pending events as small as possible (i.e. to have synced with the next upstream node)
- There are 2 cases for rebasing:
- The conflicting event only conflicts with the pending events -> only (some of) the pending events need to be rolled back
The merge function processes updates to the sync state based on incoming payloads,
handling cases such as upstream rebase, advance and local push.
Extends
Section titled “Extends”SyncState_base
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SyncState(
props,options?):SyncState
Defined in: .pnpm-home/store/v11/links/@/effect/3.21.0/5f824b960b722ac9cc27ad83fe3b2945d775b034a0e1eb327a0ff67a4a7c6da7/node_modules/effect/dist/dts/Schema.d.ts:4266
Parameters
Section titled “Parameters”localHead
Section titled “localHead”{ client: number & Brand<"ClientEventSequenceNumber">; global: number & Brand<"GlobalEventSequenceNumber">; rebaseGeneration: number; }
localHead.client
Section titled “localHead.client”number & Brand<"ClientEventSequenceNumber">
localHead.global
Section titled “localHead.global”number & Brand<"GlobalEventSequenceNumber">
localHead.rebaseGeneration
Section titled “localHead.rebaseGeneration”number
pending
Section titled “pending”readonly EncodedWithMeta[]
upstreamHead
Section titled “upstreamHead”{ client: number & Brand<"ClientEventSequenceNumber">; global: number & Brand<"GlobalEventSequenceNumber">; rebaseGeneration: number; }
upstreamHead.client
Section titled “upstreamHead.client”number & Brand<"ClientEventSequenceNumber">
upstreamHead.global
Section titled “upstreamHead.global”number & Brand<"GlobalEventSequenceNumber">
upstreamHead.rebaseGeneration
Section titled “upstreamHead.rebaseGeneration”number
options?
Section titled “options?”MakeOptions
Returns
Section titled “Returns”SyncState
Inherited from
Section titled “Inherited from”SyncState_base.constructor
Properties
Section titled “Properties”localHead
Section titled “localHead”
readonlylocalHead:object
Defined in: packages/@livestore/common/dist/sync/syncstate.d.ts:15
Equivalent to pending.at(-1)?.id if there are pending events
client
Section titled “client”
readonlyclient:number&Brand<"ClientEventSequenceNumber">
global
Section titled “global”
readonlyglobal:number&Brand<"GlobalEventSequenceNumber">
rebaseGeneration
Section titled “rebaseGeneration”
readonlyrebaseGeneration:number
Inherited from
Section titled “Inherited from”SyncState_base.localHead
pending
Section titled “pending”
readonlypending: readonlyEncodedWithMeta[]
Defined in: packages/@livestore/common/dist/sync/syncstate.d.ts:5
Inherited from
Section titled “Inherited from”SyncState_base.pending
toJSON()
Section titled “toJSON()”toJSON: () =>
any
Defined in: packages/@livestore/common/dist/sync/syncstate.d.ts:93
Returns
Section titled “Returns”any
upstreamHead
Section titled “upstreamHead”
readonlyupstreamHead:object
Defined in: packages/@livestore/common/dist/sync/syncstate.d.ts:7
What this node expects the next upstream node to have as its own local head
client
Section titled “client”
readonlyclient:number&Brand<"ClientEventSequenceNumber">
global
Section titled “global”
readonlyglobal:number&Brand<"GlobalEventSequenceNumber">
rebaseGeneration
Section titled “rebaseGeneration”
readonlyrebaseGeneration:number
Inherited from
Section titled “Inherited from”SyncState_base.upstreamHead