API reference
classes
Syncengine

Class: SyncEngine

The SyncEngine is responsible for managing the connection to the server and syncing data

Constructors

constructor

new SyncEngine(options, db): SyncEngine

Parameters

NameTypeDescription
optionsSyncOptionsconfiguration options for the sync engine
dbdefault<any>the client database to be synced

Returns

SyncEngine

Defined in

packages/client/src/sync-engine.ts:60 (opens in a new tab)

Properties

commitCallbacks

Private commitCallbacks: Map<string, Set<() => void>>

Defined in

packages/client/src/sync-engine.ts:172 (opens in a new tab)


connectionChangeHandlers

Private connectionChangeHandlers: Set<(status: undefined | ConnectionStatus) => void>

Defined in

packages/client/src/sync-engine.ts:47 (opens in a new tab)


db

Private db: default<any>

Defined in

packages/client/src/sync-engine.ts:44 (opens in a new tab)


failureCallbacks

Private failureCallbacks: Map<string, Set<(e: unknown) => void>>

Defined in

packages/client/src/sync-engine.ts:173 (opens in a new tab)


queries

Private queries: Map<string, { fulfilled: boolean ; params: CollectionQuery<any, any> }>

Defined in

packages/client/src/sync-engine.ts:36 (opens in a new tab)


queryFulfillmentCallbacks

Private queryFulfillmentCallbacks: Map<string, (response: any) => void>

Defined in

packages/client/src/sync-engine.ts:51 (opens in a new tab)


reconnectTimeout

Private reconnectTimeout: any

Defined in

packages/client/src/sync-engine.ts:42 (opens in a new tab)


reconnectTimeoutDelay

Private reconnectTimeoutDelay: number = 250

Defined in

packages/client/src/sync-engine.ts:41 (opens in a new tab)


syncOptions

Private syncOptions: SyncOptions

Defined in

packages/client/src/sync-engine.ts:45 (opens in a new tab)


transport

Private transport: SyncTransport

Defined in

packages/client/src/sync-engine.ts:34 (opens in a new tab)


txCommits$

Private txCommits$: Subject<string>

Defined in

packages/client/src/sync-engine.ts:52 (opens in a new tab)


txFailures$

Private txFailures$: Subject<{ error: unknown ; txId: string }>

Defined in

packages/client/src/sync-engine.ts:53 (opens in a new tab)

Accessors

connectionStatus

get connectionStatus(): undefined | ConnectionStatus

The current connection status of the sync engine

Returns

undefined | ConnectionStatus

Defined in

packages/client/src/sync-engine.ts:342 (opens in a new tab)


httpUri

get httpUri(): undefined | string

Returns

undefined | string

Defined in

packages/client/src/sync-engine.ts:95 (opens in a new tab)


token

get token(): undefined | string

The token used to authenticate with the server

Returns

undefined | string

Defined in

packages/client/src/sync-engine.ts:91 (opens in a new tab)

Methods

closeConnection

closeConnection(code?, reason?): void

Parameters

NameType
code?number
reason?string

Returns

void

Defined in

packages/client/src/sync-engine.ts:456 (opens in a new tab)


connect

connect(): Promise<void>

Initiate a sync connection with the server

Returns

Promise<void>

Defined in

packages/client/src/sync-engine.ts:212 (opens in a new tab)


disconnect

disconnect(): void

Disconnect from the server

Returns

void

Defined in

packages/client/src/sync-engine.ts:365 (opens in a new tab)


fetchFromServer

fetchFromServer(path, init?): Promise<Response>

Parameters

NameType
pathstring
init?RequestInit

Returns

Promise<Response>

Defined in

packages/client/src/sync-engine.ts:524 (opens in a new tab)


getConnectionParams

getConnectionParams(): Promise<TransportConnectParams>

Returns

Promise<TransportConnectParams>

Defined in

packages/client/src/sync-engine.ts:103 (opens in a new tab)


getRemoteTriples

getRemoteTriples(query): Promise<any>

Parameters

NameType
queryClientQuery<any, any>

Returns

Promise<any>

Defined in

packages/client/src/sync-engine.ts:509 (opens in a new tab)


handleErrorMessage

handleErrorMessage(message): Promise<void>

Parameters

NameType
messageany

Returns

Promise<void>

Defined in

packages/client/src/sync-engine.ts:372 (opens in a new tab)


hasQueryBeenFulfilled

hasQueryBeenFulfilled(queryId): boolean

Parameters

NameType
queryIdstring

Returns

boolean

Defined in

packages/client/src/sync-engine.ts:160 (opens in a new tab)


onConnectionStatusChange

onConnectionStatusChange(callback, runImmediately?): () => void

Sets up a listener for connection status changes

Parameters

NameTypeDefault valueDescription
callback(status: undefined | ConnectionStatus) => voidundefinedA callback that will be called when the connection status changes
runImmediatelybooleanfalseRun the callback immediately with the current connection status

Returns

fn

A function that removes the callback from the connection status change listeners

▸ (): void

Returns

void

Defined in

packages/client/src/sync-engine.ts:445 (opens in a new tab)


onQueryFulfilled

onQueryFulfilled(queryId, callback): void

Parameters

NameType
queryIdstring
callback(response: any) => void

Returns

void

Defined in

packages/client/src/sync-engine.ts:156 (opens in a new tab)


onTxCommit

onTxCommit(txId, callback): () => void

When a transaction has been confirmed by the remote database, the callback will be called

Parameters

NameType
txIdstring
callback() => void

Returns

fn

a function removing the listener callback

▸ (): void

Returns

void

Defined in

packages/client/src/sync-engine.ts:181 (opens in a new tab)


onTxFailure

onTxFailure(txId, callback): () => void

If a transaction fails to commit on the remote database, the callback will be called

Parameters

NameType
txIdstring
callback(e: unknown) => void

Returns

fn

a function removing the listener callback

▸ (): void

Returns

void

Defined in

packages/client/src/sync-engine.ts:196 (opens in a new tab)


resetReconnectTimeout

resetReconnectTimeout(): void

Returns

void

Defined in

packages/client/src/sync-engine.ts:463 (opens in a new tab)


retry

retry(txId): Promise<void>

Retry sending a transaciton to the remote database. This is commonly used when a transaction fails to commit on the remote database in the onTxFailure callback.

Parameters

NameType
txIdstring

Returns

Promise<void>

Defined in

packages/client/src/sync-engine.ts:408 (opens in a new tab)


rollback

rollback(txIds): Promise<void>

Rollback a transaction from the client database. It will no longer be sent to the remote database as a part of the syncing process. This is commonly used when a transaction fails to commit on the remote database in the onTxFailure callback.

Parameters

NameType
txIdsstring | string[]

Returns

Promise<void>

Defined in

packages/client/src/sync-engine.ts:420 (opens in a new tab)


sendTriples

sendTriples(triples): void

Parameters

NameType
triplesTripleRow[]

Returns

void

Defined in

packages/client/src/sync-engine.ts:396 (opens in a new tab)


setupWindowListeners

setupWindowListeners(): Promise<void>

Returns

Promise<void>

Defined in

packages/client/src/sync-engine.ts:118 (opens in a new tab)


signalOutboxTriples

signalOutboxTriples(): void

Returns

void

Defined in

packages/client/src/sync-engine.ts:205 (opens in a new tab)