xstate 6.0.0-beta.1 → 6.0.0-beta.3

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 (87) hide show
  1. package/README.md +4 -2
  2. package/dist/{createActor-cbe3abac.esm.js → createActor-49ea55ba.esm.js} +259 -47
  3. package/dist/{createActor-25900f76.cjs.js → createActor-73aa92ba.cjs.js} +261 -46
  4. package/dist/{createActor-551369be.development.esm.js → createActor-a085b20b.development.esm.js} +260 -48
  5. package/dist/{createActor-a49ae0ce.development.cjs.js → createActor-dfb6b790.development.cjs.js} +262 -47
  6. package/dist/declarations/src/createActor.d.ts +3 -1
  7. package/dist/declarations/src/createMachine.d.ts +6 -3
  8. package/dist/declarations/src/durable/index.d.ts +43 -8
  9. package/dist/declarations/src/effectDescriptor.d.ts +2 -2
  10. package/dist/declarations/src/fsm.d.ts +7 -7
  11. package/dist/declarations/src/machineVersion.types.d.ts +2 -2
  12. package/dist/declarations/src/setup.d.ts +2 -2
  13. package/dist/declarations/src/systemTransition.d.ts +1 -1
  14. package/dist/declarations/src/types.d.ts +4 -2
  15. package/dist/declarations/src/types.v6.d.ts +37 -2
  16. package/dist/{effectDescriptor-2fa27c54.cjs.js → effectDescriptor-3402f63e.cjs.js} +5 -5
  17. package/dist/{effectDescriptor-d8b0f749.esm.js → effectDescriptor-65821048.development.esm.js} +5 -5
  18. package/dist/{effectDescriptor-321a8ce9.development.esm.js → effectDescriptor-72c62058.esm.js} +5 -5
  19. package/dist/{effectDescriptor-f73da4ec.development.cjs.js → effectDescriptor-d0ea44ad.development.cjs.js} +5 -5
  20. package/dist/{machineSchemas-b5736804.development.esm.js → legacySnapshot-11aba2d2.development.esm.js} +117 -3
  21. package/dist/{machineSchemas-6d96bef4.development.cjs.js → legacySnapshot-2e2c1d3b.development.cjs.js} +118 -2
  22. package/dist/{machineSchemas-88d01821.cjs.js → legacySnapshot-a85dfbe2.cjs.js} +117 -1
  23. package/dist/{machineSchemas-45c21bc2.esm.js → legacySnapshot-fffe81a0.esm.js} +116 -2
  24. package/dist/xstate-actors.cjs.js +30 -5
  25. package/dist/xstate-actors.development.cjs.js +30 -5
  26. package/dist/xstate-actors.development.esm.js +31 -6
  27. package/dist/xstate-actors.esm.js +31 -6
  28. package/dist/xstate-actors.umd.min.js +1 -1
  29. package/dist/xstate-actors.umd.min.js.map +1 -1
  30. package/dist/xstate-durable.cjs.js +120 -10
  31. package/dist/xstate-durable.development.cjs.js +120 -10
  32. package/dist/xstate-durable.development.esm.js +120 -10
  33. package/dist/xstate-durable.esm.js +120 -10
  34. package/dist/xstate-durable.umd.min.js +1 -1
  35. package/dist/xstate-durable.umd.min.js.map +1 -1
  36. package/dist/xstate-fsm.cjs.js +61 -31
  37. package/dist/xstate-fsm.development.cjs.js +61 -31
  38. package/dist/xstate-fsm.development.esm.js +61 -31
  39. package/dist/xstate-fsm.esm.js +61 -31
  40. package/dist/xstate-fsm.umd.min.js +1 -1
  41. package/dist/xstate-fsm.umd.min.js.map +1 -1
  42. package/dist/xstate-graph.cjs.js +1 -1
  43. package/dist/xstate-graph.development.cjs.js +1 -1
  44. package/dist/xstate-graph.development.esm.js +2 -2
  45. package/dist/xstate-graph.esm.js +2 -2
  46. package/dist/xstate-graph.umd.min.js +1 -1
  47. package/dist/xstate-graph.umd.min.js.map +1 -1
  48. package/dist/xstate-persist.cjs.js +23 -12
  49. package/dist/xstate-persist.development.cjs.js +23 -12
  50. package/dist/xstate-persist.development.esm.js +17 -6
  51. package/dist/xstate-persist.esm.js +17 -6
  52. package/dist/xstate-persist.umd.min.js +1 -1
  53. package/dist/xstate-persist.umd.min.js.map +1 -1
  54. package/dist/xstate-validation.cjs.js +1 -1
  55. package/dist/xstate-validation.development.cjs.js +1 -1
  56. package/dist/xstate-validation.development.esm.js +1 -1
  57. package/dist/xstate-validation.esm.js +1 -1
  58. package/dist/xstate.cjs.js +86 -56
  59. package/dist/xstate.development.cjs.js +86 -56
  60. package/dist/xstate.development.esm.js +76 -46
  61. package/dist/xstate.esm.js +76 -46
  62. package/dist/xstate.umd.min.js +1 -1
  63. package/dist/xstate.umd.min.js.map +1 -1
  64. package/docs/actor-logic.md +1 -1
  65. package/docs/api-stability.json +335 -305
  66. package/docs/backend-workflows.md +3 -3
  67. package/docs/durable-execution.md +72 -48
  68. package/docs/errors.md +2 -2
  69. package/docs/examples.md +34 -34
  70. package/docs/faq.md +1 -1
  71. package/docs/fsm.md +54 -10
  72. package/docs/guards.md +1 -1
  73. package/docs/index.md +2 -1
  74. package/docs/inspect-actor-systems.md +20 -3
  75. package/docs/inspection.md +5 -1
  76. package/docs/invoke.md +36 -4
  77. package/docs/migrate-inspector.md +141 -0
  78. package/docs/persistence.md +16 -10
  79. package/docs/serialization.md +1 -1
  80. package/docs/setup-and-provide.md +3 -3
  81. package/docs/spawn.md +1 -1
  82. package/docs/system-transitions.md +8 -6
  83. package/docs/transitions.md +5 -1
  84. package/docs/tutorial.md +5 -5
  85. package/docs/typescript.md +9 -0
  86. package/docs/xstate-v5-to-v6.md +23 -21
  87. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  import { type ExecutableEffectDescriptor } from "../effectDescriptor.js";
2
2
  import { type ActorSystemRuntime } from "../system.js";
3
3
  import type { InspectionEvent } from "../inspection.js";
4
- import type { AnyActor, AnyActorLogic, AnyEventObject, CustomExecutableEffect, EventFromLogic, ExecutableEffectFrom, InputFrom, OutputFrom, Snapshot, SnapshotFrom } from "../types.js";
4
+ import type { AnyActor, AnyActorLogic, AnyEventObject, CustomExecutableEffect, EventFromLogic, ExecutableEffectFrom, InputFrom, OutputFrom, SerializedActorRef, Snapshot, SnapshotFrom } from "../types.js";
5
5
  /** @experimental */
6
6
  export interface DurableEffectMetadata {
7
7
  /** Stable within one durable execution. */
@@ -26,6 +26,28 @@ export interface DurableRootEvent<TEvent> {
26
26
  event: TEvent;
27
27
  source: AnyActor | undefined;
28
28
  }
29
+ /**
30
+ * A root-addressed event that the execution received but has not processed,
31
+ * stored in a checkpoint. `source` is the sender's logical address.
32
+ *
33
+ * @experimental
34
+ */
35
+ export interface DurableInboxEntry {
36
+ event: AnyEventObject;
37
+ source: SerializedActorRef | undefined;
38
+ }
39
+ /**
40
+ * Everything needed to resume an execution: the persisted snapshot, the next
41
+ * transition index and the events received but not yet processed. Persist
42
+ * the whole object atomically and pass it to `restore()`.
43
+ *
44
+ * @experimental
45
+ */
46
+ export interface DurableCheckpoint {
47
+ snapshot: Snapshot<unknown>;
48
+ nextTransitionIndex: number;
49
+ inbox: DurableInboxEntry[];
50
+ }
29
51
  /** @experimental */
30
52
  export interface DurableEffect<TEffect> extends DurableEffectMetadata {
31
53
  effect: TEffect;
@@ -148,13 +170,26 @@ export interface DurableExecution<TLogic extends AnyActorLogic> {
148
170
  /** Index assigned to the next transition. Persist this with checkpoints. */
149
171
  readonly nextTransitionIndex: number;
150
172
  /**
151
- * Restores a checkpoint on a fresh execution. Returns effects that start
152
- * active embedded children and re-arm pending root timers; execute them
153
- * with `executeEffects` before waiting or processing the next event.
154
- * Does not send a machine event, replay entry actions, or advance the
155
- * transition index. Restoration effect IDs use `restore:<index>:<effect>`.
173
+ * Returns a checkpoint of `snapshot`: its persisted form, the next
174
+ * transition index and the inbox of root events captured by settled
175
+ * `executeEffects` batches but not yet taken by `waitForEvent()`. Call it
176
+ * after `executeEffects` resolves. Inbox event payloads are stored as they
177
+ * are, so they must be serializable data, like timer events in persisted
178
+ * snapshots. Lifecycle events for children no longer in `snapshot` are
179
+ * dropped, and child snapshot updates are not stored: a restored child
180
+ * reports its current snapshot when it starts.
181
+ */
182
+ checkpoint(snapshot: SnapshotFrom<TLogic>, options?: unknown): DurableCheckpoint;
183
+ /**
184
+ * Restores a checkpoint on a fresh execution. Accepts a `checkpoint()`
185
+ * result, whose inbox `waitForEvent()` hands out first, or a bare persisted
186
+ * snapshot. Returns effects that start active embedded children and re-arm
187
+ * pending root timers; execute them with `executeEffects` before waiting or
188
+ * processing the next event. Does not send a machine event, replay entry
189
+ * actions, or advance the transition index. Restoration effect IDs use
190
+ * `restore:<index>:<effect>`.
156
191
  */
157
- restore(persistedSnapshot: Snapshot<unknown>): [
192
+ restore(checkpoint: DurableCheckpoint | Snapshot<unknown>): [
158
193
  snapshot: DurableSnapshot<TLogic>,
159
194
  effects: DurableEffect<ExecutableEffectFrom<TLogic>>[]
160
195
  ];
@@ -196,7 +231,7 @@ export interface DurableExecution<TLogic extends AnyActorLogic> {
196
231
  * an event a prior `executeEffects` batch captured (an invoked actor
197
232
  * completing, a child reporting up), or — once none are queued — whatever
198
233
  * the adapter's durable wait produces. With `captureRootEvents: false`,
199
- * always delegates to the adapter's wait.
234
+ * delegates to the adapter's wait once a restored inbox is empty.
200
235
  */
201
236
  waitForEvent(): Promise<EventFromLogic<TLogic>>;
202
237
  run(...[input]: undefined extends InputFrom<TLogic> ? [input?: InputFrom<TLogic>] : [input: InputFrom<TLogic>]): Promise<OutputFrom<TLogic>>;
@@ -1,7 +1,7 @@
1
1
  import type { EventObject, ExecutableEffect, SerializedActorRef } from "./types.js";
2
2
  /**
3
3
  * A serializable view of an executable effect. Actor references are replaced
4
- * by `{ $actor: address, incarnation? }` and actor sources by their registered
4
+ * by `{ "@actor": address, incarnation? }` and actor sources by their registered
5
5
  * source keys, so a durable host can journal, deduplicate, and route effects without
6
6
  * holding live actor references. Payload fields (`event`, `input`, `params`,
7
7
  * `output`, `error`) pass through by reference and are only as serializable
@@ -87,7 +87,7 @@ export type ExecutableEffectDescriptor = {
87
87
  /**
88
88
  * Returns the serializable descriptor for an executable effect: the same
89
89
  * discriminants (`kind`, `type`) with actor references replaced by
90
- * `{ $actor: address, incarnation? }` and actor sources by source keys. Payload fields pass through by
90
+ * `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
91
91
  * reference.
92
92
  *
93
93
  * @experimental
@@ -1,5 +1,8 @@
1
1
  import type { EventObject, InferEvents, MachineContext, SetupSchemas, SetupStateSchema } from "./base.types.js";
2
2
  import type { StandardSchemaV1 } from "./schema.types.js";
3
+ type FSMInitEvent = {
4
+ type: 'xstate.init';
5
+ };
3
6
  /** @public */
4
7
  export type FSMArgs<TContext extends MachineContext, TEvent extends EventObject> = {
5
8
  context: TContext;
@@ -22,13 +25,14 @@ type EventForType<TEvent extends EventObject, TType extends string> = [
22
25
  type: TType;
23
26
  }>;
24
27
  /** @public */
25
- export type FSMTransition<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TTransitionContext extends MachineContext = TContext> = TState | FSMTransitionConfig<TTransitionContext, TState> | FSMTransitionFunction<TContext, TEvent, TState, TTransitionContext>;
28
+ export type FSMTransition<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TTransitionContext extends MachineContext = TContext> = FSMTransitionConfig<TTransitionContext, TState> | FSMTransitionFunction<TContext, TEvent, TState, TTransitionContext>;
26
29
  type FSMOn<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TTransitionContext extends MachineContext = TContext> = {
27
30
  [TType in TEvent['type'] & string]?: FSMTransition<TContext, EventForType<TEvent, TType>, TState, TTransitionContext>;
28
31
  };
29
32
  /** @public */
30
33
  export type FSMStateConfig<TContext extends MachineContext, TEvent extends EventObject, TState extends string, TTransitionContext extends MachineContext = TContext> = {
31
34
  on?: FSMOn<TContext, TEvent, TState, TTransitionContext>;
35
+ always?: FSMTransition<TContext, TEvent | FSMInitEvent, TState, TTransitionContext>;
32
36
  };
33
37
  type FSMContextConfig<TContext extends MachineContext> = string extends keyof TContext ? {
34
38
  context?: TContext;
@@ -134,14 +138,10 @@ type FSMSetupTransitionConfig<TSourceContext extends MachineContext, TStates ext
134
138
  } | {
135
139
  [TTarget in keyof TStates & string]: FSMSetupTargetTransitionConfig<TSourceContext, TTarget, FSMSetupStateContext<TTarget, TStates, TGlobalContext>>;
136
140
  }[keyof TStates & string];
137
- type FSMSetupStringTransition<TSourceContext extends MachineContext, TStates extends FSMSetupStates, TGlobalContext extends MachineContext> = {
138
- [TTarget in keyof TStates & string]: [TSourceContext] extends [
139
- FSMSetupStateContext<TTarget, TStates, TGlobalContext>
140
- ] ? TTarget : never;
141
- }[keyof TStates & string];
142
141
  type FSMSetupTransitionFunction<TSourceContext extends MachineContext, TEvent extends EventObject, TStates extends FSMSetupStates, TGlobalContext extends MachineContext> = (args: FSMArgs<TSourceContext, TEvent>) => FSMSetupTransitionConfig<TSourceContext, TStates, TGlobalContext> | undefined;
143
- type FSMSetupTransition<TSourceContext extends MachineContext, TEvent extends EventObject, TStates extends FSMSetupStates, TGlobalContext extends MachineContext, TMachineStates extends Record<string, unknown>> = [keyof TStates] extends [never] ? FSMTransition<TSourceContext, TEvent, keyof TMachineStates & string> : FSMSetupStringTransition<TSourceContext, TStates, TGlobalContext> | FSMSetupTransitionConfig<TSourceContext, TStates, TGlobalContext> | FSMSetupTransitionFunction<TSourceContext, TEvent, TStates, TGlobalContext>;
142
+ type FSMSetupTransition<TSourceContext extends MachineContext, TEvent extends EventObject, TStates extends FSMSetupStates, TGlobalContext extends MachineContext, TMachineStates extends Record<string, unknown>> = [keyof TStates] extends [never] ? FSMTransition<TSourceContext, TEvent, keyof TMachineStates & string> : FSMSetupTransitionConfig<TSourceContext, TStates, TGlobalContext> | FSMSetupTransitionFunction<TSourceContext, TEvent, TStates, TGlobalContext>;
144
143
  type FSMSetupStateConfig<TSourceContext extends MachineContext, TEvent extends EventObject, TStates extends FSMSetupStates, TGlobalContext extends MachineContext, TMachineStates extends Record<string, unknown>> = {
144
+ always?: FSMSetupTransition<TSourceContext, TEvent | FSMInitEvent, TStates, TGlobalContext, TMachineStates>;
145
145
  on?: {
146
146
  [TType in TEvent['type'] & string]?: FSMSetupTransition<TSourceContext, EventForType<TEvent, TType>, TStates, TGlobalContext, TMachineStates>;
147
147
  };
@@ -15,8 +15,8 @@ export type PersistedMachineSnapshot = {
15
15
  historyValue: Record<string, unknown>;
16
16
  timers: readonly unknown[];
17
17
  _nextActorId?: number;
18
- _nextActorIds?: Record<string, number>;
19
- _nextTimerId?: number;
18
+ nextActorIds?: Record<string, number>;
19
+ nextTimerId?: number;
20
20
  stateInputs?: Record<string, Record<string, unknown>>;
21
21
  machine?: {
22
22
  id: string;
@@ -9,7 +9,7 @@ import { AnyActorSystem } from "./system.js";
9
9
  import { InspectionEvent } from "./inspection.js";
10
10
  import type { MachineSnapshot } from "./State.js";
11
11
  import { type AsyncActorLogic, type AsyncSnapshot, type AsyncLogicFunction } from "./actors/promise.js";
12
- import { ActionSchemas, DelayMapFromNames, DelaySourceMap, GuardSourceMap, GuardSchemas, InferChildren, InferActions, InferGuards, Sources, InferMachineInput, InferOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_InvokeConfig, Next_InvokeConfigBase, InvokeInputArgs, Next_StateNodeConfig, Next_TransitionConfigOrTarget, type createdInvokeConfig, FinalStateConfigOutput, OutputFromConfig, ChildCompletionEvents, DelayDurationKey, ValidateDelayNames, ValidateEventDescriptors, ValidateHistoryDefaults, ValidateInvokeInputs, ValidateVersionedMachineId, ValidateStateTargets, WithDefault } from "./types.v6.js";
12
+ import { ActionSchemas, DelayMapFromNames, DelaySourceMap, GuardSourceMap, GuardSchemas, InferChildren, InferredInvokeChildren, InferActions, InferGuards, Sources, InferMachineInput, InferOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_InvokeConfig, Next_InvokeConfigBase, InvokeInputArgs, Next_StateNodeConfig, Next_TransitionConfigOrTarget, type createdInvokeConfig, FinalStateConfigOutput, OutputFromConfig, ChildCompletionEvents, DelayDurationKey, ValidateDelayNames, ValidateEventDescriptors, ValidateHistoryDefaults, ValidateInvokeInputs, ValidateVersionedMachineId, ValidateStateTargets, WithDefault } from "./types.v6.js";
13
13
  /** @public */
14
14
  export type SetupConfig<TSchemas extends SetupSchemas, TStates extends Record<string, SetupStateSchema>, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TValidator extends ActorLogicValidator | undefined = ActorLogicValidator | undefined> = {
15
15
  validator?: TValidator;
@@ -1220,7 +1220,7 @@ export interface SetupReturn<TStates extends Record<string, SetupStateSchema> =
1220
1220
  ] extends [never] ? never : {
1221
1221
  type: 'xstate.route';
1222
1222
  to: RoutableStateId<SetupMachineStateSchema<TConfig, TStates>>;
1223
- }), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<SetupMachineStateSchema<TConfig, TStates>>, TTag & string, SetupInput<TSchemas, TInputSchema>, SetupOrConfigOutput<TSchemas, TOutputSchema, TConfig, TStates>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, PublicStateSchema<SetupMachineStateSchema<TConfig, TStates>> & {
1223
+ }), Cast<MergeChildren<SetupChildren<TSchemas, TChildrenSchemaMap>, TActor> & InferredInvokeChildren<TConfig, MergeSourceMaps<TSetupActorMap, TActorMap>>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<SetupMachineStateSchema<TConfig, TStates>>, TTag & string, SetupInput<TSchemas, TInputSchema>, SetupOrConfigOutput<TSchemas, TOutputSchema, TConfig, TStates>, SetupEmitted<TSchemas, TEmittedSchemaMap>, SetupMeta<TSchemas, TMetaSchema>, PublicStateSchema<SetupMachineStateSchema<TConfig, TStates>> & {
1224
1224
  schemas: MergedSetupSchemas<SetupConfigSchemas<TConfig>, TSchemas>;
1225
1225
  }, MergeSourceMaps<SetupActions<TSchemas, TSetupActionMap>, MergeSourceMaps<InferActions<TActionSchemaMap>, TActionMap>>, MergeSourceMaps<TSetupActorMap, TActorMap>, MergeSourceMaps<SetupGuards<TSchemas, TSetupGuardMap>, MergeSourceMaps<InferGuards<TGuardSchemaMap>, TGuardMap>>, DelayMapFromNames<TSetupDelays | TDelays, MergeSourceMaps<TSetupDelayMap, TDelayMap>>, SetupInternalEvents<TSchemas, TInternalEventSchemaMap>, SetupTransitionMeta<TSchemas, TMetaSchema, TTransitionMetaSchema>> & MachineIdentity<TConfig>;
1226
1226
  /**
@@ -11,7 +11,7 @@ export interface SystemLogic<TLogic extends AnyActorLogic = AnyActorLogic> {
11
11
  }
12
12
  /** An actor identity, without a live actor or runtime. @experimental */
13
13
  export interface SystemActorReference {
14
- readonly $actor: string;
14
+ readonly '@actor': string;
15
15
  readonly incarnation: string;
16
16
  }
17
17
  /** Actor state and topology in a system snapshot. @experimental */
@@ -40,7 +40,9 @@ export type UnifiedArg<TContext extends MachineContext, TExpressionEvent extends
40
40
  } & OutputArg<TExpressionEvent>;
41
41
  type DoneEventType = 'xstate.done.actor' | 'xstate.done.state';
42
42
  /** @public */
43
- export type OutputArg<TEvent extends EventObject> = TEvent extends {
43
+ export type OutputArg<TEvent extends EventObject> = [TEvent] extends [never] ? {
44
+ output: undefined;
45
+ } : TEvent extends {
44
46
  type: DoneEventType;
45
47
  output: infer TOutput;
46
48
  } ? {
@@ -941,7 +943,7 @@ export interface ActorLike<TCurrent, TEvent extends EventObject> extends Subscri
941
943
  */
942
944
  export interface SerializedActorRef {
943
945
  /** The actor's logical address. */
944
- $actor: string;
946
+ '@actor': string;
945
947
  /** The incarnation token, when the serializer knows it. */
946
948
  incarnation?: string;
947
949
  }
@@ -4,7 +4,7 @@ import { SetupStateSchemas, StandardSchemaV1 } from "./schema.types.js";
4
4
  import type { ActionSchemas, GuardSchemas, InferEvents, InferInternalEvents } from "./base.types.js";
5
5
  export type { ActionSchemas, GuardSchemas, InferEvents, InferInternalEvents };
6
6
  import { MachineSnapshot } from "./State.js";
7
- import { Action, ActorTimeoutEvent, AfterEvent, ActorLogic, ActorRef, ActorRefFrom, ActorSelf, AnyActorLogic, AnyActorRef, DoneActorEvent, ErrorFrom, ErrorActorEvent, EnqueueObject, EventDescriptor, ReservedEventDescriptor, ReservedMachineEvent, ReservedEventFromDescriptor, ErrorEvent, EventObject, EventPayloadPattern, ExtractEvent, InitialContext, InputFrom, MetaObject, OutputFrom, SnapshotEvent, StateValue, TransitionContextMapper, TransitionContextPatch, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry, TimeoutEvent, RequiredLogicInput } from "./types.js";
7
+ import { Action, ActorTimeoutEvent, AfterEvent, ActorLogic, ActorRef, ActorRefFrom, ActorFromLogic, ActorSelf, AnyActorLogic, AnyActorRef, DoneActorEvent, ErrorFrom, ErrorActorEvent, EnqueueObject, EventDescriptor, ReservedEventDescriptor, ReservedMachineEvent, ReservedEventFromDescriptor, ErrorEvent, EventObject, EventPayloadPattern, ExtractEvent, InitialContext, InputFrom, MetaObject, OutputFrom, SnapshotEvent, StateValue, TransitionContextMapper, TransitionContextPatch, TransitionConfigFunction, Values, AnyStateNode, SystemRegistry, TimeoutEvent, RequiredLogicInput } from "./types.js";
8
8
  import type { Compute, DoNotInfer, IsNever, NonReducibleUnknown, SingleOrArray } from "./typeUtils.js";
9
9
  import { MachineContext, Mapper } from "./types.js";
10
10
  import type { LowInfer } from "./typeUtils.js";
@@ -58,6 +58,41 @@ export type SchemaOrConfigOutput<TOutputSchema extends StandardSchemaV1, TConfig
58
58
  export type InferChildren<TChildrenSchemaMap extends Record<string, StandardSchemaV1>> = string extends keyof TChildrenSchemaMap ? {} : {
59
59
  [K in keyof TChildrenSchemaMap & string]?: StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]> extends AnyActorRef ? NormalizeActorRef<StandardSchemaV1.InferOutput<TChildrenSchemaMap[K]>> : never;
60
60
  };
61
+ type InvokeSourceLogic<TSrc, TActors extends Sources['actors']> = [0] extends [
62
+ 1 & TSrc
63
+ ] ? never : TSrc extends keyof TActors ? TActors[TSrc] : TSrc extends AnyActorLogic ? TSrc : TSrc extends (...args: any[]) => infer TResult ? InvokeSourceLogic<TResult, TActors> : never;
64
+ type InvokedChild<TInvoke, TActors extends Sources['actors']> = TInvoke extends readonly (infer TItem)[] ? InvokedChild<TItem, TActors> : TInvoke extends {
65
+ readonly [createdInvokeConfig]: infer TConfig;
66
+ src: infer TLogic;
67
+ } ? TConfig extends {
68
+ id: infer TId extends string;
69
+ } ? string extends TId ? never : TLogic extends AnyActorLogic ? {
70
+ id: TId;
71
+ ref: ActorFromLogic<TLogic>;
72
+ } : never : never : TInvoke extends {
73
+ id: infer TId extends string;
74
+ src: infer TSrc;
75
+ } ? string extends TId ? never : InvokeSourceLogic<TSrc, TActors> extends infer TLogic extends AnyActorLogic ? {
76
+ id: TId;
77
+ ref: ActorFromLogic<TLogic>;
78
+ } : never : never;
79
+ type InvokedChildren<TConfig, TActors extends Sources['actors']> = (TConfig extends {
80
+ invoke: infer TInvoke;
81
+ } ? InvokedChild<TInvoke, TActors> : never) | (TConfig extends {
82
+ states: infer TStates;
83
+ } ? {
84
+ [K in keyof TStates]: InvokedChildren<TStates[K], TActors>;
85
+ }[keyof TStates] : never);
86
+ /** Type-level plumbing for children inferred from literal invoke IDs. */
87
+ export type InferredInvokeChildren<TConfig, TActors extends Sources['actors'], TChild extends {
88
+ id: string;
89
+ ref: AnyActorRef;
90
+ } = InvokedChildren<TConfig, TActors>> = [TChild] extends [never] ? {} : {
91
+ [K in TChild['id']]?: TChild extends {
92
+ id: string;
93
+ ref: AnyActorRef;
94
+ } ? K extends TChild['id'] ? TChild['ref'] : never : never;
95
+ };
61
96
  export type InferActions<TActionSchemaMap extends ActionSchemas> = string extends keyof TActionSchemaMap ? {} : {
62
97
  [K in keyof TActionSchemaMap & string]: (params: StandardSchemaV1.InferOutput<TActionSchemaMap[K]['params']>) => void | {
63
98
  context?: any;
@@ -224,7 +259,7 @@ type LogicForChildRef<TActorRef> = NonNullable<TActorRef> extends ActorRef<infer
224
259
  * With no registered sources (empty or permissive maps) there is no competing
225
260
  * branch, so the full transition config is allowed.
226
261
  */
227
- type InlineInvokeOnDone<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>> = [keyof TActorMap & string] extends [never] ? Next_TransitionConfigOrTarget<TContext, DoneActorEvent<any>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, undefined, TChildren> : string extends keyof TActorMap ? Next_TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TActorMap[keyof TActorMap & string]>>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, undefined, TChildren> : undefined | {
262
+ type InlineInvokeOnDone<TContext extends MachineContext, TEvent extends EventObject, TEmitted extends EventObject, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TMeta extends MetaObject, TChildren extends Record<string, AnyActorRef | undefined>> = [keyof TActorMap & string] extends [never] ? Next_TransitionConfigOrTarget<TContext, DoneActorEvent<unknown>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, undefined, TChildren> : string extends keyof TActorMap ? Next_TransitionConfigOrTarget<TContext, DoneActorEvent<OutputFrom<TActorMap[keyof TActorMap & string]>>, TEvent, TEmitted, TActionMap, TActorMap, TGuardMap, TDelayMap, TMeta, undefined, TChildren> : undefined | {
228
263
  matches?: EventPayloadPattern<DoneActorEvent>;
229
264
  target?: string | string[];
230
265
  context?: TransitionContextPatch<TContext>;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-25900f76.cjs.js');
3
+ var createActor = require('./createActor-73aa92ba.cjs.js');
4
4
 
5
5
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
6
6
  const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
@@ -202,7 +202,7 @@ function getNextTransitions(state) {
202
202
 
203
203
  /**
204
204
  * A serializable view of an executable effect. Actor references are replaced
205
- * by `{ $actor: address, incarnation? }` and actor sources by their registered
205
+ * by `{ "@actor": address, incarnation? }` and actor sources by their registered
206
206
  * source keys, so a durable host can journal, deduplicate, and route effects without
207
207
  * holding live actor references. Payload fields (`event`, `input`, `params`,
208
208
  * `output`, `error`) pass through by reference and are only as serializable
@@ -224,9 +224,9 @@ function toRef(actor) {
224
224
  }
225
225
  const incarnation = createActor.isRemoteActorRef(actor) ? actor.sessionId : undefined;
226
226
  return incarnation === undefined ? {
227
- $actor: actor.address
227
+ '@actor': actor.address
228
228
  } : {
229
- $actor: actor.address,
229
+ '@actor': actor.address,
230
230
  incarnation
231
231
  };
232
232
  }
@@ -234,7 +234,7 @@ function toRef(actor) {
234
234
  /**
235
235
  * Returns the serializable descriptor for an executable effect: the same
236
236
  * discriminants (`kind`, `type`) with actor references replaced by
237
- * `{ $actor: address, incarnation? }` and actor sources by source keys. Payload fields pass through by
237
+ * `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
238
238
  * reference.
239
239
  *
240
240
  * @experimental
@@ -1,4 +1,4 @@
1
- import { ai as createInertActorScope, aj as setInertActorScopeSnapshot, l as finalizeTransitionResult, al as attachSnapshotActorRef, Q as createInitEvent, aF as hasAmbientInspector, ak as beginSpawnAllocation, am as macrostep, az as createSpawnEffect, aA as initialMicrostep, i as isAtomicStateNode, aG as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aH as isRemoteActorRef } from './createActor-cbe3abac.esm.js';
1
+ import { ai as createInertActorScope, aj as setInertActorScopeSnapshot, l as finalizeTransitionResult, al as attachSnapshotActorRef, Q as createInitEvent, aH as hasAmbientInspector, ak as beginSpawnAllocation, am as macrostep, aA as createSpawnEffect, aB as initialMicrostep, i as isAtomicStateNode, aI as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aJ as isRemoteActorRef } from './createActor-a085b20b.development.esm.js';
2
2
 
3
3
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
4
4
  const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
@@ -200,7 +200,7 @@ function getNextTransitions(state) {
200
200
 
201
201
  /**
202
202
  * A serializable view of an executable effect. Actor references are replaced
203
- * by `{ $actor: address, incarnation? }` and actor sources by their registered
203
+ * by `{ "@actor": address, incarnation? }` and actor sources by their registered
204
204
  * source keys, so a durable host can journal, deduplicate, and route effects without
205
205
  * holding live actor references. Payload fields (`event`, `input`, `params`,
206
206
  * `output`, `error`) pass through by reference and are only as serializable
@@ -222,9 +222,9 @@ function toRef(actor) {
222
222
  }
223
223
  const incarnation = isRemoteActorRef(actor) ? actor.sessionId : undefined;
224
224
  return incarnation === undefined ? {
225
- $actor: actor.address
225
+ '@actor': actor.address
226
226
  } : {
227
- $actor: actor.address,
227
+ '@actor': actor.address,
228
228
  incarnation
229
229
  };
230
230
  }
@@ -232,7 +232,7 @@ function toRef(actor) {
232
232
  /**
233
233
  * Returns the serializable descriptor for an executable effect: the same
234
234
  * discriminants (`kind`, `type`) with actor references replaced by
235
- * `{ $actor: address, incarnation? }` and actor sources by source keys. Payload fields pass through by
235
+ * `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
236
236
  * reference.
237
237
  *
238
238
  * @experimental
@@ -1,4 +1,4 @@
1
- import { ah as createInertActorScope, ai as setInertActorScopeSnapshot, l as finalizeTransitionResult, ak as attachSnapshotActorRef, O as createInitEvent, aG as hasAmbientInspector, aj as beginSpawnAllocation, al as macrostep, az as createSpawnEffect, aA as initialMicrostep, i as isAtomicStateNode, aH as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aI as isRemoteActorRef } from './createActor-551369be.development.esm.js';
1
+ import { aj as createInertActorScope, ak as setInertActorScopeSnapshot, l as finalizeTransitionResult, am as attachSnapshotActorRef, R as createInitEvent, aG as hasAmbientInspector, al as beginSpawnAllocation, an as macrostep, aA as createSpawnEffect, aB as initialMicrostep, i as isAtomicStateNode, aH as getProperAncestors, q as readTimerKey, k as getActorIdPrefix, o as isSerializedActorRef, aI as isRemoteActorRef } from './createActor-49ea55ba.esm.js';
2
2
 
3
3
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
4
4
  const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
@@ -200,7 +200,7 @@ function getNextTransitions(state) {
200
200
 
201
201
  /**
202
202
  * A serializable view of an executable effect. Actor references are replaced
203
- * by `{ $actor: address, incarnation? }` and actor sources by their registered
203
+ * by `{ "@actor": address, incarnation? }` and actor sources by their registered
204
204
  * source keys, so a durable host can journal, deduplicate, and route effects without
205
205
  * holding live actor references. Payload fields (`event`, `input`, `params`,
206
206
  * `output`, `error`) pass through by reference and are only as serializable
@@ -222,9 +222,9 @@ function toRef(actor) {
222
222
  }
223
223
  const incarnation = isRemoteActorRef(actor) ? actor.sessionId : undefined;
224
224
  return incarnation === undefined ? {
225
- $actor: actor.address
225
+ '@actor': actor.address
226
226
  } : {
227
- $actor: actor.address,
227
+ '@actor': actor.address,
228
228
  incarnation
229
229
  };
230
230
  }
@@ -232,7 +232,7 @@ function toRef(actor) {
232
232
  /**
233
233
  * Returns the serializable descriptor for an executable effect: the same
234
234
  * discriminants (`kind`, `type`) with actor references replaced by
235
- * `{ $actor: address, incarnation? }` and actor sources by source keys. Payload fields pass through by
235
+ * `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
236
236
  * reference.
237
237
  *
238
238
  * @experimental
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var createActor = require('./createActor-a49ae0ce.development.cjs.js');
3
+ var createActor = require('./createActor-dfb6b790.development.cjs.js');
4
4
 
5
5
  function attachMicrostepActorRefs(microsteps, actorScope, inputSnapshot) {
6
6
  const result = microsteps.map(([snapshot, actions, transitions]) => [snapshot, actions, transitions ?? []]);
@@ -202,7 +202,7 @@ function getNextTransitions(state) {
202
202
 
203
203
  /**
204
204
  * A serializable view of an executable effect. Actor references are replaced
205
- * by `{ $actor: address, incarnation? }` and actor sources by their registered
205
+ * by `{ "@actor": address, incarnation? }` and actor sources by their registered
206
206
  * source keys, so a durable host can journal, deduplicate, and route effects without
207
207
  * holding live actor references. Payload fields (`event`, `input`, `params`,
208
208
  * `output`, `error`) pass through by reference and are only as serializable
@@ -224,9 +224,9 @@ function toRef(actor) {
224
224
  }
225
225
  const incarnation = createActor.isRemoteActorRef(actor) ? actor.sessionId : undefined;
226
226
  return incarnation === undefined ? {
227
- $actor: actor.address
227
+ '@actor': actor.address
228
228
  } : {
229
- $actor: actor.address,
229
+ '@actor': actor.address,
230
230
  incarnation
231
231
  };
232
232
  }
@@ -234,7 +234,7 @@ function toRef(actor) {
234
234
  /**
235
235
  * Returns the serializable descriptor for an executable effect: the same
236
236
  * discriminants (`kind`, `type`) with actor references replaced by
237
- * `{ $actor: address, incarnation? }` and actor sources by source keys. Payload fields pass through by
237
+ * `{ "@actor": address, incarnation? }` and actor sources by source keys. Payload fields pass through by
238
238
  * reference.
239
239
  *
240
240
  * @experimental
@@ -1,4 +1,4 @@
1
- import { _ as resolveRegisteredActorSource, $ as allocateChildId, a0 as assertChildIdFree, a1 as reserveChildId, a2 as hasUnescapedDot, a3 as STATE_DELIMITER, a4 as mapValues, t as toArray, a5 as createInvokeId, a6 as getDelayedTransitions, a7 as getCandidates, a8 as evaluateCandidate, a9 as formatTransition, aa as NULL_EVENT, ab as toTransitionConfigArray, ac as matchesActorSession, ad as describeMachine, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, o as isSerializedActorRef, a as assertUnreservedSourceName, ae as formatRouteTransitions, af as resolveStateValue, e as createMachineSnapshot, ag as isInFinalState, ah as createInertActorScope, ai as setInertActorScopeSnapshot, Q as createDeadLetterEffect, aj as beginSpawnAllocation, ak as attachSnapshotActorRef, al as macrostep, am as isInertActorScope, an as setSnapshotActorRef, ao as cloneMachineSnapshot, ap as transitionNode, aq as XSTATE_TIMER, m as matchesEventDescriptor, ar as getTransitionResult, as as hasEffect, at as createErrorPlatformEvent, au as withActorSelf, av as resolveActionsWithContext, aw as freezeContext, ax as takeSpawnAllocationCounters, ay as mergeActorIdCounters, O as createInitEvent, az as createSpawnEffect, aA as initialMicrostep, aB as createStartEffect, aC as isStateId, aD as getPersistedSnapshot, aE as detachedScopes, aF as toStatePath, h as createActor } from './createActor-551369be.development.esm.js';
1
+ import { $ as resolveRegisteredActorSource, a0 as allocateChildId, a1 as assertChildIdFree, a2 as reserveChildId, a3 as hasUnescapedDot, a4 as STATE_DELIMITER, a5 as mapValues, t as toArray, a6 as createInvokeId, a7 as getDelayedTransitions, a8 as getCandidates, a9 as evaluateCandidate, aa as formatTransition, ab as NULL_EVENT, ac as toTransitionConfigArray, ad as matchesActorSession, ae as describeMachine, g as getAllStateNodes, b as getStateNodes, r as resolveInvokedActorLogic, o as isSerializedActorRef, a as assertUnreservedSourceName, af as formatRouteTransitions, ag as resolveStateValue, e as createMachineSnapshot, ah as isInFinalState, ai as createInertActorScope, aj as setInertActorScopeSnapshot, R as createDeadLetterEffect, ak as beginSpawnAllocation, al as attachSnapshotActorRef, am as macrostep, an as isInertActorScope, ao as setSnapshotActorRef, ap as cloneMachineSnapshot, aq as transitionNode, ar as XSTATE_TIMER, m as matchesEventDescriptor, as as getTransitionResult, at as hasEffect, au as createErrorPlatformEvent, av as withActorSelf, aw as resolveActionsWithContext, ax as freezeContext, ay as takeSpawnAllocationCounters, az as mergeActorIdCounters, Q as createInitEvent, aA as createSpawnEffect, aB as initialMicrostep, aC as createStartEffect, aD as isStateId, aE as getPersistedSnapshot, aF as detachedScopes, aG as toStatePath, h as createActor } from './createActor-a085b20b.development.esm.js';
2
2
  import { a as assertValid } from './validation-e69470ad.development.esm.js';
3
3
 
4
4
  var isDevelopment = true;
@@ -129,7 +129,7 @@ class StateNode {
129
129
  this.machine = options._machine;
130
130
  if (this.parent && hasUnescapedDot(this.key)) {
131
131
  throw new Error(// The suggestion is written as a JS string literal.
132
- `State key "${this.key}" contains "." — nest the states or escape it as "${this.key.replaceAll(/(?<!\\)\./g, '\\\\.')}".` );
132
+ `State key "${this.key}" contains ".". Nest the states or escape it as "${this.key.replaceAll(/(?<!\\)\./g, '\\\\.')}".` );
133
133
  }
134
134
  this.path = this.parent ? this.parent.path.concat(this.key) : [];
135
135
  const firstStateKey = this.config.states ? Object.keys(this.config.states)[0] : undefined;
@@ -672,6 +672,15 @@ class StateMachine {
672
672
  /** @internal */
673
673
  this.idMap = new Map();
674
674
  this.root = void 0;
675
+ /**
676
+ * Returns the machine itself, never a Proxy wrapped around it (a function
677
+ * member is not wrapped by reactive proxies, so it still closes over the raw
678
+ * instance). Persistence resolves state nodes through it, matching the
679
+ * bound `transition` / `getInitialSnapshot`.
680
+ *
681
+ * @internal
682
+ */
683
+ this._raw = () => this;
675
684
  /**
676
685
  * The machine's `id`, or the empty string when the config declares none.
677
686
  * The root state node has this id; a machine without one has no `#id` root.
@@ -1368,4 +1377,109 @@ function eventSchema(machine) {
1368
1377
  }));
1369
1378
  }
1370
1379
 
1371
- export { InvalidSnapshotError as I, StateMachine as S, StateNode as a, eventSchema as e, historicalEventSchema as h, snapshotSchema as s, validatePersistedSnapshot as v };
1380
+ // TODO(v7): remove this module and its callers. It reads snapshots written by
1381
+ // 6.0.0-beta.1, which used `$`- and `_`-prefixed field names that stores such
1382
+ // as Convex reject. Snapshots are written with the new names only.
1383
+
1384
+ // Legacy marker key -> [new key, other keys the marker object may have].
1385
+ const markers = {
1386
+ $actor: ['@actor', ['incarnation']],
1387
+ $error: ['@error', ['message']],
1388
+ $stateNode: ['@stateNode', []],
1389
+ $systemMapper: ['@systemMapper', []]
1390
+ };
1391
+ const fields = {
1392
+ _stateInputs: 'stateInputs',
1393
+ _nextTimerId: 'nextTimerId',
1394
+ _nextActorIds: 'nextActorIds'
1395
+ };
1396
+
1397
+ // Persisted snapshots are JSON; live objects (actors, state nodes, errors)
1398
+ // are left alone.
1399
+ function isPlain(value) {
1400
+ if (!value || typeof value !== 'object') return false;
1401
+ const proto = Object.getPrototypeOf(value);
1402
+ return proto === Object.prototype || proto === null || Array.isArray(value);
1403
+ }
1404
+ function renameMarkers(value, allowed) {
1405
+ if (!isPlain(value)) return value;
1406
+ if (Array.isArray(value)) {
1407
+ const items = value.map(item => renameMarkers(item, allowed));
1408
+ return items.some((item, i) => item !== value[i]) ? items : value;
1409
+ }
1410
+ const keys = Object.keys(value);
1411
+ const legacy = keys.find(key => allowed.includes(key));
1412
+ if (legacy && typeof value[legacy] === 'string' && keys.every(key => key === legacy || markers[legacy][1].includes(key))) {
1413
+ const {
1414
+ [legacy]: name,
1415
+ ...rest
1416
+ } = value;
1417
+ return {
1418
+ [markers[legacy][0]]: name,
1419
+ ...rest
1420
+ };
1421
+ }
1422
+ let copy;
1423
+ for (const key of keys) {
1424
+ const item = renameMarkers(value[key], allowed);
1425
+ if (item !== value[key]) (copy ??= {
1426
+ ...value
1427
+ })[key] = item;
1428
+ }
1429
+ return copy ?? value;
1430
+ }
1431
+
1432
+ // beta.1 always wrote `_nextTimerId` on machine snapshots. Current snapshots
1433
+ // write `nextTimerId`, so marker-shaped data in them is left alone.
1434
+ function isLegacyEnvelope(envelope) {
1435
+ return isPlain(envelope) && '_nextTimerId' in envelope && !('nextTimerId' in envelope);
1436
+ }
1437
+ function renameFields(envelope) {
1438
+ // A live machine snapshot keeps its `_`-prefixed in-memory fields.
1439
+ if (!isPlain(envelope) || typeof envelope.matches === 'function') return envelope;
1440
+ let copy;
1441
+ for (const [legacy, name] of Object.entries(fields)) {
1442
+ if (legacy in envelope && !(name in envelope)) {
1443
+ const {
1444
+ [legacy]: value,
1445
+ ...rest
1446
+ } = copy ?? envelope;
1447
+ copy = {
1448
+ ...rest,
1449
+ [name]: value
1450
+ };
1451
+ }
1452
+ }
1453
+ return copy ?? envelope;
1454
+ }
1455
+
1456
+ /** Upgrades a persisted machine snapshot written by 6.0.0-beta.1. */
1457
+ function upgradeLegacyPersistedSnapshot(snapshot) {
1458
+ if (snapshot?.machine && typeof snapshot.matches === 'function') return snapshot;
1459
+ if (!isLegacyEnvelope(snapshot)) return snapshot;
1460
+ return renameMarkers(renameFields(snapshot), ['$actor']);
1461
+ }
1462
+
1463
+ /** Upgrades a `systemTransition` snapshot written by 6.0.0-beta.1. */
1464
+ function upgradeLegacySystemSnapshot(snapshot) {
1465
+ const actors = Object.values(snapshot?.actors ?? {});
1466
+ if (!actors.some(actor => isLegacyEnvelope(actor?.snapshot))) return snapshot;
1467
+ const upgraded = renameMarkers(snapshot, Object.keys(markers));
1468
+ if (!upgraded?.actors) return upgraded;
1469
+ let renamed;
1470
+ for (const [address, actor] of Object.entries(upgraded.actors)) {
1471
+ const data = renameFields(actor?.snapshot);
1472
+ if (data !== actor?.snapshot) (renamed ??= {
1473
+ ...upgraded.actors
1474
+ })[address] = {
1475
+ ...actor,
1476
+ snapshot: data
1477
+ };
1478
+ }
1479
+ return renamed ? {
1480
+ ...upgraded,
1481
+ actors: renamed
1482
+ } : upgraded;
1483
+ }
1484
+
1485
+ export { InvalidSnapshotError as I, StateMachine as S, StateNode as a, upgradeLegacyPersistedSnapshot as b, eventSchema as e, historicalEventSchema as h, snapshotSchema as s, upgradeLegacySystemSnapshot as u, validatePersistedSnapshot as v };