import { type ILogger, type ILogLevel, type PowerSyncConnectionOptions, type StreamingSyncImplementation, type StreamingSyncImplementationListener, type SyncStatusOptions, BaseObserver, ConnectionManager, DBAdapter, SyncStatus } from '@powersync/common'; import { Mutex } from 'async-mutex'; import * as Comlink from 'comlink'; import { WebStreamingSyncImplementation, WebStreamingSyncImplementationOptions } from '../../db/sync/WebStreamingSyncImplementation'; import { ResolvedWebSQLOpenOptions } from '../../db/adapters/web-sql-flags'; import { AbstractSharedSyncClientProvider } from './AbstractSharedSyncClientProvider'; /** * @internal * Manual message events for shared sync clients */ export declare enum SharedSyncClientEvent { /** * This client requests the shared sync manager should * close it's connection to the client. */ CLOSE_CLIENT = "close-client", CLOSE_ACK = "close-ack" } /** * @internal */ export type ManualSharedSyncPayload = { event: SharedSyncClientEvent; data: any; }; /** * @internal */ export type SharedSyncInitOptions = { streamOptions: Omit; dbParams: ResolvedWebSQLOpenOptions; }; /** * @internal */ export interface SharedSyncImplementationListener extends StreamingSyncImplementationListener { initialized: () => void; } /** * @internal */ export type WrappedSyncPort = { port: MessagePort; clientProvider: Comlink.Remote; db?: DBAdapter; }; /** * @internal */ export type RemoteOperationAbortController = { controller: AbortController; activePort: WrappedSyncPort; }; /** * @internal * Shared sync implementation which runs inside a shared webworker */ export declare class SharedSyncImplementation extends BaseObserver implements StreamingSyncImplementation { protected ports: WrappedSyncPort[]; protected isInitialized: Promise; protected statusListener?: () => void; protected fetchCredentialsController?: RemoteOperationAbortController; protected uploadDataController?: RemoteOperationAbortController; protected dbAdapter: DBAdapter | null; protected syncParams: SharedSyncInitOptions | null; protected logger: ILogger; protected lastConnectOptions: PowerSyncConnectionOptions | undefined; protected portMutex: Mutex; protected connectionManager: ConnectionManager; syncStatus: SyncStatus; broadCastLogger: ILogger; constructor(); get lastSyncedAt(): Date | undefined; get isConnected(): boolean; waitForStatus(status: SyncStatusOptions): Promise; waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise; waitForReady(): Promise; setLogLevel(level: ILogLevel): void; /** * Configures the DBAdapter connection and a streaming sync client. */ setParams(params: SharedSyncInitOptions): Promise; dispose(): Promise; /** * Connects to the PowerSync backend instance. * Multiple tabs can safely call this in their initialization. * The connection will simply be reconnected whenever a new tab * connects. */ connect(options?: PowerSyncConnectionOptions): Promise; disconnect(): Promise; /** * Adds a new client tab's message port to the list of connected ports */ addPort(port: MessagePort): Promise; /** * Removes a message port client from this manager's managed * clients. */ removePort(port: MessagePort): Promise<() => void>; triggerCrudUpload(): void; hasCompletedSync(): Promise; getWriteCheckpoint(): Promise; protected withSyncImplementation(callback: (sync: StreamingSyncImplementation) => Promise): Promise; protected generateStreamingImplementation(): WebStreamingSyncImplementation; protected openInternalDB(): Promise; /** * A method to update the all shared statuses for each * client. */ private updateAllStatuses; /** * A function only used for unit tests which updates the internal * sync stream client and all tab client's sync status */ private _testUpdateAllStatuses; }