xstate 6.0.0-alpha.31 → 6.0.0-alpha.33

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 (35) hide show
  1. package/dist/{StateMachine-54d3cf7a.development.esm.js → StateMachine-33eec203.development.esm.js} +16 -7
  2. package/dist/{StateMachine-cc0c34dd.esm.js → StateMachine-d073209c.esm.js} +16 -7
  3. package/dist/{StateMachine-73b20de0.development.cjs.js → StateMachine-d3243bd1.development.cjs.js} +16 -7
  4. package/dist/{StateMachine-4e86e818.cjs.js → StateMachine-ff580dd5.cjs.js} +16 -7
  5. package/dist/declarations/src/StateMachine.d.ts +2 -1
  6. package/dist/declarations/src/StateNode.d.ts +1 -0
  7. package/dist/declarations/src/index.d.ts +1 -1
  8. package/dist/declarations/src/machineVersions.d.ts +19 -15
  9. package/dist/declarations/src/stateUtils.d.ts +9 -2
  10. package/dist/declarations/src/types.d.ts +1 -1
  11. package/dist/{index-0317dbd5.development.cjs.js → index-691f27b9.development.cjs.js} +160 -97
  12. package/dist/{index-fbe9e986.development.esm.js → index-92227865.development.esm.js} +161 -98
  13. package/dist/{index-85c48a0a.cjs.js → index-9939f02a.cjs.js} +160 -97
  14. package/dist/{index-2b16671f.esm.js → index-ab93831d.esm.js} +161 -98
  15. package/dist/xstate-actors.cjs.js +1 -1
  16. package/dist/xstate-actors.development.cjs.js +1 -1
  17. package/dist/xstate-actors.development.esm.js +1 -1
  18. package/dist/xstate-actors.esm.js +1 -1
  19. package/dist/xstate-actors.umd.min.js +1 -1
  20. package/dist/xstate-actors.umd.min.js.map +1 -1
  21. package/dist/xstate-graph.cjs.js +2 -2
  22. package/dist/xstate-graph.development.cjs.js +2 -2
  23. package/dist/xstate-graph.development.esm.js +2 -2
  24. package/dist/xstate-graph.esm.js +2 -2
  25. package/dist/xstate-graph.umd.min.js +1 -1
  26. package/dist/xstate-graph.umd.min.js.map +1 -1
  27. package/dist/xstate.cjs.js +102 -71
  28. package/dist/xstate.cjs.mjs +0 -1
  29. package/dist/xstate.development.cjs.js +102 -71
  30. package/dist/xstate.development.cjs.mjs +0 -1
  31. package/dist/xstate.development.esm.js +105 -73
  32. package/dist/xstate.esm.js +105 -73
  33. package/dist/xstate.umd.min.js +1 -1
  34. package/dist/xstate.umd.min.js.map +1 -1
  35. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as getCandidates, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, a6 as assertValid, j as macrostep, a7 as cloneMachineSnapshot, a8 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a9 as getTransitionResult, aa as hasEffect, ab as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ac as toStatePath, ad as isStateId, ae as getStateNodeByPath, af as getPersistedSnapshot, ag as resolveReferencedActor, ah as createInvokeTimeoutEvent, ai as $$ACTOR_TYPE } from './index-fbe9e986.development.esm.js';
1
+ import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as getCandidates, W as evaluateCandidate, Y as formatTransition, Z as NULL_EVENT, _ as toTransitionConfigArray, $ as createInvokeTimeoutEventId, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, a6 as assertValid, j as macrostep, a7 as cloneMachineSnapshot, a8 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a9 as getTransitionResult, aa as hasEffect, ab as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ac as toStatePath, ad as isStateId, ae as getStateNodeByPath, af as getPersistedSnapshot, ag as resolveReferencedActor, ah as createInvokeTimeoutEvent, ai as $$ACTOR_TYPE } from './index-92227865.development.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, actors, spawnedChildren) {
4
4
  return (src, options) => {
@@ -203,6 +203,7 @@ class StateNode {
203
203
  this.after = void 0;
204
204
  this.events = void 0;
205
205
  this.ownEvents = void 0;
206
+ this._candidateCache = void 0;
206
207
  this.parent = options._parent;
207
208
  this.key = options._key;
208
209
  this.machine = options._machine;
@@ -303,10 +304,15 @@ class StateNode {
303
304
  }
304
305
 
305
306
  /** @internal */
306
- next(snapshot, event, self) {
307
- const candidates = memo(this, `candidates-${getEventDescriptorKey(event)}`, () => getCandidates(this, event));
307
+ next(snapshot, event, self, selectionResults) {
308
+ const descriptorKey = getEventDescriptorKey(event);
309
+ let candidates = this._candidateCache?.get(descriptorKey);
310
+ if (!candidates) {
311
+ candidates = getCandidates(this, event);
312
+ (this._candidateCache ??= new Map()).set(descriptorKey, candidates);
313
+ }
308
314
  for (const candidate of candidates) {
309
- const guardPassed = evaluateCandidate(candidate, event, snapshot, this, self);
315
+ const guardPassed = evaluateCandidate(candidate, event, snapshot, this, self, selectionResults);
310
316
  if (guardPassed) {
311
317
  return [candidate];
312
318
  }
@@ -563,6 +569,8 @@ class StateMachine {
563
569
  this.states = void 0;
564
570
  this.events = void 0;
565
571
  this.internalEventDescriptors = void 0;
572
+ /** @internal Skips eventless-selection scans for machines without `always`. */
573
+ this._hasEventlessTransitions = void 0;
566
574
  /**
567
575
  * The original JSON definition this machine was created from (set by
568
576
  * `createMachineFromConfig`), if any. Used by `serializeMachine` for lossless
@@ -610,6 +618,7 @@ class StateMachine {
610
618
  this.root._initialize();
611
619
  formatRouteTransitions(this.root);
612
620
  this.root._refreshEventMetadata();
621
+ this._hasEventlessTransitions = Array.from(this.idMap.values()).some(stateNode => !!stateNode.always?.length);
613
622
  this.states = this.root.states; // TODO: remove!
614
623
  this.events = this.root.events;
615
624
  }
@@ -787,8 +796,8 @@ class StateMachine {
787
796
  }
788
797
  return snapshots;
789
798
  }
790
- getTransitionData(snapshot, event, self) {
791
- return transitionNode(this.root, snapshot.value, snapshot, event, self) || [];
799
+ getTransitionData(snapshot, event, self, selectionResults) {
800
+ return transitionNode(this.root, snapshot.value, snapshot, event, self, selectionResults) || [];
792
801
  }
793
802
  isInternalEventType(eventType) {
794
803
  if (eventType === XSTATE_TIMER) {
@@ -860,7 +869,7 @@ class StateMachine {
860
869
  _nodes: [this.root],
861
870
  children: {},
862
871
  status: 'active'
863
- }, this, actorScope.self);
872
+ }, this);
864
873
  if (typeof context === 'function') {
865
874
  const children = {};
866
875
  const spawn = createSpawner(actorScope, this.sources.actors, children);
@@ -1,4 +1,4 @@
1
- import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as evaluateCandidate, W as formatTransition, Y as NULL_EVENT, Z as toTransitionConfigArray, _ as createInvokeTimeoutEventId, $ as getCandidates, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, a6 as assertValid, j as macrostep, a7 as cloneMachineSnapshot, a8 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a9 as getTransitionResult, aa as hasEffect, ab as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ac as toStatePath, ad as isStateId, ae as getStateNodeByPath, af as getPersistedSnapshot, ag as resolveReferencedActor, ah as createInvokeTimeoutEvent, ai as $$ACTOR_TYPE } from './index-2b16671f.esm.js';
1
+ import { M as setSnapshotActorRef, N as getSnapshotActorRef, O as createSnapshotSystem, q as isMachineSnapshot, h as createActor, S as STATE_DELIMITER, P as mapValues, t as toArray, Q as createInvokeId, R as getDelayedTransitions, U as getEventDescriptorKey, V as getCandidates, W as evaluateCandidate, Y as formatTransition, Z as NULL_EVENT, _ as toTransitionConfigArray, $ as createInvokeTimeoutEventId, a0 as matchesActorSession, a1 as formatRouteTransitions, a2 as resolveStateValue, a3 as getAllStateNodes, s as getStateNodes, a4 as createMachineSnapshot, a5 as isInFinalState, a6 as assertValid, j as macrostep, a7 as cloneMachineSnapshot, a8 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a9 as getTransitionResult, aa as hasEffect, ab as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ac as toStatePath, ad as isStateId, ae as getStateNodeByPath, af as getPersistedSnapshot, ag as resolveReferencedActor, ah as createInvokeTimeoutEvent, ai as $$ACTOR_TYPE } from './index-ab93831d.esm.js';
2
2
 
3
3
  function createSpawner(actorScope, actors, spawnedChildren) {
4
4
  return (src, options) => {
@@ -202,6 +202,7 @@ class StateNode {
202
202
  this.after = void 0;
203
203
  this.events = void 0;
204
204
  this.ownEvents = void 0;
205
+ this._candidateCache = void 0;
205
206
  this.parent = options._parent;
206
207
  this.key = options._key;
207
208
  this.machine = options._machine;
@@ -302,10 +303,15 @@ class StateNode {
302
303
  }
303
304
 
304
305
  /** @internal */
305
- next(snapshot, event, self) {
306
- const candidates = memo(this, `candidates-${getEventDescriptorKey(event)}`, () => getCandidates(this, event));
306
+ next(snapshot, event, self, selectionResults) {
307
+ const descriptorKey = getEventDescriptorKey(event);
308
+ let candidates = this._candidateCache?.get(descriptorKey);
309
+ if (!candidates) {
310
+ candidates = getCandidates(this, event);
311
+ (this._candidateCache ??= new Map()).set(descriptorKey, candidates);
312
+ }
307
313
  for (const candidate of candidates) {
308
- const guardPassed = evaluateCandidate(candidate, event, snapshot, this, self);
314
+ const guardPassed = evaluateCandidate(candidate, event, snapshot, this, self, selectionResults);
309
315
  if (guardPassed) {
310
316
  return [candidate];
311
317
  }
@@ -545,6 +551,8 @@ class StateMachine {
545
551
  this.states = void 0;
546
552
  this.events = void 0;
547
553
  this.internalEventDescriptors = void 0;
554
+ /** @internal Skips eventless-selection scans for machines without `always`. */
555
+ this._hasEventlessTransitions = void 0;
548
556
  /**
549
557
  * The original JSON definition this machine was created from (set by
550
558
  * `createMachineFromConfig`), if any. Used by `serializeMachine` for lossless
@@ -581,6 +589,7 @@ class StateMachine {
581
589
  this.root._initialize();
582
590
  formatRouteTransitions(this.root);
583
591
  this.root._refreshEventMetadata();
592
+ this._hasEventlessTransitions = Array.from(this.idMap.values()).some(stateNode => !!stateNode.always?.length);
584
593
  this.states = this.root.states; // TODO: remove!
585
594
  this.events = this.root.events;
586
595
  }
@@ -758,8 +767,8 @@ class StateMachine {
758
767
  }
759
768
  return snapshots;
760
769
  }
761
- getTransitionData(snapshot, event, self) {
762
- return transitionNode(this.root, snapshot.value, snapshot, event, self) || [];
770
+ getTransitionData(snapshot, event, self, selectionResults) {
771
+ return transitionNode(this.root, snapshot.value, snapshot, event, self, selectionResults) || [];
763
772
  }
764
773
  isInternalEventType(eventType) {
765
774
  if (eventType === XSTATE_TIMER) {
@@ -831,7 +840,7 @@ class StateMachine {
831
840
  _nodes: [this.root],
832
841
  children: {},
833
842
  status: 'active'
834
- }, this, actorScope.self);
843
+ }, this);
835
844
  if (typeof context === 'function') {
836
845
  const children = {};
837
846
  const spawn = createSpawner(actorScope, this.sources.actors, children);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-0317dbd5.development.cjs.js');
3
+ var dist_xstateActors = require('./index-691f27b9.development.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, actors, spawnedChildren) {
6
6
  return (src, options) => {
@@ -205,6 +205,7 @@ class StateNode {
205
205
  this.after = void 0;
206
206
  this.events = void 0;
207
207
  this.ownEvents = void 0;
208
+ this._candidateCache = void 0;
208
209
  this.parent = options._parent;
209
210
  this.key = options._key;
210
211
  this.machine = options._machine;
@@ -305,10 +306,15 @@ class StateNode {
305
306
  }
306
307
 
307
308
  /** @internal */
308
- next(snapshot, event, self) {
309
- const candidates = memo(this, `candidates-${dist_xstateActors.getEventDescriptorKey(event)}`, () => dist_xstateActors.getCandidates(this, event));
309
+ next(snapshot, event, self, selectionResults) {
310
+ const descriptorKey = dist_xstateActors.getEventDescriptorKey(event);
311
+ let candidates = this._candidateCache?.get(descriptorKey);
312
+ if (!candidates) {
313
+ candidates = dist_xstateActors.getCandidates(this, event);
314
+ (this._candidateCache ??= new Map()).set(descriptorKey, candidates);
315
+ }
310
316
  for (const candidate of candidates) {
311
- const guardPassed = dist_xstateActors.evaluateCandidate(candidate, event, snapshot, this, self);
317
+ const guardPassed = dist_xstateActors.evaluateCandidate(candidate, event, snapshot, this, self, selectionResults);
312
318
  if (guardPassed) {
313
319
  return [candidate];
314
320
  }
@@ -565,6 +571,8 @@ class StateMachine {
565
571
  this.states = void 0;
566
572
  this.events = void 0;
567
573
  this.internalEventDescriptors = void 0;
574
+ /** @internal Skips eventless-selection scans for machines without `always`. */
575
+ this._hasEventlessTransitions = void 0;
568
576
  /**
569
577
  * The original JSON definition this machine was created from (set by
570
578
  * `createMachineFromConfig`), if any. Used by `serializeMachine` for lossless
@@ -612,6 +620,7 @@ class StateMachine {
612
620
  this.root._initialize();
613
621
  dist_xstateActors.formatRouteTransitions(this.root);
614
622
  this.root._refreshEventMetadata();
623
+ this._hasEventlessTransitions = Array.from(this.idMap.values()).some(stateNode => !!stateNode.always?.length);
615
624
  this.states = this.root.states; // TODO: remove!
616
625
  this.events = this.root.events;
617
626
  }
@@ -789,8 +798,8 @@ class StateMachine {
789
798
  }
790
799
  return snapshots;
791
800
  }
792
- getTransitionData(snapshot, event, self) {
793
- return dist_xstateActors.transitionNode(this.root, snapshot.value, snapshot, event, self) || [];
801
+ getTransitionData(snapshot, event, self, selectionResults) {
802
+ return dist_xstateActors.transitionNode(this.root, snapshot.value, snapshot, event, self, selectionResults) || [];
794
803
  }
795
804
  isInternalEventType(eventType) {
796
805
  if (eventType === dist_xstateActors.XSTATE_TIMER) {
@@ -862,7 +871,7 @@ class StateMachine {
862
871
  _nodes: [this.root],
863
872
  children: {},
864
873
  status: 'active'
865
- }, this, actorScope.self);
874
+ }, this);
866
875
  if (typeof context === 'function') {
867
876
  const children = {};
868
877
  const spawn = createSpawner(actorScope, this.sources.actors, children);
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-85c48a0a.cjs.js');
3
+ var dist_xstateActors = require('./index-9939f02a.cjs.js');
4
4
 
5
5
  function createSpawner(actorScope, actors, spawnedChildren) {
6
6
  return (src, options) => {
@@ -204,6 +204,7 @@ class StateNode {
204
204
  this.after = void 0;
205
205
  this.events = void 0;
206
206
  this.ownEvents = void 0;
207
+ this._candidateCache = void 0;
207
208
  this.parent = options._parent;
208
209
  this.key = options._key;
209
210
  this.machine = options._machine;
@@ -304,10 +305,15 @@ class StateNode {
304
305
  }
305
306
 
306
307
  /** @internal */
307
- next(snapshot, event, self) {
308
- const candidates = memo(this, `candidates-${dist_xstateActors.getEventDescriptorKey(event)}`, () => dist_xstateActors.getCandidates(this, event));
308
+ next(snapshot, event, self, selectionResults) {
309
+ const descriptorKey = dist_xstateActors.getEventDescriptorKey(event);
310
+ let candidates = this._candidateCache?.get(descriptorKey);
311
+ if (!candidates) {
312
+ candidates = dist_xstateActors.getCandidates(this, event);
313
+ (this._candidateCache ??= new Map()).set(descriptorKey, candidates);
314
+ }
309
315
  for (const candidate of candidates) {
310
- const guardPassed = dist_xstateActors.evaluateCandidate(candidate, event, snapshot, this, self);
316
+ const guardPassed = dist_xstateActors.evaluateCandidate(candidate, event, snapshot, this, self, selectionResults);
311
317
  if (guardPassed) {
312
318
  return [candidate];
313
319
  }
@@ -547,6 +553,8 @@ class StateMachine {
547
553
  this.states = void 0;
548
554
  this.events = void 0;
549
555
  this.internalEventDescriptors = void 0;
556
+ /** @internal Skips eventless-selection scans for machines without `always`. */
557
+ this._hasEventlessTransitions = void 0;
550
558
  /**
551
559
  * The original JSON definition this machine was created from (set by
552
560
  * `createMachineFromConfig`), if any. Used by `serializeMachine` for lossless
@@ -583,6 +591,7 @@ class StateMachine {
583
591
  this.root._initialize();
584
592
  dist_xstateActors.formatRouteTransitions(this.root);
585
593
  this.root._refreshEventMetadata();
594
+ this._hasEventlessTransitions = Array.from(this.idMap.values()).some(stateNode => !!stateNode.always?.length);
586
595
  this.states = this.root.states; // TODO: remove!
587
596
  this.events = this.root.events;
588
597
  }
@@ -760,8 +769,8 @@ class StateMachine {
760
769
  }
761
770
  return snapshots;
762
771
  }
763
- getTransitionData(snapshot, event, self) {
764
- return dist_xstateActors.transitionNode(this.root, snapshot.value, snapshot, event, self) || [];
772
+ getTransitionData(snapshot, event, self, selectionResults) {
773
+ return dist_xstateActors.transitionNode(this.root, snapshot.value, snapshot, event, self, selectionResults) || [];
765
774
  }
766
775
  isInternalEventType(eventType) {
767
776
  if (eventType === dist_xstateActors.XSTATE_TIMER) {
@@ -833,7 +842,7 @@ class StateMachine {
833
842
  _nodes: [this.root],
834
843
  children: {},
835
844
  status: 'active'
836
- }, this, actorScope.self);
845
+ }, this);
837
846
  if (typeof context === 'function') {
838
847
  const children = {};
839
848
  const spawn = createSpawner(actorScope, this.sources.actors, children);
@@ -1,5 +1,6 @@
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
5
  import type { ActorLogic, ActorLogicTransitionResult, ActorScope, AnyActor, AnyActorLogic, AnyActorRef, AnyActorScope, AnyTransitionDefinition, Equals, EventDescriptor, EmittedFrom, EventObject, EventFromLogic, ExecutableActionObjectFromLogic, HistoryValue, InputFrom, IsAny, MachineContext, MetaObject, OutputFrom, Snapshot, SnapshotFrom, StateValue, StateSchema, SnapshotStatus } from "./types.js";
5
6
  import { AnyMachineSchemas, Sources, Next_MachineConfig, MachineOptions } from "./types.v6.js";
@@ -76,7 +77,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
76
77
  * @param event The received event
77
78
  */
78
79
  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>>;
79
- getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, self: AnyActor): Array<AnyTransitionDefinition>;
80
+ getTransitionData(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, event: TEvent, self: AnyActor, selectionResults?: TransitionSelectionResults): Array<AnyTransitionDefinition>;
80
81
  isInternalEventType(eventType: string): boolean;
81
82
  /**
82
83
  * Returns the initial `State` instance, with reference to `self` as an
@@ -70,6 +70,7 @@ export declare class StateNode<TContext extends MachineContext = MachineContext,
70
70
  after: Array<DelayedTransitionDefinition<any, any>>;
71
71
  events: Array<EventDescriptor<any>>;
72
72
  ownEvents: Array<EventDescriptor<any>>;
73
+ private _candidateCache?;
73
74
  constructor(
74
75
  /** The raw config used to create the machine. */
75
76
  config: AnyStateNodeConfig, options: StateNodeOptions<TContext, TEvent>);
@@ -7,7 +7,7 @@ export { createMachineFromConfig } from "./createMachineFromConfig.js";
7
7
  export type { ActionJSON, GuardJSON, InvokeJSON, MachineJSON, StateNodeJSON, TransitionJSON } from "./createMachineFromConfig.js";
8
8
  export { machineConfigToJSON, serializeMachine, type CodeExpression } from "./serialize.js";
9
9
  export { mapState } from "./mapState.js";
10
- export { machineVersions, migrateSnapshot, type MachineVersionsOptions, type ParsedPersistedSnapshot, type PersistedMachineIdentity, type PersistedSnapshotDataFrom, type SnapshotMigrationHandlers, type PersistedSnapshotFrom } from "./machineVersions.js";
10
+ export { machineVersions, type MigrateSnapshotOptions, type MachineVersionsOptions, type ParsedPersistedSnapshot, type PersistedMachineIdentity, type PersistedSnapshotDataFrom, type PersistedSnapshotSource, type SnapshotMigrationHandlers, type PersistedSnapshotFrom } from "./machineVersions.js";
11
11
  export { types, isTypeSchema, type StandardSchemaV1, type TypeSchema } from "./schema.types.js";
12
12
  export type { ActorValidationBoundary, ActorValidationEventOrigin, ActorValidationRequest, ActorLogicValidator } from "./validation.types.js";
13
13
  export { createSystem, setup } from "./setup.js";
@@ -26,26 +26,30 @@ export type ParsedPersistedSnapshot<TMachines extends readonly AnyStateMachine[]
26
26
  export type MachineVersionsOptions<TMachines extends readonly AnyStateMachine[]> = {
27
27
  unversioned?: NonNullable<TMachines[number]['version']>;
28
28
  };
29
- type ParsedSnapshotSource = {
30
- machine: VersionedStateMachine;
31
- snapshot: Snapshot<unknown> & {
32
- context: unknown;
33
- machine: PersistedMachineIdentity;
34
- [key: string]: unknown;
35
- };
36
- };
37
- type SourceVersion<TSource extends ParsedSnapshotSource> = TSource extends unknown ? NonNullable<TSource['machine']['version']> : never;
38
- type SourceForVersion<TSource extends ParsedSnapshotSource, TVersion extends string> = TSource extends unknown ? TSource['machine']['version'] extends TVersion ? TSource : never : never;
39
- export type SnapshotMigrationHandlers<TSource extends ParsedSnapshotSource, TTarget extends AnyStateMachine> = {
40
- [TVersion in SourceVersion<TSource>]?: (snapshot: SourceForVersion<TSource, TVersion>['snapshot']) => PersistedSnapshotDataFrom<TTarget>;
29
+ type MaybePromise<T> = T | PromiseLike<T>;
30
+ type MachineVersion<TMachines extends readonly VersionedStateMachine[]> = TMachines[number]['version'];
31
+ type MachineForVersion<TMachines extends readonly VersionedStateMachine[], TVersion extends string> = {
32
+ [K in keyof TMachines]: TMachines[K] extends VersionedStateMachine ? TMachines[K]['version'] extends TVersion ? TMachines[K] : never : never;
33
+ }[number];
34
+ export type PersistedSnapshotSource = {
35
+ id?: string;
36
+ version?: string;
37
+ };
38
+ export type SnapshotMigrationHandlers<TMachines extends readonly VersionedStateMachine[], TTarget extends VersionedStateMachine> = {
39
+ [TVersion in Exclude<MachineVersion<TMachines>, TTarget['version']>]?: (snapshot: PersistedSnapshotFrom<MachineForVersion<TMachines, TVersion>>) => MaybePromise<PersistedSnapshotDataFrom<TTarget>>;
40
+ } & {
41
+ '*'?: (snapshot: unknown, source: PersistedSnapshotSource) => MaybePromise<PersistedSnapshotDataFrom<TTarget>>;
42
+ };
43
+ export type MigrateSnapshotOptions<TMachines extends readonly VersionedStateMachine[], TTargetVersion extends MachineVersion<TMachines>> = {
44
+ to: TTargetVersion;
45
+ migrations: SnapshotMigrationHandlers<TMachines, MachineForVersion<TMachines, TTargetVersion>>;
41
46
  };
42
47
  /** Creates parsers backed by retained versions of one machine. */
43
48
  export declare function machineVersions<const TMachines extends readonly [
44
49
  VersionedStateMachine,
45
50
  ...VersionedStateMachine[]
46
51
  ]>(machines: TMachines, options?: MachineVersionsOptions<TMachines>): {
47
- parseSnapshot(raw: unknown): Promise<ParsedPersistedSnapshot<TMachines>>;
52
+ parseSnapshot: (raw: unknown) => Promise<ParsedPersistedSnapshot<TMachines>>;
53
+ migrateSnapshot<TTargetVersion extends MachineVersion<TMachines>>(raw: unknown, migrationOptions: MigrateSnapshotOptions<TMachines, TTargetVersion>): Promise<PersistedSnapshotFrom<MachineForVersion<TMachines, TTargetVersion>>>;
48
54
  };
49
- /** Migrates a parsed persisted snapshot directly to a target machine. */
50
- export declare function migrateSnapshot<TSource extends ParsedSnapshotSource, TTarget extends VersionedStateMachine>(source: TSource, target: TTarget, migrations: SnapshotMigrationHandlers<TSource, TTarget>): Promise<PersistedSnapshotFrom<TTarget>>;
51
55
  export {};
@@ -31,7 +31,13 @@ export declare function getStateNodeByPath(stateNode: AnyStateNode, statePath: s
31
31
  * @param stateValue The state value or State instance
32
32
  */
33
33
  export declare function getStateNodes(stateNode: AnyStateNode, stateValue: StateValue): Array<AnyStateNode>;
34
- export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any, any>, event: TEvent, self: AnyActor): Array<TransitionDefinition<TContext, TEvent>> | undefined;
34
+ export type TransitionSelectionResult = {
35
+ enabled: boolean;
36
+ result: unknown;
37
+ reusable: boolean;
38
+ };
39
+ export type TransitionSelectionResults = Map<AnyTransitionDefinition, TransitionSelectionResult>;
40
+ export declare function transitionNode<TContext extends MachineContext, TEvent extends EventObject>(stateNode: AnyStateNode, stateValue: StateValue, snapshot: MachineSnapshot<TContext, TEvent, any, any, any, any, any, any>, event: TEvent, self: AnyActor, selectionResults?: TransitionSelectionResults): Array<TransitionDefinition<TContext, TEvent>> | undefined;
35
41
  type Microstep = readonly [AnyMachineSnapshot, ExecutableActionObject[]];
36
42
  export declare function initialMicrostep(root: AnyStateNode, preInitialState: AnyMachineSnapshot, actorScope: AnyActorScope, initEvent: AnyEventObject, internalQueue: AnyEventObject[]): Microstep;
37
43
  /**
@@ -44,6 +50,7 @@ export declare function getTransitionResult(transition: Pick<AnyTransitionDefini
44
50
  context?: AnyTransitionDefinition['context'];
45
51
  }, snapshot: AnyMachineSnapshot, event: AnyEventObject, actorScope: AnyActorScope, options?: {
46
52
  resolveActions?: boolean;
53
+ selectionResult?: TransitionSelectionResult;
47
54
  }): {
48
55
  targets: Readonly<AnyStateNode[]> | undefined;
49
56
  context: MachineContext | undefined;
@@ -64,5 +71,5 @@ export declare function macrostep(snapshot: AnyMachineSnapshot, event: EventObje
64
71
  */
65
72
  export declare function resolveStateValue(rootNode: AnyStateNode, stateValue: StateValue): StateValue;
66
73
  export declare function hasEffect(transition: AnyTransitionDefinition, context: MachineContext, event: EventObject, snapshot: AnyMachineSnapshot, self: AnyActor): boolean;
67
- export declare function evaluateCandidate(candidate: AnyTransitionDefinition, event: EventObject, snapshot: AnyMachineSnapshot, stateNode: AnyStateNode, self: AnyActor): boolean;
74
+ export declare function evaluateCandidate(candidate: AnyTransitionDefinition, event: EventObject, snapshot: AnyMachineSnapshot, stateNode: AnyStateNode, self: AnyActor, selectionResults?: TransitionSelectionResults): boolean;
68
75
  export {};
@@ -351,7 +351,7 @@ export interface AnyStateMachine extends AnyActorLogic {
351
351
  schemas?: import("./types.v6.js").AnyMachineSchemas;
352
352
  provide(sources: any): AnyStateMachine;
353
353
  resolveState(config: any): any;
354
- getTransitionData(snapshot: any, event: any, actor: AnyActorRef): AnyTransitionDefinition[];
354
+ getTransitionData(snapshot: any, event: any, actor: AnyActorRef, selectionResults?: Map<AnyTransitionDefinition, unknown>): AnyTransitionDefinition[];
355
355
  getStateNodeById(stateId: string): AnyStateNode;
356
356
  getPersistedSnapshot(snapshot: any, options?: unknown): Snapshot<unknown>;
357
357
  }