xstate 4.31.0 → 5.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/CHANGELOG.md +526 -0
  2. package/actions/ExecutableAction.ts +58 -0
  3. package/actions/dist/xstate-actions.cjs.d.ts +1 -0
  4. package/actions/dist/xstate-actions.cjs.dev.js +32 -0
  5. package/actions/dist/xstate-actions.cjs.js +7 -0
  6. package/actions/dist/xstate-actions.cjs.prod.js +32 -0
  7. package/actions/dist/xstate-actions.esm.js +2 -0
  8. package/actions/dynamicAction.ts +34 -0
  9. package/actions/package.json +4 -0
  10. package/actors/dist/xstate-actors.cjs.d.ts +1 -0
  11. package/actors/dist/xstate-actors.cjs.dev.js +21 -0
  12. package/actors/dist/xstate-actors.cjs.js +7 -0
  13. package/actors/dist/xstate-actors.cjs.prod.js +21 -0
  14. package/actors/dist/xstate-actors.esm.js +2 -0
  15. package/actors/package.json +4 -0
  16. package/dev/dist/xstate-dev.cjs.d.ts +1 -0
  17. package/dev/dist/xstate-dev.cjs.dev.js +11 -0
  18. package/dev/dist/xstate-dev.cjs.js +7 -0
  19. package/{lib/devTools.js → dev/dist/xstate-dev.cjs.prod.js} +17 -10
  20. package/dev/dist/xstate-dev.esm.js +1 -0
  21. package/dev/package.json +4 -0
  22. package/dist/Machine-9ce74c11.cjs.dev.js +755 -0
  23. package/dist/Machine-dca041dc.cjs.prod.js +749 -0
  24. package/dist/Machine-fb2f47f5.esm.js +751 -0
  25. package/dist/actions-6b86876d.cjs.dev.js +4815 -0
  26. package/dist/actions-70094c93.cjs.prod.js +4765 -0
  27. package/dist/actions-ff512f16.esm.js +4757 -0
  28. package/dist/declarations/actions/ExecutableAction.d.ts +23 -0
  29. package/dist/declarations/actions/dynamicAction.d.ts +3 -0
  30. package/dist/declarations/src/Machine.d.ts +4 -0
  31. package/dist/declarations/src/Mailbox.d.ts +12 -0
  32. package/dist/declarations/src/ObservableActorRef.d.ts +25 -0
  33. package/{lib → dist/declarations/src}/SimulatedClock.d.ts +0 -1
  34. package/dist/declarations/src/State.d.ts +104 -0
  35. package/dist/declarations/src/StateMachine.d.ts +112 -0
  36. package/dist/declarations/src/StateNode.d.ts +127 -0
  37. package/{es → dist/declarations/src}/actionTypes.d.ts +0 -3
  38. package/dist/declarations/src/actions/assign.d.ts +7 -0
  39. package/dist/declarations/src/actions/cancel.d.ts +10 -0
  40. package/dist/declarations/src/actions/choose.d.ts +3 -0
  41. package/dist/declarations/src/actions/invoke.d.ts +3 -0
  42. package/dist/declarations/src/actions/log.d.ts +11 -0
  43. package/dist/declarations/src/actions/pure.d.ts +3 -0
  44. package/dist/declarations/src/actions/raise.d.ts +9 -0
  45. package/dist/declarations/src/actions/send.d.ts +55 -0
  46. package/dist/declarations/src/actions/stop.d.ts +8 -0
  47. package/dist/declarations/src/actions.d.ts +44 -0
  48. package/dist/declarations/src/actors.d.ts +38 -0
  49. package/dist/declarations/src/constants.d.ts +5 -0
  50. package/{lib/devTools.d.ts → dist/declarations/src/dev/index.d.ts} +2 -2
  51. package/{es → dist/declarations/src}/environment.d.ts +0 -1
  52. package/dist/declarations/src/guards.d.ts +9 -0
  53. package/dist/declarations/src/index.d.ts +47 -0
  54. package/dist/declarations/src/interpreter.d.ts +147 -0
  55. package/{es → dist/declarations/src}/mapState.d.ts +0 -1
  56. package/dist/declarations/src/match.d.ts +5 -0
  57. package/dist/declarations/src/memo.d.ts +1 -0
  58. package/dist/declarations/src/model.d.ts +5 -0
  59. package/{lib → dist/declarations/src}/model.types.d.ts +10 -9
  60. package/dist/declarations/src/registry.d.ts +8 -0
  61. package/{es → dist/declarations/src}/schema.d.ts +0 -1
  62. package/dist/declarations/src/spawn.d.ts +2 -0
  63. package/dist/declarations/src/stateUtils.d.ts +85 -0
  64. package/{lib → dist/declarations/src}/typegenTypes.d.ts +28 -26
  65. package/dist/declarations/src/types.d.ts +1026 -0
  66. package/dist/declarations/src/utils.d.ts +56 -0
  67. package/{es/devTools.js → dist/index-20b364c4.esm.js} +18 -6
  68. package/dist/index-2a564d03.cjs.dev.js +64 -0
  69. package/dist/xstate.cjs.d.ts +1 -0
  70. package/dist/xstate.cjs.dev.js +217 -0
  71. package/dist/xstate.cjs.js +7 -0
  72. package/dist/xstate.cjs.prod.js +217 -0
  73. package/dist/xstate.esm.js +172 -0
  74. package/guards/dist/xstate-guards.cjs.d.ts +1 -0
  75. package/guards/dist/xstate-guards.cjs.dev.js +15 -0
  76. package/guards/dist/xstate-guards.cjs.js +7 -0
  77. package/guards/dist/xstate-guards.cjs.prod.js +15 -0
  78. package/guards/dist/xstate-guards.esm.js +2 -0
  79. package/guards/package.json +4 -0
  80. package/invoke/package.json +4 -0
  81. package/model/dist/xstate-model.cjs.d.ts +1 -0
  82. package/model/dist/xstate-model.cjs.dev.js +41 -0
  83. package/model/dist/xstate-model.cjs.js +7 -0
  84. package/model/dist/xstate-model.cjs.prod.js +41 -0
  85. package/model/dist/xstate-model.esm.js +37 -0
  86. package/model/package.json +4 -0
  87. package/package.json +21 -30
  88. package/dist/xstate.interpreter.js +0 -15
  89. package/dist/xstate.js +0 -15
  90. package/dist/xstate.web.js +0 -15
  91. package/es/Actor.d.ts +0 -25
  92. package/es/Actor.js +0 -99
  93. package/es/Machine.d.ts +0 -12
  94. package/es/Machine.js +0 -14
  95. package/es/SimulatedClock.d.ts +0 -17
  96. package/es/SimulatedClock.js +0 -81
  97. package/es/State.d.ts +0 -123
  98. package/es/State.js +0 -274
  99. package/es/StateNode.d.ts +0 -287
  100. package/es/StateNode.js +0 -1566
  101. package/es/_virtual/_tslib.js +0 -78
  102. package/es/actionTypes.js +0 -22
  103. package/es/actions.d.ts +0 -154
  104. package/es/actions.js +0 -520
  105. package/es/behaviors.d.ts +0 -37
  106. package/es/behaviors.js +0 -131
  107. package/es/constants.d.ts +0 -6
  108. package/es/constants.js +0 -6
  109. package/es/devTools.d.ts +0 -14
  110. package/es/each.d.ts +0 -4
  111. package/es/each.js +0 -13
  112. package/es/environment.js +0 -3
  113. package/es/index.d.ts +0 -22
  114. package/es/index.js +0 -23
  115. package/es/interpreter.d.ts +0 -209
  116. package/es/interpreter.js +0 -1402
  117. package/es/invoke.d.ts +0 -11
  118. package/es/invokeUtils.d.ts +0 -7
  119. package/es/invokeUtils.js +0 -40
  120. package/es/json.d.ts +0 -31
  121. package/es/json.js +0 -86
  122. package/es/mapState.js +0 -32
  123. package/es/match.d.ts +0 -9
  124. package/es/match.js +0 -34
  125. package/es/model.d.ts +0 -5
  126. package/es/model.js +0 -50
  127. package/es/model.types.d.ts +0 -52
  128. package/es/patterns.d.ts +0 -14
  129. package/es/patterns.js +0 -48
  130. package/es/registry.d.ts +0 -9
  131. package/es/registry.js +0 -19
  132. package/es/scheduler.d.ts +0 -17
  133. package/es/scheduler.js +0 -79
  134. package/es/schema.js +0 -6
  135. package/es/scxml.d.ts +0 -6
  136. package/es/serviceScope.d.ts +0 -4
  137. package/es/serviceScope.js +0 -16
  138. package/es/stateUtils.d.ts +0 -17
  139. package/es/stateUtils.js +0 -259
  140. package/es/typegenTypes.d.ts +0 -130
  141. package/es/types.d.ts +0 -1037
  142. package/es/types.js +0 -33
  143. package/es/utils.d.ts +0 -72
  144. package/es/utils.js +0 -626
  145. package/es/waitFor.d.ts +0 -32
  146. package/es/waitFor.js +0 -66
  147. package/lib/Actor.d.ts +0 -25
  148. package/lib/Actor.js +0 -108
  149. package/lib/Machine.d.ts +0 -12
  150. package/lib/Machine.js +0 -19
  151. package/lib/SimulatedClock.js +0 -85
  152. package/lib/State.d.ts +0 -123
  153. package/lib/State.js +0 -282
  154. package/lib/StateNode.d.ts +0 -287
  155. package/lib/StateNode.js +0 -1570
  156. package/lib/_virtual/_tslib.js +0 -85
  157. package/lib/actionTypes.d.ts +0 -20
  158. package/lib/actionTypes.js +0 -43
  159. package/lib/actions.d.ts +0 -154
  160. package/lib/actions.js +0 -552
  161. package/lib/behaviors.d.ts +0 -37
  162. package/lib/behaviors.js +0 -137
  163. package/lib/constants.d.ts +0 -6
  164. package/lib/constants.js +0 -13
  165. package/lib/each.d.ts +0 -4
  166. package/lib/each.js +0 -17
  167. package/lib/environment.d.ts +0 -2
  168. package/lib/environment.js +0 -7
  169. package/lib/index.d.ts +0 -22
  170. package/lib/index.js +0 -60
  171. package/lib/interpreter.d.ts +0 -209
  172. package/lib/interpreter.js +0 -1408
  173. package/lib/invoke.d.ts +0 -11
  174. package/lib/invoke.js +0 -20
  175. package/lib/invokeUtils.d.ts +0 -7
  176. package/lib/invokeUtils.js +0 -45
  177. package/lib/json.d.ts +0 -31
  178. package/lib/json.js +0 -94
  179. package/lib/mapState.d.ts +0 -4
  180. package/lib/mapState.js +0 -36
  181. package/lib/match.d.ts +0 -9
  182. package/lib/match.js +0 -38
  183. package/lib/model.d.ts +0 -5
  184. package/lib/model.js +0 -54
  185. package/lib/model.types.js +0 -2
  186. package/lib/patterns.d.ts +0 -14
  187. package/lib/patterns.js +0 -53
  188. package/lib/registry.d.ts +0 -9
  189. package/lib/registry.js +0 -23
  190. package/lib/scheduler.d.ts +0 -17
  191. package/lib/scheduler.js +0 -83
  192. package/lib/schema.d.ts +0 -3
  193. package/lib/schema.js +0 -11
  194. package/lib/scxml.d.ts +0 -6
  195. package/lib/scxml.js +0 -350
  196. package/lib/serviceScope.d.ts +0 -4
  197. package/lib/serviceScope.js +0 -21
  198. package/lib/stateUtils.d.ts +0 -17
  199. package/lib/stateUtils.js +0 -273
  200. package/lib/typegenTypes.js +0 -2
  201. package/lib/types.d.ts +0 -1037
  202. package/lib/types.js +0 -35
  203. package/lib/utils.d.ts +0 -72
  204. package/lib/utils.js +0 -673
  205. package/lib/waitFor.d.ts +0 -32
  206. package/lib/waitFor.js +0 -70
@@ -0,0 +1,23 @@
1
+ import type { State } from '../src/State';
2
+ import { TypegenDisabled } from '../src/typegenTypes';
3
+ import { BaseActionObject, EventObject, MachineContext } from '../src/types';
4
+ export interface ResolvedActionObject<TContext extends MachineContext, TEvent extends EventObject, TResolvedTypesMeta = TypegenDisabled> {
5
+ type: string;
6
+ params: Record<string, any>;
7
+ /**
8
+ * The intermediate context
9
+ */
10
+ context: TContext | undefined;
11
+ execute: (state: State<TContext, TEvent, TResolvedTypesMeta>) => any;
12
+ }
13
+ export declare class ExecutableAction<TContext extends object, TEvent extends EventObject, TResolvedTypesMeta = TypegenDisabled> implements ResolvedActionObject<TContext, TEvent, TResolvedTypesMeta> {
14
+ actionObject: BaseActionObject;
15
+ private _exec?;
16
+ type: string;
17
+ params: Record<string, any>;
18
+ context: TContext | undefined;
19
+ constructor(actionObject: BaseActionObject, _exec?: ((context: TContext, event: TEvent, meta: import("../src/types").ActionMeta<TContext, TEvent, BaseActionObject>) => void) | undefined);
20
+ execute(state: State<TContext, TEvent, TResolvedTypesMeta>): void | undefined;
21
+ setContext(context: TContext): void;
22
+ }
23
+ export declare function isExecutableAction(action: BaseActionObject | ResolvedActionObject<any, any, any>): action is ExecutableAction<any, any, any>;
@@ -0,0 +1,3 @@
1
+ import type { BaseActionObject, BaseDynamicActionObject, EventObject, MachineContext } from '../src/types';
2
+ export declare function createDynamicAction<TContext extends MachineContext, TEvent extends EventObject, TAction extends BaseActionObject, TDynamicParams extends Record<string, any>>(type: `xstate.${string}`, params: TDynamicParams, resolve: BaseDynamicActionObject<TContext, TEvent, TAction, TDynamicParams>['resolve']): BaseDynamicActionObject<TContext, TEvent, TAction, TDynamicParams>;
3
+ export declare function isDynamicAction(action: any): action is BaseDynamicActionObject<any, any, any, any>;
@@ -0,0 +1,4 @@
1
+ import { MachineConfig, EventObject, AnyEventObject, MachineContext, ActorMap, InternalMachineImplementations, BaseActionObject } from './types';
2
+ import { TypegenConstraint, TypegenDisabled, ResolveTypegenMeta } from './typegenTypes';
3
+ import { StateMachine } from './StateMachine';
4
+ export declare function createMachine<TContext extends MachineContext, TEvent extends EventObject = AnyEventObject, TActorMap extends ActorMap = ActorMap, TTypesMeta extends TypegenConstraint = TypegenDisabled>(config: MachineConfig<TContext, TEvent, BaseActionObject, TActorMap, TTypesMeta>, implementations?: InternalMachineImplementations<TContext, TEvent, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TActorMap>>): StateMachine<TContext, TEvent, BaseActionObject, TActorMap, ResolveTypegenMeta<TTypesMeta, TEvent, BaseActionObject, TActorMap>>;
@@ -0,0 +1,12 @@
1
+ export declare class Mailbox<T> {
2
+ private _process;
3
+ private _active;
4
+ private _current;
5
+ private _last;
6
+ constructor(_process: (ev: T) => void);
7
+ start(): void;
8
+ clear(): void;
9
+ prepend(event: T): void;
10
+ enqueue(event: T): void;
11
+ private flush;
12
+ }
@@ -0,0 +1,25 @@
1
+ import { EventObject, ActorRef, Behavior } from './types';
2
+ import { symbolObservable } from './utils';
3
+ export declare class ObservableActorRef<TEvent extends EventObject, TSnapshot> implements ActorRef<TEvent, TSnapshot> {
4
+ private behavior;
5
+ name: string;
6
+ private current;
7
+ private context;
8
+ private mailbox;
9
+ private _observers;
10
+ constructor(behavior: Behavior<TEvent, TSnapshot>, name: string);
11
+ start(): this;
12
+ stop(): this;
13
+ subscribe(observer: any): {
14
+ unsubscribe: () => void;
15
+ };
16
+ send(event: any): void;
17
+ toJSON(): {
18
+ name: string;
19
+ current: TSnapshot;
20
+ };
21
+ getSnapshot(): TSnapshot;
22
+ [symbolObservable](): this;
23
+ private receive;
24
+ private _process;
25
+ }
@@ -14,4 +14,3 @@ export declare class SimulatedClock implements SimulatedClock {
14
14
  clearTimeout(id: number): void;
15
15
  private flushTimeouts;
16
16
  }
17
- //# sourceMappingURL=SimulatedClock.d.ts.map
@@ -0,0 +1,104 @@
1
+ import type { StateMachine } from './StateMachine';
2
+ import type { StateNode } from './StateNode';
3
+ import { TypegenDisabled, TypegenEnabled } from './typegenTypes';
4
+ import type { ActorRef, BaseActionObject, EventObject, HistoryValue, MachineContext, Prop, SCXML, SimpleEventsOf, StateConfig, StateValue, TransitionDefinition } from './types';
5
+ export declare function isStateConfig<TContext extends MachineContext, TEvent extends EventObject>(state: any): state is StateConfig<TContext, TEvent>;
6
+ /**
7
+ * @deprecated Use `isStateConfig(object)` or `state instanceof State` instead.
8
+ */
9
+ export declare const isState: typeof isStateConfig;
10
+ export declare class State<TContext extends MachineContext, TEvent extends EventObject = EventObject, TResolvedTypesMeta = TypegenDisabled> {
11
+ value: StateValue;
12
+ context: TContext;
13
+ historyValue: HistoryValue<TContext, TEvent>;
14
+ actions: BaseActionObject[];
15
+ meta: any;
16
+ event: TEvent;
17
+ _internalQueue: Array<SCXML.Event<TEvent>>;
18
+ _event: SCXML.Event<TEvent>;
19
+ _sessionid: string | null;
20
+ _initial: boolean;
21
+ /**
22
+ * Indicates whether the state has changed from the previous state. A state is considered "changed" if:
23
+ *
24
+ * - Its value is not equal to its previous value, or:
25
+ * - It has any new actions (side-effects) to execute.
26
+ *
27
+ * An initial state (with no history) will return `undefined`.
28
+ */
29
+ changed: boolean | undefined;
30
+ /**
31
+ * The enabled state nodes representative of the state value.
32
+ */
33
+ configuration: Array<StateNode<TContext, TEvent>>;
34
+ /**
35
+ * The transition definitions that resulted in this state.
36
+ */
37
+ transitions: Array<TransitionDefinition<TContext, TEvent>>;
38
+ /**
39
+ * An object mapping actor names to spawned/invoked actors.
40
+ */
41
+ children: Record<string, ActorRef<any>>;
42
+ tags: Set<string>;
43
+ machine: StateMachine<TContext, TEvent, BaseActionObject, any, TResolvedTypesMeta> | undefined;
44
+ /**
45
+ * Creates a new State instance for the given `stateValue` and `context`.
46
+ * @param stateValue
47
+ * @param context
48
+ */
49
+ static from<TContext extends MachineContext, TEvent extends EventObject = EventObject>(stateValue: State<TContext, TEvent, any> | StateValue, context?: TContext): State<TContext, TEvent, any>;
50
+ /**
51
+ * Creates a new State instance for the given `config`.
52
+ * @param config The state config
53
+ */
54
+ static create<TC extends MachineContext, TE extends EventObject = EventObject>(config: StateConfig<TC, TE>): State<TC, TE, any>;
55
+ /**
56
+ * Creates a new `State` instance for the given `stateValue` and `context` with no actions (side-effects).
57
+ * @param stateValue
58
+ * @param context
59
+ */
60
+ static inert<TState extends State<any, any, any>>(state: TState): TState;
61
+ static inert<TContext extends MachineContext, TEvent extends EventObject = EventObject>(stateValue: StateValue, context: TContext): State<TContext, TEvent>;
62
+ /**
63
+ * Creates a new `State` instance that represents the current state of a running machine.
64
+ *
65
+ * @param config
66
+ */
67
+ constructor(config: StateConfig<TContext, TEvent>);
68
+ /**
69
+ * Returns an array of all the string leaf state node paths.
70
+ * @param stateValue
71
+ * @param delimiter The character(s) that separate each subpath in the string state node path.
72
+ */
73
+ toStrings(stateValue?: StateValue, delimiter?: string): string[];
74
+ toJSON(): Omit<this, "toJSON" | "configuration" | "transitions" | "tags" | "machine" | "toStrings" | "matches" | "done" | "hasTag" | "can" | "nextEvents"> & {
75
+ tags: string[];
76
+ };
77
+ /**
78
+ * Whether the current state value is a subset of the given parent state value.
79
+ * @param parentStateValue
80
+ */
81
+ matches<TSV extends TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'matchesStates'> : StateValue>(parentStateValue: TSV): boolean;
82
+ /**
83
+ * Indicates whether the state is a final state.
84
+ */
85
+ get done(): boolean;
86
+ /**
87
+ * Whether the current state configuration has a state node with the specified `tag`.
88
+ * @param tag
89
+ */
90
+ hasTag(tag: TResolvedTypesMeta extends TypegenEnabled ? Prop<Prop<TResolvedTypesMeta, 'resolved'>, 'tags'> : string): boolean;
91
+ /**
92
+ * Determines whether sending the `event` will cause a non-forbidden transition
93
+ * to be selected, even if the transitions have no actions nor
94
+ * change the state value.
95
+ *
96
+ * @param event The event to test
97
+ * @returns Whether the event will cause a transition
98
+ */
99
+ can(event: TEvent | SimpleEventsOf<TEvent>['type']): boolean;
100
+ /**
101
+ * The next events that will cause a transition from the current state.
102
+ */
103
+ get nextEvents(): Array<TEvent['type']>;
104
+ }
@@ -0,0 +1,112 @@
1
+ import { StateFrom } from '.';
2
+ import { State } from './State';
3
+ import { StateNode } from './StateNode';
4
+ import type { AreAllImplementationsAssumedToBeProvided, MarkAllImplementationsAsProvided, ResolveTypegenMeta, TypegenDisabled } from './typegenTypes';
5
+ import type { ActorMap, BaseActionObject, Event, EventObject, InternalMachineImplementations, MachineConfig, MachineContext, MachineImplementationsSimplified, MachineSchema, MaybeLazy, NoInfer, SCXML, StateConfig, StateNodeDefinition, StateValue, Transitions } from './types';
6
+ export declare const NULL_EVENT = "";
7
+ export declare const STATE_IDENTIFIER = "#";
8
+ export declare const WILDCARD = "*";
9
+ export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject = EventObject, TAction extends BaseActionObject = BaseActionObject, TActorMap extends ActorMap = ActorMap, TResolvedTypesMeta = ResolveTypegenMeta<TypegenDisabled, NoInfer<TEvent>, TAction, TActorMap>> {
10
+ /**
11
+ * The raw config used to create the machine.
12
+ */
13
+ config: MachineConfig<TContext, TEvent, any, any, any>;
14
+ private _contextFactory;
15
+ get context(): TContext;
16
+ private getContextAndActions;
17
+ /**
18
+ * The machine's own version.
19
+ */
20
+ version?: string;
21
+ strict: boolean;
22
+ /**
23
+ * The string delimiter for serializing the path to a string. The default is "."
24
+ */
25
+ delimiter: string;
26
+ options: MachineImplementationsSimplified<TContext, TEvent>;
27
+ schema: MachineSchema<TContext, TEvent>;
28
+ __xstatenode: true;
29
+ idMap: Map<string, StateNode<TContext, TEvent>>;
30
+ root: StateNode<TContext, TEvent>;
31
+ key: string;
32
+ states: StateNode<TContext, TEvent>['states'];
33
+ events: Array<TEvent['type']>;
34
+ constructor(
35
+ /**
36
+ * The raw config used to create the machine.
37
+ */
38
+ config: MachineConfig<TContext, TEvent, any, any, any>, options?: MachineImplementationsSimplified<TContext, TEvent>);
39
+ /**
40
+ * Clones this state machine with the provided implementations
41
+ * and merges the `context` (if provided).
42
+ *
43
+ * @param implementations Options (`actions`, `guards`, `actors`, `delays`, `context`)
44
+ * to recursively merge with the existing options.
45
+ *
46
+ * @returns A new `StateMachine` instance with the provided implementations.
47
+ */
48
+ provide(implementations: InternalMachineImplementations<TContext, TEvent, TResolvedTypesMeta, true> & {
49
+ context?: MaybeLazy<Partial<TContext>>;
50
+ }): StateMachine<TContext, TEvent, TAction, TActorMap, AreAllImplementationsAssumedToBeProvided<TResolvedTypesMeta> extends false ? MarkAllImplementationsAsProvided<TResolvedTypesMeta> : TResolvedTypesMeta>;
51
+ /**
52
+ * Clones this state machine with custom `context`.
53
+ *
54
+ * The `context` provided can be partial `context`, which will be combined with the original `context`.
55
+ *
56
+ * @param context Custom context (will override predefined context, not recursive)
57
+ */
58
+ withContext(context: Partial<TContext>): this;
59
+ /**
60
+ * Resolves the given `state` to a new `State` instance relative to this machine.
61
+ *
62
+ * This ensures that `.nextEvents` represent the correct values.
63
+ *
64
+ * @param state The state to resolve
65
+ */
66
+ resolveState(state: State<TContext, TEvent, TResolvedTypesMeta>): typeof state;
67
+ /**
68
+ * Determines the next state given the current `state` and received `event`.
69
+ * Calculates a full macrostep from all microsteps.
70
+ *
71
+ * @param state The current State instance or state value
72
+ * @param event The received event
73
+ */
74
+ transition(state: StateValue | State<TContext, TEvent, TResolvedTypesMeta> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TResolvedTypesMeta>;
75
+ /**
76
+ * Determines the next state given the current `state` and `event`.
77
+ * Calculates a microstep.
78
+ *
79
+ * @param state The current state
80
+ * @param event The received event
81
+ */
82
+ microstep(state: StateValue | State<TContext, TEvent, TResolvedTypesMeta> | undefined, event: Event<TEvent> | SCXML.Event<TEvent>): State<TContext, TEvent, TResolvedTypesMeta>;
83
+ getTransitionData(state: State<TContext, TEvent, TResolvedTypesMeta>, _event: SCXML.Event<TEvent>): Transitions<TContext, TEvent>;
84
+ /**
85
+ * The initial state _before_ evaluating any microsteps.
86
+ * This "pre-initial" state is provided to initial actions executed in the initial state.
87
+ */
88
+ private get preInitialState();
89
+ /**
90
+ * The initial State instance, which includes all actions to be executed from
91
+ * entering the initial state.
92
+ */
93
+ get initialState(): State<TContext, TEvent, TResolvedTypesMeta>;
94
+ /**
95
+ * Returns the initial `State` instance, with reference to `self` as an `ActorRef`.
96
+ */
97
+ getInitialState(): StateFrom<typeof this>;
98
+ getStateNodeById(stateId: string): StateNode<TContext, TEvent>;
99
+ get definition(): StateNodeDefinition<TContext, TEvent>;
100
+ toJSON(): StateNodeDefinition<TContext, TEvent>;
101
+ createState(stateConfig: State<TContext, TEvent, TResolvedTypesMeta> | StateConfig<TContext, TEvent>): State<TContext, TEvent, TResolvedTypesMeta>;
102
+ /**@deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
103
+ __TContext: TContext;
104
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
105
+ __TEvent: TEvent;
106
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
107
+ __TAction: TAction;
108
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
109
+ __TActorMap: TActorMap;
110
+ /** @deprecated an internal property acting as a "phantom" type, not meant to be used at runtime */
111
+ __TResolvedTypesMeta: TResolvedTypesMeta;
112
+ }
@@ -0,0 +1,127 @@
1
+ import type { Event, EventObject, StateNodeDefinition, TransitionDefinition, DelayedTransitionDefinition, StateNodeConfig, StateNodesConfig, InvokeDefinition, Mapper, PropertyMapper, SCXML, TransitionDefinitionMap, InitialTransitionDefinition, MachineContext, BaseActionObject } from './types';
2
+ import type { State } from './State';
3
+ import type { StateMachine } from './StateMachine';
4
+ interface StateNodeOptions<TContext extends MachineContext, TEvent extends EventObject> {
5
+ _key: string;
6
+ _parent?: StateNode<TContext, TEvent>;
7
+ _machine: StateMachine<TContext, TEvent, any, any, any>;
8
+ }
9
+ export declare class StateNode<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> {
10
+ /**
11
+ * The raw config used to create the machine.
12
+ */
13
+ config: StateNodeConfig<TContext, TEvent>;
14
+ /**
15
+ * The relative key of the state node, which represents its location in the overall state value.
16
+ */
17
+ key: string;
18
+ /**
19
+ * The unique ID of the state node.
20
+ */
21
+ id: string;
22
+ /**
23
+ * The type of this state node:
24
+ *
25
+ * - `'atomic'` - no child state nodes
26
+ * - `'compound'` - nested child state nodes (XOR)
27
+ * - `'parallel'` - orthogonal nested child state nodes (AND)
28
+ * - `'history'` - history state node
29
+ * - `'final'` - final state node
30
+ */
31
+ type: 'atomic' | 'compound' | 'parallel' | 'final' | 'history';
32
+ /**
33
+ * The string path from the root machine node to this node.
34
+ */
35
+ path: string[];
36
+ /**
37
+ * The child state nodes.
38
+ */
39
+ states: StateNodesConfig<TContext, TEvent>;
40
+ /**
41
+ * The type of history on this state node. Can be:
42
+ *
43
+ * - `'shallow'` - recalls only top-level historical state value
44
+ * - `'deep'` - recalls historical state value at all levels
45
+ */
46
+ history: false | 'shallow' | 'deep';
47
+ /**
48
+ * The action(s) to be executed upon entering the state node.
49
+ */
50
+ entry: BaseActionObject[];
51
+ /**
52
+ * The action(s) to be executed upon exiting the state node.
53
+ */
54
+ exit: BaseActionObject[];
55
+ /**
56
+ * The parent state node.
57
+ */
58
+ parent?: StateNode<TContext, TEvent>;
59
+ /**
60
+ * The root machine node.
61
+ */
62
+ machine: StateMachine<TContext, TEvent, any, any>;
63
+ /**
64
+ * The meta data associated with this state node, which will be returned in State instances.
65
+ */
66
+ meta?: any;
67
+ /**
68
+ * The data sent with the "done.state._id_" event if this is a final state node.
69
+ */
70
+ doneData?: Mapper<TContext, TEvent, any> | PropertyMapper<TContext, TEvent, any>;
71
+ /**
72
+ * The order this state node appears. Corresponds to the implicit SCXML document order.
73
+ */
74
+ order: number;
75
+ description?: string;
76
+ tags: string[];
77
+ transitions: Array<TransitionDefinition<TContext, TEvent>>;
78
+ always?: Array<TransitionDefinition<TContext, TEvent>>;
79
+ constructor(
80
+ /**
81
+ * The raw config used to create the machine.
82
+ */
83
+ config: StateNodeConfig<TContext, TEvent>, options: StateNodeOptions<TContext, TEvent>);
84
+ _initialize(): void;
85
+ /**
86
+ * The well-structured state node definition.
87
+ */
88
+ get definition(): StateNodeDefinition<TContext, TEvent>;
89
+ toJSON(): StateNodeDefinition<TContext, TEvent>;
90
+ /**
91
+ * The behaviors invoked as actors by this state node.
92
+ */
93
+ get invoke(): Array<InvokeDefinition<TContext, TEvent>>;
94
+ /**
95
+ * The mapping of events to transitions.
96
+ */
97
+ get on(): TransitionDefinitionMap<TContext, TEvent>;
98
+ get after(): Array<DelayedTransitionDefinition<TContext, TEvent>>;
99
+ get initial(): InitialTransitionDefinition<TContext, TEvent>;
100
+ /**
101
+ * Returns `true` if this state node explicitly handles the given event.
102
+ *
103
+ * @param event The event in question
104
+ */
105
+ handles(event: Event<TEvent>): boolean;
106
+ next(state: State<TContext, TEvent>, _event: SCXML.Event<TEvent>): TransitionDefinition<TContext, TEvent>[] | undefined;
107
+ /**
108
+ * The target state value of the history state node, if it exists. This represents the
109
+ * default state value to transition to if no history value exists yet.
110
+ */
111
+ get target(): string | undefined;
112
+ /**
113
+ * All the state node IDs of this state node and its descendant state nodes.
114
+ */
115
+ get stateIds(): string[];
116
+ /**
117
+ * All the event types accepted by this state node and its descendants.
118
+ */
119
+ get events(): Array<TEvent['type']>;
120
+ /**
121
+ * All the events that have transitions directly from this state node.
122
+ *
123
+ * Excludes any inert events.
124
+ */
125
+ get ownEvents(): Array<TEvent['type']>;
126
+ }
127
+ export {};
@@ -1,10 +1,8 @@
1
1
  import { ActionTypes } from './types';
2
- export declare const start = ActionTypes.Start;
3
2
  export declare const stop = ActionTypes.Stop;
4
3
  export declare const raise = ActionTypes.Raise;
5
4
  export declare const send = ActionTypes.Send;
6
5
  export declare const cancel = ActionTypes.Cancel;
7
- export declare const nullEvent = ActionTypes.NullEvent;
8
6
  export declare const assign = ActionTypes.Assign;
9
7
  export declare const after = ActionTypes.After;
10
8
  export declare const doneState = ActionTypes.DoneState;
@@ -17,4 +15,3 @@ export declare const error = ActionTypes.ErrorCustom;
17
15
  export declare const update = ActionTypes.Update;
18
16
  export declare const choose = ActionTypes.Choose;
19
17
  export declare const pure = ActionTypes.Pure;
20
- //# sourceMappingURL=actionTypes.d.ts.map
@@ -0,0 +1,7 @@
1
+ import type { EventObject, Assigner, PropertyAssigner, MachineContext, DynamicAssignAction } from '../types';
2
+ /**
3
+ * Updates the current context of the machine.
4
+ *
5
+ * @param assignment An object that represents the partial context to update.
6
+ */
7
+ export declare function assign<TContext extends MachineContext, TEvent extends EventObject = EventObject, TAssignment extends Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent> = Assigner<TContext, TEvent> | PropertyAssigner<TContext, TEvent>>(assignment: TAssignment): DynamicAssignAction<TContext, TEvent>;
@@ -0,0 +1,10 @@
1
+ import { EventObject, ExprWithMeta, MachineContext } from '../types';
2
+ import { BaseDynamicActionObject, CancelActionObject, DynamicCancelActionObject } from '..';
3
+ /**
4
+ * Cancels an in-flight `send(...)` action. A canceled sent action will not
5
+ * be executed, nor will its event be sent, unless it has already been sent
6
+ * (e.g., if `cancel(...)` is called after the `send(...)` action's `delay`).
7
+ *
8
+ * @param sendId The `id` of the `send(...)` action to cancel.
9
+ */
10
+ export declare function cancel<TContext extends MachineContext, TEvent extends EventObject>(sendId: string | ExprWithMeta<TContext, TEvent, string>): BaseDynamicActionObject<TContext, TEvent, CancelActionObject, DynamicCancelActionObject<TContext, TEvent>['params']>;
@@ -0,0 +1,3 @@
1
+ import { EventObject, ChooseCondition, MachineContext } from '../types';
2
+ import { BaseDynamicActionObject, ChooseAction, ResolvedChooseAction } from '..';
3
+ export declare function choose<TContext extends MachineContext, TEvent extends EventObject>(guards: Array<ChooseCondition<TContext, TEvent>>): BaseDynamicActionObject<TContext, TEvent, ResolvedChooseAction, ChooseAction<TContext, TEvent>['params']>;
@@ -0,0 +1,3 @@
1
+ import { EventObject, InvokeDefinition, MachineContext } from '../types';
2
+ import { BaseDynamicActionObject, DynamicInvokeActionObject, InvokeActionObject } from '..';
3
+ export declare function invoke<TContext extends MachineContext, TEvent extends EventObject>(invokeDef: InvokeDefinition<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, InvokeActionObject, DynamicInvokeActionObject<TContext, TEvent>['params']>;
@@ -0,0 +1,11 @@
1
+ import { EventObject, LogExpr, MachineContext, LogActionObject } from '../types';
2
+ import { BaseDynamicActionObject, DynamicLogAction } from '..';
3
+ /**
4
+ *
5
+ * @param expr The expression function to evaluate which will be logged.
6
+ * Takes in 2 arguments:
7
+ * - `ctx` - the current state context
8
+ * - `event` - the event that caused this action to be executed.
9
+ * @param label The label to give to the logged expression.
10
+ */
11
+ export declare function log<TContext extends MachineContext, TEvent extends EventObject>(expr?: string | LogExpr<TContext, TEvent>, label?: string): BaseDynamicActionObject<TContext, TEvent, LogActionObject, DynamicLogAction<TContext, TEvent>['params']>;
@@ -0,0 +1,3 @@
1
+ import { EventObject, SingleOrArray, MachineContext } from '../types';
2
+ import { BaseActionObject, BaseDynamicActionObject, DynamicPureActionObject, PureActionObject } from '..';
3
+ export declare function pure<TContext extends MachineContext, TEvent extends EventObject>(getActions: (context: TContext, event: TEvent) => SingleOrArray<BaseActionObject> | undefined): BaseDynamicActionObject<TContext, TEvent, PureActionObject, DynamicPureActionObject<TContext, TEvent>['params']>;
@@ -0,0 +1,9 @@
1
+ import { Event, EventObject, RaiseActionObject } from '../types';
2
+ import { BaseDynamicActionObject } from '..';
3
+ /**
4
+ * Raises an event. This places the event in the internal event queue, so that
5
+ * the event is immediately consumed by the machine in the current step.
6
+ *
7
+ * @param eventType The event to raise.
8
+ */
9
+ export declare function raise<TEvent extends EventObject>(event: Event<TEvent>): BaseDynamicActionObject<any, TEvent, RaiseActionObject<TEvent>, RaiseActionObject<TEvent>['params']>;
@@ -0,0 +1,55 @@
1
+ import { Event, EventObject, SendActionParams, SendExpr, AnyEventObject, MachineContext } from '../types';
2
+ import { AnyActorRef, BaseDynamicActionObject, Cast, EventFrom, ExprWithMeta, InferEvent, SendActionObject, SendActionOptions } from '..';
3
+ /**
4
+ * Sends an event. This returns an action that will be read by an interpreter to
5
+ * send the event in the next step, after the current step is finished executing.
6
+ *
7
+ * @param event The event to send.
8
+ * @param options Options to pass into the send event:
9
+ * - `id` - The unique send event identifier (used with `cancel()`).
10
+ * - `delay` - The number of milliseconds to delay the sending of the event.
11
+ * - `to` - The target of this event (by default, the machine the event was sent from).
12
+ */
13
+ export declare function send<TContext extends MachineContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent>>;
14
+ /**
15
+ * Sends an update event to this machine's parent.
16
+ */
17
+ export declare function sendUpdate<TContext extends MachineContext, TEvent extends EventObject>(): BaseDynamicActionObject<TContext, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
18
+ /**
19
+ * Sends an event to this machine's parent.
20
+ *
21
+ * @param event The event to send to the parent machine.
22
+ * @param options Options to pass into the send event.
23
+ */
24
+ export declare function sendParent<TContext extends MachineContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TSentEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
25
+ /**
26
+ * Sends an event back to the sender of the original event.
27
+ *
28
+ * @param event The event to send back to the sender
29
+ * @param options Options to pass into the send event
30
+ */
31
+ export declare function respond<TContext extends MachineContext, TEvent extends EventObject, TSentEvent extends EventObject = AnyEventObject>(event: Event<TEvent> | SendExpr<TContext, TEvent, TSentEvent>, options?: SendActionOptions<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
32
+ /**
33
+ * Forwards (sends) an event to a specified service.
34
+ *
35
+ * @param target The target service to forward the event to.
36
+ * @param options Options to pass into the send action creator.
37
+ */
38
+ export declare function forwardTo<TContext extends MachineContext, TEvent extends EventObject>(target: Required<SendActionParams<TContext, TEvent>>['to'], options?: SendActionOptions<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
39
+ /**
40
+ * Escalates an error by sending it as an event to this machine's parent.
41
+ *
42
+ * @param errorData The error data to send, or the expression function that
43
+ * takes in the `context`, `event`, and `meta`, and returns the error data to send.
44
+ * @param options Options to pass into the send action creator.
45
+ */
46
+ export declare function escalate<TContext extends MachineContext, TEvent extends EventObject, TErrorData = any>(errorData: TErrorData | ExprWithMeta<TContext, TEvent, TErrorData>, options?: SendActionParams<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
47
+ /**
48
+ * Sends an event to an actor.
49
+ *
50
+ * @param actor The `ActorRef` to send the event to.
51
+ * @param event The event to send, or an expression that evaluates to the event to send
52
+ * @param options Send action options
53
+ * @returns An XState send action object
54
+ */
55
+ export declare function sendTo<TContext extends MachineContext, TEvent extends EventObject, TActor extends AnyActorRef>(actor: (ctx: TContext) => TActor, event: EventFrom<TActor> | SendExpr<TContext, TEvent, InferEvent<Cast<EventFrom<TActor>, EventObject>>>, options?: SendActionOptions<TContext, TEvent>): BaseDynamicActionObject<TContext, TEvent, SendActionObject<AnyEventObject>, SendActionParams<TContext, TEvent, EventObject>>;
@@ -0,0 +1,8 @@
1
+ import { EventObject, ActorRef, Expr, MachineContext } from '../types';
2
+ import { BaseDynamicActionObject, DynamicStopActionObject, StopActionObject } from '..';
3
+ /**
4
+ * Stops an actor.
5
+ *
6
+ * @param actorRef The actor to stop.
7
+ */
8
+ export declare function stop<TContext extends MachineContext, TEvent extends EventObject>(actorRef: string | Expr<TContext, TEvent, ActorRef<any>>): BaseDynamicActionObject<TContext, TEvent, StopActionObject, DynamicStopActionObject<TContext, TEvent>['params']>;
@@ -0,0 +1,44 @@
1
+ import { Action, EventObject, SingleOrArray, ActionType, ActionFunction, ActionFunctionMap, ActionTypes, DoneEvent, ErrorPlatformEvent, DoneEventObject, MachineContext, BaseActionObject } from './types';
2
+ import * as actionTypes from './actionTypes';
3
+ export { send, sendTo, sendUpdate, sendParent, respond, forwardTo, escalate } from './actions/send';
4
+ export { stop } from './actions/stop';
5
+ export { log } from './actions/log';
6
+ export { cancel } from './actions/cancel';
7
+ export { assign } from './actions/assign';
8
+ export { raise } from './actions/raise';
9
+ export { choose } from './actions/choose';
10
+ export { actionTypes };
11
+ export declare const initEvent: import("./types").SCXML.Event<{
12
+ type: ActionTypes;
13
+ }>;
14
+ export declare function getActionFunction<TContext extends MachineContext, TEvent extends EventObject>(actionType: ActionType, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): BaseActionObject | ActionFunction<TContext, TEvent> | undefined;
15
+ export declare function resolveActionObject(actionObject: BaseActionObject, actionFunctionMap?: ActionFunctionMap<any, any>): BaseActionObject;
16
+ export declare function toActionObject<TContext extends MachineContext, TEvent extends EventObject>(action: BaseActionObject | ActionFunction<TContext, TEvent> | string, actionFunctionMap?: ActionFunctionMap<TContext, TEvent>): BaseActionObject;
17
+ export declare const toActionObjects: <TContext extends MachineContext, TEvent extends EventObject>(action?: SingleOrArray<Action<TContext, TEvent>> | undefined, actionFunctionMap?: ActionFunctionMap<TContext, TEvent, BaseActionObject> | undefined) => BaseActionObject[];
18
+ /**
19
+ * Returns an event type that represents an implicit event that
20
+ * is sent after the specified `delay`.
21
+ *
22
+ * @param delayRef The delay in milliseconds
23
+ * @param id The state node ID where this event is handled
24
+ */
25
+ export declare function after(delayRef: number | string, id?: string): string;
26
+ /**
27
+ * Returns an event that represents that a final state node
28
+ * has been reached in the parent state node.
29
+ *
30
+ * @param id The final state node's parent state node `id`
31
+ * @param data The data to pass into the event
32
+ */
33
+ export declare function done(id: string, data?: any): DoneEventObject;
34
+ /**
35
+ * Returns an event that represents that an invoked service has terminated.
36
+ *
37
+ * An invoked service is terminated when it has reached a top-level final state node,
38
+ * but not when it is canceled.
39
+ *
40
+ * @param invokeId The invoked service ID
41
+ * @param data The data to pass into the event
42
+ */
43
+ export declare function doneInvoke(invokeId: string, data?: any): DoneEvent;
44
+ export declare function error(id: string, data?: any): ErrorPlatformEvent & string;