import { type ActivationKey, type EffectLedger, type SessionAdapter, type SessionCheckpoint, type SessionSeed } from "./adapter.ts"; import type { AppendedSessionEvent, SessionEvent } from "./events.ts"; import { type Clock, InMemorySessionLog, type SessionLog, type SqliteDb, SqliteSessionLog } from "./log.ts"; export interface SessionBackendOptions { /** Injectable clock for deterministic checkpoint timestamps. Default {@link systemClock}. */ clock?: Clock; /** Injectable checkpoint-id generator (deterministic tests). Default `crypto.randomUUID`. */ newCheckpointId?: () => string; } /** * A session adapter bound to one activation and one incarnation. Constructing it * takes the lease at `incarnation` (advancing the fence), so a re-lease at a * higher incarnation immediately fences every prior one — a subsequent `emit` * from an older adapter throws {@link StaleIncarnationError}. */ export declare class SessionBackend implements SessionAdapter { #private; readonly key: ActivationKey; readonly incarnation: number; constructor(log: SessionLog, key: ActivationKey, incarnation: number, options?: SessionBackendOptions); /** The offset the next `emit` will assign. */ get nextOffset(): number; emit(event: SessionEvent): AppendedSessionEvent; checkpoint(commitSha: string, effectLedger: EffectLedger): SessionCheckpoint; restore(fromCheckpoint?: string): SessionSeed; } /** * Open a session adapter over an in-memory reference log. Pass a shared * {@link InMemorySessionLog} across incarnations of the same activation so the * fence and events persist across a re-lease (the reference resume scenario); * omit it for a throwaway single-incarnation log. */ export declare function openInMemorySession(key: ActivationKey, incarnation: number, options?: SessionBackendOptions & { log?: InMemorySessionLog; }): { backend: SessionBackend; log: InMemorySessionLog; }; /** Open a session adapter over the durable SQLite log. Applies the schema idempotently. */ export declare function openSqliteSession(db: SqliteDb, key: ActivationKey, incarnation: number, options?: SessionBackendOptions): { backend: SessionBackend; log: SqliteSessionLog; };