API reference@evolu/common › local‑first/Shared

Platform-agnostic Evolu SharedWorker.

Synchronization routing

WebSocket transports are shared resources keyed by their configuration and claimed by owner ID, so every tenant (one named local database) using an owner shares that owner's sockets, whichever tenant claimed them. An incoming frame is offered to every tenant with a writable registration for its owner, and each tenant reconciles independently: the protocol exchange is stateless per message and message writes are idempotent, so a response that answered another tenant's request is still a valid reconciliation step.

Every queued sync request carries a SyncTarget. A continuation returns only to the transport that produced the response. A round started by a socket opening, by a transport's first claim for an owner, or by a tenant's first use of a transport other tenants already claimed targets that transport. A tenant's first writable owner registration also reconciles its existing history through every transport already claimed for that owner. Explicit synchronization requests and mutation uploads go to every open transport claimed for the owner.

Relays omit the sending socket when broadcasting uploads. Mutation uploads and continuation uploads therefore also deliver local Broadcast frames to every other tenant with writable access to the owner, even while sockets are closed. Large mutation batches use as many frames as needed. These copies target AllTransports so their recipients refresh queries without scheduling relay propagation; the uploading tenant already owns that work.

Local delivery forwards uploads—including historical messages sent during reconciliation—to other tenants with writable access to the owner. It does not initiate reconciliation between local database histories. Automatic sibling catch-up is deferred until replication scopes and retention semantics are defined.

When a relay frame stores new owner messages, the tenant requests a full round through each other transport claimed for the owner, by any tenant, so data learned from one relay reaches the others. Duplicate receipts store nothing and request nothing. A replacement leader may have stored messages whose response was lost, so it reconciles every transport again. A later request is absorbed by a queued round with the same owners, a covering target, and a position after all writes already queued. Propagation requests can reuse a queued round with the same owners and a covering target regardless of later queued writes because their messages are already stored. A closed transport reconciles when it opens.

Functions

FunctionDescription
initSharedWorkerInitializes the platform-agnostic Evolu SharedWorker.

Interfaces

InterfaceDescription
SharedWorkerDep-

Type Aliases

Type AliasDescription
ConsoleEntryOrError-
DbWorkerInput-
DbWorkerOutput-
DbWorkerQueuedResponse-
DbWorkerReadRequest-
DbWorkerRequest-
DbWorkerWriteRequest-
EvoluInput-
EvoluInstanceId-
EvoluOutput-
SharedWorker-
SharedWorkerDeps-
SharedWorkerInput-
SharedWorkerOutput-
SyncState-

Variables

VariableDescription
consoleEntryOrErrorBroadcastChannelName-