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<WebStreamingSyncImplementationOptions, 'adapter' | 'uploadCrud' | 'remote'>;
    dbParams: ResolvedWebSQLOpenOptions;
};
/**
 * @internal
 */
export interface SharedSyncImplementationListener extends StreamingSyncImplementationListener {
    initialized: () => void;
}
/**
 * @internal
 */
export type WrappedSyncPort = {
    port: MessagePort;
    clientProvider: Comlink.Remote<AbstractSharedSyncClientProvider>;
    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<SharedSyncImplementationListener> implements StreamingSyncImplementation {
    protected ports: WrappedSyncPort[];
    protected isInitialized: Promise<void>;
    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<void>;
    waitUntilStatusMatches(predicate: (status: SyncStatus) => boolean): Promise<void>;
    waitForReady(): Promise<void>;
    setLogLevel(level: ILogLevel): void;
    /**
     * Configures the DBAdapter connection and a streaming sync client.
     */
    setParams(params: SharedSyncInitOptions): Promise<void>;
    dispose(): Promise<void>;
    /**
     * 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<void>;
    disconnect(): Promise<void>;
    /**
     * Adds a new client tab's message port to the list of connected ports
     */
    addPort(port: MessagePort): Promise<void>;
    /**
     * Removes a message port client from this manager's managed
     * clients.
     */
    removePort(port: MessagePort): Promise<() => void>;
    triggerCrudUpload(): void;
    hasCompletedSync(): Promise<boolean>;
    getWriteCheckpoint(): Promise<string>;
    protected withSyncImplementation<T>(callback: (sync: StreamingSyncImplementation) => Promise<T>): Promise<T>;
    protected generateStreamingImplementation(): WebStreamingSyncImplementation;
    protected openInternalDB(): Promise<void>;
    /**
     * 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;
}
