import { b as Cmd, c as Sub, M as Machine } from './core-sEWVgnpI.js'; /** * One unit in a fold trace — the four pieces of data a property * invariant typically asserts on. `prev` is the state before the msg * applied; `next` is the state after; `cmds` is the cmds emitted by this * single step (NOT the running total). */ interface Step { readonly prev: S; readonly msg: M; readonly next: S; readonly cmds: readonly C[]; } /** * What {@link foldEvents} hands back: every state in order, one {@link Step} per * Msg, the final state, and the Cmds `init` sent. A law reads one of these. */ interface Fold { readonly states: readonly S[]; readonly steps: readonly Step[]; readonly finalState: S; readonly initCmds: readonly C[]; } /** * Fold a Msg sequence through a machine's pure reducer, returning the * per-step trace, every state in order, the final state, and the Cmds `init` * sent. Initial state comes from `replay(machine, { msgs: [], ctx, loaded })` * — i.e. `machine.init(loaded ?? null, ctx)` faithfully. Init's emitted cmds * are NOT included in any `Step` (they're the boot moment, not a Msg): they * come back as `initCmds`, on a fresh start and on a loaded state alike. * * @param machine The machine under test. * @param ctx The Ctx — typically `stubCtxThrowingProxy()` when * init is pure. Pass a real ctx if init reads from it. * @param loaded Optional pre-init snapshot (the `loaded` arg to * `machine.init`). Defaults to `null` (fresh boot). * @param msgs The Msg sequence to fold. * * @example * ```ts * import type { Machine } from "@demlik/tea"; * import { foldEvents } from "@demlik/tea/pbt"; * * type State = { _tag: "idle" } | { _tag: "counting"; n: number } | { _tag: "stopped" }; * type Msg = { _tag: "start" } | { _tag: "tick" } | { _tag: "stop" }; * interface Ctx { readonly tabId: number } * declare const machine: Machine; * declare const ctx: Ctx; * * const { states, steps, finalState } = foldEvents(machine, ctx, null, [ * { _tag: "start" }, { _tag: "tick" }, { _tag: "stop" }, * ]); * // steps[1] = { prev: { _tag: "counting", n: 0 }, msg: { _tag: "tick" }, ... } * ``` */ declare function foldEvents(machine: Machine, ctx: NoInfer, loaded: NoInfer | null, msgs: readonly NoInfer[]): Fold; /** * What a broken law says. `report` names the fold that broke it. `reason` is the * string the check returned to say why, or `null` when it returned `false`. * * @experimental */ interface LawBreak { readonly report: string; readonly reason: string | null; } /** * The law `propertyTerminates` runs: the fold's final state is one `terminal` * accepts. `terminal` also gets the Cmds `init` sent. * * @example * ```ts * import type { Machine } from "@demlik/tea"; * import { foldEvents, lawTerminates } from "@demlik/tea/pbt"; * * type State = { _tag: "idle" } | { _tag: "done" }; * type Msg = { _tag: "finish" }; * declare const machine: Machine; * * const fold = foldEvents(machine, {}, null, [{ _tag: "finish" }]); * lawTerminates(fold, (s) => s._tag === "done"); // null when it holds * ``` * * @experimental */ declare function lawTerminates(fold: Fold, terminal: (state: NoInfer, initCmds: readonly NoInfer[]) => boolean): LawBreak | null; /** * The law `propertyInvariant` runs: `invariant` holds on every step of the fold. * Return `true` or `null` to accept, `false` or a string saying why to break. It * stops at the first step that breaks, and the report names that step. The second * argument is the Cmds `init` sent. * * @example * ```ts * import type { Machine } from "@demlik/tea"; * import { foldEvents, lawInvariant } from "@demlik/tea/pbt"; * * type State = { readonly n: number }; * type Msg = { _tag: "inc" }; * declare const machine: Machine; * * const fold = foldEvents(machine, {}, null, [{ _tag: "inc" }]); * lawInvariant(fold, ({ prev, next }) => next.n > prev.n || "n did not grow"); * ``` * * @experimental */ declare function lawInvariant(fold: Fold, invariant: (step: Step, NoInfer, NoInfer>, initCmds: readonly NoInfer[]) => boolean | string | null): LawBreak | null; /** * The law `propertyTrace` runs: `predicate` holds on the fold's steps and final * state together. Return `true` or `null` to accept, `false` or a string saying * why to break. The last argument is the Cmds `init` sent. * * @example * ```ts * import type { Machine } from "@demlik/tea"; * import { foldEvents, lawTrace } from "@demlik/tea/pbt"; * * type State = { _tag: "open" } | { _tag: "done" }; * type Msg = { _tag: "close" }; * declare const machine: Machine; * * const fold = foldEvents(machine, {}, null, [{ _tag: "close" }]); * lawTrace(fold, (steps, final) => final._tag !== "done" || steps.length > 0); * ``` * * @experimental */ declare function lawTrace(fold: Fold, predicate: (steps: readonly Step, NoInfer, NoInfer>[], finalState: NoInfer, initCmds: readonly NoInfer[]) => boolean | string | null): LawBreak | null; export { type Fold as F, type LawBreak as L, type Step as S, lawTerminates as a, lawTrace as b, foldEvents as f, lawInvariant as l };