xstate 6.0.0-beta.1 → 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/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 +2 -2
- package/dist/declarations/src/systemTransition.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +4 -2
- 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/api-stability.json +267 -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 +17 -17
- package/package.json +1 -1
package/dist/{createActor-a49ae0ce.development.cjs.js → createActor-c029d29f.development.cjs.js}
RENAMED
|
@@ -213,11 +213,11 @@ function isRemoteActorRef(actorRef) {
|
|
|
213
213
|
* JSON (`actor.toJSON()`): plain data carrying an address, not an actor.
|
|
214
214
|
*/
|
|
215
215
|
function isSerializedActorRef(target) {
|
|
216
|
-
if (typeof target !== 'object' || target === null || Array.isArray(target) || typeof target
|
|
216
|
+
if (typeof target !== 'object' || target === null || Array.isArray(target) || typeof target['@actor'] !== 'string') {
|
|
217
217
|
return false;
|
|
218
218
|
}
|
|
219
219
|
for (const key in target) {
|
|
220
|
-
if (key !== '
|
|
220
|
+
if (key !== '@actor' && key !== 'incarnation') {
|
|
221
221
|
return false;
|
|
222
222
|
}
|
|
223
223
|
}
|
|
@@ -233,7 +233,7 @@ function getAddressId(address) {
|
|
|
233
233
|
|
|
234
234
|
/** @internal The error reported when no live actor has a serialized address. */
|
|
235
235
|
function createMissingAddressError(target) {
|
|
236
|
-
return new Error(target.incarnation === undefined ? `Unable to send event to actor '${target
|
|
236
|
+
return new Error(target.incarnation === undefined ? `Unable to send event to actor '${target['@actor']}': no live actor has that address` : `Unable to send event to actor '${target['@actor']}' (incarnation '${target.incarnation}'): no live actor has that address and incarnation`);
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
/**
|
|
@@ -242,7 +242,7 @@ function createMissingAddressError(target) {
|
|
|
242
242
|
* without one follows whichever actor is live at the address.
|
|
243
243
|
*/
|
|
244
244
|
function resolveSerializedActorRef(system, target) {
|
|
245
|
-
const live = system._getByAddress?.(target
|
|
245
|
+
const live = system._getByAddress?.(target['@actor']);
|
|
246
246
|
return live && (target.incarnation === undefined || live.sessionId === target.incarnation) ? live : undefined;
|
|
247
247
|
}
|
|
248
248
|
|
|
@@ -295,7 +295,7 @@ function createInertActorRef(options) {
|
|
|
295
295
|
throw new Error(`Cannot serialize actor ref '${id}': it was returned by a spawn during speculative transition evaluation, which creates no actor and has no parent address.` );
|
|
296
296
|
}
|
|
297
297
|
return {
|
|
298
|
-
|
|
298
|
+
'@actor': address
|
|
299
299
|
};
|
|
300
300
|
}
|
|
301
301
|
};
|
|
@@ -381,7 +381,7 @@ function createRemoteActorRef(system, options) {
|
|
|
381
381
|
// one actor-reference shape whether a child is co-located or remote.
|
|
382
382
|
toJSON() {
|
|
383
383
|
return {
|
|
384
|
-
|
|
384
|
+
'@actor': options.address
|
|
385
385
|
};
|
|
386
386
|
}
|
|
387
387
|
};
|
|
@@ -501,7 +501,7 @@ function deliverEvent(source, target, event) {
|
|
|
501
501
|
throw error;
|
|
502
502
|
}
|
|
503
503
|
void system.deadLetter(source, undefined, event, 'missingTarget', {
|
|
504
|
-
targetId: getAddressId(serialized
|
|
504
|
+
targetId: getAddressId(serialized['@actor']),
|
|
505
505
|
error
|
|
506
506
|
});
|
|
507
507
|
return;
|
|
@@ -2203,6 +2203,18 @@ function withSystemInspector(inspect, fn) {
|
|
|
2203
2203
|
|
|
2204
2204
|
/** Snapshot-scoped actor identity and system view. @internal */
|
|
2205
2205
|
|
|
2206
|
+
// Each view's execution system and whether it forwards inspection. Views
|
|
2207
|
+
// never chain: they all inherit from the execution system directly.
|
|
2208
|
+
const snapshotSystemViews = new WeakMap();
|
|
2209
|
+
// Facilities owned by the execution rather than by one snapshot's view. A view
|
|
2210
|
+
// reads and writes them on the execution system, so timers, listeners and the
|
|
2211
|
+
// runtime installed through any snapshot are visible through every other.
|
|
2212
|
+
const executionFacilities = ['runtime', '_timerMap', '_rejectionListeners', '_inspectionObservers', '_emissionListeners'];
|
|
2213
|
+
// The durable execution that owns each execution system.
|
|
2214
|
+
/** A durable execution, as the owner of the views its transitions create. @internal */
|
|
2215
|
+
|
|
2216
|
+
const executionOwners = new WeakMap();
|
|
2217
|
+
let ambientExecutionOwner;
|
|
2206
2218
|
const snapshotActorRefs = new WeakMap();
|
|
2207
2219
|
const lazySnapshotActorRefs = new WeakMap();
|
|
2208
2220
|
const emptyKeyedActors = new Map();
|
|
@@ -2262,12 +2274,22 @@ function getSnapshotChildren(snapshot) {
|
|
|
2262
2274
|
*
|
|
2263
2275
|
* @internal
|
|
2264
2276
|
*/
|
|
2265
|
-
function createSnapshotSystem(baseSystem, children, baseState) {
|
|
2266
|
-
const
|
|
2277
|
+
function createSnapshotSystem(baseSystem, children, baseState, owner) {
|
|
2278
|
+
const baseView = snapshotSystemViews.get(baseSystem);
|
|
2279
|
+
const baseExecutionSystem = baseView?.executionSystem ?? baseSystem;
|
|
2280
|
+
// The runtime system under every view. A view runs its methods against the
|
|
2281
|
+
// execution system's facilities.
|
|
2282
|
+
const rootSystem = baseView?.rootSystem ?? baseSystem;
|
|
2283
|
+
const forks = owner !== undefined && executionOwners.get(baseExecutionSystem) !== owner;
|
|
2284
|
+
// A view an execution owns reports to that execution's inspector.
|
|
2285
|
+
const forwardInspection = owner ? !!owner.inspect : hasAmbientInspector() && (baseView?.forwardInspection ?? true);
|
|
2267
2286
|
const registeredActors = copyRegisteredActors(baseSystem, baseState);
|
|
2268
2287
|
const keyedActors = new Map(baseState?.keyedActors ?? getKeyedActors(baseSystem));
|
|
2269
2288
|
const reverseKeyedActors = new WeakMap();
|
|
2270
|
-
|
|
2289
|
+
// The view's execution system; adoption can make the view its own.
|
|
2290
|
+
const execution = () => snapshotSystemViews.get(system).executionSystem;
|
|
2291
|
+
const forwards = () => snapshotSystemViews.get(system).forwardInspection;
|
|
2292
|
+
const system = Object.assign(Object.create(baseExecutionSystem), {
|
|
2271
2293
|
children: registeredActors,
|
|
2272
2294
|
keyedActors,
|
|
2273
2295
|
reverseKeyedActors,
|
|
@@ -2302,15 +2324,38 @@ function createSnapshotSystem(baseSystem, children, baseState) {
|
|
|
2302
2324
|
},
|
|
2303
2325
|
get: registryKey => keyedActors.get(registryKey),
|
|
2304
2326
|
getAll: () => Object.fromEntries(keyedActors),
|
|
2305
|
-
onEmitted: listener =>
|
|
2306
|
-
_notifyEmitted: (actorRef, event) =>
|
|
2327
|
+
onEmitted: listener => rootSystem.onEmitted.call(execution(), listener),
|
|
2328
|
+
_notifyEmitted: (actorRef, event) => rootSystem._notifyEmitted.call(execution(), actorRef, event),
|
|
2307
2329
|
// Pure transition resolution must not leak topology inspection events
|
|
2308
2330
|
// into a live runtime system — planning branches stay silent. The one
|
|
2309
2331
|
// exception is a durable execution's own transitions (marked by the
|
|
2310
2332
|
// ambient inspector at creation time): there the pure path IS the
|
|
2311
|
-
// execution, so inspection forwards to the
|
|
2312
|
-
_hasInspectionObservers:
|
|
2313
|
-
_sendInspectionEvent:
|
|
2333
|
+
// execution, so inspection forwards to the execution system's observers.
|
|
2334
|
+
_hasInspectionObservers: () => forwards() && (rootSystem._hasInspectionObservers?.call(execution()) ?? false),
|
|
2335
|
+
_sendInspectionEvent: event => {
|
|
2336
|
+
if (forwards()) {
|
|
2337
|
+
rootSystem._sendInspectionEvent.call(execution(), event);
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
const executionSystem = forks ? system : baseExecutionSystem;
|
|
2342
|
+
if (forks) {
|
|
2343
|
+
forkFacilities(system, baseExecutionSystem, owner);
|
|
2344
|
+
} else {
|
|
2345
|
+
for (const key of executionFacilities) {
|
|
2346
|
+
Object.defineProperty(system, key, {
|
|
2347
|
+
configurable: true,
|
|
2348
|
+
get: () => execution()[key],
|
|
2349
|
+
set: value => {
|
|
2350
|
+
execution()[key] = value;
|
|
2351
|
+
}
|
|
2352
|
+
});
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
snapshotSystemViews.set(system, {
|
|
2356
|
+
executionSystem,
|
|
2357
|
+
rootSystem,
|
|
2358
|
+
forwardInspection
|
|
2314
2359
|
});
|
|
2315
2360
|
for (const [registryKey, actor] of keyedActors) {
|
|
2316
2361
|
if (!actor) {
|
|
@@ -2334,6 +2379,83 @@ function createSnapshotSystem(baseSystem, children, baseState) {
|
|
|
2334
2379
|
return system;
|
|
2335
2380
|
}
|
|
2336
2381
|
|
|
2382
|
+
/**
|
|
2383
|
+
* Makes `system` the execution system of `owner`, a new incarnation: it gets
|
|
2384
|
+
* the owner's runtime and the pending timers it saw, and starts with no
|
|
2385
|
+
* listeners or inspectors, so nothing registered on another execution
|
|
2386
|
+
* observes it.
|
|
2387
|
+
*/
|
|
2388
|
+
function forkFacilities(system, from, owner) {
|
|
2389
|
+
const timers = from._timerMap;
|
|
2390
|
+
for (const key of executionFacilities) {
|
|
2391
|
+
Object.defineProperty(system, key, {
|
|
2392
|
+
configurable: true,
|
|
2393
|
+
writable: true,
|
|
2394
|
+
value: key === 'runtime' ? owner.runtime : key === '_timerMap' && timers ? {
|
|
2395
|
+
...timers
|
|
2396
|
+
} : undefined
|
|
2397
|
+
});
|
|
2398
|
+
}
|
|
2399
|
+
executionOwners.set(system, owner);
|
|
2400
|
+
if (owner.inspect) {
|
|
2401
|
+
system.inspect(owner.inspect);
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
/**
|
|
2406
|
+
* Makes `owner` own `system` before it installs its runtime there, and
|
|
2407
|
+
* returns whether it does. An unowned view forks in place, so the install
|
|
2408
|
+
* never reaches the system it was derived from. A system another execution
|
|
2409
|
+
* owns is left alone.
|
|
2410
|
+
*
|
|
2411
|
+
* @internal
|
|
2412
|
+
*/
|
|
2413
|
+
function adoptSystem(system, owner) {
|
|
2414
|
+
const view = snapshotSystemViews.get(system);
|
|
2415
|
+
const current = executionOwners.get(view?.executionSystem ?? system);
|
|
2416
|
+
if (current === owner) {
|
|
2417
|
+
if (view) {
|
|
2418
|
+
view.forwardInspection = !!owner.inspect;
|
|
2419
|
+
}
|
|
2420
|
+
return true;
|
|
2421
|
+
}
|
|
2422
|
+
// A system another execution owns stays with it.
|
|
2423
|
+
if (current) {
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
if (!view) {
|
|
2427
|
+
executionOwners.set(system, owner);
|
|
2428
|
+
return true;
|
|
2429
|
+
}
|
|
2430
|
+
forkFacilities(system, view.executionSystem, owner);
|
|
2431
|
+
view.executionSystem = system;
|
|
2432
|
+
view.forwardInspection = !!owner.inspect;
|
|
2433
|
+
return true;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
/**
|
|
2437
|
+
* Runs `fn` as a transition of `owner`. A view it derives from a system the
|
|
2438
|
+
* owner does not own forks into the owner's own execution system.
|
|
2439
|
+
*
|
|
2440
|
+
* @internal
|
|
2441
|
+
*/
|
|
2442
|
+
function withExecutionOwner(owner, fn) {
|
|
2443
|
+
const previous = ambientExecutionOwner;
|
|
2444
|
+
ambientExecutionOwner = owner;
|
|
2445
|
+
try {
|
|
2446
|
+
return fn();
|
|
2447
|
+
} finally {
|
|
2448
|
+
ambientExecutionOwner = previous;
|
|
2449
|
+
}
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
/** Hands the ambient owner to the first scope that asks for it. @internal */
|
|
2453
|
+
function takeExecutionOwner() {
|
|
2454
|
+
const owner = ambientExecutionOwner;
|
|
2455
|
+
ambientExecutionOwner = undefined;
|
|
2456
|
+
return owner;
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2337
2459
|
/** Returns the actor identity associated with a transition snapshot. @internal */
|
|
2338
2460
|
function getSnapshotActorRef(snapshot) {
|
|
2339
2461
|
const existing = snapshotActorRefs.get(snapshot);
|
|
@@ -2527,8 +2649,9 @@ function setInertActorScopeSnapshot(actorScope, snapshot, attachActorRef = true)
|
|
|
2527
2649
|
const lazyState = getLazyInertActorState(actorScope);
|
|
2528
2650
|
if (lazyState) {
|
|
2529
2651
|
lazyState.snapshot = snapshot;
|
|
2530
|
-
|
|
2531
|
-
|
|
2652
|
+
const scope = lazyState.materialized ?? lazyState.identityScope;
|
|
2653
|
+
if (scope) {
|
|
2654
|
+
scope.self._snapshot = snapshot;
|
|
2532
2655
|
}
|
|
2533
2656
|
} else {
|
|
2534
2657
|
actorScope.self._snapshot = snapshot;
|
|
@@ -2563,6 +2686,15 @@ function attachSnapshotActorRef(actorScope, snapshot) {
|
|
|
2563
2686
|
setLazySnapshotActorRef(snapshot, create);
|
|
2564
2687
|
return snapshot;
|
|
2565
2688
|
}
|
|
2689
|
+
/** Records the materialized scope and releases its consumed source. */
|
|
2690
|
+
function commitMaterialization(state, scope) {
|
|
2691
|
+
// Dropping the consumed source keeps this scope from retaining earlier snapshots.
|
|
2692
|
+
state.sourceRef = undefined;
|
|
2693
|
+
state.sourceChildren = {};
|
|
2694
|
+
state.materialized = scope;
|
|
2695
|
+
state.materialize = () => scope;
|
|
2696
|
+
return scope;
|
|
2697
|
+
}
|
|
2566
2698
|
const lazyInertActorState = Symbol();
|
|
2567
2699
|
const snapshotActorScopes = new WeakMap();
|
|
2568
2700
|
let inertActorMaterializationObserver;
|
|
@@ -2607,12 +2739,14 @@ const lazyInertActorScopePrototype = {
|
|
|
2607
2739
|
return materializeInertActorScope(this).actionExecutor;
|
|
2608
2740
|
}
|
|
2609
2741
|
};
|
|
2610
|
-
|
|
2742
|
+
|
|
2743
|
+
/** Creates a transactional planning scope backed by an inert actor. */
|
|
2744
|
+
function createMaterializedInertActorScope(actorLogic, sourceRef, sourceChildren, currentSnapshot, sourceSelf, owner) {
|
|
2611
2745
|
inertActorMaterializationObserver?.();
|
|
2612
2746
|
const snapshotRef = sourceRef?.();
|
|
2613
2747
|
const previousSelf = sourceSelf ?? snapshotRef?.actor;
|
|
2614
2748
|
const baseSystem = previousSelf?.system;
|
|
2615
|
-
const system = previousSelf && baseSystem ? createSnapshotSystem(baseSystem, sourceChildren, sourceSelf ? undefined : snapshotRef?.systemState) : undefined;
|
|
2749
|
+
const system = previousSelf && baseSystem ? createSnapshotSystem(baseSystem, sourceChildren, sourceSelf ? undefined : snapshotRef?.systemState, owner) : undefined;
|
|
2616
2750
|
const self = createActor(actorLogic, {
|
|
2617
2751
|
_inert: true,
|
|
2618
2752
|
...(previousSelf ? {
|
|
@@ -2632,12 +2766,8 @@ function createMaterializedInertActorScope(actorLogic, sourceRef, sourceChildren
|
|
|
2632
2766
|
// a future construction-time read cannot pin a root-shaped address.
|
|
2633
2767
|
self._address = undefined;
|
|
2634
2768
|
}
|
|
2635
|
-
if (currentSnapshot) {
|
|
2636
|
-
self._snapshot = currentSnapshot;
|
|
2637
|
-
}
|
|
2638
|
-
|
|
2639
2769
|
// Reuse the branch actor's scope while keeping planning transactional.
|
|
2640
|
-
|
|
2770
|
+
const scope = Object.create(self._actorScope, {
|
|
2641
2771
|
defer: {
|
|
2642
2772
|
value: () => {}
|
|
2643
2773
|
},
|
|
@@ -2646,8 +2776,20 @@ function createMaterializedInertActorScope(actorLogic, sourceRef, sourceChildren
|
|
|
2646
2776
|
},
|
|
2647
2777
|
actionExecutor: {
|
|
2648
2778
|
value: () => {}
|
|
2779
|
+
},
|
|
2780
|
+
_snapshot: {
|
|
2781
|
+
enumerable: true,
|
|
2782
|
+
configurable: true,
|
|
2783
|
+
get: () => self._snapshot,
|
|
2784
|
+
set: snapshot => {
|
|
2785
|
+
self._snapshot = snapshot;
|
|
2786
|
+
}
|
|
2649
2787
|
}
|
|
2650
2788
|
});
|
|
2789
|
+
if (currentSnapshot) {
|
|
2790
|
+
scope._snapshot = currentSnapshot;
|
|
2791
|
+
}
|
|
2792
|
+
return scope;
|
|
2651
2793
|
}
|
|
2652
2794
|
|
|
2653
2795
|
/** @internal */
|
|
@@ -2662,22 +2804,34 @@ function createInertActorScope(actorLogic, snapshot, sourceSelf, sourceActorScop
|
|
|
2662
2804
|
sourceChildren: isMachineSnapshot(snapshot) ? snapshot.children : {},
|
|
2663
2805
|
identityProvider: sourceState?.identityProvider ?? sourceRef,
|
|
2664
2806
|
parent: sourceSelf?._parent ?? sourceState?.parent ?? eagerSourceRef?.actor._parent,
|
|
2807
|
+
// Only the outermost scope of an owned transition belongs to the owner;
|
|
2808
|
+
// scopes for its intermediate snapshots inherit it, and nested pure
|
|
2809
|
+
// transitions run unowned.
|
|
2810
|
+
owner: sourceActorScope ? sourceState?.owner : takeExecutionOwner(),
|
|
2665
2811
|
parentKnown: !!sourceSelf || !!sourceState?.parentKnown || !!eagerSourceRef || !snapshot
|
|
2666
2812
|
};
|
|
2667
|
-
state.materialize = () =>
|
|
2813
|
+
state.materialize = () => {
|
|
2814
|
+
const scope = createMaterializedInertActorScope(actorLogic, state.sourceRef, state.sourceChildren, state.snapshot, sourceSelf, state.owner);
|
|
2815
|
+
return commitMaterialization(state, scope);
|
|
2816
|
+
};
|
|
2668
2817
|
if (!state.identityProvider && !snapshot) {
|
|
2669
2818
|
const identitySnapshot = {};
|
|
2670
|
-
const identitySourceRef = state.sourceRef;
|
|
2671
|
-
const identitySourceChildren = state.sourceChildren;
|
|
2672
|
-
let identityScope;
|
|
2673
2819
|
let identityRef;
|
|
2674
|
-
const getIdentityScope = () =>
|
|
2820
|
+
const getIdentityScope = () => {
|
|
2821
|
+
if (!state.identityScope) {
|
|
2822
|
+
state.identityScope = createMaterializedInertActorScope(actorLogic, state.sourceRef, state.sourceChildren, undefined, sourceSelf, state.owner);
|
|
2823
|
+
if (state.snapshot !== undefined) {
|
|
2824
|
+
state.identityScope.self._snapshot = state.snapshot;
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
return state.identityScope;
|
|
2828
|
+
};
|
|
2675
2829
|
state.materialize = () => {
|
|
2676
2830
|
const scope = getIdentityScope();
|
|
2677
2831
|
if (state.snapshot !== undefined) {
|
|
2678
2832
|
scope.self._snapshot = state.snapshot;
|
|
2679
2833
|
}
|
|
2680
|
-
return state
|
|
2834
|
+
return commitMaterialization(state, scope);
|
|
2681
2835
|
};
|
|
2682
2836
|
state.identityProvider = () => {
|
|
2683
2837
|
if (identityRef) {
|
|
@@ -4661,7 +4815,7 @@ function findNonJsonPath(value, path) {
|
|
|
4661
4815
|
};
|
|
4662
4816
|
}
|
|
4663
4817
|
if ('sessionId' in current && 'send' in current && 'ref' in current) {
|
|
4664
|
-
// Actor refs persist as `{
|
|
4818
|
+
// Actor refs persist as `{ "@actor": address }`.
|
|
4665
4819
|
return undefined;
|
|
4666
4820
|
}
|
|
4667
4821
|
if (ancestors.has(current)) {
|
|
@@ -4784,6 +4938,8 @@ const machineSnapshotToJSON = function toJSON() {
|
|
|
4784
4938
|
const {
|
|
4785
4939
|
nodes,
|
|
4786
4940
|
_stateInputs,
|
|
4941
|
+
_nextTimerId,
|
|
4942
|
+
_nextActorIds,
|
|
4787
4943
|
tags,
|
|
4788
4944
|
machine,
|
|
4789
4945
|
getMeta,
|
|
@@ -4908,6 +5064,8 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
4908
5064
|
const {
|
|
4909
5065
|
nodes,
|
|
4910
5066
|
_stateInputs,
|
|
5067
|
+
_nextTimerId,
|
|
5068
|
+
_nextActorIds,
|
|
4911
5069
|
tags,
|
|
4912
5070
|
machine,
|
|
4913
5071
|
children,
|
|
@@ -5043,6 +5201,11 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
5043
5201
|
if (_stateInputs && Object.keys(_stateInputs).length > 0) {
|
|
5044
5202
|
persisted.stateInputs = _stateInputs;
|
|
5045
5203
|
}
|
|
5204
|
+
// Stores such as Convex reject `_`-prefixed field names.
|
|
5205
|
+
persisted.nextTimerId = _nextTimerId;
|
|
5206
|
+
if (_nextActorIds && Object.keys(_nextActorIds).length > 0) {
|
|
5207
|
+
persisted.nextActorIds = _nextActorIds;
|
|
5208
|
+
}
|
|
5046
5209
|
if (machine.version !== undefined) {
|
|
5047
5210
|
persisted.machine = {
|
|
5048
5211
|
id: machine.id,
|
|
@@ -5074,7 +5237,7 @@ function persistContext(contextPart, getActorId, path = 'context', ancestors = [
|
|
|
5074
5237
|
};
|
|
5075
5238
|
// The address lets refs to non-children still route after restore.
|
|
5076
5239
|
copy[key] = {
|
|
5077
|
-
|
|
5240
|
+
'@actor': value.address
|
|
5078
5241
|
};
|
|
5079
5242
|
} else {
|
|
5080
5243
|
const valuePath = Array.isArray(contextPart) ? `${path}[${key}]` : `${path}.${key}`;
|
|
@@ -5716,11 +5879,18 @@ class RuntimeSystem {
|
|
|
5716
5879
|
// Records a send on the *sender's* transition for the `sent[]` inspection
|
|
5717
5880
|
// facet. Captures the send when it is initiated (including delayed sends that
|
|
5718
5881
|
// may never deliver), keyed to the source actor's in-flight transition.
|
|
5882
|
+
// A send made with no transition in flight (a callback's `sendBack`, a value
|
|
5883
|
+
// an observable relays to its parent) is not recorded: no transition reports
|
|
5884
|
+
// it, so it would be held until the source's next transition, or for as long
|
|
5885
|
+
// as the source lives if it never makes one.
|
|
5719
5886
|
_recordSent(source, target, event, delay, id) {
|
|
5720
5887
|
if (!this._inspectionObservers?.size || !source) {
|
|
5721
5888
|
return;
|
|
5722
5889
|
}
|
|
5723
5890
|
const inspectionSource = source;
|
|
5891
|
+
if (!inspectionSource._inTransition) {
|
|
5892
|
+
return;
|
|
5893
|
+
}
|
|
5724
5894
|
const collected = inspectionSource._collectedSent ??= [];
|
|
5725
5895
|
collected.push({
|
|
5726
5896
|
targetRef: target,
|
|
@@ -5957,9 +6127,9 @@ class RuntimeSystem {
|
|
|
5957
6127
|
} else if (
|
|
5958
6128
|
// A live actor of another incarnation is stale locally; an
|
|
5959
6129
|
// address this system cannot see may belong to a host runtime.
|
|
5960
|
-
this._getByAddress(target
|
|
6130
|
+
this._getByAddress(target['@actor']) || !this.runtime?.sendEvent) {
|
|
5961
6131
|
return this.deadLetter(source, undefined, event, 'missingTarget', {
|
|
5962
|
-
targetId: getAddressId(target
|
|
6132
|
+
targetId: getAddressId(target['@actor']),
|
|
5963
6133
|
error: createMissingAddressError(target)
|
|
5964
6134
|
});
|
|
5965
6135
|
}
|
|
@@ -6246,6 +6416,12 @@ class Actor {
|
|
|
6246
6416
|
this._collectedActions = void 0;
|
|
6247
6417
|
/** @internal Events relayed to other actors during the in-flight transition. */
|
|
6248
6418
|
this._collectedSent = void 0;
|
|
6419
|
+
/**
|
|
6420
|
+
* @internal Whether a transition is in flight: while the actor starts,
|
|
6421
|
+
* processes an event, or recovers from an execution error. Sends are recorded
|
|
6422
|
+
* for `sent[]` only then.
|
|
6423
|
+
*/
|
|
6424
|
+
this._inTransition = false;
|
|
6249
6425
|
this._initialEffects = void 0;
|
|
6250
6426
|
this.registryKey = void 0;
|
|
6251
6427
|
/** The globally unique process ID for this invocation. */
|
|
@@ -6318,9 +6494,14 @@ class Actor {
|
|
|
6318
6494
|
// transition functions; computing an initial snapshot here would run
|
|
6319
6495
|
// init-time side effects (context factories, entry) a second time.
|
|
6320
6496
|
} else {
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6497
|
+
this._inTransition = true;
|
|
6498
|
+
try {
|
|
6499
|
+
const [snapshot, effects] = finalizeTransitionResult(this._actorScope, undefined, this.logic.initialTransition(this.options?.input, this._actorScope));
|
|
6500
|
+
this._setSnapshot(snapshot);
|
|
6501
|
+
this._initialEffects = effects.length ? effects : undefined;
|
|
6502
|
+
} finally {
|
|
6503
|
+
this._inTransition = false;
|
|
6504
|
+
}
|
|
6324
6505
|
}
|
|
6325
6506
|
} catch (err) {
|
|
6326
6507
|
// Restored logic may keep its snapshot shape on restore failures (e.g.
|
|
@@ -6473,6 +6654,8 @@ class Actor {
|
|
|
6473
6654
|
if (!errorEvent) {
|
|
6474
6655
|
return false;
|
|
6475
6656
|
}
|
|
6657
|
+
const inTransition = this._inTransition;
|
|
6658
|
+
this._inTransition = true;
|
|
6476
6659
|
try {
|
|
6477
6660
|
const [nextSnapshot, effects] = finalizeTransitionResult(this._actorScope, snapshot, this.logic.transition(snapshot, errorEvent, this._actorScope));
|
|
6478
6661
|
this._setSnapshot(nextSnapshot);
|
|
@@ -6481,6 +6664,8 @@ class Actor {
|
|
|
6481
6664
|
return true;
|
|
6482
6665
|
} catch {
|
|
6483
6666
|
return false;
|
|
6667
|
+
} finally {
|
|
6668
|
+
this._inTransition = inTransition;
|
|
6484
6669
|
}
|
|
6485
6670
|
}
|
|
6486
6671
|
_next(snapshot) {
|
|
@@ -6692,6 +6877,15 @@ class Actor {
|
|
|
6692
6877
|
|
|
6693
6878
|
/** Starts the Actor from the initial state */
|
|
6694
6879
|
start() {
|
|
6880
|
+
const inTransition = this._inTransition;
|
|
6881
|
+
this._inTransition = true;
|
|
6882
|
+
try {
|
|
6883
|
+
return this._start();
|
|
6884
|
+
} finally {
|
|
6885
|
+
this._inTransition = inTransition;
|
|
6886
|
+
}
|
|
6887
|
+
}
|
|
6888
|
+
_start() {
|
|
6695
6889
|
if (this._processingStatus === ProcessingStatus.Running) {
|
|
6696
6890
|
// Do not restart the service if it is already started
|
|
6697
6891
|
return this;
|
|
@@ -6807,7 +7001,16 @@ class Actor {
|
|
|
6807
7001
|
this.mailbox?.start();
|
|
6808
7002
|
return this;
|
|
6809
7003
|
}
|
|
6810
|
-
_process({
|
|
7004
|
+
_process(item) {
|
|
7005
|
+
const inTransition = this._inTransition;
|
|
7006
|
+
this._inTransition = true;
|
|
7007
|
+
try {
|
|
7008
|
+
this._processEvent(item);
|
|
7009
|
+
} finally {
|
|
7010
|
+
this._inTransition = inTransition;
|
|
7011
|
+
}
|
|
7012
|
+
}
|
|
7013
|
+
_processEvent({
|
|
6811
7014
|
event,
|
|
6812
7015
|
sourceRef
|
|
6813
7016
|
}) {
|
|
@@ -7055,12 +7258,12 @@ class Actor {
|
|
|
7055
7258
|
}
|
|
7056
7259
|
|
|
7057
7260
|
/**
|
|
7058
|
-
* Returns the actor's serializable logical identity: `{
|
|
7261
|
+
* Returns the actor's serializable logical identity: `{ "@actor": address }`.
|
|
7059
7262
|
* The result can be used as an `enq.sendTo(...)` target.
|
|
7060
7263
|
*/
|
|
7061
7264
|
toJSON() {
|
|
7062
7265
|
return {
|
|
7063
|
-
|
|
7266
|
+
'@actor': this.address
|
|
7064
7267
|
};
|
|
7065
7268
|
}
|
|
7066
7269
|
|
|
@@ -7187,6 +7390,7 @@ exports.XSTATE_LOGIC_EFFECT_START = XSTATE_LOGIC_EFFECT_START;
|
|
|
7187
7390
|
exports.XSTATE_STOP = XSTATE_STOP;
|
|
7188
7391
|
exports.XSTATE_STOP_EFFECT = XSTATE_STOP_EFFECT;
|
|
7189
7392
|
exports.XSTATE_TIMER = XSTATE_TIMER;
|
|
7393
|
+
exports.adoptSystem = adoptSystem;
|
|
7190
7394
|
exports.allocateChildId = allocateChildId;
|
|
7191
7395
|
exports.assertChildIdFree = assertChildIdFree;
|
|
7192
7396
|
exports.assertUnreservedSourceName = assertUnreservedSourceName;
|
|
@@ -7286,4 +7490,5 @@ exports.toTransitionConfigArray = toTransitionConfigArray;
|
|
|
7286
7490
|
exports.transitionNode = transitionNode;
|
|
7287
7491
|
exports.withActorSelf = withActorSelf;
|
|
7288
7492
|
exports.withExecutionIdentity = withExecutionIdentity;
|
|
7493
|
+
exports.withExecutionOwner = withExecutionOwner;
|
|
7289
7494
|
exports.withSystemInspector = withSystemInspector;
|