xstate 6.0.0-alpha.39 → 6.0.0-alpha.40

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.
@@ -1,8 +1,8 @@
1
1
  export { T as TimeoutError, c as createAsyncLogic, a as createCallbackLogic, b as createEmptyActor, d as createEventObservableLogic, e as createLogic, f as createObservableLogic } from './index-17f889df.development.esm.js';
2
2
  import { m as matchesEventDescriptor, t as toArray$1, b as builtInActions, X as XSTATE_INIT, f as finalizeTransitionResult, d as deriveDeferredStarts, c as createTransitionEnqueue, w as withActorScope, a as XSTATE_STOP, r as resolveActionsWithContext, e as XSTATE_TIMER, g as createSendToEffect, i as isLazyActorScope, p as parseDelayToMilliseconds, h as isAtomicStateNode, j as createActor } from './createActor-2a03d4b2.development.esm.js';
3
3
  export { A as Actor, x as __unsafe_getAllOwnEventDescriptors, z as checkStateIn, j as createActor, k as createListenerLogic, l as createSubscriptionLogic, D as executeEffects, o as getInitialSnapshot, q as getNextSnapshot, v as getStateNodes, E as isBuiltInExecutableAction, u as isMachineSnapshot, n as listenerLogic, y as matchesState, B as pathToStateValue, s as subscriptionLogic, C as toObserver } from './createActor-2a03d4b2.development.esm.js';
4
- import { S as StateMachine } from './StateMachine-da29dd2e.development.esm.js';
5
- export { S as StateMachine, a as StateNode } from './StateMachine-da29dd2e.development.esm.js';
4
+ import { S as StateMachine } from './StateMachine-f8c7feca.development.esm.js';
5
+ export { S as StateMachine, a as StateNode } from './StateMachine-f8c7feca.development.esm.js';
6
6
  export { a as getInitialMicrosteps, g as getMicrosteps, b as getNextTransitions, i as initialTransition, t as transition } from './transition-f581ffa6.development.esm.js';
7
7
 
8
8
  /**
@@ -1967,6 +1967,15 @@ function mapState(snapshot, mapper) {
1967
1967
  function isObject(value) {
1968
1968
  return value !== null && typeof value === 'object';
1969
1969
  }
1970
+ function isVersionedStateMachine(entry) {
1971
+ return 'transition' in entry && typeof entry.transition === 'function';
1972
+ }
1973
+ function hasSnapshotSchema(entry) {
1974
+ return 'snapshotSchema' in entry && entry.snapshotSchema !== undefined;
1975
+ }
1976
+ function hasEventSchema(entry) {
1977
+ return 'eventSchema' in entry && entry.eventSchema !== undefined;
1978
+ }
1970
1979
  function getSnapshotSource(raw, defaultId) {
1971
1980
  if (!isObject(raw)) {
1972
1981
  return {};
@@ -1993,65 +2002,57 @@ async function validate(schema, value, description) {
1993
2002
  return result.value;
1994
2003
  }
1995
2004
  async function finalizeSnapshot(snapshot, target) {
1996
- const context = await validate(target.schemas?.context, snapshot.context, `context for machine '${target.id}' version '${target.version}'`);
1997
- return {
2005
+ return await validate(target.snapshotSchema, {
1998
2006
  ...snapshot,
1999
- context,
2000
2007
  machine: {
2001
2008
  id: target.id,
2002
2009
  version: target.version
2003
2010
  },
2004
2011
  version: target.version
2005
- };
2012
+ }, `snapshot for machine '${target.id}' version '${target.version}'`);
2006
2013
  }
2007
- async function validateEvents(events, machine) {
2014
+ async function validateEvents(events, source) {
2008
2015
  return Promise.all(events.map(async (event, index) => {
2009
- if (!isObject(event) || typeof event.type !== 'string') {
2010
- throw new Error(`Invalid event at index ${index}.`);
2011
- }
2012
- const eventSchemas = machine.schemas?.events;
2013
- const isFrameworkEvent = event.type.startsWith('xstate.') || event.type.startsWith('@xstate.');
2014
- const schema = eventSchemas && Object.hasOwn(eventSchemas, event.type) ? eventSchemas[event.type] : undefined;
2015
- if (eventSchemas && !schema && !isFrameworkEvent) {
2016
- throw new Error(`Unknown event '${event.type}' for machine '${machine.id}' version '${machine.version}'.`);
2017
- }
2018
- if (!schema) {
2019
- return event;
2016
+ const result = await source.eventSchema['~standard'].validate(event);
2017
+ if (result.issues) {
2018
+ const message = result.issues[0]?.message;
2019
+ if (message?.startsWith('Unknown event ')) {
2020
+ throw new Error(message);
2021
+ }
2022
+ const type = isObject(event) ? event.type : undefined;
2023
+ throw new Error(typeof type === 'string' ? `Invalid event '${type}' at index ${index}${message ? `: ${message}` : '.'}` : `Invalid event at index ${index}${message ? `: ${message}` : '.'}`);
2020
2024
  }
2021
- const {
2022
- type,
2023
- ...payload
2024
- } = event;
2025
- const validatedPayload = await validate(schema, payload, `event '${type}' at index ${index}`);
2026
- if (!isObject(validatedPayload)) {
2027
- throw new Error(`Invalid event '${type}' at index ${index}.`);
2025
+ const validated = result.value;
2026
+ if (!isObject(validated) || typeof validated.type !== 'string') {
2027
+ throw new Error(`Invalid event at index ${index}.`);
2028
2028
  }
2029
- return {
2030
- ...validatedPayload,
2031
- type
2032
- };
2029
+ return validated;
2033
2030
  }));
2034
2031
  }
2035
2032
 
2036
- /** Creates migration and adaptation utilities backed by retained versions of one machine. */
2037
- function machineVersions(machines, options) {
2033
+ /** Creates migration and adaptation utilities for versions of one machine. */
2034
+ function machineVersions(entries, options) {
2038
2035
  const byIdentity = new Map();
2039
- const machineId = machines[0].id;
2040
- for (const machine of machines) {
2041
- if (machine.version === undefined) {
2042
- throw new Error(`Machine '${machine.id}' must define a version.`);
2036
+ const machinesByIdentity = new Map();
2037
+ const machineId = entries[0].id;
2038
+ for (const entry of entries) {
2039
+ if (entry.version === undefined) {
2040
+ throw new Error(`Machine '${entry.id}' must define a version.`);
2043
2041
  }
2044
- if (machine.version === '*') {
2042
+ if (entry.version === '*') {
2045
2043
  throw new Error("Machine version '*' is reserved for wildcard migrations.");
2046
2044
  }
2047
- if (machine.id !== machineId) {
2048
- throw new Error(`Machine '${machine.id}' does not match machine ID '${machineId}'.`);
2045
+ if (entry.id !== machineId) {
2046
+ throw new Error(`Machine '${entry.id}' does not match machine ID '${machineId}'.`);
2049
2047
  }
2050
- const key = `${machine.id}\0${machine.version}`;
2048
+ const key = `${entry.id}\0${entry.version}`;
2051
2049
  if (byIdentity.has(key)) {
2052
- throw new Error(`Duplicate machine identity '${machine.id}' version '${machine.version}'.`);
2050
+ throw new Error(`Duplicate machine identity '${entry.id}' version '${entry.version}'.`);
2051
+ }
2052
+ byIdentity.set(key, entry);
2053
+ if (isVersionedStateMachine(entry)) {
2054
+ machinesByIdentity.set(key, entry);
2053
2055
  }
2054
- byIdentity.set(key, machine);
2055
2056
  }
2056
2057
  if (options?.unversioned !== undefined && !byIdentity.has(`${machineId}\0${options.unversioned}`)) {
2057
2058
  throw new Error(`Unversioned snapshot version '${options.unversioned}' is not retained for machine '${machineId}'.`);
@@ -2085,16 +2086,21 @@ function machineVersions(machines, options) {
2085
2086
  if (raw.version !== undefined && raw.version !== version) {
2086
2087
  throw new Error(`Persisted snapshot version '${raw.version}' conflicts with machine version '${version}'.`);
2087
2088
  }
2088
- const machine = byIdentity.get(`${id}\0${version}`);
2089
- if (!machine) {
2089
+ const source = byIdentity.get(`${id}\0${version}`);
2090
+ if (!source) {
2090
2091
  throw new Error(`Unknown machine identity '${id}' version '${version}'.`);
2091
2092
  }
2092
- const context = await validate(machine.schemas?.context, raw.context, `context for machine '${id}' version '${version}'`);
2093
+ if (!hasSnapshotSchema(source)) {
2094
+ throw new Error(`Machine version '${version}' does not define a snapshot schema.`);
2095
+ }
2096
+ const snapshot = await validate(source.snapshotSchema, raw, `snapshot for machine '${id}' version '${version}'`);
2093
2097
  return {
2094
- machine,
2098
+ source,
2099
+ ...(isVersionedStateMachine(source) && {
2100
+ machine: source
2101
+ }),
2095
2102
  snapshot: {
2096
- ...raw,
2097
- context,
2103
+ ...snapshot,
2098
2104
  machine: {
2099
2105
  id,
2100
2106
  version
@@ -2105,15 +2111,16 @@ function machineVersions(machines, options) {
2105
2111
  return {
2106
2112
  parseSnapshot,
2107
2113
  async adaptEvents(events, adaptationOptions) {
2108
- const target = byIdentity.get(`${machineId}\0${adaptationOptions.to}`);
2114
+ const target = machinesByIdentity.get(`${machineId}\0${adaptationOptions.to}`);
2109
2115
  if (!target) {
2110
- throw new Error(`Target version '${adaptationOptions.to}' is not retained for machine '${machineId}'.`);
2116
+ throw new Error(`Target version '${adaptationOptions.to}' is not backed by a machine for '${machineId}'.`);
2111
2117
  }
2112
2118
  const sourceId = adaptationOptions.from.id ?? machineId;
2113
2119
  const source = byIdentity.get(`${sourceId}\0${adaptationOptions.from.version}`);
2114
2120
  let sourceError;
2115
2121
  let sourceValidationFailed = false;
2116
- if (source) {
2122
+ const hasTypedSource = source && hasEventSchema(source);
2123
+ if (hasTypedSource) {
2117
2124
  let sourceEvents;
2118
2125
  try {
2119
2126
  sourceEvents = await validateEvents(events, source);
@@ -2135,7 +2142,7 @@ function machineVersions(machines, options) {
2135
2142
  if (wildcardAdapter) {
2136
2143
  return validateEvents(await wildcardAdapter(events, adaptationOptions.from), target);
2137
2144
  }
2138
- if (source) {
2145
+ if (hasTypedSource) {
2139
2146
  if (sourceValidationFailed) {
2140
2147
  throw sourceError instanceof Error ? sourceError : new Error(`Unable to validate event history for machine '${source.id}' version '${source.version}'.`, {
2141
2148
  cause: sourceError
@@ -2143,12 +2150,15 @@ function machineVersions(machines, options) {
2143
2150
  }
2144
2151
  throw new Error(`No event adapter from version '${source.version}' to '${target.version}' for machine '${target.id}'.`);
2145
2152
  }
2153
+ if (source) {
2154
+ throw new Error(`Machine version '${source.version}' does not define an event schema; only the '*' adapter can handle its event history.`);
2155
+ }
2146
2156
  throw new Error(`Unknown event history source '${sourceId}' version '${adaptationOptions.from.version}'.`);
2147
2157
  },
2148
2158
  async migrateSnapshot(raw, migrationOptions) {
2149
- const target = byIdentity.get(`${machineId}\0${migrationOptions.to}`);
2159
+ const target = machinesByIdentity.get(`${machineId}\0${migrationOptions.to}`);
2150
2160
  if (!target) {
2151
- throw new Error(`Target version '${migrationOptions.to}' is not retained for machine '${machineId}'.`);
2161
+ throw new Error(`Target version '${migrationOptions.to}' is not backed by a machine for '${machineId}'.`);
2152
2162
  }
2153
2163
  let source;
2154
2164
  let parseError;
@@ -2158,10 +2168,10 @@ function machineVersions(machines, options) {
2158
2168
  parseError = error;
2159
2169
  }
2160
2170
  if (source) {
2161
- if (source.machine.version === target.version) {
2171
+ if (source.source.version === target.version) {
2162
2172
  return finalizeSnapshot(source.snapshot, target);
2163
2173
  }
2164
- const exactMigration = migrationOptions.migrations[source.machine.version];
2174
+ const exactMigration = migrationOptions.migrations[source.source.version];
2165
2175
  if (exactMigration) {
2166
2176
  return finalizeSnapshot(await exactMigration(source.snapshot), target);
2167
2177
  }
@@ -2169,7 +2179,7 @@ function machineVersions(machines, options) {
2169
2179
  const wildcardMigration = migrationOptions.migrations['*'];
2170
2180
  if (!wildcardMigration) {
2171
2181
  if (source) {
2172
- throw new Error(`No snapshot migration from version '${source.machine.version}' to '${target.version}' for machine '${target.id}'.`);
2182
+ throw new Error(`No snapshot migration from version '${source.source.version}' to '${target.version}' for machine '${target.id}'.`);
2173
2183
  }
2174
2184
  throw parseError;
2175
2185
  }
@@ -2631,6 +2641,12 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
2631
2641
 
2632
2642
  /** A persisted snapshot tied to a versioned actor logic identity. */
2633
2643
 
2644
+ /**
2645
+ * A persisted snapshot restorable into the given actor logic: any snapshot
2646
+ * created by logic with the same machine `id` is accepted, regardless of
2647
+ * version (version mismatches are handled at runtime, e.g. by `migrate`).
2648
+ */
2649
+
2634
2650
  /** @deprecated Use `AnyActor` instead. */
2635
2651
 
2636
2652
  // Based on RxJS types
@@ -1,8 +1,8 @@
1
1
  export { T as TimeoutError, c as createAsyncLogic, a as createCallbackLogic, b as createEmptyActor, d as createEventObservableLogic, e as createLogic, f as createObservableLogic } from './index-7020402e.esm.js';
2
2
  import { m as matchesEventDescriptor, t as toArray$1, b as builtInActions, X as XSTATE_INIT, f as finalizeTransitionResult, d as deriveDeferredStarts, c as createTransitionEnqueue, w as withActorScope, a as XSTATE_STOP, r as resolveActionsWithContext, e as XSTATE_TIMER, g as createSendToEffect, i as isLazyActorScope, p as parseDelayToMilliseconds, h as isAtomicStateNode, j as createActor } from './createActor-a211c276.esm.js';
3
3
  export { A as Actor, x as __unsafe_getAllOwnEventDescriptors, z as checkStateIn, j as createActor, k as createListenerLogic, l as createSubscriptionLogic, D as executeEffects, o as getInitialSnapshot, q as getNextSnapshot, v as getStateNodes, E as isBuiltInExecutableAction, u as isMachineSnapshot, n as listenerLogic, y as matchesState, B as pathToStateValue, s as subscriptionLogic, C as toObserver } from './createActor-a211c276.esm.js';
4
- import { S as StateMachine } from './StateMachine-2f47d890.esm.js';
5
- export { S as StateMachine, a as StateNode } from './StateMachine-2f47d890.esm.js';
4
+ import { S as StateMachine } from './StateMachine-6082c3cf.esm.js';
5
+ export { S as StateMachine, a as StateNode } from './StateMachine-6082c3cf.esm.js';
6
6
  export { a as getInitialMicrosteps, g as getMicrosteps, b as getNextTransitions, i as initialTransition, t as transition } from './transition-e8a13c00.esm.js';
7
7
 
8
8
  /**
@@ -1967,6 +1967,15 @@ function mapState(snapshot, mapper) {
1967
1967
  function isObject(value) {
1968
1968
  return value !== null && typeof value === 'object';
1969
1969
  }
1970
+ function isVersionedStateMachine(entry) {
1971
+ return 'transition' in entry && typeof entry.transition === 'function';
1972
+ }
1973
+ function hasSnapshotSchema(entry) {
1974
+ return 'snapshotSchema' in entry && entry.snapshotSchema !== undefined;
1975
+ }
1976
+ function hasEventSchema(entry) {
1977
+ return 'eventSchema' in entry && entry.eventSchema !== undefined;
1978
+ }
1970
1979
  function getSnapshotSource(raw, defaultId) {
1971
1980
  if (!isObject(raw)) {
1972
1981
  return {};
@@ -1993,65 +2002,57 @@ async function validate(schema, value, description) {
1993
2002
  return result.value;
1994
2003
  }
1995
2004
  async function finalizeSnapshot(snapshot, target) {
1996
- const context = await validate(target.schemas?.context, snapshot.context, `context for machine '${target.id}' version '${target.version}'`);
1997
- return {
2005
+ return await validate(target.snapshotSchema, {
1998
2006
  ...snapshot,
1999
- context,
2000
2007
  machine: {
2001
2008
  id: target.id,
2002
2009
  version: target.version
2003
2010
  },
2004
2011
  version: target.version
2005
- };
2012
+ }, `snapshot for machine '${target.id}' version '${target.version}'`);
2006
2013
  }
2007
- async function validateEvents(events, machine) {
2014
+ async function validateEvents(events, source) {
2008
2015
  return Promise.all(events.map(async (event, index) => {
2009
- if (!isObject(event) || typeof event.type !== 'string') {
2010
- throw new Error(`Invalid event at index ${index}.`);
2011
- }
2012
- const eventSchemas = machine.schemas?.events;
2013
- const isFrameworkEvent = event.type.startsWith('xstate.') || event.type.startsWith('@xstate.');
2014
- const schema = eventSchemas && Object.hasOwn(eventSchemas, event.type) ? eventSchemas[event.type] : undefined;
2015
- if (eventSchemas && !schema && !isFrameworkEvent) {
2016
- throw new Error(`Unknown event '${event.type}' for machine '${machine.id}' version '${machine.version}'.`);
2017
- }
2018
- if (!schema) {
2019
- return event;
2016
+ const result = await source.eventSchema['~standard'].validate(event);
2017
+ if (result.issues) {
2018
+ const message = result.issues[0]?.message;
2019
+ if (message?.startsWith('Unknown event ')) {
2020
+ throw new Error(message);
2021
+ }
2022
+ const type = isObject(event) ? event.type : undefined;
2023
+ throw new Error(typeof type === 'string' ? `Invalid event '${type}' at index ${index}${message ? `: ${message}` : '.'}` : `Invalid event at index ${index}${message ? `: ${message}` : '.'}`);
2020
2024
  }
2021
- const {
2022
- type,
2023
- ...payload
2024
- } = event;
2025
- const validatedPayload = await validate(schema, payload, `event '${type}' at index ${index}`);
2026
- if (!isObject(validatedPayload)) {
2027
- throw new Error(`Invalid event '${type}' at index ${index}.`);
2025
+ const validated = result.value;
2026
+ if (!isObject(validated) || typeof validated.type !== 'string') {
2027
+ throw new Error(`Invalid event at index ${index}.`);
2028
2028
  }
2029
- return {
2030
- ...validatedPayload,
2031
- type
2032
- };
2029
+ return validated;
2033
2030
  }));
2034
2031
  }
2035
2032
 
2036
- /** Creates migration and adaptation utilities backed by retained versions of one machine. */
2037
- function machineVersions(machines, options) {
2033
+ /** Creates migration and adaptation utilities for versions of one machine. */
2034
+ function machineVersions(entries, options) {
2038
2035
  const byIdentity = new Map();
2039
- const machineId = machines[0].id;
2040
- for (const machine of machines) {
2041
- if (machine.version === undefined) {
2042
- throw new Error(`Machine '${machine.id}' must define a version.`);
2036
+ const machinesByIdentity = new Map();
2037
+ const machineId = entries[0].id;
2038
+ for (const entry of entries) {
2039
+ if (entry.version === undefined) {
2040
+ throw new Error(`Machine '${entry.id}' must define a version.`);
2043
2041
  }
2044
- if (machine.version === '*') {
2042
+ if (entry.version === '*') {
2045
2043
  throw new Error("Machine version '*' is reserved for wildcard migrations.");
2046
2044
  }
2047
- if (machine.id !== machineId) {
2048
- throw new Error(`Machine '${machine.id}' does not match machine ID '${machineId}'.`);
2045
+ if (entry.id !== machineId) {
2046
+ throw new Error(`Machine '${entry.id}' does not match machine ID '${machineId}'.`);
2049
2047
  }
2050
- const key = `${machine.id}\0${machine.version}`;
2048
+ const key = `${entry.id}\0${entry.version}`;
2051
2049
  if (byIdentity.has(key)) {
2052
- throw new Error(`Duplicate machine identity '${machine.id}' version '${machine.version}'.`);
2050
+ throw new Error(`Duplicate machine identity '${entry.id}' version '${entry.version}'.`);
2051
+ }
2052
+ byIdentity.set(key, entry);
2053
+ if (isVersionedStateMachine(entry)) {
2054
+ machinesByIdentity.set(key, entry);
2053
2055
  }
2054
- byIdentity.set(key, machine);
2055
2056
  }
2056
2057
  if (options?.unversioned !== undefined && !byIdentity.has(`${machineId}\0${options.unversioned}`)) {
2057
2058
  throw new Error(`Unversioned snapshot version '${options.unversioned}' is not retained for machine '${machineId}'.`);
@@ -2085,16 +2086,21 @@ function machineVersions(machines, options) {
2085
2086
  if (raw.version !== undefined && raw.version !== version) {
2086
2087
  throw new Error(`Persisted snapshot version '${raw.version}' conflicts with machine version '${version}'.`);
2087
2088
  }
2088
- const machine = byIdentity.get(`${id}\0${version}`);
2089
- if (!machine) {
2089
+ const source = byIdentity.get(`${id}\0${version}`);
2090
+ if (!source) {
2090
2091
  throw new Error(`Unknown machine identity '${id}' version '${version}'.`);
2091
2092
  }
2092
- const context = await validate(machine.schemas?.context, raw.context, `context for machine '${id}' version '${version}'`);
2093
+ if (!hasSnapshotSchema(source)) {
2094
+ throw new Error(`Machine version '${version}' does not define a snapshot schema.`);
2095
+ }
2096
+ const snapshot = await validate(source.snapshotSchema, raw, `snapshot for machine '${id}' version '${version}'`);
2093
2097
  return {
2094
- machine,
2098
+ source,
2099
+ ...(isVersionedStateMachine(source) && {
2100
+ machine: source
2101
+ }),
2095
2102
  snapshot: {
2096
- ...raw,
2097
- context,
2103
+ ...snapshot,
2098
2104
  machine: {
2099
2105
  id,
2100
2106
  version
@@ -2105,15 +2111,16 @@ function machineVersions(machines, options) {
2105
2111
  return {
2106
2112
  parseSnapshot,
2107
2113
  async adaptEvents(events, adaptationOptions) {
2108
- const target = byIdentity.get(`${machineId}\0${adaptationOptions.to}`);
2114
+ const target = machinesByIdentity.get(`${machineId}\0${adaptationOptions.to}`);
2109
2115
  if (!target) {
2110
- throw new Error(`Target version '${adaptationOptions.to}' is not retained for machine '${machineId}'.`);
2116
+ throw new Error(`Target version '${adaptationOptions.to}' is not backed by a machine for '${machineId}'.`);
2111
2117
  }
2112
2118
  const sourceId = adaptationOptions.from.id ?? machineId;
2113
2119
  const source = byIdentity.get(`${sourceId}\0${adaptationOptions.from.version}`);
2114
2120
  let sourceError;
2115
2121
  let sourceValidationFailed = false;
2116
- if (source) {
2122
+ const hasTypedSource = source && hasEventSchema(source);
2123
+ if (hasTypedSource) {
2117
2124
  let sourceEvents;
2118
2125
  try {
2119
2126
  sourceEvents = await validateEvents(events, source);
@@ -2135,7 +2142,7 @@ function machineVersions(machines, options) {
2135
2142
  if (wildcardAdapter) {
2136
2143
  return validateEvents(await wildcardAdapter(events, adaptationOptions.from), target);
2137
2144
  }
2138
- if (source) {
2145
+ if (hasTypedSource) {
2139
2146
  if (sourceValidationFailed) {
2140
2147
  throw sourceError instanceof Error ? sourceError : new Error(`Unable to validate event history for machine '${source.id}' version '${source.version}'.`, {
2141
2148
  cause: sourceError
@@ -2143,12 +2150,15 @@ function machineVersions(machines, options) {
2143
2150
  }
2144
2151
  throw new Error(`No event adapter from version '${source.version}' to '${target.version}' for machine '${target.id}'.`);
2145
2152
  }
2153
+ if (source) {
2154
+ throw new Error(`Machine version '${source.version}' does not define an event schema; only the '*' adapter can handle its event history.`);
2155
+ }
2146
2156
  throw new Error(`Unknown event history source '${sourceId}' version '${adaptationOptions.from.version}'.`);
2147
2157
  },
2148
2158
  async migrateSnapshot(raw, migrationOptions) {
2149
- const target = byIdentity.get(`${machineId}\0${migrationOptions.to}`);
2159
+ const target = machinesByIdentity.get(`${machineId}\0${migrationOptions.to}`);
2150
2160
  if (!target) {
2151
- throw new Error(`Target version '${migrationOptions.to}' is not retained for machine '${machineId}'.`);
2161
+ throw new Error(`Target version '${migrationOptions.to}' is not backed by a machine for '${machineId}'.`);
2152
2162
  }
2153
2163
  let source;
2154
2164
  let parseError;
@@ -2158,10 +2168,10 @@ function machineVersions(machines, options) {
2158
2168
  parseError = error;
2159
2169
  }
2160
2170
  if (source) {
2161
- if (source.machine.version === target.version) {
2171
+ if (source.source.version === target.version) {
2162
2172
  return finalizeSnapshot(source.snapshot, target);
2163
2173
  }
2164
- const exactMigration = migrationOptions.migrations[source.machine.version];
2174
+ const exactMigration = migrationOptions.migrations[source.source.version];
2165
2175
  if (exactMigration) {
2166
2176
  return finalizeSnapshot(await exactMigration(source.snapshot), target);
2167
2177
  }
@@ -2169,7 +2179,7 @@ function machineVersions(machines, options) {
2169
2179
  const wildcardMigration = migrationOptions.migrations['*'];
2170
2180
  if (!wildcardMigration) {
2171
2181
  if (source) {
2172
- throw new Error(`No snapshot migration from version '${source.machine.version}' to '${target.version}' for machine '${target.id}'.`);
2182
+ throw new Error(`No snapshot migration from version '${source.source.version}' to '${target.version}' for machine '${target.id}'.`);
2173
2183
  }
2174
2184
  throw parseError;
2175
2185
  }
@@ -2631,6 +2641,12 @@ let SpecialTargets = /*#__PURE__*/function (SpecialTargets) {
2631
2641
 
2632
2642
  /** A persisted snapshot tied to a versioned actor logic identity. */
2633
2643
 
2644
+ /**
2645
+ * A persisted snapshot restorable into the given actor logic: any snapshot
2646
+ * created by logic with the same machine `id` is accepted, regardless of
2647
+ * version (version mismatches are handled at runtime, e.g. by `migrate`).
2648
+ */
2649
+
2634
2650
  /** @deprecated Use `AnyActor` instead. */
2635
2651
 
2636
2652
  // Based on RxJS types