import { BaseObserverInterface, BaseListener, Disposable, PowerSyncLogger, SyncStatus, BaseObserver } from '@powersync/common'; import { BucketStorageAdapter } from '../bucket/BucketStorageAdapter.js'; import { AbstractRemote } from './AbstractRemote.js'; import { CoreSyncStatus } from './core-instruction.js'; import { JavaScriptSyncState, SyncStatusSnapshot } from '../../../db/crud/SyncStatus.js'; import { ResolvedSyncOptions } from '../options.js'; /** * @internal */ export declare enum LockType { CRUD = "crud", SYNC = "sync" } /** * Abstract Lock to be implemented by various JS environments * * @internal */ export interface LockOptions { callback: () => Promise; type: LockType; signal?: AbortSignal; } /** * @internal */ export interface AbstractStreamingSyncImplementationOptions { adapter: BucketStorageAdapter; subscriptions: SubscribedStream[]; uploadCrud: () => Promise; /** * An identifier for which PowerSync DB this sync implementation is * linked to. Most commonly DB name, but not restricted to DB name. */ identifier?: string; logger: PowerSyncLogger; remote: AbstractRemote; /** * The serialized schema - mainly used to forward information about raw tables to the sync client. */ serializedSchema: any; } /** * @internal */ export interface StreamingSyncImplementationListener extends BaseListener { /** * Triggers whenever the status' members have changed in value */ statusChanged?: ((status: SyncStatusSnapshot) => void) | undefined; } /** * @internal */ export interface StreamingSyncImplementation extends BaseObserverInterface, Disposable { /** * Connects to the sync service */ connect(options: ResolvedSyncOptions): Promise; /** * Disconnects from the sync services. * @throws if not connected or if abort is not controlled internally */ disconnect(): Promise; getWriteCheckpoint: () => Promise; isConnected: boolean; triggerCrudUpload: () => void; waitForReady(): Promise; waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise; updateSubscriptions(subscriptions: SubscribedStream[]): void; markConnectionMayHaveChanged(): void; } /** * @internal */ export type SubscribedStream = { name: string; params: Record | null; }; /** * @internal */ export declare abstract class AbstractStreamingSyncImplementation extends BaseObserver implements StreamingSyncImplementation { protected options: AbstractStreamingSyncImplementationOptions; protected abortController: AbortController | null; protected crudUpdateListener?: () => void; protected streamingSyncPromise?: Promise<[void, void]>; protected logger: PowerSyncLogger; protected activeStreams: SubscribedStream[]; private connectionMayHaveChanged; private crudUploadNotifier; private notifyCompletedUploads?; private handleActiveStreamsChange?; syncStatus: SyncStatusSnapshot; constructor(options: AbstractStreamingSyncImplementationOptions); triggerCrudUpload(): void; waitForReady(): Promise; waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise; get lastSyncedAt(): Date | undefined; get isConnected(): boolean; dispose(): Promise; abstract obtainLock(lockOptions: LockOptions): Promise; getWriteCheckpoint(): Promise; private crudUploadLoop; private _uploadAllCrud; connect(options: ResolvedSyncOptions): Promise; disconnect(): Promise; private markAsDisconnected; private streamingSync; markConnectionMayHaveChanged(): void; /** * Older versions of the JS SDK used to encode subkeys as JSON in `OplogEntry.toJSON`. * Because subkeys are always strings, this leads to quotes being added around them in `ps_oplog`. * While this is not a problem as long as it's done consistently, it causes issues when a database * created by the JS SDK is used with other SDKs, or (more likely) when the new Rust sync client * is enabled. * * So, we add a migration from the old key format (with quotes) to the new one (no quotes). The * migration is only triggered when necessary (for now). The function returns whether the new format * should be used, so that the JS SDK is able to write to updated databases. * * @param requireFixedKeyFormat - Whether we require the new format or also support the old one. * The Rust client requires the new subkey format. * @returns Whether the database is now using the new, fixed subkey format. */ private requireKeyFormat; protected streamingSyncIteration(signal: AbortSignal, options: ResolvedSyncOptions): Promise; private receiveSyncLines; private rustSyncIteration; protected updateSyncStatus(core: CoreSyncStatus | null, jsState?: JavaScriptSyncState): void; protected updateJsSyncState(state: JavaScriptSyncState): void; private delayRetry; updateSubscriptions(subscriptions: SubscribedStream[]): void; } interface RustIterationResult { immediateRestart: boolean; } export {};