import { UnlockFn } from '@powersync/common'; import { RawSqliteConnection } from './RawSqliteConnection.js'; import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory.js'; /** * A wrapper around a {@link RawSqliteConnection} allowing multiple tabs to access it. * * To allow potentially concurrent accesses from different clients, this requires a local mutex implementation here. * * Note that instances of this class are not safe to proxy across context boundaries with comlink! We need to be able to * rely on mutexes being returned reliably, so additional checks to detect say a client tab closing are required to * avoid deadlocks. */ export declare class ConcurrentSqliteConnection { private readonly inner; /** * An outer mutex ensuring at most one {@link ConnectionLeaseToken} can exist for this connection at a time. * * If null, we'll use navigator locks instead. */ private leaseMutex; /** * @param needsNavigatorLocks Whether access to the database needs an additional navigator lock guard. * * While {@link ConcurrentSqliteConnection} prevents concurrent access to a database _connection_, it's possible we * might have multiple connections to the same physical database (e.g. if multiple tabs use dedicated workers). * In those setups, we use navigator locks instead of an internal mutex to guard access.. */ constructor(inner: RawSqliteConnection, needsNavigatorLocks: boolean); get options(): ResolvedWASQLiteOpenFactoryOptions; acquireMutex(abort?: AbortSignal): Promise; unsafeUseInner(): RawSqliteConnection; /** * @returns A {@link ConnectionLeaseToken}. Until that token is returned, no other client can use the database. */ acquireConnection(abort?: AbortSignal): Promise; close(): Promise; } /** * An instance representing temporary exclusive access to a {@link ConcurrentSqliteConnection}. */ export declare class ConnectionLeaseToken { private returnMutex; private connection; /** Ensures that the client with access to this token can't run statements concurrently. */ private useMutex; private closed; constructor(returnMutex: UnlockFn, connection: RawSqliteConnection); /** * Returns this lease, allowing another client to use the database connection. */ returnLease(): Promise; /** * This should only be used internally, since the callback must not use the raw connection after resolving. */ use(callback: (conn: RawSqliteConnection) => Promise): Promise; }