xstate 6.0.0-beta.0 → 6.0.0-beta.2

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 (81) hide show
  1. package/bin/xstate.js +10 -4
  2. package/dist/{createActor-551369be.development.esm.js → createActor-0250284a.development.esm.js} +244 -41
  3. package/dist/{createActor-cbe3abac.esm.js → createActor-20a97166.esm.js} +243 -40
  4. package/dist/{createActor-a49ae0ce.development.cjs.js → createActor-c029d29f.development.cjs.js} +245 -40
  5. package/dist/{createActor-25900f76.cjs.js → createActor-c91c9ffe.cjs.js} +244 -39
  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/machineVersion.types.d.ts +2 -2
  11. package/dist/declarations/src/setup.d.ts +5 -5
  12. package/dist/declarations/src/systemTransition.d.ts +1 -1
  13. package/dist/declarations/src/types.d.ts +11 -3
  14. package/dist/declarations/src/types.v6.d.ts +37 -2
  15. package/dist/{effectDescriptor-f73da4ec.development.cjs.js → effectDescriptor-3fff5c51.development.cjs.js} +5 -5
  16. package/dist/{effectDescriptor-2fa27c54.cjs.js → effectDescriptor-47f73e7e.cjs.js} +5 -5
  17. package/dist/{effectDescriptor-321a8ce9.development.esm.js → effectDescriptor-5ac7dccb.development.esm.js} +5 -5
  18. package/dist/{effectDescriptor-d8b0f749.esm.js → effectDescriptor-e93df910.esm.js} +5 -5
  19. package/dist/{machineSchemas-88d01821.cjs.js → legacySnapshot-8d595687.cjs.js} +117 -1
  20. package/dist/{machineSchemas-45c21bc2.esm.js → legacySnapshot-9e06feb4.esm.js} +116 -2
  21. package/dist/{machineSchemas-b5736804.development.esm.js → legacySnapshot-ae6594a7.development.esm.js} +117 -3
  22. package/dist/{machineSchemas-6d96bef4.development.cjs.js → legacySnapshot-ebf0b2b8.development.cjs.js} +118 -2
  23. package/dist/xstate-actors.cjs.js +1 -1
  24. package/dist/xstate-actors.development.cjs.js +1 -1
  25. package/dist/xstate-actors.development.esm.js +2 -2
  26. package/dist/xstate-actors.esm.js +2 -2
  27. package/dist/xstate-actors.umd.min.js +1 -1
  28. package/dist/xstate-actors.umd.min.js.map +1 -1
  29. package/dist/xstate-durable.cjs.js +120 -10
  30. package/dist/xstate-durable.development.cjs.js +120 -10
  31. package/dist/xstate-durable.development.esm.js +120 -10
  32. package/dist/xstate-durable.esm.js +120 -10
  33. package/dist/xstate-durable.umd.min.js +1 -1
  34. package/dist/xstate-durable.umd.min.js.map +1 -1
  35. package/dist/xstate-fsm.cjs.js +4 -4
  36. package/dist/xstate-fsm.development.cjs.js +4 -4
  37. package/dist/xstate-fsm.development.esm.js +4 -4
  38. package/dist/xstate-fsm.esm.js +4 -4
  39. package/dist/xstate-fsm.umd.min.js +1 -1
  40. package/dist/xstate-fsm.umd.min.js.map +1 -1
  41. package/dist/xstate-graph.cjs.js +1 -1
  42. package/dist/xstate-graph.development.cjs.js +1 -1
  43. package/dist/xstate-graph.development.esm.js +2 -2
  44. package/dist/xstate-graph.esm.js +2 -2
  45. package/dist/xstate-graph.umd.min.js +1 -1
  46. package/dist/xstate-graph.umd.min.js.map +1 -1
  47. package/dist/xstate-persist.cjs.js +23 -12
  48. package/dist/xstate-persist.development.cjs.js +23 -12
  49. package/dist/xstate-persist.development.esm.js +17 -6
  50. package/dist/xstate-persist.esm.js +17 -6
  51. package/dist/xstate-persist.umd.min.js +1 -1
  52. package/dist/xstate-persist.umd.min.js.map +1 -1
  53. package/dist/xstate-validation.cjs.js +1 -1
  54. package/dist/xstate-validation.development.cjs.js +1 -1
  55. package/dist/xstate-validation.development.esm.js +1 -1
  56. package/dist/xstate-validation.esm.js +1 -1
  57. package/dist/xstate.cjs.js +63 -51
  58. package/dist/xstate.development.cjs.js +63 -51
  59. package/dist/xstate.development.esm.js +53 -41
  60. package/dist/xstate.esm.js +53 -41
  61. package/dist/xstate.umd.min.js +1 -1
  62. package/dist/xstate.umd.min.js.map +1 -1
  63. package/docs/agents.md +9 -0
  64. package/docs/api-stability.json +273 -249
  65. package/docs/backend-workflows.md +3 -3
  66. package/docs/durable-execution.md +72 -48
  67. package/docs/errors.md +2 -2
  68. package/docs/examples.md +34 -34
  69. package/docs/fsm.md +2 -1
  70. package/docs/guards.md +1 -1
  71. package/docs/index.md +1 -1
  72. package/docs/invoke.md +34 -2
  73. package/docs/persistence.md +16 -10
  74. package/docs/serialization.md +1 -1
  75. package/docs/setup-and-provide.md +3 -3
  76. package/docs/spawn.md +1 -1
  77. package/docs/system-transitions.md +6 -6
  78. package/docs/tutorial.md +5 -5
  79. package/docs/typescript.md +9 -0
  80. package/docs/xstate-v5-to-v6.md +176 -19
  81. package/package.json +1 -1
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var dist_xstateActors = require('./xstate-actors.development.cjs.js');
6
- var createActor = require('./createActor-a49ae0ce.development.cjs.js');
7
- var machineSchemas = require('./machineSchemas-6d96bef4.development.cjs.js');
6
+ var createActor = require('./createActor-c029d29f.development.cjs.js');
7
+ var legacySnapshot = require('./legacySnapshot-ebf0b2b8.development.cjs.js');
8
8
  var schema_types = require('./schema.types-1c16f035.development.cjs.js');
9
- var effectDescriptor = require('./effectDescriptor-f73da4ec.development.cjs.js');
9
+ var effectDescriptor = require('./effectDescriptor-3fff5c51.development.cjs.js');
10
10
  require('./validation-f2714a35.development.cjs.js');
11
11
 
12
12
  /**
@@ -94,7 +94,7 @@ function createMachine(config, ...rest) {
94
94
  throw new Error('createMachine(config) takes one argument; the second argument (implementations) was removed. Declare implementations with setup({ actions, guards, actors, delays }).createMachine(config), or pass them to machine.provide({ ... }).' );
95
95
  }
96
96
  createActor.diagnoseAuthorConfig(config);
97
- return new machineSchemas.StateMachine(config);
97
+ return new legacySnapshot.StateMachine(config);
98
98
  }
99
99
 
100
100
  /**
@@ -104,7 +104,7 @@ function createMachine(config, ...rest) {
104
104
  * @experimental Used by `@xstate/scxml`; not part of the stable API.
105
105
  */
106
106
  function createMachineFromCompiledConfig(config, validator) {
107
- return new machineSchemas.StateMachine(config, undefined, validator);
107
+ return new legacySnapshot.StateMachine(config, undefined, validator);
108
108
  }
109
109
 
110
110
  /** @public */
@@ -1146,10 +1146,10 @@ function isVersionedStateMachine(entry) {
1146
1146
  return 'transition' in entry && typeof entry.transition === 'function';
1147
1147
  }
1148
1148
  function getEntrySnapshotSchema(entry) {
1149
- return isVersionedStateMachine(entry) ? machineSchemas.snapshotSchema(entry) : entry.snapshotSchema;
1149
+ return isVersionedStateMachine(entry) ? legacySnapshot.snapshotSchema(entry) : entry.snapshotSchema;
1150
1150
  }
1151
1151
  function getEntryEventSchema(entry) {
1152
- return isVersionedStateMachine(entry) ? machineSchemas.historicalEventSchema(entry) : entry.eventSchema;
1152
+ return isVersionedStateMachine(entry) ? legacySnapshot.historicalEventSchema(entry) : entry.eventSchema;
1153
1153
  }
1154
1154
  function getSnapshotSource(raw) {
1155
1155
  if (!isObject(raw)) {
@@ -1174,7 +1174,7 @@ async function validate(schema, value, description) {
1174
1174
  return result.value;
1175
1175
  }
1176
1176
  async function finalizeSnapshot(snapshot, target) {
1177
- return await validate(machineSchemas.snapshotSchema(target), {
1177
+ return await validate(legacySnapshot.snapshotSchema(target), {
1178
1178
  ...snapshot,
1179
1179
  machine: {
1180
1180
  id: target.id,
@@ -1311,13 +1311,13 @@ function machineVersions(entries, options) {
1311
1311
  }
1312
1312
  const adapter = adaptationOptions.adapters[source.version];
1313
1313
  if (adapter) {
1314
- return validateEvents(await adapter(sourceEvents), target, machineSchemas.historicalEventSchema(target));
1314
+ return validateEvents(await adapter(sourceEvents), target, legacySnapshot.historicalEventSchema(target));
1315
1315
  }
1316
1316
  }
1317
1317
  }
1318
1318
  const wildcardAdapter = adaptationOptions.adapters['*'];
1319
1319
  if (wildcardAdapter) {
1320
- return validateEvents(await wildcardAdapter(events, adaptationOptions.from), target, machineSchemas.historicalEventSchema(target));
1320
+ return validateEvents(await wildcardAdapter(events, adaptationOptions.from), target, legacySnapshot.historicalEventSchema(target));
1321
1321
  }
1322
1322
  if (hasTypedSource) {
1323
1323
  if (sourceValidationFailed) {
@@ -1780,7 +1780,7 @@ const setup = function setupImplementation(config = {}) {
1780
1780
  } : undefined)
1781
1781
  };
1782
1782
  createActor.diagnoseAuthorConfig(config);
1783
- return new machineSchemas.StateMachine(config, undefined, validator);
1783
+ return new legacySnapshot.StateMachine(config, undefined, validator);
1784
1784
  },
1785
1785
  createInvoke(invokeConfig, ..._check) {
1786
1786
  return typeof invokeConfig.src === 'function' ? {
@@ -2111,13 +2111,13 @@ class SimulatedClock {
2111
2111
  // logical timer key (or, for a directly delivered event, the event type).
2112
2112
  function systemTimerKey(source, event) {
2113
2113
  const key = event.type === 'xstate.timer' ? createActor.readTimerKey(event) : undefined;
2114
- return JSON.stringify([source.$actor, source.incarnation, key ? createActor.serializeTimerKey(key) : event.type]);
2114
+ return JSON.stringify([source['@actor'], source.incarnation, key ? createActor.serializeTimerKey(key) : event.type]);
2115
2115
  }
2116
2116
  function isLogicalTimerPending(snapshot, key) {
2117
2117
  return (snapshot.timers ?? []).some(timer => createActor.matchesTimerKey(timer, key));
2118
2118
  }
2119
2119
  function isReference(value) {
2120
- return !!value && typeof value.$actor === 'string' && typeof value.incarnation === 'string';
2120
+ return !!value && typeof value['@actor'] === 'string' && typeof value.incarnation === 'string';
2121
2121
  }
2122
2122
  function isHandle(value) {
2123
2123
  return !!value && typeof value.address === 'string' && typeof value.getSnapshot === 'function';
@@ -2128,12 +2128,12 @@ const systemLogger = () => {};
2128
2128
  /** Converts runtime-shaped, reduction-local capabilities to snapshot data. */
2129
2129
  function encode(value, seen = new Set(), mappers) {
2130
2130
  if (typeof value === 'function' && mappers?.has(value)) return {
2131
- $systemMapper: mappers.get(value)
2131
+ '@systemMapper': mappers.get(value)
2132
2132
  };
2133
2133
  if (isHandle(value)) {
2134
2134
  if (!value[systemActorHandle]) throw new Error('Live actors cannot be stored in a pure system snapshot.');
2135
2135
  return {
2136
- $actor: value.address,
2136
+ '@actor': value.address,
2137
2137
  incarnation: value.sessionId
2138
2138
  };
2139
2139
  }
@@ -2146,11 +2146,11 @@ function encode(value, seen = new Set(), mappers) {
2146
2146
  let result;
2147
2147
  if (value.machine && typeof value.machine.transition === 'function' && typeof value.id === 'string' && Array.isArray(value.path)) {
2148
2148
  result = {
2149
- $stateNode: value.id
2149
+ '@stateNode': value.id
2150
2150
  };
2151
2151
  } else if (value instanceof Error) {
2152
2152
  result = {
2153
- $error: value.name,
2153
+ '@error': value.name,
2154
2154
  message: value.message
2155
2155
  };
2156
2156
  } else if (Array.isArray(value)) {
@@ -2176,10 +2176,17 @@ function snapshotData(snapshot, mappers) {
2176
2176
  getMeta,
2177
2177
  getInputs,
2178
2178
  toJSON,
2179
+ // Stores such as Convex reject `_`-prefixed field names.
2180
+ _stateInputs: stateInputs,
2181
+ _nextTimerId: nextTimerId,
2182
+ _nextActorIds: nextActorIds,
2179
2183
  ...data
2180
2184
  } = snapshot;
2181
2185
  return encode({
2182
2186
  ...data,
2187
+ stateInputs,
2188
+ nextTimerId,
2189
+ nextActorIds,
2183
2190
  nodeIds: nodes.map(node => node.id)
2184
2191
  }, new Set(), mappers);
2185
2192
  }
@@ -2223,6 +2230,8 @@ class SystemReduction {
2223
2230
  this.mappers = void 0;
2224
2231
  this.remaining = void 0;
2225
2232
  if (!Number.isSafeInteger(maxSteps) || maxSteps < 1) throw new Error('maxSteps must be a positive integer.');
2233
+ // TODO(v7): remove with legacySnapshot.ts.
2234
+ snapshot = legacySnapshot.upgradeLegacySystemSnapshot(snapshot);
2226
2235
  this.logic = definitions(logic);
2227
2236
  this.mappers = logic.mappers ?? {};
2228
2237
  this.mapperNames = new Map(Object.entries(this.mappers).map(([key, mapper]) => [mapper, key]));
@@ -2253,26 +2262,26 @@ class SystemReduction {
2253
2262
  }
2254
2263
  reference(actor) {
2255
2264
  return {
2256
- $actor: actor.address,
2265
+ '@actor': actor.address,
2257
2266
  incarnation: actor.sessionId
2258
2267
  };
2259
2268
  }
2260
2269
  current(ref) {
2261
- const actor = this.snapshot.actors[ref.$actor];
2270
+ const actor = this.snapshot.actors[ref['@actor']];
2262
2271
  return actor?.incarnation === ref.incarnation ? actor : undefined;
2263
2272
  }
2264
2273
  decode(value, machine) {
2265
2274
  if (isReference(value)) return this.handle(value);
2266
2275
  if (!value || typeof value !== 'object') return value;
2267
- if (typeof value.$systemMapper === 'string') {
2268
- const mapper = Object.hasOwn(this.mappers, value.$systemMapper) && this.mappers[value.$systemMapper];
2269
- if (!mapper) throw new Error(`Missing pure mapper '${value.$systemMapper}'.`);
2276
+ if (typeof value['@systemMapper'] === 'string') {
2277
+ const mapper = Object.hasOwn(this.mappers, value['@systemMapper']) && this.mappers[value['@systemMapper']];
2278
+ if (!mapper) throw new Error(`Missing pure mapper '${value['@systemMapper']}'.`);
2270
2279
  return mapper;
2271
2280
  }
2272
- if (typeof value.$stateNode === 'string') return machine.getStateNodeById(value.$stateNode);
2273
- if (typeof value.$error === 'string') {
2281
+ if (typeof value['@stateNode'] === 'string') return machine.getStateNodeById(value['@stateNode']);
2282
+ if (typeof value['@error'] === 'string') {
2274
2283
  const error = new Error(value.message);
2275
- error.name = value.$error;
2284
+ error.name = value['@error'];
2276
2285
  if (error.name === 'TimeoutError') Object.setPrototypeOf(error, dist_xstateActors.TimeoutError.prototype);
2277
2286
  return error;
2278
2287
  }
@@ -2290,7 +2299,7 @@ class SystemReduction {
2290
2299
  const kind = this.attachedKind(actor);
2291
2300
  if (!actor.started || actor.snapshot.status !== 'active' || kind !== '@xstate.listener' && kind !== '@xstate.subscription') continue;
2292
2301
  const target = actor.input.actor;
2293
- if (!target || target.$actor !== source.$actor || target.incarnation !== source.incarnation || !actor.parent || this.current(actor.parent)?.snapshot.status !== 'active') continue;
2302
+ if (!target || target['@actor'] !== source['@actor'] || target.incarnation !== source.incarnation || !actor.parent || this.current(actor.parent)?.snapshot.status !== 'active') continue;
2294
2303
  const input = this.decode(actor.input);
2295
2304
  let event;
2296
2305
  if (kind === '@xstate.listener') {
@@ -2301,7 +2310,7 @@ class SystemReduction {
2301
2310
  if (mapper) event = mapper(snapshot.status === 'done' ? snapshot.output : snapshot.status === 'error' ? snapshot.error : snapshot);
2302
2311
  }
2303
2312
  if (event) this.enqueue({
2304
- $actor: actor.address,
2313
+ '@actor': actor.address,
2305
2314
  incarnation: actor.incarnation
2306
2315
  }, actor.parent, event);
2307
2316
  }
@@ -2309,8 +2318,8 @@ class SystemReduction {
2309
2318
  stopAttachments(parent) {
2310
2319
  for (const actor of Object.values(this.snapshot.actors)) {
2311
2320
  const kind = this.attachedKind(actor);
2312
- if ((kind === '@xstate.listener' || kind === '@xstate.subscription') && actor.parent?.$actor === parent.$actor && actor.parent.incarnation === parent.incarnation) this.stop({
2313
- $actor: actor.address,
2321
+ if ((kind === '@xstate.listener' || kind === '@xstate.subscription') && actor.parent?.['@actor'] === parent['@actor'] && actor.parent.incarnation === parent.incarnation) this.stop({
2322
+ '@actor': actor.address,
2314
2323
  incarnation: actor.incarnation
2315
2324
  });
2316
2325
  }
@@ -2329,6 +2338,9 @@ class SystemReduction {
2329
2338
  const data = this.decode(actor.snapshot, logic);
2330
2339
  const snapshot = typeof logic.getStateNodeById === 'function' && data.nodeIds ? createActor.createMachineSnapshot({
2331
2340
  ...data,
2341
+ _stateInputs: data.stateInputs,
2342
+ _nextTimerId: data.nextTimerId,
2343
+ _nextActorIds: data.nextActorIds,
2332
2344
  _nodes: data.nodeIds.map(id => logic.getStateNodeById(id))
2333
2345
  }, logic) : data;
2334
2346
  this.snapshots.set(key, snapshot);
@@ -2351,8 +2363,8 @@ class SystemReduction {
2351
2363
  };
2352
2364
  const handle = {
2353
2365
  [systemActorHandle]: true,
2354
- id: actor?.id ?? ref.$actor.split('/').at(-1),
2355
- address: ref.$actor,
2366
+ id: actor?.id ?? ref['@actor'].split('/').at(-1),
2367
+ address: ref['@actor'],
2356
2368
  sessionId: ref.incarnation,
2357
2369
  options: {
2358
2370
  _inert: true,
@@ -2391,13 +2403,13 @@ class SystemReduction {
2391
2403
  _unregister: actor => {
2392
2404
  this.stopping.add(JSON.stringify(this.reference(actor)));
2393
2405
  for (const [key, ref] of Object.entries(this.snapshot.registry)) {
2394
- if (ref.$actor === actor.address && ref.incarnation === actor.sessionId) delete this.snapshot.registry[key];
2406
+ if (ref['@actor'] === actor.address && ref.incarnation === actor.sessionId) delete this.snapshot.registry[key];
2395
2407
  }
2396
2408
  },
2397
2409
  _getByAddress: address => {
2398
2410
  const actor = this.snapshot.actors[address];
2399
2411
  return actor?.snapshot.status === 'active' ? this.handle({
2400
- $actor: address,
2412
+ '@actor': address,
2401
2413
  incarnation: actor.incarnation
2402
2414
  }) : undefined;
2403
2415
  },
@@ -2443,11 +2455,11 @@ class SystemReduction {
2443
2455
  if (!definition) throw new Error('Register dynamically spawned logic in systemLogic.actors.');
2444
2456
  const parent = options.parent && this.reference(options.parent);
2445
2457
  const id = options.id ?? `${createActor.getActorIdPrefix(options.src ?? logic)}:${this.snapshot.counters.actor}`;
2446
- const address = `${parent ? parent.$actor + '/' : ''}${createActor.encodeAddressSegment(id)}`;
2458
+ const address = `${parent ? parent['@actor'] + '/' : ''}${createActor.encodeAddressSegment(id)}`;
2447
2459
  const occupied = this.snapshot.actors[address];
2448
2460
  if (occupied?.snapshot.status === 'active') {
2449
2461
  const previous = {
2450
- $actor: address,
2462
+ '@actor': address,
2451
2463
  incarnation: occupied.incarnation
2452
2464
  };
2453
2465
  if (!this.stopping.has(JSON.stringify(previous))) throw new Error(`Actor address '${address}' is already occupied.`);
@@ -2455,7 +2467,7 @@ class SystemReduction {
2455
2467
  }
2456
2468
  const incarnation = String(this.snapshot.counters.actor++);
2457
2469
  const ref = {
2458
- $actor: address,
2470
+ '@actor': address,
2459
2471
  incarnation
2460
2472
  };
2461
2473
  const state = {
@@ -2493,7 +2505,7 @@ class SystemReduction {
2493
2505
  const actor = this.current(ref);
2494
2506
  if (!actor) return;
2495
2507
  this.snapshots.set(JSON.stringify(ref), snapshot);
2496
- this.snapshot.actors[ref.$actor] = {
2508
+ this.snapshot.actors[ref['@actor']] = {
2497
2509
  ...actor,
2498
2510
  snapshot: snapshotData(snapshot, this.mapperNames)
2499
2511
  };
@@ -2543,7 +2555,7 @@ class SystemReduction {
2543
2555
  ...key
2544
2556
  });
2545
2557
  for (const [timerKey, timer] of Object.entries(this.snapshot.timers)) {
2546
- if (timer.source.$actor === ref.$actor && timer.source.incarnation === ref.incarnation && (cancelled === undefined || timerKey === cancelled)) delete this.snapshot.timers[timerKey];
2558
+ if (timer.source['@actor'] === ref['@actor'] && timer.source.incarnation === ref.incarnation && (cancelled === undefined || timerKey === cancelled)) delete this.snapshot.timers[timerKey];
2547
2559
  }
2548
2560
  }
2549
2561
  effectsFor(ref, effects) {
@@ -2581,9 +2593,9 @@ class SystemReduction {
2581
2593
  } else if (createActor.isSerializedActorRef(value.target)) {
2582
2594
  // A ref that went through JSON targets the current incarnation
2583
2595
  // at its address; without one the event is a dead letter.
2584
- const target = this.snapshot.actors[value.target.$actor];
2596
+ const target = this.snapshot.actors[value.target['@actor']];
2585
2597
  if (target?.snapshot.status === 'active' && (value.target.incarnation === undefined || value.target.incarnation === target.incarnation)) this.enqueue(ref, {
2586
- $actor: target.address,
2598
+ '@actor': target.address,
2587
2599
  incarnation: target.incarnation
2588
2600
  }, value.event);else this.external(ref, {
2589
2601
  kind: 'builtin',
@@ -2623,7 +2635,7 @@ class SystemReduction {
2623
2635
  start(ref) {
2624
2636
  const actor = this.current(ref);
2625
2637
  if (!actor || actor.started || actor.snapshot.status === 'stopped') return;
2626
- this.snapshot.actors[ref.$actor] = {
2638
+ this.snapshot.actors[ref['@actor']] = {
2627
2639
  ...actor,
2628
2640
  started: true
2629
2641
  };
@@ -2663,13 +2675,13 @@ class SystemReduction {
2663
2675
  });
2664
2676
  this.cancel(ref);
2665
2677
  this.handle(ref).system._unregister(this.handle(ref));
2666
- this.snapshot.messages = this.snapshot.messages.filter(message => message.target.$actor !== ref.$actor || message.target.incarnation !== ref.incarnation);
2678
+ this.snapshot.messages = this.snapshot.messages.filter(message => message.target['@actor'] !== ref['@actor'] || message.target.incarnation !== ref.incarnation);
2667
2679
  this.cancelExternal(ref);
2668
2680
  this.stopAttachments(ref);
2669
2681
  }
2670
2682
  cancelExternal(ref) {
2671
2683
  for (const [id, effect] of Object.entries(this.snapshot.externalEffects)) {
2672
- if (effect.kind !== 'action' || effect.type === '@xstate.cancelEffect' || effect.type === '@xstate.cleanup' || effect.source.$actor !== ref.$actor || effect.source.incarnation !== ref.incarnation) continue;
2684
+ if (effect.kind !== 'action' || effect.type === '@xstate.cancelEffect' || effect.type === '@xstate.cleanup' || effect.source['@actor'] !== ref['@actor'] || effect.source.incarnation !== ref.incarnation) continue;
2673
2685
  delete this.snapshot.externalEffects[id];
2674
2686
  const cancellation = {
2675
2687
  id: `${this.snapshot.executionId}:${this.snapshot.counters.effect++}`,
@@ -2706,7 +2718,7 @@ class SystemReduction {
2706
2718
  }
2707
2719
  const logic = this.logic.get(actor.src);
2708
2720
  if (!logic) throw new Error(`Missing actor definition '${actor.src}'.`);
2709
- if (logic.isInternalEventType?.(message.event.type) && (!message.source || message.source.$actor !== actor.address || message.source.incarnation !== actor.incarnation)) {
2721
+ if (logic.isInternalEventType?.(message.event.type) && (!message.source || message.source['@actor'] !== actor.address || message.source.incarnation !== actor.incarnation)) {
2710
2722
  throw new Error(`Internal event '${message.event.type}' cannot be injected into a pure system.`);
2711
2723
  }
2712
2724
  if (!message.source && /^(xstate\.after(?:\.|$)|xstate\.timeout(?:\.|$))/.test(message.event.type)) throw new Error('Select a pending timer instead of injecting its internal event.');
@@ -2763,7 +2775,7 @@ class SystemReduction {
2763
2775
  if (event.type === 'xstate.timer') {
2764
2776
  const actor = this.snapshot.actors[path];
2765
2777
  if (!actor) throw new Error(`Unknown actor address '${path}'.`);
2766
- const timer = Object.values(this.snapshot.timers).find(pending => pending.source.$actor === path && pending.source.incarnation === actor.incarnation && pending.occurrence === event.occurrence);
2778
+ const timer = Object.values(this.snapshot.timers).find(pending => pending.source['@actor'] === path && pending.source.incarnation === actor.incarnation && pending.occurrence === event.occurrence);
2767
2779
  if (!timer) throw new Error('Select a current timer occurrence.');
2768
2780
  this.advance(timer.dueAt);
2769
2781
  return;
@@ -2772,12 +2784,12 @@ class SystemReduction {
2772
2784
  const actor = this.snapshot.actors[path];
2773
2785
  if (!actor) throw new Error(`Unknown actor address '${path}'.`);
2774
2786
  const ref = {
2775
- $actor: path,
2787
+ '@actor': path,
2776
2788
  incarnation: actor.incarnation
2777
2789
  };
2778
2790
  if (event.type === 'xstate.system.effect.result') {
2779
2791
  const effect = this.snapshot.externalEffects[event.effectId];
2780
- if (!effect || effect.source.$actor !== path || event.event && (effect.source.incarnation !== actor.incarnation || actor.snapshot.status !== 'active' || effect.type === '@xstate.cancelEffect' || effect.type === '@xstate.cleanup')) throw new Error('External effect result does not match its owner or is stale.');
2792
+ if (!effect || effect.source['@actor'] !== path || event.event && (effect.source.incarnation !== actor.incarnation || actor.snapshot.status !== 'active' || effect.type === '@xstate.cancelEffect' || effect.type === '@xstate.cleanup')) throw new Error('External effect result does not match its owner or is stale.');
2781
2793
  delete this.snapshot.externalEffects[event.effectId];
2782
2794
  if (event.event) {
2783
2795
  this.enqueue(ref, ref, event.event);
@@ -3007,10 +3019,10 @@ exports.matchesState = createActor.matchesState;
3007
3019
  exports.runStep = createActor.runStep;
3008
3020
  exports.stopActor = createActor.stopActor;
3009
3021
  exports.terminateActor = createActor.terminateActor;
3010
- exports.InvalidSnapshotError = machineSchemas.InvalidSnapshotError;
3011
- exports.StateMachine = machineSchemas.StateMachine;
3012
- exports.StateNode = machineSchemas.StateNode;
3013
- exports.eventSchema = machineSchemas.eventSchema;
3022
+ exports.InvalidSnapshotError = legacySnapshot.InvalidSnapshotError;
3023
+ exports.StateMachine = legacySnapshot.StateMachine;
3024
+ exports.StateNode = legacySnapshot.StateNode;
3025
+ exports.eventSchema = legacySnapshot.eventSchema;
3014
3026
  exports.isTypeSchema = schema_types.isTypeSchema;
3015
3027
  exports.types = schema_types.types;
3016
3028
  exports.describeExecutableEffect = effectDescriptor.describeExecutableEffect;