xstate 6.0.0-alpha.43 → 6.0.0-alpha.45
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/{StateMachine-fcc48e11.cjs.js → StateMachine-2eecedfe.cjs.js} +2 -2
- package/dist/{StateMachine-1ea29688.development.esm.js → StateMachine-4bf86161.development.esm.js} +2 -2
- package/dist/{StateMachine-16d7ee93.development.cjs.js → StateMachine-5b915fb1.development.cjs.js} +2 -2
- package/dist/{StateMachine-b13b4b09.esm.js → StateMachine-d2fcf2e8.esm.js} +2 -2
- package/dist/{createActor-9538c7f8.cjs.js → createActor-48401456.cjs.js} +56 -4
- package/dist/{createActor-1a3a1d14.development.cjs.js → createActor-5c9fa117.development.cjs.js} +56 -4
- package/dist/{createActor-f9cc6590.development.esm.js → createActor-60ee6b5b.development.esm.js} +55 -5
- package/dist/{createActor-973c72ad.esm.js → createActor-641ab5f7.esm.js} +55 -5
- package/dist/declarations/src/createActor.d.ts +0 -1
- package/dist/declarations/src/createMachine.d.ts +3 -3
- package/dist/declarations/src/durable/index.d.ts +51 -16
- package/dist/declarations/src/inspectionAmbient.d.ts +1 -0
- package/dist/declarations/src/schema.types.d.ts +2 -0
- package/dist/declarations/src/setup.d.ts +33 -5
- package/dist/declarations/src/system.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +1 -0
- package/dist/declarations/src/types.v6.d.ts +15 -1
- package/dist/{effectDescriptor-f8c9337f.cjs.js → effectDescriptor-0cba79a1.development.cjs.js} +19 -1
- package/dist/{effectDescriptor-7d6f945a.development.cjs.js → effectDescriptor-adb27412.cjs.js} +19 -1
- package/dist/{effectDescriptor-416ca00a.esm.js → effectDescriptor-dffb91a8.esm.js} +19 -1
- package/dist/{effectDescriptor-e6730c9a.development.esm.js → effectDescriptor-fed26db6.development.esm.js} +19 -1
- package/dist/{index-f284cc7b.development.esm.js → index-158e7c37.development.esm.js} +1 -1
- package/dist/{index-e0ba4813.development.cjs.js → index-662114ff.development.cjs.js} +1 -1
- package/dist/{index-b478f443.esm.js → index-8f19f242.esm.js} +1 -1
- package/dist/{index-ba7170ba.cjs.js → index-fce4ea5c.cjs.js} +1 -1
- package/dist/xstate-actors.cjs.js +2 -2
- package/dist/xstate-actors.development.cjs.js +2 -2
- 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 +80 -20
- package/dist/xstate-durable.development.cjs.js +80 -20
- package/dist/xstate-durable.development.esm.js +80 -20
- package/dist/xstate-durable.esm.js +80 -20
- package/dist/xstate-durable.umd.min.js +1 -1
- package/dist/xstate-durable.umd.min.js.map +1 -1
- package/dist/xstate-graph.cjs.js +3 -3
- package/dist/xstate-graph.development.cjs.js +3 -3
- package/dist/xstate-graph.development.esm.js +3 -3
- package/dist/xstate-graph.esm.js +3 -3
- package/dist/xstate-graph.umd.min.js +1 -1
- package/dist/xstate-graph.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 +19 -5
- package/dist/xstate.development.cjs.js +19 -5
- package/dist/xstate.development.esm.js +21 -7
- package/dist/xstate.esm.js +21 -7
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
4
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var createActor = require('./createActor-48401456.cjs.js');
|
|
4
|
+
var dist_xstateActors = require('./index-fce4ea5c.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
7
7
|
return (src, options) => {
|
package/dist/{StateMachine-1ea29688.development.esm.js → StateMachine-4bf86161.development.esm.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q as allocateChildId, R as assertChildIdFree, S as reserveChildId, T as STATE_DELIMITER, U as mapValues, t as toArray, V as createInvokeId, W as getDelayedTransitions, Y as getEventDescriptorKey, Z as getCandidates, _ as evaluateCandidate, $ as formatTransition, a0 as NULL_EVENT, a1 as toTransitionConfigArray, a2 as createInvokeTimeoutEventId, a3 as matchesActorSession, a4 as formatRouteTransitions, a5 as resolveStateValue, a6 as getAllStateNodes, x as getStateNodes, a7 as createMachineSnapshot, a8 as isInFinalState, a9 as createInertActorScope, aa as setInertActorScopeSnapshot, a as beginSpawnAllocation, ab as attachSnapshotActorRef, ac as macrostep, ad as isInertActorScope, ae as setSnapshotActorRef, af as cloneMachineSnapshot, ag as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ah as getTransitionResult, ai as hasEffect, aj as createErrorPlatformEvent, ak as withActorSelf, r as resolveActionsWithContext, al as takeSpawnAllocationCounters, am as mergeActorIdCounters, K as createInitEvent, an as createSpawnEffect, ao as initialMicrostep, ap as toStatePath, aq as isStateId, ar as getStateNodeByPath, as as getPersistedSnapshot, at as createRemoteActorRef, au as resolveReferencedActor, av as createInvokeTimeoutEvent, aw as parseGeneratedActorId, ax as ACTOR_REF_TYPE, k as createActor } from './createActor-
|
|
2
|
-
import { g as assertValid } from './index-
|
|
1
|
+
import { Q as allocateChildId, R as assertChildIdFree, S as reserveChildId, T as STATE_DELIMITER, U as mapValues, t as toArray, V as createInvokeId, W as getDelayedTransitions, Y as getEventDescriptorKey, Z as getCandidates, _ as evaluateCandidate, $ as formatTransition, a0 as NULL_EVENT, a1 as toTransitionConfigArray, a2 as createInvokeTimeoutEventId, a3 as matchesActorSession, a4 as formatRouteTransitions, a5 as resolveStateValue, a6 as getAllStateNodes, x as getStateNodes, a7 as createMachineSnapshot, a8 as isInFinalState, a9 as createInertActorScope, aa as setInertActorScopeSnapshot, a as beginSpawnAllocation, ab as attachSnapshotActorRef, ac as macrostep, ad as isInertActorScope, ae as setSnapshotActorRef, af as cloneMachineSnapshot, ag as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ah as getTransitionResult, ai as hasEffect, aj as createErrorPlatformEvent, ak as withActorSelf, r as resolveActionsWithContext, al as takeSpawnAllocationCounters, am as mergeActorIdCounters, K as createInitEvent, an as createSpawnEffect, ao as initialMicrostep, ap as toStatePath, aq as isStateId, ar as getStateNodeByPath, as as getPersistedSnapshot, at as createRemoteActorRef, au as resolveReferencedActor, av as createInvokeTimeoutEvent, aw as parseGeneratedActorId, ax as ACTOR_REF_TYPE, k as createActor } from './createActor-60ee6b5b.development.esm.js';
|
|
2
|
+
import { g as assertValid } from './index-158e7c37.development.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
5
5
|
return (src, options) => {
|
package/dist/{StateMachine-16d7ee93.development.cjs.js → StateMachine-5b915fb1.development.cjs.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var createActor = require('./createActor-
|
|
4
|
-
var dist_xstateActors = require('./index-
|
|
3
|
+
var createActor = require('./createActor-5c9fa117.development.cjs.js');
|
|
4
|
+
var dist_xstateActors = require('./index-662114ff.development.cjs.js');
|
|
5
5
|
|
|
6
6
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
7
7
|
return (src, options) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q as allocateChildId, R as assertChildIdFree, S as reserveChildId, T as STATE_DELIMITER, U as mapValues, t as toArray, V as createInvokeId, W as getDelayedTransitions, Y as getEventDescriptorKey, Z as getCandidates, _ as evaluateCandidate, $ as formatTransition, a0 as NULL_EVENT, a1 as toTransitionConfigArray, a2 as createInvokeTimeoutEventId, a3 as matchesActorSession, a4 as formatRouteTransitions, a5 as resolveStateValue, a6 as getAllStateNodes, x as getStateNodes, a7 as createMachineSnapshot, a8 as isInFinalState, a9 as createInertActorScope, aa as setInertActorScopeSnapshot, a as beginSpawnAllocation, ab as attachSnapshotActorRef, ac as macrostep, ad as isInertActorScope, ae as setSnapshotActorRef, af as cloneMachineSnapshot, ag as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ah as getTransitionResult, ai as hasEffect, aj as createErrorPlatformEvent, ak as withActorSelf, r as resolveActionsWithContext, al as takeSpawnAllocationCounters, am as mergeActorIdCounters, K as createInitEvent, an as createSpawnEffect, ao as initialMicrostep, ap as toStatePath, aq as isStateId, ar as getStateNodeByPath, as as getPersistedSnapshot, at as createRemoteActorRef, au as resolveReferencedActor, av as createInvokeTimeoutEvent, aw as parseGeneratedActorId, ax as ACTOR_REF_TYPE, k as createActor } from './createActor-
|
|
2
|
-
import { g as assertValid } from './index-
|
|
1
|
+
import { Q as allocateChildId, R as assertChildIdFree, S as reserveChildId, T as STATE_DELIMITER, U as mapValues, t as toArray, V as createInvokeId, W as getDelayedTransitions, Y as getEventDescriptorKey, Z as getCandidates, _ as evaluateCandidate, $ as formatTransition, a0 as NULL_EVENT, a1 as toTransitionConfigArray, a2 as createInvokeTimeoutEventId, a3 as matchesActorSession, a4 as formatRouteTransitions, a5 as resolveStateValue, a6 as getAllStateNodes, x as getStateNodes, a7 as createMachineSnapshot, a8 as isInFinalState, a9 as createInertActorScope, aa as setInertActorScopeSnapshot, a as beginSpawnAllocation, ab as attachSnapshotActorRef, ac as macrostep, ad as isInertActorScope, ae as setSnapshotActorRef, af as cloneMachineSnapshot, ag as transitionNode, g as XSTATE_TIMER, m as matchesEventDescriptor, ah as getTransitionResult, ai as hasEffect, aj as createErrorPlatformEvent, ak as withActorSelf, r as resolveActionsWithContext, al as takeSpawnAllocationCounters, am as mergeActorIdCounters, K as createInitEvent, an as createSpawnEffect, ao as initialMicrostep, ap as toStatePath, aq as isStateId, ar as getStateNodeByPath, as as getPersistedSnapshot, at as createRemoteActorRef, au as resolveReferencedActor, av as createInvokeTimeoutEvent, aw as parseGeneratedActorId, ax as ACTOR_REF_TYPE, k as createActor } from './createActor-641ab5f7.esm.js';
|
|
2
|
+
import { g as assertValid } from './index-8f19f242.esm.js';
|
|
3
3
|
|
|
4
4
|
function createSpawner(actorScope, actors, spawnedChildren) {
|
|
5
5
|
return (src, options) => {
|
|
@@ -1266,6 +1266,45 @@ function parseDelayToMilliseconds(delay) {
|
|
|
1266
1266
|
return parseDurationToMilliseconds(delay);
|
|
1267
1267
|
}
|
|
1268
1268
|
|
|
1269
|
+
/**
|
|
1270
|
+
* The ambiently installed system inspector. Set for the duration of a durable
|
|
1271
|
+
* execution's transitions (`createDurable(..., { inspect })`), it makes the
|
|
1272
|
+
* pure-transition machinery observable: freshly constructed runtime systems
|
|
1273
|
+
* attach it, and snapshot systems created while it is set forward inspection
|
|
1274
|
+
* to their base system instead of stubbing it out.
|
|
1275
|
+
*/
|
|
1276
|
+
let ambientInspector;
|
|
1277
|
+
|
|
1278
|
+
/** @internal */
|
|
1279
|
+
function hasAmbientInspector() {
|
|
1280
|
+
return ambientInspector !== undefined;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
/** @internal */
|
|
1284
|
+
function getAmbientInspector() {
|
|
1285
|
+
return ambientInspector;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Runs `fn` with systems it creates wired to `inspect` from construction, so
|
|
1290
|
+
* creation-time inspection events (the root actor's own registration, actors
|
|
1291
|
+
* spawned during the first transition) are observed too.
|
|
1292
|
+
*
|
|
1293
|
+
* @internal
|
|
1294
|
+
*/
|
|
1295
|
+
function withSystemInspector(inspect, fn) {
|
|
1296
|
+
if (!inspect) {
|
|
1297
|
+
return fn();
|
|
1298
|
+
}
|
|
1299
|
+
const previous = ambientInspector;
|
|
1300
|
+
ambientInspector = inspect;
|
|
1301
|
+
try {
|
|
1302
|
+
return fn();
|
|
1303
|
+
} finally {
|
|
1304
|
+
ambientInspector = previous;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1269
1308
|
/** Snapshot-scoped actor identity and system view. @internal */
|
|
1270
1309
|
|
|
1271
1310
|
const snapshotActorRefs = new WeakMap();
|
|
@@ -1328,6 +1367,7 @@ function getSnapshotChildren(snapshot) {
|
|
|
1328
1367
|
* @internal
|
|
1329
1368
|
*/
|
|
1330
1369
|
function createSnapshotSystem(baseSystem, children, baseState) {
|
|
1370
|
+
const forwardInspection = hasAmbientInspector();
|
|
1331
1371
|
const registeredActors = copyRegisteredActors(baseSystem, baseState);
|
|
1332
1372
|
const keyedActors = new Map(baseState?.keyedActors ?? getKeyedActors(baseSystem));
|
|
1333
1373
|
const reverseKeyedActors = new WeakMap();
|
|
@@ -1366,10 +1406,13 @@ function createSnapshotSystem(baseSystem, children, baseState) {
|
|
|
1366
1406
|
},
|
|
1367
1407
|
get: registryKey => keyedActors.get(registryKey),
|
|
1368
1408
|
getAll: () => Object.fromEntries(keyedActors),
|
|
1369
|
-
// Pure transition resolution must not leak topology inspection events
|
|
1370
|
-
// a live runtime system.
|
|
1371
|
-
|
|
1372
|
-
|
|
1409
|
+
// Pure transition resolution must not leak topology inspection events
|
|
1410
|
+
// into a live runtime system — planning branches stay silent. The one
|
|
1411
|
+
// exception is a durable execution's own transitions (marked by the
|
|
1412
|
+
// ambient inspector at creation time): there the pure path IS the
|
|
1413
|
+
// execution, so inspection forwards to the base system's observers.
|
|
1414
|
+
_hasInspectionObservers: forwardInspection ? () => baseSystem._hasInspectionObservers?.() ?? false : () => false,
|
|
1415
|
+
_sendInspectionEvent: forwardInspection ? event => baseSystem._sendInspectionEvent(event) : () => {}
|
|
1373
1416
|
});
|
|
1374
1417
|
for (const [registryKey, actor] of keyedActors) {
|
|
1375
1418
|
if (!actor) {
|
|
@@ -4372,6 +4415,10 @@ class RuntimeSystem {
|
|
|
4372
4415
|
this._clock = options.clock;
|
|
4373
4416
|
this._logger = options.logger;
|
|
4374
4417
|
this.createActorRef = options.createActorRef;
|
|
4418
|
+
const ambientInspector = getAmbientInspector();
|
|
4419
|
+
if (ambientInspector) {
|
|
4420
|
+
this.inspect(ambientInspector);
|
|
4421
|
+
}
|
|
4375
4422
|
this._snapshot = {
|
|
4376
4423
|
_scheduledTimers: restoredSnapshot?.scheduler ?? emptyScheduledTimers,
|
|
4377
4424
|
// System-level counters are process-local backstops; per-actor
|
|
@@ -5072,6 +5119,9 @@ class Actor {
|
|
|
5072
5119
|
}
|
|
5073
5120
|
this._inspectTransition(this._snapshot, event);
|
|
5074
5121
|
}
|
|
5122
|
+
|
|
5123
|
+
/** @internal Emits the transition inspection event; used by the pure
|
|
5124
|
+
* `transition()` path for snapshots driven outside a live actor. */
|
|
5075
5125
|
_inspectTransition(snapshot, event) {
|
|
5076
5126
|
if (this.system._hasInspectionObservers?.() ?? true) {
|
|
5077
5127
|
this.system._sendInspectionEvent({
|
|
@@ -5672,6 +5722,7 @@ exports.getSnapshotActorRef = getSnapshotActorRef;
|
|
|
5672
5722
|
exports.getStateNodeByPath = getStateNodeByPath;
|
|
5673
5723
|
exports.getStateNodes = getStateNodes;
|
|
5674
5724
|
exports.getTransitionResult = getTransitionResult;
|
|
5725
|
+
exports.hasAmbientInspector = hasAmbientInspector;
|
|
5675
5726
|
exports.hasEffect = hasEffect;
|
|
5676
5727
|
exports.initialMicrostep = initialMicrostep;
|
|
5677
5728
|
exports.isAtomicStateNode = isAtomicStateNode;
|
|
@@ -5712,3 +5763,4 @@ exports.transitionNode = transitionNode;
|
|
|
5712
5763
|
exports.withActorScope = withActorScope;
|
|
5713
5764
|
exports.withActorSelf = withActorSelf;
|
|
5714
5765
|
exports.withExecutionIdentity = withExecutionIdentity;
|
|
5766
|
+
exports.withSystemInspector = withSystemInspector;
|
package/dist/{createActor-1a3a1d14.development.cjs.js → createActor-5c9fa117.development.cjs.js}
RENAMED
|
@@ -1274,6 +1274,45 @@ function parseDelayToMilliseconds(delay) {
|
|
|
1274
1274
|
return parseDurationToMilliseconds(delay);
|
|
1275
1275
|
}
|
|
1276
1276
|
|
|
1277
|
+
/**
|
|
1278
|
+
* The ambiently installed system inspector. Set for the duration of a durable
|
|
1279
|
+
* execution's transitions (`createDurable(..., { inspect })`), it makes the
|
|
1280
|
+
* pure-transition machinery observable: freshly constructed runtime systems
|
|
1281
|
+
* attach it, and snapshot systems created while it is set forward inspection
|
|
1282
|
+
* to their base system instead of stubbing it out.
|
|
1283
|
+
*/
|
|
1284
|
+
let ambientInspector;
|
|
1285
|
+
|
|
1286
|
+
/** @internal */
|
|
1287
|
+
function hasAmbientInspector() {
|
|
1288
|
+
return ambientInspector !== undefined;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
/** @internal */
|
|
1292
|
+
function getAmbientInspector() {
|
|
1293
|
+
return ambientInspector;
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Runs `fn` with systems it creates wired to `inspect` from construction, so
|
|
1298
|
+
* creation-time inspection events (the root actor's own registration, actors
|
|
1299
|
+
* spawned during the first transition) are observed too.
|
|
1300
|
+
*
|
|
1301
|
+
* @internal
|
|
1302
|
+
*/
|
|
1303
|
+
function withSystemInspector(inspect, fn) {
|
|
1304
|
+
if (!inspect) {
|
|
1305
|
+
return fn();
|
|
1306
|
+
}
|
|
1307
|
+
const previous = ambientInspector;
|
|
1308
|
+
ambientInspector = inspect;
|
|
1309
|
+
try {
|
|
1310
|
+
return fn();
|
|
1311
|
+
} finally {
|
|
1312
|
+
ambientInspector = previous;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1277
1316
|
/** Snapshot-scoped actor identity and system view. @internal */
|
|
1278
1317
|
|
|
1279
1318
|
const snapshotActorRefs = new WeakMap();
|
|
@@ -1336,6 +1375,7 @@ function getSnapshotChildren(snapshot) {
|
|
|
1336
1375
|
* @internal
|
|
1337
1376
|
*/
|
|
1338
1377
|
function createSnapshotSystem(baseSystem, children, baseState) {
|
|
1378
|
+
const forwardInspection = hasAmbientInspector();
|
|
1339
1379
|
const registeredActors = copyRegisteredActors(baseSystem, baseState);
|
|
1340
1380
|
const keyedActors = new Map(baseState?.keyedActors ?? getKeyedActors(baseSystem));
|
|
1341
1381
|
const reverseKeyedActors = new WeakMap();
|
|
@@ -1374,10 +1414,13 @@ function createSnapshotSystem(baseSystem, children, baseState) {
|
|
|
1374
1414
|
},
|
|
1375
1415
|
get: registryKey => keyedActors.get(registryKey),
|
|
1376
1416
|
getAll: () => Object.fromEntries(keyedActors),
|
|
1377
|
-
// Pure transition resolution must not leak topology inspection events
|
|
1378
|
-
// a live runtime system.
|
|
1379
|
-
|
|
1380
|
-
|
|
1417
|
+
// Pure transition resolution must not leak topology inspection events
|
|
1418
|
+
// into a live runtime system — planning branches stay silent. The one
|
|
1419
|
+
// exception is a durable execution's own transitions (marked by the
|
|
1420
|
+
// ambient inspector at creation time): there the pure path IS the
|
|
1421
|
+
// execution, so inspection forwards to the base system's observers.
|
|
1422
|
+
_hasInspectionObservers: forwardInspection ? () => baseSystem._hasInspectionObservers?.() ?? false : () => false,
|
|
1423
|
+
_sendInspectionEvent: forwardInspection ? event => baseSystem._sendInspectionEvent(event) : () => {}
|
|
1381
1424
|
});
|
|
1382
1425
|
for (const [registryKey, actor] of keyedActors) {
|
|
1383
1426
|
if (!actor) {
|
|
@@ -4405,6 +4448,10 @@ class RuntimeSystem {
|
|
|
4405
4448
|
this._clock = options.clock;
|
|
4406
4449
|
this._logger = options.logger;
|
|
4407
4450
|
this.createActorRef = options.createActorRef;
|
|
4451
|
+
const ambientInspector = getAmbientInspector();
|
|
4452
|
+
if (ambientInspector) {
|
|
4453
|
+
this.inspect(ambientInspector);
|
|
4454
|
+
}
|
|
4408
4455
|
this._snapshot = {
|
|
4409
4456
|
_scheduledTimers: restoredSnapshot?.scheduler ?? emptyScheduledTimers,
|
|
4410
4457
|
// System-level counters are process-local backstops; per-actor
|
|
@@ -5108,6 +5155,9 @@ class Actor {
|
|
|
5108
5155
|
}
|
|
5109
5156
|
this._inspectTransition(this._snapshot, event);
|
|
5110
5157
|
}
|
|
5158
|
+
|
|
5159
|
+
/** @internal Emits the transition inspection event; used by the pure
|
|
5160
|
+
* `transition()` path for snapshots driven outside a live actor. */
|
|
5111
5161
|
_inspectTransition(snapshot, event) {
|
|
5112
5162
|
if (this.system._hasInspectionObservers?.() ?? true) {
|
|
5113
5163
|
this.system._sendInspectionEvent({
|
|
@@ -5714,6 +5764,7 @@ exports.getSnapshotActorRef = getSnapshotActorRef;
|
|
|
5714
5764
|
exports.getStateNodeByPath = getStateNodeByPath;
|
|
5715
5765
|
exports.getStateNodes = getStateNodes;
|
|
5716
5766
|
exports.getTransitionResult = getTransitionResult;
|
|
5767
|
+
exports.hasAmbientInspector = hasAmbientInspector;
|
|
5717
5768
|
exports.hasEffect = hasEffect;
|
|
5718
5769
|
exports.initialMicrostep = initialMicrostep;
|
|
5719
5770
|
exports.isAtomicStateNode = isAtomicStateNode;
|
|
@@ -5754,3 +5805,4 @@ exports.transitionNode = transitionNode;
|
|
|
5754
5805
|
exports.withActorScope = withActorScope;
|
|
5755
5806
|
exports.withActorSelf = withActorSelf;
|
|
5756
5807
|
exports.withExecutionIdentity = withExecutionIdentity;
|
|
5808
|
+
exports.withSystemInspector = withSystemInspector;
|
package/dist/{createActor-f9cc6590.development.esm.js → createActor-60ee6b5b.development.esm.js}
RENAMED
|
@@ -1272,6 +1272,45 @@ function parseDelayToMilliseconds(delay) {
|
|
|
1272
1272
|
return parseDurationToMilliseconds(delay);
|
|
1273
1273
|
}
|
|
1274
1274
|
|
|
1275
|
+
/**
|
|
1276
|
+
* The ambiently installed system inspector. Set for the duration of a durable
|
|
1277
|
+
* execution's transitions (`createDurable(..., { inspect })`), it makes the
|
|
1278
|
+
* pure-transition machinery observable: freshly constructed runtime systems
|
|
1279
|
+
* attach it, and snapshot systems created while it is set forward inspection
|
|
1280
|
+
* to their base system instead of stubbing it out.
|
|
1281
|
+
*/
|
|
1282
|
+
let ambientInspector;
|
|
1283
|
+
|
|
1284
|
+
/** @internal */
|
|
1285
|
+
function hasAmbientInspector() {
|
|
1286
|
+
return ambientInspector !== undefined;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
/** @internal */
|
|
1290
|
+
function getAmbientInspector() {
|
|
1291
|
+
return ambientInspector;
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Runs `fn` with systems it creates wired to `inspect` from construction, so
|
|
1296
|
+
* creation-time inspection events (the root actor's own registration, actors
|
|
1297
|
+
* spawned during the first transition) are observed too.
|
|
1298
|
+
*
|
|
1299
|
+
* @internal
|
|
1300
|
+
*/
|
|
1301
|
+
function withSystemInspector(inspect, fn) {
|
|
1302
|
+
if (!inspect) {
|
|
1303
|
+
return fn();
|
|
1304
|
+
}
|
|
1305
|
+
const previous = ambientInspector;
|
|
1306
|
+
ambientInspector = inspect;
|
|
1307
|
+
try {
|
|
1308
|
+
return fn();
|
|
1309
|
+
} finally {
|
|
1310
|
+
ambientInspector = previous;
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1275
1314
|
/** Snapshot-scoped actor identity and system view. @internal */
|
|
1276
1315
|
|
|
1277
1316
|
const snapshotActorRefs = new WeakMap();
|
|
@@ -1334,6 +1373,7 @@ function getSnapshotChildren(snapshot) {
|
|
|
1334
1373
|
* @internal
|
|
1335
1374
|
*/
|
|
1336
1375
|
function createSnapshotSystem(baseSystem, children, baseState) {
|
|
1376
|
+
const forwardInspection = hasAmbientInspector();
|
|
1337
1377
|
const registeredActors = copyRegisteredActors(baseSystem, baseState);
|
|
1338
1378
|
const keyedActors = new Map(baseState?.keyedActors ?? getKeyedActors(baseSystem));
|
|
1339
1379
|
const reverseKeyedActors = new WeakMap();
|
|
@@ -1372,10 +1412,13 @@ function createSnapshotSystem(baseSystem, children, baseState) {
|
|
|
1372
1412
|
},
|
|
1373
1413
|
get: registryKey => keyedActors.get(registryKey),
|
|
1374
1414
|
getAll: () => Object.fromEntries(keyedActors),
|
|
1375
|
-
// Pure transition resolution must not leak topology inspection events
|
|
1376
|
-
// a live runtime system.
|
|
1377
|
-
|
|
1378
|
-
|
|
1415
|
+
// Pure transition resolution must not leak topology inspection events
|
|
1416
|
+
// into a live runtime system — planning branches stay silent. The one
|
|
1417
|
+
// exception is a durable execution's own transitions (marked by the
|
|
1418
|
+
// ambient inspector at creation time): there the pure path IS the
|
|
1419
|
+
// execution, so inspection forwards to the base system's observers.
|
|
1420
|
+
_hasInspectionObservers: forwardInspection ? () => baseSystem._hasInspectionObservers?.() ?? false : () => false,
|
|
1421
|
+
_sendInspectionEvent: forwardInspection ? event => baseSystem._sendInspectionEvent(event) : () => {}
|
|
1379
1422
|
});
|
|
1380
1423
|
for (const [registryKey, actor] of keyedActors) {
|
|
1381
1424
|
if (!actor) {
|
|
@@ -4403,6 +4446,10 @@ class RuntimeSystem {
|
|
|
4403
4446
|
this._clock = options.clock;
|
|
4404
4447
|
this._logger = options.logger;
|
|
4405
4448
|
this.createActorRef = options.createActorRef;
|
|
4449
|
+
const ambientInspector = getAmbientInspector();
|
|
4450
|
+
if (ambientInspector) {
|
|
4451
|
+
this.inspect(ambientInspector);
|
|
4452
|
+
}
|
|
4406
4453
|
this._snapshot = {
|
|
4407
4454
|
_scheduledTimers: restoredSnapshot?.scheduler ?? emptyScheduledTimers,
|
|
4408
4455
|
// System-level counters are process-local backstops; per-actor
|
|
@@ -5106,6 +5153,9 @@ class Actor {
|
|
|
5106
5153
|
}
|
|
5107
5154
|
this._inspectTransition(this._snapshot, event);
|
|
5108
5155
|
}
|
|
5156
|
+
|
|
5157
|
+
/** @internal Emits the transition inspection event; used by the pure
|
|
5158
|
+
* `transition()` path for snapshots driven outside a live actor. */
|
|
5109
5159
|
_inspectTransition(snapshot, event) {
|
|
5110
5160
|
if (this.system._hasInspectionObservers?.() ?? true) {
|
|
5111
5161
|
this.system._sendInspectionEvent({
|
|
@@ -5654,4 +5704,4 @@ function createActor(logic, options) {
|
|
|
5654
5704
|
return new Actor(logic, options);
|
|
5655
5705
|
}
|
|
5656
5706
|
|
|
5657
|
-
export { formatTransition as $, Actor as A, checkStateIn as B, pathToStateValue as C, toObserver as D, executeEffects as E, isBuiltInExecutableAction as F, deliverEvent as G, runStep as H, stopActor as I, terminateActor as J, createInitEvent as K, createCustomEffect as L, XSTATE_LOGIC_EFFECT_START as M, XSTATE_LOGIC_EFFECT_RESOLVE as N, XSTATE_LOGIC_EFFECT_REJECT as O, createEmitEffect as P, allocateChildId as Q, assertChildIdFree as R, reserveChildId as S, STATE_DELIMITER as T, mapValues as U, createInvokeId as V, getDelayedTransitions as W, XSTATE_INIT as X, getEventDescriptorKey as Y, getCandidates as Z, evaluateCandidate as _, beginSpawnAllocation as a, NULL_EVENT as a0, toTransitionConfigArray as a1, createInvokeTimeoutEventId as a2, matchesActorSession as a3, formatRouteTransitions as a4, resolveStateValue as a5, getAllStateNodes as a6, createMachineSnapshot as a7, isInFinalState as a8, createInertActorScope as a9,
|
|
5707
|
+
export { formatTransition as $, Actor as A, checkStateIn as B, pathToStateValue as C, toObserver as D, executeEffects as E, isBuiltInExecutableAction as F, deliverEvent as G, runStep as H, stopActor as I, terminateActor as J, createInitEvent as K, createCustomEffect as L, XSTATE_LOGIC_EFFECT_START as M, XSTATE_LOGIC_EFFECT_RESOLVE as N, XSTATE_LOGIC_EFFECT_REJECT as O, createEmitEffect as P, allocateChildId as Q, assertChildIdFree as R, reserveChildId as S, STATE_DELIMITER as T, mapValues as U, createInvokeId as V, getDelayedTransitions as W, XSTATE_INIT as X, getEventDescriptorKey as Y, getCandidates as Z, evaluateCandidate as _, beginSpawnAllocation as a, NULL_EVENT as a0, toTransitionConfigArray as a1, createInvokeTimeoutEventId as a2, matchesActorSession as a3, formatRouteTransitions as a4, resolveStateValue as a5, getAllStateNodes as a6, createMachineSnapshot as a7, isInFinalState as a8, createInertActorScope as a9, isRemoteActorRef as aA, getActorIdPrefix as aB, getAllOwnEvents as aC, matchesEvent as aD, encodeAddressSegment as aE, getRootActorId as aF, RUNTIME_OPERATIONS as aG, withSystemInspector as aH, getSnapshotActorRef as aI, withExecutionIdentity as aJ, setInertActorScopeSnapshot as aa, attachSnapshotActorRef as ab, macrostep as ac, isInertActorScope as ad, setSnapshotActorRef as ae, cloneMachineSnapshot as af, transitionNode as ag, getTransitionResult as ah, hasEffect as ai, createErrorPlatformEvent as aj, withActorSelf as ak, takeSpawnAllocationCounters as al, mergeActorIdCounters as am, createSpawnEffect as an, initialMicrostep as ao, toStatePath as ap, isStateId as aq, getStateNodeByPath as ar, getPersistedSnapshot as as, createRemoteActorRef as at, resolveReferencedActor as au, createInvokeTimeoutEvent as av, parseGeneratedActorId as aw, ACTOR_REF_TYPE as ax, hasAmbientInspector as ay, getProperAncestors as az, builtInActions as b, createTransitionEnqueue as c, deriveDeferredStarts as d, XSTATE_STOP as e, finalizeTransitionResult as f, XSTATE_TIMER as g, createSendToEffect as h, isLazyActorScope as i, isAtomicStateNode as j, createActor as k, createListenerLogic as l, matchesEventDescriptor as m, createSubscriptionLogic as n, listenerLogic as o, parseDelayToMilliseconds as p, getInitialSnapshot as q, resolveActionsWithContext as r, subscriptionLogic as s, toArray as t, getNextSnapshot as u, isMachineSnapshot as v, withActorScope as w, getStateNodes as x, getAllOwnEventDescriptors as y, matchesState as z };
|
|
@@ -1264,6 +1264,45 @@ function parseDelayToMilliseconds(delay) {
|
|
|
1264
1264
|
return parseDurationToMilliseconds(delay);
|
|
1265
1265
|
}
|
|
1266
1266
|
|
|
1267
|
+
/**
|
|
1268
|
+
* The ambiently installed system inspector. Set for the duration of a durable
|
|
1269
|
+
* execution's transitions (`createDurable(..., { inspect })`), it makes the
|
|
1270
|
+
* pure-transition machinery observable: freshly constructed runtime systems
|
|
1271
|
+
* attach it, and snapshot systems created while it is set forward inspection
|
|
1272
|
+
* to their base system instead of stubbing it out.
|
|
1273
|
+
*/
|
|
1274
|
+
let ambientInspector;
|
|
1275
|
+
|
|
1276
|
+
/** @internal */
|
|
1277
|
+
function hasAmbientInspector() {
|
|
1278
|
+
return ambientInspector !== undefined;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/** @internal */
|
|
1282
|
+
function getAmbientInspector() {
|
|
1283
|
+
return ambientInspector;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
/**
|
|
1287
|
+
* Runs `fn` with systems it creates wired to `inspect` from construction, so
|
|
1288
|
+
* creation-time inspection events (the root actor's own registration, actors
|
|
1289
|
+
* spawned during the first transition) are observed too.
|
|
1290
|
+
*
|
|
1291
|
+
* @internal
|
|
1292
|
+
*/
|
|
1293
|
+
function withSystemInspector(inspect, fn) {
|
|
1294
|
+
if (!inspect) {
|
|
1295
|
+
return fn();
|
|
1296
|
+
}
|
|
1297
|
+
const previous = ambientInspector;
|
|
1298
|
+
ambientInspector = inspect;
|
|
1299
|
+
try {
|
|
1300
|
+
return fn();
|
|
1301
|
+
} finally {
|
|
1302
|
+
ambientInspector = previous;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1267
1306
|
/** Snapshot-scoped actor identity and system view. @internal */
|
|
1268
1307
|
|
|
1269
1308
|
const snapshotActorRefs = new WeakMap();
|
|
@@ -1326,6 +1365,7 @@ function getSnapshotChildren(snapshot) {
|
|
|
1326
1365
|
* @internal
|
|
1327
1366
|
*/
|
|
1328
1367
|
function createSnapshotSystem(baseSystem, children, baseState) {
|
|
1368
|
+
const forwardInspection = hasAmbientInspector();
|
|
1329
1369
|
const registeredActors = copyRegisteredActors(baseSystem, baseState);
|
|
1330
1370
|
const keyedActors = new Map(baseState?.keyedActors ?? getKeyedActors(baseSystem));
|
|
1331
1371
|
const reverseKeyedActors = new WeakMap();
|
|
@@ -1364,10 +1404,13 @@ function createSnapshotSystem(baseSystem, children, baseState) {
|
|
|
1364
1404
|
},
|
|
1365
1405
|
get: registryKey => keyedActors.get(registryKey),
|
|
1366
1406
|
getAll: () => Object.fromEntries(keyedActors),
|
|
1367
|
-
// Pure transition resolution must not leak topology inspection events
|
|
1368
|
-
// a live runtime system.
|
|
1369
|
-
|
|
1370
|
-
|
|
1407
|
+
// Pure transition resolution must not leak topology inspection events
|
|
1408
|
+
// into a live runtime system — planning branches stay silent. The one
|
|
1409
|
+
// exception is a durable execution's own transitions (marked by the
|
|
1410
|
+
// ambient inspector at creation time): there the pure path IS the
|
|
1411
|
+
// execution, so inspection forwards to the base system's observers.
|
|
1412
|
+
_hasInspectionObservers: forwardInspection ? () => baseSystem._hasInspectionObservers?.() ?? false : () => false,
|
|
1413
|
+
_sendInspectionEvent: forwardInspection ? event => baseSystem._sendInspectionEvent(event) : () => {}
|
|
1371
1414
|
});
|
|
1372
1415
|
for (const [registryKey, actor] of keyedActors) {
|
|
1373
1416
|
if (!actor) {
|
|
@@ -4370,6 +4413,10 @@ class RuntimeSystem {
|
|
|
4370
4413
|
this._clock = options.clock;
|
|
4371
4414
|
this._logger = options.logger;
|
|
4372
4415
|
this.createActorRef = options.createActorRef;
|
|
4416
|
+
const ambientInspector = getAmbientInspector();
|
|
4417
|
+
if (ambientInspector) {
|
|
4418
|
+
this.inspect(ambientInspector);
|
|
4419
|
+
}
|
|
4373
4420
|
this._snapshot = {
|
|
4374
4421
|
_scheduledTimers: restoredSnapshot?.scheduler ?? emptyScheduledTimers,
|
|
4375
4422
|
// System-level counters are process-local backstops; per-actor
|
|
@@ -5070,6 +5117,9 @@ class Actor {
|
|
|
5070
5117
|
}
|
|
5071
5118
|
this._inspectTransition(this._snapshot, event);
|
|
5072
5119
|
}
|
|
5120
|
+
|
|
5121
|
+
/** @internal Emits the transition inspection event; used by the pure
|
|
5122
|
+
* `transition()` path for snapshots driven outside a live actor. */
|
|
5073
5123
|
_inspectTransition(snapshot, event) {
|
|
5074
5124
|
if (this.system._hasInspectionObservers?.() ?? true) {
|
|
5075
5125
|
this.system._sendInspectionEvent({
|
|
@@ -5612,4 +5662,4 @@ function createActor(logic, options) {
|
|
|
5612
5662
|
return new Actor(logic, options);
|
|
5613
5663
|
}
|
|
5614
5664
|
|
|
5615
|
-
export { formatTransition as $, Actor as A, checkStateIn as B, pathToStateValue as C, toObserver as D, executeEffects as E, isBuiltInExecutableAction as F, deliverEvent as G, runStep as H, stopActor as I, terminateActor as J, createInitEvent as K, createCustomEffect as L, XSTATE_LOGIC_EFFECT_START as M, XSTATE_LOGIC_EFFECT_RESOLVE as N, XSTATE_LOGIC_EFFECT_REJECT as O, createEmitEffect as P, allocateChildId as Q, assertChildIdFree as R, reserveChildId as S, STATE_DELIMITER as T, mapValues as U, createInvokeId as V, getDelayedTransitions as W, XSTATE_INIT as X, getEventDescriptorKey as Y, getCandidates as Z, evaluateCandidate as _, beginSpawnAllocation as a, NULL_EVENT as a0, toTransitionConfigArray as a1, createInvokeTimeoutEventId as a2, matchesActorSession as a3, formatRouteTransitions as a4, resolveStateValue as a5, getAllStateNodes as a6, createMachineSnapshot as a7, isInFinalState as a8, createInertActorScope as a9,
|
|
5665
|
+
export { formatTransition as $, Actor as A, checkStateIn as B, pathToStateValue as C, toObserver as D, executeEffects as E, isBuiltInExecutableAction as F, deliverEvent as G, runStep as H, stopActor as I, terminateActor as J, createInitEvent as K, createCustomEffect as L, XSTATE_LOGIC_EFFECT_START as M, XSTATE_LOGIC_EFFECT_RESOLVE as N, XSTATE_LOGIC_EFFECT_REJECT as O, createEmitEffect as P, allocateChildId as Q, assertChildIdFree as R, reserveChildId as S, STATE_DELIMITER as T, mapValues as U, createInvokeId as V, getDelayedTransitions as W, XSTATE_INIT as X, getEventDescriptorKey as Y, getCandidates as Z, evaluateCandidate as _, beginSpawnAllocation as a, NULL_EVENT as a0, toTransitionConfigArray as a1, createInvokeTimeoutEventId as a2, matchesActorSession as a3, formatRouteTransitions as a4, resolveStateValue as a5, getAllStateNodes as a6, createMachineSnapshot as a7, isInFinalState as a8, createInertActorScope as a9, isRemoteActorRef as aA, getActorIdPrefix as aB, getAllOwnEvents as aC, matchesEvent as aD, encodeAddressSegment as aE, getRootActorId as aF, RUNTIME_OPERATIONS as aG, withSystemInspector as aH, getSnapshotActorRef as aI, withExecutionIdentity as aJ, setInertActorScopeSnapshot as aa, attachSnapshotActorRef as ab, macrostep as ac, isInertActorScope as ad, setSnapshotActorRef as ae, cloneMachineSnapshot as af, transitionNode as ag, getTransitionResult as ah, hasEffect as ai, createErrorPlatformEvent as aj, withActorSelf as ak, takeSpawnAllocationCounters as al, mergeActorIdCounters as am, createSpawnEffect as an, initialMicrostep as ao, toStatePath as ap, isStateId as aq, getStateNodeByPath as ar, getPersistedSnapshot as as, createRemoteActorRef as at, resolveReferencedActor as au, createInvokeTimeoutEvent as av, parseGeneratedActorId as aw, ACTOR_REF_TYPE as ax, hasAmbientInspector as ay, getProperAncestors as az, builtInActions as b, createTransitionEnqueue as c, deriveDeferredStarts as d, XSTATE_STOP as e, finalizeTransitionResult as f, XSTATE_TIMER as g, createSendToEffect as h, isLazyActorScope as i, isAtomicStateNode as j, createActor as k, createListenerLogic as l, matchesEventDescriptor as m, createSubscriptionLogic as n, listenerLogic as o, parseDelayToMilliseconds as p, getInitialSnapshot as q, resolveActionsWithContext as r, subscriptionLogic as s, toArray as t, getNextSnapshot as u, isMachineSnapshot as v, withActorScope as w, getStateNodes as x, getAllOwnEventDescriptors as y, matchesState as z };
|
|
@@ -89,7 +89,6 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
|
|
|
89
89
|
private _tryHandleExecutionError;
|
|
90
90
|
private _next;
|
|
91
91
|
private update;
|
|
92
|
-
private _inspectTransition;
|
|
93
92
|
private _flushInitialEffects;
|
|
94
93
|
/**
|
|
95
94
|
* Subscribe an observer to an actor’s snapshot values.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from "./schema.types.js";
|
|
2
2
|
import { StateMachine } from "./StateMachine.js";
|
|
3
3
|
import { AnyActorRef, EventObject, AnyEventObject, Cast, MachineContext, ProvidedActor, StateValueFromStateSchema, ToChildren, MetaObject, StateSchema, DoNotInfer, RoutableStateId, Compute } from "./types.js";
|
|
4
|
-
import { Sources, DelayMapFromNames, InferChildren, InferOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, ValidateHistoryDefaults, ValidateStateTargets, ValidateTopLevelFinalOutputs, WidenLiterals, WithDefault } from "./types.v6.js";
|
|
4
|
+
import { Sources, DelayMapFromNames, InferChildren, InferOutput, SchemaOrConfigOutput, InferEvents, InferInternalEvents, Next_MachineConfig, Next_StateNodeConfig, ValidateDelayReferences, ValidateHistoryDefaults, ValidateStateTargets, ValidateTopLevelFinalOutputs, WidenLiterals, WithDefault } from "./types.v6.js";
|
|
5
5
|
type MergeChildren<TChildren extends Record<string, AnyActorRef | undefined>, TActor extends ProvidedActor> = [keyof TChildren] extends [never] ? Compute<ToChildren<TActor>> : Compute<TChildren>;
|
|
6
6
|
type MachineIdentity<TConfig> = {
|
|
7
7
|
readonly id: TConfig extends {
|
|
@@ -61,7 +61,7 @@ export declare function createMachine<TContextSchema extends StandardSchemaV1, c
|
|
|
61
61
|
} & ValidateTopLevelFinalOutputs<TSS, InferOutput<TContextSchema, MachineContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>): StateMachine<InferOutput<TContextSchema, MachineContext>, (InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>) | ([RoutableStateId<TSS>] extends [never] ? never : {
|
|
62
62
|
type: 'xstate.route';
|
|
63
63
|
to: RoutableStateId<TSS>;
|
|
64
|
-
}), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<TSS>, TTag & string, TInput,
|
|
64
|
+
}), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<TSS>, TTag & string, TInput, SchemaOrConfigOutput<TOutputSchema, TSS>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
|
|
65
65
|
TSS, // TStateSchema
|
|
66
66
|
TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>, InferInternalEvents<TInternalEventSchemaMap>> & {
|
|
67
67
|
states: TSS;
|
|
@@ -79,7 +79,7 @@ export declare function createMachine<TContext extends MachineContext = never, c
|
|
|
79
79
|
} & ValidateTopLevelFinalOutputs<TSS, WidenLiterals<TContext>, InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>>): StateMachine<WidenLiterals<TContext>, (InferEvents<TEventSchemaMap> | InferInternalEvents<TInternalEventSchemaMap>) | ([RoutableStateId<TSS>] extends [never] ? never : {
|
|
80
80
|
type: 'xstate.route';
|
|
81
81
|
to: RoutableStateId<TSS>;
|
|
82
|
-
}), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<TSS>, TTag & string, TInput,
|
|
82
|
+
}), Cast<MergeChildren<InferChildren<TChildrenSchemaMap>, TActor>, Record<string, AnyActorRef | undefined>>, StateValueFromStateSchema<TSS>, TTag & string, TInput, SchemaOrConfigOutput<TOutputSchema, TSS>, WithDefault<InferEvents<TEmittedSchemaMap>, AnyEventObject>, InferOutput<TMetaSchema, MetaObject>, // TMeta
|
|
83
83
|
TSS, // TStateSchema
|
|
84
84
|
TActionMap, TActorMap, TGuardMap, DelayMapFromNames<TDelays, TDelayMap>, InferInternalEvents<TInternalEventSchemaMap>> & {
|
|
85
85
|
states: TSS;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type EffectDescriptor } from "../effectDescriptor.js";
|
|
2
2
|
import { type ActorSystemRuntime } from "../system.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { InspectionEvent } from "../inspection.js";
|
|
4
|
+
import type { AnyActor, AnyActorLogic, AnyEventObject, CustomExecutableActionObject, EventFromLogic, ExecutableActionObjectFromLogic, InputFrom, OutputFrom, Snapshot, SnapshotFrom } from "../types.js";
|
|
4
5
|
export interface DurableEffectMetadata {
|
|
5
6
|
/** Stable within one durable execution. */
|
|
6
7
|
id: string;
|
|
@@ -42,10 +43,11 @@ export interface DurableEffect<TEffect> extends DurableEffectMetadata {
|
|
|
42
43
|
* operations keep their default local behavior.
|
|
43
44
|
*
|
|
44
45
|
* Events addressed to this execution's root actor do not reach `sendEvent`
|
|
45
|
-
* during `executeEffects`: the execution captures them and
|
|
46
|
-
*
|
|
47
|
-
* the loop is parked, a root-addressed event reaches
|
|
48
|
-
* other target, so the host enqueues it in its own
|
|
46
|
+
* during `executeEffects`: the execution captures and retains them, and the
|
|
47
|
+
* execution's `waitForEvent()` hands them out before deferring to this
|
|
48
|
+
* adapter. While the loop is parked, a root-addressed event reaches
|
|
49
|
+
* `sendEvent` like any other target, so the host enqueues it in its own
|
|
50
|
+
* mailbox.
|
|
49
51
|
*/
|
|
50
52
|
export interface DurableExecutionAdapter<TLogic extends AnyActorLogic> extends Partial<ActorSystemRuntime> {
|
|
51
53
|
/**
|
|
@@ -62,8 +64,14 @@ export interface DurableExecutionAdapter<TLogic extends AnyActorLogic> extends P
|
|
|
62
64
|
* source, input, event or target data beyond the runtime method arguments.
|
|
63
65
|
*/
|
|
64
66
|
runtime?(metadata: DurableEffectMetadata, effect: ExecutableActionObjectFromLogic<TLogic>): Partial<ActorSystemRuntime>;
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Waits durably for the next event addressed to this execution. Typed to
|
|
69
|
+
* also accept plain event objects: an adapter written against
|
|
70
|
+
* `AnyActorLogic` (a generic host library) cannot produce
|
|
71
|
+
* `EventFromLogic<TLogic>`, and the events a host relays are runtime data
|
|
72
|
+
* anyway — the execution narrows at its own boundary.
|
|
73
|
+
*/
|
|
74
|
+
waitForEvent(metadata: DurableWaitMetadata): EventFromLogic<TLogic> | AnyEventObject | PromiseLike<EventFromLogic<TLogic> | AnyEventObject>;
|
|
67
75
|
/** Index assigned to the first transition. Defaults to `0`. */
|
|
68
76
|
transitionIndex?: number;
|
|
69
77
|
/**
|
|
@@ -83,6 +91,13 @@ export declare class DurableExecutionCancelledError extends Error {
|
|
|
83
91
|
export declare class DurableExecutionResumeError extends Error {
|
|
84
92
|
constructor();
|
|
85
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* The snapshot type a durable execution hands back: the logic's own snapshot,
|
|
96
|
+
* intersected with the base `Snapshot` union so the `status`/`output`/`error`
|
|
97
|
+
* discriminant stays visible even when `TLogic` is an unresolved type
|
|
98
|
+
* parameter (a generic host library), where `SnapshotFrom` alone is opaque.
|
|
99
|
+
*/
|
|
100
|
+
export type DurableSnapshot<TLogic extends AnyActorLogic> = SnapshotFrom<TLogic> & Snapshot<OutputFrom<TLogic>>;
|
|
86
101
|
export interface DurableExecution<TLogic extends AnyActorLogic> {
|
|
87
102
|
/**
|
|
88
103
|
* The logical address of this execution's root actor: the logic's own name,
|
|
@@ -101,11 +116,11 @@ export interface DurableExecution<TLogic extends AnyActorLogic> {
|
|
|
101
116
|
/** Index assigned to the next transition. Persist this with checkpoints. */
|
|
102
117
|
readonly nextTransitionIndex: number;
|
|
103
118
|
initialTransition(...[input]: undefined extends InputFrom<TLogic> ? [input?: InputFrom<TLogic>] : [input: InputFrom<TLogic>]): [
|
|
104
|
-
snapshot:
|
|
119
|
+
snapshot: DurableSnapshot<TLogic>,
|
|
105
120
|
effects: DurableEffect<ExecutableActionObjectFromLogic<TLogic>>[]
|
|
106
121
|
];
|
|
107
122
|
transition(snapshot: SnapshotFrom<TLogic>, event: EventFromLogic<TLogic>): [
|
|
108
|
-
snapshot:
|
|
123
|
+
snapshot: DurableSnapshot<TLogic>,
|
|
109
124
|
effects: DurableEffect<ExecutableActionObjectFromLogic<TLogic>>[]
|
|
110
125
|
];
|
|
111
126
|
/**
|
|
@@ -113,8 +128,13 @@ export interface DurableExecution<TLogic extends AnyActorLogic> {
|
|
|
113
128
|
* for addressing and inspection. `undefined` for snapshots this execution
|
|
114
129
|
* has not seen (for example a freshly deserialized checkpoint that has not
|
|
115
130
|
* been passed through `transition()` yet).
|
|
131
|
+
*
|
|
132
|
+
* With an `address`, returns the live actor at that logical address in the
|
|
133
|
+
* snapshot's actor tree instead — the root itself, one of its transitive
|
|
134
|
+
* children, or `undefined` when no live actor has that address (for
|
|
135
|
+
* example a timer firing for an actor that already completed).
|
|
116
136
|
*/
|
|
117
|
-
getActorRef(snapshot: SnapshotFrom<TLogic
|
|
137
|
+
getActorRef(snapshot: SnapshotFrom<TLogic>, address?: string): AnyActor | undefined;
|
|
118
138
|
/**
|
|
119
139
|
* Executes effects and resolves only when every runtime operation they
|
|
120
140
|
* transitively initiated — including operations from live child actors
|
|
@@ -122,12 +142,18 @@ export interface DurableExecution<TLogic extends AnyActorLogic> {
|
|
|
122
142
|
* failed operation rejects it. Operations are handed to the runtime one at
|
|
123
143
|
* a time, in initiation order.
|
|
124
144
|
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
145
|
+
* Events addressed to this execution's root actor that were produced along
|
|
146
|
+
* the way are retained, in order, and handed out by `waitForEvent()`
|
|
147
|
+
* before it defers to the adapter — so the drive loop is just
|
|
148
|
+
* `transition(snapshot, await waitForEvent())` + `executeEffects`.
|
|
149
|
+
*/
|
|
150
|
+
executeEffects(effects: readonly DurableEffect<ExecutableActionObjectFromLogic<TLogic>>[]): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Resolves with the next event addressed to this execution's root actor:
|
|
153
|
+
* an event a prior `executeEffects` batch captured (an invoked actor
|
|
154
|
+
* completing, a child reporting up), or — once none are queued — whatever
|
|
155
|
+
* the adapter's durable wait produces.
|
|
129
156
|
*/
|
|
130
|
-
executeEffects(effects: readonly DurableEffect<ExecutableActionObjectFromLogic<TLogic>>[]): Promise<DurableRootEvent<EventFromLogic<TLogic>>[]>;
|
|
131
157
|
waitForEvent(): Promise<EventFromLogic<TLogic>>;
|
|
132
158
|
run(...[input]: undefined extends InputFrom<TLogic> ? [input?: InputFrom<TLogic>] : [input: InputFrom<TLogic>]): Promise<OutputFrom<TLogic>>;
|
|
133
159
|
}
|
|
@@ -140,4 +166,13 @@ export interface DurableExecution<TLogic extends AnyActorLogic> {
|
|
|
140
166
|
*
|
|
141
167
|
* @experimental
|
|
142
168
|
*/
|
|
143
|
-
export
|
|
169
|
+
export interface DurableExecutionOptions {
|
|
170
|
+
/**
|
|
171
|
+
* Observes the execution's inspection events — actor lifecycle, event
|
|
172
|
+
* routing, transitions — across the whole live actor tree. The host-side
|
|
173
|
+
* home for operation logs and instrumentation, so adapters stay pure
|
|
174
|
+
* physics.
|
|
175
|
+
*/
|
|
176
|
+
inspect?: (inspectionEvent: InspectionEvent) => void;
|
|
177
|
+
}
|
|
178
|
+
export declare function createDurable<TLogic extends AnyActorLogic>(logic: TLogic, adapter: DurableExecutionAdapter<TLogic>, options?: DurableExecutionOptions): DurableExecution<TLogic>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,6 +7,8 @@ export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
|
7
7
|
export type SetupStateSchemas = {
|
|
8
8
|
context?: StandardSchemaV1;
|
|
9
9
|
input?: StandardSchemaV1;
|
|
10
|
+
/** The output emitted when this state node completes. */
|
|
11
|
+
output?: StandardSchemaV1;
|
|
10
12
|
};
|
|
11
13
|
/** A type-only Standard Schema produced by {@link types}. */
|
|
12
14
|
export interface TypeSchema<T> extends StandardSchemaV1<T, T> {
|