import { DBAdapter, DBLockOptions, LockContext } from '@powersync/common'; import type { RawWaSqliteDatabaseOptions } from '../wa-sqlite/RawSqliteConnection.js'; /** * Options for a {@link InMemoryWriteAheadLogPool}. */ export interface InMemoryWriteAheadLogPoolOptions { /** * The amount of workers to use, must at least be `1`. */ numWorkers: number; /** * Optional additional options used to configure how the database is opened in workers. */ database?: Partial; /** * The maximum size of the database buffer, in bytes. * * This VFS uses a growable buffer, so not all of this is allocated immediately. By default, the VFS attempts to use * 16 GB and falls back to 1 GB if that fails (e.g. on 32-bit platforms). */ maxDatabaseSize?: number; /** * The maximum size of the write-ahead log, in bytes. * * The size of the write-ahead log constraints the amount of data that can be written in a single transaction. * * This VFS uses a growable buffer, so not all of this is allocated immediately. By default, the VFS attempts to use * 1 GB. */ maxWriteAheadLogSize?: number; } /** * An in-memory database backed by a pool of workers. * * Multiple workers can execute readonly transactions in parallel, and a single writer is allowed to write to the * database in parallel to readers. To allow multiple workers to access the same database, this is based on shared array * buffers and requires the page to be [cross-origin isolated](https://web.dev/articles/cross-origin-isolation-guide). * * To use this VFS, pass it to the {@link PowerSyncDatabase} constructor: * * ```TypeScript * import { PowerSyncDatabase, Schema } from '@powersync/web'; * import InMemoryWriteAheadLogPool from '@powersync/web/extra/shared-memory-pool'; * * const db = new PowerSyncDatabase({ * opened: new InMemoryWriteAheadLogPool({numWorkers: 3}), * schema: new Schema(...), * }); * ``` * * This database uses a concept known as a write-ahead log: Instead of writing changes directly to the database (which * would cause conflicts with readers), the writer appends modified database pages into an append-only overlay log. When * readers start a transaction, they consider the main database and items from the log until a specific position, * meaning that future appends won't disrupt existing readers. * * To avoid the write-ahead log from growing indefinitely, it is regularly copied back into the main database file. This * process is called a checkpoint, and in this implementation it blocks all other database access. However, it only * needs to copy between memory and is usually fairly fast. This implementation checkpoints after a transaction * completes and at least 10% of the WAL are used. We might fine-tune this later. */ export declare class InMemoryWriteAheadLogPool extends DBAdapter { #private; readonly name: string; constructor(options: InMemoryWriteAheadLogPoolOptions); readLock(fn: (tx: LockContext) => Promise, options?: DBLockOptions): Promise; writeLock(fn: (tx: LockContext) => Promise, options?: DBLockOptions): Promise; refreshSchema(): Promise; close(): Promise; } export default InMemoryWriteAheadLogPool;