import type { StateNode } from "./StateNode.js"; import type { StateMachine } from "./StateMachine.js"; import type { ProvidedActor, AnyMachineSnapshot, AnyStateMachine, EventObject, HistoryValue, MachineContext, StateConfig, StateValue, AnyActorRef, Snapshot, ParameterizedObject, IsNever } from "./types.js"; type ToTestStateValue = TStateValue extends string ? TStateValue : IsNever extends true ? never : keyof TStateValue | { [K in keyof TStateValue]?: ToTestStateValue>; }; export declare function isMachineSnapshot(value: unknown): value is AnyMachineSnapshot; interface MachineSnapshotBase, TStateValue extends StateValue, TTag extends string, TOutput, _TUnusedButLeftForCompatReasons = never> { /** * The state machine that produced this state snapshot. */ machine: StateMachine; /** * The tags of the active state nodes that represent the current state value. */ tags: Set; /** * The current state value. * * This represents the active state nodes in the state machine. * - For atomic state nodes, it is a string. * - For compound parent state nodes, it is an object where: * - The key is the parent state node's key * - The value is the current state value of the active child state node(s) * * @example ```ts // single-level state node snapshot.value; // => 'yellow' // nested state nodes snapshot.value; // => { red: 'wait' } ``` */ value: TStateValue; /** * The current status of this snapshot. */ status: 'active' | 'done' | 'error' | 'stopped'; error: unknown; context: TContext; historyValue: Readonly>; /** * The enabled state nodes representative of the state value. */ _nodes: Array>; /** * An object mapping actor names to spawned/invoked actors. */ children: TChildren; /** * Whether the current state value is a subset of the given partial state value. * @param partialStateValue */ matches: (partialStateValue: ToTestStateValue) => boolean; /** * Whether the current state nodes has a state node with the specified `tag`. * @param tag */ hasTag: (tag: TTag) => boolean; /** * Determines whether sending the `event` will cause a non-forbidden transition * to be selected, even if the transitions have no actions nor * change the state value. * * @param event The event to test * @returns Whether the event will cause a transition */ can: (event: TEvent) => boolean; getMeta: () => Record; toJSON: () => unknown; } interface ActiveMachineSnapshot, TStateValue extends StateValue, TTag extends string, TOutput> extends MachineSnapshotBase { status: 'active'; output: undefined; error: undefined; } interface DoneMachineSnapshot, TStateValue extends StateValue, TTag extends string, TOutput> extends MachineSnapshotBase { status: 'done'; output: TOutput; error: undefined; } interface ErrorMachineSnapshot, TStateValue extends StateValue, TTag extends string, TOutput> extends MachineSnapshotBase { status: 'error'; output: undefined; error: unknown; } interface StoppedMachineSnapshot, TStateValue extends StateValue, TTag extends string, TOutput> extends MachineSnapshotBase { status: 'stopped'; output: undefined; error: undefined; } export type MachineSnapshot, TStateValue extends StateValue, TTag extends string, TOutput, _TUnusedButLeftForCompatReasons = never> = ActiveMachineSnapshot | DoneMachineSnapshot | ErrorMachineSnapshot | StoppedMachineSnapshot; export declare function createMachineSnapshot, TStateValue extends StateValue, TTag extends string>(config: StateConfig, machine: AnyStateMachine): MachineSnapshot; export declare function cloneMachineSnapshot(snapshot: TState, config?: Partial>): TState; export declare function getPersistedSnapshot, TStateValue extends StateValue, TTag extends string, TOutput>(snapshot: MachineSnapshot, options?: unknown): Snapshot; export {};