xstate 6.0.0-alpha.63 → 6.0.0-alpha.65

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 (66) hide show
  1. package/README.md +45 -1
  2. package/dist/{createActor-f71670cf.development.cjs.js → createActor-1df42c9e.development.cjs.js} +238 -36
  3. package/dist/{createActor-523a98c7.esm.js → createActor-4629a290.esm.js} +162 -34
  4. package/dist/{createActor-48f753a9.development.esm.js → createActor-8f57b47b.development.esm.js} +234 -37
  5. package/dist/{createActor-eba8226e.cjs.js → createActor-b987e971.cjs.js} +166 -33
  6. package/dist/declarations/src/SimulatedClock.d.ts +1 -1
  7. package/dist/declarations/src/State.d.ts +25 -3
  8. package/dist/declarations/src/StateMachine.d.ts +20 -7
  9. package/dist/declarations/src/actors/promise.d.ts +5 -5
  10. package/dist/declarations/src/createMachine.d.ts +8 -6
  11. package/dist/declarations/src/createMachineFromConfig.d.ts +13 -2
  12. package/dist/declarations/src/durable/index.d.ts +13 -0
  13. package/dist/declarations/src/eventTypes.d.ts +8 -0
  14. package/dist/declarations/src/graph/index.d.ts +1 -0
  15. package/dist/declarations/src/graph/types.d.ts +20 -2
  16. package/dist/declarations/src/index.d.ts +2 -1
  17. package/dist/declarations/src/machineVersions.d.ts +2 -2
  18. package/dist/declarations/src/serialize.d.ts +7 -2
  19. package/dist/declarations/src/setup.d.ts +208 -30
  20. package/dist/declarations/src/systemTransition.d.ts +103 -0
  21. package/dist/declarations/src/types.d.ts +47 -26
  22. package/dist/declarations/src/types.v6.d.ts +18 -8
  23. package/dist/declarations/src/utils.d.ts +9 -0
  24. package/dist/{effectDescriptor-bc9e3e81.cjs.js → effectDescriptor-4cf24593.cjs.js} +1 -1
  25. package/dist/{effectDescriptor-ad75e430.esm.js → effectDescriptor-973fc1ba.esm.js} +1 -1
  26. package/dist/{effectDescriptor-8c87a3e7.development.cjs.js → effectDescriptor-b2b7deaa.development.cjs.js} +1 -1
  27. package/dist/{effectDescriptor-eadf1b25.development.esm.js → effectDescriptor-c4671afc.development.esm.js} +1 -1
  28. package/dist/{index-83f11f07.cjs.js → index-0cf33789.development.cjs.js} +37 -15
  29. package/dist/{index-2a4be1f2.development.esm.js → index-15382daf.development.esm.js} +37 -15
  30. package/dist/{index-211a5dce.esm.js → index-52ad3d45.esm.js} +37 -15
  31. package/dist/{index-3cb56f46.development.cjs.js → index-f201d440.cjs.js} +37 -15
  32. package/dist/xstate-actors.cjs.js +2 -2
  33. package/dist/xstate-actors.development.cjs.js +2 -2
  34. package/dist/xstate-actors.development.esm.js +2 -2
  35. package/dist/xstate-actors.esm.js +2 -2
  36. package/dist/xstate-actors.umd.min.js +1 -1
  37. package/dist/xstate-actors.umd.min.js.map +1 -1
  38. package/dist/xstate-durable.cjs.js +36 -4
  39. package/dist/xstate-durable.development.cjs.js +36 -4
  40. package/dist/xstate-durable.development.esm.js +36 -4
  41. package/dist/xstate-durable.esm.js +36 -4
  42. package/dist/xstate-durable.umd.min.js +1 -1
  43. package/dist/xstate-durable.umd.min.js.map +1 -1
  44. package/dist/xstate-graph.cjs.js +8 -4
  45. package/dist/xstate-graph.cjs.mjs +1 -0
  46. package/dist/xstate-graph.development.cjs.js +8 -4
  47. package/dist/xstate-graph.development.cjs.mjs +1 -0
  48. package/dist/xstate-graph.development.esm.js +8 -4
  49. package/dist/xstate-graph.esm.js +8 -4
  50. package/dist/xstate-graph.umd.min.js +1 -1
  51. package/dist/xstate-graph.umd.min.js.map +1 -1
  52. package/dist/xstate-validation.cjs.js +24 -7
  53. package/dist/xstate-validation.development.cjs.js +24 -7
  54. package/dist/xstate-validation.development.esm.js +24 -7
  55. package/dist/xstate-validation.esm.js +24 -7
  56. package/dist/xstate-validation.umd.min.js +1 -1
  57. package/dist/xstate-validation.umd.min.js.map +1 -1
  58. package/dist/xstate.cjs.js +1316 -291
  59. package/dist/xstate.cjs.mjs +3 -0
  60. package/dist/xstate.development.cjs.js +1335 -291
  61. package/dist/xstate.development.cjs.mjs +3 -0
  62. package/dist/xstate.development.esm.js +1335 -294
  63. package/dist/xstate.esm.js +1316 -294
  64. package/dist/xstate.umd.min.js +1 -1
  65. package/dist/xstate.umd.min.js.map +1 -1
  66. package/package.json +1 -1
@@ -183,6 +183,20 @@ function reportUnhandledError(err) {
183
183
 
184
184
  const symbolObservable = (() => typeof Symbol === 'function' && Symbol.observable || '@@observable')();
185
185
 
186
+ // Runtime metadata stays outside pure snapshots. Timer objects survive unrelated
187
+ // transitions; a cancelled/replaced timer gets a new object and a new deadline.
188
+ const starts = new WeakMap();
189
+
190
+ /** @internal */
191
+ function getTimerStart(timer) {
192
+ return starts.get(timer) ?? timer.startedAt;
193
+ }
194
+
195
+ /** @internal */
196
+ function recordTimerStart(timer, startedAt) {
197
+ starts.set(timer, startedAt);
198
+ }
199
+
186
200
  function assertSendToEvent(event) {
187
201
  if (typeof event === 'string') {
188
202
  throw new Error(`Only event objects may be used with sendTo`);
@@ -240,6 +254,9 @@ function resolveRegisteredActorSource(actors, logic) {
240
254
  return cache.get(logic);
241
255
  }
242
256
 
257
+ /** Static scheduling metadata on actor definitions, never on live actors. @internal */
258
+ const systemLogicMetadata = Symbol('xstate.systemLogicMetadata');
259
+
243
260
  const subscriptions = /* #__PURE__ */new WeakMap();
244
261
 
245
262
  /**
@@ -258,7 +275,7 @@ id) {
258
275
  error: undefined,
259
276
  input
260
277
  }, []];
261
- return {
278
+ const logic = {
262
279
  id,
263
280
  start: (state, {
264
281
  self,
@@ -322,6 +339,12 @@ id) {
322
339
  getPersistedSnapshot: snapshot => snapshot,
323
340
  restoreSnapshot: snapshot => snapshot
324
341
  };
342
+ Object.defineProperty(logic, systemLogicMetadata, {
343
+ value: {
344
+ kind: id
345
+ }
346
+ });
347
+ return logic;
325
348
  }
326
349
 
327
350
  /**
@@ -506,7 +529,8 @@ function withActorScope(args, actorScope) {
506
529
  }
507
530
 
508
531
  function execCustomEffect() {
509
- return this.action?.(...this.args);
532
+ const result = this.action?.(...this.args);
533
+ return result;
510
534
  }
511
535
  function execEmitEffect(runtime = this.source.system) {
512
536
  return runtime.emitEvent(this.source, this.event);
@@ -1028,6 +1052,13 @@ function createTransitionEnqueue(actorScope, actions, internalEvents, actorSubsc
1028
1052
  props[key] = guard(props[key]);
1029
1053
  }
1030
1054
  const enqueue = createEnqueueObject(props, guard((action, ...args) => {
1055
+ // A named action is `undefined` when it has no implementation. Skip it:
1056
+ // an `{ action, args }` record without a function would be emitted as
1057
+ // an event. Speculative passes (`can()`, conflict resolution) run with
1058
+ // `createActors: false`; warn only when the transition really runs.
1059
+ if (typeof action !== 'function') {
1060
+ return;
1061
+ }
1031
1062
  pushBuiltInAction(actions, action, ...args);
1032
1063
  }));
1033
1064
  enqueueClosers.set(enqueue, () => {
@@ -2245,6 +2276,10 @@ function getDelayedTransitions(stateNode) {
2245
2276
  }));
2246
2277
  }
2247
2278
  function formatTransition(stateNode, descriptor, transitionConfig) {
2279
+ const removedKey = getRemovedTransitionKey(transitionConfig);
2280
+ if (removedKey) {
2281
+ throw new Error(`Transition "${descriptor || 'always'}" in state "${stateNode.id}" uses ${removedKey}, which was removed in v6. Use a transition function.`);
2282
+ }
2248
2283
  const normalizedTarget = normalizeTarget(transitionConfig.target);
2249
2284
  const reenter = transitionConfig.reenter ?? false;
2250
2285
  const target = resolveTarget(stateNode, normalizedTarget);
@@ -2255,14 +2290,46 @@ function formatTransition(stateNode, descriptor, transitionConfig) {
2255
2290
  source: stateNode,
2256
2291
  reenter,
2257
2292
  eventType: descriptor,
2258
- toJSON: () => ({
2259
- ...transition,
2260
- source: `#${stateNode.id}`,
2261
- target: target ? target.map(t => `#${t.id}`) : undefined
2262
- })
2293
+ toJSON: () => transitionDefinitionToJSON(transition)
2263
2294
  };
2264
2295
  return transition;
2265
2296
  }
2297
+ function transitionDefinitionToJSON(transition) {
2298
+ const {
2299
+ definition: _,
2300
+ ...serializableTransition
2301
+ } = transition;
2302
+ return {
2303
+ ...serializableTransition,
2304
+ source: `#${transition.source.id}`,
2305
+ target: transition.target?.map(target => `#${target.id}`)
2306
+ };
2307
+ }
2308
+
2309
+ /**
2310
+ * Returns the v5 key of a transition object that v6 would misread, in every
2311
+ * build: `cond` is never read, so the transition would always be taken,
2312
+ * transition `actions` would not run as written, and only a function `guard`
2313
+ * can be called. Development builds explain each key earlier, in
2314
+ * `diagnoseAuthorConfig`. Compiled configs (JSON, SCXML) never set them.
2315
+ */
2316
+ function getRemovedTransitionKey(transitionConfig) {
2317
+ const {
2318
+ cond,
2319
+ actions,
2320
+ guard
2321
+ } = transitionConfig;
2322
+ if (cond !== undefined) {
2323
+ return '"cond"';
2324
+ }
2325
+ if (actions !== undefined) {
2326
+ return '"actions"';
2327
+ }
2328
+ if (guard !== undefined && typeof guard !== 'function') {
2329
+ return 'an object-form "guard"';
2330
+ }
2331
+ return undefined;
2332
+ }
2266
2333
  function isStateNodeDescendantOf(stateNode, ancestor) {
2267
2334
  for (let current = stateNode.parent; current; current = current.parent) {
2268
2335
  if (current === ancestor) {
@@ -2605,12 +2672,18 @@ function removeConflictingTransitions(enabledTransitions, stateNodeSet, snapshot
2605
2672
  }
2606
2673
  function createTransitionResultResolver(snapshot, event, actorScope, resolveActions, selectionResults) {
2607
2674
  let cache;
2608
- return transition => {
2609
- if (!transition.to) {
2610
- return getTransitionResult(transition, snapshot, event, actorScope, {
2611
- resolveActions,
2612
- selectionResult: selectionResults?.get(transition)
2613
- });
2675
+ return (transition, applied) => {
2676
+ if (!transition.to && !applied) {
2677
+ // An object transition's targets are static, so reading them must not
2678
+ // run its `context` and `input` mappers
2679
+ return {
2680
+ targets: transition.target,
2681
+ context: undefined,
2682
+ reenter: transition.reenter,
2683
+ actions: undefined,
2684
+ internalEvents: undefined,
2685
+ input: undefined
2686
+ };
2614
2687
  }
2615
2688
  let result = cache?.get(transition);
2616
2689
  if (!result) {
@@ -2838,13 +2911,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2838
2911
  children: args.children,
2839
2912
  actions: args.actions,
2840
2913
  actors: args.actors,
2914
+ guards: currentSnapshot.machine.sources.guards,
2915
+ delays: currentSnapshot.machine.sources.delays,
2841
2916
  input,
2842
2917
  stateNode
2843
2918
  }, actorScope) : {
2844
2919
  ...args,
2920
+ guards: currentSnapshot.machine.sources.guards,
2921
+ delays: currentSnapshot.machine.sources.delays,
2845
2922
  input,
2846
2923
  stateNode
2847
- }, enqueue), '_special' in transitionFn ? {
2924
+ },
2925
+ // This function runs during action resolution, where enqueued
2926
+ // effects are no longer collected.
2927
+ enqueue), '_special' in transitionFn ? {
2848
2928
  _special: true
2849
2929
  } : {});
2850
2930
  return [[wrappedAction], undefined, undefined];
@@ -2882,7 +2962,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2882
2962
  }
2883
2963
  for (const exitStateNode of statesToExit) {
2884
2964
  const stateInput = getStateInput(currentSnapshot, exitStateNode.id);
2885
- const [exitActions, nextContext, internalEvents] = exitStateNode.exit ? getStateActionsAndContext(exitStateNode.exit, nextState.context, currentSnapshot.children, stateInput, 'exit', exitStateNode) : [[], undefined, undefined];
2965
+ const [exitActions, nextContext, internalEvents] = exitStateNode.exit ? getStateActionsAndContext(exitStateNode.exit, nextState.context, nextState.children, stateInput, 'exit', exitStateNode) : [[], undefined, undefined];
2886
2966
  if (internalEvents?.length) {
2887
2967
  internalQueue.push(...internalEvents);
2888
2968
  }
@@ -2912,11 +2992,20 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
2912
2992
  let context = nextState.context;
2913
2993
  const transitionActions = [];
2914
2994
  const internalEvents = [];
2995
+ const resolvedTransitions = [];
2915
2996
  for (const t of filteredTransitions) {
2916
- if (t.actions) {
2917
- transitionActions.push(...toArray(t.actions));
2997
+ const res = getCurrentTransitionResult(t, true);
2998
+ if (t.to) {
2999
+ const resolvedTransition = {
3000
+ ...t,
3001
+ target: res.targets,
3002
+ definition: t
3003
+ };
3004
+ resolvedTransition.toJSON = () => transitionDefinitionToJSON(resolvedTransition);
3005
+ resolvedTransitions.push(resolvedTransition);
3006
+ } else {
3007
+ resolvedTransitions.push(t);
2918
3008
  }
2919
- const res = getCurrentTransitionResult(t);
2920
3009
  if (res.context !== undefined) {
2921
3010
  context = mergeContextPatch(context, res.context);
2922
3011
  }
@@ -3072,7 +3161,7 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3072
3161
  const {
3073
3162
  targets,
3074
3163
  input
3075
- } = getCurrentTransitionResult(transition);
3164
+ } = getCurrentTransitionResult(transition, true);
3076
3165
  if (input && targets) {
3077
3166
  for (const targetNode of targets.filter(targetNode => enteredTargetsByTransition.get(transition)?.has(targetNode))) {
3078
3167
  stateInputMap[targetNode.id] = input;
@@ -3081,12 +3170,12 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3081
3170
  }
3082
3171
  }
3083
3172
  const completedNodes = new Set();
3084
- const children = {
3085
- ...nextState.children
3086
- };
3087
3173
  for (const stateNodeToEnter of [...statesToEnter].sort((a, b) => a.order - b.order)) {
3088
3174
  mutStateNodeSet.add(stateNodeToEnter);
3089
3175
  const actions = [];
3176
+ // Read the children for each state: the entry actions of the states
3177
+ // entered before this one may have spawned or stopped children.
3178
+ let children = nextState.children;
3090
3179
 
3091
3180
  // Final states are inert, so (as in SCXML) their invocations never
3092
3181
  // start.
@@ -3125,7 +3214,10 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3125
3214
  args: [actor]
3126
3215
  });
3127
3216
  if (invokeDef.id) {
3128
- children[invokeDef.id] = actor;
3217
+ children = {
3218
+ ...children,
3219
+ [invokeDef.id]: actor
3220
+ };
3129
3221
  }
3130
3222
  }
3131
3223
  if (invoked) {
@@ -3245,7 +3337,12 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3245
3337
  nextStateNodesToExit.forEach(stateNode => {
3246
3338
  if (stateNode.exit) {
3247
3339
  const stateInput = getStateInput(nextState, stateNode.id);
3248
- const [exitActions,, nextInternalEvents] = getStateActionsAndContext(stateNode.exit, nextState.context, nextState.children, stateInput, 'exit', stateNode);
3340
+ const [exitActions, nextContext, nextInternalEvents] = getStateActionsAndContext(stateNode.exit, nextState.context, nextState.children, stateInput, 'exit', stateNode);
3341
+ if (nextContext) {
3342
+ nextState = cloneMachineSnapshot(nextState, {
3343
+ context: nextContext
3344
+ });
3345
+ }
3249
3346
  allExitActions.push(...exitActions);
3250
3347
  if (nextInternalEvents?.length) {
3251
3348
  internalQueue.push(...nextInternalEvents);
@@ -3266,14 +3363,14 @@ function microstep(transitions, currentSnapshot, actorScope, event, isInitial, i
3266
3363
  // If context was changed (e.g. by entry actions during self-transition),
3267
3364
  // clone to ensure reference inequality for eventless transition re-evaluation
3268
3365
  if (nextState.context !== originalContext) {
3269
- return [nextState === currentSnapshot ? cloneMachineSnapshot(nextState) : nextState, executableActions];
3366
+ return [nextState === currentSnapshot ? cloneMachineSnapshot(nextState) : nextState, executableActions, resolvedTransitions];
3270
3367
  }
3271
- return [nextState, executableActions];
3368
+ return [nextState, executableActions, resolvedTransitions];
3272
3369
  }
3273
3370
  return [cloneMachineSnapshot(nextState, {
3274
3371
  _nodes: nextStateNodes,
3275
3372
  historyValue
3276
- }), executableActions];
3373
+ }), executableActions, resolvedTransitions];
3277
3374
  }
3278
3375
  }
3279
3376
 
@@ -3383,6 +3480,15 @@ class InfiniteTransitionError extends Error {
3383
3480
  }
3384
3481
  }
3385
3482
  function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps = []) {
3483
+ // A done, error or stopped snapshot processes no events, as in an actor:
3484
+ // every event is unhandled. The initial macrostep passes `initialMicrosteps`
3485
+ // and may start from a snapshot that is already done.
3486
+ if (snapshot.status !== 'active' && !initialMicrosteps.length) {
3487
+ return {
3488
+ snapshot,
3489
+ microsteps: [[snapshot, [], []]]
3490
+ };
3491
+ }
3386
3492
  let nextSnapshot = snapshot;
3387
3493
  const microsteps = initialMicrosteps.slice();
3388
3494
  // Whether a transition handled the external event. A handled event always
@@ -3451,6 +3557,7 @@ function macrostep(snapshot, event, actorScope, internalQueue, initialMicrosteps
3451
3557
  };
3452
3558
  }
3453
3559
  function addMicrostep(step, transitions) {
3560
+ transitions = step[2] ?? transitions;
3454
3561
  // collect microsteps; their transitions are surfaced on the enclosing
3455
3562
  // '@xstate.transition' event via its `microsteps[]` facet (there is no
3456
3563
  // standalone microstep event) and returned by `getMicrosteps()`
@@ -3861,6 +3968,17 @@ function isMachineSnapshot(value) {
3861
3968
  return !!value && typeof value === 'object' && 'machine' in value && 'value' in value;
3862
3969
  }
3863
3970
 
3971
+ /**
3972
+ * The values that `snapshot.matches(...)` accepts for a state value: a state
3973
+ * key, a dot-delimited path to a descendant state, or a partial state value.
3974
+ * Non-literal state values accept any value.
3975
+ */
3976
+
3977
+ /**
3978
+ * `unknown` if `matches(...)` accepts `TTestStateValue` for `TStateValue`,
3979
+ * otherwise `never`. Non-literal test values are always accepted.
3980
+ */
3981
+
3864
3982
  /** @public */
3865
3983
 
3866
3984
  const machineSnapshotMatches = function matches(testValue) {
@@ -4052,7 +4170,7 @@ function getPersistedSnapshot(snapshot, options) {
4052
4170
  // readings (a simulated clock, a monotonic counter) are meaningless in any
4053
4171
  // other process, and restoring them under the wall clock would fire every
4054
4172
  // pending delay instantly. Pure-transition snapshots have no local
4055
- // schedule and persist no timestamp.
4173
+ // schedule; durable executions record an accepted start separately.
4056
4174
  const scheduledTimers = snapshotActor?.system?._clock?.now ? undefined : snapshotActor?.system?._snapshot?._scheduledTimers;
4057
4175
  for (const id in timers) {
4058
4176
  const timer = timers[id];
@@ -4083,10 +4201,10 @@ function getPersistedSnapshot(snapshot, options) {
4083
4201
  // deadline. Derived from dueAt, not the scheduling moment, so repeated
4084
4202
  // persist/restore cycles keep the same deadline. Without a live schedule
4085
4203
  // (a restored-but-never-started actor, a pure-transition snapshot) the
4086
- // timer's carried-in start — which only a wall-clock actor ever stamped —
4087
- // passes through, so re-persisting cannot push the deadline back.
4204
+ // timer's accepted durable start or carried-in start passes through,
4205
+ // so re-persisting cannot push the deadline back.
4088
4206
  const scheduled = scheduledTimers?.[`${snapshotActor.sessionId}.${id}`];
4089
- const startedAt = scheduled ? scheduled.dueAt - timer.delay : timer.startedAt;
4207
+ const startedAt = scheduled ? scheduled.dueAt - timer.delay : getTimerStart(timer);
4090
4208
  timersJson[id] = {
4091
4209
  id: timer.id,
4092
4210
  delay: timer.delay,
@@ -4361,7 +4479,14 @@ function getAllOwnEventDescriptors(snapshot) {
4361
4479
  return [...new Set([...snapshot.nodes.flatMap(sn => sn.ownEvents)])];
4362
4480
  }
4363
4481
 
4364
- /** @internal Events synthesized from active transition descriptors. */
4482
+ /**
4483
+ * Returns one event per transition of the active state nodes of `snapshot`,
4484
+ * including the internal events for invoked actors (`xstate.done.actor`,
4485
+ * `xstate.error.actor`) and delayed transitions (`xstate.after`). Graph
4486
+ * traversal sends these when the `events` option is not given.
4487
+ *
4488
+ * @public
4489
+ */
4365
4490
  function getAllOwnEvents(snapshot) {
4366
4491
  const events = snapshot.nodes.flatMap(stateNode => [...stateNode.transitions.values()].flatMap(transitions => transitions.map(transition => {
4367
4492
  const event = {
@@ -5910,7 +6035,10 @@ class Actor {
5910
6035
  const [nextSnapshot, effects] = nextState;
5911
6036
  if (nextSnapshot === previousSnapshot && !effects.length &&
5912
6037
  // State machine snapshots only; other logic may ignore events freely.
5913
- 'machine' in previousSnapshot && !event.type.startsWith('xstate.')) {
6038
+ 'machine' in previousSnapshot && (
6039
+ // `xstate.route` is sent by users, so a route that matches nothing is
6040
+ // reported like any other unhandled event.
6041
+ !event.type.startsWith('xstate.') || event.type === 'xstate.route')) {
5914
6042
  this._reportUnhandledEvent(event);
5915
6043
  }
5916
6044
  snapshot = nextSnapshot;
@@ -6252,7 +6380,9 @@ exports.cloneMachineSnapshot = cloneMachineSnapshot;
6252
6380
  exports.createActor = createActor;
6253
6381
  exports.createCustomEffect = createCustomEffect;
6254
6382
  exports.createDeadLetterEffect = createDeadLetterEffect;
6383
+ exports.createDoneActorEvent = createDoneActorEvent;
6255
6384
  exports.createEmitEffect = createEmitEffect;
6385
+ exports.createErrorActorEvent = createErrorActorEvent;
6256
6386
  exports.createErrorPlatformEvent = createErrorPlatformEvent;
6257
6387
  exports.createInertActorScope = createInertActorScope;
6258
6388
  exports.createInitEvent = createInitEvent;
@@ -6287,6 +6417,7 @@ exports.getRootActorId = getRootActorId;
6287
6417
  exports.getSnapshotActorRef = getSnapshotActorRef;
6288
6418
  exports.getStateNodeByPath = getStateNodeByPath;
6289
6419
  exports.getStateNodes = getStateNodes;
6420
+ exports.getTimerStart = getTimerStart;
6290
6421
  exports.getTransitionResult = getTransitionResult;
6291
6422
  exports.hasAmbientInspector = hasAmbientInspector;
6292
6423
  exports.hasEffect = hasEffect;
@@ -6310,6 +6441,7 @@ exports.mergeActorIdCounters = mergeActorIdCounters;
6310
6441
  exports.parseDelayToMilliseconds = parseDelayToMilliseconds;
6311
6442
  exports.parseGeneratedActorId = parseGeneratedActorId;
6312
6443
  exports.pathToStateValue = pathToStateValue;
6444
+ exports.recordTimerStart = recordTimerStart;
6313
6445
  exports.reserveChildId = reserveChildId;
6314
6446
  exports.resolveActionsWithContext = resolveActionsWithContext;
6315
6447
  exports.resolveReferencedActor = resolveReferencedActor;
@@ -6320,6 +6452,7 @@ exports.setInertActorScopeSnapshot = setInertActorScopeSnapshot;
6320
6452
  exports.setSnapshotActorRef = setSnapshotActorRef;
6321
6453
  exports.stopActor = stopActor;
6322
6454
  exports.subscriptionLogic = subscriptionLogic;
6455
+ exports.systemLogicMetadata = systemLogicMetadata;
6323
6456
  exports.takeSpawnAllocationCounters = takeSpawnAllocationCounters;
6324
6457
  exports.terminateActor = terminateActor;
6325
6458
  exports.toArray = toArray;
@@ -7,10 +7,10 @@ export interface SimulatedClock extends Clock {
7
7
  }
8
8
  export declare class SimulatedClock implements SimulatedClock {
9
9
  private timeouts;
10
+ private readonly deadlines;
10
11
  private _now;
11
12
  private _id;
12
13
  private _flushing;
13
- private _flushingInvalidated;
14
14
  now(): number;
15
15
  private getId;
16
16
  setTimeout(fn: (...args: any[]) => void, timeout: number): number;
@@ -10,6 +10,23 @@ type MatchingObjectStateValue<TStateValue extends Record<string, unknown>, TTest
10
10
  [K in keyof TStateValue]: K extends keyof TTestStateValue ? MatchingStateValue<NonNullable<TStateValue[K]>, NonNullable<TTestStateValue[K]>> : TStateValue[K];
11
11
  };
12
12
  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;
13
+ type StateValuePath<TStateValue extends StateValue> = TStateValue extends StateValueMap ? {
14
+ [K in keyof TStateValue & string]: K | (NonNullable<TStateValue[K]> extends infer TChild extends StateValue ? `${K}.${StateValuePath<TChild>}` : never);
15
+ }[keyof TStateValue & string] : TStateValue;
16
+ /**
17
+ * The values that `snapshot.matches(...)` accepts for a state value: a state
18
+ * key, a dot-delimited path to a descendant state, or a partial state value.
19
+ * Non-literal state values accept any value.
20
+ */
21
+ export type ToTestStateValue<TStateValue extends StateValue> = StateValue extends TStateValue ? StateValue : TStateValue extends string ? TStateValue : TStateValue extends StateValueMap ? string extends keyof TStateValue ? StateValue : StateValuePath<TStateValue> | {
22
+ [K in keyof TStateValue]?: NonNullable<TStateValue[K]> extends infer TChild extends StateValue ? ToTestStateValue<TChild> : never;
23
+ } : never;
24
+ type IsWideStateValue<TTestStateValue extends StateValue> = string extends TTestStateValue ? true : TTestStateValue extends StateValueMap ? string extends keyof TTestStateValue ? true : false : false;
25
+ /**
26
+ * `unknown` if `matches(...)` accepts `TTestStateValue` for `TStateValue`,
27
+ * otherwise `never`. Non-literal test values are always accepted.
28
+ */
29
+ export type TestStateValueCheck<TStateValue extends StateValue, TTestStateValue extends StateValue> = IsWideStateValue<TTestStateValue> extends true ? unknown : [TTestStateValue] extends [ToTestStateValue<TStateValue>] ? unknown : never;
13
30
  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> {
14
31
  /** The state machine that produced this state snapshot. */
15
32
  machine: AnyStateMachine;
@@ -54,9 +71,11 @@ interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends Ev
54
71
  *
55
72
  * @param partialStateValue
56
73
  */
57
- matches<const TTestStateValue extends string>(partialStateValue: TTestStateValue, ...args: string extends TTestStateValue ? [never] : []): this is MachineSnapshot<StateContextFromStateValue<TStateSchema, TContext, TTestStateValue>, TEvent, TChildren, MatchingStateValue<TStateValue, TTestStateValue>, TTag, _TOutput, TMeta, TStateSchema>;
58
- matches<const TTestStateValue extends 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>;
59
- matches(partialStateValue: StateValue): boolean;
74
+ 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>;
75
+ 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>;
76
+ matches<TSnapshot extends {
77
+ value: StateValue;
78
+ }, const TTestStateValue extends StateValue>(this: TSnapshot, partialStateValue: TTestStateValue & NoInfer<TestStateValueCheck<TSnapshot['value'], TTestStateValue>>): boolean;
60
79
  /**
61
80
  * Whether the current state nodes has a state node with the specified `tag`.
62
81
  *
@@ -68,6 +87,9 @@ interface MachineSnapshotBase<TContext extends MachineContext, TEvent extends Ev
68
87
  * transition to be selected, even if the transitions have no actions nor
69
88
  * change the state value.
70
89
  *
90
+ * Returns false for terminal snapshots. Throws if transition evaluation
91
+ * throws; this dry run does not run onError recovery.
92
+ *
71
93
  * @param event The event to test
72
94
  * @returns Whether the event will cause a transition
73
95
  */
@@ -1,3 +1,4 @@
1
+ import type { PublicEventFromMachine } from "./eventTypes.js";
1
2
  import { MachineSnapshot } from "./State.js";
2
3
  import { StateNode } from "./StateNode.js";
3
4
  import { type TransitionSelectionResults } from "./stateUtils.js";
@@ -7,7 +8,7 @@ import { AnyMachineSchemas, DelaySourceMap, GuardSourceMap, Sources, Next_Machin
7
8
  import type { ActorLogicValidator } from "./validation.types.js";
8
9
  import type { StandardSchemaV1 } from "./schema.types.js";
9
10
  import type { PersistedMachineSnapshot } from "./machineVersion.types.js";
10
- type CompatibleProvidedActorSource<TExpected extends AnyActorLogic, TActual extends AnyActorLogic> = IsAny<TActual> extends true ? TActual : [OutputFrom<TActual>] extends [OutputFrom<TExpected>] ? [Omit<SnapshotFrom<TActual>, 'input'>] extends [
11
+ export type CompatibleProvidedActorSource<TExpected extends AnyActorLogic, TActual extends AnyActorLogic> = IsAny<TActual> extends true ? TActual : [OutputFrom<TActual>] extends [OutputFrom<TExpected>] ? [Omit<SnapshotFrom<TActual>, 'input'>] extends [
11
12
  Omit<SnapshotFrom<TExpected>, 'input'>
12
13
  ] ? [InputFrom<TExpected>] extends [InputFrom<TActual>] ? [EventFromLogic<TExpected>] extends [EventFromLogic<TActual>] ? [EmittedFrom<TActual>] extends [EmittedFrom<TExpected>] ? TActual : never : never : never : never : never;
13
14
  type ProvidedActors<TExpectedActorMap extends Sources['actors'], TProvidedActorMap extends Partial<Record<keyof TExpectedActorMap & string, AnyActorLogic>>> = {
@@ -16,9 +17,19 @@ type ProvidedActors<TExpectedActorMap extends Sources['actors'], TProvidedActorM
16
17
  type ProvidedSourceMap<TDeclared, TProvided> = {
17
18
  [K in keyof TDeclared]: K extends keyof TProvided ? {} extends Pick<TProvided, K> ? TDeclared[K] | Exclude<TProvided[K], undefined> : Exclude<TProvided[K], undefined> : TDeclared[K];
18
19
  };
19
- type ProvidedActionContracts<T> = {
20
- [K in keyof T]: T[K] extends (...args: infer TArgs) => any ? (...args: TArgs) => void : never;
20
+ declare const declaredAction: unique symbol;
21
+ type DeclaredAction<T> = T extends {
22
+ readonly [declaredAction]?: infer TDeclared;
23
+ } ? unknown extends TDeclared ? T : Exclude<TDeclared, undefined> : T;
24
+ type ProvidedActionSourceMap<TDeclared, TProvided> = {
25
+ [K in keyof TDeclared]: K extends keyof TProvided ? ({} extends Pick<TProvided, K> ? TDeclared[K] | Exclude<TProvided[K], undefined> : Exclude<TProvided[K], undefined>) & {
26
+ readonly [declaredAction]?: DeclaredAction<TDeclared[K]>;
27
+ } : TDeclared[K];
21
28
  };
29
+ export type ProvidedActionContracts<T> = {
30
+ [K in keyof T]: DeclaredAction<T[K]> extends (...args: infer TArgs) => infer TResult ? (...args: TArgs) => ProvidedActionResult<TResult> : never;
31
+ };
32
+ type ProvidedActionResult<TResult> = void extends TResult ? void : Extract<TResult, ReturnType<Sources['actions'][string]>>;
22
33
  /** @public */
23
34
  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> {
24
35
  /** The raw config used to create the machine. */
@@ -57,13 +68,15 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
57
68
  version: TConfig extends {
58
69
  version: infer TVersion extends string;
59
70
  } ? TVersion : undefined;
60
- schemas: AnyMachineSchemas | undefined;
71
+ schemas: (TConfig extends {
72
+ schemas: infer TSchemas extends AnyMachineSchemas;
73
+ } ? TSchemas : AnyMachineSchemas) | undefined;
61
74
  /** Standard Schema for snapshots persisted by this machine version. */
62
75
  readonly snapshotSchema: StandardSchemaV1<unknown, Snapshot<unknown> & PersistedMachineSnapshot & {
63
76
  context: TContext;
64
77
  }>;
65
- /** Standard Schema for complete events accepted by this machine version. */
66
- readonly eventSchema: StandardSchemaV1<unknown, TEvent>;
78
+ /** Standard Schema for complete public input events; excludes internal and runtime events. */
79
+ readonly eventSchema: StandardSchemaV1<unknown, PublicEventFromMachine<TEvent, TInternalEvent>>;
67
80
  sources: Sources;
68
81
  /** Runtime options for machine execution. */
69
82
  options: MachineOptions;
@@ -102,7 +115,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
102
115
  delays?: {
103
116
  [K in keyof TDelayMap]?: DelaySourceMap<TContext, TEvent>[string];
104
117
  };
105
- }): StateMachine<TContext, TEvent, TChildren, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig, ProvidedSourceMap<TActionMap, TProvidedActionMap>, ProvidedSourceMap<TActorMap, TProvidedActorMap>, TGuardMap, TDelayMap, TInternalEvent, TTransitionMeta>;
118
+ }): StateMachine<TContext, TEvent, TChildren, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig, ProvidedActionSourceMap<TActionMap, TProvidedActionMap>, ProvidedSourceMap<TActorMap, TProvidedActorMap>, TGuardMap, TDelayMap, TInternalEvent, TTransitionMeta>;
106
119
  resolveState(config: {
107
120
  value: StateValue;
108
121
  context?: TContext;
@@ -183,6 +183,11 @@ export type AsyncLogicError<TErrorSchema extends StandardSchemaV1, TTimeout> = [
183
183
  * @see {@link https://stately.ai/docs/input | Input docs} for more information about how input is passed
184
184
  * @public
185
185
  */
186
+ export declare function createAsyncLogic<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject>(asyncLogic: Omit<LogicConfig<TOutput, TInput, TEmitted>, 'schemas'> & {
187
+ schemas?: undefined;
188
+ }): AsyncActorLogic<TOutput, TInput, TEmitted> & {
189
+ id?: string;
190
+ };
186
191
  export declare function createAsyncLogic<const TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TEmitted extends EventObject = EventObject, const TErrorSchema extends StandardSchemaV1 = StandardSchemaV1, TTimeout extends number | string | undefined = undefined>(asyncLogic: LogicConfig<StandardSchemaV1.InferOutput<TOutputSchema>, StandardSchemaV1.InferOutput<TInputSchema>, TEmitted, TInputSchema, TOutputSchema, TErrorSchema> & {
187
192
  schemas: {
188
193
  input: TInputSchema;
@@ -228,9 +233,4 @@ export declare function createAsyncLogic<TOutput, TInput = NonReducibleUnknown,
228
233
  }): AsyncActorLogic<TOutput, TInput, TEmitted, AsyncLogicError<TErrorSchema, TTimeout>> & {
229
234
  id?: string;
230
235
  };
231
- export declare function createAsyncLogic<TOutput, TInput = NonReducibleUnknown, TEmitted extends EventObject = EventObject>(asyncLogic: Omit<LogicConfig<TOutput, TInput, TEmitted>, 'schemas'> & {
232
- schemas?: undefined;
233
- }): AsyncActorLogic<TOutput, TInput, TEmitted> & {
234
- id?: string;
235
- };
236
236
  export {};
@@ -1,6 +1,8 @@
1
1
  import { StandardSchemaV1 } from "./schema.types.js";
2
2
  import { StateMachine } from "./StateMachine.js";
3
- import { AnyActorRef, EventObject, AnyEventObject, Cast, MachineContext, ProvidedActor, StateValueFromStateSchema, ToChildren, MetaObject, StateSchema, DoNotInfer, RoutableStateId, Compute } from "./types.js";
3
+ import type { Spawner } from "./spawn.js";
4
+ import type { ActorLogicValidator } from "./validation.types.js";
5
+ import { AnyActorRef, AnyStateMachine, EventObject, AnyEventObject, Cast, MachineContext, ProvidedActor, StateValueFromStateSchema, ToChildren, MetaObject, StateSchema, DoNotInfer, RoutableStateId, Compute } from "./types.js";
4
6
  import { ChildCompletionEvents, Sources, DelayMapFromNames, InferChildren, InferMachineInput, InferOutput, SchemaOrConfigOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, ValidateEventDescriptors, ValidateHistoryDefaults, ValidateStateTargets, ValidateTopLevelFinalOutputs, WidenLiterals, WithDefault } from "./types.v6.js";
5
7
  type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
6
8
  type MachineIdentity<TConfig> = {
@@ -60,7 +62,7 @@ export declare function createMachine<TContextSchema extends StandardSchemaV1, c
60
62
  context: TContextSchema;
61
63
  children?: TChildrenSchemaMap;
62
64
  };
63
- } & ValidateTopLevelFinalOutputs<TSS, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>): StateMachine<InferOutput<TContextSchema, MachineContext>, (InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>) | ([RoutableStateId<TSS>] extends [never] ? never : {
65
+ } & ValidateTopLevelFinalOutputs<TSS, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>): [TSS] extends [never] ? AnyStateMachine : StateMachine<InferOutput<TContextSchema, MachineContext>, (InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>) | ([RoutableStateId<TSS>] extends [never] ? never : {
64
66
  type: 'xstate.route';
65
67
  to: RoutableStateId<TSS>;
66
68
  }), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<TSS>, TTag & string, InferMachineInput<TInputSchema>, SchemaOrConfigOutput<TOutputSchema, TSS>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
@@ -68,17 +70,17 @@ TSS, // TStateSchema
68
70
  TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>, InferInternalEvents<TInternalEventSchemaMap>, TransitionMetaFromSchemas<TMetaSchema, TTransitionMetaSchema>> & {
69
71
  states: TSS;
70
72
  } & MachineIdentity<TSS>;
71
- export declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1 = TMetaSchema, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, const TInternalEventSchemaMap extends Record<string, StandardSchemaV1> = {}, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Sources['actions'] = Sources['actions'], TActorMap extends Sources['actors'] = Sources['actors'], TGuardMap extends Sources['guards'] = Sources['guards'], TDelayMap extends Sources['delays'] = Sources['delays'], TDelays extends string = string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string = StandardSchemaV1.InferOutput<TTagSchema> & string, _TInput = unknown, const TSS extends StateSchema = StateSchema>(config: TSS & ValidateDelayReferences<TSS> & ValidateHistoryDefaults<TSS> & ValidateStateTargets<TSS> & ValidateEventDescriptors<TSS, NoInfer<InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>> & Next_MachineConfig<StandardSchemaV1, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap, WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap> | ChildCompletionEvents<Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, false> & {
73
+ export declare function createMachine<TContext extends MachineContext = never, const TEventSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TEmittedSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1, const TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1 = TMetaSchema, TTagSchema extends StandardSchemaV1 = StandardSchemaV1, const TChildrenSchemaMap extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, const TInternalEventSchemaMap extends Record<string, StandardSchemaV1> = {}, _TEvent extends EventObject = EventObject, TActor extends ProvidedActor = ProvidedActor, TActionMap extends Sources['actions'] = Sources['actions'], TActorMap extends Sources['actors'] = Sources['actors'], TGuardMap extends Sources['guards'] = Sources['guards'], TDelayMap extends Sources['delays'] = Sources['delays'], TDelays extends string = string, TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string = StandardSchemaV1.InferOutput<TTagSchema> & string, _TInput = unknown, const TSS extends StateSchema = StateSchema>(config: TSS & ValidateDelayReferences<TSS> & ValidateHistoryDefaults<TSS> & ValidateStateTargets<TSS> & ValidateEventDescriptors<TSS, NoInfer<InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>> & Omit<Next_MachineConfig<StandardSchemaV1, TEventSchemaMap, TInternalEventSchemaMap, TEmittedSchemaMap, TInputSchema, TOutputSchema, TMetaSchema, TTransitionMetaSchema, TTagSchema, TChildrenSchemaMap, WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap> | ChildCompletionEvents<Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>>, Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, TDelays, TTag, TActionMap, TActorMap, TGuardMap, TDelayMap, false>, 'context'> & {
72
74
  schemas?: {
73
75
  context?: never;
74
76
  };
75
77
  context?: TContext | ((_: {
76
- spawn: any;
78
+ spawn: Spawner;
77
79
  actors: TActorMap;
78
80
  input: InferOutput<TInputSchema, unknown>;
79
81
  self: any;
80
82
  }) => TContext);
81
- } & ValidateTopLevelFinalOutputs<TSS, WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>): StateMachine<WidenLiterals<TContext>, (InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>) | ([RoutableStateId<TSS>] extends [never] ? never : {
83
+ } & ValidateTopLevelFinalOutputs<TSS, WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>): [TSS] extends [never] ? AnyStateMachine : StateMachine<WidenLiterals<TContext>, (InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>) | ([RoutableStateId<TSS>] extends [never] ? never : {
82
84
  type: 'xstate.route';
83
85
  to: RoutableStateId<TSS>;
84
86
  }), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<TSS>, TTag & string, InferMachineInput<TInputSchema>, SchemaOrConfigOutput<TOutputSchema, TSS>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
@@ -92,7 +94,7 @@ TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>, InferIn
92
94
  *
93
95
  * @experimental Used by `@xstate/scxml`; not part of the stable API.
94
96
  */
95
- export declare function createMachineFromCompiledConfig(config: any): any;
97
+ export declare function createMachineFromCompiledConfig(config: any, validator?: ActorLogicValidator): any;
96
98
  /** @public */
97
99
  export declare function createStateConfig<TContextSchema extends StandardSchemaV1, TEventSchema extends StandardSchemaV1, TEmittedSchema extends StandardSchemaV1, _TInputSchema extends StandardSchemaV1, const TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TTransitionMetaSchema extends StandardSchemaV1, TTagSchema extends StandardSchemaV1, _TEvent extends StandardSchemaV1.InferOutput<TEventSchema> & EventObject, // TODO: consider using a stricter `EventObject` here
98
100
  _TActor extends ProvidedActor, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TDelays extends string, _TTag extends StandardSchemaV1.InferOutput<TTagSchema> & string, _TInput, const TSS extends StateSchema>(config: TSS & Next_StateNodeConfig<InferOutput<TContextSchema, MachineContext>, DoNotInfer<StandardSchemaV1.InferOutput<TEventSchema> & EventObject>, DoNotInfer<TDelays>, DoNotInfer<StandardSchemaV1.InferOutput<TTagSchema> & string>, DoNotInfer<StandardSchemaV1.InferOutput<TOutputSchema>>, DoNotInfer<StandardSchemaV1.InferOutput<TEmittedSchema> & EventObject>, DoNotInfer<InferOutput<TMetaSchema, MetaObject>>, DoNotInfer<Record<string, AnyActorRef | undefined>>, DoNotInfer<TActionMap>, DoNotInfer<TActorMap>, DoNotInfer<TGuardMap>, DoNotInfer<TDelayMap>, any, any, any, any, DoNotInfer<TransitionMetaFromSchemas<TMetaSchema, TTransitionMetaSchema>>>): typeof config;
@@ -1,7 +1,9 @@
1
- import { AnyActorLogic, AnyEventObject, AnyStateMachine, EventObject, MachineContext, MetaObject } from "./types.js";
1
+ import { AnyActorLogic, AnyEventObject, AnyStateMachine, MachineContext, MetaObject } from "./types.js";
2
+ import type { AnyMachineSchemas } from "./types.v6.js";
3
+ import type { ActorLogicValidator } from "./validation.types.js";
2
4
  interface RaiseJSON {
3
5
  type: '@xstate.raise';
4
- event: EventObject;
6
+ event: AnyEventObject;
5
7
  id?: string;
6
8
  delay?: number;
7
9
  }
@@ -144,6 +146,15 @@ interface MachineSources {
144
146
  actors?: Record<string, AnyActorLogic>;
145
147
  delays?: Record<string, number | ((...args: any[]) => number)>;
146
148
  evaluators?: Record<string, (args: EvaluatorArgs) => unknown>;
149
+ /**
150
+ * Runtime schemas (Standard Schema) for the revived machine. JSON `schemas`
151
+ * in the definition are descriptive and are not used at runtime.
152
+ */
153
+ schemas?: AnyMachineSchemas;
154
+ /**
155
+ * Checks events and results against `schemas`, like `setup({ validator })`.
156
+ */
157
+ validator?: ActorLogicValidator;
147
158
  }
148
159
  /** @public */
149
160
  export declare function createMachineFromConfig(json: MachineJSON, sources?: MachineSources): AnyStateMachine;