xstate 6.0.0-alpha.61 → 6.0.0-alpha.63
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/README.md +7 -0
- package/dist/{createActor-0d08a5f3.development.esm.js → createActor-48f753a9.development.esm.js} +55 -7
- package/dist/{createActor-f4b06bda.esm.js → createActor-523a98c7.esm.js} +52 -7
- package/dist/{createActor-3347cc32.cjs.js → createActor-eba8226e.cjs.js} +53 -6
- package/dist/{createActor-81470538.development.cjs.js → createActor-f71670cf.development.cjs.js} +56 -6
- package/dist/declarations/src/StateMachine.d.ts +16 -8
- package/dist/declarations/src/createActor.d.ts +2 -4
- package/dist/declarations/src/createMachineFromConfig.d.ts +5 -0
- package/dist/declarations/src/durable/index.d.ts +12 -1
- package/dist/declarations/src/setup.d.ts +1 -1
- package/dist/declarations/src/types.d.ts +3 -8
- package/dist/declarations/src/types.v6.d.ts +0 -5
- package/dist/{effectDescriptor-a1ea3f94.development.cjs.js → effectDescriptor-8c87a3e7.development.cjs.js} +1 -1
- package/dist/{effectDescriptor-dbd6ef85.esm.js → effectDescriptor-ad75e430.esm.js} +1 -1
- package/dist/{effectDescriptor-f4708cf3.cjs.js → effectDescriptor-bc9e3e81.cjs.js} +1 -1
- package/dist/{effectDescriptor-31a53206.development.esm.js → effectDescriptor-eadf1b25.development.esm.js} +1 -1
- package/dist/{index-ff1d8226.esm.js → index-211a5dce.esm.js} +1 -1
- package/dist/{index-1e523796.development.esm.js → index-2a4be1f2.development.esm.js} +1 -1
- package/dist/{index-2384b028.development.cjs.js → index-3cb56f46.development.cjs.js} +1 -1
- package/dist/{index-eee6a6a1.cjs.js → index-83f11f07.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 +93 -31
- package/dist/xstate-durable.development.cjs.js +93 -31
- package/dist/xstate-durable.development.esm.js +93 -31
- package/dist/xstate-durable.esm.js +93 -31
- 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 +2 -2
- package/dist/xstate-graph.development.cjs.js +2 -2
- 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-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 +29 -8
- package/dist/xstate.development.cjs.js +31 -9
- package/dist/xstate.development.esm.js +33 -11
- package/dist/xstate.esm.js +31 -10
- package/dist/xstate.umd.min.js +1 -1
- package/dist/xstate.umd.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,13 @@ XState is a state management and orchestration solution for JavaScript and TypeS
|
|
|
17
17
|
|
|
18
18
|
It uses event-driven programming, state machines, statecharts, and the actor model to handle complex logic in predictable, robust, and visual ways. XState provides a powerful and flexible way to manage application and workflow state by allowing developers to model logic as actors and state machines.
|
|
19
19
|
|
|
20
|
+
<!-- durable execution and checkpoint restoration from packages/core/src/durable/index.ts -->
|
|
21
|
+
|
|
22
|
+
For durable hosts, the experimental `xstate/durable` entry point provides
|
|
23
|
+
`createDurable`. Resume a checkpoint with `execution.restore(persistedSnapshot)`
|
|
24
|
+
and execute the returned effects to restart active embedded children and pending
|
|
25
|
+
timers without replaying entry actions. See [durable execution](../../docs/durable-execution.md).
|
|
26
|
+
|
|
20
27
|
For flat finite state machines, `xstate/fsm` provides a tiny pure transition
|
|
21
28
|
table with context and TypeScript support:
|
|
22
29
|
|
package/dist/{createActor-0d08a5f3.development.esm.js → createActor-48f753a9.development.esm.js}
RENAMED
|
@@ -1129,6 +1129,8 @@ function getBuiltInActionFields(action, args) {
|
|
|
1129
1129
|
return undefined;
|
|
1130
1130
|
}
|
|
1131
1131
|
}
|
|
1132
|
+
|
|
1133
|
+
/** @internal Creates an actor-start effect, including for restored children. */
|
|
1132
1134
|
function createStartEffect(actor) {
|
|
1133
1135
|
const args = [actor];
|
|
1134
1136
|
return {
|
|
@@ -1142,6 +1144,41 @@ function createStartEffect(actor) {
|
|
|
1142
1144
|
id: actor.id
|
|
1143
1145
|
};
|
|
1144
1146
|
}
|
|
1147
|
+
|
|
1148
|
+
/** @internal Recreates a pending logical timer without re-entering its state. */
|
|
1149
|
+
function createTimerEffect(actorScope, timer, delay) {
|
|
1150
|
+
const source = actorScope.self;
|
|
1151
|
+
const options = {
|
|
1152
|
+
id: timer.id,
|
|
1153
|
+
delay
|
|
1154
|
+
};
|
|
1155
|
+
if (timer.type === '@xstate.raise') {
|
|
1156
|
+
return {
|
|
1157
|
+
kind: 'builtin',
|
|
1158
|
+
type: timer.type,
|
|
1159
|
+
source,
|
|
1160
|
+
event: timer.event,
|
|
1161
|
+
id: timer.id,
|
|
1162
|
+
delay,
|
|
1163
|
+
params: undefined,
|
|
1164
|
+
args: [actorScope, timer.event, options],
|
|
1165
|
+
exec: execRaiseEffect
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
const target = timer.target === 'self' ? source : timer.target;
|
|
1169
|
+
return {
|
|
1170
|
+
kind: 'builtin',
|
|
1171
|
+
type: timer.type,
|
|
1172
|
+
source,
|
|
1173
|
+
target,
|
|
1174
|
+
event: timer.event,
|
|
1175
|
+
id: timer.id,
|
|
1176
|
+
delay,
|
|
1177
|
+
params: undefined,
|
|
1178
|
+
args: [actorScope, target, timer.event, options],
|
|
1179
|
+
exec: execSendToEffect
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1145
1182
|
function createSpawnEffect(actor) {
|
|
1146
1183
|
const args = [actor];
|
|
1147
1184
|
return {
|
|
@@ -2097,11 +2134,19 @@ function getCandidates(stateNode, event) {
|
|
|
2097
2134
|
function scheduleDelayedEvent(stateNode, timerId, resolveEvent, resolveScheduledDelay) {
|
|
2098
2135
|
const oldEntry = stateNode.entry;
|
|
2099
2136
|
stateNode.entry = (x, enq) => {
|
|
2137
|
+
const result = typeof oldEntry === 'function' ? oldEntry(x, enq) : undefined;
|
|
2138
|
+
// The entry context patch is applied by the caller after this wrapper returns.
|
|
2139
|
+
const context = result?.context !== undefined ? mergeContextPatch(x.context, result.context) : x.context;
|
|
2100
2140
|
enq.raise(resolveEvent(x), {
|
|
2101
2141
|
id: timerId,
|
|
2102
|
-
delay: resolveScheduledDelay(
|
|
2142
|
+
delay: resolveScheduledDelay({
|
|
2143
|
+
context,
|
|
2144
|
+
event: x.event,
|
|
2145
|
+
delays: x.delays,
|
|
2146
|
+
input: x.input
|
|
2147
|
+
})
|
|
2103
2148
|
});
|
|
2104
|
-
return
|
|
2149
|
+
return result;
|
|
2105
2150
|
};
|
|
2106
2151
|
const oldExit = stateNode.exit;
|
|
2107
2152
|
stateNode.exit = (_, enq) => {
|
|
@@ -5412,6 +5457,9 @@ class Actor {
|
|
|
5412
5457
|
this._deferred = void 0;
|
|
5413
5458
|
this._restored = false;
|
|
5414
5459
|
this._warnedUnhandledTypes = void 0;
|
|
5460
|
+
if (options && 'state' in options) {
|
|
5461
|
+
throw new Error('The "state" actor option was removed. Pass the persisted snapshot as "snapshot" instead: createActor(logic, { snapshot }).');
|
|
5462
|
+
}
|
|
5415
5463
|
const resolvedOptions = options ? {
|
|
5416
5464
|
...defaultOptions,
|
|
5417
5465
|
...options
|
|
@@ -5428,7 +5476,7 @@ class Actor {
|
|
|
5428
5476
|
this.system = parent ? parent.system : resolvedOptions._systemRef?.current ?? createRuntimeSystem(this, {
|
|
5429
5477
|
clock,
|
|
5430
5478
|
logger,
|
|
5431
|
-
snapshot: resolvedOptions.snapshot
|
|
5479
|
+
snapshot: resolvedOptions.snapshot,
|
|
5432
5480
|
createActorRef
|
|
5433
5481
|
});
|
|
5434
5482
|
if (!parent && resolvedOptions._systemRef && !resolvedOptions._systemRef.current) {
|
|
@@ -5461,7 +5509,7 @@ class Actor {
|
|
|
5461
5509
|
|
|
5462
5510
|
// prepare to collect initial microsteps during initialTransition
|
|
5463
5511
|
this._collectedMicrosteps = undefined;
|
|
5464
|
-
const persistedState = options?.snapshot
|
|
5512
|
+
const persistedState = options?.snapshot;
|
|
5465
5513
|
this._restored = persistedState !== undefined;
|
|
5466
5514
|
try {
|
|
5467
5515
|
if (persistedState) {
|
|
@@ -6223,7 +6271,7 @@ class Actor {
|
|
|
6223
6271
|
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
6224
6272
|
* the actor, while snapshots represent the actor's last emitted value.
|
|
6225
6273
|
*
|
|
6226
|
-
* Can be restored with {@link ActorOptions.
|
|
6274
|
+
* Can be restored with {@link ActorOptions.snapshot}
|
|
6227
6275
|
* @see https://stately.ai/docs/persistence
|
|
6228
6276
|
*/
|
|
6229
6277
|
|
|
@@ -6271,7 +6319,7 @@ class Actor {
|
|
|
6271
6319
|
|
|
6272
6320
|
/**
|
|
6273
6321
|
* The options `createActor` (and framework hooks) require for `TLogic`:
|
|
6274
|
-
* `{ input }` or a persisted `{ snapshot }`
|
|
6322
|
+
* `{ input }` or a persisted `{ snapshot }` when
|
|
6275
6323
|
* the logic requires input, otherwise nothing.
|
|
6276
6324
|
*
|
|
6277
6325
|
* @public
|
|
@@ -6323,4 +6371,4 @@ function createActor(logic, ...[options]) {
|
|
|
6323
6371
|
return new Actor(logic, options);
|
|
6324
6372
|
}
|
|
6325
6373
|
|
|
6326
|
-
export {
|
|
6374
|
+
export { parseGeneratedActorId as $, attachSnapshotActorRef as A, macrostep as B, isInertActorScope as C, setSnapshotActorRef as D, cloneMachineSnapshot as E, transitionNode as F, getTransitionResult as G, hasEffect as H, createErrorPlatformEvent as I, withActorSelf as J, resolveActionsWithContext as K, takeSpawnAllocationCounters as L, mergeActorIdCounters as M, NULL_EVENT as N, createInitEvent as O, createSpawnEffect as P, initialMicrostep as Q, createStartEffect as R, STATE_DELIMITER as S, toStatePath as T, isStateId as U, getStateNodeByPath as V, getPersistedSnapshot as W, XSTATE_TIMER as X, createRemoteActorRef as Y, resolveReferencedActor as Z, createInvokeTimeoutEvent as _, allocateChildId as a, ACTOR_REF_TYPE as a0, createActor as a1, parseDelayToMilliseconds as a2, isAtomicStateNode as a3, ProcessingStatus as a4, isActorRefLike as a5, createListenerLogic as a6, createSubscriptionLogic as a7, listenerLogic as a8, subscriptionLogic as a9, getActorIdPrefix as aA, getAllOwnEvents as aB, matchesEvent as aC, encodeAddressSegment as aD, getRootActorId as aE, RUNTIME_OPERATIONS as aF, withSystemInspector as aG, createTimerEffect as aH, getSnapshotActorRef as aI, withExecutionIdentity as aJ, Actor as aa, isMachineSnapshot as ab, InfiniteTransitionError as ac, getAllOwnEventDescriptors as ad, matchesState as ae, checkStateIn as af, pathToStateValue as ag, toObserver as ah, executeEffects as ai, isBuiltInExecutableAction as aj, deliverEvent as ak, runStep as al, stopActor as am, terminateActor as an, XSTATE_STOP as ao, createCustomEffect as ap, XSTATE_LOGIC_EFFECT_START as aq, XSTATE_LOGIC_EFFECT_RESOLVE as ar, XSTATE_LOGIC_EFFECT_REJECT as as, finalizeTransitionResult as at, createEmitEffect as au, createSendToEffect as av, XSTATE_INIT as aw, hasAmbientInspector as ax, getProperAncestors as ay, isRemoteActorRef as az, assertChildIdFree as b, reserveChildId as c, mapValues as d, createInvokeId as e, getEventDescriptorKey as f, getDelayedTransitions as g, getCandidates as h, evaluateCandidate as i, formatTransition as j, toTransitionConfigArray as k, createInvokeTimeoutEventId as l, matchesEventDescriptor as m, matchesActorSession as n, formatRouteTransitions as o, resolveStateValue as p, getAllStateNodes as q, resolveRegisteredActorSource as r, getStateNodes as s, toArray as t, createMachineSnapshot as u, isInFinalState as v, createInertActorScope as w, setInertActorScopeSnapshot as x, createDeadLetterEffect as y, beginSpawnAllocation as z };
|
|
@@ -1119,6 +1119,8 @@ function getBuiltInActionFields(action, args) {
|
|
|
1119
1119
|
return undefined;
|
|
1120
1120
|
}
|
|
1121
1121
|
}
|
|
1122
|
+
|
|
1123
|
+
/** @internal Creates an actor-start effect, including for restored children. */
|
|
1122
1124
|
function createStartEffect(actor) {
|
|
1123
1125
|
const args = [actor];
|
|
1124
1126
|
return {
|
|
@@ -1132,6 +1134,41 @@ function createStartEffect(actor) {
|
|
|
1132
1134
|
id: actor.id
|
|
1133
1135
|
};
|
|
1134
1136
|
}
|
|
1137
|
+
|
|
1138
|
+
/** @internal Recreates a pending logical timer without re-entering its state. */
|
|
1139
|
+
function createTimerEffect(actorScope, timer, delay) {
|
|
1140
|
+
const source = actorScope.self;
|
|
1141
|
+
const options = {
|
|
1142
|
+
id: timer.id,
|
|
1143
|
+
delay
|
|
1144
|
+
};
|
|
1145
|
+
if (timer.type === '@xstate.raise') {
|
|
1146
|
+
return {
|
|
1147
|
+
kind: 'builtin',
|
|
1148
|
+
type: timer.type,
|
|
1149
|
+
source,
|
|
1150
|
+
event: timer.event,
|
|
1151
|
+
id: timer.id,
|
|
1152
|
+
delay,
|
|
1153
|
+
params: undefined,
|
|
1154
|
+
args: [actorScope, timer.event, options],
|
|
1155
|
+
exec: execRaiseEffect
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
const target = timer.target === 'self' ? source : timer.target;
|
|
1159
|
+
return {
|
|
1160
|
+
kind: 'builtin',
|
|
1161
|
+
type: timer.type,
|
|
1162
|
+
source,
|
|
1163
|
+
target,
|
|
1164
|
+
event: timer.event,
|
|
1165
|
+
id: timer.id,
|
|
1166
|
+
delay,
|
|
1167
|
+
params: undefined,
|
|
1168
|
+
args: [actorScope, target, timer.event, options],
|
|
1169
|
+
exec: execSendToEffect
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1135
1172
|
function createSpawnEffect(actor) {
|
|
1136
1173
|
const args = [actor];
|
|
1137
1174
|
return {
|
|
@@ -2087,11 +2124,19 @@ function getCandidates(stateNode, event) {
|
|
|
2087
2124
|
function scheduleDelayedEvent(stateNode, timerId, resolveEvent, resolveScheduledDelay) {
|
|
2088
2125
|
const oldEntry = stateNode.entry;
|
|
2089
2126
|
stateNode.entry = (x, enq) => {
|
|
2127
|
+
const result = typeof oldEntry === 'function' ? oldEntry(x, enq) : undefined;
|
|
2128
|
+
// The entry context patch is applied by the caller after this wrapper returns.
|
|
2129
|
+
const context = result?.context !== undefined ? mergeContextPatch(x.context, result.context) : x.context;
|
|
2090
2130
|
enq.raise(resolveEvent(x), {
|
|
2091
2131
|
id: timerId,
|
|
2092
|
-
delay: resolveScheduledDelay(
|
|
2132
|
+
delay: resolveScheduledDelay({
|
|
2133
|
+
context,
|
|
2134
|
+
event: x.event,
|
|
2135
|
+
delays: x.delays,
|
|
2136
|
+
input: x.input
|
|
2137
|
+
})
|
|
2093
2138
|
});
|
|
2094
|
-
return
|
|
2139
|
+
return result;
|
|
2095
2140
|
};
|
|
2096
2141
|
const oldExit = stateNode.exit;
|
|
2097
2142
|
stateNode.exit = (_, enq) => {
|
|
@@ -5301,7 +5346,7 @@ class Actor {
|
|
|
5301
5346
|
this.system = parent ? parent.system : resolvedOptions._systemRef?.current ?? createRuntimeSystem(this, {
|
|
5302
5347
|
clock,
|
|
5303
5348
|
logger,
|
|
5304
|
-
snapshot: resolvedOptions.snapshot
|
|
5349
|
+
snapshot: resolvedOptions.snapshot,
|
|
5305
5350
|
createActorRef
|
|
5306
5351
|
});
|
|
5307
5352
|
if (!parent && resolvedOptions._systemRef && !resolvedOptions._systemRef.current) {
|
|
@@ -5334,7 +5379,7 @@ class Actor {
|
|
|
5334
5379
|
|
|
5335
5380
|
// prepare to collect initial microsteps during initialTransition
|
|
5336
5381
|
this._collectedMicrosteps = undefined;
|
|
5337
|
-
const persistedState = options?.snapshot
|
|
5382
|
+
const persistedState = options?.snapshot;
|
|
5338
5383
|
this._restored = persistedState !== undefined;
|
|
5339
5384
|
try {
|
|
5340
5385
|
if (persistedState) {
|
|
@@ -6086,7 +6131,7 @@ class Actor {
|
|
|
6086
6131
|
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
6087
6132
|
* the actor, while snapshots represent the actor's last emitted value.
|
|
6088
6133
|
*
|
|
6089
|
-
* Can be restored with {@link ActorOptions.
|
|
6134
|
+
* Can be restored with {@link ActorOptions.snapshot}
|
|
6090
6135
|
* @see https://stately.ai/docs/persistence
|
|
6091
6136
|
*/
|
|
6092
6137
|
|
|
@@ -6131,7 +6176,7 @@ class Actor {
|
|
|
6131
6176
|
|
|
6132
6177
|
/**
|
|
6133
6178
|
* The options `createActor` (and framework hooks) require for `TLogic`:
|
|
6134
|
-
* `{ input }` or a persisted `{ snapshot }`
|
|
6179
|
+
* `{ input }` or a persisted `{ snapshot }` when
|
|
6135
6180
|
* the logic requires input, otherwise nothing.
|
|
6136
6181
|
*
|
|
6137
6182
|
* @public
|
|
@@ -6183,4 +6228,4 @@ function createActor(logic, ...[options]) {
|
|
|
6183
6228
|
return new Actor(logic, options);
|
|
6184
6229
|
}
|
|
6185
6230
|
|
|
6186
|
-
export {
|
|
6231
|
+
export { parseGeneratedActorId as $, attachSnapshotActorRef as A, macrostep as B, isInertActorScope as C, setSnapshotActorRef as D, cloneMachineSnapshot as E, transitionNode as F, getTransitionResult as G, hasEffect as H, createErrorPlatformEvent as I, withActorSelf as J, resolveActionsWithContext as K, takeSpawnAllocationCounters as L, mergeActorIdCounters as M, NULL_EVENT as N, createInitEvent as O, createSpawnEffect as P, initialMicrostep as Q, createStartEffect as R, STATE_DELIMITER as S, toStatePath as T, isStateId as U, getStateNodeByPath as V, getPersistedSnapshot as W, XSTATE_TIMER as X, createRemoteActorRef as Y, resolveReferencedActor as Z, createInvokeTimeoutEvent as _, allocateChildId as a, ACTOR_REF_TYPE as a0, createActor as a1, parseDelayToMilliseconds as a2, isAtomicStateNode as a3, ProcessingStatus as a4, isActorRefLike as a5, createListenerLogic as a6, createSubscriptionLogic as a7, listenerLogic as a8, subscriptionLogic as a9, getActorIdPrefix as aA, getAllOwnEvents as aB, matchesEvent as aC, encodeAddressSegment as aD, getRootActorId as aE, RUNTIME_OPERATIONS as aF, withSystemInspector as aG, createTimerEffect as aH, getSnapshotActorRef as aI, withExecutionIdentity as aJ, Actor as aa, isMachineSnapshot as ab, InfiniteTransitionError as ac, getAllOwnEventDescriptors as ad, matchesState as ae, checkStateIn as af, pathToStateValue as ag, toObserver as ah, executeEffects as ai, isBuiltInExecutableAction as aj, deliverEvent as ak, runStep as al, stopActor as am, terminateActor as an, XSTATE_STOP as ao, createCustomEffect as ap, XSTATE_LOGIC_EFFECT_START as aq, XSTATE_LOGIC_EFFECT_RESOLVE as ar, XSTATE_LOGIC_EFFECT_REJECT as as, finalizeTransitionResult as at, createEmitEffect as au, createSendToEffect as av, XSTATE_INIT as aw, hasAmbientInspector as ax, getProperAncestors as ay, isRemoteActorRef as az, assertChildIdFree as b, reserveChildId as c, mapValues as d, createInvokeId as e, getEventDescriptorKey as f, getDelayedTransitions as g, getCandidates as h, evaluateCandidate as i, formatTransition as j, toTransitionConfigArray as k, createInvokeTimeoutEventId as l, matchesEventDescriptor as m, matchesActorSession as n, formatRouteTransitions as o, resolveStateValue as p, getAllStateNodes as q, resolveRegisteredActorSource as r, getStateNodes as s, toArray as t, createMachineSnapshot as u, isInFinalState as v, createInertActorScope as w, setInertActorScopeSnapshot as x, createDeadLetterEffect as y, beginSpawnAllocation as z };
|
|
@@ -1121,6 +1121,8 @@ function getBuiltInActionFields(action, args) {
|
|
|
1121
1121
|
return undefined;
|
|
1122
1122
|
}
|
|
1123
1123
|
}
|
|
1124
|
+
|
|
1125
|
+
/** @internal Creates an actor-start effect, including for restored children. */
|
|
1124
1126
|
function createStartEffect(actor) {
|
|
1125
1127
|
const args = [actor];
|
|
1126
1128
|
return {
|
|
@@ -1134,6 +1136,41 @@ function createStartEffect(actor) {
|
|
|
1134
1136
|
id: actor.id
|
|
1135
1137
|
};
|
|
1136
1138
|
}
|
|
1139
|
+
|
|
1140
|
+
/** @internal Recreates a pending logical timer without re-entering its state. */
|
|
1141
|
+
function createTimerEffect(actorScope, timer, delay) {
|
|
1142
|
+
const source = actorScope.self;
|
|
1143
|
+
const options = {
|
|
1144
|
+
id: timer.id,
|
|
1145
|
+
delay
|
|
1146
|
+
};
|
|
1147
|
+
if (timer.type === '@xstate.raise') {
|
|
1148
|
+
return {
|
|
1149
|
+
kind: 'builtin',
|
|
1150
|
+
type: timer.type,
|
|
1151
|
+
source,
|
|
1152
|
+
event: timer.event,
|
|
1153
|
+
id: timer.id,
|
|
1154
|
+
delay,
|
|
1155
|
+
params: undefined,
|
|
1156
|
+
args: [actorScope, timer.event, options],
|
|
1157
|
+
exec: execRaiseEffect
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1160
|
+
const target = timer.target === 'self' ? source : timer.target;
|
|
1161
|
+
return {
|
|
1162
|
+
kind: 'builtin',
|
|
1163
|
+
type: timer.type,
|
|
1164
|
+
source,
|
|
1165
|
+
target,
|
|
1166
|
+
event: timer.event,
|
|
1167
|
+
id: timer.id,
|
|
1168
|
+
delay,
|
|
1169
|
+
params: undefined,
|
|
1170
|
+
args: [actorScope, target, timer.event, options],
|
|
1171
|
+
exec: execSendToEffect
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1137
1174
|
function createSpawnEffect(actor) {
|
|
1138
1175
|
const args = [actor];
|
|
1139
1176
|
return {
|
|
@@ -2089,11 +2126,19 @@ function getCandidates(stateNode, event) {
|
|
|
2089
2126
|
function scheduleDelayedEvent(stateNode, timerId, resolveEvent, resolveScheduledDelay) {
|
|
2090
2127
|
const oldEntry = stateNode.entry;
|
|
2091
2128
|
stateNode.entry = (x, enq) => {
|
|
2129
|
+
const result = typeof oldEntry === 'function' ? oldEntry(x, enq) : undefined;
|
|
2130
|
+
// The entry context patch is applied by the caller after this wrapper returns.
|
|
2131
|
+
const context = result?.context !== undefined ? mergeContextPatch(x.context, result.context) : x.context;
|
|
2092
2132
|
enq.raise(resolveEvent(x), {
|
|
2093
2133
|
id: timerId,
|
|
2094
|
-
delay: resolveScheduledDelay(
|
|
2134
|
+
delay: resolveScheduledDelay({
|
|
2135
|
+
context,
|
|
2136
|
+
event: x.event,
|
|
2137
|
+
delays: x.delays,
|
|
2138
|
+
input: x.input
|
|
2139
|
+
})
|
|
2095
2140
|
});
|
|
2096
|
-
return
|
|
2141
|
+
return result;
|
|
2097
2142
|
};
|
|
2098
2143
|
const oldExit = stateNode.exit;
|
|
2099
2144
|
stateNode.exit = (_, enq) => {
|
|
@@ -5303,7 +5348,7 @@ class Actor {
|
|
|
5303
5348
|
this.system = parent ? parent.system : resolvedOptions._systemRef?.current ?? createRuntimeSystem(this, {
|
|
5304
5349
|
clock,
|
|
5305
5350
|
logger,
|
|
5306
|
-
snapshot: resolvedOptions.snapshot
|
|
5351
|
+
snapshot: resolvedOptions.snapshot,
|
|
5307
5352
|
createActorRef
|
|
5308
5353
|
});
|
|
5309
5354
|
if (!parent && resolvedOptions._systemRef && !resolvedOptions._systemRef.current) {
|
|
@@ -5336,7 +5381,7 @@ class Actor {
|
|
|
5336
5381
|
|
|
5337
5382
|
// prepare to collect initial microsteps during initialTransition
|
|
5338
5383
|
this._collectedMicrosteps = undefined;
|
|
5339
|
-
const persistedState = options?.snapshot
|
|
5384
|
+
const persistedState = options?.snapshot;
|
|
5340
5385
|
this._restored = persistedState !== undefined;
|
|
5341
5386
|
try {
|
|
5342
5387
|
if (persistedState) {
|
|
@@ -6088,7 +6133,7 @@ class Actor {
|
|
|
6088
6133
|
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
6089
6134
|
* the actor, while snapshots represent the actor's last emitted value.
|
|
6090
6135
|
*
|
|
6091
|
-
* Can be restored with {@link ActorOptions.
|
|
6136
|
+
* Can be restored with {@link ActorOptions.snapshot}
|
|
6092
6137
|
* @see https://stately.ai/docs/persistence
|
|
6093
6138
|
*/
|
|
6094
6139
|
|
|
@@ -6133,7 +6178,7 @@ class Actor {
|
|
|
6133
6178
|
|
|
6134
6179
|
/**
|
|
6135
6180
|
* The options `createActor` (and framework hooks) require for `TLogic`:
|
|
6136
|
-
* `{ input }` or a persisted `{ snapshot }`
|
|
6181
|
+
* `{ input }` or a persisted `{ snapshot }` when
|
|
6137
6182
|
* the logic requires input, otherwise nothing.
|
|
6138
6183
|
*
|
|
6139
6184
|
* @public
|
|
@@ -6219,7 +6264,9 @@ exports.createMachineSnapshot = createMachineSnapshot;
|
|
|
6219
6264
|
exports.createRemoteActorRef = createRemoteActorRef;
|
|
6220
6265
|
exports.createSendToEffect = createSendToEffect;
|
|
6221
6266
|
exports.createSpawnEffect = createSpawnEffect;
|
|
6267
|
+
exports.createStartEffect = createStartEffect;
|
|
6222
6268
|
exports.createSubscriptionLogic = createSubscriptionLogic;
|
|
6269
|
+
exports.createTimerEffect = createTimerEffect;
|
|
6223
6270
|
exports.deliverEvent = deliverEvent;
|
|
6224
6271
|
exports.encodeAddressSegment = encodeAddressSegment;
|
|
6225
6272
|
exports.evaluateCandidate = evaluateCandidate;
|
package/dist/{createActor-81470538.development.cjs.js → createActor-f71670cf.development.cjs.js}
RENAMED
|
@@ -1131,6 +1131,8 @@ function getBuiltInActionFields(action, args) {
|
|
|
1131
1131
|
return undefined;
|
|
1132
1132
|
}
|
|
1133
1133
|
}
|
|
1134
|
+
|
|
1135
|
+
/** @internal Creates an actor-start effect, including for restored children. */
|
|
1134
1136
|
function createStartEffect(actor) {
|
|
1135
1137
|
const args = [actor];
|
|
1136
1138
|
return {
|
|
@@ -1144,6 +1146,41 @@ function createStartEffect(actor) {
|
|
|
1144
1146
|
id: actor.id
|
|
1145
1147
|
};
|
|
1146
1148
|
}
|
|
1149
|
+
|
|
1150
|
+
/** @internal Recreates a pending logical timer without re-entering its state. */
|
|
1151
|
+
function createTimerEffect(actorScope, timer, delay) {
|
|
1152
|
+
const source = actorScope.self;
|
|
1153
|
+
const options = {
|
|
1154
|
+
id: timer.id,
|
|
1155
|
+
delay
|
|
1156
|
+
};
|
|
1157
|
+
if (timer.type === '@xstate.raise') {
|
|
1158
|
+
return {
|
|
1159
|
+
kind: 'builtin',
|
|
1160
|
+
type: timer.type,
|
|
1161
|
+
source,
|
|
1162
|
+
event: timer.event,
|
|
1163
|
+
id: timer.id,
|
|
1164
|
+
delay,
|
|
1165
|
+
params: undefined,
|
|
1166
|
+
args: [actorScope, timer.event, options],
|
|
1167
|
+
exec: execRaiseEffect
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
const target = timer.target === 'self' ? source : timer.target;
|
|
1171
|
+
return {
|
|
1172
|
+
kind: 'builtin',
|
|
1173
|
+
type: timer.type,
|
|
1174
|
+
source,
|
|
1175
|
+
target,
|
|
1176
|
+
event: timer.event,
|
|
1177
|
+
id: timer.id,
|
|
1178
|
+
delay,
|
|
1179
|
+
params: undefined,
|
|
1180
|
+
args: [actorScope, target, timer.event, options],
|
|
1181
|
+
exec: execSendToEffect
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1147
1184
|
function createSpawnEffect(actor) {
|
|
1148
1185
|
const args = [actor];
|
|
1149
1186
|
return {
|
|
@@ -2099,11 +2136,19 @@ function getCandidates(stateNode, event) {
|
|
|
2099
2136
|
function scheduleDelayedEvent(stateNode, timerId, resolveEvent, resolveScheduledDelay) {
|
|
2100
2137
|
const oldEntry = stateNode.entry;
|
|
2101
2138
|
stateNode.entry = (x, enq) => {
|
|
2139
|
+
const result = typeof oldEntry === 'function' ? oldEntry(x, enq) : undefined;
|
|
2140
|
+
// The entry context patch is applied by the caller after this wrapper returns.
|
|
2141
|
+
const context = result?.context !== undefined ? mergeContextPatch(x.context, result.context) : x.context;
|
|
2102
2142
|
enq.raise(resolveEvent(x), {
|
|
2103
2143
|
id: timerId,
|
|
2104
|
-
delay: resolveScheduledDelay(
|
|
2144
|
+
delay: resolveScheduledDelay({
|
|
2145
|
+
context,
|
|
2146
|
+
event: x.event,
|
|
2147
|
+
delays: x.delays,
|
|
2148
|
+
input: x.input
|
|
2149
|
+
})
|
|
2105
2150
|
});
|
|
2106
|
-
return
|
|
2151
|
+
return result;
|
|
2107
2152
|
};
|
|
2108
2153
|
const oldExit = stateNode.exit;
|
|
2109
2154
|
stateNode.exit = (_, enq) => {
|
|
@@ -5414,6 +5459,9 @@ class Actor {
|
|
|
5414
5459
|
this._deferred = void 0;
|
|
5415
5460
|
this._restored = false;
|
|
5416
5461
|
this._warnedUnhandledTypes = void 0;
|
|
5462
|
+
if (options && 'state' in options) {
|
|
5463
|
+
throw new Error('The "state" actor option was removed. Pass the persisted snapshot as "snapshot" instead: createActor(logic, { snapshot }).');
|
|
5464
|
+
}
|
|
5417
5465
|
const resolvedOptions = options ? {
|
|
5418
5466
|
...defaultOptions,
|
|
5419
5467
|
...options
|
|
@@ -5430,7 +5478,7 @@ class Actor {
|
|
|
5430
5478
|
this.system = parent ? parent.system : resolvedOptions._systemRef?.current ?? createRuntimeSystem(this, {
|
|
5431
5479
|
clock,
|
|
5432
5480
|
logger,
|
|
5433
|
-
snapshot: resolvedOptions.snapshot
|
|
5481
|
+
snapshot: resolvedOptions.snapshot,
|
|
5434
5482
|
createActorRef
|
|
5435
5483
|
});
|
|
5436
5484
|
if (!parent && resolvedOptions._systemRef && !resolvedOptions._systemRef.current) {
|
|
@@ -5463,7 +5511,7 @@ class Actor {
|
|
|
5463
5511
|
|
|
5464
5512
|
// prepare to collect initial microsteps during initialTransition
|
|
5465
5513
|
this._collectedMicrosteps = undefined;
|
|
5466
|
-
const persistedState = options?.snapshot
|
|
5514
|
+
const persistedState = options?.snapshot;
|
|
5467
5515
|
this._restored = persistedState !== undefined;
|
|
5468
5516
|
try {
|
|
5469
5517
|
if (persistedState) {
|
|
@@ -6225,7 +6273,7 @@ class Actor {
|
|
|
6225
6273
|
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
6226
6274
|
* the actor, while snapshots represent the actor's last emitted value.
|
|
6227
6275
|
*
|
|
6228
|
-
* Can be restored with {@link ActorOptions.
|
|
6276
|
+
* Can be restored with {@link ActorOptions.snapshot}
|
|
6229
6277
|
* @see https://stately.ai/docs/persistence
|
|
6230
6278
|
*/
|
|
6231
6279
|
|
|
@@ -6273,7 +6321,7 @@ class Actor {
|
|
|
6273
6321
|
|
|
6274
6322
|
/**
|
|
6275
6323
|
* The options `createActor` (and framework hooks) require for `TLogic`:
|
|
6276
|
-
* `{ input }` or a persisted `{ snapshot }`
|
|
6324
|
+
* `{ input }` or a persisted `{ snapshot }` when
|
|
6277
6325
|
* the logic requires input, otherwise nothing.
|
|
6278
6326
|
*
|
|
6279
6327
|
* @public
|
|
@@ -6359,7 +6407,9 @@ exports.createMachineSnapshot = createMachineSnapshot;
|
|
|
6359
6407
|
exports.createRemoteActorRef = createRemoteActorRef;
|
|
6360
6408
|
exports.createSendToEffect = createSendToEffect;
|
|
6361
6409
|
exports.createSpawnEffect = createSpawnEffect;
|
|
6410
|
+
exports.createStartEffect = createStartEffect;
|
|
6362
6411
|
exports.createSubscriptionLogic = createSubscriptionLogic;
|
|
6412
|
+
exports.createTimerEffect = createTimerEffect;
|
|
6363
6413
|
exports.deliverEvent = deliverEvent;
|
|
6364
6414
|
exports.encodeAddressSegment = encodeAddressSegment;
|
|
6365
6415
|
exports.evaluateCandidate = evaluateCandidate;
|
|
@@ -13,12 +13,17 @@ type CompatibleProvidedActorSource<TExpected extends AnyActorLogic, TActual exte
|
|
|
13
13
|
type ProvidedActors<TExpectedActorMap extends Sources['actors'], TProvidedActorMap extends Partial<Record<keyof TExpectedActorMap & string, AnyActorLogic>>> = {
|
|
14
14
|
[K in keyof TProvidedActorMap]: K extends keyof TExpectedActorMap ? TProvidedActorMap[K] extends AnyActorLogic ? CompatibleProvidedActorSource<TExpectedActorMap[K], TProvidedActorMap[K]> : never : never;
|
|
15
15
|
};
|
|
16
|
+
type ProvidedSourceMap<TDeclared, TProvided> = {
|
|
17
|
+
[K in keyof TDeclared]: K extends keyof TProvided ? {} extends Pick<TProvided, K> ? TDeclared[K] | Exclude<TProvided[K], undefined> : Exclude<TProvided[K], undefined> : TDeclared[K];
|
|
18
|
+
};
|
|
19
|
+
type ProvidedActionContracts<T> = {
|
|
20
|
+
[K in keyof T]: T[K] extends (...args: infer TArgs) => any ? (...args: TArgs) => void : never;
|
|
21
|
+
};
|
|
16
22
|
/** @public */
|
|
17
23
|
export declare class StateMachine<TContext extends MachineContext, TEvent extends EventObject, TChildren extends Record<string, AnyActorRef | undefined>, TStateValue extends StateValue, TTag extends string, TInput, TOutput, TEmitted extends EventObject, TMeta extends MetaObject, TConfig extends StateSchema, TActionMap extends Sources['actions'], TActorMap extends Sources['actors'], TGuardMap extends Sources['guards'], TDelayMap extends Sources['delays'], TInternalEvent extends EventObject = never, TTransitionMeta extends MetaObject = TMeta> implements ActorLogic<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, TInput, AnyActorSystem, TEmitted> {
|
|
18
24
|
/** The raw config used to create the machine. */
|
|
19
25
|
config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any, any, any, any> & {
|
|
20
26
|
schemas?: AnyMachineSchemas;
|
|
21
|
-
internalEvents?: readonly string[];
|
|
22
27
|
};
|
|
23
28
|
validator?: ActorLogicValidator | undefined;
|
|
24
29
|
/**
|
|
@@ -49,7 +54,9 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
49
54
|
readonly _actorMap: TActorMap;
|
|
50
55
|
readonly _stateSchema: TConfig;
|
|
51
56
|
/** The machine's own version. */
|
|
52
|
-
version
|
|
57
|
+
version: TConfig extends {
|
|
58
|
+
version: infer TVersion extends string;
|
|
59
|
+
} ? TVersion : undefined;
|
|
53
60
|
schemas: AnyMachineSchemas | undefined;
|
|
54
61
|
/** Standard Schema for snapshots persisted by this machine version. */
|
|
55
62
|
readonly snapshotSchema: StandardSchemaV1<unknown, Snapshot<unknown> & PersistedMachineSnapshot & {
|
|
@@ -61,7 +68,9 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
61
68
|
/** Runtime options for machine execution. */
|
|
62
69
|
options: MachineOptions;
|
|
63
70
|
root: StateNode<TContext, TEvent, TMeta, TTransitionMeta>;
|
|
64
|
-
id:
|
|
71
|
+
id: TConfig extends {
|
|
72
|
+
id: infer TId extends string;
|
|
73
|
+
} ? TId : '(machine)';
|
|
65
74
|
states: StateNode<TContext, TEvent, TMeta, TTransitionMeta>['states'];
|
|
66
75
|
events: Array<EventDescriptor<TEvent>>;
|
|
67
76
|
internalEventDescriptors: ReadonlyArray<string>;
|
|
@@ -76,7 +85,6 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
76
85
|
/** The raw config used to create the machine. */
|
|
77
86
|
config: Next_MachineConfig<any, any, any, any, any, any, any, any, any, any, any, any, any> & {
|
|
78
87
|
schemas?: AnyMachineSchemas;
|
|
79
|
-
internalEvents?: readonly string[];
|
|
80
88
|
}, sources?: Sources, validator?: ActorLogicValidator | undefined);
|
|
81
89
|
/**
|
|
82
90
|
* Clones this state machine with the provided sources.
|
|
@@ -85,8 +93,8 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
85
93
|
* recursively merge with the existing options.
|
|
86
94
|
* @returns A new `StateMachine` instance with the provided sources.
|
|
87
95
|
*/
|
|
88
|
-
provide<const TProvidedActorMap extends Partial<Record<keyof TActorMap & string, AnyActorLogic>> = {}>(sources: {
|
|
89
|
-
actions?: Partial<TActionMap>;
|
|
96
|
+
provide<const TProvidedActorMap extends Partial<Record<keyof TActorMap & string, AnyActorLogic>> = {}, const TProvidedActionMap extends Partial<ProvidedActionContracts<TActionMap>> = {}>(sources: {
|
|
97
|
+
actions?: TProvidedActionMap & Partial<ProvidedActionContracts<TActionMap>> & Record<Exclude<keyof TProvidedActionMap, keyof TActionMap>, never>;
|
|
90
98
|
actors?: TProvidedActorMap & ProvidedActors<TActorMap, TProvidedActorMap>;
|
|
91
99
|
guards?: Partial<TGuardMap> & {
|
|
92
100
|
[K in keyof TGuardMap]?: GuardSourceMap<TContext, TEvent>[string];
|
|
@@ -94,7 +102,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
94
102
|
delays?: {
|
|
95
103
|
[K in keyof TDelayMap]?: DelaySourceMap<TContext, TEvent>[string];
|
|
96
104
|
};
|
|
97
|
-
}):
|
|
105
|
+
}): StateMachine<TContext, TEvent, TChildren, TStateValue, TTag, TInput, TOutput, TEmitted, TMeta, TConfig, ProvidedSourceMap<TActionMap, TProvidedActionMap>, ProvidedSourceMap<TActorMap, TProvidedActorMap>, TGuardMap, TDelayMap, TInternalEvent, TTransitionMeta>;
|
|
98
106
|
resolveState(config: {
|
|
99
107
|
value: StateValue;
|
|
100
108
|
context?: TContext;
|
|
@@ -132,7 +140,7 @@ export declare class StateMachine<TContext extends MachineContext, TEvent extend
|
|
|
132
140
|
*/
|
|
133
141
|
getInitialSnapshot(actorScope?: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>, input?: TInput): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>;
|
|
134
142
|
initialTransition(input: TInput | undefined, actorScope?: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>): ActorLogicTransitionResult<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, ExecutableActionObjectFromLogic<this>>;
|
|
135
|
-
start(snapshot?: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>): void;
|
|
143
|
+
start(snapshot?: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, actorScope?: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>): void;
|
|
136
144
|
getStateNodeById(stateId: string): StateNode<TContext, TEvent, TMeta, TTransitionMeta>;
|
|
137
145
|
getPersistedSnapshot(snapshot: MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, options?: unknown): Snapshot<unknown>;
|
|
138
146
|
restoreSnapshot(snapshot: Snapshot<unknown>, actorScope?: ActorScope<MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>, TEvent, AnyActorSystem, TEmitted>): MachineSnapshot<TContext, TEvent, TChildren, TStateValue, TTag, TOutput, TMeta, TConfig>;
|
|
@@ -202,7 +202,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
|
|
|
202
202
|
* {@link Actor.getSnapshot}. Persisted state represents the internal state of
|
|
203
203
|
* the actor, while snapshots represent the actor's last emitted value.
|
|
204
204
|
*
|
|
205
|
-
* Can be restored with {@link ActorOptions.
|
|
205
|
+
* Can be restored with {@link ActorOptions.snapshot}
|
|
206
206
|
* @see https://stately.ai/docs/persistence
|
|
207
207
|
*/
|
|
208
208
|
getPersistedSnapshot(options?: {
|
|
@@ -246,7 +246,7 @@ export declare class Actor<TLogic extends AnyActorLogic> implements ActorInstanc
|
|
|
246
246
|
export type RequiredActorOptionsKeys<TLogic extends AnyActorLogic> = undefined extends InputFrom<TLogic> ? never : 'input';
|
|
247
247
|
/**
|
|
248
248
|
* The options `createActor` (and framework hooks) require for `TLogic`:
|
|
249
|
-
* `{ input }` or a persisted `{ snapshot }`
|
|
249
|
+
* `{ input }` or a persisted `{ snapshot }` when
|
|
250
250
|
* the logic requires input, otherwise nothing.
|
|
251
251
|
*
|
|
252
252
|
* @public
|
|
@@ -257,8 +257,6 @@ export type RequiredActorOptionsFor<TLogic extends AnyActorLogic> = [
|
|
|
257
257
|
[K in RequiredActorOptionsKeys<TLogic>]: unknown;
|
|
258
258
|
} | {
|
|
259
259
|
snapshot: NonNullable<ActorOptions<TLogic>['snapshot']>;
|
|
260
|
-
} | {
|
|
261
|
-
state: NonNullable<ActorOptions<TLogic>['state']>;
|
|
262
260
|
};
|
|
263
261
|
/** Options accepted by {@link createActor}. */
|
|
264
262
|
type CreateActorOptionsArgs<TLogic extends AnyActorLogic> = [
|
|
@@ -123,6 +123,11 @@ export interface MachineJSON extends StateNodeJSON {
|
|
|
123
123
|
duration: number | string | ResolvableJSON;
|
|
124
124
|
}>;
|
|
125
125
|
schemas?: Record<string, unknown>;
|
|
126
|
+
/**
|
|
127
|
+
* Event types that only the machine itself (and its children) may send;
|
|
128
|
+
* external senders are rejected with reason `internalEvent`.
|
|
129
|
+
*/
|
|
130
|
+
internalEvents?: string[];
|
|
126
131
|
}
|
|
127
132
|
type EvaluatorSlot = 'context' | 'guard' | 'choice' | 'action' | 'actionParams' | 'transition' | 'input' | 'output' | 'delay' | 'transitionContext' | 'unknown';
|
|
128
133
|
type EvaluatorKind = 'expr' | 'code';
|
|
@@ -134,6 +134,17 @@ export interface DurableExecution<TLogic extends AnyActorLogic> {
|
|
|
134
134
|
readonly machineVersion: string | undefined;
|
|
135
135
|
/** Index assigned to the next transition. Persist this with checkpoints. */
|
|
136
136
|
readonly nextTransitionIndex: number;
|
|
137
|
+
/**
|
|
138
|
+
* Restores a checkpoint on a fresh execution. Returns effects that start
|
|
139
|
+
* active embedded children and re-arm pending root timers; execute them
|
|
140
|
+
* with `executeEffects` before waiting or processing the next event.
|
|
141
|
+
* Does not send a machine event, replay entry actions, or advance the
|
|
142
|
+
* transition index. Restoration effect IDs use `restore:<index>:<effect>`.
|
|
143
|
+
*/
|
|
144
|
+
restore(persistedSnapshot: Snapshot<unknown>): [
|
|
145
|
+
snapshot: DurableSnapshot<TLogic>,
|
|
146
|
+
effects: DurableEffect<ExecutableActionObjectFromLogic<TLogic>>[]
|
|
147
|
+
];
|
|
137
148
|
initialTransition(...[input]: undefined extends InputFrom<TLogic> ? [input?: InputFrom<TLogic>] : [input: InputFrom<TLogic>]): [
|
|
138
149
|
snapshot: DurableSnapshot<TLogic>,
|
|
139
150
|
effects: DurableEffect<ExecutableActionObjectFromLogic<TLogic>>[]
|
|
@@ -146,7 +157,7 @@ export interface DurableExecution<TLogic extends AnyActorLogic> {
|
|
|
146
157
|
* Returns the actor reference behind a snapshot produced by this execution,
|
|
147
158
|
* for addressing and inspection. `undefined` for snapshots this execution
|
|
148
159
|
* has not seen (for example a freshly deserialized checkpoint that has not
|
|
149
|
-
* been passed through `transition()` yet).
|
|
160
|
+
* been passed through `restore()` or `transition()` yet).
|
|
150
161
|
*
|
|
151
162
|
* With an `address`, returns the live actor at that logical address in the
|
|
152
163
|
* snapshot's actor tree instead — the root itself, one of its transitive
|