import { b as Cmd, c as Sub, M as Machine } from '../core-sEWVgnpI.js'; import { h as EventSourcedOptions, L as LoggedStore, F as FencedStore, i as Refusal, D as DeletableStore, S as Store } from '../runtime-types-f231H8Gq.js'; import { F as FencedJournal$1, J as Journal$1, E as EncodedRecord$1, a as JournalAppend$1, b as JournalConflict$1, c as JournalEntry$1, d as JournalRead$1, e as JournalRefusal$1 } from '../index-_evnHmXt.js'; import { T as Trace } from '../index-DvlQz14y.js'; export { B as BreadcrumbsOptions, a as Recorder, R as RecorderOptions, b as TraceAttachment, c as TraceBreadcrumb, d as TraceStep, e as breadcrumbsFromTrace, p as parseJSONL, r as recorder, t as traceAttachment } from '../index-DvlQz14y.js'; export { c as SnapshotConfig, d as SnapshotFailedMsg, e as SnapshotKnob, f as SnapshotLoadCmd, g as SnapshotLoadFailedMsg, h as SnapshotLoadedMsg, b as SnapshotSavedMsg, a as SnapshotState, S as SnapshotWriteCmd, i as createSnapshot, s as snapshotLoadDef, j as snapshotWriteDef } from '../index-DUdoElz8.js'; import '@standard-schema/spec'; /** Journal I/O boundary for the pure durable-log rules. */ /** * Plain journal-backed stores require one active writer per stream throughout the loaded activation; concurrent plain writers can corrupt history. * * Build an engine-facing durable log from opaque journal storage and schemas. * Opt into fencing explicitly with a FencedJournal and `{ fenced: true }`. * The caller owns the journal and closes it after the activation ends. * * @experimental */ declare function eventSourcedStore(journal: FencedJournal$1, options: EventSourcedOptions & { readonly fenced: true; }): LoggedStore & FencedStore; declare function eventSourcedStore(journal: Journal$1, options: EventSourcedOptions & { readonly fenced?: false; }): LoggedStore; /** * One SQL row, bound by the host to its table and row id (and, when the save * must be part of the host's transaction, to that transaction's connection). * tea imports no SQL library. Each call is ONE atomic statement and the port * holds no state. * * @experimental */ interface RowPort { /** The row's columns and its revision, or `null` when no row exists. `row` is never `null`, and a revision starts at 1. */ read(): Promise<{ readonly row: unknown; readonly revision: number; } | null>; /** Insert the row with `columns` at revision 1. `true` if inserted; `false`, writing nothing, if a row already exists. */ insert(columns: Readonly>): Promise; /** Set `columns` and the revision to `expected + 1` where the row's revision is `expected`. `true` if a row changed, `false` if none did. */ update(columns: Readonly>, expected: number): Promise; /** Delete the row. Resolves when no row exists, so deleting nothing is fine. */ remove(): Promise; } /** * The host's side of the boundary for {@link rowStore}. * * @experimental */ interface RowStoreOptions { /** The row's columns to `S`, or `refuse(reason)` for a row it cannot read. It never answers `null`: the row exists, and absence is decided only by `read` returning no row. It is never called with `null`, and it must not throw. */ readonly parse: (row: unknown) => S | Refusal; /** `S` to the row's columns. It must not throw. The revision is the port's, never part of the columns. */ readonly encode: (state: S) => Readonly>; /** Asked for by name, as on every fenced factory (ADR 0017, item 4). There is no unfenced form. */ readonly fenced: true; } /** * A fenced `Store` whose storage is one SQL row: the State lives in the row's * own columns, and the fence is the row's revision. * * Built for a machine whose State is read by SQL and whose writers are * stateless requests. A request is one `run`: * * ```ts * const store = rowStore(port, { parse, encode, fenced: true }); * const rt = await run(job, { store, boot: "restored", interpret, onError }).ready; * await rt.dispatch({ _tag: "claim", by: "w1" }); * await rt.stop(); * ``` * * `saveFenced(state, n)` writes revision `n + 1` or throws `StoreConflictError` * carrying both versions; revision 0 is the insert. `actualVersion` is the * revision a diagnostic read observed after the refusal, or 0 when it found no * row, so it is not necessarily the revision at the failed comparison. It * equals `expectedVersion` when that read finds the revision that was expected, * as `StoreConflictError(n, n)` after an update that changed nothing, and as * `StoreConflictError(0, 0)` when a refused insert's row has vanished by then. * A failed diagnostic read propagates its rejection. A run on a fenced store * needs an `onError` (ADR 0031). * * With `boot: "restored"` (ADR 0039), for an existing row, when `init` returns * the loaded State itself (`Object.is`), no Subs or Cmd follow-ups dispatch * additional messages, and storage succeeds, a one-Msg request costs one read * and zero writes for a no-cell refusal, or one read and one write for an * accepted transition. Birth and a changed State from init add a boot write. A * failed save can add diagnostic reads and a final save attempt at stop. On a * wake, restored init's Cmds do not run; on a birth, with nothing loaded, * init's Cmds run. * * Bind `port` to the host's transaction and the save is part of it. tea opens * no transaction and has no commit hook: a lost fence reaches the host as the * rejection of the dispatch whose save was refused, or of `ready` for a birth * race, and throwing it out of the transaction rolls the sibling writes back. * * An insert always writes revision 1, so after `delete()` a re-created row * starts again at revision 1: a host that re-creates a deleted id must not let * writers from before the delete continue. * * Pending work is not stored: keep it in the State (see * `docs/explanation/durability-model.md`). * * @experimental */ declare function rowStore(port: RowPort, options: RowStoreOptions): FencedStore & DeletableStore; /** * The outcome of {@link replayTrace}. * * @typeParam S - the machine's State type. * @typeParam M - the machine's Msg union. */ interface ReplayResult { /** * `true` iff every recorded msg replayed and the recomputed states match the * recording: each step's state when the trace carries `steps`, the final * state otherwise. */ matches: boolean; /** The trace's recorded `finalState` — what the run originally produced. */ expected: S; /** * The state the current reducer produced for the same input. On a * {@link ReplayResult.refusal | refusal} it is the state the refused msg * arrived in. */ actual: S; /** * The state the current reducer computed after each replayed msg, in order: * `states[i]` follows `trace.msgs[i]`. It stops short of `msgs.length` on a * refusal. A viewer draws the session from it as the current code sees it. */ states: readonly S[]; /** * The Cmds the current reducer started for each replayed msg, in order: * `cmds[i]` follows `trace.msgs[i]`, like `states`. Nothing runs them. */ cmds: readonly (readonly Cmd[])[]; /** * Present iff the states differ, or a step's Cmds differ from the recorded * ones. The FIRST point of divergence found by a * deterministic pre-order walk: * - `path` — a dotted/indexed access path from the state root, e.g. * `state.queue[2].status` or `state` for a root-level * scalar mismatch. When every State matches but a step's * Cmds do not, the path starts at that step's Cmd list, * e.g. `cmds[0].total`. * - `expected` — the recorded value at that path. * - `actual` — the recomputed value at that path. * - `at` — the first msg after which the recomputed state differs * from the recorded one. Present when the trace carries * `steps`; a trace with only a final state can name the * path but not the msg. */ divergence?: { path: string; expected: unknown; actual: unknown; at?: { index: number; msg: M; }; }; /** * Present iff the current machine has no update cell for a recorded msg in * the state it arrived in: a Msg renamed or removed since the recording, or * a cell the state no longer has. Replay stops there; `states` holds the * steps before it. */ refusal?: { index: number; msg: M; stateName: string; acceptedTypes: readonly string[]; }; } /** * Replay a recorded {@link Trace} against `machine` and diff the recomputed * states against the recorded ones. * * Folds recorded messages from the captured post-init State, without calling * init, Cmd handlers, Store operations or Sub runners. A trace without that * anchor is refused; a fresh init cannot reconstruct its starting State. * * When the trace carries `steps`, every step is compared and the divergence * names the msg it starts at. A step that also carries its `cmds` has them * compared after its State, so a change that starts different effects from * the same States is caught too. When the machine has no cell for a recorded msg, * replay stops and the result carries a `refusal` instead of throwing. * * @param machine - the machine to replay against. Mutating its reducer (the * whole point of a regression check) is what makes a recorded * trace diverge. * @param trace - a Trace from `../recorder` (live `dump()` or a re-hydrated * `parseJSONL(...)`). * @param _ctx - optional legacy argument; recorded replay needs no init context. */ declare function replayTrace(machine: Machine, trace: Trace, _ctx?: Ctx): ReplayResult; /** * Replay a recording read back from storage, whose states and msgs are plain * data not typed as the machine's own. It trusts the host's recording to be * the machine's own: unlike {@link replayTrace}, nothing checks at compile time * that the trace belongs to the machine. Replay only folds and compares them, * so the result's states and msgs are `unknown` data too. * * @param machine - the machine to replay against. * @param trace - a recording read back as plain data, for example by * `JSON.parse`. * @param ctx - optional legacy argument; recorded replay needs no init context. */ declare function replayStoredTrace(machine: Machine, trace: Trace, ctx?: Ctx): ReplayResult; /** * Order-insensitive structural deep-equality — the comparator the * record/replay lane owns, exposed so consumers (e.g. `@demlik/tea/parity`'s * `parityEqual`) reuse it rather than adding a third deep-compare. It is one * of two structural walkers in the package, divergent on purpose: * this `deepEqual` returns a boolean verdict (order-insensitive, for * replay/parity equality), and `devtools`'s `diffState` returns a change list * (for a human-readable diff view) — same shape, two jobs, not one to collapse. * `true` iff `a` and `b` are structurally equal under {@link firstDivergence}'s * walk (object keys compared order-insensitively, arrays index-by-index). */ declare function deepEqual(a: unknown, b: unknown): boolean; /** * @demlik/tea/persistence — `writeTrace`: write a captured `Trace` into a * `Store` as the boundaries a live run would have saved. A drive that records * in memory (`recorder` with `captureSteps: true`) can keep a failed drive's * recording and drop a successful one, instead of writing every drive's. */ /** * Write a captured Trace into a Store as the frames a live run would have * saved: an `init` boundary for `loaded`, then one `step` boundary per * recorded transition, each with the State after it and the Cmds it started. * A store that does not record evidence keeps messages only. * * The recorder's boot observe carries no Cmds, so the `init` frame is written * with `cmds: []`; it equals a live run's `init` frame only when `init` starts * no Cmds. A step recorded without Cmds is written without Cmd evidence. * Throws, before it loads or saves anything, when the trace has no `loaded` * State, when it holds messages but no steps (record with * `captureSteps: true`), or when it has a different number of steps than * messages. */ declare function writeTrace(store: Pick, "load" | "save">, trace: Trace): Promise; /** * @packageDocumentation * @demlik/tea/persistence — the durability batteries: record a run to a trace, * replay that trace back, checkpoint a long-running machine to a host store * between evictions, and keep a machine's State in a store this subpath ships: * `eventSourcedStore`, a durable log over a journal, and `rowStore`, one SQL * row fenced by its revision. * * The persistence operations live under `src/internal/persistence/`. * Journal contract aliases expose the storage door from `src/internal/journal/` * without copying its shape. The persistence modules behind this entry: * * - `log-store` — compose a journal and schemas into the engine-facing durable log. * - `recorder` — capture a run as a `Trace` (plus breadcrumbs and * attachments), sufficient to reproduce it. * - `row-store` — a fenced Store over one SQL row. * - `snapshot` — periodic state checkpoint to a host store, so a long-running * machine resumes from its last checkpoint rather than from the top. * - `trace-replay` — feed a recorded `Trace` back through a machine and report * where, if anywhere, the replay diverged. * - `write-trace` — write a captured `Trace` into a `Store` as the boundaries a * live run would have saved. * * `battery` tier (MAINTAINING.md): a published named pattern over the kernel, * which may break in a minor provided the changelog for that minor says so. */ /** Ordered storage of opaque text in atomic batches. * @experimental */ type Journal = Journal$1; /** A journal with an explicit expected-head append capability. * @experimental */ type FencedJournal = FencedJournal$1; /** Opaque text and the position assigned by its journal. * @experimental */ type JournalEntry = JournalEntry$1; /** A stream's head and the entries after a requested position. * @experimental */ type JournalRead = JournalRead$1; /** Acknowledged text and positions from one atomic append. * @experimental */ type JournalAppend = JournalAppend$1; /** Storage failure data, preserving append uncertainty. * @experimental */ type JournalRefusal = JournalRefusal$1; /** An expected-head mismatch that changed no storage. * @experimental */ type JournalConflict = JournalConflict$1; /** Opaque well-formed Unicode text preserved exactly by a driver. * @experimental */ type EncodedRecord = EncodedRecord$1; export { type EncodedRecord, type FencedJournal, type Journal, type JournalAppend, type JournalConflict, type JournalEntry, type JournalRead, type JournalRefusal, type ReplayResult, type RowPort, type RowStoreOptions, Trace, deepEqual, eventSourcedStore, replayStoredTrace, replayTrace, rowStore, writeTrace };