trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
67 lines • 2.48 kB
TypeScript
/**
* IndexedDB-backed op log.
*
* Browser-side companion to {@link JsonOpLog}. Designed to satisfy the
* {@link OpLog} contract while accommodating IndexedDB's async nature:
*
* - `load()` opens the database and pulls every persisted op into an
* in-memory cache. All subsequent reads serve from cache, so the engine
* can continue using synchronous `readAll`/`getLastOp`/`count`.
* - `append()` is synchronous from the caller's perspective: it updates the
* in-memory cache immediately and enqueues a durable IDB write. The
* returned promise from `flush()` resolves once every queued write has
* committed.
* - Hash dedup happens against the cache before the write is enqueued, so
* replayed sync batches never insert the same op twice.
*
* Default store layout: one database per repo, one object store keyed by
* `hash`, with a monotonically-increasing `seq` index so we can replay in
* append order on load. Callers may override the IDB factory in tests by
* passing `indexedDB` in the constructor options.
*/
import type { VcsOp } from './types.js';
import type { OpLog } from './op-log.js';
/**
* Subset of the IndexedDB Factory we use. Matches both `globalThis.indexedDB`
* and `fake-indexeddb`'s `IDBFactory`. Allows test injection without pulling
* in the full DOM typings.
*/
export interface IdbFactoryLike {
open(name: string, version?: number): IDBOpenDBRequest;
}
export interface IdbOpLogOptions {
/** Database name. One Trellis repo per database. */
dbName: string;
/**
* Object store name. Defaults to `ops`. Override if multiple op logs share
* a database (e.g. integration journal vs. lane journals).
*/
storeName?: string;
/**
* Injected IndexedDB factory. Defaults to `globalThis.indexedDB`. Tests
* pass `fake-indexeddb`'s factory directly.
*/
indexedDB?: IdbFactoryLike;
}
export declare class IdbOpLog implements OpLog {
private ops;
private hashes;
private db;
private nextSeq;
private pendingWrites;
private readonly dbName;
private readonly storeName;
private readonly factory;
constructor(opts: IdbOpLogOptions);
load(): Promise<void>;
append(op: VcsOp): void;
readAll(): VcsOp[];
getLastOp(): VcsOp | undefined;
count(): number;
flush(): Promise<void>;
close(): Promise<void>;
private openDb;
private readAllRecords;
private putRecord;
}
//# sourceMappingURL=idb-op-log.d.ts.map