import * as SQLite from '@journeyapps/wa-sqlite'; import { BaseObserver, BatchedUpdateNotification } from '@powersync/common'; import { Mutex } from 'async-mutex'; import { AsyncDatabaseConnection, OnTableChangeCallback, ProxiedQueryResult } from '../AsyncDatabaseConnection'; import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory'; /** * List of currently tested virtual filesystems */ export declare enum WASQLiteVFS { IDBBatchAtomicVFS = "IDBBatchAtomicVFS", OPFSCoopSyncVFS = "OPFSCoopSyncVFS", AccessHandlePoolVFS = "AccessHandlePoolVFS" } /** * @internal */ export type WASQLiteBroadCastTableUpdateEvent = { changedTables: Set; connectionId: number; }; /** * @internal */ export type WASQLiteConnectionListener = { tablesUpdated: (event: BatchedUpdateNotification) => void; }; /** * @internal */ export type SQLiteModule = Parameters[0]; /** * @internal */ export type WASQLiteModuleFactoryOptions = { dbFileName: string; encryptionKey?: string; }; /** * @internal */ export type WASQLiteModuleFactory = (options: WASQLiteModuleFactoryOptions) => Promise<{ module: SQLiteModule; vfs: SQLiteVFS; }>; /** * @internal */ export declare const AsyncWASQLiteModuleFactory: () => Promise; /** * @internal */ export declare const MultiCipherAsyncWASQLiteModuleFactory: () => Promise; /** * @internal */ export declare const SyncWASQLiteModuleFactory: () => Promise; /** * @internal */ export declare const MultiCipherSyncWASQLiteModuleFactory: () => Promise; /** * @internal */ export declare const DEFAULT_MODULE_FACTORIES: { IDBBatchAtomicVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{ module: any; vfs: any; }>; AccessHandlePoolVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{ module: any; vfs: any; }>; OPFSCoopSyncVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{ module: any; vfs: any; }>; }; /** * @internal * WA-SQLite connection which directly interfaces with WA-SQLite. * This is usually instantiated inside a worker. */ export declare class WASqliteConnection extends BaseObserver implements AsyncDatabaseConnection { protected options: ResolvedWASQLiteOpenFactoryOptions; private _sqliteAPI; private _dbP; private _moduleFactory; protected updatedTables: Set; protected updateTimer: ReturnType | null; protected statementMutex: Mutex; protected broadcastChannel: BroadcastChannel | null; /** * Unique id for this specific connection. This is used to prevent broadcast table change * notification loops. */ protected connectionId: number; constructor(options: ResolvedWASQLiteOpenFactoryOptions); protected get sqliteAPI(): SQLiteAPI; protected get dbP(): number; protected openDB(): Promise; protected executeEncryptionPragma(): Promise; protected openSQLiteAPI(): Promise; protected registerBroadcastListeners(): void; protected queueTableUpdate(tableNames: Set, shouldBroadcast?: boolean): void; init(): Promise; getConfig(): Promise; fireUpdates(shouldBroadcast?: boolean): void; /** * This executes SQL statements in a batch. */ executeBatch(sql: string, bindings?: any[][]): Promise; /** * This executes single SQL statements inside a requested lock. */ execute(sql: string | TemplateStringsArray, bindings?: any[]): Promise; executeRaw(sql: string | TemplateStringsArray, bindings?: any[]): Promise; close(): Promise; registerOnTableChange(callback: OnTableChangeCallback): Promise<() => void>; /** * This requests a lock for executing statements. * Should only be used internally. */ protected acquireExecuteLock: (callback: () => Promise) => Promise; /** * This executes a single statement using SQLite3. */ protected executeSingleStatement(sql: string | TemplateStringsArray, bindings?: any[]): Promise; /** * This executes a single statement using SQLite3 and returns the results as an array of arrays. */ protected executeSingleStatementRaw(sql: string | TemplateStringsArray, bindings?: any[]): Promise; private _execute; }