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
|
@@ -164,11 +164,11 @@ function isRemoteActorRef(actorRef) {
|
|
|
164
164
|
* JSON (`actor.toJSON()`): plain data carrying an address, not an actor.
|
|
165
165
|
*/
|
|
166
166
|
function isSerializedActorRef(target) {
|
|
167
|
-
if (typeof target !== 'object' || target === null || Array.isArray(target) || typeof target
|
|
167
|
+
if (typeof target !== 'object' || target === null || Array.isArray(target) || typeof target['@actor'] !== 'string') {
|
|
168
168
|
return false;
|
|
169
169
|
}
|
|
170
170
|
for (const key in target) {
|
|
171
|
-
if (key !== '
|
|
171
|
+
if (key !== '@actor' && key !== 'incarnation') {
|
|
172
172
|
return false;
|
|
173
173
|
}
|
|
174
174
|
}
|
|
@@ -184,7 +184,7 @@ function getAddressId(address) {
|
|
|
184
184
|
|
|
185
185
|
/** @internal The error reported when no live actor has a serialized address. */
|
|
186
186
|
function createMissingAddressError(target) {
|
|
187
|
-
return new Error(xstateError(50, ...(target.incarnation === undefined ? [target
|
|
187
|
+
return new Error(xstateError(50, ...(target.incarnation === undefined ? [target['@actor']] : [target['@actor'], target.incarnation])) );
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
/**
|
|
@@ -193,7 +193,7 @@ function createMissingAddressError(target) {
|
|
|
193
193
|
* without one follows whichever actor is live at the address.
|
|
194
194
|
*/
|
|
195
195
|
function resolveSerializedActorRef(system, target) {
|
|
196
|
-
const live = system._getByAddress?.(target
|
|
196
|
+
const live = system._getByAddress?.(target['@actor']);
|
|
197
197
|
return live && (target.incarnation === undefined || live.sessionId === target.incarnation) ? live : undefined;
|
|
198
198
|
}
|
|
199
199
|
|
|
@@ -246,7 +246,7 @@ function createInertActorRef(options) {
|
|
|
246
246
|
throw new Error(xstateError(51, id));
|
|
247
247
|
}
|
|
248
248
|
return {
|
|
249
|
-
|
|
249
|
+
'@actor': address
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
252
|
};
|
|
@@ -332,7 +332,7 @@ function createRemoteActorRef(system, options) {
|
|
|
332
332
|
// one actor-reference shape whether a child is co-located or remote.
|
|
333
333
|
toJSON() {
|
|
334
334
|
return {
|
|
335
|
-
|
|
335
|
+
'@actor': options.address
|
|
336
336
|
};
|
|
337
337
|
}
|
|
338
338
|
};
|
|
@@ -452,7 +452,7 @@ function deliverEvent(source, target, event) {
|
|
|
452
452
|
throw error;
|
|
453
453
|
}
|
|
454
454
|
void system.deadLetter(source, undefined, event, 'missingTarget', {
|
|
455
|
-
targetId: getAddressId(serialized
|
|
455
|
+
targetId: getAddressId(serialized['@actor']),
|
|
456
456
|
error
|
|
457
457
|
});
|
|
458
458
|
return;
|
|
@@ -2112,6 +2112,18 @@ function withSystemInspector(inspect, fn) {
|
|
|
2112
2112
|
|
|
2113
2113
|
/** Snapshot-scoped actor identity and system view. @internal */
|
|
2114
2114
|
|
|
2115
|
+
// Each view's execution system and whether it forwards inspection. Views
|
|
2116
|
+
// never chain: they all inherit from the execution system directly.
|
|
2117
|
+
const snapshotSystemViews = new WeakMap();
|
|
2118
|
+
// Facilities owned by the execution rather than by one snapshot's view. A view
|
|
2119
|
+
// reads and writes them on the execution system, so timers, listeners and the
|
|
2120
|
+
// runtime installed through any snapshot are visible through every other.
|
|
2121
|
+
const executionFacilities = ['runtime', '_timerMap', '_rejectionListeners', '_inspectionObservers', '_emissionListeners'];
|
|
2122
|
+
// The durable execution that owns each execution system.
|
|
2123
|
+
/** A durable execution, as the owner of the views its transitions create. @internal */
|
|
2124
|
+
|
|
2125
|
+
const executionOwners = new WeakMap();
|
|
2126
|
+
let ambientExecutionOwner;
|
|
2115
2127
|
const snapshotActorRefs = new WeakMap();
|
|
2116
2128
|
const lazySnapshotActorRefs = new WeakMap();
|
|
2117
2129
|
const emptyKeyedActors = new Map();
|
|
@@ -2171,12 +2183,22 @@ function getSnapshotChildren(snapshot) {
|
|
|
2171
2183
|
*
|
|
2172
2184
|
* @internal
|
|
2173
2185
|
*/
|
|
2174
|
-
function createSnapshotSystem(baseSystem, children, baseState) {
|
|
2175
|
-
const
|
|
2186
|
+
function createSnapshotSystem(baseSystem, children, baseState, owner) {
|
|
2187
|
+
const baseView = snapshotSystemViews.get(baseSystem);
|
|
2188
|
+
const baseExecutionSystem = baseView?.executionSystem ?? baseSystem;
|
|
2189
|
+
// The runtime system under every view. A view runs its methods against the
|
|
2190
|
+
// execution system's facilities.
|
|
2191
|
+
const rootSystem = baseView?.rootSystem ?? baseSystem;
|
|
2192
|
+
const forks = owner !== undefined && executionOwners.get(baseExecutionSystem) !== owner;
|
|
2193
|
+
// A view an execution owns reports to that execution's inspector.
|
|
2194
|
+
const forwardInspection = owner ? !!owner.inspect : hasAmbientInspector() && (baseView?.forwardInspection ?? true);
|
|
2176
2195
|
const registeredActors = copyRegisteredActors(baseSystem, baseState);
|
|
2177
2196
|
const keyedActors = new Map(baseState?.keyedActors ?? getKeyedActors(baseSystem));
|
|
2178
2197
|
const reverseKeyedActors = new WeakMap();
|
|
2179
|
-
|
|
2198
|
+
// The view's execution system; adoption can make the view its own.
|
|
2199
|
+
const execution = () => snapshotSystemViews.get(system).executionSystem;
|
|
2200
|
+
const forwards = () => snapshotSystemViews.get(system).forwardInspection;
|
|
2201
|
+
const system = Object.assign(Object.create(baseExecutionSystem), {
|
|
2180
2202
|
children: registeredActors,
|
|
2181
2203
|
keyedActors,
|
|
2182
2204
|
reverseKeyedActors,
|
|
@@ -2211,15 +2233,38 @@ function createSnapshotSystem(baseSystem, children, baseState) {
|
|
|
2211
2233
|
},
|
|
2212
2234
|
get: registryKey => keyedActors.get(registryKey),
|
|
2213
2235
|
getAll: () => Object.fromEntries(keyedActors),
|
|
2214
|
-
onEmitted: listener =>
|
|
2215
|
-
_notifyEmitted: (actorRef, event) =>
|
|
2236
|
+
onEmitted: listener => rootSystem.onEmitted.call(execution(), listener),
|
|
2237
|
+
_notifyEmitted: (actorRef, event) => rootSystem._notifyEmitted.call(execution(), actorRef, event),
|
|
2216
2238
|
// Pure transition resolution must not leak topology inspection events
|
|
2217
2239
|
// into a live runtime system — planning branches stay silent. The one
|
|
2218
2240
|
// exception is a durable execution's own transitions (marked by the
|
|
2219
2241
|
// ambient inspector at creation time): there the pure path IS the
|
|
2220
|
-
// execution, so inspection forwards to the
|
|
2221
|
-
_hasInspectionObservers:
|
|
2222
|
-
_sendInspectionEvent:
|
|
2242
|
+
// execution, so inspection forwards to the execution system's observers.
|
|
2243
|
+
_hasInspectionObservers: () => forwards() && (rootSystem._hasInspectionObservers?.call(execution()) ?? false),
|
|
2244
|
+
_sendInspectionEvent: event => {
|
|
2245
|
+
if (forwards()) {
|
|
2246
|
+
rootSystem._sendInspectionEvent.call(execution(), event);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
});
|
|
2250
|
+
const executionSystem = forks ? system : baseExecutionSystem;
|
|
2251
|
+
if (forks) {
|
|
2252
|
+
forkFacilities(system, baseExecutionSystem, owner);
|
|
2253
|
+
} else {
|
|
2254
|
+
for (const key of executionFacilities) {
|
|
2255
|
+
Object.defineProperty(system, key, {
|
|
2256
|
+
configurable: true,
|
|
2257
|
+
get: () => execution()[key],
|
|
2258
|
+
set: value => {
|
|
2259
|
+
execution()[key] = value;
|
|
2260
|
+
}
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
snapshotSystemViews.set(system, {
|
|
2265
|
+
executionSystem,
|
|
2266
|
+
rootSystem,
|
|
2267
|
+
forwardInspection
|
|
2223
2268
|
});
|
|
2224
2269
|
for (const [registryKey, actor] of keyedActors) {
|
|
2225
2270
|
if (!actor) {
|
|
@@ -2243,6 +2288,83 @@ function createSnapshotSystem(baseSystem, children, baseState) {
|
|
|
2243
2288
|
return system;
|
|
2244
2289
|
}
|
|
2245
2290
|
|
|
2291
|
+
/**
|
|
2292
|
+
* Makes `system` the execution system of `owner`, a new incarnation: it gets
|
|
2293
|
+
* the owner's runtime and the pending timers it saw, and starts with no
|
|
2294
|
+
* listeners or inspectors, so nothing registered on another execution
|
|
2295
|
+
* observes it.
|
|
2296
|
+
*/
|
|
2297
|
+
function forkFacilities(system, from, owner) {
|
|
2298
|
+
const timers = from._timerMap;
|
|
2299
|
+
for (const key of executionFacilities) {
|
|
2300
|
+
Object.defineProperty(system, key, {
|
|
2301
|
+
configurable: true,
|
|
2302
|
+
writable: true,
|
|
2303
|
+
value: key === 'runtime' ? owner.runtime : key === '_timerMap' && timers ? {
|
|
2304
|
+
...timers
|
|
2305
|
+
} : undefined
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
executionOwners.set(system, owner);
|
|
2309
|
+
if (owner.inspect) {
|
|
2310
|
+
system.inspect(owner.inspect);
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
/**
|
|
2315
|
+
* Makes `owner` own `system` before it installs its runtime there, and
|
|
2316
|
+
* returns whether it does. An unowned view forks in place, so the install
|
|
2317
|
+
* never reaches the system it was derived from. A system another execution
|
|
2318
|
+
* owns is left alone.
|
|
2319
|
+
*
|
|
2320
|
+
* @internal
|
|
2321
|
+
*/
|
|
2322
|
+
function adoptSystem(system, owner) {
|
|
2323
|
+
const view = snapshotSystemViews.get(system);
|
|
2324
|
+
const current = executionOwners.get(view?.executionSystem ?? system);
|
|
2325
|
+
if (current === owner) {
|
|
2326
|
+
if (view) {
|
|
2327
|
+
view.forwardInspection = !!owner.inspect;
|
|
2328
|
+
}
|
|
2329
|
+
return true;
|
|
2330
|
+
}
|
|
2331
|
+
// A system another execution owns stays with it.
|
|
2332
|
+
if (current) {
|
|
2333
|
+
return false;
|
|
2334
|
+
}
|
|
2335
|
+
if (!view) {
|
|
2336
|
+
executionOwners.set(system, owner);
|
|
2337
|
+
return true;
|
|
2338
|
+
}
|
|
2339
|
+
forkFacilities(system, view.executionSystem, owner);
|
|
2340
|
+
view.executionSystem = system;
|
|
2341
|
+
view.forwardInspection = !!owner.inspect;
|
|
2342
|
+
return true;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
/**
|
|
2346
|
+
* Runs `fn` as a transition of `owner`. A view it derives from a system the
|
|
2347
|
+
* owner does not own forks into the owner's own execution system.
|
|
2348
|
+
*
|
|
2349
|
+
* @internal
|
|
2350
|
+
*/
|
|
2351
|
+
function withExecutionOwner(owner, fn) {
|
|
2352
|
+
const previous = ambientExecutionOwner;
|
|
2353
|
+
ambientExecutionOwner = owner;
|
|
2354
|
+
try {
|
|
2355
|
+
return fn();
|
|
2356
|
+
} finally {
|
|
2357
|
+
ambientExecutionOwner = previous;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
/** Hands the ambient owner to the first scope that asks for it. @internal */
|
|
2362
|
+
function takeExecutionOwner() {
|
|
2363
|
+
const owner = ambientExecutionOwner;
|
|
2364
|
+
ambientExecutionOwner = undefined;
|
|
2365
|
+
return owner;
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2246
2368
|
/** Returns the actor identity associated with a transition snapshot. @internal */
|
|
2247
2369
|
function getSnapshotActorRef(snapshot) {
|
|
2248
2370
|
const existing = snapshotActorRefs.get(snapshot);
|
|
@@ -2436,8 +2558,9 @@ function setInertActorScopeSnapshot(actorScope, snapshot, attachActorRef = true)
|
|
|
2436
2558
|
const lazyState = getLazyInertActorState(actorScope);
|
|
2437
2559
|
if (lazyState) {
|
|
2438
2560
|
lazyState.snapshot = snapshot;
|
|
2439
|
-
|
|
2440
|
-
|
|
2561
|
+
const scope = lazyState.materialized ?? lazyState.identityScope;
|
|
2562
|
+
if (scope) {
|
|
2563
|
+
scope.self._snapshot = snapshot;
|
|
2441
2564
|
}
|
|
2442
2565
|
} else {
|
|
2443
2566
|
actorScope.self._snapshot = snapshot;
|
|
@@ -2472,6 +2595,15 @@ function attachSnapshotActorRef(actorScope, snapshot) {
|
|
|
2472
2595
|
setLazySnapshotActorRef(snapshot, create);
|
|
2473
2596
|
return snapshot;
|
|
2474
2597
|
}
|
|
2598
|
+
/** Records the materialized scope and releases its consumed source. */
|
|
2599
|
+
function commitMaterialization(state, scope) {
|
|
2600
|
+
// Dropping the consumed source keeps this scope from retaining earlier snapshots.
|
|
2601
|
+
state.sourceRef = undefined;
|
|
2602
|
+
state.sourceChildren = {};
|
|
2603
|
+
state.materialized = scope;
|
|
2604
|
+
state.materialize = () => scope;
|
|
2605
|
+
return scope;
|
|
2606
|
+
}
|
|
2475
2607
|
const lazyInertActorState = Symbol();
|
|
2476
2608
|
const snapshotActorScopes = new WeakMap();
|
|
2477
2609
|
let inertActorMaterializationObserver;
|
|
@@ -2516,12 +2648,14 @@ const lazyInertActorScopePrototype = {
|
|
|
2516
2648
|
return materializeInertActorScope(this).actionExecutor;
|
|
2517
2649
|
}
|
|
2518
2650
|
};
|
|
2519
|
-
|
|
2651
|
+
|
|
2652
|
+
/** Creates a transactional planning scope backed by an inert actor. */
|
|
2653
|
+
function createMaterializedInertActorScope(actorLogic, sourceRef, sourceChildren, currentSnapshot, sourceSelf, owner) {
|
|
2520
2654
|
inertActorMaterializationObserver?.();
|
|
2521
2655
|
const snapshotRef = sourceRef?.();
|
|
2522
2656
|
const previousSelf = sourceSelf ?? snapshotRef?.actor;
|
|
2523
2657
|
const baseSystem = previousSelf?.system;
|
|
2524
|
-
const system = previousSelf && baseSystem ? createSnapshotSystem(baseSystem, sourceChildren, sourceSelf ? undefined : snapshotRef?.systemState) : undefined;
|
|
2658
|
+
const system = previousSelf && baseSystem ? createSnapshotSystem(baseSystem, sourceChildren, sourceSelf ? undefined : snapshotRef?.systemState, owner) : undefined;
|
|
2525
2659
|
const self = createActor(actorLogic, {
|
|
2526
2660
|
_inert: true,
|
|
2527
2661
|
...(previousSelf ? {
|
|
@@ -2541,12 +2675,8 @@ function createMaterializedInertActorScope(actorLogic, sourceRef, sourceChildren
|
|
|
2541
2675
|
// a future construction-time read cannot pin a root-shaped address.
|
|
2542
2676
|
self._address = undefined;
|
|
2543
2677
|
}
|
|
2544
|
-
if (currentSnapshot) {
|
|
2545
|
-
self._snapshot = currentSnapshot;
|
|
2546
|
-
}
|
|
2547
|
-
|
|
2548
2678
|
// Reuse the branch actor's scope while keeping planning transactional.
|
|
2549
|
-
|
|
2679
|
+
const scope = Object.create(self._actorScope, {
|
|
2550
2680
|
defer: {
|
|
2551
2681
|
value: () => {}
|
|
2552
2682
|
},
|
|
@@ -2555,8 +2685,20 @@ function createMaterializedInertActorScope(actorLogic, sourceRef, sourceChildren
|
|
|
2555
2685
|
},
|
|
2556
2686
|
actionExecutor: {
|
|
2557
2687
|
value: () => {}
|
|
2688
|
+
},
|
|
2689
|
+
_snapshot: {
|
|
2690
|
+
enumerable: true,
|
|
2691
|
+
configurable: true,
|
|
2692
|
+
get: () => self._snapshot,
|
|
2693
|
+
set: snapshot => {
|
|
2694
|
+
self._snapshot = snapshot;
|
|
2695
|
+
}
|
|
2558
2696
|
}
|
|
2559
2697
|
});
|
|
2698
|
+
if (currentSnapshot) {
|
|
2699
|
+
scope._snapshot = currentSnapshot;
|
|
2700
|
+
}
|
|
2701
|
+
return scope;
|
|
2560
2702
|
}
|
|
2561
2703
|
|
|
2562
2704
|
/** @internal */
|
|
@@ -2571,22 +2713,34 @@ function createInertActorScope(actorLogic, snapshot, sourceSelf, sourceActorScop
|
|
|
2571
2713
|
sourceChildren: isMachineSnapshot(snapshot) ? snapshot.children : {},
|
|
2572
2714
|
identityProvider: sourceState?.identityProvider ?? sourceRef,
|
|
2573
2715
|
parent: sourceSelf?._parent ?? sourceState?.parent ?? eagerSourceRef?.actor._parent,
|
|
2716
|
+
// Only the outermost scope of an owned transition belongs to the owner;
|
|
2717
|
+
// scopes for its intermediate snapshots inherit it, and nested pure
|
|
2718
|
+
// transitions run unowned.
|
|
2719
|
+
owner: sourceActorScope ? sourceState?.owner : takeExecutionOwner(),
|
|
2574
2720
|
parentKnown: !!sourceSelf || !!sourceState?.parentKnown || !!eagerSourceRef || !snapshot
|
|
2575
2721
|
};
|
|
2576
|
-
state.materialize = () =>
|
|
2722
|
+
state.materialize = () => {
|
|
2723
|
+
const scope = createMaterializedInertActorScope(actorLogic, state.sourceRef, state.sourceChildren, state.snapshot, sourceSelf, state.owner);
|
|
2724
|
+
return commitMaterialization(state, scope);
|
|
2725
|
+
};
|
|
2577
2726
|
if (!state.identityProvider && !snapshot) {
|
|
2578
2727
|
const identitySnapshot = {};
|
|
2579
|
-
const identitySourceRef = state.sourceRef;
|
|
2580
|
-
const identitySourceChildren = state.sourceChildren;
|
|
2581
|
-
let identityScope;
|
|
2582
2728
|
let identityRef;
|
|
2583
|
-
const getIdentityScope = () =>
|
|
2729
|
+
const getIdentityScope = () => {
|
|
2730
|
+
if (!state.identityScope) {
|
|
2731
|
+
state.identityScope = createMaterializedInertActorScope(actorLogic, state.sourceRef, state.sourceChildren, undefined, sourceSelf, state.owner);
|
|
2732
|
+
if (state.snapshot !== undefined) {
|
|
2733
|
+
state.identityScope.self._snapshot = state.snapshot;
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
return state.identityScope;
|
|
2737
|
+
};
|
|
2584
2738
|
state.materialize = () => {
|
|
2585
2739
|
const scope = getIdentityScope();
|
|
2586
2740
|
if (state.snapshot !== undefined) {
|
|
2587
2741
|
scope.self._snapshot = state.snapshot;
|
|
2588
2742
|
}
|
|
2589
|
-
return state
|
|
2743
|
+
return commitMaterialization(state, scope);
|
|
2590
2744
|
};
|
|
2591
2745
|
state.identityProvider = () => {
|
|
2592
2746
|
if (identityRef) {
|
|
@@ -4559,6 +4713,8 @@ const machineSnapshotToJSON = function toJSON() {
|
|
|
4559
4713
|
const {
|
|
4560
4714
|
nodes,
|
|
4561
4715
|
_stateInputs,
|
|
4716
|
+
_nextTimerId,
|
|
4717
|
+
_nextActorIds,
|
|
4562
4718
|
tags,
|
|
4563
4719
|
machine,
|
|
4564
4720
|
getMeta,
|
|
@@ -4677,6 +4833,8 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
4677
4833
|
const {
|
|
4678
4834
|
nodes,
|
|
4679
4835
|
_stateInputs,
|
|
4836
|
+
_nextTimerId,
|
|
4837
|
+
_nextActorIds,
|
|
4680
4838
|
tags,
|
|
4681
4839
|
machine,
|
|
4682
4840
|
children,
|
|
@@ -4803,6 +4961,11 @@ function getPersistedSnapshot(snapshot, options) {
|
|
|
4803
4961
|
if (_stateInputs && Object.keys(_stateInputs).length > 0) {
|
|
4804
4962
|
persisted.stateInputs = _stateInputs;
|
|
4805
4963
|
}
|
|
4964
|
+
// Stores such as Convex reject `_`-prefixed field names.
|
|
4965
|
+
persisted.nextTimerId = _nextTimerId;
|
|
4966
|
+
if (_nextActorIds && Object.keys(_nextActorIds).length > 0) {
|
|
4967
|
+
persisted.nextActorIds = _nextActorIds;
|
|
4968
|
+
}
|
|
4806
4969
|
if (machine.version !== undefined) {
|
|
4807
4970
|
persisted.machine = {
|
|
4808
4971
|
id: machine.id,
|
|
@@ -4825,7 +4988,7 @@ function persistContext(contextPart, getActorId, path = 'context', ancestors = [
|
|
|
4825
4988
|
};
|
|
4826
4989
|
// The address lets refs to non-children still route after restore.
|
|
4827
4990
|
copy[key] = {
|
|
4828
|
-
|
|
4991
|
+
'@actor': value.address
|
|
4829
4992
|
};
|
|
4830
4993
|
} else {
|
|
4831
4994
|
const valuePath = Array.isArray(contextPart) ? `${path}[${key}]` : `${path}.${key}`;
|
|
@@ -5458,11 +5621,18 @@ class RuntimeSystem {
|
|
|
5458
5621
|
// Records a send on the *sender's* transition for the `sent[]` inspection
|
|
5459
5622
|
// facet. Captures the send when it is initiated (including delayed sends that
|
|
5460
5623
|
// may never deliver), keyed to the source actor's in-flight transition.
|
|
5624
|
+
// A send made with no transition in flight (a callback's `sendBack`, a value
|
|
5625
|
+
// an observable relays to its parent) is not recorded: no transition reports
|
|
5626
|
+
// it, so it would be held until the source's next transition, or for as long
|
|
5627
|
+
// as the source lives if it never makes one.
|
|
5461
5628
|
_recordSent(source, target, event, delay, id) {
|
|
5462
5629
|
if (!this._inspectionObservers?.size || !source) {
|
|
5463
5630
|
return;
|
|
5464
5631
|
}
|
|
5465
5632
|
const inspectionSource = source;
|
|
5633
|
+
if (!inspectionSource._inTransition) {
|
|
5634
|
+
return;
|
|
5635
|
+
}
|
|
5466
5636
|
const collected = inspectionSource._collectedSent ??= [];
|
|
5467
5637
|
collected.push({
|
|
5468
5638
|
targetRef: target,
|
|
@@ -5699,9 +5869,9 @@ class RuntimeSystem {
|
|
|
5699
5869
|
} else if (
|
|
5700
5870
|
// A live actor of another incarnation is stale locally; an
|
|
5701
5871
|
// address this system cannot see may belong to a host runtime.
|
|
5702
|
-
this._getByAddress(target
|
|
5872
|
+
this._getByAddress(target['@actor']) || !this.runtime?.sendEvent) {
|
|
5703
5873
|
return this.deadLetter(source, undefined, event, 'missingTarget', {
|
|
5704
|
-
targetId: getAddressId(target
|
|
5874
|
+
targetId: getAddressId(target['@actor']),
|
|
5705
5875
|
error: createMissingAddressError(target)
|
|
5706
5876
|
});
|
|
5707
5877
|
}
|
|
@@ -5985,6 +6155,12 @@ class Actor {
|
|
|
5985
6155
|
this._collectedActions = void 0;
|
|
5986
6156
|
/** @internal Events relayed to other actors during the in-flight transition. */
|
|
5987
6157
|
this._collectedSent = void 0;
|
|
6158
|
+
/**
|
|
6159
|
+
* @internal Whether a transition is in flight: while the actor starts,
|
|
6160
|
+
* processes an event, or recovers from an execution error. Sends are recorded
|
|
6161
|
+
* for `sent[]` only then.
|
|
6162
|
+
*/
|
|
6163
|
+
this._inTransition = false;
|
|
5988
6164
|
this._initialEffects = void 0;
|
|
5989
6165
|
this.registryKey = void 0;
|
|
5990
6166
|
/** The globally unique process ID for this invocation. */
|
|
@@ -6057,9 +6233,14 @@ class Actor {
|
|
|
6057
6233
|
// transition functions; computing an initial snapshot here would run
|
|
6058
6234
|
// init-time side effects (context factories, entry) a second time.
|
|
6059
6235
|
} else {
|
|
6060
|
-
|
|
6061
|
-
|
|
6062
|
-
|
|
6236
|
+
this._inTransition = true;
|
|
6237
|
+
try {
|
|
6238
|
+
const [snapshot, effects] = finalizeTransitionResult(this._actorScope, undefined, this.logic.initialTransition(this.options?.input, this._actorScope));
|
|
6239
|
+
this._setSnapshot(snapshot);
|
|
6240
|
+
this._initialEffects = effects.length ? effects : undefined;
|
|
6241
|
+
} finally {
|
|
6242
|
+
this._inTransition = false;
|
|
6243
|
+
}
|
|
6063
6244
|
}
|
|
6064
6245
|
} catch (err) {
|
|
6065
6246
|
// Restored logic may keep its snapshot shape on restore failures (e.g.
|
|
@@ -6212,6 +6393,8 @@ class Actor {
|
|
|
6212
6393
|
if (!errorEvent) {
|
|
6213
6394
|
return false;
|
|
6214
6395
|
}
|
|
6396
|
+
const inTransition = this._inTransition;
|
|
6397
|
+
this._inTransition = true;
|
|
6215
6398
|
try {
|
|
6216
6399
|
const [nextSnapshot, effects] = finalizeTransitionResult(this._actorScope, snapshot, this.logic.transition(snapshot, errorEvent, this._actorScope));
|
|
6217
6400
|
this._setSnapshot(nextSnapshot);
|
|
@@ -6220,6 +6403,8 @@ class Actor {
|
|
|
6220
6403
|
return true;
|
|
6221
6404
|
} catch {
|
|
6222
6405
|
return false;
|
|
6406
|
+
} finally {
|
|
6407
|
+
this._inTransition = inTransition;
|
|
6223
6408
|
}
|
|
6224
6409
|
}
|
|
6225
6410
|
_next(snapshot) {
|
|
@@ -6431,6 +6616,15 @@ class Actor {
|
|
|
6431
6616
|
|
|
6432
6617
|
/** Starts the Actor from the initial state */
|
|
6433
6618
|
start() {
|
|
6619
|
+
const inTransition = this._inTransition;
|
|
6620
|
+
this._inTransition = true;
|
|
6621
|
+
try {
|
|
6622
|
+
return this._start();
|
|
6623
|
+
} finally {
|
|
6624
|
+
this._inTransition = inTransition;
|
|
6625
|
+
}
|
|
6626
|
+
}
|
|
6627
|
+
_start() {
|
|
6434
6628
|
if (this._processingStatus === ProcessingStatus.Running) {
|
|
6435
6629
|
// Do not restart the service if it is already started
|
|
6436
6630
|
return this;
|
|
@@ -6546,7 +6740,16 @@ class Actor {
|
|
|
6546
6740
|
this.mailbox?.start();
|
|
6547
6741
|
return this;
|
|
6548
6742
|
}
|
|
6549
|
-
_process({
|
|
6743
|
+
_process(item) {
|
|
6744
|
+
const inTransition = this._inTransition;
|
|
6745
|
+
this._inTransition = true;
|
|
6746
|
+
try {
|
|
6747
|
+
this._processEvent(item);
|
|
6748
|
+
} finally {
|
|
6749
|
+
this._inTransition = inTransition;
|
|
6750
|
+
}
|
|
6751
|
+
}
|
|
6752
|
+
_processEvent({
|
|
6550
6753
|
event,
|
|
6551
6754
|
sourceRef
|
|
6552
6755
|
}) {
|
|
@@ -6783,12 +6986,12 @@ class Actor {
|
|
|
6783
6986
|
}
|
|
6784
6987
|
|
|
6785
6988
|
/**
|
|
6786
|
-
* Returns the actor's serializable logical identity: `{
|
|
6989
|
+
* Returns the actor's serializable logical identity: `{ "@actor": address }`.
|
|
6787
6990
|
* The result can be used as an `enq.sendTo(...)` target.
|
|
6788
6991
|
*/
|
|
6789
6992
|
toJSON() {
|
|
6790
6993
|
return {
|
|
6791
|
-
|
|
6994
|
+
'@actor': this.address
|
|
6792
6995
|
};
|
|
6793
6996
|
}
|
|
6794
6997
|
|
|
@@ -6899,4 +7102,4 @@ function createActor(logic, ...[options]) {
|
|
|
6899
7102
|
return new Actor(logic, options);
|
|
6900
7103
|
}
|
|
6901
7104
|
|
|
6902
|
-
export { resolveRegisteredActorSource as $, isMachineSnapshot as A, listenerLogic as B, subscriptionLogic as C, createListenerLogic as D, createSubscriptionLogic as E, Actor as F, matchesState as G, toObserver as H, InfiniteTransitionError as I, executeEffects as J, isBuiltInExecutableEffect as K, deliverEvent as L, runStep as M, stopActor as N, terminateActor as O, ProcessingStatus as P, createInitEvent as Q, createDeadLetterEffect as R, createCustomEffect as S, XSTATE_LOGIC_EFFECT_START as T, XSTATE_LOGIC_EFFECT_RESOLVE as U, XSTATE_LOGIC_EFFECT_REJECT as V, createEmitEffect as W, XSTATE_STOP_EFFECT as X, createSendToEffect as Y, XSTATE_INIT as Z, publishEmittedEvent as _, assertUnreservedSourceName as a, allocateChildId as a0, assertChildIdFree as a1, reserveChildId as a2, hasUnescapedDot as a3, STATE_DELIMITER as a4, mapValues as a5, createInvokeId as a6, getDelayedTransitions as a7, getCandidates as a8, evaluateCandidate as a9, initialMicrostep as aA, createStartEffect as aB, isStateId as aC, getPersistedSnapshot as aD, detachedScopes as aE, hasAmbientInspector as aF, getProperAncestors as aG, isRemoteActorRef as aH, getAllOwnEvents as aI, matchesEvent as aJ, getRootActorId as aK, RUNTIME_OPERATIONS as aL,
|
|
7105
|
+
export { resolveRegisteredActorSource as $, isMachineSnapshot as A, listenerLogic as B, subscriptionLogic as C, createListenerLogic as D, createSubscriptionLogic as E, Actor as F, matchesState as G, toObserver as H, InfiniteTransitionError as I, executeEffects as J, isBuiltInExecutableEffect as K, deliverEvent as L, runStep as M, stopActor as N, terminateActor as O, ProcessingStatus as P, createInitEvent as Q, createDeadLetterEffect as R, createCustomEffect as S, XSTATE_LOGIC_EFFECT_START as T, XSTATE_LOGIC_EFFECT_RESOLVE as U, XSTATE_LOGIC_EFFECT_REJECT as V, createEmitEffect as W, XSTATE_STOP_EFFECT as X, createSendToEffect as Y, XSTATE_INIT as Z, publishEmittedEvent as _, assertUnreservedSourceName as a, allocateChildId as a0, assertChildIdFree as a1, reserveChildId as a2, hasUnescapedDot as a3, STATE_DELIMITER as a4, mapValues as a5, createInvokeId as a6, getDelayedTransitions as a7, getCandidates as a8, evaluateCandidate as a9, initialMicrostep as aA, createStartEffect as aB, isStateId as aC, getPersistedSnapshot as aD, detachedScopes as aE, hasAmbientInspector as aF, getProperAncestors as aG, isRemoteActorRef as aH, getAllOwnEvents as aI, matchesEvent as aJ, getRootActorId as aK, RUNTIME_OPERATIONS as aL, createTimerEffect as aM, getSnapshotActorRef as aN, withExecutionOwner as aO, getTimerStart as aP, recordTimerStart as aQ, withSystemInspector as aR, adoptSystem as aS, withExecutionIdentity as aT, diagnoseActorOptions as aU, createRemoteActorRef as aV, createInvokeTimeoutEvent as aW, parseGeneratedActorId as aX, formatTransition as aa, NULL_EVENT as ab, toTransitionConfigArray as ac, matchesActorSession as ad, describeMachine as ae, formatRouteTransitions as af, resolveStateValue as ag, isInFinalState as ah, createInertActorScope as ai, setInertActorScopeSnapshot as aj, beginSpawnAllocation as ak, attachSnapshotActorRef as al, macrostep as am, isInertActorScope as an, setSnapshotActorRef as ao, cloneMachineSnapshot as ap, transitionNode as aq, XSTATE_TIMER as ar, getTransitionResult as as, hasEffect as at, createErrorPlatformEvent as au, withActorSelf as av, resolveActionsWithContext as aw, takeSpawnAllocationCounters as ax, mergeActorIdCounters as ay, createSpawnEffect as az, getStateNodes as b, isActorRefLike as c, diagnoseAuthorConfig as d, createMachineSnapshot as e, diagnoseSetupConfig as f, getAllStateNodes as g, createActor as h, isAtomicStateNode as i, encodeAddressSegment as j, getActorIdPrefix as k, finalizeTransitionResult as l, matchesEventDescriptor as m, getTimerKey as n, isSerializedActorRef as o, parseDelayToMilliseconds as p, readTimerKey as q, resolveInvokedActorLogic as r, systemLogicMetadata as s, toArray as t, XSTATE_STOP as u, createDoneActorEvent as v, createErrorActorEvent as w, xstateError as x, serializeTimerKey as y, matchesTimerKey as z };
|