UNPKG

5.56 kBTypeScriptView Raw
1import { MachineSnapshot } from "./State.js";
2import { StateNode } from "./StateNode.js";
3import { AnyActorSystem } from "./system.js";
4import type { ActorLogic, ActorScope, AnyActorRef, AnyActorScope, DoNotInfer, Equals, EventDescriptor, EventObject, HistoryValue, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MetaObject, ParameterizedObject, ProvidedActor, Snapshot, StateMachineDefinition, StateValue, TransitionDefinition, ResolvedStateMachineTypes, StateSchema, SnapshotStatus } from "./types.js";
5export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor, TAction extends ParameterizedObject, TGuard extends ParameterizedObject, TDelay extends string, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TConfig extends StateSchema> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, TInput, AnyActorSystem, TEmitted> {
6 /** The raw config used to create the machine. */
7 config: MachineConfig<TContext, TEvent, any, any, any, any, any, any, TOutput, any, // TEmitted
8 any> & {
9 schemas?: unknown;
10 };
11 /** The machine's own version. */
12 version?: string;
13 schemas: unknown;
14 implementations: MachineImplementationsSimplified<TContext, TEvent>;
15 root: StateNode<TContext, TEvent>;
16 id: string;
17 states: StateNode<TContext, TEvent>['states'];
18 events: Array<EventDescriptor<TEvent>>;
19 constructor(
20 /** The raw config used to create the machine. */
21 config: MachineConfig<TContext, TEvent, any, any, any, any, any, any, TOutput, any, // TEmitted
22 any> & {
23 schemas?: unknown;
24 }, implementations?: MachineImplementationsSimplified<TContext, TEvent>);
25 /**
26 * Clones this state machine with the provided implementations and merges the
27 * `context` (if provided).
28 *
29 * @param implementations Options (`actions`, `guards`, `actors`, `delays`,
30 * `context`) to recursively merge with the existing options.
31 * @returns A new `StateMachine` instance with the provided implementations.
32 */
33 provide(implementations: InternalMachineImplementations<ResolvedStateMachineTypes<TContext, DoNotInfer<TEvent>, TActor, TAction, TGuard, TDelay, TTag, TEmitted>>): StateMachine<TContext, TEvent, TChildren, TActor, TAction, TGuard, TDelay, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig>;
34 resolveState(config: {
35 value: StateValue;
36 context?: TContext;
37 historyValue?: HistoryValue<TContext, TEvent>;
38 status?: SnapshotStatus;
39 output?: TOutput;
40 error?: unknown;
41 } & (Equals<TContext, MachineContext> extends false ? {
42 context: unknown;
43 } : {})): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>;
44 /**
45 * Determines the next snapshot given the current `snapshot` and received
46 * `event`. Calculates a full macrostep from all microsteps.
47 *
48 * @param snapshot The current snapshot
49 * @param event The received event
50 */
51 transition(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, actorScope: ActorScope<typeof snapshot, TEvent, AnyActorSystem, TEmitted>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>;
52 /**
53 * Determines the next state given the current `state` and `event`. Calculates
54 * a microstep.
55 *
56 * @param state The current state
57 * @param event The received event
58 */
59 microstep(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, actorScope: AnyActorScope): Array<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>>;
60 getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent): Array<TransitionDefinition<TContext, TEvent>>;
61 /**
62 * The initial state _before_ evaluating any microsteps. This "pre-initial"
63 * state is provided to initial actions executed in the initial state.
64 */
65 private getPreInitialState;
66 /**
67 * Returns the initial `State` instance, with reference to `self` as an
68 * `ActorRef`.
69 */
70 getInitialSnapshot(actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>, input?: TInput): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>;
71 start(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>): void;
72 getStateNodeById(stateId: string): StateNode<TContext, TEvent>;
73 get definition(): StateMachineDefinition<TContext, TEvent>;
74 toJSON(): StateMachineDefinition<TContext, TEvent>;
75 getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, options?: unknown): Snapshot<unknown>;
76 restoreSnapshot(snapshot: Snapshot<unknown>, _actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>;
77}