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.
- package/bin/xstate.js +10 -4
- package/dist/{createActor-551369be.development.esm.js → createActor-0250284a.development.esm.js} +244 -41
- package/dist/{createActor-cbe3abac.esm.js → createActor-20a97166.esm.js} +243 -40
- package/dist/{createActor-a49ae0ce.development.cjs.js → createActor-c029d29f.development.cjs.js} +245 -40
- package/dist/{createActor-25900f76.cjs.js → createActor-c91c9ffe.cjs.js} +244 -39
- package/dist/declarations/src/createActor.d.ts +3 -1
- package/dist/declarations/src/createMachine.d.ts +6 -3
- package/dist/declarations/src/durable/index.d.ts +43 -8
- package/dist/declarations/src/effectDescriptor.d.ts +2 -2
- package/dist/declarations/src/machineVersion.types.d.ts +2 -2
- package/dist/declarations/src/setup.d.ts +5 -5
- package/dist/declarations/src/systemTransition.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +11 -3
- package/dist/declarations/src/types.v6.d.ts +37 -2
- package/dist/{effectDescriptor-f73da4ec.development.cjs.js → effectDescriptor-3fff5c51.development.cjs.js} +5 -5
- package/dist/{effectDescriptor-2fa27c54.cjs.js → effectDescriptor-47f73e7e.cjs.js} +5 -5
- package/dist/{effectDescriptor-321a8ce9.development.esm.js → effectDescriptor-5ac7dccb.development.esm.js} +5 -5
- package/dist/{effectDescriptor-d8b0f749.esm.js → effectDescriptor-e93df910.esm.js} +5 -5
- package/dist/{machineSchemas-88d01821.cjs.js → legacySnapshot-8d595687.cjs.js} +117 -1
- package/dist/{machineSchemas-45c21bc2.esm.js → legacySnapshot-9e06feb4.esm.js} +116 -2
- package/dist/{machineSchemas-b5736804.development.esm.js → legacySnapshot-ae6594a7.development.esm.js} +117 -3
- package/dist/{machineSchemas-6d96bef4.development.cjs.js → legacySnapshot-ebf0b2b8.development.cjs.js} +118 -2
- package/dist/xstate-actors.cjs.js +1 -1
- package/dist/xstate-actors.development.cjs.js +1 -1
- package/dist/xstate-actors.development.esm.js +2 -2
- package/dist/xstate-actors.esm.js +2 -2
- package/dist/xstate-actors.umd.min.js +1 -1
- package/dist/xstate-actors.umd.min.js.map +1 -1
- package/dist/xstate-durable.cjs.js +120 -10
- package/dist/xstate-durable.development.cjs.js +120 -10
- package/dist/xstate-durable.development.esm.js +120 -10
- package/dist/xstate-durable.esm.js +120 -10
- package/dist/xstate-durable.umd.min.js +1 -1
- package/dist/xstate-durable.umd.min.js.map +1 -1
- package/dist/xstate-fsm.cjs.js +4 -4
- package/dist/xstate-fsm.development.cjs.js +4 -4
- package/dist/xstate-fsm.development.esm.js +4 -4
- package/dist/xstate-fsm.esm.js +4 -4
- package/dist/xstate-fsm.umd.min.js +1 -1
- package/dist/xstate-fsm.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +1 -1
- package/dist/xstate-graph.development.cjs.js +1 -1
- package/dist/xstate-graph.development.esm.js +2 -2
- package/dist/xstate-graph.esm.js +2 -2
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.umd.min.js.map +1 -1
- package/dist/xstate-persist.cjs.js +23 -12
- package/dist/xstate-persist.development.cjs.js +23 -12
- package/dist/xstate-persist.development.esm.js +17 -6
- package/dist/xstate-persist.esm.js +17 -6
- package/dist/xstate-persist.umd.min.js +1 -1
- package/dist/xstate-persist.umd.min.js.map +1 -1
- package/dist/xstate-validation.cjs.js +1 -1
- package/dist/xstate-validation.development.cjs.js +1 -1
- package/dist/xstate-validation.development.esm.js +1 -1
- package/dist/xstate-validation.esm.js +1 -1
- package/dist/xstate.cjs.js +63 -51
- package/dist/xstate.development.cjs.js +63 -51
- package/dist/xstate.development.esm.js +53 -41
- package/dist/xstate.esm.js +53 -41
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/docs/agents.md +9 -0
- package/docs/api-stability.json +273 -249
- package/docs/backend-workflows.md +3 -3
- package/docs/durable-execution.md +72 -48
- package/docs/errors.md +2 -2
- package/docs/examples.md +34 -34
- package/docs/fsm.md +2 -1
- package/docs/guards.md +1 -1
- package/docs/index.md +1 -1
- package/docs/invoke.md +34 -2
- package/docs/persistence.md +16 -10
- package/docs/serialization.md +1 -1
- package/docs/setup-and-provide.md +3 -3
- package/docs/spawn.md +1 -1
- package/docs/system-transitions.md +6 -6
- package/docs/tutorial.md +5 -5
- package/docs/typescript.md +9 -0
- package/docs/xstate-v5-to-v6.md +176 -19
- package/package.json +1 -1
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var legacySnapshot = require('./legacySnapshot-8d595687.cjs.js');
|
|
6
|
+
var createActor = require('./createActor-c91c9ffe.cjs.js');
|
|
7
7
|
require('./validation-4561b43c.cjs.js');
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -51,7 +51,7 @@ function restoreActor(logic, persistedSnapshot, options) {
|
|
|
51
51
|
* `restoreSnapshot` (or verbatim).
|
|
52
52
|
*/
|
|
53
53
|
function restoreLogicSnapshot(logic, persisted, actorScope) {
|
|
54
|
-
if (logic instanceof
|
|
54
|
+
if (logic instanceof legacySnapshot.StateMachine) {
|
|
55
55
|
return restoreMachineSnapshot(logic, persisted, actorScope);
|
|
56
56
|
}
|
|
57
57
|
// Only `undefined` means "no snapshot": an explicit `null` (or another
|
|
@@ -64,7 +64,7 @@ function restoreLogicSnapshot(logic, persisted, actorScope) {
|
|
|
64
64
|
function createRestoreHook(logic, persisted) {
|
|
65
65
|
return {
|
|
66
66
|
restore: actorScope => restoreLogicSnapshot(logic, persisted, actorScope),
|
|
67
|
-
error: error => logic instanceof
|
|
67
|
+
error: error => logic instanceof legacySnapshot.StateMachine ? createRestoreErrorSnapshot(logic, persisted, error) : undefined
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -93,10 +93,17 @@ function createRestoreErrorSnapshot(machine, persisted, error) {
|
|
|
93
93
|
* in context.
|
|
94
94
|
*/
|
|
95
95
|
function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
96
|
+
// A reactive Proxy wraps state nodes but bound transitions use raw nodes.
|
|
97
|
+
// Normalize here for both restoreActor and direct callers.
|
|
98
|
+
if (machine instanceof legacySnapshot.StateMachine) {
|
|
99
|
+
machine = machine._raw();
|
|
100
|
+
}
|
|
101
|
+
// TODO(v7): remove with legacySnapshot.ts.
|
|
102
|
+
snapshot = legacySnapshot.upgradeLegacyPersistedSnapshot(snapshot);
|
|
96
103
|
const usesInertScope = !actorScope;
|
|
97
104
|
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(machine);
|
|
98
105
|
if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) {
|
|
99
|
-
throw new
|
|
106
|
+
throw new legacySnapshot.InvalidSnapshotError(createActor.xstateError(24, machine.id));
|
|
100
107
|
}
|
|
101
108
|
const snapshotMachine = snapshot.machine;
|
|
102
109
|
// A live machine snapshot carries its producing machine so helpers such as
|
|
@@ -122,7 +129,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
122
129
|
const {
|
|
123
130
|
nodes,
|
|
124
131
|
childLogics
|
|
125
|
-
} =
|
|
132
|
+
} = legacySnapshot.validatePersistedSnapshot(machine, snapshotData);
|
|
126
133
|
const children = {};
|
|
127
134
|
const snapshotChildren = snapshotData.children;
|
|
128
135
|
for (const actorId of Object.keys(snapshotChildren)) {
|
|
@@ -187,7 +194,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
187
194
|
const target = typeof timer.target === 'string' ? timer.target === 'self' ? 'self' : children[timer.target] : createActor.isSerializedActorRef(timer.target) ? timer.target : resolvedActorScope.self._parent;
|
|
188
195
|
if (!target) {
|
|
189
196
|
const targetDescription = typeof timer.target === 'string' ? timer.target : timer.target.type;
|
|
190
|
-
throw new
|
|
197
|
+
throw new legacySnapshot.InvalidSnapshotError(createActor.xstateError(33, targetDescription));
|
|
191
198
|
}
|
|
192
199
|
timers.push({
|
|
193
200
|
...timer,
|
|
@@ -204,7 +211,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
204
211
|
const arr = historyValue[key];
|
|
205
212
|
for (const item of arr) {
|
|
206
213
|
let resolved;
|
|
207
|
-
if (item instanceof
|
|
214
|
+
if (item instanceof legacySnapshot.StateNode) {
|
|
208
215
|
resolved = item;
|
|
209
216
|
} else {
|
|
210
217
|
try {
|
|
@@ -228,12 +235,15 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
228
235
|
// `_nextActorIds` plus the child-id fold below; dropped so old and new
|
|
229
236
|
// snapshots round-trip to the same shape.
|
|
230
237
|
_nextActorId: _legacyNextActorId,
|
|
238
|
+
nextTimerId,
|
|
239
|
+
nextActorIds,
|
|
240
|
+
stateInputs: _persistedStateInputs,
|
|
231
241
|
...persistedRest
|
|
232
242
|
} = snapshot;
|
|
233
243
|
// Fold generated-shaped child ids into the counters as a floor: snapshots
|
|
234
244
|
// persisted before per-actor counters (or hand-crafted ones) still must
|
|
235
245
|
// never reuse a live child's id.
|
|
236
|
-
let restoredCounters =
|
|
246
|
+
let restoredCounters = nextActorIds;
|
|
237
247
|
for (const childId of Object.keys(snapshotChildren)) {
|
|
238
248
|
const generated = createActor.parseGeneratedActorId(childId);
|
|
239
249
|
if (generated && (restoredCounters?.[generated.prefix] ?? 0) <= generated.index) {
|
|
@@ -252,7 +262,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
252
262
|
return value;
|
|
253
263
|
}
|
|
254
264
|
// The context object itself is data, never a serialized actor ref.
|
|
255
|
-
// Only an object whose keys are exactly
|
|
265
|
+
// Only an object whose keys are exactly `@actor` (+ `incarnation`)
|
|
256
266
|
// is a serialized ref; any other object is data.
|
|
257
267
|
if (!isRoot && createActor.isSerializedActorRef(value)) {
|
|
258
268
|
// A ref that names one of this snapshot's children revives to that
|
|
@@ -262,7 +272,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
262
272
|
if (value.incarnation !== undefined) {
|
|
263
273
|
return value;
|
|
264
274
|
}
|
|
265
|
-
return Object.values(children).find(child => child.address === value
|
|
275
|
+
return Object.values(children).find(child => child.address === value['@actor']) ?? value;
|
|
266
276
|
}
|
|
267
277
|
const proto = Object.getPrototypeOf(value);
|
|
268
278
|
if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {
|
|
@@ -288,6 +298,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
288
298
|
context: reviveContext(persistedRest.context, true),
|
|
289
299
|
children,
|
|
290
300
|
timers,
|
|
301
|
+
_nextTimerId: nextTimerId,
|
|
291
302
|
_nextActorIds: restoredCounters,
|
|
292
303
|
_nodes: nodes,
|
|
293
304
|
// Derived from the resolved configuration, so a partial value such as
|
|
@@ -308,7 +319,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
308
319
|
return restoredSnapshot;
|
|
309
320
|
}
|
|
310
321
|
|
|
311
|
-
exports.snapshotSchema =
|
|
322
|
+
exports.snapshotSchema = legacySnapshot.snapshotSchema;
|
|
312
323
|
exports.restoreActor = restoreActor;
|
|
313
324
|
exports.restoreLogicSnapshot = restoreLogicSnapshot;
|
|
314
325
|
exports.restoreMachineSnapshot = restoreMachineSnapshot;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var legacySnapshot = require('./legacySnapshot-ebf0b2b8.development.cjs.js');
|
|
6
|
+
var createActor = require('./createActor-c029d29f.development.cjs.js');
|
|
7
7
|
require('./validation-f2714a35.development.cjs.js');
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -51,7 +51,7 @@ function restoreActor(logic, persistedSnapshot, options) {
|
|
|
51
51
|
* `restoreSnapshot` (or verbatim).
|
|
52
52
|
*/
|
|
53
53
|
function restoreLogicSnapshot(logic, persisted, actorScope) {
|
|
54
|
-
if (logic instanceof
|
|
54
|
+
if (logic instanceof legacySnapshot.StateMachine) {
|
|
55
55
|
return restoreMachineSnapshot(logic, persisted, actorScope);
|
|
56
56
|
}
|
|
57
57
|
// Only `undefined` means "no snapshot": an explicit `null` (or another
|
|
@@ -64,7 +64,7 @@ function restoreLogicSnapshot(logic, persisted, actorScope) {
|
|
|
64
64
|
function createRestoreHook(logic, persisted) {
|
|
65
65
|
return {
|
|
66
66
|
restore: actorScope => restoreLogicSnapshot(logic, persisted, actorScope),
|
|
67
|
-
error: error => logic instanceof
|
|
67
|
+
error: error => logic instanceof legacySnapshot.StateMachine ? createRestoreErrorSnapshot(logic, persisted, error) : undefined
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -93,10 +93,17 @@ function createRestoreErrorSnapshot(machine, persisted, error) {
|
|
|
93
93
|
* in context.
|
|
94
94
|
*/
|
|
95
95
|
function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
96
|
+
// A reactive Proxy wraps state nodes but bound transitions use raw nodes.
|
|
97
|
+
// Normalize here for both restoreActor and direct callers.
|
|
98
|
+
if (machine instanceof legacySnapshot.StateMachine) {
|
|
99
|
+
machine = machine._raw();
|
|
100
|
+
}
|
|
101
|
+
// TODO(v7): remove with legacySnapshot.ts.
|
|
102
|
+
snapshot = legacySnapshot.upgradeLegacyPersistedSnapshot(snapshot);
|
|
96
103
|
const usesInertScope = !actorScope;
|
|
97
104
|
const resolvedActorScope = actorScope ?? createActor.createInertActorScope(machine);
|
|
98
105
|
if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) {
|
|
99
|
-
throw new
|
|
106
|
+
throw new legacySnapshot.InvalidSnapshotError(`Persisted snapshot for ${createActor.describeMachine(machine.id)} must be an object.` );
|
|
100
107
|
}
|
|
101
108
|
const snapshotMachine = snapshot.machine;
|
|
102
109
|
// A live machine snapshot carries its producing machine so helpers such as
|
|
@@ -122,7 +129,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
122
129
|
const {
|
|
123
130
|
nodes,
|
|
124
131
|
childLogics
|
|
125
|
-
} =
|
|
132
|
+
} = legacySnapshot.validatePersistedSnapshot(machine, snapshotData);
|
|
126
133
|
const children = {};
|
|
127
134
|
const snapshotChildren = snapshotData.children;
|
|
128
135
|
for (const actorId of Object.keys(snapshotChildren)) {
|
|
@@ -187,7 +194,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
187
194
|
const target = typeof timer.target === 'string' ? timer.target === 'self' ? 'self' : children[timer.target] : createActor.isSerializedActorRef(timer.target) ? timer.target : resolvedActorScope.self._parent;
|
|
188
195
|
if (!target) {
|
|
189
196
|
const targetDescription = typeof timer.target === 'string' ? timer.target : timer.target.type;
|
|
190
|
-
throw new
|
|
197
|
+
throw new legacySnapshot.InvalidSnapshotError(`Unable to restore timer ${timer.id !== undefined ? `'${timer.id}'` : `for event '${timer.event.type}'`}: target actor '${targetDescription}' is unavailable.` );
|
|
191
198
|
}
|
|
192
199
|
timers.push({
|
|
193
200
|
...timer,
|
|
@@ -204,7 +211,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
204
211
|
const arr = historyValue[key];
|
|
205
212
|
for (const item of arr) {
|
|
206
213
|
let resolved;
|
|
207
|
-
if (item instanceof
|
|
214
|
+
if (item instanceof legacySnapshot.StateNode) {
|
|
208
215
|
resolved = item;
|
|
209
216
|
} else {
|
|
210
217
|
try {
|
|
@@ -239,12 +246,15 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
239
246
|
// `_nextActorIds` plus the child-id fold below; dropped so old and new
|
|
240
247
|
// snapshots round-trip to the same shape.
|
|
241
248
|
_nextActorId: _legacyNextActorId,
|
|
249
|
+
nextTimerId,
|
|
250
|
+
nextActorIds,
|
|
251
|
+
stateInputs: _persistedStateInputs,
|
|
242
252
|
...persistedRest
|
|
243
253
|
} = snapshot;
|
|
244
254
|
// Fold generated-shaped child ids into the counters as a floor: snapshots
|
|
245
255
|
// persisted before per-actor counters (or hand-crafted ones) still must
|
|
246
256
|
// never reuse a live child's id.
|
|
247
|
-
let restoredCounters =
|
|
257
|
+
let restoredCounters = nextActorIds;
|
|
248
258
|
for (const childId of Object.keys(snapshotChildren)) {
|
|
249
259
|
const generated = createActor.parseGeneratedActorId(childId);
|
|
250
260
|
if (generated && (restoredCounters?.[generated.prefix] ?? 0) <= generated.index) {
|
|
@@ -263,7 +273,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
263
273
|
return value;
|
|
264
274
|
}
|
|
265
275
|
// The context object itself is data, never a serialized actor ref.
|
|
266
|
-
// Only an object whose keys are exactly
|
|
276
|
+
// Only an object whose keys are exactly `@actor` (+ `incarnation`)
|
|
267
277
|
// is a serialized ref; any other object is data.
|
|
268
278
|
if (!isRoot && createActor.isSerializedActorRef(value)) {
|
|
269
279
|
// A ref that names one of this snapshot's children revives to that
|
|
@@ -273,7 +283,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
273
283
|
if (value.incarnation !== undefined) {
|
|
274
284
|
return value;
|
|
275
285
|
}
|
|
276
|
-
return Object.values(children).find(child => child.address === value
|
|
286
|
+
return Object.values(children).find(child => child.address === value['@actor']) ?? value;
|
|
277
287
|
}
|
|
278
288
|
const proto = Object.getPrototypeOf(value);
|
|
279
289
|
if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {
|
|
@@ -299,6 +309,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
299
309
|
context: reviveContext(persistedRest.context, true),
|
|
300
310
|
children,
|
|
301
311
|
timers,
|
|
312
|
+
_nextTimerId: nextTimerId,
|
|
302
313
|
_nextActorIds: restoredCounters,
|
|
303
314
|
_nodes: nodes,
|
|
304
315
|
// Derived from the resolved configuration, so a partial value such as
|
|
@@ -319,7 +330,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
319
330
|
return restoredSnapshot;
|
|
320
331
|
}
|
|
321
332
|
|
|
322
|
-
exports.snapshotSchema =
|
|
333
|
+
exports.snapshotSchema = legacySnapshot.snapshotSchema;
|
|
323
334
|
exports.restoreActor = restoreActor;
|
|
324
335
|
exports.restoreLogicSnapshot = restoreLogicSnapshot;
|
|
325
336
|
exports.restoreMachineSnapshot = restoreMachineSnapshot;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { S as StateMachine, b as upgradeLegacyPersistedSnapshot, I as InvalidSnapshotError, v as validatePersistedSnapshot, a as StateNode } from './legacySnapshot-ae6594a7.development.esm.js';
|
|
2
|
+
export { s as snapshotSchema } from './legacySnapshot-ae6594a7.development.esm.js';
|
|
3
|
+
import { aV as diagnoseActorOptions, E as Actor, ao as cloneMachineSnapshot, e as createMachineSnapshot, ah as createInertActorScope, ad as describeMachine, aW as createRemoteActorRef, aX as createInvokeTimeoutEvent, o as isSerializedActorRef, aY as parseGeneratedActorId, ai as setInertActorScopeSnapshot, ak as attachSnapshotActorRef, am as isInertActorScope, an as setSnapshotActorRef } from './createActor-0250284a.development.esm.js';
|
|
4
4
|
import './validation-e69470ad.development.esm.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -90,6 +90,13 @@ function createRestoreErrorSnapshot(machine, persisted, error) {
|
|
|
90
90
|
* in context.
|
|
91
91
|
*/
|
|
92
92
|
function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
93
|
+
// A reactive Proxy wraps state nodes but bound transitions use raw nodes.
|
|
94
|
+
// Normalize here for both restoreActor and direct callers.
|
|
95
|
+
if (machine instanceof StateMachine) {
|
|
96
|
+
machine = machine._raw();
|
|
97
|
+
}
|
|
98
|
+
// TODO(v7): remove with legacySnapshot.ts.
|
|
99
|
+
snapshot = upgradeLegacyPersistedSnapshot(snapshot);
|
|
93
100
|
const usesInertScope = !actorScope;
|
|
94
101
|
const resolvedActorScope = actorScope ?? createInertActorScope(machine);
|
|
95
102
|
if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) {
|
|
@@ -236,12 +243,15 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
236
243
|
// `_nextActorIds` plus the child-id fold below; dropped so old and new
|
|
237
244
|
// snapshots round-trip to the same shape.
|
|
238
245
|
_nextActorId: _legacyNextActorId,
|
|
246
|
+
nextTimerId,
|
|
247
|
+
nextActorIds,
|
|
248
|
+
stateInputs: _persistedStateInputs,
|
|
239
249
|
...persistedRest
|
|
240
250
|
} = snapshot;
|
|
241
251
|
// Fold generated-shaped child ids into the counters as a floor: snapshots
|
|
242
252
|
// persisted before per-actor counters (or hand-crafted ones) still must
|
|
243
253
|
// never reuse a live child's id.
|
|
244
|
-
let restoredCounters =
|
|
254
|
+
let restoredCounters = nextActorIds;
|
|
245
255
|
for (const childId of Object.keys(snapshotChildren)) {
|
|
246
256
|
const generated = parseGeneratedActorId(childId);
|
|
247
257
|
if (generated && (restoredCounters?.[generated.prefix] ?? 0) <= generated.index) {
|
|
@@ -260,7 +270,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
260
270
|
return value;
|
|
261
271
|
}
|
|
262
272
|
// The context object itself is data, never a serialized actor ref.
|
|
263
|
-
// Only an object whose keys are exactly
|
|
273
|
+
// Only an object whose keys are exactly `@actor` (+ `incarnation`)
|
|
264
274
|
// is a serialized ref; any other object is data.
|
|
265
275
|
if (!isRoot && isSerializedActorRef(value)) {
|
|
266
276
|
// A ref that names one of this snapshot's children revives to that
|
|
@@ -270,7 +280,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
270
280
|
if (value.incarnation !== undefined) {
|
|
271
281
|
return value;
|
|
272
282
|
}
|
|
273
|
-
return Object.values(children).find(child => child.address === value
|
|
283
|
+
return Object.values(children).find(child => child.address === value['@actor']) ?? value;
|
|
274
284
|
}
|
|
275
285
|
const proto = Object.getPrototypeOf(value);
|
|
276
286
|
if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {
|
|
@@ -296,6 +306,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
296
306
|
context: reviveContext(persistedRest.context, true),
|
|
297
307
|
children,
|
|
298
308
|
timers,
|
|
309
|
+
_nextTimerId: nextTimerId,
|
|
299
310
|
_nextActorIds: restoredCounters,
|
|
300
311
|
_nodes: nodes,
|
|
301
312
|
// Derived from the resolved configuration, so a partial value such as
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { S as StateMachine, b as upgradeLegacyPersistedSnapshot, I as InvalidSnapshotError, v as validatePersistedSnapshot, a as StateNode } from './legacySnapshot-9e06feb4.esm.js';
|
|
2
|
+
export { s as snapshotSchema } from './legacySnapshot-9e06feb4.esm.js';
|
|
3
|
+
import { aU as diagnoseActorOptions, F as Actor, x as xstateError, ap as cloneMachineSnapshot, e as createMachineSnapshot, ai as createInertActorScope, aV as createRemoteActorRef, aW as createInvokeTimeoutEvent, o as isSerializedActorRef, aX as parseGeneratedActorId, aj as setInertActorScopeSnapshot, al as attachSnapshotActorRef, an as isInertActorScope, ao as setSnapshotActorRef } from './createActor-20a97166.esm.js';
|
|
4
4
|
import './validation-05f1d517.esm.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -90,6 +90,13 @@ function createRestoreErrorSnapshot(machine, persisted, error) {
|
|
|
90
90
|
* in context.
|
|
91
91
|
*/
|
|
92
92
|
function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
93
|
+
// A reactive Proxy wraps state nodes but bound transitions use raw nodes.
|
|
94
|
+
// Normalize here for both restoreActor and direct callers.
|
|
95
|
+
if (machine instanceof StateMachine) {
|
|
96
|
+
machine = machine._raw();
|
|
97
|
+
}
|
|
98
|
+
// TODO(v7): remove with legacySnapshot.ts.
|
|
99
|
+
snapshot = upgradeLegacyPersistedSnapshot(snapshot);
|
|
93
100
|
const usesInertScope = !actorScope;
|
|
94
101
|
const resolvedActorScope = actorScope ?? createInertActorScope(machine);
|
|
95
102
|
if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) {
|
|
@@ -225,12 +232,15 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
225
232
|
// `_nextActorIds` plus the child-id fold below; dropped so old and new
|
|
226
233
|
// snapshots round-trip to the same shape.
|
|
227
234
|
_nextActorId: _legacyNextActorId,
|
|
235
|
+
nextTimerId,
|
|
236
|
+
nextActorIds,
|
|
237
|
+
stateInputs: _persistedStateInputs,
|
|
228
238
|
...persistedRest
|
|
229
239
|
} = snapshot;
|
|
230
240
|
// Fold generated-shaped child ids into the counters as a floor: snapshots
|
|
231
241
|
// persisted before per-actor counters (or hand-crafted ones) still must
|
|
232
242
|
// never reuse a live child's id.
|
|
233
|
-
let restoredCounters =
|
|
243
|
+
let restoredCounters = nextActorIds;
|
|
234
244
|
for (const childId of Object.keys(snapshotChildren)) {
|
|
235
245
|
const generated = parseGeneratedActorId(childId);
|
|
236
246
|
if (generated && (restoredCounters?.[generated.prefix] ?? 0) <= generated.index) {
|
|
@@ -249,7 +259,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
249
259
|
return value;
|
|
250
260
|
}
|
|
251
261
|
// The context object itself is data, never a serialized actor ref.
|
|
252
|
-
// Only an object whose keys are exactly
|
|
262
|
+
// Only an object whose keys are exactly `@actor` (+ `incarnation`)
|
|
253
263
|
// is a serialized ref; any other object is data.
|
|
254
264
|
if (!isRoot && isSerializedActorRef(value)) {
|
|
255
265
|
// A ref that names one of this snapshot's children revives to that
|
|
@@ -259,7 +269,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
259
269
|
if (value.incarnation !== undefined) {
|
|
260
270
|
return value;
|
|
261
271
|
}
|
|
262
|
-
return Object.values(children).find(child => child.address === value
|
|
272
|
+
return Object.values(children).find(child => child.address === value['@actor']) ?? value;
|
|
263
273
|
}
|
|
264
274
|
const proto = Object.getPrototypeOf(value);
|
|
265
275
|
if (!Array.isArray(value) && proto !== Object.prototype && proto !== null) {
|
|
@@ -285,6 +295,7 @@ function restoreMachineSnapshot(machine, snapshot, actorScope) {
|
|
|
285
295
|
context: reviveContext(persistedRest.context, true),
|
|
286
296
|
children,
|
|
287
297
|
timers,
|
|
298
|
+
_nextTimerId: nextTimerId,
|
|
288
299
|
_nextActorIds: restoredCounters,
|
|
289
300
|
_nodes: nodes,
|
|
290
301
|
// Derived from the resolved configuration, so a partial value such as
|