xstate 6.0.0-alpha.24 → 6.0.0-alpha.25

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 (37) hide show
  1. package/dist/{StateMachine-4f3ebd99.esm.js → StateMachine-69278d2c.esm.js} +35 -26
  2. package/dist/{StateMachine-27ce068a.development.cjs.js → StateMachine-ac1167f3.development.cjs.js} +38 -29
  3. package/dist/{StateMachine-0d7aa36b.cjs.js → StateMachine-b20d5a53.cjs.js} +35 -26
  4. package/dist/{StateMachine-f3d5f2d8.development.esm.js → StateMachine-bf4ec0f1.development.esm.js} +38 -29
  5. package/dist/declarations/src/StateMachine.d.ts +11 -11
  6. package/dist/declarations/src/createMachine.d.ts +6 -6
  7. package/dist/declarations/src/createMachineFromConfig.d.ts +5 -5
  8. package/dist/declarations/src/fsm.d.ts +2 -2
  9. package/dist/declarations/src/index.d.ts +1 -1
  10. package/dist/declarations/src/serialize.d.ts +3 -3
  11. package/dist/declarations/src/setup.d.ts +43 -43
  12. package/dist/declarations/src/spawn.d.ts +1 -1
  13. package/dist/declarations/src/types.d.ts +39 -39
  14. package/dist/declarations/src/types.v6.d.ts +24 -24
  15. package/dist/{index-cf2e8954.esm.js → index-036a773f.esm.js} +85 -39
  16. package/dist/{index-46c96e83.development.cjs.js → index-1ad8a761.development.cjs.js} +85 -38
  17. package/dist/{index-1a180503.development.esm.js → index-b90ebcd4.development.esm.js} +85 -39
  18. package/dist/{index-0ef8d20d.cjs.js → index-f58cc498.cjs.js} +85 -38
  19. package/dist/xstate-actors.cjs.js +1 -1
  20. package/dist/xstate-actors.development.cjs.js +1 -1
  21. package/dist/xstate-actors.development.esm.js +1 -1
  22. package/dist/xstate-actors.esm.js +1 -1
  23. package/dist/xstate-actors.umd.min.js +1 -1
  24. package/dist/xstate-actors.umd.min.js.map +1 -1
  25. package/dist/xstate-graph.cjs.js +2 -2
  26. package/dist/xstate-graph.development.cjs.js +2 -2
  27. package/dist/xstate-graph.development.esm.js +2 -2
  28. package/dist/xstate-graph.esm.js +2 -2
  29. package/dist/xstate-graph.umd.min.js +1 -1
  30. package/dist/xstate-graph.umd.min.js.map +1 -1
  31. package/dist/xstate.cjs.js +52 -52
  32. package/dist/xstate.development.cjs.js +52 -52
  33. package/dist/xstate.development.esm.js +54 -54
  34. package/dist/xstate.esm.js +54 -54
  35. package/dist/xstate.umd.min.js +1 -1
  36. package/dist/xstate.umd.min.js.map +1 -1
  37. package/package.json +1 -1
@@ -1,8 +1,8 @@
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, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as $$ACTOR_TYPE } from './index-cf2e8954.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 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, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as createInvokeTimeoutEvent, ah as $$ACTOR_TYPE } from './index-036a773f.esm.js';
2
2
 
3
- function createSpawner(actorScope, actorSources, spawnedChildren) {
3
+ function createSpawner(actorScope, actors, spawnedChildren) {
4
4
  return (src, options) => {
5
- const referencedSrc = Object.entries(actorSources).find(([, logic]) => logic === src)?.[0];
5
+ const referencedSrc = Object.entries(actors).find(([, logic]) => logic === src)?.[0];
6
6
  const actor = actorScope.system.createActorRef(src, {
7
7
  id: options?.id,
8
8
  parent: actorScope.self,
@@ -45,7 +45,8 @@ function createInertActorScope(actorLogic, snapshot, sourceSelf) {
45
45
  const self = createActor(actorLogic, {
46
46
  _inert: true,
47
47
  ...(previousSelf ? {
48
- id: previousSelf.id
48
+ id: previousSelf.id,
49
+ _sessionId: previousSelf.sessionId
49
50
  } : {}),
50
51
  ...(system ? {
51
52
  _systemRef: {
@@ -523,12 +524,12 @@ function getEmptyCanActorScope() {
523
524
  }
524
525
  class StateMachine {
525
526
  constructor(/** The raw config used to create the machine. */
526
- config, implementations) {
527
+ config, sources) {
527
528
  this.config = config;
528
529
  /** The machine's own version. */
529
530
  this.version = void 0;
530
531
  this.schemas = void 0;
531
- this.implementations = void 0;
532
+ this.sources = void 0;
532
533
  /** Runtime options for machine execution. */
533
534
  this.options = void 0;
534
535
  /** @internal */
@@ -547,12 +548,12 @@ class StateMachine {
547
548
  */
548
549
  this._json = void 0;
549
550
  this.id = config.id || '(machine)';
550
- this.implementations = {
551
- actorSources: config.actorSources ?? {},
551
+ this.sources = {
552
+ actors: config.actors ?? {},
552
553
  actions: config.actions ?? {},
553
554
  delays: config.delays ?? {},
554
555
  guards: config.guards ?? {},
555
- ...implementations
556
+ ...sources
556
557
  };
557
558
  this.version = this.config.version;
558
559
  this.schemas = this.config.schemas;
@@ -579,38 +580,38 @@ class StateMachine {
579
580
  }
580
581
 
581
582
  /**
582
- * Clones this state machine with the provided implementations.
583
+ * Clones this state machine with the provided sources.
583
584
  *
584
- * @param implementations Options (`actions`, `guards`, `actorSources`,
585
- * `delays`) to recursively merge with the existing options.
586
- * @returns A new `StateMachine` instance with the provided implementations.
585
+ * @param sources Options (`actions`, `guards`, `actors`, `delays`) to
586
+ * recursively merge with the existing options.
587
+ * @returns A new `StateMachine` instance with the provided sources.
587
588
  */
588
- provide(implementations) {
589
+ provide(sources) {
589
590
  const {
590
591
  actions,
591
592
  guards,
592
- actorSources,
593
+ actors,
593
594
  delays
594
- } = this.implementations;
595
+ } = this.sources;
595
596
  const provided = new StateMachine(this.config, {
596
597
  actions: {
597
598
  ...actions,
598
- ...implementations.actions
599
+ ...sources.actions
599
600
  },
600
601
  guards: {
601
602
  ...guards,
602
- ...implementations.guards
603
+ ...sources.guards
603
604
  },
604
- actorSources: {
605
- ...actorSources,
606
- ...implementations.actorSources
605
+ actors: {
606
+ ...actors,
607
+ ...sources.actors
607
608
  },
608
609
  delays: {
609
610
  ...delays,
610
- ...implementations.delays
611
+ ...sources.delays
611
612
  }
612
613
  });
613
- // Providing implementations does not change the serializable definition.
614
+ // Providing sources does not change the serializable definition.
614
615
  provided._json = this._json;
615
616
  return provided;
616
617
  }
@@ -801,12 +802,12 @@ class StateMachine {
801
802
  }, this, actorScope.self);
802
803
  if (typeof context === 'function') {
803
804
  const children = {};
804
- const spawn = createSpawner(actorScope, this.implementations.actorSources, children);
805
+ const spawn = createSpawner(actorScope, this.sources.actors, children);
805
806
  const resolvedContext = context({
806
807
  spawn,
807
808
  input: initEvent.input,
808
809
  self: actorScope.self,
809
- actorSources: this.implementations.actorSources
810
+ actors: this.sources.actors
810
811
  });
811
812
  const [nextState] = resolveActionsWithContext(preInitial, initEvent, actorScope, []);
812
813
  if (resolvedContext) {
@@ -918,7 +919,6 @@ class StateMachine {
918
919
  syncSnapshot: actorData.syncSnapshot,
919
920
  snapshot: childState,
920
921
  src,
921
- _sessionId: actorData.sessionId,
922
922
  registryKey: actorData.registryKey
923
923
  });
924
924
  // Mark so `start()` knows to start this child (freshly invoked/spawned
@@ -929,6 +929,14 @@ class StateMachine {
929
929
  const timers = {};
930
930
  const persistedTimers = snapshotData.timers ?? {};
931
931
  for (const [id, timer] of Object.entries(persistedTimers)) {
932
+ let event = timer.event;
933
+ if (event.type === 'xstate.timeout.actor') {
934
+ const actorId = event.actorId;
935
+ const child = children[actorId];
936
+ if (child) {
937
+ event = createInvokeTimeoutEvent(actorId, child.sessionId);
938
+ }
939
+ }
932
940
  const target = typeof timer.target === 'string' ? timer.target === 'self' ? 'self' : children[timer.target] : resolvedActorScope.self._parent;
933
941
  if (!target) {
934
942
  const targetDescription = typeof timer.target === 'string' ? timer.target : timer.target.type;
@@ -936,6 +944,7 @@ class StateMachine {
936
944
  }
937
945
  timers[id] = {
938
946
  ...timer,
947
+ event,
939
948
  target
940
949
  };
941
950
  }
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-46c96e83.development.cjs.js');
3
+ var dist_xstateActors = require('./index-1ad8a761.development.cjs.js');
4
4
 
5
- function createSpawner(actorScope, actorSources, spawnedChildren) {
5
+ function createSpawner(actorScope, actors, spawnedChildren) {
6
6
  return (src, options) => {
7
- const referencedSrc = Object.entries(actorSources).find(([, logic]) => logic === src)?.[0];
7
+ const referencedSrc = Object.entries(actors).find(([, logic]) => logic === src)?.[0];
8
8
  const actor = actorScope.system.createActorRef(src, {
9
9
  id: options?.id,
10
10
  parent: actorScope.self,
@@ -47,7 +47,8 @@ function createInertActorScope(actorLogic, snapshot, sourceSelf) {
47
47
  const self = dist_xstateActors.createActor(actorLogic, {
48
48
  _inert: true,
49
49
  ...(previousSelf ? {
50
- id: previousSelf.id
50
+ id: previousSelf.id,
51
+ _sessionId: previousSelf.sessionId
51
52
  } : {}),
52
53
  ...(system ? {
53
54
  _systemRef: {
@@ -543,12 +544,12 @@ function getEmptyCanActorScope() {
543
544
  }
544
545
  class StateMachine {
545
546
  constructor(/** The raw config used to create the machine. */
546
- config, implementations) {
547
+ config, sources) {
547
548
  this.config = config;
548
549
  /** The machine's own version. */
549
550
  this.version = void 0;
550
551
  this.schemas = void 0;
551
- this.implementations = void 0;
552
+ this.sources = void 0;
552
553
  /** Runtime options for machine execution. */
553
554
  this.options = void 0;
554
555
  /** @internal */
@@ -567,18 +568,18 @@ class StateMachine {
567
568
  */
568
569
  this._json = void 0;
569
570
  this.id = config.id || '(machine)';
570
- this.implementations = {
571
- actorSources: config.actorSources ?? {},
571
+ this.sources = {
572
+ actors: config.actors ?? {},
572
573
  actions: config.actions ?? {},
573
574
  delays: config.delays ?? {},
574
575
  guards: config.guards ?? {},
575
- ...implementations
576
+ ...sources
576
577
  };
577
578
  {
578
579
  // The `@xstate.` prefix is reserved for built-in serialized action and
579
- // guard descriptors — user implementation names must not collide.
580
- for (const kind of ['actions', 'guards', 'actorSources', 'delays']) {
581
- for (const key of Object.keys(this.implementations[kind])) {
580
+ // guard descriptors — user source names must not collide.
581
+ for (const kind of ['actions', 'guards', 'actors', 'delays']) {
582
+ for (const key of Object.keys(this.sources[kind])) {
582
583
  if (key.startsWith('@xstate.')) {
583
584
  throw new Error(`Invalid ${kind} name '${key}': the '@xstate.' prefix is reserved for built-in descriptors.`);
584
585
  }
@@ -610,38 +611,38 @@ class StateMachine {
610
611
  }
611
612
 
612
613
  /**
613
- * Clones this state machine with the provided implementations.
614
+ * Clones this state machine with the provided sources.
614
615
  *
615
- * @param implementations Options (`actions`, `guards`, `actorSources`,
616
- * `delays`) to recursively merge with the existing options.
617
- * @returns A new `StateMachine` instance with the provided implementations.
616
+ * @param sources Options (`actions`, `guards`, `actors`, `delays`) to
617
+ * recursively merge with the existing options.
618
+ * @returns A new `StateMachine` instance with the provided sources.
618
619
  */
619
- provide(implementations) {
620
+ provide(sources) {
620
621
  const {
621
622
  actions,
622
623
  guards,
623
- actorSources,
624
+ actors,
624
625
  delays
625
- } = this.implementations;
626
+ } = this.sources;
626
627
  const provided = new StateMachine(this.config, {
627
628
  actions: {
628
629
  ...actions,
629
- ...implementations.actions
630
+ ...sources.actions
630
631
  },
631
632
  guards: {
632
633
  ...guards,
633
- ...implementations.guards
634
+ ...sources.guards
634
635
  },
635
- actorSources: {
636
- ...actorSources,
637
- ...implementations.actorSources
636
+ actors: {
637
+ ...actors,
638
+ ...sources.actors
638
639
  },
639
640
  delays: {
640
641
  ...delays,
641
- ...implementations.delays
642
+ ...sources.delays
642
643
  }
643
644
  });
644
- // Providing implementations does not change the serializable definition.
645
+ // Providing sources does not change the serializable definition.
645
646
  provided._json = this._json;
646
647
  return provided;
647
648
  }
@@ -832,12 +833,12 @@ class StateMachine {
832
833
  }, this, actorScope.self);
833
834
  if (typeof context === 'function') {
834
835
  const children = {};
835
- const spawn = createSpawner(actorScope, this.implementations.actorSources, children);
836
+ const spawn = createSpawner(actorScope, this.sources.actors, children);
836
837
  const resolvedContext = context({
837
838
  spawn,
838
839
  input: initEvent.input,
839
840
  self: actorScope.self,
840
- actorSources: this.implementations.actorSources
841
+ actors: this.sources.actors
841
842
  });
842
843
  const [nextState] = dist_xstateActors.resolveActionsWithContext(preInitial, initEvent, actorScope, []);
843
844
  if (resolvedContext) {
@@ -949,7 +950,6 @@ class StateMachine {
949
950
  syncSnapshot: actorData.syncSnapshot,
950
951
  snapshot: childState,
951
952
  src,
952
- _sessionId: actorData.sessionId,
953
953
  registryKey: actorData.registryKey
954
954
  });
955
955
  // Mark so `start()` knows to start this child (freshly invoked/spawned
@@ -960,6 +960,14 @@ class StateMachine {
960
960
  const timers = {};
961
961
  const persistedTimers = snapshotData.timers ?? {};
962
962
  for (const [id, timer] of Object.entries(persistedTimers)) {
963
+ let event = timer.event;
964
+ if (event.type === 'xstate.timeout.actor') {
965
+ const actorId = event.actorId;
966
+ const child = children[actorId];
967
+ if (child) {
968
+ event = dist_xstateActors.createInvokeTimeoutEvent(actorId, child.sessionId);
969
+ }
970
+ }
963
971
  const target = typeof timer.target === 'string' ? timer.target === 'self' ? 'self' : children[timer.target] : resolvedActorScope.self._parent;
964
972
  if (!target) {
965
973
  const targetDescription = typeof timer.target === 'string' ? timer.target : timer.target.type;
@@ -967,6 +975,7 @@ class StateMachine {
967
975
  }
968
976
  timers[id] = {
969
977
  ...timer,
978
+ event,
970
979
  target
971
980
  };
972
981
  }
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var dist_xstateActors = require('./index-0ef8d20d.cjs.js');
3
+ var dist_xstateActors = require('./index-f58cc498.cjs.js');
4
4
 
5
- function createSpawner(actorScope, actorSources, spawnedChildren) {
5
+ function createSpawner(actorScope, actors, spawnedChildren) {
6
6
  return (src, options) => {
7
- const referencedSrc = Object.entries(actorSources).find(([, logic]) => logic === src)?.[0];
7
+ const referencedSrc = Object.entries(actors).find(([, logic]) => logic === src)?.[0];
8
8
  const actor = actorScope.system.createActorRef(src, {
9
9
  id: options?.id,
10
10
  parent: actorScope.self,
@@ -47,7 +47,8 @@ function createInertActorScope(actorLogic, snapshot, sourceSelf) {
47
47
  const self = dist_xstateActors.createActor(actorLogic, {
48
48
  _inert: true,
49
49
  ...(previousSelf ? {
50
- id: previousSelf.id
50
+ id: previousSelf.id,
51
+ _sessionId: previousSelf.sessionId
51
52
  } : {}),
52
53
  ...(system ? {
53
54
  _systemRef: {
@@ -525,12 +526,12 @@ function getEmptyCanActorScope() {
525
526
  }
526
527
  class StateMachine {
527
528
  constructor(/** The raw config used to create the machine. */
528
- config, implementations) {
529
+ config, sources) {
529
530
  this.config = config;
530
531
  /** The machine's own version. */
531
532
  this.version = void 0;
532
533
  this.schemas = void 0;
533
- this.implementations = void 0;
534
+ this.sources = void 0;
534
535
  /** Runtime options for machine execution. */
535
536
  this.options = void 0;
536
537
  /** @internal */
@@ -549,12 +550,12 @@ class StateMachine {
549
550
  */
550
551
  this._json = void 0;
551
552
  this.id = config.id || '(machine)';
552
- this.implementations = {
553
- actorSources: config.actorSources ?? {},
553
+ this.sources = {
554
+ actors: config.actors ?? {},
554
555
  actions: config.actions ?? {},
555
556
  delays: config.delays ?? {},
556
557
  guards: config.guards ?? {},
557
- ...implementations
558
+ ...sources
558
559
  };
559
560
  this.version = this.config.version;
560
561
  this.schemas = this.config.schemas;
@@ -581,38 +582,38 @@ class StateMachine {
581
582
  }
582
583
 
583
584
  /**
584
- * Clones this state machine with the provided implementations.
585
+ * Clones this state machine with the provided sources.
585
586
  *
586
- * @param implementations Options (`actions`, `guards`, `actorSources`,
587
- * `delays`) to recursively merge with the existing options.
588
- * @returns A new `StateMachine` instance with the provided implementations.
587
+ * @param sources Options (`actions`, `guards`, `actors`, `delays`) to
588
+ * recursively merge with the existing options.
589
+ * @returns A new `StateMachine` instance with the provided sources.
589
590
  */
590
- provide(implementations) {
591
+ provide(sources) {
591
592
  const {
592
593
  actions,
593
594
  guards,
594
- actorSources,
595
+ actors,
595
596
  delays
596
- } = this.implementations;
597
+ } = this.sources;
597
598
  const provided = new StateMachine(this.config, {
598
599
  actions: {
599
600
  ...actions,
600
- ...implementations.actions
601
+ ...sources.actions
601
602
  },
602
603
  guards: {
603
604
  ...guards,
604
- ...implementations.guards
605
+ ...sources.guards
605
606
  },
606
- actorSources: {
607
- ...actorSources,
608
- ...implementations.actorSources
607
+ actors: {
608
+ ...actors,
609
+ ...sources.actors
609
610
  },
610
611
  delays: {
611
612
  ...delays,
612
- ...implementations.delays
613
+ ...sources.delays
613
614
  }
614
615
  });
615
- // Providing implementations does not change the serializable definition.
616
+ // Providing sources does not change the serializable definition.
616
617
  provided._json = this._json;
617
618
  return provided;
618
619
  }
@@ -803,12 +804,12 @@ class StateMachine {
803
804
  }, this, actorScope.self);
804
805
  if (typeof context === 'function') {
805
806
  const children = {};
806
- const spawn = createSpawner(actorScope, this.implementations.actorSources, children);
807
+ const spawn = createSpawner(actorScope, this.sources.actors, children);
807
808
  const resolvedContext = context({
808
809
  spawn,
809
810
  input: initEvent.input,
810
811
  self: actorScope.self,
811
- actorSources: this.implementations.actorSources
812
+ actors: this.sources.actors
812
813
  });
813
814
  const [nextState] = dist_xstateActors.resolveActionsWithContext(preInitial, initEvent, actorScope, []);
814
815
  if (resolvedContext) {
@@ -920,7 +921,6 @@ class StateMachine {
920
921
  syncSnapshot: actorData.syncSnapshot,
921
922
  snapshot: childState,
922
923
  src,
923
- _sessionId: actorData.sessionId,
924
924
  registryKey: actorData.registryKey
925
925
  });
926
926
  // Mark so `start()` knows to start this child (freshly invoked/spawned
@@ -931,6 +931,14 @@ class StateMachine {
931
931
  const timers = {};
932
932
  const persistedTimers = snapshotData.timers ?? {};
933
933
  for (const [id, timer] of Object.entries(persistedTimers)) {
934
+ let event = timer.event;
935
+ if (event.type === 'xstate.timeout.actor') {
936
+ const actorId = event.actorId;
937
+ const child = children[actorId];
938
+ if (child) {
939
+ event = dist_xstateActors.createInvokeTimeoutEvent(actorId, child.sessionId);
940
+ }
941
+ }
934
942
  const target = typeof timer.target === 'string' ? timer.target === 'self' ? 'self' : children[timer.target] : resolvedActorScope.self._parent;
935
943
  if (!target) {
936
944
  const targetDescription = typeof timer.target === 'string' ? timer.target : timer.target.type;
@@ -938,6 +946,7 @@ class StateMachine {
938
946
  }
939
947
  timers[id] = {
940
948
  ...timer,
949
+ event,
941
950
  target
942
951
  };
943
952
  }
@@ -1,8 +1,8 @@
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, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as $$ACTOR_TYPE } from './index-1a180503.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 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, j as macrostep, a6 as cloneMachineSnapshot, a7 as transitionNode, e as XSTATE_TIMER, m as matchesEventDescriptor, a8 as getTransitionResult, a9 as hasEffect, aa as createErrorPlatformEvent, r as resolveActionsWithContext, k as createInitEvent, l as createSpawnEffect, n as initialMicrostep, ab as toStatePath, ac as isStateId, ad as getStateNodeByPath, ae as getPersistedSnapshot, af as resolveReferencedActor, ag as createInvokeTimeoutEvent, ah as $$ACTOR_TYPE } from './index-b90ebcd4.development.esm.js';
2
2
 
3
- function createSpawner(actorScope, actorSources, spawnedChildren) {
3
+ function createSpawner(actorScope, actors, spawnedChildren) {
4
4
  return (src, options) => {
5
- const referencedSrc = Object.entries(actorSources).find(([, logic]) => logic === src)?.[0];
5
+ const referencedSrc = Object.entries(actors).find(([, logic]) => logic === src)?.[0];
6
6
  const actor = actorScope.system.createActorRef(src, {
7
7
  id: options?.id,
8
8
  parent: actorScope.self,
@@ -45,7 +45,8 @@ function createInertActorScope(actorLogic, snapshot, sourceSelf) {
45
45
  const self = createActor(actorLogic, {
46
46
  _inert: true,
47
47
  ...(previousSelf ? {
48
- id: previousSelf.id
48
+ id: previousSelf.id,
49
+ _sessionId: previousSelf.sessionId
49
50
  } : {}),
50
51
  ...(system ? {
51
52
  _systemRef: {
@@ -541,12 +542,12 @@ function getEmptyCanActorScope() {
541
542
  }
542
543
  class StateMachine {
543
544
  constructor(/** The raw config used to create the machine. */
544
- config, implementations) {
545
+ config, sources) {
545
546
  this.config = config;
546
547
  /** The machine's own version. */
547
548
  this.version = void 0;
548
549
  this.schemas = void 0;
549
- this.implementations = void 0;
550
+ this.sources = void 0;
550
551
  /** Runtime options for machine execution. */
551
552
  this.options = void 0;
552
553
  /** @internal */
@@ -565,18 +566,18 @@ class StateMachine {
565
566
  */
566
567
  this._json = void 0;
567
568
  this.id = config.id || '(machine)';
568
- this.implementations = {
569
- actorSources: config.actorSources ?? {},
569
+ this.sources = {
570
+ actors: config.actors ?? {},
570
571
  actions: config.actions ?? {},
571
572
  delays: config.delays ?? {},
572
573
  guards: config.guards ?? {},
573
- ...implementations
574
+ ...sources
574
575
  };
575
576
  {
576
577
  // The `@xstate.` prefix is reserved for built-in serialized action and
577
- // guard descriptors — user implementation names must not collide.
578
- for (const kind of ['actions', 'guards', 'actorSources', 'delays']) {
579
- for (const key of Object.keys(this.implementations[kind])) {
578
+ // guard descriptors — user source names must not collide.
579
+ for (const kind of ['actions', 'guards', 'actors', 'delays']) {
580
+ for (const key of Object.keys(this.sources[kind])) {
580
581
  if (key.startsWith('@xstate.')) {
581
582
  throw new Error(`Invalid ${kind} name '${key}': the '@xstate.' prefix is reserved for built-in descriptors.`);
582
583
  }
@@ -608,38 +609,38 @@ class StateMachine {
608
609
  }
609
610
 
610
611
  /**
611
- * Clones this state machine with the provided implementations.
612
+ * Clones this state machine with the provided sources.
612
613
  *
613
- * @param implementations Options (`actions`, `guards`, `actorSources`,
614
- * `delays`) to recursively merge with the existing options.
615
- * @returns A new `StateMachine` instance with the provided implementations.
614
+ * @param sources Options (`actions`, `guards`, `actors`, `delays`) to
615
+ * recursively merge with the existing options.
616
+ * @returns A new `StateMachine` instance with the provided sources.
616
617
  */
617
- provide(implementations) {
618
+ provide(sources) {
618
619
  const {
619
620
  actions,
620
621
  guards,
621
- actorSources,
622
+ actors,
622
623
  delays
623
- } = this.implementations;
624
+ } = this.sources;
624
625
  const provided = new StateMachine(this.config, {
625
626
  actions: {
626
627
  ...actions,
627
- ...implementations.actions
628
+ ...sources.actions
628
629
  },
629
630
  guards: {
630
631
  ...guards,
631
- ...implementations.guards
632
+ ...sources.guards
632
633
  },
633
- actorSources: {
634
- ...actorSources,
635
- ...implementations.actorSources
634
+ actors: {
635
+ ...actors,
636
+ ...sources.actors
636
637
  },
637
638
  delays: {
638
639
  ...delays,
639
- ...implementations.delays
640
+ ...sources.delays
640
641
  }
641
642
  });
642
- // Providing implementations does not change the serializable definition.
643
+ // Providing sources does not change the serializable definition.
643
644
  provided._json = this._json;
644
645
  return provided;
645
646
  }
@@ -830,12 +831,12 @@ class StateMachine {
830
831
  }, this, actorScope.self);
831
832
  if (typeof context === 'function') {
832
833
  const children = {};
833
- const spawn = createSpawner(actorScope, this.implementations.actorSources, children);
834
+ const spawn = createSpawner(actorScope, this.sources.actors, children);
834
835
  const resolvedContext = context({
835
836
  spawn,
836
837
  input: initEvent.input,
837
838
  self: actorScope.self,
838
- actorSources: this.implementations.actorSources
839
+ actors: this.sources.actors
839
840
  });
840
841
  const [nextState] = resolveActionsWithContext(preInitial, initEvent, actorScope, []);
841
842
  if (resolvedContext) {
@@ -947,7 +948,6 @@ class StateMachine {
947
948
  syncSnapshot: actorData.syncSnapshot,
948
949
  snapshot: childState,
949
950
  src,
950
- _sessionId: actorData.sessionId,
951
951
  registryKey: actorData.registryKey
952
952
  });
953
953
  // Mark so `start()` knows to start this child (freshly invoked/spawned
@@ -958,6 +958,14 @@ class StateMachine {
958
958
  const timers = {};
959
959
  const persistedTimers = snapshotData.timers ?? {};
960
960
  for (const [id, timer] of Object.entries(persistedTimers)) {
961
+ let event = timer.event;
962
+ if (event.type === 'xstate.timeout.actor') {
963
+ const actorId = event.actorId;
964
+ const child = children[actorId];
965
+ if (child) {
966
+ event = createInvokeTimeoutEvent(actorId, child.sessionId);
967
+ }
968
+ }
961
969
  const target = typeof timer.target === 'string' ? timer.target === 'self' ? 'self' : children[timer.target] : resolvedActorScope.self._parent;
962
970
  if (!target) {
963
971
  const targetDescription = typeof timer.target === 'string' ? timer.target : timer.target.type;
@@ -965,6 +973,7 @@ class StateMachine {
965
973
  }
966
974
  timers[id] = {
967
975
  ...timer,
976
+ event,
968
977
  target
969
978
  };
970
979
  }