import { C as CtxArg } from './runtime-types-f231H8Gq.js'; /** * The default round bound when `opts.maxRounds` is omitted: **100**. * * A round is one drain of the pending Msgs plus one drain of the Cmds those * folds emitted, so a settling machine costs a handful; 100 is loose enough * that a legitimate retry ladder finishes inside it and tight enough that a * genuine cycle stops rather than hangs. */ declare const DEFAULT_MAX_ROUNDS = 100; /** * One entry of a driven run's history, in dispatch order. * * - `msg` — a Msg folded through the machine's reducer. The seed Msg is the * first entry of every trace; every later one is a settle Msg a handler * returned (or fired through its injected `dispatch`), or a Msg a running * Sub emitted. * - `cmd` — a Cmd handed to an interpret handler. It is recorded BEFORE the * handler runs, so a trace recovered from a failed handler names the Cmd * that failed as its last entry. */ type DriveTraceEntry = { readonly kind: "msg"; readonly msg: M; } | { readonly kind: "cmd"; readonly cmd: C; }; /** What a settled `drive` hands back. */ interface DriveResult { /** The state after the machine went quiet — no Msg pending, no Cmd unperformed. */ readonly state: S; /** * Every Msg folded and every Cmd dispatched, in order. Filtering it to its * `msg` entries and replaying those through `replay` from the same initial * state reproduces {@link DriveResult.state}. */ readonly trace: readonly DriveTraceEntry[]; } /** * `drive`'s `ctx` field. `CtxArg` widened by exactly one case: a machine * declaring `ctx: undefined` in its `types` block — the pure shape every * how-to on this package writes — may omit it too. `CtxArg` alone keeps `ctx` * REQUIRED there, because `{}` is not assignable to `undefined`, which would * make the common pure call site spell `{ ctx: undefined }` to say nothing. * A machine whose `Ctx` carries a field a handler reads still requires it. */ type DriveCtxArg = [undefined] extends [Ctx] ? { readonly ctx?: Ctx; } : CtxArg; /** * The options both `drive`s take. `ctx` is conditionally optional (see * {@link DriveCtxArg}). */ type DriveOptions = DriveCtxArg & { /** * The round bound. Exceeding it fails the drive with * {@link DriveRoundsExceededError}; `drive` never returns a half-driven * state. Defaults to {@link DEFAULT_MAX_ROUNDS} (100). */ readonly maxRounds?: number; /** * The clock that stamps `at` on a `Cmd.define`d Cmd's minted `_ok` / `_err` * Msg — the one `run` takes. Defaults to `Date.now`; pin it for a test that * asserts on `at`. */ readonly clock?: () => number; }; /** * Raised when a driven machine is still emitting work after `maxRounds` rounds. * Follows the tea error dialect (`override readonly name`) and carries a `_tag` * discriminant, so a test branches on it by `instanceof` or on the tag. * * It carries the round count it stopped at and the PARTIAL trace up to that * point, which is what a test needs to see the cycle — the bound alone says * only that one exists. */ declare class DriveRoundsExceededError extends Error { /** The bound that was exceeded. */ readonly maxRounds: number; /** The round the driver stopped at — always `maxRounds + 1`. */ readonly rounds: number; /** Every Msg folded and Cmd dispatched before the driver gave up. */ readonly trace: readonly DriveTraceEntry[]; readonly name = "DriveRoundsExceededError"; readonly _tag: "DriveRoundsExceededError"; constructor( /** The bound that was exceeded. */ maxRounds: number, /** The round the driver stopped at — always `maxRounds + 1`. */ rounds: number, /** Every Msg folded and Cmd dispatched before the driver gave up. */ trace: readonly DriveTraceEntry[]); } /** * Raised when a Cmd reaches `drive` with no handler for its `_tag` in the * handler record. The record's mapped type makes that a compile error at a * well-typed call site; this is the runtime arm for a handler record assembled * dynamically or cast. */ declare class DriveNoHandlerError extends Error { /** The Cmd `_tag` nothing in the handler record answered. */ readonly cmdType: string; /** Every Msg folded and Cmd dispatched before the miss. */ readonly trace: readonly DriveTraceEntry[]; readonly name = "DriveNoHandlerError"; readonly _tag: "DriveNoHandlerError"; constructor( /** The Cmd `_tag` nothing in the handler record answered. */ cmdType: string, /** Every Msg folded and Cmd dispatched before the miss. */ trace: readonly DriveTraceEntry[]); } /** * Read back the partial trace `drive` attached to an error a handler failed * with. Returns `undefined` for anything `drive` did not annotate. * * A failing handler's error leaves `drive` UNSWALLOWED — same value, same * `instanceof`, same `_tag` — so a test that already branches on the handler's * own error type keeps doing so. The trace rides along on a non-enumerable * property so it is recoverable without changing how the error prints or * serializes. */ declare function driveTraceOf(err: unknown): readonly DriveTraceEntry[] | undefined; export { type DriveOptions as D, type DriveResult as a, DEFAULT_MAX_ROUNDS as b, type DriveCtxArg as c, DriveNoHandlerError as d, DriveRoundsExceededError as e, type DriveTraceEntry as f, driveTraceOf as g };