xstate 6.0.0-alpha.8 → 6.0.0-beta.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 (235) hide show
  1. package/README.md +223 -78
  2. package/bin/agent.js +347 -0
  3. package/bin/xstate.js +52 -0
  4. package/dist/createActor-25900f76.cjs.js +7015 -0
  5. package/dist/createActor-551369be.development.esm.js +7175 -0
  6. package/dist/createActor-a49ae0ce.development.cjs.js +7289 -0
  7. package/dist/createActor-cbe3abac.esm.js +6902 -0
  8. package/dist/declarations/src/SimulatedClock.d.ts +2 -1
  9. package/dist/declarations/src/State.d.ts +66 -5
  10. package/dist/declarations/src/StateMachine.d.ts +107 -32
  11. package/dist/declarations/src/StateNode.d.ts +21 -16
  12. package/dist/declarations/src/actions.d.ts +11 -6
  13. package/dist/declarations/src/actors/callback.d.ts +11 -2
  14. package/dist/declarations/src/actors/index.d.ts +6 -5
  15. package/dist/declarations/src/actors/listener.d.ts +8 -3
  16. package/dist/declarations/src/actors/logic.d.ts +42 -52
  17. package/dist/declarations/src/actors/observable.d.ts +15 -2
  18. package/dist/declarations/src/actors/promise.d.ts +90 -22
  19. package/dist/declarations/src/actors/subscription.d.ts +9 -3
  20. package/dist/declarations/src/assert.d.ts +1 -0
  21. package/dist/declarations/src/base.types.d.ts +102 -0
  22. package/dist/declarations/src/createActor.d.ts +101 -27
  23. package/dist/declarations/src/createMachine.d.ts +38 -17
  24. package/dist/declarations/src/delay.d.ts +8 -0
  25. package/dist/declarations/src/durable/index.d.ts +231 -0
  26. package/dist/declarations/src/effectDescriptor.d.ts +95 -0
  27. package/dist/declarations/src/eventTypes.d.ts +9 -0
  28. package/dist/declarations/src/fsm/index.d.ts +2 -0
  29. package/dist/declarations/src/fsm.d.ts +169 -0
  30. package/dist/declarations/src/graph/adjacency.d.ts +6 -3
  31. package/dist/declarations/src/graph/graph.d.ts +6 -3
  32. package/dist/declarations/src/graph/index.d.ts +2 -3
  33. package/dist/declarations/src/graph/pathFromEvents.d.ts +5 -2
  34. package/dist/declarations/src/graph/shortestPaths.d.ts +5 -3
  35. package/dist/declarations/src/graph/simplePaths.d.ts +5 -3
  36. package/dist/declarations/src/graph/types.d.ts +113 -59
  37. package/dist/declarations/src/hotSwap.d.ts +18 -0
  38. package/dist/declarations/src/index.d.ts +28 -19
  39. package/dist/declarations/src/inspection.d.ts +24 -1
  40. package/dist/declarations/src/machineFromJSON.d.ts +171 -0
  41. package/dist/declarations/src/machineSchemas.d.ts +27 -0
  42. package/dist/declarations/src/machineVersion.types.d.ts +53 -0
  43. package/dist/declarations/src/machineVersions.d.ts +103 -0
  44. package/dist/declarations/src/mapState.d.ts +2 -0
  45. package/dist/declarations/src/persist/index.d.ts +36 -0
  46. package/dist/declarations/src/persistedSnapshotValidation.d.ts +18 -0
  47. package/dist/declarations/src/runtimeHelpers.d.ts +43 -0
  48. package/dist/declarations/src/schema.types.d.ts +31 -4
  49. package/dist/declarations/src/serialize.d.ts +39 -28
  50. package/dist/declarations/src/setup.d.ts +1086 -147
  51. package/dist/declarations/src/spawn.d.ts +6 -4
  52. package/dist/declarations/src/stateUtils.d.ts +57 -14
  53. package/dist/declarations/src/system.d.ts +178 -17
  54. package/dist/declarations/src/systemTransition.d.ts +108 -0
  55. package/dist/declarations/src/toPromise.d.ts +1 -0
  56. package/dist/declarations/src/transition.d.ts +48 -10
  57. package/dist/declarations/src/transitionActions.d.ts +22 -4
  58. package/dist/declarations/src/typeUtils.d.ts +51 -0
  59. package/dist/declarations/src/types.d.ts +835 -318
  60. package/dist/declarations/src/types.v6.d.ts +547 -104
  61. package/dist/declarations/src/utils.d.ts +38 -8
  62. package/dist/declarations/src/validation/index.d.ts +49 -0
  63. package/dist/declarations/src/validation.types.d.ts +29 -0
  64. package/dist/declarations/src/waitFor.d.ts +1 -0
  65. package/dist/effectDescriptor-2fa27c54.cjs.js +351 -0
  66. package/dist/effectDescriptor-321a8ce9.development.esm.js +343 -0
  67. package/dist/effectDescriptor-d8b0f749.esm.js +343 -0
  68. package/dist/effectDescriptor-f73da4ec.development.cjs.js +351 -0
  69. package/dist/machineSchemas-45c21bc2.esm.js +1292 -0
  70. package/dist/machineSchemas-6d96bef4.development.cjs.js +1379 -0
  71. package/dist/machineSchemas-88d01821.cjs.js +1300 -0
  72. package/dist/machineSchemas-b5736804.development.esm.js +1371 -0
  73. package/dist/schema.types-0ecd17b8.esm.js +71 -0
  74. package/dist/schema.types-15a68ddc.cjs.js +74 -0
  75. package/dist/schema.types-1c16f035.development.cjs.js +74 -0
  76. package/dist/schema.types-1cd4652e.development.esm.js +71 -0
  77. package/dist/validation-05f1d517.esm.js +8 -0
  78. package/dist/validation-4561b43c.cjs.js +10 -0
  79. package/dist/validation-e69470ad.development.esm.js +8 -0
  80. package/dist/validation-f2714a35.development.cjs.js +10 -0
  81. package/dist/xstate-actors.cjs.js +1068 -12
  82. package/dist/xstate-actors.cjs.mjs +2 -4
  83. package/dist/xstate-actors.development.cjs.js +1068 -12
  84. package/dist/xstate-actors.development.cjs.mjs +2 -4
  85. package/dist/xstate-actors.development.esm.js +1064 -1
  86. package/dist/xstate-actors.esm.js +1064 -1
  87. package/dist/xstate-actors.umd.min.js +1 -1
  88. package/dist/xstate-actors.umd.min.js.map +1 -1
  89. package/dist/xstate-durable.cjs.d.mts +2 -0
  90. package/dist/xstate-durable.cjs.d.ts +2 -0
  91. package/dist/xstate-durable.cjs.js +513 -0
  92. package/dist/xstate-durable.cjs.mjs +5 -0
  93. package/dist/xstate-durable.development.cjs.js +513 -0
  94. package/dist/xstate-durable.development.cjs.mjs +5 -0
  95. package/dist/xstate-durable.development.esm.js +507 -0
  96. package/dist/xstate-durable.esm.js +507 -0
  97. package/dist/xstate-durable.umd.min.js +2 -0
  98. package/dist/xstate-durable.umd.min.js.map +1 -0
  99. package/dist/xstate-fsm.cjs.d.mts +2 -0
  100. package/dist/xstate-fsm.cjs.d.ts +2 -0
  101. package/dist/xstate-fsm.cjs.js +111 -0
  102. package/dist/xstate-fsm.cjs.mjs +5 -0
  103. package/dist/xstate-fsm.development.cjs.js +111 -0
  104. package/dist/xstate-fsm.development.cjs.mjs +5 -0
  105. package/dist/xstate-fsm.development.esm.js +105 -0
  106. package/dist/xstate-fsm.esm.js +105 -0
  107. package/dist/xstate-fsm.umd.min.js +2 -0
  108. package/dist/xstate-fsm.umd.min.js.map +1 -0
  109. package/dist/xstate-graph.cjs.js +173 -457
  110. package/dist/xstate-graph.cjs.mjs +2 -5
  111. package/dist/xstate-graph.development.cjs.js +173 -457
  112. package/dist/xstate-graph.development.cjs.mjs +2 -5
  113. package/dist/xstate-graph.development.esm.js +171 -451
  114. package/dist/xstate-graph.esm.js +171 -451
  115. package/dist/xstate-graph.umd.min.js +1 -1
  116. package/dist/xstate-graph.umd.min.js.map +1 -1
  117. package/dist/xstate-persist.cjs.d.mts +2 -0
  118. package/dist/xstate-persist.cjs.d.ts +2 -0
  119. package/dist/xstate-persist.cjs.js +314 -0
  120. package/dist/xstate-persist.cjs.mjs +6 -0
  121. package/dist/xstate-persist.development.cjs.js +325 -0
  122. package/dist/xstate-persist.development.cjs.mjs +6 -0
  123. package/dist/xstate-persist.development.esm.js +319 -0
  124. package/dist/xstate-persist.esm.js +308 -0
  125. package/dist/xstate-persist.umd.min.js +2 -0
  126. package/dist/xstate-persist.umd.min.js.map +1 -0
  127. package/dist/xstate-validation.cjs.d.mts +2 -0
  128. package/dist/xstate-validation.cjs.d.ts +2 -0
  129. package/dist/xstate-validation.cjs.js +330 -0
  130. package/dist/xstate-validation.cjs.mjs +5 -0
  131. package/dist/xstate-validation.development.cjs.js +330 -0
  132. package/dist/xstate-validation.development.cjs.mjs +5 -0
  133. package/dist/xstate-validation.development.esm.js +324 -0
  134. package/dist/xstate-validation.esm.js +324 -0
  135. package/dist/xstate-validation.umd.min.js +2 -0
  136. package/dist/xstate-validation.umd.min.js.map +1 -0
  137. package/dist/xstate.cjs.js +2486 -1430
  138. package/dist/xstate.cjs.mjs +23 -13
  139. package/dist/xstate.development.cjs.js +2486 -1430
  140. package/dist/xstate.development.cjs.mjs +23 -13
  141. package/dist/xstate.development.esm.js +2445 -1398
  142. package/dist/xstate.esm.js +2445 -1398
  143. package/dist/xstate.umd.min.js +1 -1
  144. package/dist/xstate.umd.min.js.map +1 -1
  145. package/docs/actions.md +75 -0
  146. package/docs/actor-logic.md +250 -0
  147. package/docs/actors.md +64 -0
  148. package/docs/agents.md +132 -0
  149. package/docs/api-stability.json +4287 -0
  150. package/docs/async-logic.md +75 -0
  151. package/docs/async-requests.md +157 -0
  152. package/docs/backend-workflows.md +124 -0
  153. package/docs/cancellation.md +42 -0
  154. package/docs/cheatsheet.md +563 -0
  155. package/docs/choice-states.md +109 -0
  156. package/docs/choose-xstate.md +47 -0
  157. package/docs/configuration.md +161 -0
  158. package/docs/context.md +67 -0
  159. package/docs/create-actor.md +159 -0
  160. package/docs/data-and-effects.md +48 -0
  161. package/docs/delays.md +81 -0
  162. package/docs/durable-execution.md +520 -0
  163. package/docs/emitted-events.md +146 -0
  164. package/docs/errors.md +812 -0
  165. package/docs/examples.md +75 -0
  166. package/docs/faq.md +60 -0
  167. package/docs/final-states.md +149 -0
  168. package/docs/forms-and-wizards.md +166 -0
  169. package/docs/frameworks.md +69 -0
  170. package/docs/fsm.md +164 -0
  171. package/docs/glossary.md +68 -0
  172. package/docs/guards.md +137 -0
  173. package/docs/history-states.md +161 -0
  174. package/docs/how-xstate-runs-machines.md +86 -0
  175. package/docs/index.md +74 -0
  176. package/docs/input-output.md +69 -0
  177. package/docs/inspect-actor-systems.md +118 -0
  178. package/docs/inspection.md +75 -0
  179. package/docs/internal-events.md +156 -0
  180. package/docs/invoke.md +371 -0
  181. package/docs/lifecycle-and-errors.md +48 -0
  182. package/docs/listen-and-subscribe.md +126 -0
  183. package/docs/model-based-testing.md +321 -0
  184. package/docs/modeling.md +40 -0
  185. package/docs/parallel-states.md +182 -0
  186. package/docs/persist-and-restore-actors.md +120 -0
  187. package/docs/persistence.md +312 -0
  188. package/docs/quick-start.md +55 -0
  189. package/docs/retries-and-timeouts.md +122 -0
  190. package/docs/route-states.md +104 -0
  191. package/docs/scxml.md +92 -0
  192. package/docs/selectors.md +99 -0
  193. package/docs/serialization.md +127 -0
  194. package/docs/setup-and-provide.md +273 -0
  195. package/docs/snapshots.md +134 -0
  196. package/docs/spawn.md +212 -0
  197. package/docs/state-input.md +162 -0
  198. package/docs/statecharts.md +54 -0
  199. package/docs/states-events-transitions.md +82 -0
  200. package/docs/states.md +168 -0
  201. package/docs/system-transitions.md +172 -0
  202. package/docs/systems.md +166 -0
  203. package/docs/testing.md +152 -0
  204. package/docs/timeouts.md +125 -0
  205. package/docs/transition-functions.md +89 -0
  206. package/docs/transitions.md +187 -0
  207. package/docs/troubleshooting.md +56 -0
  208. package/docs/tutorial.md +481 -0
  209. package/docs/typescript.md +213 -0
  210. package/docs/typestates.md +112 -0
  211. package/docs/utilities.md +39 -0
  212. package/docs/why-state-machines.md +59 -0
  213. package/docs/xstate-v5-to-v6.md +1923 -0
  214. package/docs/your-first-machine.md +79 -0
  215. package/durable/package.json +8 -0
  216. package/fsm/package.json +8 -0
  217. package/package.json +72 -10
  218. package/persist/package.json +8 -0
  219. package/validation/package.json +8 -0
  220. package/actions/package.json +0 -8
  221. package/dev/package.json +0 -8
  222. package/dist/StateMachine-0aa98f54.development.esm.js +0 -746
  223. package/dist/StateMachine-aef700df.cjs.js +0 -732
  224. package/dist/StateMachine-d4931336.esm.js +0 -729
  225. package/dist/StateMachine-da872dde.development.cjs.js +0 -749
  226. package/dist/declarations/src/createMachineFromConfig.d.ts +0 -177
  227. package/dist/declarations/src/getNextSnapshot.d.ts +0 -37
  228. package/dist/declarations/src/graph/TestModel.d.ts +0 -70
  229. package/dist/declarations/src/graph/pathGenerators.d.ts +0 -4
  230. package/dist/index-219cb621.development.cjs.js +0 -4476
  231. package/dist/index-2f2fbd9b.development.esm.js +0 -4421
  232. package/dist/index-559ceab3.cjs.js +0 -4437
  233. package/dist/index-8828376f.esm.js +0 -4382
  234. package/guards/package.json +0 -8
  235. package/invoke/package.json +0 -4
@@ -1,4 +1,5 @@
1
1
  import { Clock } from "./system.js";
2
+ /** @public */
2
3
  export interface SimulatedClock extends Clock {
3
4
  start(speed: number): void;
4
5
  increment(ms: number): void;
@@ -6,10 +7,10 @@ export interface SimulatedClock extends Clock {
6
7
  }
7
8
  export declare class SimulatedClock implements SimulatedClock {
8
9
  private timeouts;
10
+ private readonly deadlines;
9
11
  private _now;
10
12
  private _id;
11
13
  private _flushing;
12
- private _flushingInvalidated;
13
14
  now(): number;
14
15
  private getId;
15
16
  setTimeout(fn: (...args: any[]) => void, timeout: number): number;
@@ -1,5 +1,51 @@
1
- import type { AnyMachineSnapshot, AnyStateMachine, EventObject, HistoryValue, MachineContext, StateConfig, StateValue, AnyActorRef, Snapshot, MetaObject, StateSchema, StateId, StateIdInputs, StateContextFromStateValue, SnapshotStatus, AnyStateNode } from "./types.js";
1
+ import type { AnyMachineSnapshot, AnyStateMachine, AnyActor, EventObject, HistoryValue, MachineContext, StateConfig, StateValue, StateValueMap, AnyActorRef, Snapshot, MetaObject, StateSchema, StateId, StateIdInputs, StateContextFromStateValue, StateIdReference, SnapshotStatus, AnyStateNode, LogicalTimer } from "./types.js";
2
+ export declare function freezeContext(value: any, visiting?: Set<object>): void;
3
+ /** @public */
2
4
  export declare function isMachineSnapshot(value: unknown): value is AnyMachineSnapshot;
5
+ type Values<T> = T[keyof T];
6
+ type MatchingObjectStateValue<TStateValue extends Record<string, unknown>, TTestStateValue extends Record<string, unknown>> = false extends Values<{
7
+ [K in keyof TTestStateValue]: K extends keyof TStateValue ? NonNullable<TStateValue[K]> extends StateValue ? NonNullable<TTestStateValue[K]> extends StateValue ? [
8
+ MatchingStateValue<NonNullable<TStateValue[K]>, NonNullable<TTestStateValue[K]>>
9
+ ] extends [never] ? false : true : false : false : false;
10
+ }> ? never : {
11
+ [K in keyof TStateValue]: K extends keyof TTestStateValue ? MatchingStateValue<NonNullable<TStateValue[K]>, NonNullable<TTestStateValue[K]>> : TStateValue[K];
12
+ };
13
+ type MatchingStateValue<TStateValue extends StateValue, TTestStateValue extends StateValue> = StateValue extends TTestStateValue ? TStateValue : string extends TTestStateValue ? TStateValue : TStateValue extends unknown ? TTestStateValue extends string ? TStateValue extends string ? TTestStateValue extends TStateValue ? TTestStateValue : Extract<TStateValue, TTestStateValue> : TStateValue extends Record<string, unknown> ? TStateValue & Record<TTestStateValue, StateValue | undefined> : never : TTestStateValue extends Record<string, unknown> ? TStateValue extends Record<string, unknown> ? MatchingObjectStateValue<TStateValue, TTestStateValue> : never : never : never;
14
+ type StateValuePath<TStateValue extends StateValue> = TStateValue extends StateValueMap ? {
15
+ [K in keyof TStateValue & string]: K | (NonNullable<TStateValue[K]> extends infer TChild extends StateValue ? `${K}.${StateValuePath<TChild>}` : never);
16
+ }[keyof TStateValue & string] : TStateValue;
17
+ /**
18
+ * The values that `snapshot.matches(...)` accepts for a state value: a state
19
+ * key, a dot-delimited path to a descendant state, or a partial state value.
20
+ * Non-literal state values accept any value.
21
+ */
22
+ export type ToTestStateValue<TStateValue extends StateValue> = StateValue extends TStateValue ? StateValue : TStateValue extends string ? TStateValue : TStateValue extends StateValueMap ? string extends keyof TStateValue ? StateValue : StateValuePath<TStateValue> | {
23
+ [K in keyof TStateValue]?: NonNullable<TStateValue[K]> extends infer TChild extends StateValue ? ToTestStateValue<TChild> : never;
24
+ } : never;
25
+ /**
26
+ * `true` if `TTestStateValue` can match `TStateValue`, checked per position:
27
+ * each literal key names a state at its level and each literal child matches
28
+ * that state. A non-literal value (`string`, or a map with `string` keys)
29
+ * passes at its own position only, so `{ checkout: string }` is accepted and
30
+ * `{ nope: 'payment', checkout: string }` is not.
31
+ */
32
+ type IsTestStateValueValid<TStateValue extends StateValue, TTestStateValue> = StateValue extends TStateValue ? true : string extends TTestStateValue ? true : TTestStateValue extends string ? [TTestStateValue] extends [StateValuePath<TStateValue>] ? true : false : TTestStateValue extends StateValueMap ? string extends keyof TTestStateValue ? true : true extends (TStateValue extends StateValueMap ? IsTestStateValueMapValid<TStateValue, TTestStateValue> : never) ? true : false : false;
33
+ type IsTestStateValueMapValid<TStateValueMap extends StateValueMap, TTestStateValue extends StateValueMap> = [Exclude<keyof TTestStateValue, keyof TStateValueMap>] extends [never] ? false extends {
34
+ [K in keyof TTestStateValue]-?: IsTestStateValueValid<NonNullable<TStateValueMap[K & keyof TStateValueMap]>, NonNullable<TTestStateValue[K]>>;
35
+ }[keyof TTestStateValue] ? false : true : false;
36
+ /**
37
+ * `unknown` if `matches(...)` accepts `TTestStateValue` for `TStateValue`,
38
+ * otherwise `never`. Literal values must name states; a non-literal value
39
+ * (such as a `string` leaf) is accepted at its own position.
40
+ */
41
+ export type TestStateValueCheck<TStateValue extends StateValue, TTestStateValue extends StateValue> = [TTestStateValue] extends [ToTestStateValue<TStateValue>] ? unknown : false extends IsTestStateValueValid<TStateValue, TTestStateValue> ? never : unknown;
42
+ /**
43
+ * The `#id` references a snapshot (or union of snapshots) accepts, read from
44
+ * its `getMeta()` keys so the overload does not depend on the state schema.
45
+ */
46
+ type SnapshotStateIdReference<TSnapshot> = TSnapshot extends {
47
+ getMeta: () => Record<infer TStateId, any>;
48
+ } ? string extends TStateId ? `#${string}` : `#${Exclude<TStateId, ''> & string}` : `#${string}`;
3
49
  interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, _TOutput, TMeta extends MetaObject, TStateSchema extends StateSchema = StateSchema> {
4
50
  /** The state machine that produced this state snapshot. */
5
51
  machine: AnyStateMachine;
@@ -33,16 +79,27 @@ interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends Ev
33
79
  context: TContext;
34
80
  historyValue: Readonly<HistoryValue>;
35
81
  /** The enabled state nodes representative of the state value. */
36
- _nodes: Array<AnyStateNode>;
82
+ nodes: Array<AnyStateNode>;
37
83
  /** An object mapping actor names to spawned/invoked actors. */
38
84
  children: TChildren;
85
+ /** Pending logical timers owned by this machine snapshot. */
86
+ timers: readonly LogicalTimer[];
39
87
  /**
40
88
  * Whether the current state value is a subset of the given partial state
41
- * value.
89
+ * value, or, for a `'#id'` reference, whether the state node with that `id`
90
+ * is active.
42
91
  *
43
92
  * @param partialStateValue
44
93
  */
45
- matches<const TTestStateValue extends StateValue>(partialStateValue: TTestStateValue): this is MachineSnapshot<StateContextFromStateValue<TStateSchema, TContext, TTestStateValue>, TEvent, TChildren, TStateValue, TTag, _TOutput, TMeta, TStateSchema>;
94
+ matches<const TTestStateId extends StateIdReference<TStateSchema>>(stateId: TTestStateId): boolean;
95
+ matches<const TTestStateValue extends Extract<ToTestStateValue<TStateValue>, string>>(partialStateValue: TTestStateValue, ...args: string extends TTestStateValue ? [never] : []): this is MachineSnapshot<StateContextFromStateValue<TStateSchema, TContext, TTestStateValue>, TEvent, TChildren, MatchingStateValue<TStateValue, TTestStateValue>, TTag, _TOutput, TMeta, TStateSchema>;
96
+ matches<const TTestStateValue extends Extract<ToTestStateValue<TStateValue>, StateValueMap>>(partialStateValue: TTestStateValue, ...args: string extends keyof TTestStateValue ? [never] : []): this is MachineSnapshot<StateContextFromStateValue<TStateSchema, TContext, TTestStateValue>, TEvent, TChildren, MatchingStateValue<TStateValue, TTestStateValue>, TTag, _TOutput, TMeta, TStateSchema>;
97
+ matches<TSnapshot extends {
98
+ value: StateValue;
99
+ }>(this: TSnapshot, stateId: NoInfer<SnapshotStateIdReference<TSnapshot>>): boolean;
100
+ matches<TSnapshot extends {
101
+ value: StateValue;
102
+ }, const TTestStateValue extends StateValue>(this: TSnapshot, partialStateValue: TTestStateValue & NoInfer<TestStateValueCheck<TSnapshot['value'], TTestStateValue>>): boolean;
46
103
  /**
47
104
  * Whether the current state nodes has a state node with the specified `tag`.
48
105
  *
@@ -54,6 +111,9 @@ interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends Ev
54
111
  * transition to be selected, even if the transitions have no actions nor
55
112
  * change the state value.
56
113
  *
114
+ * Returns false for terminal snapshots. Throws if transition evaluation
115
+ * throws; this dry run does not run onError recovery.
116
+ *
57
117
  * @param event The event to test
58
118
  * @returns Whether the event will cause a transition
59
119
  */
@@ -86,8 +146,9 @@ interface StoppedMachineSnapshot<TContext extends MachineContext, TEvent extends
86
146
  output: undefined;
87
147
  error: undefined;
88
148
  }
149
+ /** @public */
89
150
  export type MachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject, TStateSchema extends StateSchema> = ActiveMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> | DoneMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> | ErrorMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema> | StoppedMachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TStateSchema>;
90
- export declare function createMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TMeta extends MetaObject, TStateSchema extends StateSchema>(config: StateConfig<TContext, TEvent>, machine: AnyStateMachine): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, undefined, TMeta, TStateSchema>;
151
+ export declare function createMachineSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TMeta extends MetaObject, TStateSchema extends StateSchema>(config: StateConfig<TContext, TEvent>, machine: AnyStateMachine, actorRef?: AnyActor): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, undefined, TMeta, TStateSchema>;
91
152
  export declare function cloneMachineSnapshot<TState extends AnyMachineSnapshot>(snapshot: TState, config?: Partial<StateConfig<any, any>>): TState;
92
153
  export declare function getPersistedSnapshot<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TOutput, TMeta extends MetaObject>(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, any>, options?: unknown): Snapshot<unknown>;
93
154
  export {};
@@ -1,44 +1,117 @@
1
1
  import { MachineSnapshot } from "./State.js";
2
2
  import { StateNode } from "./StateNode.js";
3
+ import { type TransitionSelectionResults } from "./stateUtils.js";
3
4
  import { AnyActorSystem } from "./system.js";
4
- import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActor, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EventObject, ExecutableActionObjectFromLogic, HistoryValue, MachineContext, MetaObject, Snapshot, StateValue, StateSchema, SnapshotStatus } from "./types.js";
5
- import { AnyMachineSchemas, Implementations, Next_MachineConfig, MachineOptions } from "./types.v6.js";
6
- export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TConfig extends StateSchema, TActionMap extends Implementations['actions'], TActorMap extends Implementations['actorSources'], TGuardMap extends Implementations['guards'], TDelayMap extends Implementations['delays']> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, TInput, AnyActorSystem, TEmitted> {
5
+ import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActorLogic, AnyActorRef, AnyActorScope, AnyStateMachine, AnyTransitionDefinition, EventDescriptor, EmittedFrom, EventObject, EventFromLogic, ExecutableEffectFrom, HistoryValue, InputFrom, MachineContext, MetaObject, OutputFrom, SnapshotFrom, StateValue, StateSchema, SnapshotStatus } from "./types.js";
6
+ import type { Equals, IsAny } from "./typeUtils.js";
7
+ import { AnyMachineSchemas, DelaySourceMap, GuardSourceMap, Sources, Next_MachineConfig, MachineOptions } from "./types.v6.js";
8
+ import type { ActorLogicValidator } from "./validation.types.js";
9
+ export type CompatibleProvidedActorSource<TExpected extends AnyActorLogic, TActual extends AnyActorLogic> = IsAny<TActual> extends true ? TActual : [OutputFrom<TActual>] extends [OutputFrom<TExpected>] ? [Omit<SnapshotFrom<TActual>, 'input'>] extends [
10
+ Omit<SnapshotFrom<TExpected>, 'input'>
11
+ ] ? [InputFrom<TExpected>] extends [InputFrom<TActual>] ? [EventFromLogic<TExpected>] extends [EventFromLogic<TActual>] ? [EmittedFrom<TActual>] extends [EmittedFrom<TExpected>] ? TActual : never : never : never : never : never;
12
+ type ProvidedActors<TExpectedActorMap extends Sources['actors'], TProvidedActorMap extends Partial<Record<keyof TExpectedActorMap & string, AnyActorLogic>>> = {
13
+ [K in keyof TProvidedActorMap]: K extends keyof TExpectedActorMap ? TProvidedActorMap[K] extends AnyActorLogic ? CompatibleProvidedActorSource<TExpectedActorMap[K], TProvidedActorMap[K]> : never : never;
14
+ };
15
+ type ProvidedSourceMap<TDeclared, TProvided> = {
16
+ [K in keyof TDeclared]: K extends keyof TProvided ? {} extends Pick<TProvided, K> ? TDeclared[K] | Exclude<TProvided[K], undefined> : Exclude<TProvided[K], undefined> : TDeclared[K];
17
+ };
18
+ type DeclaredAction<T> = T extends {
19
+ readonly '~declaredAction'?: infer TDeclared;
20
+ } ? unknown extends TDeclared ? T : Exclude<TDeclared, undefined> : T;
21
+ type ProvidedActionSourceMap<TDeclared, TProvided> = {
22
+ [K in keyof TDeclared]: K extends keyof TProvided ? ({} extends Pick<TProvided, K> ? TDeclared[K] | Exclude<TProvided[K], undefined> : Exclude<TProvided[K], undefined>) & {
23
+ readonly '~declaredAction'?: DeclaredAction<TDeclared[K]>;
24
+ } : TDeclared[K];
25
+ };
26
+ export type ProvidedActionContracts<T> = {
27
+ [K in keyof T]: DeclaredAction<T[K]> extends (...args: infer TArgs) => infer TResult ? (...args: TArgs) => ProvidedActionResult<TResult> : never;
28
+ };
29
+ type ProvidedActionResult<TResult> = void extends TResult ? void : Extract<TResult, ReturnType<Sources['actions'][string]>>;
30
+ export { InvalidSnapshotError } from "./persistedSnapshotValidation.js";
31
+ /** @public */
32
+ export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TConfig extends StateSchema, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TInternalEvent extends EventObject = never, TTransitionMeta extends MetaObject = TMeta> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, TInput, AnyActorSystem, TEmitted> {
7
33
  /** The raw config used to create the machine. */
8
- config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any, any> & {
34
+ config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any, any, any, any> & {
9
35
  schemas?: AnyMachineSchemas;
10
- internalEvents?: readonly string[];
11
36
  };
37
+ validator?: ActorLogicValidator | undefined;
38
+ /**
39
+ * Type-only marker for the actor's internal event protocol. `actor.send` and
40
+ * `actor.trigger` read it to drop internal events from the public protocol,
41
+ * so it must survive `stripInternal` into the published declarations. Not
42
+ * `declare` (the build's babel pipeline rejects declare class fields); the
43
+ * one `undefined` property this emits per machine instance is inert.
44
+ */
45
+ readonly _internalEventType: TInternalEvent;
46
+ /** Type-only marker for transition metadata. Never assigned at runtime. */
47
+ readonly _transitionMetaType: TTransitionMeta;
48
+ /**
49
+ * Type-only marker for the declared input type. `getInitialSnapshot` takes
50
+ * input optionally, so inferring input from it always adds `undefined`;
51
+ * `InputFrom` reads this carrier instead. Method-shaped so it stays
52
+ * bivariant like `getInitialSnapshot`. Never assigned at runtime.
53
+ */
54
+ readonly _inputType: {
55
+ carry(input: TInput): void;
56
+ }['carry'];
57
+ /**
58
+ * Type-level carriers for the machine's source maps and state schema. Type
59
+ * helpers in integration packages read these to walk a machine's declared
60
+ * actions, actors and invoked sources. They are never assigned at runtime.
61
+ */
62
+ readonly _actionMap: TActionMap;
63
+ readonly _actorMap: TActorMap;
64
+ readonly _stateSchema: TConfig;
12
65
  /** The machine's own version. */
13
- version?: string;
14
- schemas: AnyMachineSchemas | undefined;
15
- implementations: Implementations;
66
+ version: TConfig extends {
67
+ version: infer TVersion extends string;
68
+ } ? TVersion : undefined;
69
+ schemas: (TConfig extends {
70
+ schemas: infer TSchemas extends AnyMachineSchemas;
71
+ } ? TSchemas : AnyMachineSchemas) | undefined;
72
+ sources: Sources;
16
73
  /** Runtime options for machine execution. */
17
74
  options: MachineOptions;
18
- root: StateNode<TContext, TEvent>;
19
- id: string;
20
- states: StateNode<TContext, TEvent>['states'];
75
+ root: StateNode<TContext, TEvent, TMeta, TTransitionMeta>;
76
+ /**
77
+ * The machine's `id`, or the empty string when the config declares none.
78
+ * The root state node has this id; a machine without one has no `#id` root.
79
+ */
80
+ id: TConfig extends {
81
+ id: infer TId extends string;
82
+ } ? TId : '';
83
+ states: StateNode<TContext, TEvent, TMeta, TTransitionMeta>['states'];
21
84
  events: Array<EventDescriptor<TEvent>>;
22
85
  internalEventDescriptors: ReadonlyArray<string>;
86
+ /**
87
+ * Adapter hooks for actor-local transition evaluation state. Used by
88
+ * `@xstate/scxml`; not part of the stable API.
89
+ *
90
+ * @experimental
91
+ */
92
+ _microstepHooks?: AnyStateMachine['_microstepHooks'];
23
93
  constructor(
24
94
  /** The raw config used to create the machine. */
25
- config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any, any> & {
95
+ config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any, any, any, any> & {
26
96
  schemas?: AnyMachineSchemas;
27
- internalEvents?: readonly string[];
28
- }, implementations?: Implementations);
97
+ }, sources?: Sources, validator?: ActorLogicValidator | undefined);
29
98
  /**
30
- * Clones this state machine with the provided implementations.
99
+ * Clones this state machine with the provided sources.
31
100
  *
32
- * @param implementations Options (`actions`, `guards`, `actorSources`,
33
- * `delays`) to recursively merge with the existing options.
34
- * @returns A new `StateMachine` instance with the provided implementations.
101
+ * @param sources Options (`actions`, `guards`, `actors`, `delays`) to
102
+ * recursively merge with the existing options.
103
+ * @returns A new `StateMachine` instance with the provided sources.
35
104
  */
36
- provide(implementations: {
37
- actions?: Partial<TActionMap>;
38
- actorSources?: Partial<TActorMap>;
39
- guards?: Partial<TGuardMap>;
40
- delays?: Partial<TDelayMap>;
41
- }): StateMachine<TContext, TEvent, TChildren, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig, TActionMap, TActorMap, TGuardMap, TDelayMap>;
105
+ provide<const TProvidedActorMap extends Partial<Record<keyof TActorMap & string, AnyActorLogic>> = {}, const TProvidedActionMap extends Partial<ProvidedActionContracts<TActionMap>> = {}>(sources: {
106
+ actions?: TProvidedActionMap & Partial<ProvidedActionContracts<TActionMap>> & Record<Exclude<keyof TProvidedActionMap, keyof TActionMap>, never>;
107
+ actors?: TProvidedActorMap & ProvidedActors<TActorMap, TProvidedActorMap>;
108
+ guards?: Partial<TGuardMap> & {
109
+ [K in keyof TGuardMap]?: GuardSourceMap<TContext, TEvent>[string];
110
+ };
111
+ delays?: {
112
+ [K in keyof TDelayMap]?: DelaySourceMap<TContext, TEvent>[string];
113
+ };
114
+ }): StateMachine<TContext, TEvent, TChildren, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig, ProvidedActionSourceMap<TActionMap, TProvidedActionMap>, ProvidedSourceMap<TActorMap, TProvidedActorMap>, TGuardMap, TDelayMap, TInternalEvent, TTransitionMeta>;
42
115
  resolveState(config: {
43
116
  value: StateValue;
44
117
  context?: TContext;
@@ -56,7 +129,10 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
56
129
  * @param snapshot The current snapshot
57
130
  * @param event The received event
58
131
  */
59
- transition(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, actorScope: ActorScope<typeof snapshot, TEvent, AnyActorSystem, TEmitted>): ActorLogicTransitionResult<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, ExecutableActionObjectFromLogic<this>>;
132
+ transition(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, actorScope?: ActorScope<typeof snapshot, TEvent, AnyActorSystem, TEmitted>): ActorLogicTransitionResult<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, ExecutableEffectFrom<this>>;
133
+ private _collectEffects;
134
+ private _attachPureActorRef;
135
+ private _transitionFast;
60
136
  /**
61
137
  * Determines the next state given the current `state` and `event`. Calculates
62
138
  * a microstep.
@@ -65,16 +141,15 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
65
141
  * @param event The received event
66
142
  */
67
143
  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>>;
68
- getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, self: AnyActor): Array<AnyTransitionDefinition>;
144
+ getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, actorScope: AnyActorScope, selectionResults?: TransitionSelectionResults): Array<AnyTransitionDefinition>;
69
145
  isInternalEventType(eventType: string): boolean;
70
146
  /**
71
147
  * Returns the initial `State` instance, with reference to `self` as an
72
148
  * `ActorRef`.
73
149
  */
74
- 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>;
75
- initialTransition(input: TInput | undefined, actorScope: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>): ActorLogicTransitionResult<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, ExecutableActionObjectFromLogic<this>>;
76
- start(snapshot?: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>): void;
77
- getStateNodeById(stateId: string): StateNode<TContext, TEvent>;
78
- getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, options?: unknown): Snapshot<unknown>;
79
- 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>;
150
+ 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>;
151
+ initialTransition(input: TInput | undefined, actorScope?: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>): ActorLogicTransitionResult<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, ExecutableEffectFrom<this>>;
152
+ start(snapshot?: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, actorScope?: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>): void;
153
+ getStateNodeById(stateId: string): StateNode<TContext, TEvent, TMeta, TTransitionMeta>;
154
+ getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, options?: unknown): import("./types.js").Snapshot<unknown>;
80
155
  }
@@ -1,10 +1,13 @@
1
- import type { DelayedTransitionDefinition, EventObject, InitialTransitionDefinition, MachineContext, Mapper, StateNodesConfig, TransitionDefinitionMap, AnyStateMachine, AnyStateNodeConfig, NonReducibleUnknown, EventDescriptor, AnyAction, AnyTransitionDefinition, AnyInvokeDefinition } from "./types.js";
2
- interface StateNodeOptions<TContext extends MachineContext, TEvent extends EventObject> {
1
+ import type { SetupStateSchemas } from "./schema.types.js";
2
+ import type { DelayedTransitionDefinition, EventObject, InitialTransitionDefinition, MachineContext, Mapper, TransitionDefinition, TransitionDefinitionMap, AnyStateMachine, AnyStateNodeConfig, EventDescriptor, AnyAction, InvokeDefinition, MetaObject } from "./types.js";
3
+ import type { NonReducibleUnknown } from "./typeUtils.js";
4
+ interface StateNodeOptions<TStateMeta extends MetaObject, TTransitionMeta extends MetaObject> {
3
5
  _key: string;
4
- _parent?: StateNode<TContext, TEvent>;
6
+ _parent?: StateNode<any, any, TStateMeta, TTransitionMeta>;
5
7
  _machine: AnyStateMachine;
6
8
  }
7
- export declare class StateNode<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject> {
9
+ /** @public */
10
+ export declare class StateNode<TContext extends MachineContext = MachineContext, TEvent extends EventObject = EventObject, TStateMeta extends MetaObject = any, TTransitionMeta extends MetaObject = TStateMeta> {
8
11
  /** The raw config used to create the machine. */
9
12
  config: AnyStateNodeConfig;
10
13
  /**
@@ -28,7 +31,7 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
28
31
  /** The string path from the root machine node to this node. */
29
32
  path: string[];
30
33
  /** The child state nodes. */
31
- states: StateNodesConfig<any, any>;
34
+ states: Record<string, StateNode<TContext, TEvent, TStateMeta, TTransitionMeta>>;
32
35
  /**
33
36
  * The type of history on this state node. Can be:
34
37
  *
@@ -41,17 +44,17 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
41
44
  /** The action(s) to be executed upon exiting the state node. */
42
45
  exit: AnyAction | undefined;
43
46
  /** The parent state node. */
44
- parent?: StateNode<any, any>;
47
+ parent?: StateNode<TContext, TEvent, TStateMeta, TTransitionMeta>;
45
48
  /** The root machine node. */
46
49
  machine: AnyStateMachine;
47
50
  /**
48
51
  * The meta data associated with this state node, which will be returned in
49
52
  * State instances.
50
53
  */
51
- meta?: any;
54
+ meta?: TStateMeta;
52
55
  /**
53
- * The output data sent with the "xstate.done.state._id_" event if this is a
54
- * final state node.
56
+ * The output data sent with the `xstate.done.state` event if this is a final
57
+ * state node.
55
58
  */
56
59
  output?: Mapper<MachineContext, EventObject, unknown, EventObject> | NonReducibleUnknown;
57
60
  /**
@@ -60,17 +63,19 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
60
63
  */
61
64
  order: number;
62
65
  description?: string;
66
+ schemas: SetupStateSchemas | undefined;
63
67
  tags: string[];
64
- transitions: Map<string, AnyTransitionDefinition[]>;
65
- always?: Array<AnyTransitionDefinition>;
66
- invoke: Array<AnyInvokeDefinition>;
67
- on: TransitionDefinitionMap<any, any>;
68
- after: Array<DelayedTransitionDefinition<any, any>>;
68
+ transitions: Map<string, TransitionDefinition<any, any, TTransitionMeta>[]>;
69
+ always?: Array<TransitionDefinition<any, any, TTransitionMeta>>;
70
+ invoke: Array<InvokeDefinition<any, any, any, TTransitionMeta, any, any, any, any>>;
71
+ on: TransitionDefinitionMap<any, any, TTransitionMeta>;
72
+ after: Array<DelayedTransitionDefinition<any, any, TTransitionMeta>>;
69
73
  events: Array<EventDescriptor<any>>;
70
74
  ownEvents: Array<EventDescriptor<any>>;
75
+ private _candidateCache?;
71
76
  constructor(
72
77
  /** The raw config used to create the machine. */
73
- config: AnyStateNodeConfig, options: StateNodeOptions<TContext, TEvent>);
74
- get initial(): InitialTransitionDefinition;
78
+ config: AnyStateNodeConfig, options: StateNodeOptions<TStateMeta, TTransitionMeta>);
79
+ get initial(): InitialTransitionDefinition<TTransitionMeta>;
75
80
  }
76
81
  export {};
@@ -1,14 +1,19 @@
1
- import { AnyActor, AnyActorScope, EventObject } from "./types.js";
1
+ import { type ActorTermination, AnyActor, AnyActorScope, EventObject, TimerKey } from "./types.js";
2
+ export declare function assertSendToEvent(event: EventObject): void;
2
3
  export declare const builtInActions: {
3
- "@xstate.start": (actor: AnyActor) => void;
4
+ "@xstate.spawn": (actor: AnyActor) => any;
5
+ "@xstate.start": (actor: AnyActor) => any;
4
6
  "@xstate.raise": (actorScope: AnyActorScope, event: EventObject, options: {
5
7
  id?: string;
8
+ seq?: number;
6
9
  delay?: number;
7
- }) => void;
10
+ }) => void | PromiseLike<void>;
8
11
  "@xstate.sendTo": (actorScope: AnyActorScope, actor: AnyActor, event: EventObject, options: {
9
12
  id?: string;
13
+ seq?: number;
10
14
  delay?: number;
11
- }) => void;
12
- "@xstate.cancel": (actorScope: AnyActorScope, sendId: string) => void;
13
- "@xstate.stop": (actorScope: AnyActorScope, actor: AnyActor) => void;
15
+ }) => void | PromiseLike<void>;
16
+ "@xstate.cancel": (actorScope: AnyActorScope, key: TimerKey) => void | PromiseLike<void>;
17
+ "@xstate.stop": (actorScope: AnyActorScope, actor: AnyActor) => void | PromiseLike<void>;
18
+ "@xstate.terminate": (actor: AnyActor, termination: ActorTermination) => any;
14
19
  };
@@ -1,6 +1,9 @@
1
1
  import { AnyActorSystem } from "../system.js";
2
- import { ActorLogic, ActorRefFromLogic, AnyEventObject, EventObject, NonReducibleUnknown, Snapshot } from "../types.js";
2
+ import { ActorLogic, ActorRefFrom, AnyEventObject, EventObject, Snapshot } from "../types.js";
3
+ import type { NonReducibleUnknown } from "../typeUtils.js";
3
4
  import { StandardSchemaV1 } from "../schema.types.js";
5
+ import type { ActorLogicValidator } from "../validation.types.js";
6
+ /** @public */
4
7
  export type CallbackSnapshot<TInput> = Snapshot<undefined> & {
5
8
  input: TInput;
6
9
  effects?: Record<string, {
@@ -13,6 +16,7 @@ export type CallbackSnapshot<TInput> = Snapshot<undefined> & {
13
16
  error: unknown;
14
17
  }>;
15
18
  };
19
+ /** @public */
16
20
  export type CallbackActorLogic<TEvent extends EventObject, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject> = ActorLogic<CallbackSnapshot<TInput>, TEvent, TInput, AnyActorSystem, TEmitted>;
17
21
  /**
18
22
  * Represents an actor created by `createCallbackLogic`.
@@ -49,11 +53,13 @@ export type CallbackActorLogic<TEvent extends EventObject, TInput = NonReducible
49
53
  * ```
50
54
  *
51
55
  * @see {@link createCallbackLogic}
56
+ * @public
52
57
  */
53
- export type CallbackActorRef<TEvent extends EventObject, TInput = NonReducibleUnknown> = ActorRefFromLogic<CallbackActorLogic<TEvent, TInput>>;
58
+ export type CallbackActorRef<TEvent extends EventObject, TInput = NonReducibleUnknown> = ActorRefFrom<CallbackActorLogic<TEvent, TInput>>;
54
59
  type Receiver<TEvent extends EventObject> = (listener: {
55
60
  bivarianceHack(event: TEvent): void;
56
61
  }['bivarianceHack']) => void;
62
+ /** @public */
57
63
  export type CallbackLogicFunction<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject> = ({ input, system, self, sendBack, receive, emit }: {
58
64
  /**
59
65
  * Data that was provided to the callback actor
@@ -74,7 +80,9 @@ export type CallbackLogicFunction<TEvent extends EventObject = AnyEventObject, T
74
80
  receive: Receiver<TEvent>;
75
81
  emit: (emitted: TEmitted) => void;
76
82
  }) => (() => void) | void;
83
+ /** @public */
77
84
  export interface CallbackLogicConfig<TEvent extends EventObject = AnyEventObject, TSentEvent extends EventObject = AnyEventObject, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject, TInputSchema extends StandardSchemaV1 = StandardSchemaV1> {
85
+ validator?: ActorLogicValidator;
78
86
  schemas?: {
79
87
  input?: TInputSchema;
80
88
  };
@@ -145,6 +153,7 @@ export interface CallbackLogicConfig<TEvent extends EventObject = AnyEventObject
145
153
  * @returns Callback logic
146
154
  * @see {@link CallbackLogicFunction} for more information about the callback function and its object argument
147
155
  * @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
156
+ * @public
148
157
  */
149
158
  export declare function createCallbackLogic<TEvent extends EventObject, const TInputSchema extends StandardSchemaV1, TEmitted extends EventObject = EventObject>(config: CallbackLogicConfig<TEvent, AnyEventObject, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema> & {
150
159
  schemas: {
@@ -1,9 +1,10 @@
1
1
  import type { ActorFromLogic } from "../types.js";
2
2
  export { createCallbackLogic, type CallbackActorLogic, type CallbackActorRef, type CallbackLogicConfig, type CallbackSnapshot, type CallbackLogicFunction } from "./callback.js";
3
3
  export { createObservableLogic, createEventObservableLogic, type EventObservableLogicConfig, type EventObservableLogicFunction, type ObservableActorLogic, type ObservableActorRef, type ObservableLogicConfig, type ObservableLogicFunction, type ObservableSnapshot } from "./observable.js";
4
- export { createLogic, type LogicActorLogic, type LogicActorRef, type LogicArgs, type LogicConfig, type LogicEffect, type LogicEffectState, type LogicEnqueue, type LogicFunction, type LogicPatch, type LogicSnapshot } from "./logic.js";
5
- export { createAsyncLogic, type AsyncActorLogic, type AsyncActorRef, type AsyncSnapshot, type LogicArgs as AsyncLogicArgs, type LogicConfig as AsyncLogicConfig, type LogicEnqueue as AsyncLogicEnqueue, type LogicFunction as AsyncLogicFunction, TimeoutError } from "./promise.js";
6
- export { createListenerLogic, listenerLogic, type ListenerActorLogic, type ListenerActorRef, type ListenerSnapshot, type ListenerInput } from "./listener.js";
7
- export { createSubscriptionLogic, subscriptionLogic, type SubscriptionActorLogic, type SubscriptionActorRef, type SubscriptionSnapshot, type SubscriptionInput, type SubscriptionMappers } from "./subscription.js";
8
- declare const emptyLogic: import("./logic.js").LogicActorLogic<undefined, undefined, import("../types.js").EventObject, import("../types.js").NonReducibleUnknown, import("../types.js").EventObject>;
4
+ export { createStepLogic, type StepActorLogic, type StepActorRef, type StepLogicArgs, type StepLogicConfig, type StepEffectState, type StepLogicEnqueue, type StepLogicFunction, type StepPatch, type StepSnapshot } from "./logic.js";
5
+ export { createAsyncLogic, type AsyncActorLogic, type AsyncActorRef, type AsyncSnapshot, type AsyncLogicArgs, type AsyncLogicConfig, type AsyncLogicEnqueue, type AsyncLogicFunction, TimeoutError } from "./promise.js";
6
+ export { createListenerLogic, type ListenerActorLogic, type ListenerActorRef, type ListenerSnapshot, type ListenerInput } from "./listener.js";
7
+ export { createSubscriptionLogic, type SubscriptionActorLogic, type SubscriptionActorRef, type SubscriptionSnapshot, type SubscriptionInput, type SubscriptionMappers } from "./subscription.js";
8
+ declare const emptyLogic: import("./logic.js").StepActorLogic<undefined, undefined, import("../base.types.js").EventObject, import("../typeUtils.js").NonReducibleUnknown, import("../base.types.js").EventObject>;
9
+ /** @public */
9
10
  export declare function createEmptyActor(): ActorFromLogic<typeof emptyLogic>;
@@ -1,18 +1,23 @@
1
1
  import { AnyActorSystem } from "../system.js";
2
- import { ActorLogic, ActorRefFromLogic, AnyActor, EventObject, Snapshot } from "../types.js";
2
+ import { ActorLogic, ActorRefFrom, AnyActor, EventObject, Snapshot } from "../types.js";
3
+ /** @public */
3
4
  export type ListenerSnapshot = Snapshot<undefined> & {
4
5
  input: ListenerInput<any, any>;
5
6
  };
7
+ /** @public */
6
8
  export interface ListenerInput<TEmitted extends EventObject, TMappedEvent extends EventObject> {
7
9
  actor: AnyActor;
8
10
  eventType: string;
9
11
  mapper: (event: TEmitted) => TMappedEvent;
10
12
  }
13
+ /** @public */
11
14
  export type ListenerActorLogic<TEmitted extends EventObject = EventObject, TMappedEvent extends EventObject = EventObject> = ActorLogic<ListenerSnapshot, EventObject, ListenerInput<TEmitted, TMappedEvent>, AnyActorSystem, EventObject>;
12
- export type ListenerActorRef<TEmitted extends EventObject = EventObject, TMappedEvent extends EventObject = EventObject> = ActorRefFromLogic<ListenerActorLogic<TEmitted, TMappedEvent>>;
15
+ /** @public */
16
+ export type ListenerActorRef<TEmitted extends EventObject = EventObject, TMappedEvent extends EventObject = EventObject> = ActorRefFrom<ListenerActorLogic<TEmitted, TMappedEvent>>;
13
17
  /**
14
18
  * Creates actor logic for listening to emitted events from another actor. Used
15
19
  * internally by `enq.listen()`.
20
+ *
21
+ * @public
16
22
  */
17
23
  export declare function createListenerLogic<TEmitted extends EventObject = EventObject, TMappedEvent extends EventObject = EventObject>(): ListenerActorLogic<TEmitted, TMappedEvent>;
18
- export declare const listenerLogic: ListenerActorLogic<EventObject, EventObject>;