import type { JsonObject, SessionStore } from './types.js'; /** * A workflow event with append-only identity enforced by (runId, eventIndex). */ export interface RunEvent { runId: string; eventIndex: number; type: string; timestamp: string; data?: JsonObject; } /** * Minimal interface for a workflow/event run store. * Used by durable runtime backends (Temporal, Cloudflare, etc.) * to persist run metadata and events. */ export interface RunStore { /** Persist a run record. */ saveRun(run: unknown): Promise | void; /** Retrieve a run by its id. */ getRun(id: string): Promise | unknown | undefined; /** List all persisted runs. */ listRuns(): Promise | unknown[]; /** Append a workflow event. Implementations must enforce append-only semantics * for (runId, eventIndex) — duplicate indexes for the same runId must be rejected. */ appendRunEvent?(runId: string, event: RunEvent): Promise | void; /** Retrieve workflow events for a run, optionally starting from a specific index. */ getRunEvents?(runId: string, fromIndex?: number): Promise | RunEvent[]; } /** * Minimal interface for a workflow run registry. * Used by durable runtime backends to index and track run statuses. */ export interface RunRegistry { /** Register a new run with its initial status. */ registerRun(runId: string, status: string): Promise | void; /** Update the status of an existing run. */ updateStatus(runId: string, status: string): Promise | void; } /** * A persistence adapter abstracts over storage backends (SQLite, Postgres, * file, etc.). The SDK only requires `connect() → SessionStore`. Optional * methods `connectRunStore` and `connectRunRegistry` are used by workflow * backends (Temporal, Cloudflare). The optional `migrate()` hook is called * once at startup to ensure schema exists, and `close()` releases resources. */ export interface PersistenceAdapter { /** Open the connection and return a {@link SessionStore}. */ connect(): Promise | SessionStore; /** Return a {@link RunStore} for workflow run data and events. */ connectRunStore?(): Promise | RunStore; /** Return a {@link RunRegistry} for workflow run indexing and listing. */ connectRunRegistry?(): Promise | RunRegistry; /** * Run idempotent schema setup (CREATE TABLE IF NOT EXISTS, etc.). * Called once at startup before {@link connect}. Adapters that create * schema implicitly may omit this method. */ migrate?(): Promise; /** Gracefully release resources (connection pools, file handles). */ close?(): Promise; } /** * Create an in-memory {@link PersistenceAdapter} backed by a fresh * {@link InMemorySessionStore}. This is the default when no persistence * is configured. The returned adapter's `connect()` always returns the * same store instance. */ export declare function persistenceAdapter(): PersistenceAdapter; //# sourceMappingURL=persistence.d.ts.map