xstate 6.0.0-alpha.9 → 6.0.0-beta.1

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 +58 -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 +103 -35
  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 -20
  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 +1074 -157
  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 +842 -319
  60. package/dist/declarations/src/types.v6.d.ts +540 -106
  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 -1431
  138. package/dist/xstate.cjs.mjs +23 -13
  139. package/dist/xstate.development.cjs.js +2486 -1431
  140. package/dist/xstate.development.cjs.mjs +23 -13
  141. package/dist/xstate.development.esm.js +2445 -1399
  142. package/dist/xstate.esm.js +2445 -1399
  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 +141 -0
  149. package/docs/api-stability.json +4293 -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 +2080 -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
package/README.md CHANGED
@@ -1,3 +1,78 @@
1
+ # XState v6
2
+
3
+ This package contains **XState v6 alpha**. Its APIs differ from v5.
4
+
5
+ <!-- bundled documentation generated by scripts/build-package-docs.mjs from docs/meta.json -->
6
+
7
+ Before writing code with an installed package, read `docs/index.md` beside this
8
+ README, usually `node_modules/xstate/docs/index.md`. These bundled docs match the
9
+ installed package version.
10
+
11
+ For coding agents, start with `docs/agents.md`. Run `npx xstate docs` to locate
12
+ the installed documentation and read its machine-readable stability manifest.
13
+ The data-only CLI also supports `inspect`, `validate`, `simulate`, `test`,
14
+ `replay` and `diff`; see the agent guide for their contracts and limits.
15
+
16
+ Online, start with the [quick start](https://github.com/statelyai/xstate/blob/next/docs/quick-start.md)
17
+ or the [v5 to v6 migration guide](https://github.com/statelyai/xstate/blob/next/docs/xstate-v5-to-v6.md).
18
+
19
+ <!-- v6 authoring replacements from src/index.ts, src/transitionActions.ts and src/types.ts -->
20
+
21
+ | XState v5 | XState v6 |
22
+ | --- | --- |
23
+ | `assign(...)` | Return a shallow `{ context: { ... } }` patch from a transition, entry or exit function. |
24
+ | `fromPromise(fn)` | `createAsyncLogic({ run: fn })` from `xstate`. |
25
+ | `types: {} as { ... }` | `schemas` with `types<T>()` for type-only schemas or Standard Schema for runtime schemas. |
26
+ | `{ target, guard, actions }` | A transition function that checks its condition and returns `{ target, context }`; queue effects with `enq`. |
27
+
28
+ <!-- quick start using public createMachine and createActor exports from src/index.ts -->
29
+
30
+ ## Quick start
31
+
32
+ ```bash
33
+ npm install xstate@beta
34
+ ```
35
+
36
+ ```ts
37
+ import { createMachine, createActor } from 'xstate';
38
+
39
+ // State machine
40
+ const toggleMachine = createMachine({
41
+ id: 'toggle',
42
+ initial: 'inactive',
43
+ context: {
44
+ count: 0
45
+ },
46
+ states: {
47
+ inactive: {
48
+ on: {
49
+ TOGGLE: { target: 'active' }
50
+ }
51
+ },
52
+ active: {
53
+ entry: ({ context }) => ({
54
+ context: { count: context.count + 1 }
55
+ }),
56
+ on: {
57
+ TOGGLE: { target: 'inactive' }
58
+ }
59
+ }
60
+ }
61
+ });
62
+
63
+ // Actor (instance of the machine logic, like a store)
64
+ const toggleActor = createActor(toggleMachine);
65
+ toggleActor.subscribe((state) => console.log(state.value, state.context));
66
+ toggleActor.start();
67
+ // => logs 'inactive', { count: 0 }
68
+
69
+ toggleActor.send({ type: 'TOGGLE' });
70
+ // => logs 'active', { count: 1 }
71
+
72
+ toggleActor.send({ type: 'TOGGLE' });
73
+ // => logs 'inactive', { count: 1 }
74
+ ```
75
+
1
76
  <p align="center">
2
77
  <br />
3
78
 
@@ -6,20 +81,120 @@
6
81
  <img alt="XState logotype" src="https://raw.githubusercontent.com/statelyai/public-assets/main/logos/xstate-logo-black-nobg.svg" width="200">
7
82
  </picture>
8
83
  <br />
9
- <strong>Actor-based state management & orchestration for complex app logic.</strong> <a href="https://stately.ai/docs">→ Documentation</a>
84
+ <strong>Actor-based state management & orchestration for complex app logic.</strong> <a href="https://github.com/statelyai/xstate/tree/next/docs">→ Documentation</a>
10
85
  <br />
11
86
  <br />
12
87
  </p>
13
88
 
14
- XState is a state management and orchestration solution for JavaScript and TypeScript apps. It has _zero_ dependencies, and is useful for frontend and backend application logic.
89
+ <!-- runtime dependencies and public entry points from package.json -->
90
+
91
+ XState is a state management and orchestration solution for JavaScript and TypeScript apps. The `xstate` package has _zero_ runtime dependencies. XState is useful for frontend and backend application logic.
15
92
 
16
93
  It uses event-driven programming, state machines, statecharts, and the actor model to handle complex logic in predictable, robust, and visual ways. XState provides a powerful and flexible way to manage application and workflow state by allowing developers to model logic as actors and state machines.
17
94
 
95
+ <!-- system-wide emission observation from packages/core/src/setup.ts and packages/core/src/system.ts -->
96
+
97
+ Observe emitted events from root and child actors with `createSystem({ onEmitted })`:
98
+
99
+ ```ts
100
+ import { createMachine, createSystem } from 'xstate';
101
+
102
+ const machine = createMachine({
103
+ entry: (_, enq) => enq.emit({ type: 'started' })
104
+ });
105
+
106
+ const system = createSystem({
107
+ onEmitted: ({ actorRef, event }) => {
108
+ console.log(actorRef.id, event);
109
+ }
110
+ });
111
+
112
+ const root = system.createActor(machine).start();
113
+ ```
114
+
115
+ Use `system.onEmitted(listener)` for a removable subscription. `actor.on(...)`
116
+ observes only that actor. See [actor systems](https://github.com/statelyai/xstate/blob/next/docs/systems.md#observe-emitted-events-across-a-system).
117
+
118
+ <!-- experimental whole-system transitions from packages/core/src/systemTransition.ts -->
119
+
120
+ For pure actor-system simulation, `initialSystemTransition`, `systemTransition`
121
+ and `advanceSystemTime` return an immutable system snapshot and external effects
122
+ as data. Branch or replay actors, messages and virtual timers without starting live
123
+ actors. See [pure system transitions](https://github.com/statelyai/xstate/blob/next/docs/system-transitions.md).
124
+
125
+ <!-- snapshot restoration from packages/core/src/persist/index.ts -->
126
+
127
+ The `xstate/persist` entry point provides `restoreActor(logic, persistedSnapshot, options?)`
128
+ to resume any actor from a persisted snapshot, and `snapshotSchema(machine)` for the
129
+ persisted snapshot contract. See [persistence](https://github.com/statelyai/xstate/blob/next/docs/persistence.md).
130
+
131
+ <!-- durable execution and checkpoint restoration from packages/core/src/durable/index.ts -->
132
+
133
+ For durable hosts, the experimental `xstate/durable` entry point provides
134
+ `createDurable`. Resume a checkpoint with `execution.restore(persistedSnapshot)`
135
+ and execute the returned effects to restart active embedded children and pending
136
+ timers without replaying entry actions. Await `executeEffects()` before persisting
137
+ to retain accepted timer deadlines. The host handles root error snapshots;
138
+ `run()` rejects with the root error. See [durable execution](https://github.com/statelyai/xstate/blob/next/docs/durable-execution.md).
139
+
140
+ <!-- state context refinements from packages/core/src/setup.ts and packages/core/src/State.ts -->
141
+
142
+ For [typestates](https://github.com/statelyai/xstate/blob/next/docs/typestates.md), declare state-level `schemas.context`
143
+ in `setup({ states })`. State functions receive narrowed context, transitions
144
+ check the target context requirements, and `snapshot.matches(...)` narrows
145
+ context when reading snapshots.
146
+
147
+ <!-- typed inline invocation from packages/core/src/setup.ts -->
148
+
149
+ Use `s.createInvoke({ src, input, onDone })` inline in `s.createMachine(...)` for an actor used in one state. It infers the actor's input and output and the enclosing state's narrowed context without registering that actor in `setup.actors`. See [typed inline invokes](https://github.com/statelyai/xstate/blob/next/docs/invoke.md#typed-inline-invokes).
150
+
151
+ Pass an async function directly as `src`, with `schemas.input`, `schemas.output`, and `schemas.error` on the same invoke. Output also infers from the async return when its schema is omitted. Existing logic values use their own schemas.
152
+
153
+ The helper requires input for actors whose input excludes `undefined`, and checks child IDs and source compatibility against `schemas.children` declared in the setup or machine.
154
+
155
+ <!-- graph traversal events from packages/core/src/graph/index.ts -->
156
+
157
+ Graph traversal requires samples for known event types with required payloads. Pass an `events` map such as `{ ADD: [{ value: 1 }, { value: 0 }] }`; each entry also accepts a snapshot callback returning nonempty payload cases. Maps preserve payload-free defaults, invoke completions, errors, and delayed events. Event arrays and callbacks returning events replace all defaults. Coverage remains sample-based. See [model-based testing](https://github.com/statelyai/xstate/blob/next/docs/model-based-testing.md).
158
+
159
+ <!-- JSON loading and runtime validation from packages/core/src/machineFromJSON.ts -->
160
+
161
+ Revive JSON definitions with `machineFromJSON(json, { schemas, validator, ...sources })` to restore runtime validation. The loader validates config keys and references. See [serialization](https://github.com/statelyai/xstate/blob/next/docs/serialization.md).
162
+
163
+ For flat finite state machines, `xstate/fsm` provides a tiny pure transition
164
+ table with context and TypeScript support:
165
+
166
+ <!-- public exports from packages/core/src/fsm/index.ts; exact capabilities documented in docs/fsm.md -->
167
+
168
+ ```ts
169
+ import { createFSM } from 'xstate/fsm';
170
+
171
+ const machine = createFSM({
172
+ initial: 'inactive',
173
+ states: {
174
+ inactive: { on: { toggle: 'active' } },
175
+ active: { on: { toggle: 'inactive' } }
176
+ }
177
+ });
178
+
179
+ let state = machine.initialState;
180
+ [state] = machine.transition(state, { type: 'toggle' });
181
+ ```
182
+
183
+ The FSM is also actor logic, so `createActor(machine)` from `xstate` runs it.
184
+
185
+ For typed context, event payloads, or state-specific context snapshots, use
186
+ `setup` and `types` from `xstate/fsm`. These schemas are type-only in this
187
+ subpath; use root `xstate` for runtime schema validation.
188
+
189
+ See the [exact supported surface](https://stately.ai/docs/fsm). Use the root `xstate`
190
+ entry point for compound or parallel statecharts, invocation, named sources,
191
+ runtime schemas, serialization and inspection.
192
+
18
193
  ### ✨ Create state machines visually in Stately Studio → [state.new](https://state.new)
19
194
 
20
195
  ---
21
196
 
22
- 📖 [Read the documentation](https://stately.ai/docs)
197
+ 📖 [Read the documentation](https://github.com/statelyai/xstate/tree/next/docs)
23
198
 
24
199
  ➡️ [Create state machines with the Stately Editor](https://stately.ai/editor)
25
200
 
@@ -27,9 +202,13 @@ It uses event-driven programming, state machines, statecharts, and the actor mod
27
202
 
28
203
  📑 Inspired by the [SCXML specification](https://www.w3.org/TR/scxml/)
29
204
 
205
+ <!-- public SCXML entry point from packages/xstate-scxml/src/index.ts -->
206
+
207
+ Create machines from SCXML documents with the separate [`@xstate/scxml`](https://www.npmjs.com/package/@xstate/scxml) package. See the [SCXML guide](https://github.com/statelyai/xstate/blob/next/docs/scxml.md).
208
+
30
209
  💬 Chat on the [Stately Discord Community](https://discord.gg/xstate)
31
210
 
32
- ✍️ Browse through the many [XState examples](https://github.com/statelyai/xstate/tree/main/examples)
211
+ ✍️ Browse through the many [XState examples](https://github.com/statelyai/xstate/tree/next/examples)
33
212
 
34
213
  ## Templates
35
214
 
@@ -44,14 +223,14 @@ Get started by forking one of these templates on CodeSandbox:
44
223
  <tr>
45
224
  <td>
46
225
 
47
- [🤖 XState Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/vanilla-ts)
226
+ [🤖 XState Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/vanilla-ts)
48
227
 
49
- [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/main/templates/vanilla-ts?file=%2Fsrc%2FfeedbackMachine.ts)
228
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/vanilla-ts?file=%2Fsrc%2FfeedbackMachine.ts)
50
229
 
51
230
  </td>
52
231
  <td>
53
232
 
54
- - XState v5
233
+ - XState v6 alpha
55
234
  - TypeScript
56
235
  - _No framework_
57
236
 
@@ -61,15 +240,15 @@ Get started by forking one of these templates on CodeSandbox:
61
240
  <tr>
62
241
  <td>
63
242
 
64
- [⚛️ XState + React Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/react-ts)
243
+ [⚛️ XState + React Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/react-ts)
65
244
 
66
- [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/main/templates/react-ts?file=%2Fsrc%2FfeedbackMachine.ts)
245
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/react-ts?file=%2Fsrc%2FfeedbackMachine.ts)
67
246
 
68
247
  </td>
69
248
  <td>
70
249
 
71
250
  - [React](https://react.dev/)
72
- - XState v5
251
+ - XState v6 alpha
73
252
  - TypeScript
74
253
 
75
254
  </td>
@@ -78,15 +257,15 @@ Get started by forking one of these templates on CodeSandbox:
78
257
  <tr>
79
258
  <td>
80
259
 
81
- [💚 XState + Vue Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/vue-ts)
260
+ [💚 XState + Vue Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/vue-ts)
82
261
 
83
- [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/main/templates/vue-ts?file=%2Fsrc%2FfeedbackMachine.ts)
262
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/vue-ts?file=%2Fsrc%2FfeedbackMachine.ts)
84
263
 
85
264
  </td>
86
265
  <td>
87
266
 
88
267
  - [Vue](https://vuejs.org/)
89
- - XState v5
268
+ - XState v6 alpha
90
269
  - TypeScript
91
270
 
92
271
  </td>
@@ -95,15 +274,15 @@ Get started by forking one of these templates on CodeSandbox:
95
274
  <tr>
96
275
  <td>
97
276
 
98
- [🧡 XState + Svelte Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/main/templates/svelte-ts)
277
+ [🧡 XState + Svelte Template (CodeSandbox)](https://codesandbox.io/p/devbox/github/statelyai/xstate/tree/next/templates/svelte-ts)
99
278
 
100
- [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/main/templates/svelte-ts?file=%2Fsrc%2FfeedbackMachine.ts)
279
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/statelyai/xstate/tree/next/templates/svelte-ts?file=%2Fsrc%2FfeedbackMachine.ts)
101
280
 
102
281
  </td>
103
282
  <td>
104
283
 
105
284
  - [Svelte](https://svelte.dev/)
106
- - XState v5
285
+ - XState v6 alpha
107
286
  - TypeScript
108
287
 
109
288
  </td>
@@ -112,52 +291,6 @@ Get started by forking one of these templates on CodeSandbox:
112
291
  </tbody>
113
292
  </table>
114
293
 
115
- ## Super quick start
116
-
117
- ```bash
118
- npm install xstate
119
- ```
120
-
121
- ```ts
122
- import { createMachine, createActor } from 'xstate';
123
-
124
- // State machine
125
- const toggleMachine = createMachine({
126
- id: 'toggle',
127
- initial: 'inactive',
128
- context: {
129
- count: 0
130
- },
131
- states: {
132
- inactive: {
133
- on: {
134
- TOGGLE: { target: 'active' }
135
- }
136
- },
137
- active: {
138
- entry: ({ context }) => ({
139
- context: { count: context.count + 1 }
140
- }),
141
- on: {
142
- TOGGLE: { target: 'inactive' }
143
- }
144
- }
145
- }
146
- });
147
-
148
- // Actor (instance of the machine logic, like a store)
149
- const toggleActor = createActor(toggleMachine);
150
- toggleActor.subscribe((state) => console.log(state.value, state.context));
151
- toggleActor.start();
152
- // => logs 'inactive', { count: 0 }
153
-
154
- toggleActor.send({ type: 'TOGGLE' });
155
- // => logs 'active', { count: 1 }
156
-
157
- toggleActor.send({ type: 'TOGGLE' });
158
- // => logs 'inactive', { count: 1 }
159
- ```
160
-
161
294
  ## [Stately Studio](https://stately.ai)
162
295
 
163
296
  - Visually create, edit, and collaborate on state machines
@@ -166,7 +299,7 @@ toggleActor.send({ type: 'TOGGLE' });
166
299
  - Deploy to Stately Sky
167
300
  - Generate & modify machines with Stately AI
168
301
 
169
- <a href="stately.ai/registry/new?ref=github" title="Stately Studio">
302
+ <a href="https://stately.ai/registry/new?ref=github" title="Stately Studio">
170
303
  <img src="https://github.com/statelyai/xstate/assets/1093738/74ed9cbc-b824-4ed7-a16d-f104947af8a7" alt="XState Viz" width="800" />
171
304
  </a>
172
305
 
@@ -186,10 +319,10 @@ Read [📽 the slides](http://slides.com/davidkhourshid/finite-state-machines) (
186
319
  | Package | Description |
187
320
  | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
188
321
  | 🤖 `xstate` | Core finite state machine and statecharts library + interpreter |
189
- | [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/main/packages/xstate-react) | React hooks and utilities for using XState in React applications |
190
- | [💚 `@xstate/vue`](https://github.com/statelyai/xstate/tree/main/packages/xstate-vue) | Vue composition functions and utilities for using XState in Vue applications |
191
- | [🎷 `@xstate/svelte`](https://github.com/statelyai/xstate/tree/main/packages/xstate-svelte) | Svelte utilities for using XState in Svelte applications |
192
- | [🥏 `@xstate/solid`](https://github.com/statelyai/xstate/tree/main/packages/xstate-solid) | Solid hooks and utilities for using XState in Solid applications |
322
+ | [⚛️ `@xstate/react`](https://github.com/statelyai/xstate/tree/next/packages/xstate-react) | React hooks and utilities for using XState in React applications |
323
+ | [💚 `@xstate/vue`](https://github.com/statelyai/xstate/tree/next/packages/xstate-vue) | Vue composition functions and utilities for using XState in Vue applications |
324
+ | [🎷 `@xstate/svelte`](https://github.com/statelyai/xstate/tree/next/packages/xstate-svelte) | Svelte utilities for using XState in Svelte applications |
325
+ | [🥏 `@xstate/solid`](https://github.com/statelyai/xstate/tree/next/packages/xstate-solid) | Solid hooks and utilities for using XState in Solid applications |
193
326
 
194
327
  ## Finite State Machines
195
328
 
@@ -208,17 +341,17 @@ const lightMachine = createMachine({
208
341
  states: {
209
342
  green: {
210
343
  on: {
211
- TIMER: 'yellow'
344
+ TIMER: { target: 'yellow' }
212
345
  }
213
346
  },
214
347
  yellow: {
215
348
  on: {
216
- TIMER: 'red'
349
+ TIMER: { target: 'red' }
217
350
  }
218
351
  },
219
352
  red: {
220
353
  on: {
221
- TIMER: 'green'
354
+ TIMER: { target: 'green' }
222
355
  }
223
356
  }
224
357
  }
@@ -281,12 +414,12 @@ const pedestrianStates = {
281
414
  states: {
282
415
  walk: {
283
416
  on: {
284
- PED_TIMER: 'wait'
417
+ PED_TIMER: { target: 'wait' }
285
418
  }
286
419
  },
287
420
  wait: {
288
421
  on: {
289
- PED_TIMER: 'stop'
422
+ PED_TIMER: { target: 'stop' }
290
423
  }
291
424
  },
292
425
  stop: {}
@@ -299,17 +432,17 @@ const lightMachine = createMachine({
299
432
  states: {
300
433
  green: {
301
434
  on: {
302
- TIMER: 'yellow'
435
+ TIMER: { target: 'yellow' }
303
436
  }
304
437
  },
305
438
  yellow: {
306
439
  on: {
307
- TIMER: 'red'
440
+ TIMER: { target: 'red' }
308
441
  }
309
442
  },
310
443
  red: {
311
444
  on: {
312
- TIMER: 'green'
445
+ TIMER: { target: 'green' }
313
446
  },
314
447
  ...pedestrianStates
315
448
  }
@@ -485,15 +618,15 @@ const paymentMachine = createMachine({
485
618
  states: {
486
619
  cash: {
487
620
  on: {
488
- SWITCH_CHECK: 'check'
621
+ SWITCH_CHECK: { target: 'check' }
489
622
  }
490
623
  },
491
624
  check: {
492
625
  on: {
493
- SWITCH_CASH: 'cash'
626
+ SWITCH_CASH: { target: 'cash' }
494
627
  }
495
628
  },
496
- hist: { type: 'history' }
629
+ hist: { type: 'history', target: 'cash' }
497
630
  },
498
631
  on: { NEXT: { target: 'review' } }
499
632
  },
@@ -575,3 +708,15 @@ For these reasons, it is impractical for our team to be bound by decisions taken
575
708
  ### Packages
576
709
 
577
710
  Most of the packages in the XState family declare a peer dependency on XState itself. We’ll be cautious about maintaining compatibility with already-released packages when releasing a new version of XState, **but** each release of packages depending on XState will always adjust the declared peer dependency range to include the latest version of XState. For example, you should always be able to update `xstate` without `@xstate/react`. But when you update `@xstate/react`, we highly recommend updating `xstate` too.
711
+
712
+ <!-- public input validation contract from src/StateMachine.ts -->
713
+ Validate external input with `eventSchema(machine)` before `actor.send()`.
714
+ It validates complete public events, excludes internal/runtime events, and allows
715
+ explicitly configured routes. Payload checks require runtime schemas;
716
+ `types<T>()` supplies types only. See [public input validation](https://github.com/statelyai/xstate/blob/next/docs/internal-events.md#validating-public-input).
717
+
718
+ <!-- entry effects and terminal transition behavior from packages/core/src/stateUtils.ts and transitionActions.ts -->
719
+
720
+ Use the `enq` argument in transition, entry and exit functions to queue effects. Return context or child patches from those functions; the return value of an enqueued effect is ignored, with a development warning. See [actions](https://github.com/statelyai/xstate/blob/next/docs/actions.md).
721
+
722
+ For actors that are done, stopped or failed, pure transitions return the same snapshot and no effects, and `snapshot.can(...)` returns `false`. See [snapshots](https://github.com/statelyai/xstate/blob/next/docs/snapshots.md) and [states](https://github.com/statelyai/xstate/blob/next/docs/states.md).