/*! * Copyright (c) 2026 Interop Alliance. All rights reserved. */ /** * SyncController: this library's session binding over the replication * controller core in `@interop/was-sync/rxdb`. * * The core owns the lifecycle -- the serialized start/stop queue, one * `replicateRxCollection` state machine per collection, the per-collection * capability skip, the status and auth-error callbacks, the poll timer, and the * failed-bring-up unwind. What this binding owns is everything app-shaped: the * port built from the session's {@link WasRemoteStore} and {@link LocalStore}, * the browser reachability source, the poll interval from the app's * {@link WasSyncConfig}, and the Zustand {@link SyncStatusStore} the statuses * are written into (keyed by the registry's LOGICAL collection key, which is * the first argument the core delivers). * * A controller is single-use per session, which is the core's own rule: `stop()` * is terminal for a core instance, so the binding builds a fresh one inside * `start()` and resets the status store on stop. */ import type { RxChangeEvent } from 'rxdb/plugins/core'; import type { SyncedDoc } from '@interop/was-sync'; import { type WasCollectionConfig, type WasSyncConfig } from '../config.js'; import type { LocalStore } from './localStore.js'; import type { WasRemoteStore } from './wasRemoteStore.js'; import type { SyncStatusStore } from './syncStatusStore.js'; export { isAuthError } from '@interop/was-sync/rxdb'; /** * A per-session controller around background replication. */ export declare class SyncController { #private; /** * @param options {object} * @param options.collections {WasCollectionConfig[]} * @param options.syncStatus {SyncStatusStore} the session's per-collection * status store this controller reports into * @param [options.sync] {WasSyncConfig} */ constructor({ collections, syncStatus, sync }: { collections: WasCollectionConfig[]; syncStatus: SyncStatusStore; sync?: WasSyncConfig; }); /** * Starts background replication for every entity collection covered by the * grant set. Idempotent (a no-op if already running, or if `stop()` has * already run: `stop()` is terminal, so a logout that raced an in-flight * session bootstrap never spins up replications against a closed database). * * A failed bring-up rethrows, with every collection's status left at `error`, * so the caller's bootstrap can surface it. * * @param options {object} * @param options.remoteStore {WasRemoteStore} * @param options.localStore {LocalStore} * @param [options.onRemoteChange] {(collectionKey: string, event) => void} * fired per RxDB change (pull or conflict-resolved push) for reactive * per-doc store patching * @param [options.onAuthError] {() => void} fired when a replication error * carries a 401/403 (storage access expired/revoked) * @returns {Promise} */ start({ remoteStore, localStore, onRemoteChange, onAuthError }: { remoteStore: WasRemoteStore; localStore: LocalStore; onRemoteChange?: (collectionKey: string, event: RxChangeEvent) => void; onAuthError?: () => void; }): Promise; /** * Triggers an immediate replication cycle on every running collection, rather * than waiting for RxDB's next scheduled tick. Fire-and-forget. * * @returns {void} */ reSync(): void; /** * Stops replication and releases resources (the database is owned by the * caller). Idempotent, and terminal: a later `start()` is refused. * * @returns {Promise} */ stop(): Promise; } //# sourceMappingURL=syncController.d.ts.map