@typeonce/effect-machine 0.47.0 → 0.48.0
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/AGENTS.md +374 -22
- package/CLAUDE.md +374 -22
- package/README.md +56 -7
- package/ai-docs/src/10_modeling/01_create-a-machine.ts +3 -3
- package/ai-docs/src/10_modeling/index.md +64 -17
- package/ai-docs/src/20_root-api/index.md +2 -2
- package/ai-docs/src/35_cluster/index.md +213 -0
- package/ai-docs/src/37_new-host/index.md +90 -0
- package/dist/LocalMachine.d.ts +417 -0
- package/dist/LocalMachine.d.ts.map +1 -0
- package/dist/LocalMachine.js +193 -0
- package/dist/LocalMachine.js.map +1 -0
- package/dist/Machine.d.ts +1122 -814
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +195 -186
- package/dist/Machine.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +8 -10
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +7 -6
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/capability.d.ts +101 -0
- package/dist/internal/machine/capability.d.ts.map +1 -0
- package/dist/internal/machine/capability.js +70 -0
- package/dist/internal/machine/capability.js.map +1 -0
- package/dist/internal/machine/{invocationDefinition.d.ts → capturedInvocation.d.ts} +11 -11
- package/dist/internal/machine/capturedInvocation.d.ts.map +1 -0
- package/dist/internal/machine/{invocationDefinition.js → capturedInvocation.js} +2 -2
- package/dist/internal/machine/capturedInvocation.js.map +1 -0
- package/dist/internal/machine/child.d.ts +14 -0
- package/dist/internal/machine/child.d.ts.map +1 -0
- package/dist/internal/machine/child.js +19 -0
- package/dist/internal/machine/child.js.map +1 -0
- package/dist/internal/machine/childRegistry.d.ts +0 -2
- package/dist/internal/machine/childRegistry.d.ts.map +1 -1
- package/dist/internal/machine/childRegistry.js +2 -2
- package/dist/internal/machine/childRegistry.js.map +1 -1
- package/dist/internal/machine/cluster.d.ts +19 -4
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js +263 -110
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/clusterChild.d.ts +66 -0
- package/dist/internal/machine/clusterChild.d.ts.map +1 -0
- package/dist/internal/machine/clusterChild.js +105 -0
- package/dist/internal/machine/clusterChild.js.map +1 -0
- package/dist/internal/machine/clusterFailure.d.ts +14 -0
- package/dist/internal/machine/clusterFailure.d.ts.map +1 -0
- package/dist/internal/machine/clusterFailure.js +44 -0
- package/dist/internal/machine/clusterFailure.js.map +1 -0
- package/dist/internal/machine/clusterInstance.d.ts +194 -0
- package/dist/internal/machine/clusterInstance.d.ts.map +1 -0
- package/dist/internal/machine/clusterInstance.js +1076 -0
- package/dist/internal/machine/clusterInstance.js.map +1 -0
- package/dist/internal/machine/clusterKeepAlive.d.ts +47 -0
- package/dist/internal/machine/clusterKeepAlive.d.ts.map +1 -0
- package/dist/internal/machine/clusterKeepAlive.js +72 -0
- package/dist/internal/machine/clusterKeepAlive.js.map +1 -0
- package/dist/internal/machine/clusterProgress.d.ts +73 -0
- package/dist/internal/machine/clusterProgress.d.ts.map +1 -0
- package/dist/internal/machine/clusterProgress.js +116 -0
- package/dist/internal/machine/clusterProgress.js.map +1 -0
- package/dist/internal/machine/clusterProtocol.d.ts +37 -4
- package/dist/internal/machine/clusterProtocol.d.ts.map +1 -1
- package/dist/internal/machine/clusterProtocol.js +18 -4
- package/dist/internal/machine/clusterProtocol.js.map +1 -1
- package/dist/internal/machine/clusterProxy.d.ts +46 -0
- package/dist/internal/machine/clusterProxy.d.ts.map +1 -0
- package/dist/internal/machine/clusterProxy.js +150 -0
- package/dist/internal/machine/clusterProxy.js.map +1 -0
- package/dist/internal/machine/clusterRead.d.ts +61 -0
- package/dist/internal/machine/clusterRead.d.ts.map +1 -0
- package/dist/internal/machine/clusterRead.js +108 -0
- package/dist/internal/machine/clusterRead.js.map +1 -0
- package/dist/internal/machine/clusterSqlStorage.d.ts +16 -0
- package/dist/internal/machine/clusterSqlStorage.d.ts.map +1 -0
- package/dist/internal/machine/clusterSqlStorage.js +138 -0
- package/dist/internal/machine/clusterSqlStorage.js.map +1 -0
- package/dist/internal/machine/clusterStorageCheck.d.ts +19 -0
- package/dist/internal/machine/clusterStorageCheck.d.ts.map +1 -0
- package/dist/internal/machine/clusterStorageCheck.js +186 -0
- package/dist/internal/machine/clusterStorageCheck.js.map +1 -0
- package/dist/internal/machine/clusterTarget.d.ts +74 -0
- package/dist/internal/machine/clusterTarget.d.ts.map +1 -0
- package/dist/internal/machine/clusterTarget.js +81 -0
- package/dist/internal/machine/clusterTarget.js.map +1 -0
- package/dist/internal/machine/clusterTimer.d.ts +21 -0
- package/dist/internal/machine/clusterTimer.d.ts.map +1 -0
- package/dist/internal/machine/clusterTimer.js +50 -0
- package/dist/internal/machine/clusterTimer.js.map +1 -0
- package/dist/internal/machine/clusterWake.d.ts +61 -0
- package/dist/internal/machine/clusterWake.d.ts.map +1 -0
- package/dist/internal/machine/clusterWake.js +81 -0
- package/dist/internal/machine/clusterWake.js.map +1 -0
- package/dist/internal/machine/clusterWork.d.ts +130 -0
- package/dist/internal/machine/clusterWork.d.ts.map +1 -0
- package/dist/internal/machine/clusterWork.js +191 -0
- package/dist/internal/machine/clusterWork.js.map +1 -0
- package/dist/internal/machine/command.d.ts +4 -4
- package/dist/internal/machine/command.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.d.ts +8 -6
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.js +1 -5
- package/dist/internal/machine/commandRuntime.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +0 -13
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +0 -151
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/errors.d.ts +11 -2
- package/dist/internal/machine/errors.d.ts.map +1 -1
- package/dist/internal/machine/errors.js +11 -2
- package/dist/internal/machine/errors.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +45 -3
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +328 -191
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +6 -6
- package/dist/internal/machine/implementation.d.ts.map +1 -1
- package/dist/internal/machine/inspectionRuntime.d.ts +1 -1
- package/dist/internal/machine/inspectionRuntime.d.ts.map +1 -1
- package/dist/internal/machine/invocationChanges.d.ts +60 -0
- package/dist/internal/machine/invocationChanges.d.ts.map +1 -0
- package/dist/internal/machine/invocationChanges.js +54 -0
- package/dist/internal/machine/invocationChanges.js.map +1 -0
- package/dist/internal/machine/{activities.d.ts → invocationDefinitions.d.ts} +8 -8
- package/dist/internal/machine/invocationDefinitions.d.ts.map +1 -0
- package/dist/internal/machine/{activities.js → invocationDefinitions.js} +5 -5
- package/dist/internal/machine/invocationDefinitions.js.map +1 -0
- package/dist/internal/machine/invocationEvent.d.ts +16 -7
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +26 -12
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/invocationOutcome.d.ts +89 -0
- package/dist/internal/machine/invocationOutcome.d.ts.map +1 -0
- package/dist/internal/machine/invocationOutcome.js +76 -0
- package/dist/internal/machine/invocationOutcome.js.map +1 -0
- package/dist/internal/machine/invocationResolution.d.ts +137 -0
- package/dist/internal/machine/invocationResolution.d.ts.map +1 -0
- package/dist/internal/machine/invocationResolution.js +150 -0
- package/dist/internal/machine/invocationResolution.js.map +1 -0
- package/dist/internal/machine/logicScope.d.ts +24 -0
- package/dist/internal/machine/logicScope.d.ts.map +1 -0
- package/dist/internal/machine/logicScope.js +33 -0
- package/dist/internal/machine/logicScope.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +17 -23
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +24 -40
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/observation.d.ts +3 -0
- package/dist/internal/machine/observation.d.ts.map +1 -1
- package/dist/internal/machine/observation.js +56 -2
- package/dist/internal/machine/observation.js.map +1 -1
- package/dist/internal/machine/plannedSnapshot.d.ts.map +1 -1
- package/dist/internal/machine/plannedSnapshot.js +11 -20
- package/dist/internal/machine/plannedSnapshot.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +36 -23
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +15 -8
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +17 -9
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +43 -503
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +1 -1
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +48 -10
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +20 -16
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +93 -88
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/runtimeCompiled.d.ts.map +1 -1
- package/dist/internal/machine/runtimeCompiled.js +359 -120
- package/dist/internal/machine/runtimeCompiled.js.map +1 -1
- package/dist/internal/machine/runtimeProtocol.d.ts +151 -82
- package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
- package/dist/internal/machine/runtimeProtocol.js +236 -219
- package/dist/internal/machine/runtimeProtocol.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +0 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +0 -1
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/step.d.ts +486 -0
- package/dist/internal/machine/step.d.ts.map +1 -0
- package/dist/internal/machine/step.js +957 -0
- package/dist/internal/machine/step.js.map +1 -0
- package/dist/internal/machine/stepHost.d.ts +33 -0
- package/dist/internal/machine/stepHost.d.ts.map +1 -0
- package/dist/internal/machine/stepHost.js +501 -0
- package/dist/internal/machine/stepHost.js.map +1 -0
- package/dist/internal/machine/symbols.d.ts +2 -11
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js +2 -2
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/transition.d.ts +7 -7
- package/dist/internal/machine/transition.d.ts.map +1 -1
- package/dist/internal/testing/machine/check.d.ts.map +1 -1
- package/dist/internal/testing/machine/check.js +217 -25
- package/dist/internal/testing/machine/check.js.map +1 -1
- package/dist/internal/testing/machine/exploration.d.ts +19 -2
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
- package/dist/internal/testing/machine/exploration.js +14 -3
- package/dist/internal/testing/machine/exploration.js.map +1 -1
- package/dist/internal/testing/machine/format.js.map +1 -1
- package/dist/internal/testing/machine/probe.d.ts.map +1 -1
- package/dist/internal/testing/machine/probe.js +1 -1
- package/dist/internal/testing/machine/probe.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts +2 -2
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +10 -3
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/trace.d.ts +38 -3
- package/dist/internal/testing/machine/trace.d.ts.map +1 -1
- package/dist/internal/testing/machine/trace.js +180 -33
- package/dist/internal/testing/machine/trace.js.map +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +9 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/internal/testing/machine/work.d.ts +47 -0
- package/dist/internal/testing/machine/work.d.ts.map +1 -0
- package/dist/internal/testing/machine/work.js +74 -0
- package/dist/internal/testing/machine/work.js.map +1 -0
- package/dist/testing/MachineTest.d.ts +253 -37
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +81 -9
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +1071 -41
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +441 -12
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachineProxy.d.ts +257 -0
- package/dist/unstable/cluster/ClusterMachineProxy.d.ts.map +1 -0
- package/dist/unstable/cluster/ClusterMachineProxy.js +73 -0
- package/dist/unstable/cluster/ClusterMachineProxy.js.map +1 -0
- package/dist/unstable/cluster/SqlMachineStorage.d.ts +125 -0
- package/dist/unstable/cluster/SqlMachineStorage.d.ts.map +1 -0
- package/dist/unstable/cluster/SqlMachineStorage.js +62 -0
- package/dist/unstable/cluster/SqlMachineStorage.js.map +1 -0
- package/dist/unstable/cluster/index.d.ts +13 -0
- package/dist/unstable/cluster/index.d.ts.map +1 -1
- package/dist/unstable/cluster/index.js +13 -0
- package/dist/unstable/cluster/index.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +21 -26
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/package.json +5 -3
- package/src/LocalMachine.ts +611 -0
- package/src/Machine.ts +1383 -1336
- package/src/index.ts +1 -0
- package/src/internal/machine/atom.ts +20 -49
- package/src/internal/machine/capability.ts +123 -0
- package/src/internal/machine/{invocationDefinition.ts → capturedInvocation.ts} +13 -13
- package/src/internal/machine/child.ts +25 -0
- package/src/internal/machine/childRegistry.ts +1 -4
- package/src/internal/machine/cluster.ts +420 -205
- package/src/internal/machine/clusterChild.ts +117 -0
- package/src/internal/machine/clusterFailure.ts +53 -0
- package/src/internal/machine/clusterInstance.ts +1779 -0
- package/src/internal/machine/clusterKeepAlive.ts +93 -0
- package/src/internal/machine/clusterProgress.ts +159 -0
- package/src/internal/machine/clusterProtocol.ts +46 -4
- package/src/internal/machine/clusterProxy.ts +233 -0
- package/src/internal/machine/clusterRead.ts +207 -0
- package/src/internal/machine/clusterSqlStorage.ts +181 -0
- package/src/internal/machine/clusterStorageCheck.ts +274 -0
- package/src/internal/machine/clusterTarget.ts +154 -0
- package/src/internal/machine/clusterTimer.ts +58 -0
- package/src/internal/machine/clusterWake.ts +100 -0
- package/src/internal/machine/clusterWork.ts +269 -0
- package/src/internal/machine/command.ts +4 -4
- package/src/internal/machine/commandRuntime.ts +12 -24
- package/src/internal/machine/configuration.ts +0 -181
- package/src/internal/machine/errors.ts +11 -2
- package/src/internal/machine/executionPlan.ts +493 -263
- package/src/internal/machine/implementation.ts +6 -6
- package/src/internal/machine/inspectionRuntime.ts +1 -1
- package/src/internal/machine/invocationChanges.ts +89 -0
- package/src/internal/machine/{activities.ts → invocationDefinitions.ts} +10 -10
- package/src/internal/machine/invocationEvent.ts +35 -12
- package/src/internal/machine/invocationOutcome.ts +145 -0
- package/src/internal/machine/invocationResolution.ts +307 -0
- package/src/internal/machine/logicScope.ts +47 -0
- package/src/internal/machine/machine.ts +35 -100
- package/src/internal/machine/observation.ts +67 -2
- package/src/internal/machine/plannedSnapshot.ts +17 -20
- package/src/internal/machine/planner.ts +75 -99
- package/src/internal/machine/process.ts +78 -722
- package/src/internal/machine/protocol.ts +70 -26
- package/src/internal/machine/runtime.ts +198 -195
- package/src/internal/machine/runtimeCompiled.ts +496 -171
- package/src/internal/machine/runtimeProtocol.ts +416 -305
- package/src/internal/machine/stateDefinition.ts +0 -5
- package/src/internal/machine/step.ts +1518 -0
- package/src/internal/machine/stepHost.ts +634 -0
- package/src/internal/machine/symbols.ts +3 -14
- package/src/internal/machine/transition.ts +11 -11
- package/src/internal/testing/machine/check.ts +240 -36
- package/src/internal/testing/machine/exploration.ts +42 -3
- package/src/internal/testing/machine/format.ts +1 -1
- package/src/internal/testing/machine/probe.ts +2 -1
- package/src/internal/testing/machine/runtime.ts +15 -5
- package/src/internal/testing/machine/trace.ts +261 -41
- package/src/internal/testing/machine/transitionCoverage.ts +1 -1
- package/src/internal/testing/machine/verification.ts +11 -5
- package/src/internal/testing/machine/work.ts +101 -0
- package/src/testing/MachineTest.ts +268 -44
- package/src/unstable/cluster/ClusterMachine.ts +1183 -59
- package/src/unstable/cluster/ClusterMachineProxy.ts +372 -0
- package/src/unstable/cluster/SqlMachineStorage.ts +136 -0
- package/src/unstable/cluster/index.ts +15 -0
- package/src/unstable/reactivity/AtomMachine.ts +27 -88
- package/dist/internal/machine/activities.d.ts.map +0 -1
- package/dist/internal/machine/activities.js.map +0 -1
- package/dist/internal/machine/invocation.d.ts +0 -33
- package/dist/internal/machine/invocation.d.ts.map +0 -1
- package/dist/internal/machine/invocation.js +0 -220
- package/dist/internal/machine/invocation.js.map +0 -1
- package/dist/internal/machine/invocationDefinition.d.ts.map +0 -1
- package/dist/internal/machine/invocationDefinition.js.map +0 -1
- package/dist/internal/machine/requirements.d.ts +0 -4
- package/dist/internal/machine/requirements.d.ts.map +0 -1
- package/dist/internal/machine/requirements.js +0 -2
- package/dist/internal/machine/requirements.js.map +0 -1
- package/dist/internal/machine/runtimeGeneric.d.ts +0 -3
- package/dist/internal/machine/runtimeGeneric.d.ts.map +0 -1
- package/dist/internal/machine/runtimeGeneric.js +0 -465
- package/dist/internal/machine/runtimeGeneric.js.map +0 -1
- package/src/internal/machine/invocation.ts +0 -376
- package/src/internal/machine/requirements.ts +0 -11
- package/src/internal/machine/runtimeGeneric.ts +0 -797
package/src/Machine.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Schema-first machine
|
|
2
|
+
* Schema-first machine models.
|
|
3
|
+
*
|
|
4
|
+
* This module declares machines, plans their steps, encodes their snapshots, and
|
|
5
|
+
* defines the contracts their types mention. It runs nothing: a host executes a
|
|
6
|
+
* machine, such as `LocalMachine` in memory or `ClusterMachine` as a Cluster
|
|
7
|
+
* entity.
|
|
3
8
|
*
|
|
4
9
|
* @since 0.4.0
|
|
5
10
|
*/
|
|
@@ -15,7 +20,8 @@ import type * as Schema from "effect/Schema"
|
|
|
15
20
|
import type * as Scope from "effect/Scope"
|
|
16
21
|
import type * as Stream from "effect/Stream"
|
|
17
22
|
import type * as Types from "effect/Types"
|
|
18
|
-
import type
|
|
23
|
+
import type { ChildMachineRuntime, MachineRuntime } from "./internal/machine/capability.js"
|
|
24
|
+
import type * as InvocationDefinitions from "./internal/machine/invocationDefinitions.js"
|
|
19
25
|
import type {
|
|
20
26
|
ChildAlreadyExistsError,
|
|
21
27
|
InfiniteTransitionError,
|
|
@@ -25,10 +31,8 @@ import type {
|
|
|
25
31
|
StoppedError
|
|
26
32
|
} from "./internal/machine/machine.js"
|
|
27
33
|
import * as internal from "./internal/machine/machine.js"
|
|
28
|
-
import { InitialEventTypeId } from "./internal/machine/machine.js"
|
|
34
|
+
import { InitialEventTypeId, InvocationEventTypeId } from "./internal/machine/machine.js"
|
|
29
35
|
import type { EnsureExecutable } from "./internal/machine/readiness.js"
|
|
30
|
-
import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js"
|
|
31
|
-
import type { MachineRuntime } from "./internal/machine/runtimeProtocol.js"
|
|
32
36
|
import type * as StateDefinition from "./internal/machine/stateDefinition.js"
|
|
33
37
|
import type * as Topology from "./internal/machine/topology.js"
|
|
34
38
|
|
|
@@ -56,12 +60,14 @@ export const TypeId: TypeId = "~effect/Machine"
|
|
|
56
60
|
// interface carries the string key as a brand only.
|
|
57
61
|
declare const MachineOutputStatesTypeId: "~effect/Machine/OutputStates"
|
|
58
62
|
declare const MachineTypeId: "~effect/Machine/TypeCarrier"
|
|
63
|
+
declare const MachineEffectResultsTypeId: "~effect/Machine/EffectResults"
|
|
59
64
|
declare const EventConstructionTypeId: "~effect/Machine/EventConstruction"
|
|
60
65
|
declare const EmittedEventConstructionTypeId: "~effect/Machine/EmittedEventConstruction"
|
|
61
66
|
declare const EventProtocolTypeId: "~effect/Machine/EventProtocol"
|
|
62
67
|
declare const ParentModeTypeId: "~effect/Machine/ParentMode"
|
|
63
|
-
declare const ChildMachineLogicTypeId: "~effect/Machine/ChildMachineLogic"
|
|
64
68
|
declare const InvokeTypeId: "~effect/Machine/Invoke"
|
|
69
|
+
declare const InvocationSupportTypeId: "~effect/Machine/InvocationSupport"
|
|
70
|
+
declare const MachineStepStateTypeId: "~effect/Machine/MachineStep/State"
|
|
65
71
|
declare const StateConstructionTypeId: "~effect/Machine/StateConstruction"
|
|
66
72
|
declare const TargetSnapshotTypeId: "~effect/Machine/TargetSnapshot"
|
|
67
73
|
declare const HistoryTargetTypeId: "~effect/Machine/HistoryTarget"
|
|
@@ -111,6 +117,56 @@ export const InitialEvent: InitialEvent = { _tag: InitialEventTypeId }
|
|
|
111
117
|
*/
|
|
112
118
|
export const isInitialEvent = (u: unknown): u is InitialEvent => hasProperty(u, "_tag") && u._tag === InitialEventTypeId
|
|
113
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Type identifier used for the synthetic event of a step caused by invoked work.
|
|
122
|
+
*
|
|
123
|
+
* @category type IDs
|
|
124
|
+
* @since 0.48.0
|
|
125
|
+
*/
|
|
126
|
+
export { InvocationEventTypeId }
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Synthetic event passed to lifecycle callbacks of a step that invoked work
|
|
130
|
+
* caused: its output, typed failure, stream element, or child snapshot.
|
|
131
|
+
*
|
|
132
|
+
* **Details**
|
|
133
|
+
*
|
|
134
|
+
* An outcome is not an event of the machine's protocol, so the states that its
|
|
135
|
+
* transition enters and exits, and the work they start, receive this marker as
|
|
136
|
+
* their `event`, as they receive `InitialEvent` while the initial state
|
|
137
|
+
* settles. `path` and `id` name the state that invoked the work and the
|
|
138
|
+
* invocation, and `kind` names what the work reported. The reported value
|
|
139
|
+
* itself is available to the transition that handles it, as `output`,
|
|
140
|
+
* `error`, `element`, or `snapshot`.
|
|
141
|
+
*
|
|
142
|
+
* **Gotchas**
|
|
143
|
+
*
|
|
144
|
+
* A host that restarts work after a recovery, such as `ClusterMachine`, passes
|
|
145
|
+
* `InitialEvent` to the input mapper of the restarted work, not this event.
|
|
146
|
+
*
|
|
147
|
+
* @category models
|
|
148
|
+
* @since 0.48.0
|
|
149
|
+
*/
|
|
150
|
+
export interface InvocationEvent {
|
|
151
|
+
readonly _tag: typeof InvocationEventTypeId
|
|
152
|
+
/** Path of the state that invoked the work. */
|
|
153
|
+
readonly path: string
|
|
154
|
+
/** Id of the invocation within that state. */
|
|
155
|
+
readonly id: string
|
|
156
|
+
/** What the work reported. */
|
|
157
|
+
readonly kind: "Done" | "Failure" | "Element" | "Snapshot"
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Returns `true` if a value is the synthetic event of a step caused by invoked
|
|
162
|
+
* work.
|
|
163
|
+
*
|
|
164
|
+
* @category guards
|
|
165
|
+
* @since 0.48.0
|
|
166
|
+
*/
|
|
167
|
+
export const isInvocationEvent = (u: unknown): u is InvocationEvent =>
|
|
168
|
+
hasProperty(u, "_tag") && u._tag === InvocationEventTypeId
|
|
169
|
+
|
|
114
170
|
type IsAny<A> = 0 extends (1 & A) ? true : false
|
|
115
171
|
|
|
116
172
|
/**
|
|
@@ -171,8 +227,6 @@ export interface Machine<
|
|
|
171
227
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
172
228
|
E = never,
|
|
173
229
|
R = never,
|
|
174
|
-
InitialE = never,
|
|
175
|
-
InitialR = never,
|
|
176
230
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
177
231
|
Output = never,
|
|
178
232
|
Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
@@ -189,8 +243,6 @@ export interface Machine<
|
|
|
189
243
|
UnhandledStates,
|
|
190
244
|
E,
|
|
191
245
|
R,
|
|
192
|
-
InitialE,
|
|
193
|
-
InitialR,
|
|
194
246
|
FinalStates,
|
|
195
247
|
Output,
|
|
196
248
|
Emits,
|
|
@@ -269,7 +321,7 @@ export interface Machine<
|
|
|
269
321
|
readonly handlers: Readonly<Record<string, unknown>>
|
|
270
322
|
|
|
271
323
|
/** @internal */
|
|
272
|
-
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States
|
|
324
|
+
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States>
|
|
273
325
|
/** @internal */
|
|
274
326
|
readonly initialDefinition: Machine.InitialDefinition
|
|
275
327
|
}
|
|
@@ -292,8 +344,6 @@ export interface Definition<
|
|
|
292
344
|
States extends Machine.StateSchemas,
|
|
293
345
|
Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
294
346
|
Input extends Schema.Top = typeof Schema.Void,
|
|
295
|
-
InitialE = never,
|
|
296
|
-
InitialR = never,
|
|
297
347
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
298
348
|
Output = never,
|
|
299
349
|
Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
@@ -309,8 +359,6 @@ export interface Definition<
|
|
|
309
359
|
Machine.StateIdentifier<States>,
|
|
310
360
|
never,
|
|
311
361
|
never,
|
|
312
|
-
InitialE,
|
|
313
|
-
InitialR,
|
|
314
362
|
FinalStates,
|
|
315
363
|
Output,
|
|
316
364
|
Emits,
|
|
@@ -357,8 +405,6 @@ export interface Definition<
|
|
|
357
405
|
Events,
|
|
358
406
|
Emits,
|
|
359
407
|
Input,
|
|
360
|
-
InitialE,
|
|
361
|
-
InitialR,
|
|
362
408
|
FinalStates,
|
|
363
409
|
Output,
|
|
364
410
|
InputEvents,
|
|
@@ -419,8 +465,17 @@ export {
|
|
|
419
465
|
*/
|
|
420
466
|
MachineSchemaEncodeError,
|
|
421
467
|
/**
|
|
422
|
-
* Error
|
|
423
|
-
*
|
|
468
|
+
* Error raised when invoked work uses an operation that requires a local
|
|
469
|
+
* machine process, on a host that does not provide one.
|
|
470
|
+
*
|
|
471
|
+
* **Details**
|
|
472
|
+
*
|
|
473
|
+
* `ClusterMachine` raises it when work reads `self.sessionId`, calls
|
|
474
|
+
* `self.send`, or calls an operation of `children`. The step functions of
|
|
475
|
+
* {@link toStep} raise it when work calls an operation on children and the
|
|
476
|
+
* host passed no `children`. It is a defect rather than a typed failure,
|
|
477
|
+
* because the same work runs correctly on a local machine.
|
|
478
|
+
* `operation` names the refused operation.
|
|
424
479
|
*
|
|
425
480
|
* @category errors
|
|
426
481
|
* @since 0.4.0
|
|
@@ -446,8 +501,38 @@ export {
|
|
|
446
501
|
|
|
447
502
|
export type {
|
|
448
503
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
504
|
+
* Capability to act on the child machines that the states of the running
|
|
505
|
+
* machine invoke, required by `sendTo` and `stopChild` with the descriptor of
|
|
506
|
+
* a child machine.
|
|
507
|
+
*
|
|
508
|
+
* **When to use**
|
|
509
|
+
*
|
|
510
|
+
* Name this requirement when annotating a reusable helper built from those
|
|
511
|
+
* operations, or when exporting a value whose inferred type includes it.
|
|
512
|
+
*
|
|
513
|
+
* **Details**
|
|
514
|
+
*
|
|
515
|
+
* The model declares this capability, and a host provides it to the work it
|
|
516
|
+
* runs. `LocalMachine` and `ClusterMachine` provide it, also when `AtomMachine`
|
|
517
|
+
* hosts the machine. Unlike {@link MachineRuntime}, it starts no process, so a
|
|
518
|
+
* host that runs child machines provides it.
|
|
519
|
+
*
|
|
520
|
+
* `Machine.Machine.Services` contains it when the work that a state invokes
|
|
521
|
+
* requires it, or when the machine of an invoked child does.
|
|
522
|
+
* `LocalMachine.RequiredServices` removes it.
|
|
523
|
+
*
|
|
524
|
+
* **Gotchas**
|
|
525
|
+
*
|
|
526
|
+
* Only the type is public: hosts of this library provide the service, and it
|
|
527
|
+
* cannot be constructed elsewhere.
|
|
528
|
+
*
|
|
529
|
+
* @category services
|
|
530
|
+
* @since 0.48.0
|
|
531
|
+
*/
|
|
532
|
+
ChildMachineRuntime,
|
|
533
|
+
/**
|
|
534
|
+
* Capability to act on the processes of the running machine, required by
|
|
535
|
+
* `spawn`, and by `sendTo` and `stopChild` with a child address.
|
|
451
536
|
*
|
|
452
537
|
* **When to use**
|
|
453
538
|
*
|
|
@@ -456,108 +541,103 @@ export type {
|
|
|
456
541
|
*
|
|
457
542
|
* **Details**
|
|
458
543
|
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
*
|
|
462
|
-
*
|
|
544
|
+
* The model declares this capability, and a host provides it to the work it
|
|
545
|
+
* runs. `LocalMachine` provides it, also when `AtomMachine` hosts the machine.
|
|
546
|
+
*
|
|
547
|
+
* `Machine.Machine.Services` contains it when the Effect, Stream, or `Logic` that
|
|
548
|
+
* a state invokes requires it, or when the machine of an invoked child does. A
|
|
549
|
+
* host that provides it runs every process that the work spawns, whatever that
|
|
550
|
+
* process invokes. `LocalMachine.RequiredServices` removes it.
|
|
551
|
+
*
|
|
552
|
+
* **Gotchas**
|
|
553
|
+
*
|
|
554
|
+
* `ClusterMachine` does not provide it, so `ClusterMachine.make` does not compile
|
|
555
|
+
* for a machine whose services contain it.
|
|
556
|
+
*
|
|
557
|
+
* Only the type is public: hosts of this library provide the service, and it
|
|
558
|
+
* cannot be constructed elsewhere.
|
|
463
559
|
*
|
|
464
560
|
* @category services
|
|
465
561
|
* @since 0.47.0
|
|
466
562
|
*/
|
|
467
563
|
MachineRuntime
|
|
468
|
-
} from "./internal/machine/
|
|
469
|
-
|
|
470
|
-
const RuntimeRequirementTypeId = "~effect/Machine/RuntimeRequirement"
|
|
471
|
-
const ActionRequirementTypeId = "~effect/Machine/ActionRequirement"
|
|
564
|
+
} from "./internal/machine/capability.js"
|
|
472
565
|
|
|
473
566
|
/**
|
|
474
|
-
*
|
|
475
|
-
*
|
|
567
|
+
* Requirement that a machine runs on a host which supports one kind of
|
|
568
|
+
* invocation.
|
|
476
569
|
*
|
|
477
|
-
*
|
|
478
|
-
* @since 0.4.0
|
|
479
|
-
*/
|
|
480
|
-
export interface ActionRequirement<Error, Requirements> {
|
|
481
|
-
readonly [ActionRequirementTypeId]: {
|
|
482
|
-
readonly error: Types.Covariant<Error>
|
|
483
|
-
readonly requirements: Types.Covariant<Requirements>
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* Extracts the typed error channel of staged machine actions.
|
|
570
|
+
* **When to use**
|
|
489
571
|
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
|
|
493
|
-
export type ActionError<Requirements> = Requirements extends ActionRequirement<infer Error, any> ? Error : never
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Extracts the service requirements of staged machine actions.
|
|
572
|
+
* Name this requirement when annotating a machine that invokes a Stream, a
|
|
573
|
+
* `Logic`, or a child machine, or when a host states in its types which
|
|
574
|
+
* invocations it runs.
|
|
497
575
|
*
|
|
498
|
-
*
|
|
499
|
-
* @since 0.4.0
|
|
500
|
-
*/
|
|
501
|
-
export type ActionServices<Requirements> = Requirements extends ActionRequirement<any, infer Services> ? Services
|
|
502
|
-
: never
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Removes staged action requirements from machine planning services.
|
|
576
|
+
* **Details**
|
|
506
577
|
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
*
|
|
578
|
+
* `Machine.Machine.Services` contains one for each kind that the states of a
|
|
579
|
+
* machine invoke. Registering a source without invoking it adds nothing. A
|
|
580
|
+
* machine that invokes a child machine also carries the requirements of that
|
|
581
|
+
* child.
|
|
582
|
+
*
|
|
583
|
+
* Every host runs Effects and timers, so no requirement stands for them.
|
|
584
|
+
* `LocalMachine` supports every kind, also when `AtomMachine` hosts the machine,
|
|
585
|
+
* and `LocalMachine.RequiredServices` removes them all. `ClusterMachine` supports
|
|
586
|
+
* child machines, which it runs as entities of their own, and
|
|
587
|
+
* `ClusterMachine.make` does not compile for a machine that invokes a Stream or
|
|
588
|
+
* a `Logic`, whose progress it cannot store.
|
|
589
|
+
*
|
|
590
|
+
* **Gotchas**
|
|
591
|
+
*
|
|
592
|
+
* This exists in types only. Nothing constructs it, and it is not provided as a
|
|
593
|
+
* service.
|
|
514
594
|
*
|
|
515
595
|
* @category utility types
|
|
516
|
-
* @since 0.
|
|
596
|
+
* @since 0.48.0
|
|
517
597
|
*/
|
|
518
|
-
export
|
|
519
|
-
|
|
520
|
-
|
|
598
|
+
export interface InvocationSupport<out Kind extends InvocationSupport.Kind> {
|
|
599
|
+
readonly [InvocationSupportTypeId]: Kind
|
|
600
|
+
}
|
|
521
601
|
|
|
522
602
|
/**
|
|
523
|
-
*
|
|
524
|
-
*
|
|
603
|
+
* Namespace containing type-level members associated with
|
|
604
|
+
* {@link InvocationSupport}.
|
|
525
605
|
*
|
|
526
|
-
* @category
|
|
527
|
-
* @since 0.
|
|
606
|
+
* @category utility types
|
|
607
|
+
* @since 0.48.0
|
|
528
608
|
*/
|
|
529
|
-
export
|
|
530
|
-
/**
|
|
531
|
-
* Queues an event for the current machine macrostep.
|
|
532
|
-
*
|
|
533
|
-
* @since 0.4.0
|
|
534
|
-
*/
|
|
535
|
-
readonly raise: (event: Machine.EventInput<Events>) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
|
|
536
|
-
|
|
609
|
+
export declare namespace InvocationSupport {
|
|
537
610
|
/**
|
|
538
|
-
*
|
|
611
|
+
* Kinds of invocation that a host may not support.
|
|
539
612
|
*
|
|
540
|
-
* @
|
|
613
|
+
* @category models
|
|
614
|
+
* @since 0.48.0
|
|
541
615
|
*/
|
|
542
|
-
|
|
543
|
-
event: Machine.EmittedEventInput<Emits>
|
|
544
|
-
) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
|
|
616
|
+
export type Kind = "Stream" | "Logic" | "Child"
|
|
545
617
|
}
|
|
546
618
|
|
|
547
619
|
/**
|
|
548
620
|
* Minimal typed target accepted by inter-machine send commands.
|
|
549
621
|
*
|
|
550
|
-
* `send` reports whether the event was accepted for delivery.
|
|
551
|
-
*
|
|
552
|
-
* strengthens that guarantee.
|
|
622
|
+
* `send` reports whether the event was accepted for delivery. When the target
|
|
623
|
+
* processes it is up to the host that runs the target.
|
|
553
624
|
*
|
|
554
625
|
* @category models
|
|
555
626
|
* @since 0.12.0
|
|
556
627
|
*/
|
|
557
628
|
export interface MachineTarget<in Event> {
|
|
629
|
+
/** Id of the target, such as its machine definition id or child address. */
|
|
558
630
|
readonly id: string
|
|
631
|
+
|
|
632
|
+
/** Unique identity of the running target. */
|
|
559
633
|
readonly sessionId: string
|
|
560
|
-
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Accepts an event for delivery. Fails with `StoppedError` once the target has
|
|
637
|
+
* terminated, and with `MachineSchemaDecodeError` when the target rejects an
|
|
638
|
+
* event that its schema refuses.
|
|
639
|
+
*/
|
|
640
|
+
readonly send: (event: Event) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>
|
|
561
641
|
}
|
|
562
642
|
|
|
563
643
|
/**
|
|
@@ -626,7 +706,7 @@ export type MachineReferences<
|
|
|
626
706
|
* @category models
|
|
627
707
|
* @since 0.4.0
|
|
628
708
|
*/
|
|
629
|
-
export interface
|
|
709
|
+
export interface Commands<in Events, in Emits> {
|
|
630
710
|
/** Raises an event inside the current macrostep. */
|
|
631
711
|
readonly raise: (event: Machine.EventInput<Events>) => void
|
|
632
712
|
|
|
@@ -650,6 +730,8 @@ export interface Enqueue<in Events, in Emits> {
|
|
|
650
730
|
/**
|
|
651
731
|
* A closed machine command recorded by a synchronous transition.
|
|
652
732
|
*
|
|
733
|
+
* Planning only records commands. The host that runs the machine executes them.
|
|
734
|
+
*
|
|
653
735
|
* @category models
|
|
654
736
|
* @since 0.4.0
|
|
655
737
|
*/
|
|
@@ -664,35 +746,6 @@ export type Command =
|
|
|
664
746
|
readonly child: ChildMachine.Any | ChildAddress<never>
|
|
665
747
|
}
|
|
666
748
|
|
|
667
|
-
/**
|
|
668
|
-
* Namespace containing type-level members associated with `Runtime`.
|
|
669
|
-
*
|
|
670
|
-
* @category models
|
|
671
|
-
* @since 0.4.0
|
|
672
|
-
*/
|
|
673
|
-
export declare namespace Runtime {
|
|
674
|
-
/**
|
|
675
|
-
* Opaque service requirement for a machine runtime capability.
|
|
676
|
-
*
|
|
677
|
-
* @category services
|
|
678
|
-
* @since 0.4.0
|
|
679
|
-
*/
|
|
680
|
-
export interface Requirement<Events, Emits> {
|
|
681
|
-
readonly [RuntimeRequirementTypeId]: {
|
|
682
|
-
readonly events: Events
|
|
683
|
-
readonly emits: Emits
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<
|
|
689
|
-
infer RequiredEvents,
|
|
690
|
-
infer RequiredEmits
|
|
691
|
-
> ? IsAny<Requirements> extends true ? never
|
|
692
|
-
: [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements
|
|
693
|
-
: Requirements
|
|
694
|
-
: never
|
|
695
|
-
|
|
696
749
|
type StateDefinitionError<
|
|
697
750
|
Message extends string,
|
|
698
751
|
Path extends PropertyKey = never,
|
|
@@ -1148,7 +1201,8 @@ type SpawnResult<State, Event, Error, Requirements, Output, SpawnError, InitialE
|
|
|
1148
1201
|
>
|
|
1149
1202
|
|
|
1150
1203
|
/**
|
|
1151
|
-
* Represents the active or terminal lifecycle state of a running machine
|
|
1204
|
+
* Represents the active or terminal lifecycle state of a running machine, as its
|
|
1205
|
+
* host publishes it.
|
|
1152
1206
|
*
|
|
1153
1207
|
* **Details**
|
|
1154
1208
|
*
|
|
@@ -1170,7 +1224,7 @@ export type RuntimeSnapshot<State, Error = never, Output = never> =
|
|
|
1170
1224
|
readonly output: Output
|
|
1171
1225
|
}
|
|
1172
1226
|
| {
|
|
1173
|
-
readonly status: "
|
|
1227
|
+
readonly status: "failed"
|
|
1174
1228
|
readonly state: State
|
|
1175
1229
|
readonly cause: Cause.Cause<Error>
|
|
1176
1230
|
}
|
|
@@ -1179,190 +1233,6 @@ export type RuntimeSnapshot<State, Error = never, Output = never> =
|
|
|
1179
1233
|
readonly state: State
|
|
1180
1234
|
}
|
|
1181
1235
|
|
|
1182
|
-
/**
|
|
1183
|
-
* Live, root-scoped records describing one prepared machine tree.
|
|
1184
|
-
*
|
|
1185
|
-
* Inspection records deliberately erase machine-specific values to `unknown`:
|
|
1186
|
-
* one stream may contain unrelated root, child-machine, and `Logic` protocols.
|
|
1187
|
-
* The record structure remains a closed discriminated union, while typed
|
|
1188
|
-
* application observation continues through `changes` and `emissions`.
|
|
1189
|
-
* Records retain decoded local events and snapshots and are not themselves a
|
|
1190
|
-
* stable JSON export format. Telemetry exporters must project process-local
|
|
1191
|
-
* values into an explicit portable representation.
|
|
1192
|
-
*
|
|
1193
|
-
* @category models
|
|
1194
|
-
* @since 0.13.0
|
|
1195
|
-
*/
|
|
1196
|
-
export declare namespace Inspection {
|
|
1197
|
-
/** Read-only identity of a local machine endpoint. */
|
|
1198
|
-
export interface Endpoint {
|
|
1199
|
-
readonly id: string
|
|
1200
|
-
readonly sessionId: string
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
/** Read-only identity of a runtime represented in the inspection tree. */
|
|
1204
|
-
export interface Subject extends Endpoint {
|
|
1205
|
-
readonly kind: "Machine" | "Logic"
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
/** Causal origin of an inspected runtime. */
|
|
1209
|
-
export type Origin =
|
|
1210
|
-
| { readonly _tag: "Root" }
|
|
1211
|
-
| {
|
|
1212
|
-
readonly _tag: "Invoke"
|
|
1213
|
-
readonly ownerPath: string
|
|
1214
|
-
readonly invokeId: string
|
|
1215
|
-
}
|
|
1216
|
-
| {
|
|
1217
|
-
readonly _tag: "Spawn"
|
|
1218
|
-
readonly address: string | undefined
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
/** Causal owner of a send or emission. */
|
|
1222
|
-
export type Causation =
|
|
1223
|
-
| { readonly _tag: "Initialization" }
|
|
1224
|
-
| { readonly _tag: "Macrostep"; readonly macrostepId: number }
|
|
1225
|
-
| { readonly _tag: "Activity"; readonly activitySessionId: string }
|
|
1226
|
-
|
|
1227
|
-
/** Closed command projection safe for observation. */
|
|
1228
|
-
export type Command =
|
|
1229
|
-
| {
|
|
1230
|
-
readonly _tag: "SendTo"
|
|
1231
|
-
readonly target: Endpoint | { readonly id: string }
|
|
1232
|
-
readonly event: unknown
|
|
1233
|
-
}
|
|
1234
|
-
| {
|
|
1235
|
-
readonly _tag: "Stop"
|
|
1236
|
-
readonly target: Endpoint | { readonly id: string }
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
/** One statechart microstep in a committed macrostep. */
|
|
1240
|
-
export interface Microstep {
|
|
1241
|
-
readonly event: unknown
|
|
1242
|
-
readonly transitions: ReadonlyArray<Machine.RetainedTransition>
|
|
1243
|
-
readonly raisedEvents: ReadonlyArray<unknown>
|
|
1244
|
-
readonly emittedEvents: ReadonlyArray<unknown>
|
|
1245
|
-
readonly commands: ReadonlyArray<Command>
|
|
1246
|
-
readonly exitPaths: ReadonlyArray<string>
|
|
1247
|
-
readonly entryPaths: ReadonlyArray<string>
|
|
1248
|
-
readonly changed: boolean
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
/** Common ordering and identity fields for every record. */
|
|
1252
|
-
export interface Base {
|
|
1253
|
-
/** Total publication order within this prepared root. */
|
|
1254
|
-
readonly sequence: number
|
|
1255
|
-
/** Session id of the prepared root that owns this inspection stream. */
|
|
1256
|
-
readonly rootSessionId: string
|
|
1257
|
-
/** Runtime instance described by this record. */
|
|
1258
|
-
readonly subject: Subject
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
/** Announces allocation of a root or owned process identity. */
|
|
1262
|
-
export interface Created extends Base {
|
|
1263
|
-
readonly _tag: "Created"
|
|
1264
|
-
readonly parent: Subject | undefined
|
|
1265
|
-
readonly origin: Origin
|
|
1266
|
-
/** Compiled statechart definition; absent for generic `Logic`. */
|
|
1267
|
-
readonly definition: Machine.Any | undefined
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
/** Announces successful initialization. */
|
|
1271
|
-
export interface Initialized extends Base {
|
|
1272
|
-
readonly _tag: "Initialized"
|
|
1273
|
-
readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown>
|
|
1274
|
-
readonly initialEntryPaths: ReadonlyArray<string>
|
|
1275
|
-
readonly microsteps: ReadonlyArray<Microstep>
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
/** Announces failure before an initial runtime snapshot exists. */
|
|
1279
|
-
export interface StartFailed extends Base {
|
|
1280
|
-
readonly _tag: "StartFailed"
|
|
1281
|
-
readonly cause: Cause.Cause<unknown>
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
/** Announces acceptance of an event by a local mailbox. */
|
|
1285
|
-
export interface EventSent extends Base {
|
|
1286
|
-
readonly _tag: "EventSent"
|
|
1287
|
-
readonly deliveryId: number
|
|
1288
|
-
readonly source: Subject | undefined
|
|
1289
|
-
readonly target: Endpoint
|
|
1290
|
-
readonly event: unknown
|
|
1291
|
-
readonly causedBy: Causation | undefined
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
/** Announces complete processing of one statechart mailbox event. */
|
|
1295
|
-
export interface EventProcessed extends Base {
|
|
1296
|
-
readonly _tag: "EventProcessed"
|
|
1297
|
-
readonly macrostepId: number
|
|
1298
|
-
readonly deliveryId: number
|
|
1299
|
-
readonly source: Subject | undefined
|
|
1300
|
-
readonly event: unknown
|
|
1301
|
-
readonly before: RuntimeSnapshot<unknown, unknown, unknown>
|
|
1302
|
-
readonly after: RuntimeSnapshot<unknown, unknown, unknown>
|
|
1303
|
-
readonly handled: boolean
|
|
1304
|
-
readonly configurationChanged: boolean
|
|
1305
|
-
readonly microsteps: ReadonlyArray<Microstep>
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
/** Announces a direct state update made by generic `Logic`. */
|
|
1309
|
-
export interface StateChanged extends Base {
|
|
1310
|
-
readonly _tag: "StateChanged"
|
|
1311
|
-
readonly before: unknown
|
|
1312
|
-
readonly after: unknown
|
|
1313
|
-
readonly causedByDeliveryId: number | undefined
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
/** Announces actual publication on a machine's domain emission stream. */
|
|
1317
|
-
export interface Emitted extends Base {
|
|
1318
|
-
readonly _tag: "Emitted"
|
|
1319
|
-
readonly emission: unknown
|
|
1320
|
-
readonly causedBy: Causation | undefined
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1323
|
-
/** Identity of one Effect or timer invocation run. */
|
|
1324
|
-
export interface Activity {
|
|
1325
|
-
readonly id: string
|
|
1326
|
-
readonly sessionId: string
|
|
1327
|
-
readonly owner: Subject
|
|
1328
|
-
readonly ownerPath: string
|
|
1329
|
-
readonly kind: "Effect" | "Stream" | "Timer"
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
/** Announces an Effect, Stream, or timer invocation starting. */
|
|
1333
|
-
export interface ActivityStarted extends Base {
|
|
1334
|
-
readonly _tag: "ActivityStarted"
|
|
1335
|
-
readonly activity: Activity
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
/** Announces an Effect or timer invocation outcome. */
|
|
1339
|
-
export interface ActivityStopped extends Base {
|
|
1340
|
-
readonly _tag: "ActivityStopped"
|
|
1341
|
-
readonly activity: Activity
|
|
1342
|
-
/** Success or failure from the invoke; interruption means its owner stopped it. */
|
|
1343
|
-
readonly exit: Exit.Exit<unknown, unknown>
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
/** Announces a terminal local runtime snapshot. */
|
|
1347
|
-
export interface Terminated extends Base {
|
|
1348
|
-
readonly _tag: "Terminated"
|
|
1349
|
-
readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown>
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
/** Complete live inspection protocol. */
|
|
1353
|
-
export type Event =
|
|
1354
|
-
| Created
|
|
1355
|
-
| Initialized
|
|
1356
|
-
| StartFailed
|
|
1357
|
-
| EventSent
|
|
1358
|
-
| EventProcessed
|
|
1359
|
-
| StateChanged
|
|
1360
|
-
| Emitted
|
|
1361
|
-
| ActivityStarted
|
|
1362
|
-
| ActivityStopped
|
|
1363
|
-
| Terminated
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
1236
|
/**
|
|
1367
1237
|
* Represents a classified terminal outcome derived from a runtime snapshot.
|
|
1368
1238
|
*
|
|
@@ -1379,87 +1249,46 @@ export type RuntimeOutcome<State, Error = never, Output = never> =
|
|
|
1379
1249
|
readonly _tag: "Failure"
|
|
1380
1250
|
readonly error: Error
|
|
1381
1251
|
readonly cause: Cause.Cause<Error>
|
|
1382
|
-
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "
|
|
1252
|
+
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "failed" }>
|
|
1383
1253
|
}
|
|
1384
1254
|
| {
|
|
1385
1255
|
readonly _tag: "Defect"
|
|
1386
1256
|
readonly defect: unknown
|
|
1387
1257
|
readonly cause: Cause.Cause<Error>
|
|
1388
|
-
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "
|
|
1258
|
+
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "failed" }>
|
|
1389
1259
|
}
|
|
1390
1260
|
| {
|
|
1391
1261
|
readonly _tag: "Interrupted"
|
|
1392
1262
|
readonly cause: Cause.Cause<Error>
|
|
1393
|
-
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "
|
|
1263
|
+
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "failed" }>
|
|
1394
1264
|
}
|
|
1395
1265
|
| {
|
|
1396
1266
|
readonly _tag: "Cause"
|
|
1397
1267
|
readonly cause: Cause.Cause<Error>
|
|
1398
|
-
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "
|
|
1268
|
+
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "failed" }>
|
|
1399
1269
|
}
|
|
1400
1270
|
| {
|
|
1401
1271
|
readonly _tag: "Stopped"
|
|
1402
1272
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "stopped" }>
|
|
1403
1273
|
}
|
|
1404
1274
|
|
|
1405
|
-
/**
|
|
1406
|
-
* A fresh machine whose observable streams exist before initialization.
|
|
1407
|
-
*
|
|
1408
|
-
* Subscribe to `emissions` before evaluating `start` when initial-entry
|
|
1409
|
-
* emissions must be observed. `start` is one-shot: concurrent and repeated
|
|
1410
|
-
* evaluations share the same initialization and running reference, and the
|
|
1411
|
-
* `Scope` of the first evaluation owns the machine.
|
|
1412
|
-
*
|
|
1413
|
-
* @category models
|
|
1414
|
-
* @since 0.11.0
|
|
1415
|
-
*/
|
|
1416
|
-
export interface Prepared<out State, in Event, out Error, out Output, out Emitted, out StartError, StartRequirements> {
|
|
1417
|
-
/** Stable machine definition id, or a generated fallback when none was declared. */
|
|
1418
|
-
readonly id: string
|
|
1419
|
-
|
|
1420
|
-
/** Unique identity reserved for this prepared machine instance. */
|
|
1421
|
-
readonly sessionId: string
|
|
1422
|
-
|
|
1423
|
-
/** Waits for startup, then streams the initial lifecycle snapshot and later changes. */
|
|
1424
|
-
readonly changes: Stream.Stream<RuntimeSnapshot<State, Error, Output>, StartError>
|
|
1425
|
-
|
|
1426
|
-
/** Streams ephemeral notifications published after subscription. */
|
|
1427
|
-
readonly emissions: Stream.Stream<Emitted>
|
|
1428
|
-
|
|
1429
|
-
/**
|
|
1430
|
-
* Streams ordered operational records for this root and every locally owned
|
|
1431
|
-
* descendant. The stream is hot, non-replayed, never fails, and completes
|
|
1432
|
-
* after the prepared root terminates. Subscribe before evaluating `start` to
|
|
1433
|
-
* observe initialization.
|
|
1434
|
-
*/
|
|
1435
|
-
readonly inspection: Stream.Stream<Inspection.Event>
|
|
1436
|
-
|
|
1437
|
-
/** Initializes this machine once, owned by the first evaluating `Scope`, and returns its running reference. */
|
|
1438
|
-
readonly start: Effect.Effect<MachineRef<State, Event, Error, Output, Emitted>, StartError, StartRequirements>
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
1275
|
/**
|
|
1442
1276
|
* Provides access to a running machine's state, lifecycle, event input, and
|
|
1443
1277
|
* termination operations.
|
|
1444
1278
|
*
|
|
1279
|
+
* **Details**
|
|
1280
|
+
*
|
|
1281
|
+
* This is the contract every host's reference satisfies. `send` reports whether
|
|
1282
|
+
* an event was accepted for delivery. Errors that occur while processing an
|
|
1283
|
+
* accepted event are observed through `snapshot`, `changes`, or `join`. Sending
|
|
1284
|
+
* after termination fails with `StoppedError`.
|
|
1285
|
+
*
|
|
1445
1286
|
* **Gotchas**
|
|
1446
1287
|
*
|
|
1447
|
-
*
|
|
1448
|
-
*
|
|
1449
|
-
*
|
|
1450
|
-
*
|
|
1451
|
-
* starts in the sender's turn and runs until it first suspends, so browser
|
|
1452
|
-
* APIs that require user activation, such as `window.open`, can run in the
|
|
1453
|
-
* first step of an invoked Effect. Work that suspends continues in the
|
|
1454
|
-
* background, and its outcome is handled in a later turn, even when the work
|
|
1455
|
-
* completes without suspending, so the entered state is always observed
|
|
1456
|
-
* before the outcome leaves it. An event sent while the machine is processing
|
|
1457
|
-
* is queued behind the current work. `changes` subscribers receive every committed
|
|
1458
|
-
* snapshot in order once the sender yields, with consecutive sends delivered
|
|
1459
|
-
* together. This guarantee belongs to `MachineRef`; a `MachineTarget` only
|
|
1460
|
-
* promises delivery. Errors that occur while processing an accepted event are
|
|
1461
|
-
* observed through `snapshot`, `changes`, or `join`. Sending after
|
|
1462
|
-
* termination fails with `StoppedError`.
|
|
1288
|
+
* When an accepted event is processed is up to the host. Code written against
|
|
1289
|
+
* `MachineRef` cannot assume that `snapshot` reflects an event once `send`
|
|
1290
|
+
* returns. `LocalMachine.start` documents the delivery order that a reference to
|
|
1291
|
+
* a local machine adds to this contract.
|
|
1463
1292
|
*
|
|
1464
1293
|
* @category models
|
|
1465
1294
|
* @since 0.4.0
|
|
@@ -1491,16 +1320,22 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
1491
1320
|
/** Waits for machine output or fails when execution fails or is stopped. */
|
|
1492
1321
|
readonly join: Effect.Effect<Output, Error | StoppedError>
|
|
1493
1322
|
|
|
1494
|
-
/** Stops this machine instance and
|
|
1323
|
+
/** Stops this machine instance and the children it owns. */
|
|
1495
1324
|
readonly stop: Effect.Effect<void>
|
|
1496
1325
|
|
|
1497
1326
|
/**
|
|
1498
|
-
* Accepts an event for
|
|
1499
|
-
*
|
|
1500
|
-
* `
|
|
1501
|
-
*
|
|
1327
|
+
* Accepts an event for delivery. When the machine processes it is up to its
|
|
1328
|
+
* host. An event that the schema of the machine refuses is rejected with
|
|
1329
|
+
* `MachineSchemaDecodeError`, and the machine keeps running; once the machine
|
|
1330
|
+
* has ended, `send` fails with `StoppedError`.
|
|
1331
|
+
*
|
|
1332
|
+
* A transition that throws follows one rule on every host: the error goes to
|
|
1333
|
+
* the sender when one waits for the event to be processed, and otherwise the
|
|
1334
|
+
* machine fails with it. A `send` of `LocalMachine` returns before its event
|
|
1335
|
+
* is processed, so the machine fails; a `ClusterMachine` client waits, so it
|
|
1336
|
+
* is rejected and the machine goes on.
|
|
1502
1337
|
*/
|
|
1503
|
-
readonly send: (event: Event) => Effect.Effect<void, StoppedError>
|
|
1338
|
+
readonly send: (event: Event) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>
|
|
1504
1339
|
|
|
1505
1340
|
/**
|
|
1506
1341
|
* Returns the current directly owned child for a typed descriptor.
|
|
@@ -1522,7 +1357,12 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
1522
1357
|
}
|
|
1523
1358
|
|
|
1524
1359
|
/**
|
|
1525
|
-
*
|
|
1360
|
+
* Stateful process logic used by `spawn` and state-owned invocations.
|
|
1361
|
+
*
|
|
1362
|
+
* Logic describes a process by what it needs from a host: the capabilities of
|
|
1363
|
+
* `Logic.InitialContext` and `Logic.RunContext`. `LocalMachine` runs it as a process owned by
|
|
1364
|
+
* the machine. `ClusterMachine.make` does not compile for a machine that invokes
|
|
1365
|
+
* it.
|
|
1526
1366
|
*
|
|
1527
1367
|
* @category models
|
|
1528
1368
|
* @since 0.4.0
|
|
@@ -1536,26 +1376,26 @@ export interface Logic<
|
|
|
1536
1376
|
out InitialError = never
|
|
1537
1377
|
> {
|
|
1538
1378
|
/** Creates the initial process state and may spawn scoped child processes. */
|
|
1539
|
-
initial(
|
|
1379
|
+
initial(context: Logic.InitialContext<Event>): Effect.Effect<State, InitialError, Requirements>
|
|
1540
1380
|
|
|
1541
1381
|
/** Runs the stateful process loop until it produces output or fails. */
|
|
1542
|
-
run(context: Logic.
|
|
1382
|
+
run(context: Logic.RunContext<State, Event>): Effect.Effect<Output, Error, Requirements>
|
|
1543
1383
|
}
|
|
1544
1384
|
|
|
1545
1385
|
/**
|
|
1546
|
-
*
|
|
1386
|
+
* Capabilities a host gives to process logic.
|
|
1547
1387
|
*
|
|
1548
1388
|
* @category models
|
|
1549
1389
|
* @since 0.4.0
|
|
1550
1390
|
*/
|
|
1551
1391
|
export declare namespace Logic {
|
|
1552
1392
|
/**
|
|
1553
|
-
*
|
|
1393
|
+
* Endpoint of a process that can receive events and be stopped.
|
|
1554
1394
|
*
|
|
1555
1395
|
* @category models
|
|
1556
1396
|
* @since 0.4.0
|
|
1557
1397
|
*/
|
|
1558
|
-
export interface
|
|
1398
|
+
export interface Endpoint<in Event> {
|
|
1559
1399
|
/** Parent-local address id. */
|
|
1560
1400
|
readonly id: string
|
|
1561
1401
|
|
|
@@ -1565,8 +1405,12 @@ export declare namespace Logic {
|
|
|
1565
1405
|
/** Stops the addressed child process. */
|
|
1566
1406
|
readonly stop: Effect.Effect<void>
|
|
1567
1407
|
|
|
1568
|
-
/**
|
|
1569
|
-
|
|
1408
|
+
/**
|
|
1409
|
+
* Sends an event to the addressed process. When the endpoint belongs to a
|
|
1410
|
+
* machine whose event schema refuses the event, fails with
|
|
1411
|
+
* {@link MachineSchemaDecodeError} and leaves the machine running.
|
|
1412
|
+
*/
|
|
1413
|
+
readonly send: (event: Event) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>
|
|
1570
1414
|
}
|
|
1571
1415
|
|
|
1572
1416
|
/**
|
|
@@ -1610,28 +1454,40 @@ export declare namespace Logic {
|
|
|
1610
1454
|
}
|
|
1611
1455
|
|
|
1612
1456
|
/**
|
|
1613
|
-
*
|
|
1457
|
+
* Capabilities available while process logic initializes.
|
|
1614
1458
|
*
|
|
1615
1459
|
* @category models
|
|
1616
1460
|
* @since 0.4.0
|
|
1617
1461
|
*/
|
|
1618
|
-
export interface
|
|
1619
|
-
/**
|
|
1620
|
-
readonly self:
|
|
1462
|
+
export interface InitialContext<Event> {
|
|
1463
|
+
/** Endpoint of the process being initialized. */
|
|
1464
|
+
readonly self: Endpoint<Event>
|
|
1621
1465
|
|
|
1622
|
-
/**
|
|
1623
|
-
readonly parent:
|
|
1466
|
+
/** Endpoint of the owning process, when one exists. */
|
|
1467
|
+
readonly parent: Endpoint<unknown> | undefined
|
|
1624
1468
|
|
|
1625
|
-
/** Starts a child process owned by this
|
|
1469
|
+
/** Starts a child process owned by this process. */
|
|
1626
1470
|
readonly spawn: Spawn<Event>
|
|
1627
1471
|
|
|
1628
|
-
/**
|
|
1472
|
+
/**
|
|
1473
|
+
* Sends an event to a process endpoint, machine target, or typed
|
|
1474
|
+
* parent-local child address. When the addressed receiver is a machine
|
|
1475
|
+
* whose event schema refuses the event, fails with
|
|
1476
|
+
* {@link MachineSchemaDecodeError} and leaves the receiver running.
|
|
1477
|
+
*/
|
|
1629
1478
|
readonly sendTo: {
|
|
1630
|
-
<TargetEvent>(
|
|
1479
|
+
<TargetEvent>(
|
|
1480
|
+
target: Endpoint<TargetEvent>,
|
|
1481
|
+
event: TargetEvent
|
|
1482
|
+
): Effect.Effect<void, StoppedError | MachineSchemaDecodeError>
|
|
1483
|
+
<TargetEvent>(
|
|
1484
|
+
target: MachineTarget<TargetEvent>,
|
|
1485
|
+
event: TargetEvent
|
|
1486
|
+
): Effect.Effect<void, StoppedError | MachineSchemaDecodeError>
|
|
1631
1487
|
<Address extends ChildAddress<never>>(
|
|
1632
1488
|
id: Address,
|
|
1633
1489
|
event: ChildAddress.Event<Address>
|
|
1634
|
-
): Effect.Effect<void, StoppedError>
|
|
1490
|
+
): Effect.Effect<void, StoppedError | MachineSchemaDecodeError>
|
|
1635
1491
|
}
|
|
1636
1492
|
|
|
1637
1493
|
/** Stops a child process selected by its parent-local address. */
|
|
@@ -1639,12 +1495,12 @@ export declare namespace Logic {
|
|
|
1639
1495
|
}
|
|
1640
1496
|
|
|
1641
1497
|
/**
|
|
1642
|
-
*
|
|
1498
|
+
* Capabilities available while stateful process logic runs.
|
|
1643
1499
|
*
|
|
1644
1500
|
* @category models
|
|
1645
1501
|
* @since 0.4.0
|
|
1646
1502
|
*/
|
|
1647
|
-
export interface
|
|
1503
|
+
export interface RunContext<State, Event> extends InitialContext<Event> {
|
|
1648
1504
|
/** Waits for the next event delivered to this process. */
|
|
1649
1505
|
readonly receive: Effect.Effect<Event>
|
|
1650
1506
|
|
|
@@ -1672,8 +1528,8 @@ type InvokeLifecycleId = string & { readonly [ChildAddressTypeId]?: never }
|
|
|
1672
1528
|
*
|
|
1673
1529
|
* **Details**
|
|
1674
1530
|
*
|
|
1675
|
-
* The descriptor
|
|
1676
|
-
* Register it in `make({ children })` to invoke it by `src`, and pass a
|
|
1531
|
+
* The descriptor holds the child's id and machine definition, and nothing a host
|
|
1532
|
+
* needs to run the child: the host that starts it decides how. Register it in `make({ children })` to invoke it by `src`, and pass a
|
|
1677
1533
|
* descriptor for the same id and machine to `sendTo` and child lookup APIs, so
|
|
1678
1534
|
* state, event, error, and output types are inferred without separate
|
|
1679
1535
|
* annotations.
|
|
@@ -1689,9 +1545,6 @@ export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
|
1689
1545
|
|
|
1690
1546
|
/** Complete machine definition carried by this descriptor. */
|
|
1691
1547
|
readonly machine: M
|
|
1692
|
-
|
|
1693
|
-
/** @internal Brand of descriptors built by `child` and `childFamily`. */
|
|
1694
|
-
readonly [ChildMachineLogicTypeId]: typeof ChildMachineLogicTypeId
|
|
1695
1548
|
}
|
|
1696
1549
|
|
|
1697
1550
|
/**
|
|
@@ -1773,9 +1626,7 @@ export declare namespace ChildMachine {
|
|
|
1773
1626
|
* @since 0.20.0
|
|
1774
1627
|
*/
|
|
1775
1628
|
export type StartError<Child extends Any> = Child extends ChildMachine<string, infer M> ?
|
|
1776
|
-
| Machine.InitialError<M>
|
|
1777
1629
|
| Machine.Error<M>
|
|
1778
|
-
| ActionError<Machine.InitialServices<M> | Machine.Services<M>>
|
|
1779
1630
|
| InfiniteTransitionError
|
|
1780
1631
|
| MachineSchemaDecodeError
|
|
1781
1632
|
| StartupError
|
|
@@ -1783,18 +1634,20 @@ export declare namespace ChildMachine {
|
|
|
1783
1634
|
: never
|
|
1784
1635
|
|
|
1785
1636
|
/**
|
|
1786
|
-
* Services needed to initialize a spawned child machine
|
|
1637
|
+
* Services needed to initialize a spawned child machine, without
|
|
1638
|
+
* {@link MachineRuntime} and {@link InvocationSupport}.
|
|
1639
|
+
*
|
|
1640
|
+
* **Details**
|
|
1641
|
+
*
|
|
1642
|
+
* The process that spawns the child already runs on a host that spawns, and such
|
|
1643
|
+
* a host runs a child whatever that invokes.
|
|
1787
1644
|
*
|
|
1788
1645
|
* @category utility types
|
|
1789
1646
|
* @since 0.20.0
|
|
1790
1647
|
*/
|
|
1791
1648
|
export type StartRequirements<Child extends Any> = Child extends ChildMachine<string, infer M> ? Exclude<
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
Machine.Event<M>,
|
|
1795
|
-
Machine.EmittedEvent<M>
|
|
1796
|
-
>,
|
|
1797
|
-
Scope.Scope
|
|
1649
|
+
Machine.Services<M>,
|
|
1650
|
+
MachineRuntime | ChildMachineRuntime | InvocationSupport<InvocationSupport.Kind> | Scope.Scope
|
|
1798
1651
|
>
|
|
1799
1652
|
: never
|
|
1800
1653
|
|
|
@@ -1808,7 +1661,6 @@ export declare namespace ChildMachine {
|
|
|
1808
1661
|
Machine.Snapshot<Machine.States<M>>,
|
|
1809
1662
|
Machine.EventInput<Machine.InputEvent<M>>,
|
|
1810
1663
|
| Machine.Error<M>
|
|
1811
|
-
| ActionError<Machine.Services<M>>
|
|
1812
1664
|
| InfiniteTransitionError
|
|
1813
1665
|
| MachineSchemaDecodeError
|
|
1814
1666
|
| StoppedError,
|
|
@@ -1828,8 +1680,12 @@ export declare namespace ChildMachine {
|
|
|
1828
1680
|
}
|
|
1829
1681
|
|
|
1830
1682
|
/**
|
|
1831
|
-
* Effectful operations for child machines owned directly by the
|
|
1832
|
-
* machine
|
|
1683
|
+
* Effectful operations for child machines owned directly by the running
|
|
1684
|
+
* machine.
|
|
1685
|
+
*
|
|
1686
|
+
* Input mappers receive it from the host. `LocalMachine` runs each child as an
|
|
1687
|
+
* owned local machine. The owner that `ClusterMachine` supplies refuses every
|
|
1688
|
+
* operation with {@link ProcessLocalError}.
|
|
1833
1689
|
*
|
|
1834
1690
|
* @category models
|
|
1835
1691
|
* @since 0.20.0
|
|
@@ -1845,18 +1701,22 @@ export interface ChildOwner<OwnerEvent> {
|
|
|
1845
1701
|
ChildMachine.StartRequirements<Child>
|
|
1846
1702
|
>
|
|
1847
1703
|
|
|
1848
|
-
/**
|
|
1704
|
+
/**
|
|
1705
|
+
* Sends an event to one active child. Missing children are ignored. An event
|
|
1706
|
+
* that the child's event schema refuses fails with
|
|
1707
|
+
* {@link MachineSchemaDecodeError} and leaves the child running.
|
|
1708
|
+
*/
|
|
1849
1709
|
readonly sendTo: <Child extends ChildMachine.Any>(
|
|
1850
1710
|
child: Child,
|
|
1851
1711
|
event: ChildMachine.Event<Child>
|
|
1852
|
-
) => Effect.Effect<void, StoppedError>
|
|
1712
|
+
) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>
|
|
1853
1713
|
|
|
1854
1714
|
/** Stops one active child. Missing children are ignored. */
|
|
1855
1715
|
readonly stop: <Child extends ChildMachine.Any>(child: Child) => Effect.Effect<void>
|
|
1856
1716
|
}
|
|
1857
1717
|
|
|
1858
1718
|
/**
|
|
1859
|
-
*
|
|
1719
|
+
* Typed address of a child, unique within the machine that owns it.
|
|
1860
1720
|
*
|
|
1861
1721
|
* @category models
|
|
1862
1722
|
* @since 0.4.0
|
|
@@ -1927,6 +1787,7 @@ export declare namespace ChildAddress {
|
|
|
1927
1787
|
* @since 0.4.0
|
|
1928
1788
|
*/
|
|
1929
1789
|
export interface SpawnOptions {
|
|
1790
|
+
/** Address of the child, unique among the active children of its owner. */
|
|
1930
1791
|
readonly id?: string
|
|
1931
1792
|
}
|
|
1932
1793
|
|
|
@@ -1949,8 +1810,6 @@ export declare namespace Machine {
|
|
|
1949
1810
|
UnhandledStates extends StateIdentifier<States>,
|
|
1950
1811
|
E,
|
|
1951
1812
|
R,
|
|
1952
|
-
InitialE,
|
|
1953
|
-
InitialR,
|
|
1954
1813
|
FinalStates extends StateIdentifier<States>,
|
|
1955
1814
|
Output,
|
|
1956
1815
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
@@ -1964,8 +1823,6 @@ export declare namespace Machine {
|
|
|
1964
1823
|
readonly unhandledStates: UnhandledStates
|
|
1965
1824
|
readonly error: E
|
|
1966
1825
|
readonly services: R
|
|
1967
|
-
readonly initialError: InitialE
|
|
1968
|
-
readonly initialServices: InitialR
|
|
1969
1826
|
readonly finalStates: FinalStates
|
|
1970
1827
|
readonly output: Output
|
|
1971
1828
|
readonly emittedEvents: Emits
|
|
@@ -2032,7 +1889,7 @@ export declare namespace Machine {
|
|
|
2032
1889
|
export interface Any extends Pipeable {
|
|
2033
1890
|
readonly [TypeId]: TypeId
|
|
2034
1891
|
/** @internal */
|
|
2035
|
-
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any
|
|
1892
|
+
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any>
|
|
2036
1893
|
readonly states: StateSchemas
|
|
2037
1894
|
readonly root: Pick<State<Machine.StateNodeConfig>, typeof StateTypeId | "node">
|
|
2038
1895
|
readonly events: EventProtocol.Any<"public">
|
|
@@ -2106,28 +1963,18 @@ export declare namespace Machine {
|
|
|
2106
1963
|
export type Error<M extends Any> = M[typeof MachineTypeId]["error"]
|
|
2107
1964
|
|
|
2108
1965
|
/**
|
|
2109
|
-
* Extracts
|
|
1966
|
+
* Extracts what a machine definition requires of the host that runs it.
|
|
2110
1967
|
*
|
|
2111
|
-
*
|
|
2112
|
-
* @since 0.4.0
|
|
2113
|
-
*/
|
|
2114
|
-
export type Services<M extends Any> = M[typeof MachineTypeId]["services"]
|
|
2115
|
-
|
|
2116
|
-
/**
|
|
2117
|
-
* Extracts the startup error channel carried by a machine definition.
|
|
1968
|
+
* **Details**
|
|
2118
1969
|
*
|
|
2119
|
-
*
|
|
2120
|
-
* @
|
|
2121
|
-
|
|
2122
|
-
export type InitialError<M extends Any> = M[typeof MachineTypeId]["initialError"]
|
|
2123
|
-
|
|
2124
|
-
/**
|
|
2125
|
-
* Extracts startup service requirements carried by a machine definition.
|
|
1970
|
+
* The requirements are the services of the work its states invoke,
|
|
1971
|
+
* {@link MachineRuntime} when that work uses it, and one
|
|
1972
|
+
* {@link InvocationSupport} for each invoked kind that not every host runs.
|
|
2126
1973
|
*
|
|
2127
1974
|
* @category utility types
|
|
2128
1975
|
* @since 0.4.0
|
|
2129
1976
|
*/
|
|
2130
|
-
export type
|
|
1977
|
+
export type Services<M extends Any> = M[typeof MachineTypeId]["services"]
|
|
2131
1978
|
|
|
2132
1979
|
/**
|
|
2133
1980
|
* Extracts final state paths carried by a machine definition.
|
|
@@ -2172,6 +2019,61 @@ export declare namespace Machine {
|
|
|
2172
2019
|
/** Extracts the public input protocol required from an owning machine. */
|
|
2173
2020
|
export type ParentEvents<M extends Any> = M[typeof MachineTypeId]["parentEvents"]
|
|
2174
2021
|
|
|
2022
|
+
/**
|
|
2023
|
+
* The value an Effect source succeeds with and the typed error it fails with.
|
|
2024
|
+
*
|
|
2025
|
+
* @category utility types
|
|
2026
|
+
* @since 0.48.0
|
|
2027
|
+
*/
|
|
2028
|
+
export interface EffectResult<Done, Failure> {
|
|
2029
|
+
readonly done: Done
|
|
2030
|
+
readonly failure: Failure
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
/**
|
|
2034
|
+
* Extracts the result types of every Effect source a machine registers,
|
|
2035
|
+
* keyed by source name.
|
|
2036
|
+
*
|
|
2037
|
+
* **Details**
|
|
2038
|
+
*
|
|
2039
|
+
* The machine returned by `handle` carries these types, and only as types:
|
|
2040
|
+
* nothing is added to the machine value. A source that takes input
|
|
2041
|
+
* contributes the Effect its function returns.
|
|
2042
|
+
*
|
|
2043
|
+
* **Gotchas**
|
|
2044
|
+
*
|
|
2045
|
+
* A machine whose type was widened, for example by annotating it as a
|
|
2046
|
+
* `Machine.Machine<...>` or as `Machine.Machine.Any`, no longer carries them,
|
|
2047
|
+
* and this type is `never`.
|
|
2048
|
+
*
|
|
2049
|
+
* @category utility types
|
|
2050
|
+
* @since 0.48.0
|
|
2051
|
+
*/
|
|
2052
|
+
export type EffectResults<M extends Any> = M extends {
|
|
2053
|
+
readonly [MachineEffectResultsTypeId]?: infer Results extends Readonly<Record<string, EffectResult<any, any>>>
|
|
2054
|
+
} ? Results
|
|
2055
|
+
: never
|
|
2056
|
+
|
|
2057
|
+
/**
|
|
2058
|
+
* Type-only evidence of the result types of a machine's Effect sources, read
|
|
2059
|
+
* through {@link EffectResults}.
|
|
2060
|
+
*
|
|
2061
|
+
* @category models
|
|
2062
|
+
* @since 0.48.0
|
|
2063
|
+
*/
|
|
2064
|
+
export interface EffectResultsEvidence<Results> {
|
|
2065
|
+
/**
|
|
2066
|
+
* @internal Optional, so a machine type rebuilt from its parameters stays
|
|
2067
|
+
* assignable to and from the type that `handle` returned.
|
|
2068
|
+
*/
|
|
2069
|
+
readonly [MachineEffectResultsTypeId]?: Results
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
/** The result types of one registered Effect source. */
|
|
2073
|
+
export type EffectResultOf<Source> = InvokeResolvedSource<Source> extends
|
|
2074
|
+
Effect.Effect<infer Done, infer Failure, infer _R> ? EffectResult<Done, Failure>
|
|
2075
|
+
: never
|
|
2076
|
+
|
|
2175
2077
|
/** Extracts whether a machine requires or optionally accepts an owner. */
|
|
2176
2078
|
export type ParentAvailability<M extends Any> = ParentModeOf<M[typeof MachineTypeId]["parentEvents"]>
|
|
2177
2079
|
|
|
@@ -2923,7 +2825,9 @@ export declare namespace Machine {
|
|
|
2923
2825
|
* @category models
|
|
2924
2826
|
* @since 0.4.0
|
|
2925
2827
|
*/
|
|
2926
|
-
export type
|
|
2828
|
+
export type InvocationDefinition<SourcePath extends string = string> = InvocationDefinitions.InvocationDefinition<
|
|
2829
|
+
SourcePath
|
|
2830
|
+
>
|
|
2927
2831
|
|
|
2928
2832
|
/**
|
|
2929
2833
|
* Transition retained after hierarchy precedence and conflict resolution for
|
|
@@ -3229,12 +3133,17 @@ export declare namespace Machine {
|
|
|
3229
3133
|
export type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"]
|
|
3230
3134
|
|
|
3231
3135
|
/**
|
|
3232
|
-
* Event values received by lifecycle callbacks
|
|
3136
|
+
* Event values received by lifecycle callbacks: a declared event,
|
|
3137
|
+
* `InitialEvent` while the initial state settles, or `InvocationEvent` for a
|
|
3138
|
+
* step caused by invoked work.
|
|
3233
3139
|
*
|
|
3234
3140
|
* @category utility types
|
|
3235
3141
|
* @since 0.4.0
|
|
3236
3142
|
*/
|
|
3237
|
-
export type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> =
|
|
3143
|
+
export type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> =
|
|
3144
|
+
| EventOf<Events>
|
|
3145
|
+
| InitialEvent
|
|
3146
|
+
| InvocationEvent
|
|
3238
3147
|
|
|
3239
3148
|
/**
|
|
3240
3149
|
* Extracts a state value from a state definition by identifier.
|
|
@@ -3811,7 +3720,7 @@ export declare namespace Machine {
|
|
|
3811
3720
|
* value without changing its active descendants.
|
|
3812
3721
|
*
|
|
3813
3722
|
* @category models
|
|
3814
|
-
* @since 0.
|
|
3723
|
+
* @since 0.48.0
|
|
3815
3724
|
*/
|
|
3816
3725
|
export interface StateUpdate<
|
|
3817
3726
|
States extends StateSchemas,
|
|
@@ -3955,8 +3864,6 @@ export declare namespace Machine {
|
|
|
3955
3864
|
Emits extends ReadonlyArray<TaggedSchema>,
|
|
3956
3865
|
StateId extends StateIdentifier<States>,
|
|
3957
3866
|
EventTag extends TagOf<Events[number]>,
|
|
3958
|
-
E,
|
|
3959
|
-
R,
|
|
3960
3867
|
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
3961
3868
|
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
3962
3869
|
> = MachineReferences<InputEvents, ParentEvents> & {
|
|
@@ -4296,7 +4203,7 @@ export declare namespace Machine {
|
|
|
4296
4203
|
* @category utility types
|
|
4297
4204
|
* @since 0.4.0
|
|
4298
4205
|
*/
|
|
4299
|
-
export type StateActionResult
|
|
4206
|
+
export type StateActionResult = undefined
|
|
4300
4207
|
|
|
4301
4208
|
/**
|
|
4302
4209
|
* Initial target that a machine resolves at startup.
|
|
@@ -4304,7 +4211,7 @@ export declare namespace Machine {
|
|
|
4304
4211
|
* @category utility types
|
|
4305
4212
|
* @since 0.4.0
|
|
4306
4213
|
*/
|
|
4307
|
-
export type InitialResult<States extends StateSchemas
|
|
4214
|
+
export type InitialResult<States extends StateSchemas> = InitialTarget<StateIdentifier<States>>
|
|
4308
4215
|
|
|
4309
4216
|
/**
|
|
4310
4217
|
* Result that a transition declaration resolves to.
|
|
@@ -4319,7 +4226,7 @@ export declare namespace Machine {
|
|
|
4319
4226
|
* @category utility types
|
|
4320
4227
|
* @since 0.4.0
|
|
4321
4228
|
*/
|
|
4322
|
-
export type HandlerResult<States extends StateSchemas
|
|
4229
|
+
export type HandlerResult<States extends StateSchemas> =
|
|
4323
4230
|
| Snapshot<States>
|
|
4324
4231
|
| Target<States, StateIdentifier<States>>
|
|
4325
4232
|
| HistoryTarget<States, HistoryIdentifier<States>>
|
|
@@ -4356,45 +4263,19 @@ export declare namespace Machine {
|
|
|
4356
4263
|
never
|
|
4357
4264
|
}[keyof NonNullable<History>]
|
|
4358
4265
|
: never
|
|
4359
|
-
/** Extracts the return value from a choice resolver. */
|
|
4360
|
-
export type ChoiceReturn<Config> = Config extends { readonly choice: infer Choice } ? EventTransitionReturn<Choice>
|
|
4361
|
-
: never
|
|
4362
4266
|
/**
|
|
4363
|
-
* Extracts the
|
|
4267
|
+
* Extracts the invoke config or configs from a state config.
|
|
4364
4268
|
*
|
|
4365
4269
|
* @category utility types
|
|
4366
4270
|
* @since 0.4.0
|
|
4367
4271
|
*/
|
|
4368
|
-
export type
|
|
4369
|
-
|
|
4272
|
+
export type InvokeReturn<Config> = "invoke" extends keyof Config
|
|
4273
|
+
? Config extends { readonly invoke?: infer Invoke }
|
|
4274
|
+
? NonNullable<Invoke> extends ReadonlyArray<infer One> ? One : NonNullable<Invoke>
|
|
4275
|
+
: never
|
|
4370
4276
|
: never
|
|
4371
4277
|
/**
|
|
4372
|
-
* Extracts the
|
|
4373
|
-
*
|
|
4374
|
-
* @category utility types
|
|
4375
|
-
* @since 0.4.0
|
|
4376
|
-
*/
|
|
4377
|
-
export type EventHandlerReturn<Config> = Config extends { readonly on?: infer On }
|
|
4378
|
-
? { readonly [EventTag in keyof On]: EventTransitionReturn<NonNullable<On[EventTag]>> }[
|
|
4379
|
-
keyof On
|
|
4380
|
-
]
|
|
4381
|
-
: never
|
|
4382
|
-
/**
|
|
4383
|
-
* Extracts the invoke config or configs from a state config.
|
|
4384
|
-
*
|
|
4385
|
-
* @category utility types
|
|
4386
|
-
* @since 0.4.0
|
|
4387
|
-
*/
|
|
4388
|
-
export type InvokeReturn<Config> = "invoke" extends keyof Config
|
|
4389
|
-
? Config extends { readonly invoke?: infer Invoke }
|
|
4390
|
-
? NonNullable<Invoke> extends (...args: any) => infer Resolved
|
|
4391
|
-
? NonNullable<Resolved> extends ReadonlyArray<infer One> ? One : NonNullable<Resolved>
|
|
4392
|
-
: NonNullable<Invoke> extends ReadonlyArray<infer One> ? One
|
|
4393
|
-
: NonNullable<Invoke>
|
|
4394
|
-
: never
|
|
4395
|
-
: never
|
|
4396
|
-
/**
|
|
4397
|
-
* Extracts the child process logic returned by an invoke source.
|
|
4278
|
+
* Extracts the child process logic returned by an invoke source.
|
|
4398
4279
|
*
|
|
4399
4280
|
* @category utility types
|
|
4400
4281
|
* @since 0.4.0
|
|
@@ -4408,16 +4289,10 @@ export declare namespace Machine {
|
|
|
4408
4289
|
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<
|
|
4409
4290
|
Snapshot<States<M>>,
|
|
4410
4291
|
EventInput<InputEvent<M>>,
|
|
4411
|
-
Error<M> |
|
|
4412
|
-
|
|
4413
|
-
Exclude<ExecutionServices<InitialServices<M> | Services<M>>, MachineRuntime>,
|
|
4414
|
-
Event<M>,
|
|
4415
|
-
EmittedEvent<M>
|
|
4416
|
-
>,
|
|
4292
|
+
Error<M> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
|
|
4293
|
+
Services<M>,
|
|
4417
4294
|
Output<M>,
|
|
4418
|
-
| InitialError<M>
|
|
4419
4295
|
| Error<M>
|
|
4420
|
-
| ActionError<InitialServices<M> | Services<M>>
|
|
4421
4296
|
| InfiniteTransitionError
|
|
4422
4297
|
| MachineSchemaDecodeError
|
|
4423
4298
|
| StartupError
|
|
@@ -4450,12 +4325,15 @@ export declare namespace Machine {
|
|
|
4450
4325
|
/**
|
|
4451
4326
|
* Extracts the startup error from an invoke source child process logic.
|
|
4452
4327
|
*
|
|
4328
|
+
* **Details**
|
|
4329
|
+
*
|
|
4330
|
+
* Invoked logic contributes its startup error. A child machine declares none.
|
|
4331
|
+
*
|
|
4453
4332
|
* @category utility types
|
|
4454
4333
|
* @since 0.4.0
|
|
4455
4334
|
*/
|
|
4456
|
-
export type InvokeInitialError<Invoke> = Invoke extends
|
|
4457
|
-
|
|
4458
|
-
} ? InitialError
|
|
4335
|
+
export type InvokeInitialError<Invoke> = IsAny<Invoke> extends true ? unknown
|
|
4336
|
+
: Invoke extends { readonly child: unknown } ? never
|
|
4459
4337
|
: LogicInitialErrorOf<InvokeLogic<Invoke>>
|
|
4460
4338
|
/**
|
|
4461
4339
|
* Extracts the runtime error from an invoked child process.
|
|
@@ -4473,10 +4351,7 @@ export declare namespace Machine {
|
|
|
4473
4351
|
* @category utility types
|
|
4474
4352
|
* @since 0.4.0
|
|
4475
4353
|
*/
|
|
4476
|
-
export type InvokeOutput<Invoke> = Invoke
|
|
4477
|
-
readonly [InvokeTypeId]: { readonly output: Types.Covariant<infer Output> }
|
|
4478
|
-
} ? Output
|
|
4479
|
-
: LogicOutputOf<InvokeLogic<Invoke>>
|
|
4354
|
+
export type InvokeOutput<Invoke> = LogicOutputOf<InvokeLogic<Invoke>>
|
|
4480
4355
|
/**
|
|
4481
4356
|
* Extracts the service requirements from an invoke source child process logic.
|
|
4482
4357
|
*
|
|
@@ -4489,27 +4364,9 @@ export declare namespace Machine {
|
|
|
4489
4364
|
: LogicServicesOf<InvokeLogic<Invoke>>
|
|
4490
4365
|
|
|
4491
4366
|
/** Public parent inputs required by an invoked child machine. */
|
|
4492
|
-
export type InvokeParentEvents<Invoke> = Invoke extends
|
|
4493
|
-
readonly [InvokeTypeId]: { readonly parentEvents: Types.Covariant<infer ParentEvent> }
|
|
4494
|
-
} ? ParentEvent
|
|
4495
|
-
: IsAny<Invoke> extends true ? never
|
|
4367
|
+
export type InvokeParentEvents<Invoke> = IsAny<Invoke> extends true ? never
|
|
4496
4368
|
: Invoke extends { readonly child: ChildMachine<string, infer M> } ? EventOf<ParentEvents<M>>
|
|
4497
4369
|
: never
|
|
4498
|
-
/** Extracts transition results returned by invocation lifecycle handlers. */
|
|
4499
|
-
export type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ?
|
|
4500
|
-
| (Invoke extends {
|
|
4501
|
-
readonly [InvokeTypeId]: { readonly outcomes: Types.Covariant<infer Outcomes> }
|
|
4502
|
-
} ? EventTransitionReturn<Outcomes> :
|
|
4503
|
-
never)
|
|
4504
|
-
| (Invoke extends { readonly onDone?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
|
|
4505
|
-
| (Invoke extends { readonly onFailure?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
|
|
4506
|
-
| (Invoke extends { readonly onElement?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
|
|
4507
|
-
| (Invoke extends { readonly onSnapshot?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
|
|
4508
|
-
: never
|
|
4509
|
-
type InvokeOutcomeError<Invoke> = IsAny<InvokeOutcomeReturn<Invoke>> extends true ? never
|
|
4510
|
-
: Effect.Error<InvokeOutcomeReturn<Invoke>>
|
|
4511
|
-
type InvokeOutcomeServices<Invoke> = IsAny<InvokeOutcomeReturn<Invoke>> extends true ? never
|
|
4512
|
-
: Effect.Services<InvokeOutcomeReturn<Invoke>>
|
|
4513
4370
|
// Effect, Stream, and timer invocations run under a runtime-reserved child id
|
|
4514
4371
|
// derived from their state path and distinct lifecycle id. Only caller-chosen
|
|
4515
4372
|
// child ids (logic addresses and child descriptor ids) can collide.
|
|
@@ -4535,65 +4392,47 @@ export declare namespace Machine {
|
|
|
4535
4392
|
:
|
|
4536
4393
|
| InvokeCollisionError<InvokeReturn<Config>>
|
|
4537
4394
|
| InvokeInitialError<InvokeReturn<Config>>
|
|
4538
|
-
|
|
4395
|
+
type InvokeSupport<Invoke> = IsAny<Invoke> extends true ? never
|
|
4396
|
+
: Invoke extends { readonly stream: unknown } ? InvocationSupport<"Stream">
|
|
4397
|
+
: Invoke extends { readonly logic: unknown } ? InvocationSupport<"Logic">
|
|
4398
|
+
: Invoke extends { readonly child: unknown } ? InvocationSupport<"Child">
|
|
4399
|
+
: never
|
|
4539
4400
|
/**
|
|
4540
|
-
* Extracts the
|
|
4401
|
+
* Extracts the requirements that the invocations of a state handler config add
|
|
4402
|
+
* to its machine.
|
|
4403
|
+
*
|
|
4404
|
+
* **Details**
|
|
4405
|
+
*
|
|
4406
|
+
* The contribution contains the services of every invoked source, and one
|
|
4407
|
+
* {@link InvocationSupport} for each invoked kind that not every host runs. An
|
|
4408
|
+
* invoked child machine contributes all the requirements of its machine.
|
|
4541
4409
|
*
|
|
4542
4410
|
* @category utility types
|
|
4543
4411
|
* @since 0.4.0
|
|
4544
4412
|
*/
|
|
4545
4413
|
export type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never
|
|
4546
4414
|
:
|
|
4547
|
-
|
|
|
4415
|
+
| InvokeSupport<InvokeReturn<Config>>
|
|
4548
4416
|
| InvokeServices<InvokeReturn<Config>>
|
|
4549
|
-
| InvokeOutcomeServices<InvokeReturn<Config>>
|
|
4550
4417
|
/**
|
|
4551
|
-
* Extracts
|
|
4418
|
+
* Extracts all service requirements contributed by a state handler config.
|
|
4552
4419
|
*
|
|
4553
|
-
*
|
|
4554
|
-
* @since 0.4.0
|
|
4555
|
-
*/
|
|
4556
|
-
export type AlwaysReturn<Config> = Config extends { readonly always?: infer Always }
|
|
4557
|
-
? EventTransitionReturn<NonNullable<Always>>
|
|
4558
|
-
: never
|
|
4559
|
-
/**
|
|
4560
|
-
* Extracts the return value from a state completion transition.
|
|
4420
|
+
* **Details**
|
|
4561
4421
|
*
|
|
4562
|
-
*
|
|
4563
|
-
*
|
|
4564
|
-
|
|
4565
|
-
export type DoneReturn<Config> = Config extends { readonly onDone?: infer OnDone }
|
|
4566
|
-
? EventTransitionReturn<NonNullable<OnDone>>
|
|
4567
|
-
: never
|
|
4568
|
-
|
|
4569
|
-
/**
|
|
4570
|
-
* Extracts all service requirements contributed by a state handler config.
|
|
4422
|
+
* Transitions and actions are synchronous, so only invocations contribute
|
|
4423
|
+
* services. An action or history default whose return type is `any` contributes
|
|
4424
|
+
* `unknown`.
|
|
4571
4425
|
*
|
|
4572
4426
|
* @category utility types
|
|
4573
4427
|
* @since 0.4.0
|
|
4574
4428
|
*/
|
|
4575
4429
|
export type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never :
|
|
4576
|
-
| Effect.Services<EventHandlerReturn<Config>>
|
|
4577
|
-
| Effect.Services<AlwaysReturn<Config>>
|
|
4578
|
-
| Effect.Services<DoneReturn<Config>>
|
|
4579
4430
|
| Effect.Services<StateActionReturn<Config, "entry">>
|
|
4580
4431
|
| Effect.Services<StateActionReturn<Config, "exit">>
|
|
4581
4432
|
| Effect.Services<HistoryDefaultReturn<Config>>
|
|
4582
|
-
| Effect.Services<ChoiceReturn<Config>>
|
|
4583
4433
|
| InvokeRequirements<Config>
|
|
4584
4434
|
: never
|
|
4585
4435
|
|
|
4586
|
-
/** The only transition value accepted by machine handler APIs. */
|
|
4587
|
-
type TransitionConfig<
|
|
4588
|
-
States extends StateSchemas,
|
|
4589
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
4590
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4591
|
-
StateId extends StateNodeIdentifier<States>,
|
|
4592
|
-
Context,
|
|
4593
|
-
Reenter extends boolean = false,
|
|
4594
|
-
Acceptance extends TransitionAcceptance = "required"
|
|
4595
|
-
> = Transition<States, StateId, Context, Events, Emits, {}, Reenter, Acceptance>
|
|
4596
|
-
|
|
4597
4436
|
/** Opaque evidence that `resolve` selected one declared branch. */
|
|
4598
4437
|
export interface SelectedBranch<out Key extends string, out Result> {
|
|
4599
4438
|
readonly [SelectedBranchTypeId]: {
|
|
@@ -4602,136 +4441,6 @@ export declare namespace Machine {
|
|
|
4602
4441
|
}
|
|
4603
4442
|
}
|
|
4604
4443
|
|
|
4605
|
-
export type InvokeSource<Value, Context> = Value | ((context: Context) => Value)
|
|
4606
|
-
|
|
4607
|
-
/**
|
|
4608
|
-
* State-owned work that runs for the lifetime of its active state.
|
|
4609
|
-
*
|
|
4610
|
-
* **Details**
|
|
4611
|
-
*
|
|
4612
|
-
* Every `invoke` entry carries this type-level marker, which records the
|
|
4613
|
-
* state that owns the entry together with the machine's state schemas and
|
|
4614
|
-
* event protocols. The marker property is optional and is never set at
|
|
4615
|
-
* runtime.
|
|
4616
|
-
*
|
|
4617
|
-
* @category models
|
|
4618
|
-
* @since 0.23.0
|
|
4619
|
-
*/
|
|
4620
|
-
export interface InvokeOwned<
|
|
4621
|
-
States extends StateSchemas,
|
|
4622
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
4623
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4624
|
-
StateId extends StateIdentifier<States>,
|
|
4625
|
-
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4626
|
-
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4627
|
-
> {
|
|
4628
|
-
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<
|
|
4629
|
-
readonly [States, Events, Emits, StateId, InputEvents, ParentEvents]
|
|
4630
|
-
>
|
|
4631
|
-
}
|
|
4632
|
-
|
|
4633
|
-
type StoredInvokeConfig<
|
|
4634
|
-
States extends StateSchemas,
|
|
4635
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
4636
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4637
|
-
StateId extends StateIdentifier<States>,
|
|
4638
|
-
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4639
|
-
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4640
|
-
> =
|
|
4641
|
-
& InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4642
|
-
& (
|
|
4643
|
-
| {
|
|
4644
|
-
readonly id: string
|
|
4645
|
-
readonly effect: (
|
|
4646
|
-
context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4647
|
-
) => Effect.Effect<any, any, any>
|
|
4648
|
-
readonly stream?: never
|
|
4649
|
-
readonly after?: never
|
|
4650
|
-
readonly logic?: never
|
|
4651
|
-
readonly child?: never
|
|
4652
|
-
readonly address?: never
|
|
4653
|
-
readonly onDone?: unknown
|
|
4654
|
-
readonly onFailure?: unknown
|
|
4655
|
-
readonly onElement?: never
|
|
4656
|
-
readonly onSnapshot?: never
|
|
4657
|
-
}
|
|
4658
|
-
| {
|
|
4659
|
-
readonly id: string
|
|
4660
|
-
readonly stream: (
|
|
4661
|
-
context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4662
|
-
) => Stream.Stream<any, any, any>
|
|
4663
|
-
readonly effect?: never
|
|
4664
|
-
readonly after?: never
|
|
4665
|
-
readonly logic?: never
|
|
4666
|
-
readonly child?: never
|
|
4667
|
-
readonly address?: never
|
|
4668
|
-
readonly onElement?: unknown
|
|
4669
|
-
readonly onDone: unknown
|
|
4670
|
-
readonly onFailure?: unknown
|
|
4671
|
-
readonly onSnapshot?: never
|
|
4672
|
-
}
|
|
4673
|
-
| {
|
|
4674
|
-
readonly id: string
|
|
4675
|
-
readonly after: InvokeSource<
|
|
4676
|
-
Duration.Input,
|
|
4677
|
-
InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4678
|
-
>
|
|
4679
|
-
readonly effect?: never
|
|
4680
|
-
readonly stream?: never
|
|
4681
|
-
readonly logic?: never
|
|
4682
|
-
readonly child?: never
|
|
4683
|
-
readonly address?: never
|
|
4684
|
-
readonly onDone: unknown
|
|
4685
|
-
readonly onFailure?: never
|
|
4686
|
-
readonly onElement?: never
|
|
4687
|
-
readonly onSnapshot?: never
|
|
4688
|
-
}
|
|
4689
|
-
| {
|
|
4690
|
-
readonly id: string
|
|
4691
|
-
readonly address: string
|
|
4692
|
-
readonly logic: InvokeSource<
|
|
4693
|
-
Logic<any, any, any, any, any, any>,
|
|
4694
|
-
InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4695
|
-
>
|
|
4696
|
-
readonly effect?: never
|
|
4697
|
-
readonly stream?: never
|
|
4698
|
-
readonly after?: never
|
|
4699
|
-
readonly child?: never
|
|
4700
|
-
readonly onDone?: unknown
|
|
4701
|
-
readonly onFailure?: unknown
|
|
4702
|
-
readonly onElement?: never
|
|
4703
|
-
readonly onSnapshot?: unknown
|
|
4704
|
-
}
|
|
4705
|
-
| {
|
|
4706
|
-
readonly child: ChildMachine.Any
|
|
4707
|
-
readonly input?:
|
|
4708
|
-
| {}
|
|
4709
|
-
| null
|
|
4710
|
-
| ((context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown)
|
|
4711
|
-
readonly id?: never
|
|
4712
|
-
readonly address?: never
|
|
4713
|
-
readonly effect?: never
|
|
4714
|
-
readonly stream?: never
|
|
4715
|
-
readonly after?: never
|
|
4716
|
-
readonly logic?: never
|
|
4717
|
-
readonly onDone?: unknown
|
|
4718
|
-
readonly onFailure?: unknown
|
|
4719
|
-
readonly onElement?: never
|
|
4720
|
-
readonly onSnapshot?: unknown
|
|
4721
|
-
}
|
|
4722
|
-
)
|
|
4723
|
-
|
|
4724
|
-
type StoredInvokeDefinition<
|
|
4725
|
-
States extends StateSchemas,
|
|
4726
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
4727
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4728
|
-
StateId extends StateIdentifier<States>,
|
|
4729
|
-
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4730
|
-
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4731
|
-
> =
|
|
4732
|
-
| StoredInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
|
|
4733
|
-
| ReadonlyArray<StoredInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>>
|
|
4734
|
-
|
|
4735
4444
|
type LogicInitialEffectOf<Value> = Value extends { readonly initial: infer Initial } ?
|
|
4736
4445
|
Initial extends (...args: ReadonlyArray<any>) => infer Result ? Result : never
|
|
4737
4446
|
: never
|
|
@@ -4742,8 +4451,8 @@ export declare namespace Machine {
|
|
|
4742
4451
|
|
|
4743
4452
|
export type LogicStateOf<Value> = Effect.Success<LogicInitialEffectOf<Value>>
|
|
4744
4453
|
export type LogicEventOf<Value> = Value extends { readonly initial: infer Initial } ?
|
|
4745
|
-
Initial extends (
|
|
4746
|
-
|
|
4454
|
+
Initial extends (context: infer LogicInitialContext, ...args: ReadonlyArray<any>) => any ?
|
|
4455
|
+
LogicInitialContext extends Logic.InitialContext<infer Event> ? Event : never
|
|
4747
4456
|
: never
|
|
4748
4457
|
: never
|
|
4749
4458
|
export type LogicErrorOf<Value> = Effect.Error<LogicRunEffectOf<Value>>
|
|
@@ -4754,7 +4463,6 @@ export declare namespace Machine {
|
|
|
4754
4463
|
/** Output construction available to final and output-producing parallel states. */
|
|
4755
4464
|
type OutputHandlerConfig<
|
|
4756
4465
|
States extends StateSchemas,
|
|
4757
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
4758
4466
|
StateId extends StateIdentifier<States>,
|
|
4759
4467
|
Context
|
|
4760
4468
|
> = NodeByIdentifier<States, StateId> extends { readonly output: Schema.Top } ? {
|
|
@@ -4771,7 +4479,6 @@ export declare namespace Machine {
|
|
|
4771
4479
|
StateId extends StateIdentifier<States>
|
|
4772
4480
|
> = NodeByIdentifier<States, StateId> extends { readonly type: "parallel" } ? OutputHandlerConfig<
|
|
4773
4481
|
States,
|
|
4774
|
-
Events,
|
|
4775
4482
|
StateId,
|
|
4776
4483
|
ParallelOutputContext<States, Events, StateId>
|
|
4777
4484
|
>
|
|
@@ -4834,7 +4541,7 @@ export declare namespace Machine {
|
|
|
4834
4541
|
ParentId extends StateIdentifier<States>
|
|
4835
4542
|
> = (
|
|
4836
4543
|
context: HistoryDefaultContext<States, Events, Emits, ParentId>,
|
|
4837
|
-
enqueue:
|
|
4544
|
+
enqueue: Commands<EventOf<Events>, EmittedEventOf<Emits>>
|
|
4838
4545
|
) =>
|
|
4839
4546
|
| CompleteSnapshotContaining<States, ParentId>
|
|
4840
4547
|
| StateConstruction<CompleteSnapshotContaining<States, ParentId>>
|
|
@@ -4876,42 +4583,6 @@ export declare namespace Machine {
|
|
|
4876
4583
|
readonly [Key in HistoryStateKey<Children>]?: HistoryDefaultEntry<States, Events, Emits, ParentId>
|
|
4877
4584
|
}
|
|
4878
4585
|
|
|
4879
|
-
/**
|
|
4880
|
-
* Required implementation for a choice pseudo-state.
|
|
4881
|
-
*
|
|
4882
|
-
* **Details**
|
|
4883
|
-
*
|
|
4884
|
-
* A choice state declares only `choice`, the transition that resolves it to
|
|
4885
|
-
* a concrete destination. Every other handler key is rejected.
|
|
4886
|
-
*
|
|
4887
|
-
* @category models
|
|
4888
|
-
* @since 0.23.0
|
|
4889
|
-
*/
|
|
4890
|
-
export interface ChoiceStateConfig<
|
|
4891
|
-
States extends StateSchemas,
|
|
4892
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
4893
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
4894
|
-
ChoiceId extends ChoiceIdentifier<States>,
|
|
4895
|
-
InputEvents extends ReadonlyArray<TaggedSchema> = Events,
|
|
4896
|
-
ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
|
|
4897
|
-
> {
|
|
4898
|
-
/** Required transition that resolves this transient choice to a concrete destination. */
|
|
4899
|
-
readonly choice: TransitionConfig<
|
|
4900
|
-
States,
|
|
4901
|
-
Events,
|
|
4902
|
-
Emits,
|
|
4903
|
-
ChoiceId,
|
|
4904
|
-
ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>
|
|
4905
|
-
>
|
|
4906
|
-
readonly entry?: never
|
|
4907
|
-
readonly exit?: never
|
|
4908
|
-
readonly invoke?: never
|
|
4909
|
-
readonly always?: never
|
|
4910
|
-
readonly on?: never
|
|
4911
|
-
readonly onDone?: never
|
|
4912
|
-
readonly output?: never
|
|
4913
|
-
}
|
|
4914
|
-
|
|
4915
4586
|
type HandlerChildren<Node> = Node extends { readonly states: infer Children extends StateSchemas } ? Children : never
|
|
4916
4587
|
|
|
4917
4588
|
type HandlerConfigPart<Config> = {
|
|
@@ -5106,13 +4777,10 @@ export declare namespace Machine {
|
|
|
5106
4777
|
Node,
|
|
5107
4778
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5108
4779
|
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5109
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5110
4780
|
StateId extends StateNodeIdentifier<AllStates>,
|
|
5111
4781
|
Config,
|
|
5112
4782
|
AvailableOutputStates extends StateIdentifier<AllStates>
|
|
5113
|
-
> = StateId extends ChoiceIdentifier<AllStates> ?
|
|
5114
|
-
& HandlerChoiceUnknownConfigKeyValidation<StateId, Config>
|
|
5115
|
-
& HandlerRuntimeValidation<Events, Emits, StateId, Config>
|
|
4783
|
+
> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config>
|
|
5116
4784
|
: StateId extends StateIdentifier<AllStates> ?
|
|
5117
4785
|
& HandlerUnknownConfigKeyValidation<StateId, Config>
|
|
5118
4786
|
& HandlerOnKeyValidation<Events, StateId, Config>
|
|
@@ -5121,7 +4789,6 @@ export declare namespace Machine {
|
|
|
5121
4789
|
& HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config>
|
|
5122
4790
|
& HandlerRequiredHistoryInitializeValidation<AllStates, StateId, Config>
|
|
5123
4791
|
& ValidateConstructionDeclarations<Node, Config>
|
|
5124
|
-
& HandlerRuntimeValidation<Events, Emits, StateId, Config>
|
|
5125
4792
|
: unknown
|
|
5126
4793
|
|
|
5127
4794
|
type HandlerChoiceUnknownConfigKeyValidation<
|
|
@@ -5150,25 +4817,11 @@ export declare namespace Machine {
|
|
|
5150
4817
|
>
|
|
5151
4818
|
}
|
|
5152
4819
|
|
|
5153
|
-
type HandlerRuntimeValidation<
|
|
5154
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
5155
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5156
|
-
StateId extends string,
|
|
5157
|
-
Config,
|
|
5158
|
-
Incompatible = keyof Config extends never ? never : IncompatibleRuntime<
|
|
5159
|
-
ConfigServices<HandlerConfigPart<Config>>,
|
|
5160
|
-
EventOf<Events>,
|
|
5161
|
-
EmittedEventOf<Emits>
|
|
5162
|
-
>
|
|
5163
|
-
> = [Incompatible] extends [never] ? unknown
|
|
5164
|
-
: HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>
|
|
5165
|
-
|
|
5166
4820
|
type HandlerTreeValidation<
|
|
5167
4821
|
States extends StateSchemas,
|
|
5168
4822
|
Node,
|
|
5169
4823
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5170
4824
|
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5171
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5172
4825
|
Path extends StateNodeIdentifier<States>,
|
|
5173
4826
|
Config,
|
|
5174
4827
|
OutputStates extends StateIdentifier<States>
|
|
@@ -5178,7 +4831,6 @@ export declare namespace Machine {
|
|
|
5178
4831
|
Node,
|
|
5179
4832
|
Events,
|
|
5180
4833
|
InputEvents,
|
|
5181
|
-
Emits,
|
|
5182
4834
|
Path,
|
|
5183
4835
|
Config,
|
|
5184
4836
|
OutputStates
|
|
@@ -5191,7 +4843,6 @@ export declare namespace Machine {
|
|
|
5191
4843
|
Children[K],
|
|
5192
4844
|
Events,
|
|
5193
4845
|
InputEvents,
|
|
5194
|
-
Emits,
|
|
5195
4846
|
Extract<JoinPath<Path, Extract<K, string>>, StateNodeIdentifier<States>>,
|
|
5196
4847
|
Handlers[K],
|
|
5197
4848
|
OutputStates
|
|
@@ -5206,7 +4857,6 @@ export declare namespace Machine {
|
|
|
5206
4857
|
States extends StateSchemas,
|
|
5207
4858
|
Events extends ReadonlyArray<TaggedSchema>,
|
|
5208
4859
|
InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
5209
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
5210
4860
|
Config,
|
|
5211
4861
|
OutputStates extends StateIdentifier<States>
|
|
5212
4862
|
> = HandlerTreeValidation<
|
|
@@ -5214,7 +4864,6 @@ export declare namespace Machine {
|
|
|
5214
4864
|
States[""],
|
|
5215
4865
|
Events,
|
|
5216
4866
|
InputEvents,
|
|
5217
|
-
Emits,
|
|
5218
4867
|
Extract<"", StateNodeIdentifier<States>>,
|
|
5219
4868
|
Config,
|
|
5220
4869
|
OutputStates
|
|
@@ -5262,13 +4911,9 @@ export declare namespace Machine {
|
|
|
5262
4911
|
: never
|
|
5263
4912
|
|
|
5264
4913
|
type HandlerConfigError<Config> = Config extends unknown ? [keyof Config] extends [never] ? never :
|
|
5265
|
-
| Effect.Error<EventHandlerReturn<Config>>
|
|
5266
|
-
| Effect.Error<AlwaysReturn<Config>>
|
|
5267
|
-
| Effect.Error<DoneReturn<Config>>
|
|
5268
4914
|
| Effect.Error<StateActionReturn<Config, "entry">>
|
|
5269
4915
|
| Effect.Error<StateActionReturn<Config, "exit">>
|
|
5270
4916
|
| Effect.Error<HistoryDefaultReturn<Config>>
|
|
5271
|
-
| Effect.Error<ChoiceReturn<Config>>
|
|
5272
4917
|
| InvokeError<Config>
|
|
5273
4918
|
: never
|
|
5274
4919
|
|
|
@@ -5496,7 +5141,6 @@ export declare namespace Machine {
|
|
|
5496
5141
|
| ({} extends NodeMakeInput<Node> ? { readonly from?: never; readonly decoded?: never } : never)
|
|
5497
5142
|
type InlineDestinationConstruction<
|
|
5498
5143
|
S extends StateSchemas,
|
|
5499
|
-
Src extends StateNodeIdentifier<S>,
|
|
5500
5144
|
P extends DestinationPath<S>,
|
|
5501
5145
|
C
|
|
5502
5146
|
> = P extends ChoiceIdentifier<S> ? { readonly from?: never; readonly decoded?: never }
|
|
@@ -5552,7 +5196,7 @@ export declare namespace Machine {
|
|
|
5552
5196
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
5553
5197
|
readonly resolve?: never
|
|
5554
5198
|
}
|
|
5555
|
-
& InlineDestinationConstruction<S,
|
|
5199
|
+
& InlineDestinationConstruction<S, P, C>
|
|
5556
5200
|
}[DestinationPath<S>]
|
|
5557
5201
|
// A misspelled target matches this member, so validation can name the declared paths instead of `never`.
|
|
5558
5202
|
type InlineUnknownTarget<S extends StateSchemas> = {
|
|
@@ -5642,7 +5286,7 @@ export declare namespace Machine {
|
|
|
5642
5286
|
/** Selects one of the declared `branches`. */
|
|
5643
5287
|
readonly select: BranchSelect<S, Src, R>
|
|
5644
5288
|
},
|
|
5645
|
-
enqueue:
|
|
5289
|
+
enqueue: Commands<EventOf<Ev>, EmittedEventOf<Em>>
|
|
5646
5290
|
) => unknown
|
|
5647
5291
|
/** Set to true to exit and reenter the handler source. */
|
|
5648
5292
|
readonly reenter?: Reenter extends true ? boolean : never
|
|
@@ -5692,7 +5336,7 @@ export declare namespace Machine {
|
|
|
5692
5336
|
& ObjectPolicy<C, Reenter, Acceptance>
|
|
5693
5337
|
& {
|
|
5694
5338
|
/** Enqueues synchronous commands when this transition is selected. */
|
|
5695
|
-
readonly commands?: (context: C, enqueue:
|
|
5339
|
+
readonly commands?: (context: C, enqueue: Commands<EventOf<Ev>, EmittedEventOf<Em>>) => void
|
|
5696
5340
|
}
|
|
5697
5341
|
& DeclarationData<
|
|
5698
5342
|
| InlineDestination<S, Src, C>
|
|
@@ -5776,7 +5420,10 @@ export declare namespace Machine {
|
|
|
5776
5420
|
/** Maps the owning state context to the registered source input. */
|
|
5777
5421
|
readonly input?: never
|
|
5778
5422
|
}
|
|
5779
|
-
|
|
5423
|
+
// Distributes over the source names, so a state that picks its work by a
|
|
5424
|
+
// condition keeps the requirements and outcomes of every name it can pick.
|
|
5425
|
+
type ResolvedInvoke<R, K extends PropertyKey> = K extends PropertyKey ? ResolvedSource<R, K> : never
|
|
5426
|
+
type ResolvedSource<R, K extends PropertyKey> = SourceKind<R, K> extends "effects" ?
|
|
5780
5427
|
{ readonly effect: () => InvokeResolvedSource<SourceValue<R, K>> }
|
|
5781
5428
|
: SourceKind<R, K> extends "streams" ? { readonly stream: () => InvokeResolvedSource<SourceValue<R, K>> }
|
|
5782
5429
|
: SourceKind<R, K> extends "timers" ? { readonly after: Duration.Input }
|
|
@@ -5788,8 +5435,7 @@ export declare namespace Machine {
|
|
|
5788
5435
|
& { readonly child: SourceValue<R, K> }
|
|
5789
5436
|
& (SourceValue<R, K> extends ChildMachine<string, infer M> ? {
|
|
5790
5437
|
readonly [InvokeTypeId]: {
|
|
5791
|
-
readonly error: Types.Covariant<Error<M
|
|
5792
|
-
readonly initialError: Types.Covariant<InitialError<M>>
|
|
5438
|
+
readonly error: Types.Covariant<Error<M>>
|
|
5793
5439
|
readonly requirements: Types.Covariant<Services<M>>
|
|
5794
5440
|
}
|
|
5795
5441
|
} :
|
|
@@ -5869,7 +5515,7 @@ export declare namespace Machine {
|
|
|
5869
5515
|
>
|
|
5870
5516
|
}
|
|
5871
5517
|
type RegisteredInvokeError<R, K extends PropertyKey> = SourceKind<R, K> extends "children"
|
|
5872
|
-
? SourceValue<R, K> extends ChildMachine<string, infer M> ? Error<M>
|
|
5518
|
+
? SourceValue<R, K> extends ChildMachine<string, infer M> ? Error<M> : never
|
|
5873
5519
|
: InvokeRuntimeError<ResolvedInvoke<R, K>>
|
|
5874
5520
|
/**
|
|
5875
5521
|
* A registered source invocation with its required input and reachable outcomes.
|
|
@@ -6067,21 +5713,21 @@ export declare namespace Machine {
|
|
|
6067
5713
|
/** Runs synchronously on entry and may enqueue commands. */
|
|
6068
5714
|
readonly entry?: (
|
|
6069
5715
|
context: StateActionContext<S, Ev, Em, Src, In, Pa>,
|
|
6070
|
-
enqueue:
|
|
6071
|
-
) => StateActionResult
|
|
5716
|
+
enqueue: Commands<EventOf<Ev>, EmittedEventOf<Em>>
|
|
5717
|
+
) => StateActionResult
|
|
6072
5718
|
}
|
|
6073
5719
|
& (Node extends { readonly type: "final" } ?
|
|
6074
5720
|
& {
|
|
6075
5721
|
/** Runs synchronously on exit and may enqueue commands. */
|
|
6076
5722
|
readonly exit?: never
|
|
6077
5723
|
}
|
|
6078
|
-
& OutputHandlerConfig<S,
|
|
5724
|
+
& OutputHandlerConfig<S, Src, FinalOutputContext<S, Ev, Src>>
|
|
6079
5725
|
: {
|
|
6080
5726
|
/** Runs synchronously on exit and may enqueue commands. */
|
|
6081
5727
|
readonly exit?: (
|
|
6082
5728
|
context: StateActionContext<S, Ev, Em, Src, In, Pa>,
|
|
6083
|
-
enqueue:
|
|
6084
|
-
) => StateActionResult
|
|
5729
|
+
enqueue: Commands<EventOf<Ev>, EmittedEventOf<Em>>
|
|
5730
|
+
) => StateActionResult
|
|
6085
5731
|
} & ActiveOutputHandlerConfig<S, Ev, Src>)
|
|
6086
5732
|
: {
|
|
6087
5733
|
/** Runs synchronously on entry and may enqueue commands. */
|
|
@@ -6162,7 +5808,7 @@ export declare namespace Machine {
|
|
|
6162
5808
|
readonly [Tag in TagOf<Ev[number]>]?: Transition<
|
|
6163
5809
|
S,
|
|
6164
5810
|
Src,
|
|
6165
|
-
HandlerContext<S, Ev, Em, Src, Tag,
|
|
5811
|
+
HandlerContext<S, Ev, Em, Src, Tag, In, Pa>,
|
|
6166
5812
|
Ev,
|
|
6167
5813
|
Em,
|
|
6168
5814
|
R,
|
|
@@ -6462,10 +6108,12 @@ export declare namespace Machine {
|
|
|
6462
6108
|
type UnknownSourceMessage<R> = [Extract<SourceKeys<R>, string>] extends [never]
|
|
6463
6109
|
? "Unknown source. Register it in make with effects, streams, timers, logic, or children"
|
|
6464
6110
|
: `Unknown source. Registered: ${JoinUnion<Extract<SourceKeys<R>, string>>}`
|
|
6111
|
+
// Each array entry keeps its declaration: a config array is also checked against the element type of this tuple,
|
|
6112
|
+
// so an entry carrying only validation keys would reject outcome keys such as `resolve` as excess properties.
|
|
6465
6113
|
type ValidateObjectInvoke<I, R, Root, S extends StateSchemas, Path extends string> = I extends
|
|
6466
6114
|
ReadonlyArray<unknown> ?
|
|
6467
|
-
number extends I["length"] ? { readonly [K in keyof I]: ValidateInvokeEntry<I[K], R, never, Root, S, Path> }
|
|
6468
|
-
: { readonly [K in keyof I]: ValidateInvokeEntry<I[K], R, DuplicateInvokeId<I, K, R>, Root, S, Path> } :
|
|
6115
|
+
number extends I["length"] ? { readonly [K in keyof I]: I[K] & ValidateInvokeEntry<I[K], R, never, Root, S, Path> }
|
|
6116
|
+
: { readonly [K in keyof I]: I[K] & ValidateInvokeEntry<I[K], R, DuplicateInvokeId<I, K, R>, Root, S, Path> } :
|
|
6469
6117
|
ValidateInvokeEntry<I, R, never, Root, S, Path>
|
|
6470
6118
|
// Handler config of a dotted state path, read from the root handler config.
|
|
6471
6119
|
type HandlerConfigAt<Config, Path extends string> = Config extends { readonly states: infer Children } ?
|
|
@@ -6603,8 +6251,6 @@ export declare namespace Machine {
|
|
|
6603
6251
|
Ev extends ReadonlyArray<TaggedSchema>,
|
|
6604
6252
|
Em extends ReadonlyArray<TaggedSchema>,
|
|
6605
6253
|
I extends Schema.Top,
|
|
6606
|
-
IE,
|
|
6607
|
-
IR,
|
|
6608
6254
|
Final extends StateIdentifier<S>,
|
|
6609
6255
|
Out,
|
|
6610
6256
|
In extends ReadonlyArray<TaggedSchema>,
|
|
@@ -6630,127 +6276,32 @@ export declare namespace Machine {
|
|
|
6630
6276
|
S,
|
|
6631
6277
|
Ev,
|
|
6632
6278
|
In,
|
|
6633
|
-
Em,
|
|
6634
6279
|
NormalizeObjectConfig<NoInfer<C>, R>,
|
|
6635
6280
|
Extract<
|
|
6636
6281
|
HandlerTreeEvidence<S, { readonly "": NormalizeObjectConfig<NoInfer<C>, R> }>["outputState"],
|
|
6637
6282
|
StateIdentifier<S>
|
|
6638
6283
|
>
|
|
6639
6284
|
>
|
|
6640
|
-
):
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
|
|
6285
|
+
):
|
|
6286
|
+
& Machine<
|
|
6287
|
+
S,
|
|
6288
|
+
Ev,
|
|
6289
|
+
I,
|
|
6290
|
+
Exclude<StateIdentifier<S>, HandleEvidence<S, C, R>["stateId"]>,
|
|
6291
|
+
HandleEvidence<S, C, R>["error"],
|
|
6647
6292
|
HandleEvidence<S, C, R>["services"],
|
|
6648
|
-
|
|
6649
|
-
|
|
6650
|
-
|
|
6651
|
-
|
|
6652
|
-
|
|
6653
|
-
|
|
6654
|
-
|
|
6655
|
-
|
|
6656
|
-
|
|
6657
|
-
|
|
6658
|
-
|
|
6659
|
-
>
|
|
6660
|
-
}
|
|
6661
|
-
|
|
6662
|
-
/**
|
|
6663
|
-
* Any state config.
|
|
6664
|
-
*
|
|
6665
|
-
* @category utility types
|
|
6666
|
-
* @since 0.4.0
|
|
6667
|
-
*/
|
|
6668
|
-
export type AnyStateConfig =
|
|
6669
|
-
| StateConfig<any, any, any, any, any, any, any>
|
|
6670
|
-
| ChoiceStateConfig<any, any, any, any>
|
|
6671
|
-
|
|
6672
|
-
/**
|
|
6673
|
-
* Runtime event-handler map stored for a single state tag.
|
|
6674
|
-
*
|
|
6675
|
-
* @category models
|
|
6676
|
-
* @since 0.4.0
|
|
6677
|
-
*/
|
|
6678
|
-
export type EventHandlerMap<
|
|
6679
|
-
States extends StateSchemas,
|
|
6680
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
6681
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
6682
|
-
StateId extends StateIdentifier<States>,
|
|
6683
|
-
EventTag extends TagOf<Events[number]>,
|
|
6684
|
-
E,
|
|
6685
|
-
R
|
|
6686
|
-
> = Readonly<
|
|
6687
|
-
Record<
|
|
6688
|
-
PropertyKey,
|
|
6689
|
-
TransitionConfig<
|
|
6690
|
-
States,
|
|
6691
|
-
Events,
|
|
6692
|
-
Emits,
|
|
6693
|
-
StateId,
|
|
6694
|
-
HandlerContext<States, Events, Emits, StateId, EventTag, E, R>,
|
|
6695
|
-
true,
|
|
6696
|
-
TransitionAcceptance
|
|
6293
|
+
Final,
|
|
6294
|
+
Out,
|
|
6295
|
+
Em,
|
|
6296
|
+
Extract<HandleEvidence<S, C, R>["outputState"], StateIdentifier<S>>,
|
|
6297
|
+
In,
|
|
6298
|
+
Pa
|
|
6299
|
+
>
|
|
6300
|
+
// Type-only: what `MachineTest.check` reads to type supplied results.
|
|
6301
|
+
// Mapped in place, so a declaration prints the results and not the sources.
|
|
6302
|
+
& EffectResultsEvidence<
|
|
6303
|
+
{ readonly [K in keyof Registered<R, "effects"> & string]: EffectResultOf<Registered<R, "effects">[K]> }
|
|
6697
6304
|
>
|
|
6698
|
-
>
|
|
6699
|
-
>
|
|
6700
|
-
|
|
6701
|
-
/**
|
|
6702
|
-
* Runtime state config stored for a single state tag.
|
|
6703
|
-
*
|
|
6704
|
-
* @category models
|
|
6705
|
-
* @since 0.4.0
|
|
6706
|
-
*/
|
|
6707
|
-
export interface StateConfig<
|
|
6708
|
-
States extends StateSchemas,
|
|
6709
|
-
Events extends ReadonlyArray<TaggedSchema>,
|
|
6710
|
-
Emits extends ReadonlyArray<TaggedSchema>,
|
|
6711
|
-
StateId extends StateIdentifier<States>,
|
|
6712
|
-
EventTag extends TagOf<Events[number]>,
|
|
6713
|
-
E,
|
|
6714
|
-
R
|
|
6715
|
-
> {
|
|
6716
|
-
/** Runs synchronously on entry and may enqueue commands. */
|
|
6717
|
-
readonly entry?: (
|
|
6718
|
-
context: StateActionContext<States, Events, Emits, StateId>,
|
|
6719
|
-
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
6720
|
-
) => StateActionResult<E, R>
|
|
6721
|
-
/** Runs synchronously on exit and may enqueue commands. */
|
|
6722
|
-
readonly exit?: (
|
|
6723
|
-
context: StateActionContext<States, Events, Emits, StateId>,
|
|
6724
|
-
enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
|
|
6725
|
-
) => StateActionResult<E, R>
|
|
6726
|
-
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
6727
|
-
readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>
|
|
6728
|
-
/** Eventless transition evaluated during stabilization. */
|
|
6729
|
-
readonly always?: TransitionConfig<
|
|
6730
|
-
States,
|
|
6731
|
-
Events,
|
|
6732
|
-
Emits,
|
|
6733
|
-
StateId,
|
|
6734
|
-
AlwaysContext<States, Events, Emits, StateId>,
|
|
6735
|
-
false,
|
|
6736
|
-
TransitionAcceptance
|
|
6737
|
-
>
|
|
6738
|
-
/** Handles successful invocation or state completion with its exact output type. */
|
|
6739
|
-
readonly onDone?: TransitionConfig<
|
|
6740
|
-
States,
|
|
6741
|
-
Events,
|
|
6742
|
-
Emits,
|
|
6743
|
-
StateId,
|
|
6744
|
-
DoneContext<States, Events, Emits, StateId>,
|
|
6745
|
-
false,
|
|
6746
|
-
TransitionAcceptance
|
|
6747
|
-
>
|
|
6748
|
-
/** Constructs the decoded output declared by the state schema. */
|
|
6749
|
-
readonly output?:
|
|
6750
|
-
| ((context: FinalOutputContext<States, Events, StateId>) => unknown)
|
|
6751
|
-
| ((context: ParallelOutputContext<States, Events, StateId>) => unknown)
|
|
6752
|
-
/** Event handlers keyed by the public or internal event tag. */
|
|
6753
|
-
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>
|
|
6754
6305
|
}
|
|
6755
6306
|
|
|
6756
6307
|
// An explicit export makes this ambient namespace export only the members marked `export`; the rest stay private.
|
|
@@ -6849,8 +6400,6 @@ export const isFinal: <
|
|
|
6849
6400
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
6850
6401
|
E = never,
|
|
6851
6402
|
R = never,
|
|
6852
|
-
InitialE = never,
|
|
6853
|
-
InitialR = never,
|
|
6854
6403
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
6855
6404
|
Output = never,
|
|
6856
6405
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
@@ -6864,8 +6413,6 @@ export const isFinal: <
|
|
|
6864
6413
|
UnhandledStates,
|
|
6865
6414
|
E,
|
|
6866
6415
|
R,
|
|
6867
|
-
InitialE,
|
|
6868
|
-
InitialR,
|
|
6869
6416
|
FinalStates,
|
|
6870
6417
|
Output,
|
|
6871
6418
|
Emits,
|
|
@@ -6935,8 +6482,6 @@ type MakeConfig<
|
|
|
6935
6482
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
6936
6483
|
Emits extends ReadonlyArray<Machine.TaggedSchema>,
|
|
6937
6484
|
Input extends Schema.Top,
|
|
6938
|
-
InitialE,
|
|
6939
|
-
InitialR,
|
|
6940
6485
|
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
6941
6486
|
ParentDeclaration extends Parent.Any | undefined,
|
|
6942
6487
|
Effects extends Machine.EffectSources,
|
|
@@ -6985,8 +6530,6 @@ type MakeResult<
|
|
|
6985
6530
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
6986
6531
|
Emits extends ReadonlyArray<Machine.TaggedSchema>,
|
|
6987
6532
|
Input extends Schema.Top,
|
|
6988
|
-
InitialE,
|
|
6989
|
-
InitialR,
|
|
6990
6533
|
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
6991
6534
|
ParentDeclaration extends Parent.Any | undefined,
|
|
6992
6535
|
Effects extends Machine.EffectSources,
|
|
@@ -6998,8 +6541,6 @@ type MakeResult<
|
|
|
6998
6541
|
{ readonly "": Root },
|
|
6999
6542
|
readonly [...InputEvents, ...InternalEvents],
|
|
7000
6543
|
Input,
|
|
7001
|
-
InitialE,
|
|
7002
|
-
InitialR,
|
|
7003
6544
|
Machine.FinalStateFromDefinition<{ readonly "": Root }>,
|
|
7004
6545
|
Machine.TerminalOutput<{ readonly "": Root }>,
|
|
7005
6546
|
Emits,
|
|
@@ -7027,8 +6568,6 @@ type Make = {
|
|
|
7027
6568
|
const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
7028
6569
|
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
7029
6570
|
const Input extends Schema.Top = typeof Schema.Void,
|
|
7030
|
-
InitialE = never,
|
|
7031
|
-
InitialR = never,
|
|
7032
6571
|
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
7033
6572
|
const ParentDeclaration extends Parent.Any | undefined = undefined,
|
|
7034
6573
|
const Effects extends Machine.EffectSources = {},
|
|
@@ -7043,8 +6582,6 @@ type Make = {
|
|
|
7043
6582
|
InputEvents,
|
|
7044
6583
|
Emits,
|
|
7045
6584
|
Input,
|
|
7046
|
-
InitialE,
|
|
7047
|
-
InitialR,
|
|
7048
6585
|
InternalEvents,
|
|
7049
6586
|
ParentDeclaration,
|
|
7050
6587
|
Effects,
|
|
@@ -7059,8 +6596,6 @@ type Make = {
|
|
|
7059
6596
|
InputEvents,
|
|
7060
6597
|
Emits,
|
|
7061
6598
|
Input,
|
|
7062
|
-
InitialE,
|
|
7063
|
-
InitialR,
|
|
7064
6599
|
InternalEvents,
|
|
7065
6600
|
ParentDeclaration,
|
|
7066
6601
|
Effects,
|
|
@@ -7087,6 +6622,13 @@ type Make = {
|
|
|
7087
6622
|
* registered source by name with `invoke: { src }`, and only invoked sources
|
|
7088
6623
|
* add to the machine's requirements.
|
|
7089
6624
|
*
|
|
6625
|
+
* Each run of invoked work owns a `Scope`, which every host closes when the run
|
|
6626
|
+
* ends or is stopped. An Effect and a Stream get a new one for each run, and
|
|
6627
|
+
* logic gets one from its `initial` through the end of its `run`. Finalizers
|
|
6628
|
+
* added with `Effect.addFinalizer` or `Effect.acquireRelease` therefore run with
|
|
6629
|
+
* the work, not when the machine stops. A timer acquires nothing, and a child
|
|
6630
|
+
* machine has no scope of its own: its invoked work follows the same rule.
|
|
6631
|
+
*
|
|
7090
6632
|
* `Machine.events` defines the public input protocol. `Machine.internalEvents`
|
|
7091
6633
|
* adds raised events and other machine-local deliveries.
|
|
7092
6634
|
* `Machine.emittedEvents` defines outward ephemeral notifications. The
|
|
@@ -7104,7 +6646,7 @@ type Make = {
|
|
|
7104
6646
|
* **Example** (Invoking a registered Effect)
|
|
7105
6647
|
*
|
|
7106
6648
|
* ```ts import.meta.vitest
|
|
7107
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
6649
|
+
* import { LocalMachine, Machine } from "@typeonce/effect-machine"
|
|
7108
6650
|
* import { Effect, Option, Schema } from "effect"
|
|
7109
6651
|
*
|
|
7110
6652
|
* const Lookup = Schema.TaggedUnion({ Loading: { id: Schema.String }, Ready: { name: Schema.String } })
|
|
@@ -7130,7 +6672,7 @@ type Make = {
|
|
|
7130
6672
|
* })
|
|
7131
6673
|
*
|
|
7132
6674
|
* const name = Effect.scoped(Effect.gen(function*() {
|
|
7133
|
-
* const ref = yield*
|
|
6675
|
+
* const ref = yield* LocalMachine.start(machine)
|
|
7134
6676
|
* yield* ref.send(Events.Load({ id: "1" }))
|
|
7135
6677
|
* const ready = yield* Machine.waitFor(ref, ({ state }) => state.state.path === "Ready").pipe(Effect.timeout("5 seconds"))
|
|
7136
6678
|
* return States.get(ready.state, "Ready").pipe(Option.map((state) => state.name))
|
|
@@ -7244,7 +6786,7 @@ export const events: <const Cases extends Readonly<Record<string, Schema.Struct.
|
|
|
7244
6786
|
* **Example** (Reusing a tagged union as the event protocol)
|
|
7245
6787
|
*
|
|
7246
6788
|
* ```ts import.meta.vitest
|
|
7247
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
6789
|
+
* import { LocalMachine, Machine } from "@typeonce/effect-machine"
|
|
7248
6790
|
* import { Effect, Schema } from "effect"
|
|
7249
6791
|
*
|
|
7250
6792
|
* const Event = Machine.eventsFromSchemas(
|
|
@@ -7262,7 +6804,7 @@ export const events: <const Cases extends Readonly<Record<string, Schema.Struct.
|
|
|
7262
6804
|
* })
|
|
7263
6805
|
*
|
|
7264
6806
|
* const count = Effect.scoped(Effect.gen(function*() {
|
|
7265
|
-
* const ref = yield*
|
|
6807
|
+
* const ref = yield* LocalMachine.start(machine)
|
|
7266
6808
|
* yield* ref.send(Event.Increment({ by: 1 }))
|
|
7267
6809
|
* return (yield* ref.state).value.count
|
|
7268
6810
|
* }))
|
|
@@ -7435,7 +6977,7 @@ export const emittedEventsFromSchemas: {
|
|
|
7435
6977
|
* **When to use**
|
|
7436
6978
|
*
|
|
7437
6979
|
* Use when you need to store or transport a statechart snapshot independently
|
|
7438
|
-
* of
|
|
6980
|
+
* of the host that runs the machine.
|
|
7439
6981
|
*
|
|
7440
6982
|
* **Details**
|
|
7441
6983
|
*
|
|
@@ -7487,8 +7029,6 @@ export const encodeSnapshot: <
|
|
|
7487
7029
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
7488
7030
|
E = never,
|
|
7489
7031
|
R = never,
|
|
7490
|
-
InitialE = never,
|
|
7491
|
-
InitialR = never,
|
|
7492
7032
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
7493
7033
|
Output = never,
|
|
7494
7034
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
@@ -7502,8 +7042,6 @@ export const encodeSnapshot: <
|
|
|
7502
7042
|
UnhandledStates,
|
|
7503
7043
|
E,
|
|
7504
7044
|
R,
|
|
7505
|
-
InitialE,
|
|
7506
|
-
InitialR,
|
|
7507
7045
|
FinalStates,
|
|
7508
7046
|
Output,
|
|
7509
7047
|
Emits,
|
|
@@ -7570,8 +7108,6 @@ export const decodeSnapshot: <
|
|
|
7570
7108
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
7571
7109
|
E = never,
|
|
7572
7110
|
R = never,
|
|
7573
|
-
InitialE = never,
|
|
7574
|
-
InitialR = never,
|
|
7575
7111
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
7576
7112
|
Output = never,
|
|
7577
7113
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
@@ -7585,8 +7121,6 @@ export const decodeSnapshot: <
|
|
|
7585
7121
|
UnhandledStates,
|
|
7586
7122
|
E,
|
|
7587
7123
|
R,
|
|
7588
|
-
InitialE,
|
|
7589
|
-
InitialR,
|
|
7590
7124
|
FinalStates,
|
|
7591
7125
|
Output,
|
|
7592
7126
|
Emits,
|
|
@@ -7615,9 +7149,9 @@ export const decodeSnapshot: <
|
|
|
7615
7149
|
*
|
|
7616
7150
|
* **Gotchas**
|
|
7617
7151
|
*
|
|
7618
|
-
*
|
|
7619
|
-
* protocol. Manual planners may inspect commands
|
|
7620
|
-
* to execute child-addressed operations.
|
|
7152
|
+
* Planning does not execute the closed command list. A host such as `LocalMachine`
|
|
7153
|
+
* executes it as part of its commit protocol. Manual planners may inspect commands
|
|
7154
|
+
* but need running machine targets to execute child-addressed operations.
|
|
7621
7155
|
*
|
|
7622
7156
|
* **Example** (Planning startup without running the machine)
|
|
7623
7157
|
*
|
|
@@ -7636,7 +7170,6 @@ export const decodeSnapshot: <
|
|
|
7636
7170
|
* ```
|
|
7637
7171
|
*
|
|
7638
7172
|
* @see {@link plan} for planning a received event.
|
|
7639
|
-
* @see {@link start} for the managed runtime protocol.
|
|
7640
7173
|
* @category constructors
|
|
7641
7174
|
* @since 0.4.0
|
|
7642
7175
|
*/
|
|
@@ -7648,8 +7181,6 @@ export const planInitial: <
|
|
|
7648
7181
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
7649
7182
|
E = never,
|
|
7650
7183
|
R = never,
|
|
7651
|
-
InitialE = never,
|
|
7652
|
-
InitialR = never,
|
|
7653
7184
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
7654
7185
|
Output = never,
|
|
7655
7186
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
@@ -7664,8 +7195,6 @@ export const planInitial: <
|
|
|
7664
7195
|
UnhandledStates,
|
|
7665
7196
|
E,
|
|
7666
7197
|
R,
|
|
7667
|
-
InitialE,
|
|
7668
|
-
InitialR,
|
|
7669
7198
|
FinalStates,
|
|
7670
7199
|
Output,
|
|
7671
7200
|
Emits,
|
|
@@ -7713,7 +7242,7 @@ export const planInitial: <
|
|
|
7713
7242
|
readonly output: undefined
|
|
7714
7243
|
}
|
|
7715
7244
|
),
|
|
7716
|
-
|
|
7245
|
+
E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError,
|
|
7717
7246
|
never
|
|
7718
7247
|
> = internal.planInitial
|
|
7719
7248
|
|
|
@@ -7794,7 +7323,7 @@ export const transitionDefinitions: <M extends Machine.Any>(machine: M) => Reado
|
|
|
7794
7323
|
> = internal.transitionDefinitions
|
|
7795
7324
|
|
|
7796
7325
|
/**
|
|
7797
|
-
* Returns serializable descriptions of every state-owned
|
|
7326
|
+
* Returns serializable descriptions of every state-owned invocation.
|
|
7798
7327
|
*
|
|
7799
7328
|
* **Details**
|
|
7800
7329
|
*
|
|
@@ -7805,10 +7334,10 @@ export const transitionDefinitions: <M extends Machine.Any>(machine: M) => Reado
|
|
|
7805
7334
|
* @category getters
|
|
7806
7335
|
* @since 0.4.0
|
|
7807
7336
|
*/
|
|
7808
|
-
export const
|
|
7337
|
+
export const invocationDefinitions: <M extends Machine.Any>(
|
|
7809
7338
|
machine: M
|
|
7810
|
-
) => ReadonlyArray<Machine.
|
|
7811
|
-
internal.
|
|
7339
|
+
) => ReadonlyArray<Machine.InvocationDefinition<Machine.StateIdentifier<Machine.States<M>>>> =
|
|
7340
|
+
internal.invocationDefinitions
|
|
7812
7341
|
|
|
7813
7342
|
/**
|
|
7814
7343
|
* Returns every state node active in a decoded snapshot, in definition order.
|
|
@@ -7851,8 +7380,6 @@ export const enabled: <
|
|
|
7851
7380
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
7852
7381
|
E = never,
|
|
7853
7382
|
R = never,
|
|
7854
|
-
InitialE = never,
|
|
7855
|
-
InitialR = never,
|
|
7856
7383
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
7857
7384
|
Output = never,
|
|
7858
7385
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
@@ -7866,8 +7393,6 @@ export const enabled: <
|
|
|
7866
7393
|
UnhandledStates,
|
|
7867
7394
|
E,
|
|
7868
7395
|
R,
|
|
7869
|
-
InitialE,
|
|
7870
|
-
InitialR,
|
|
7871
7396
|
FinalStates,
|
|
7872
7397
|
Output,
|
|
7873
7398
|
Emits,
|
|
@@ -7942,8 +7467,6 @@ export const can: {
|
|
|
7942
7467
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
7943
7468
|
E = never,
|
|
7944
7469
|
R = never,
|
|
7945
|
-
InitialE = never,
|
|
7946
|
-
InitialR = never,
|
|
7947
7470
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
7948
7471
|
Output = never,
|
|
7949
7472
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
@@ -7958,8 +7481,6 @@ export const can: {
|
|
|
7958
7481
|
UnhandledStates,
|
|
7959
7482
|
E,
|
|
7960
7483
|
R,
|
|
7961
|
-
InitialE,
|
|
7962
|
-
InitialR,
|
|
7963
7484
|
FinalStates,
|
|
7964
7485
|
Output,
|
|
7965
7486
|
Emits,
|
|
@@ -7981,8 +7502,6 @@ export const can: {
|
|
|
7981
7502
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
7982
7503
|
E = never,
|
|
7983
7504
|
R = never,
|
|
7984
|
-
InitialE = never,
|
|
7985
|
-
InitialR = never,
|
|
7986
7505
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
7987
7506
|
Output = never,
|
|
7988
7507
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
@@ -7997,8 +7516,6 @@ export const can: {
|
|
|
7997
7516
|
UnhandledStates,
|
|
7998
7517
|
E,
|
|
7999
7518
|
R,
|
|
8000
|
-
InitialE,
|
|
8001
|
-
InitialR,
|
|
8002
7519
|
FinalStates,
|
|
8003
7520
|
Output,
|
|
8004
7521
|
Emits,
|
|
@@ -8025,8 +7542,8 @@ export const can: {
|
|
|
8025
7542
|
*
|
|
8026
7543
|
* **Gotchas**
|
|
8027
7544
|
*
|
|
8028
|
-
* `plan` returns data; it does not implement
|
|
8029
|
-
* `
|
|
7545
|
+
* `plan` returns data; it does not implement a commit protocol. A host such as
|
|
7546
|
+
* `LocalMachine` executes child commands, publishes `next`, and then delivers
|
|
8030
7547
|
* `emittedEvents`. Events with no enabled transition are ignored and produce
|
|
8031
7548
|
* an unchanged plan.
|
|
8032
7549
|
*
|
|
@@ -8057,7 +7574,6 @@ export const can: {
|
|
|
8057
7574
|
* ```
|
|
8058
7575
|
*
|
|
8059
7576
|
* @see {@link planInitial} for planning machine startup.
|
|
8060
|
-
* @see {@link start} for managed execution and lifecycle observation.
|
|
8061
7577
|
* @category combinators
|
|
8062
7578
|
* @since 0.4.0
|
|
8063
7579
|
*/
|
|
@@ -8069,8 +7585,6 @@ export const plan: <
|
|
|
8069
7585
|
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
8070
7586
|
E = never,
|
|
8071
7587
|
R = never,
|
|
8072
|
-
InitialE = never,
|
|
8073
|
-
InitialR = never,
|
|
8074
7588
|
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
8075
7589
|
Output = never,
|
|
8076
7590
|
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
@@ -8085,8 +7599,6 @@ export const plan: <
|
|
|
8085
7599
|
UnhandledStates,
|
|
8086
7600
|
E,
|
|
8087
7601
|
R,
|
|
8088
|
-
InitialE,
|
|
8089
|
-
InitialR,
|
|
8090
7602
|
FinalStates,
|
|
8091
7603
|
Output,
|
|
8092
7604
|
Emits,
|
|
@@ -8139,73 +7651,930 @@ export const plan: <
|
|
|
8139
7651
|
> = internal.plan
|
|
8140
7652
|
|
|
8141
7653
|
/**
|
|
8142
|
-
*
|
|
8143
|
-
*
|
|
8144
|
-
*
|
|
8145
|
-
* **When to use**
|
|
8146
|
-
*
|
|
8147
|
-
* Use when you need a machine-scoped process to publish intermediate snapshots
|
|
8148
|
-
* directly.
|
|
7654
|
+
* The pure form of a machine, returned by {@link toStep}: functions that say
|
|
7655
|
+
* what the next state is, and which work to start and stop, without running
|
|
7656
|
+
* anything.
|
|
8149
7657
|
*
|
|
8150
7658
|
* **Details**
|
|
8151
7659
|
*
|
|
8152
|
-
*
|
|
8153
|
-
*
|
|
8154
|
-
*
|
|
8155
|
-
*
|
|
7660
|
+
* Every function is synchronous and returns a value. Equal arguments give equal
|
|
7661
|
+
* results, and no call changes a value a caller holds, so a caller may keep an
|
|
7662
|
+
* earlier {@link MachineStep.State} and step from it again.
|
|
7663
|
+
*
|
|
7664
|
+
* - `start` starts the machine from its input, as `LocalMachine.start` does.
|
|
7665
|
+
* - `send` takes one public event. A failed `Exit` means the step did not
|
|
7666
|
+
* happen and the state passed in still holds: the event does not match its
|
|
7667
|
+
* schema (`MachineSchemaDecodeError`), or the machine has ended
|
|
7668
|
+
* (`StoppedError`).
|
|
7669
|
+
* - `settle` reports the end of work that a step started, with its `Exit`, and
|
|
7670
|
+
* that work could not start, with the failure of its evaluation.
|
|
7671
|
+
* - `element` reports one element of a running Stream.
|
|
7672
|
+
* - `report` reports the state of a running `Logic` or child machine.
|
|
7673
|
+
* - `stop` stops the machine as its owner, as `MachineRef.stop` does.
|
|
7674
|
+
* - `resume` starts the machine from a decoded snapshot, as `LocalMachine.resume`
|
|
7675
|
+
* does. A durable host passes the {@link MachineStep.Progress} of the work of
|
|
7676
|
+
* the active states, so that work which ended does not run again and work
|
|
7677
|
+
* which still runs is not started twice.
|
|
7678
|
+
*
|
|
7679
|
+
* A machine that fails or ends still takes a step. The step carries the last
|
|
7680
|
+
* state, the work to stop, and its {@link MachineStep.Step} `exit`.
|
|
8156
7681
|
*
|
|
8157
7682
|
* **Gotchas**
|
|
8158
7683
|
*
|
|
8159
|
-
*
|
|
8160
|
-
*
|
|
8161
|
-
*
|
|
8162
|
-
*
|
|
7684
|
+
* The result of `settle`, `element`, or `report` for work whose state was
|
|
7685
|
+
* exited is a step that changes nothing, also when the same state was entered
|
|
7686
|
+
* again since. So is the result for work that already ended, and for any work
|
|
7687
|
+
* of a machine that has ended.
|
|
8163
7688
|
*
|
|
8164
|
-
*
|
|
8165
|
-
*
|
|
8166
|
-
*
|
|
7689
|
+
* These functions take the work object that a step listed, and compare it by
|
|
7690
|
+
* identity. A copy of it changes nothing. Neither does work that was listed
|
|
7691
|
+
* before a `resume`, or by another step taken from the same state, even though
|
|
7692
|
+
* its `path`, `id`, and `run` are equal.
|
|
8167
7693
|
*
|
|
8168
|
-
* @
|
|
8169
|
-
* @
|
|
8170
|
-
* @since 0.4.0
|
|
7694
|
+
* @category models
|
|
7695
|
+
* @since 0.48.0
|
|
8171
7696
|
*/
|
|
8172
|
-
export
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
Requirements = never,
|
|
8178
|
-
InitialError = never,
|
|
8179
|
-
InitialRequirements = never
|
|
8180
|
-
>(options: {
|
|
8181
|
-
/** The first state, or an Effect that produces it from the process scope before `run` starts. */
|
|
8182
|
-
readonly initial:
|
|
8183
|
-
| State
|
|
8184
|
-
| ((
|
|
8185
|
-
scope: Logic.Scope<Event>
|
|
8186
|
-
) => Effect.Effect<State, InitialError, InitialRequirements>)
|
|
8187
|
-
readonly run: (
|
|
8188
|
-
context: Logic.Context<State, Event>
|
|
8189
|
-
) => Effect.Effect<Output, Error, Requirements>
|
|
8190
|
-
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError> = internal.logic
|
|
7697
|
+
export interface MachineStep<in out M extends Machine.Any> {
|
|
7698
|
+
/** Starts the machine from its decoded input. */
|
|
7699
|
+
readonly start: (
|
|
7700
|
+
...input: [...Machine.InputArgs<Machine.InputSchema<M>>]
|
|
7701
|
+
) => Exit.Exit<MachineStep.Step<M>, MachineStep.StartError>
|
|
8191
7702
|
|
|
8192
|
-
/**
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8199
|
-
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
7703
|
+
/**
|
|
7704
|
+
* Takes one public event. A failure means that the event was rejected and
|
|
7705
|
+
* `state` still holds.
|
|
7706
|
+
*/
|
|
7707
|
+
readonly send: (
|
|
7708
|
+
state: MachineStep.State<M>,
|
|
7709
|
+
event: Machine.EventInputOf<Machine.InputEvents<M>>
|
|
7710
|
+
) => Exit.Exit<MachineStep.Step<M>, MachineStep.Rejection>
|
|
7711
|
+
|
|
7712
|
+
/**
|
|
7713
|
+
* Reports the end of work that a step started, or the failure of its
|
|
7714
|
+
* evaluation when it could not start.
|
|
7715
|
+
*/
|
|
7716
|
+
readonly settle: (
|
|
7717
|
+
state: MachineStep.State<M>,
|
|
7718
|
+
work: MachineStep.Work<M>,
|
|
7719
|
+
exit: Exit.Exit<unknown, unknown>
|
|
7720
|
+
) => MachineStep.Step<M>
|
|
7721
|
+
|
|
7722
|
+
/**
|
|
7723
|
+
* Reports one element of a running Stream. The element is taken before the
|
|
7724
|
+
* next one is pulled.
|
|
7725
|
+
*/
|
|
7726
|
+
readonly element: (
|
|
7727
|
+
state: MachineStep.State<M>,
|
|
7728
|
+
work: MachineStep.Work.Stream<M>,
|
|
7729
|
+
element: unknown
|
|
7730
|
+
) => MachineStep.Step<M>
|
|
7731
|
+
|
|
7732
|
+
/**
|
|
7733
|
+
* Reports the state of a running `Logic` or child machine while it is
|
|
7734
|
+
* active: the state that the `Logic` sets, or the snapshot that a step of the
|
|
7735
|
+
* child publishes. Its owner reads it as the `state` of the snapshot that
|
|
7736
|
+
* `onSnapshot` receives.
|
|
7737
|
+
*/
|
|
7738
|
+
readonly report: (
|
|
7739
|
+
state: MachineStep.State<M>,
|
|
7740
|
+
work: MachineStep.Work.Logic<M> | MachineStep.Work.Child<M>,
|
|
7741
|
+
snapshot: unknown
|
|
7742
|
+
) => MachineStep.Step<M>
|
|
7743
|
+
|
|
7744
|
+
/** Stops the machine as its owner. Its `exit` fails with `StoppedError`. */
|
|
7745
|
+
readonly stop: (state: MachineStep.State<M>) => MachineStep.Step<M>
|
|
7746
|
+
|
|
7747
|
+
/**
|
|
7748
|
+
* Starts the machine from a decoded snapshot. `progress` names the work of
|
|
7749
|
+
* the active states that ended or still runs; any other work starts.
|
|
7750
|
+
*/
|
|
7751
|
+
readonly resume: (
|
|
7752
|
+
snapshot: Machine.Snapshot<Machine.States<M>>,
|
|
7753
|
+
progress?: ReadonlyArray<MachineStep.Progress<M>>
|
|
7754
|
+
) => Exit.Exit<MachineStep.Step<M>, MachineSchemaDecodeError>
|
|
7755
|
+
}
|
|
8203
7756
|
|
|
8204
7757
|
/**
|
|
8205
|
-
*
|
|
7758
|
+
* Types of the values that a {@link MachineStep} takes and returns.
|
|
8206
7759
|
*
|
|
8207
|
-
*
|
|
8208
|
-
*
|
|
7760
|
+
* @category models
|
|
7761
|
+
* @since 0.48.0
|
|
7762
|
+
*/
|
|
7763
|
+
export declare namespace MachineStep {
|
|
7764
|
+
/**
|
|
7765
|
+
* The state of a machine, as a host passes it from one step to the next.
|
|
7766
|
+
*
|
|
7767
|
+
* **Details**
|
|
7768
|
+
*
|
|
7769
|
+
* It is an immutable value. It holds the logical state, the work that runs,
|
|
7770
|
+
* and which entry of each invoking state the work belongs to, which is how a
|
|
7771
|
+
* step tells current work from work of an earlier entry.
|
|
7772
|
+
*
|
|
7773
|
+
* **Gotchas**
|
|
7774
|
+
*
|
|
7775
|
+
* Only the steps of the same machine construct it. Encode
|
|
7776
|
+
* {@link Step} `snapshot` with `Machine.encodeSnapshot` to store it, and
|
|
7777
|
+
* `resume` from the decoded snapshot.
|
|
7778
|
+
*
|
|
7779
|
+
* @category models
|
|
7780
|
+
* @since 0.48.0
|
|
7781
|
+
*/
|
|
7782
|
+
export interface State<in out M extends Machine.Any> {
|
|
7783
|
+
readonly [MachineStepStateTypeId]: Types.Invariant<M>
|
|
7784
|
+
}
|
|
7785
|
+
|
|
7786
|
+
/**
|
|
7787
|
+
* What one step did, and what its host does next.
|
|
7788
|
+
*
|
|
7789
|
+
* **Details**
|
|
7790
|
+
*
|
|
7791
|
+
* A host carries a step out in this order, which is the order of
|
|
7792
|
+
* `LocalMachine`: it carries out `commands`, interrupts `stop`, publishes
|
|
7793
|
+
* `snapshot`, delivers `emitted`, starts `start`, and interrupts `stopAfter`.
|
|
7794
|
+
*
|
|
7795
|
+
* `snapshot` and `microsteps` are built when they are first read, so a host
|
|
7796
|
+
* that publishes neither pays for neither.
|
|
7797
|
+
*
|
|
7798
|
+
* @category models
|
|
7799
|
+
* @since 0.48.0
|
|
7800
|
+
*/
|
|
7801
|
+
export interface Step<in out M extends Machine.Any> {
|
|
7802
|
+
/** The state to pass to the next step. */
|
|
7803
|
+
readonly state: State<M>
|
|
7804
|
+
|
|
7805
|
+
/** The logical state, as a view reads it and `Machine.encodeSnapshot` stores it. */
|
|
7806
|
+
readonly snapshot: Machine.Snapshot<Machine.States<M>>
|
|
7807
|
+
|
|
7808
|
+
/**
|
|
7809
|
+
* The event this step planned, as transitions received it: a decoded
|
|
7810
|
+
* public event, the lifecycle event of work, or the initial event of `start`
|
|
7811
|
+
* and `resume`. It is set also when planning it failed the machine.
|
|
7812
|
+
* `undefined` when the step planned no event, as for `stop`, a result that
|
|
7813
|
+
* is ignored, or a result that fails the machine without a transition.
|
|
7814
|
+
*/
|
|
7815
|
+
readonly event: Machine.LifecycleEvent<Machine.Events<M>> | undefined
|
|
7816
|
+
|
|
7817
|
+
/** The microsteps of the plan, in order, as `Machine.plan` returns them. Empty when nothing changed. */
|
|
7818
|
+
readonly microsteps: ReadonlyArray<Microstep<M>>
|
|
7819
|
+
|
|
7820
|
+
/** What transitions asked of the host with `enqueue.sendTo` and `enqueue.stop`, in order. */
|
|
7821
|
+
readonly commands: ReadonlyArray<Command<M>>
|
|
7822
|
+
|
|
7823
|
+
/**
|
|
7824
|
+
* Running work to interrupt before publishing `snapshot`, in order: work of
|
|
7825
|
+
* exited states, or all remaining work when the machine fails or is
|
|
7826
|
+
* stopped. Its `Exit` is not reported.
|
|
7827
|
+
*/
|
|
7828
|
+
readonly stop: ReadonlyArray<Work<M>>
|
|
7829
|
+
|
|
7830
|
+
/** Events emitted to the observers of the machine, in order. */
|
|
7831
|
+
readonly emitted: ReadonlyArray<Machine.EmittedEvent<M>>
|
|
7832
|
+
|
|
7833
|
+
/** Work to start, in order. Report its end with `settle`. */
|
|
7834
|
+
readonly start: ReadonlyArray<Work<M>>
|
|
7835
|
+
|
|
7836
|
+
/**
|
|
7837
|
+
* Running work of states that were not exited, to interrupt after
|
|
7838
|
+
* publishing `snapshot` and delivering `emitted` when this step reaches a
|
|
7839
|
+
* final state, latest first. Empty on every non-final, failed, or owner-stopped
|
|
7840
|
+
* step. Its `Exit` is not reported.
|
|
7841
|
+
*/
|
|
7842
|
+
readonly stopAfter: ReadonlyArray<Work<M>>
|
|
7843
|
+
|
|
7844
|
+
/**
|
|
7845
|
+
* Every piece of work that runs once this step is carried out, in start
|
|
7846
|
+
* order: the work that runs on, and then `start`. After `resume`, it also
|
|
7847
|
+
* holds the work that {@link Progress} names as running.
|
|
7848
|
+
*/
|
|
7849
|
+
readonly running: ReadonlyArray<Work<M>>
|
|
7850
|
+
|
|
7851
|
+
/**
|
|
7852
|
+
* Paths of the states that this step exited, in exit order, each once. A
|
|
7853
|
+
* durable host forgets what it stored about the work of these states. A
|
|
7854
|
+
* state that the step exited and entered again is in `exited` and in
|
|
7855
|
+
* `entered`. `start`, `resume`, `stop`, and a result that is ignored exit
|
|
7856
|
+
* nothing.
|
|
7857
|
+
*/
|
|
7858
|
+
readonly exited: ReadonlyArray<Machine.StateIdentifier<Machine.States<M>>>
|
|
7859
|
+
|
|
7860
|
+
/**
|
|
7861
|
+
* Paths of the states that this step entered, in entry order, each once.
|
|
7862
|
+
* `start` enters the states of the initial state. `resume` restores its
|
|
7863
|
+
* states and enters none.
|
|
7864
|
+
*/
|
|
7865
|
+
readonly entered: ReadonlyArray<Machine.StateIdentifier<Machine.States<M>>>
|
|
7866
|
+
|
|
7867
|
+
/**
|
|
7868
|
+
* How the machine ended, once it has: its output, or why it failed or
|
|
7869
|
+
* stopped. A machine that has ended runs no work and takes no event.
|
|
7870
|
+
*/
|
|
7871
|
+
readonly exit: Exit.Exit<Machine.Output<M>, Error<M>> | undefined
|
|
7872
|
+
}
|
|
7873
|
+
|
|
7874
|
+
/**
|
|
7875
|
+
* One microstep of a {@link Step}.
|
|
7876
|
+
*
|
|
7877
|
+
* @category models
|
|
7878
|
+
* @since 0.48.0
|
|
7879
|
+
*/
|
|
7880
|
+
export interface Microstep<M extends Machine.Any> {
|
|
7881
|
+
readonly next: Machine.Snapshot<Machine.States<M>>
|
|
7882
|
+
readonly event: Machine.LifecycleEvent<Machine.Events<M>>
|
|
7883
|
+
readonly transitions: ReadonlyArray<
|
|
7884
|
+
Machine.RetainedTransition<
|
|
7885
|
+
Machine.StateNodeIdentifier<Machine.States<M>>,
|
|
7886
|
+
Machine.TagOf<Machine.Events<M>[number]>,
|
|
7887
|
+
Machine.StateNodeIdentifier<Machine.States<M>>
|
|
7888
|
+
>
|
|
7889
|
+
>
|
|
7890
|
+
readonly commands: ReadonlyArray<Command>
|
|
7891
|
+
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Machine.Events<M>>>
|
|
7892
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEvent<M>>
|
|
7893
|
+
readonly exitPaths: ReadonlyArray<string>
|
|
7894
|
+
readonly entryPaths: ReadonlyArray<string>
|
|
7895
|
+
readonly changed: boolean
|
|
7896
|
+
}
|
|
7897
|
+
|
|
7898
|
+
/**
|
|
7899
|
+
* What a transition asked of its host with `enqueue.sendTo` or
|
|
7900
|
+
* `enqueue.stop`.
|
|
7901
|
+
*
|
|
7902
|
+
* **Details**
|
|
7903
|
+
*
|
|
7904
|
+
* - `Send` sends `event` to a target with `target.send(event)`. An event sent
|
|
7905
|
+
* to `self` reaches the `self` target of the host, which plans it in a
|
|
7906
|
+
* later step.
|
|
7907
|
+
* - `SendToChild` sends `event` to a child of the machine. `work` is the
|
|
7908
|
+
* running `Logic` or child machine that `child` selects, when one runs.
|
|
7909
|
+
* Otherwise the host sends it to a child that work spawned with that
|
|
7910
|
+
* address, and ignores it when there is none.
|
|
7911
|
+
* - `StopChild` stops a child of the machine. `work` is the running `Logic`
|
|
7912
|
+
* or child machine that `child` selects, which no longer runs after this
|
|
7913
|
+
* step: the host stops it, and reports nothing of it. Otherwise the host
|
|
7914
|
+
* stops a child that work spawned with that address, if there is one.
|
|
7915
|
+
*
|
|
7916
|
+
* @category models
|
|
7917
|
+
* @since 0.48.0
|
|
7918
|
+
*/
|
|
7919
|
+
export type Command<M extends Machine.Any = Machine.Any> =
|
|
7920
|
+
| Command.Send
|
|
7921
|
+
| Command.SendToChild<M>
|
|
7922
|
+
| Command.StopChild<M>
|
|
7923
|
+
|
|
7924
|
+
/**
|
|
7925
|
+
* The kinds of {@link Command}.
|
|
7926
|
+
*
|
|
7927
|
+
* @category models
|
|
7928
|
+
* @since 0.48.0
|
|
7929
|
+
*/
|
|
7930
|
+
export namespace Command {
|
|
7931
|
+
/**
|
|
7932
|
+
* Sends an event to a target outside the machine.
|
|
7933
|
+
*
|
|
7934
|
+
* @category models
|
|
7935
|
+
* @since 0.48.0
|
|
7936
|
+
*/
|
|
7937
|
+
export interface Send {
|
|
7938
|
+
readonly _tag: "Send"
|
|
7939
|
+
readonly target: MachineTarget<unknown>
|
|
7940
|
+
readonly event: unknown
|
|
7941
|
+
}
|
|
7942
|
+
|
|
7943
|
+
/**
|
|
7944
|
+
* Sends an event to a child of the machine.
|
|
7945
|
+
*
|
|
7946
|
+
* @category models
|
|
7947
|
+
* @since 0.48.0
|
|
7948
|
+
*/
|
|
7949
|
+
export interface SendToChild<M extends Machine.Any> {
|
|
7950
|
+
readonly _tag: "SendToChild"
|
|
7951
|
+
readonly child: ChildMachine.Any | ChildAddress<never>
|
|
7952
|
+
readonly work: Work.Logic<M> | Work.Child<M> | undefined
|
|
7953
|
+
readonly event: unknown
|
|
7954
|
+
}
|
|
7955
|
+
|
|
7956
|
+
/**
|
|
7957
|
+
* Stops a child of the machine.
|
|
7958
|
+
*
|
|
7959
|
+
* @category models
|
|
7960
|
+
* @since 0.48.0
|
|
7961
|
+
*/
|
|
7962
|
+
export interface StopChild<M extends Machine.Any> {
|
|
7963
|
+
readonly _tag: "StopChild"
|
|
7964
|
+
readonly child: ChildMachine.Any | ChildAddress<never>
|
|
7965
|
+
readonly work: Work.Logic<M> | Work.Child<M> | undefined
|
|
7966
|
+
}
|
|
7967
|
+
}
|
|
7968
|
+
|
|
7969
|
+
/**
|
|
7970
|
+
* One piece of work that an entry of a state starts.
|
|
7971
|
+
*
|
|
7972
|
+
* **Details**
|
|
7973
|
+
*
|
|
7974
|
+
* Work is described, not evaluated. A host evaluates it when it starts it,
|
|
7975
|
+
* with the accessor of its kind: `effect`, `duration`, `stream`, `logic`, or
|
|
7976
|
+
* `input`. Each accessor calls the source and the input mapper of the work at
|
|
7977
|
+
* most once, however often it is called, and returns an `Exit` instead of
|
|
7978
|
+
* throwing.
|
|
7979
|
+
*
|
|
7980
|
+
* A host starts the work of a step in order. A failed `Exit` of an accessor
|
|
7981
|
+
* means that the work could not start: the host settles the work with that
|
|
7982
|
+
* `Exit` at once. That fails the machine, which then runs no work, so the
|
|
7983
|
+
* rest of the step does not start. This is what `LocalMachine` does when a
|
|
7984
|
+
* source throws.
|
|
7985
|
+
*
|
|
7986
|
+
* @category models
|
|
7987
|
+
* @since 0.48.0
|
|
7988
|
+
*/
|
|
7989
|
+
export type Work<M extends Machine.Any> =
|
|
7990
|
+
| Work.Effect<M>
|
|
7991
|
+
| Work.Timer<M>
|
|
7992
|
+
| Work.Stream<M>
|
|
7993
|
+
| Work.Logic<M>
|
|
7994
|
+
| Work.Child<M>
|
|
7995
|
+
|
|
7996
|
+
/**
|
|
7997
|
+
* The kinds of {@link Work}.
|
|
7998
|
+
*
|
|
7999
|
+
* @category models
|
|
8000
|
+
* @since 0.48.0
|
|
8001
|
+
*/
|
|
8002
|
+
export namespace Work {
|
|
8003
|
+
/**
|
|
8004
|
+
* What every kind of work names.
|
|
8005
|
+
*
|
|
8006
|
+
* @category models
|
|
8007
|
+
* @since 0.48.0
|
|
8008
|
+
*/
|
|
8009
|
+
export interface Proto<M extends Machine.Any> {
|
|
8010
|
+
/** Path of the state that invokes the work. */
|
|
8011
|
+
readonly path: Machine.StateIdentifier<Machine.States<M>>
|
|
8012
|
+
|
|
8013
|
+
/** Id of the invocation within its state. */
|
|
8014
|
+
readonly id: string
|
|
8015
|
+
|
|
8016
|
+
/** Name of the registered source, when the work has one. */
|
|
8017
|
+
readonly source: string | undefined
|
|
8018
|
+
|
|
8019
|
+
/** The entry of its state that started the work, counted from `0`. */
|
|
8020
|
+
readonly run: number
|
|
8021
|
+
}
|
|
8022
|
+
|
|
8023
|
+
/**
|
|
8024
|
+
* An Effect to run. It owns a `Scope`, closed with its `Exit`.
|
|
8025
|
+
*
|
|
8026
|
+
* @category models
|
|
8027
|
+
* @since 0.48.0
|
|
8028
|
+
*/
|
|
8029
|
+
export interface Effect<M extends Machine.Any> extends Proto<M> {
|
|
8030
|
+
readonly _tag: "Effect"
|
|
8031
|
+
|
|
8032
|
+
/** Evaluates the Effect to run, at most once. */
|
|
8033
|
+
readonly effect: () => Exit.Exit<StepEffect<unknown, Requirements<M>>>
|
|
8034
|
+
}
|
|
8035
|
+
|
|
8036
|
+
/**
|
|
8037
|
+
* A timer. It waits for its duration, and its host then settles it with a
|
|
8038
|
+
* successful `Exit`.
|
|
8039
|
+
*
|
|
8040
|
+
* **Details**
|
|
8041
|
+
*
|
|
8042
|
+
* `duration` evaluates how long the timer waits, at most once. It follows
|
|
8043
|
+
* the rule of every kind of work: a failure means that the timer could not
|
|
8044
|
+
* start, whether its input mapper or source threw, or its input names no
|
|
8045
|
+
* duration. A host that keeps timers of its own, or stores a due time
|
|
8046
|
+
* before it commits a step, reads `duration` in the step that enters the
|
|
8047
|
+
* state, and settles the timer with that failure where it would have
|
|
8048
|
+
* started.
|
|
8049
|
+
*
|
|
8050
|
+
* `effect` is the timer as an Effect that sleeps for the duration, for a
|
|
8051
|
+
* host whose timers wait on fibers. It fails as `duration` fails.
|
|
8052
|
+
*
|
|
8053
|
+
* @category models
|
|
8054
|
+
* @since 0.48.0
|
|
8055
|
+
*/
|
|
8056
|
+
export interface Timer<M extends Machine.Any> extends Proto<M> {
|
|
8057
|
+
readonly _tag: "Timer"
|
|
8058
|
+
|
|
8059
|
+
/** Evaluates how long the timer waits, at most once. */
|
|
8060
|
+
readonly duration: () => Exit.Exit<Duration.Duration>
|
|
8061
|
+
|
|
8062
|
+
/** Evaluates the timer as an Effect that waits for its duration. */
|
|
8063
|
+
readonly effect: () => Exit.Exit<StepEffect<void, never>>
|
|
8064
|
+
}
|
|
8065
|
+
|
|
8066
|
+
/**
|
|
8067
|
+
* A Stream to run. It owns a `Scope`, closed with its end. The host reports
|
|
8068
|
+
* each element with `element`, pulls the next element once that step is
|
|
8069
|
+
* carried out, and settles the Stream with the `Exit` of its run.
|
|
8070
|
+
*
|
|
8071
|
+
* @category models
|
|
8072
|
+
* @since 0.48.0
|
|
8073
|
+
*/
|
|
8074
|
+
export interface Stream<M extends Machine.Any> extends Proto<M> {
|
|
8075
|
+
readonly _tag: "Stream"
|
|
8076
|
+
|
|
8077
|
+
/** Evaluates the Stream to run, at most once. */
|
|
8078
|
+
readonly stream: () => Exit.Exit<StepStream<Requirements<M>>>
|
|
8079
|
+
}
|
|
8080
|
+
|
|
8081
|
+
/**
|
|
8082
|
+
* Process logic to run as a child of the machine, at its `address`.
|
|
8083
|
+
*
|
|
8084
|
+
* **Details**
|
|
8085
|
+
*
|
|
8086
|
+
* The host runs `initial` and then `run`, with contexts of its own: the
|
|
8087
|
+
* `parent` endpoint is the machine. It reports each state that the logic
|
|
8088
|
+
* sets with `report`, and settles the logic with the `Exit` of `run`, or
|
|
8089
|
+
* with the failure of `initial`. Both run in one `Scope`, forked from the
|
|
8090
|
+
* `Scope` that `initial` runs in and closed when `run` ends.
|
|
8091
|
+
*
|
|
8092
|
+
* @category models
|
|
8093
|
+
* @since 0.48.0
|
|
8094
|
+
*/
|
|
8095
|
+
export interface Logic<M extends Machine.Any> extends Proto<M> {
|
|
8096
|
+
readonly _tag: "Logic"
|
|
8097
|
+
|
|
8098
|
+
/** Address of the logic among the children of the machine. */
|
|
8099
|
+
readonly address: ChildAddress<never>
|
|
8100
|
+
|
|
8101
|
+
/** Evaluates the logic to run, at most once. */
|
|
8102
|
+
readonly logic: () => Exit.Exit<
|
|
8103
|
+
StepLogic<Requirements<M> | Scope.Scope>
|
|
8104
|
+
>
|
|
8105
|
+
}
|
|
8106
|
+
|
|
8107
|
+
/**
|
|
8108
|
+
* A child machine to run, with the machine as its parent.
|
|
8109
|
+
*
|
|
8110
|
+
* **Details**
|
|
8111
|
+
*
|
|
8112
|
+
* A host runs it as a machine of its own, such as one more `Machine.toStep`
|
|
8113
|
+
* of `child.machine` with `parent` set to a target of this machine. It
|
|
8114
|
+
* reports each snapshot of the child with `report`, and settles it with the
|
|
8115
|
+
* output of the child or with why it failed.
|
|
8116
|
+
*
|
|
8117
|
+
* @category models
|
|
8118
|
+
* @since 0.48.0
|
|
8119
|
+
*/
|
|
8120
|
+
export interface Child<M extends Machine.Any> extends Proto<M> {
|
|
8121
|
+
readonly _tag: "Child"
|
|
8122
|
+
|
|
8123
|
+
/** The descriptor of the child, which commands select it by. */
|
|
8124
|
+
readonly child: ChildMachine.Any
|
|
8125
|
+
|
|
8126
|
+
/**
|
|
8127
|
+
* Evaluates the arguments of the child's `start`, at most once: empty when
|
|
8128
|
+
* the invocation declares no input, and the input it maps otherwise.
|
|
8129
|
+
*/
|
|
8130
|
+
readonly input: () => Exit.Exit<ReadonlyArray<unknown>>
|
|
8131
|
+
}
|
|
8132
|
+
}
|
|
8133
|
+
|
|
8134
|
+
/**
|
|
8135
|
+
* How far a piece of work of an active state got, as a durable host stored
|
|
8136
|
+
* it, for `resume`.
|
|
8137
|
+
*
|
|
8138
|
+
* **Details**
|
|
8139
|
+
*
|
|
8140
|
+
* `Ended` work is not listed again: its end was applied, and running it again
|
|
8141
|
+
* would apply it twice. `Running` work is not listed in {@link Step} `start`,
|
|
8142
|
+
* because the host still runs it. It is in {@link Step} `running`, as the work
|
|
8143
|
+
* object that the host settles once it ends. Any work of an active state that
|
|
8144
|
+
* no progress names starts.
|
|
8145
|
+
*
|
|
8146
|
+
* @category models
|
|
8147
|
+
* @since 0.48.0
|
|
8148
|
+
*/
|
|
8149
|
+
export interface Progress<M extends Machine.Any> {
|
|
8150
|
+
/** Path of the state that invokes the work. */
|
|
8151
|
+
readonly path: Machine.StateIdentifier<Machine.States<M>>
|
|
8152
|
+
|
|
8153
|
+
/** Id of the invocation within its state. */
|
|
8154
|
+
readonly id: string
|
|
8155
|
+
|
|
8156
|
+
readonly status: "Ended" | "Running"
|
|
8157
|
+
}
|
|
8158
|
+
|
|
8159
|
+
/**
|
|
8160
|
+
* The children of a running machine, which its host owns.
|
|
8161
|
+
*
|
|
8162
|
+
* **Details**
|
|
8163
|
+
*
|
|
8164
|
+
* Work acts on the children of its machine through these operations: the
|
|
8165
|
+
* `children` of an input mapper, and `Machine.spawn`, `Machine.sendTo`, and
|
|
8166
|
+
* `Machine.stopChild`. A child is selected by its descriptor, or by the
|
|
8167
|
+
* address it was spawned or invoked at.
|
|
8168
|
+
*
|
|
8169
|
+
* A host that runs the `Logic` and child machines of the states also routes
|
|
8170
|
+
* `sendTo` and `stop` to them, and refuses to `spawn` a child at an address
|
|
8171
|
+
* that one of them holds, with `ChildAlreadyExistsError`.
|
|
8172
|
+
*
|
|
8173
|
+
* @category models
|
|
8174
|
+
* @since 0.48.0
|
|
8175
|
+
*/
|
|
8176
|
+
export interface Children {
|
|
8177
|
+
/** Starts a child machine, as `ChildOwner.spawn` does. */
|
|
8178
|
+
readonly spawn: (
|
|
8179
|
+
child: ChildMachine.Any,
|
|
8180
|
+
options: { readonly input: unknown } | undefined
|
|
8181
|
+
) => StepEffect<MachineRef<unknown, never, unknown, unknown, unknown>, unknown>
|
|
8182
|
+
|
|
8183
|
+
/** Starts process logic, as `Machine.spawn` does. */
|
|
8184
|
+
readonly spawnLogic: (
|
|
8185
|
+
logic: StepLogic<unknown>,
|
|
8186
|
+
options: SpawnOptions | undefined
|
|
8187
|
+
) => StepEffect<MachineRef<unknown, never, unknown, unknown, unknown>, unknown>
|
|
8188
|
+
|
|
8189
|
+
/**
|
|
8190
|
+
* Sends an event to a child. A child that does not run is ignored. When the
|
|
8191
|
+
* child is a machine whose event schema refuses the event, fails with
|
|
8192
|
+
* {@link MachineSchemaDecodeError} and leaves the child running.
|
|
8193
|
+
*/
|
|
8194
|
+
readonly sendTo: (
|
|
8195
|
+
child: ChildMachine.Any | ChildAddress<never>,
|
|
8196
|
+
event: unknown
|
|
8197
|
+
) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>
|
|
8198
|
+
|
|
8199
|
+
/** Stops a child. A child that does not run is ignored. */
|
|
8200
|
+
readonly stop: (child: ChildMachine.Any | ChildAddress<never>) => Effect.Effect<void>
|
|
8201
|
+
}
|
|
8202
|
+
|
|
8203
|
+
/**
|
|
8204
|
+
* What {@link toStep} asks of a host for a machine.
|
|
8205
|
+
*
|
|
8206
|
+
* **Details**
|
|
8207
|
+
*
|
|
8208
|
+
* - `self` is the target of the running machine, through which the host takes
|
|
8209
|
+
* the events that the machine and its work send to it.
|
|
8210
|
+
* - `parent` is the target of the owner of a machine that declares a parent,
|
|
8211
|
+
* and is required when that parent is. Transitions and input mappers receive
|
|
8212
|
+
* it as `parent`.
|
|
8213
|
+
* - `children` are the children of the machine. They are required when work
|
|
8214
|
+
* of the machine requires `Machine.MachineRuntime` or
|
|
8215
|
+
* `Machine.ChildMachineRuntime`. Without them, every operation on children
|
|
8216
|
+
* fails the machine with `ProcessLocalError`.
|
|
8217
|
+
*
|
|
8218
|
+
* @category models
|
|
8219
|
+
* @since 0.48.0
|
|
8220
|
+
*/
|
|
8221
|
+
export type Options<M extends Machine.Any> =
|
|
8222
|
+
& { readonly self: MachineTarget<Machine.EventInputOf<Machine.InputEvents<M>>> }
|
|
8223
|
+
& ParentOption<Machine.ParentEvents<M>>
|
|
8224
|
+
& ChildrenOption<Machine.Services<M>>
|
|
8225
|
+
|
|
8226
|
+
/**
|
|
8227
|
+
* Refuses, at compile time, a machine that a host cannot run.
|
|
8228
|
+
*
|
|
8229
|
+
* **When to use**
|
|
8230
|
+
*
|
|
8231
|
+
* Intersect it with the machine parameter of a host that runs only some
|
|
8232
|
+
* kinds of work: `machine: M & MachineStep.Supported<M, "Stream", never>`.
|
|
8233
|
+
*
|
|
8234
|
+
* **Details**
|
|
8235
|
+
*
|
|
8236
|
+
* `Kinds` are the kinds of {@link InvocationSupport} that the host runs, and
|
|
8237
|
+
* `Capabilities` are the services of children that it supplies as
|
|
8238
|
+
* {@link Children}. Effects and timers need no kind. A machine that needs
|
|
8239
|
+
* more resolves to an object whose property
|
|
8240
|
+
* `~effect/Machine/MachineStep/Unsupported` names what is missing.
|
|
8241
|
+
*
|
|
8242
|
+
* @category utility types
|
|
8243
|
+
* @since 0.48.0
|
|
8244
|
+
*/
|
|
8245
|
+
export type Supported<
|
|
8246
|
+
M extends Machine.Any,
|
|
8247
|
+
Kinds extends InvocationSupport.Kind,
|
|
8248
|
+
Capabilities extends MachineRuntime | ChildMachineRuntime = never
|
|
8249
|
+
> = IsAny<Machine.Services<M>> extends true ? unknown
|
|
8250
|
+
: [
|
|
8251
|
+
| UnsupportedInvocation<Machine.Services<M>, Kinds>
|
|
8252
|
+
| UnsupportedCapability<Machine.Services<M>, Capabilities>
|
|
8253
|
+
] extends [never] ? unknown
|
|
8254
|
+
: {
|
|
8255
|
+
readonly "~effect/Machine/MachineStep/Unsupported": {
|
|
8256
|
+
readonly invocations: UnsupportedInvocation<Machine.Services<M>, Kinds>
|
|
8257
|
+
readonly capabilities: UnsupportedCapability<Machine.Services<M>, Capabilities>
|
|
8258
|
+
}
|
|
8259
|
+
}
|
|
8260
|
+
|
|
8261
|
+
/**
|
|
8262
|
+
* Services that the work of a machine requires of its host. The services of
|
|
8263
|
+
* children come from {@link Children}.
|
|
8264
|
+
*
|
|
8265
|
+
* @category utility types
|
|
8266
|
+
* @since 0.48.0
|
|
8267
|
+
*/
|
|
8268
|
+
export type Requirements<M extends Machine.Any> = Exclude<
|
|
8269
|
+
Machine.Services<M>,
|
|
8270
|
+
InvocationSupport<InvocationSupport.Kind> | MachineRuntime | ChildMachineRuntime | Scope.Scope
|
|
8271
|
+
>
|
|
8272
|
+
|
|
8273
|
+
/**
|
|
8274
|
+
* Why a machine failed, or that its owner stopped it, as `MachineRef.join`
|
|
8275
|
+
* of `LocalMachine` reports it.
|
|
8276
|
+
*
|
|
8277
|
+
* @category errors
|
|
8278
|
+
* @since 0.48.0
|
|
8279
|
+
*/
|
|
8280
|
+
export type Error<M extends Machine.Any> =
|
|
8281
|
+
| Machine.Error<M>
|
|
8282
|
+
| InfiniteTransitionError
|
|
8283
|
+
| MachineSchemaDecodeError
|
|
8284
|
+
| StoppedError
|
|
8285
|
+
|
|
8286
|
+
/**
|
|
8287
|
+
* Why a machine could not start, as `LocalMachine.start` reports it.
|
|
8288
|
+
*
|
|
8289
|
+
* @category errors
|
|
8290
|
+
* @since 0.48.0
|
|
8291
|
+
*/
|
|
8292
|
+
export type StartError = InfiniteTransitionError | MachineSchemaDecodeError | StartupError
|
|
8293
|
+
|
|
8294
|
+
/**
|
|
8295
|
+
* Why `send` did not take an event. The state passed to it still holds.
|
|
8296
|
+
*
|
|
8297
|
+
* @category errors
|
|
8298
|
+
* @since 0.48.0
|
|
8299
|
+
*/
|
|
8300
|
+
export type Rejection = MachineSchemaDecodeError | StoppedError
|
|
8301
|
+
}
|
|
8302
|
+
|
|
8303
|
+
// The kinds of work are named `Effect`, `Stream`, and `Logic` in their
|
|
8304
|
+
// namespace, so they refer to the modules through these aliases.
|
|
8305
|
+
type StepEffect<A, R> = Effect.Effect<A, unknown, R>
|
|
8306
|
+
|
|
8307
|
+
type StepStream<R> = Stream.Stream<unknown, unknown, R>
|
|
8308
|
+
|
|
8309
|
+
type StepLogic<R> = Logic<unknown, unknown, unknown, R, unknown, unknown>
|
|
8310
|
+
|
|
8311
|
+
type ParentOption<ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> = Machine.ParentModeOf<ParentEvents> extends
|
|
8312
|
+
"required" ? { readonly parent: MachineTarget<Machine.EventInputOf<ParentEvents>> }
|
|
8313
|
+
: Machine.ParentModeOf<ParentEvents> extends "optional"
|
|
8314
|
+
? { readonly parent?: MachineTarget<Machine.EventInputOf<ParentEvents>> | undefined }
|
|
8315
|
+
: { readonly parent?: undefined }
|
|
8316
|
+
|
|
8317
|
+
type ChildrenOption<R> = IsAny<R> extends true ? { readonly children?: MachineStep.Children | undefined }
|
|
8318
|
+
: [Extract<R, MachineRuntime | ChildMachineRuntime>] extends [never]
|
|
8319
|
+
? { readonly children?: MachineStep.Children | undefined }
|
|
8320
|
+
: { readonly children: MachineStep.Children }
|
|
8321
|
+
|
|
8322
|
+
type UnsupportedInvocation<R, Kinds> = R extends InvocationSupport<infer Kind> ? Exclude<Kind, Kinds> : never
|
|
8323
|
+
|
|
8324
|
+
type UnsupportedCapability<R, Capabilities> = R extends MachineRuntime
|
|
8325
|
+
? [MachineRuntime] extends [Capabilities] ? never : "MachineRuntime"
|
|
8326
|
+
: R extends ChildMachineRuntime ? [ChildMachineRuntime] extends [Capabilities] ? never : "ChildMachineRuntime"
|
|
8327
|
+
: never
|
|
8328
|
+
|
|
8329
|
+
/**
|
|
8330
|
+
* Extracts the step function of a machine: its pure form, for code that runs
|
|
8331
|
+
* a machine on a new host.
|
|
8332
|
+
*
|
|
8333
|
+
* **When to use**
|
|
8334
|
+
*
|
|
8335
|
+
* Applications run machines with `LocalMachine`, `AtomMachine`, or
|
|
8336
|
+
* `ClusterMachine`. Use `toStep` to write a host for a new runtime, such as a
|
|
8337
|
+
* UI framework or a store, that keeps the state itself, runs the work of the
|
|
8338
|
+
* machine, and reports back how it ended.
|
|
8339
|
+
*
|
|
8340
|
+
* **Details**
|
|
8341
|
+
*
|
|
8342
|
+
* The returned {@link MachineStep} runs nothing, and calls no user code for the
|
|
8343
|
+
* work it lists. Each of its functions returns the next state, as a value,
|
|
8344
|
+
* together with the commands to carry out, the work to stop and to start, in
|
|
8345
|
+
* the order the host carries them out. Work is an Effect, a timer, a Stream, a
|
|
8346
|
+
* `Logic`, or a child machine, described as data that the host evaluates when
|
|
8347
|
+
* it starts it. The current entry of a state is part of the state value, so a
|
|
8348
|
+
* result of work whose state was exited is ignored without the host comparing
|
|
8349
|
+
* anything.
|
|
8350
|
+
*
|
|
8351
|
+
* `toStep` accepts every machine that `LocalMachine.start` accepts, and also a
|
|
8352
|
+
* machine that declares a parent. A host states in its own types which kinds of
|
|
8353
|
+
* work it runs, with {@link MachineStep.Supported}. The options are the
|
|
8354
|
+
* {@link MachineStep.Options} of the machine: `self`, the `parent` of a machine
|
|
8355
|
+
* that has one, and the `children` that its work acts on.
|
|
8356
|
+
*
|
|
8357
|
+
* `send` rejects an event that does not match its schema, and keeps the
|
|
8358
|
+
* machine, as `send` of every host does.
|
|
8359
|
+
*
|
|
8360
|
+
* **Gotchas**
|
|
8361
|
+
*
|
|
8362
|
+
* The compiler reads only the requirements of a machine, and an input mapper
|
|
8363
|
+
* receives `children` whatever its machine requires. A host that passes no
|
|
8364
|
+
* `children` refuses every operation on them at run time with
|
|
8365
|
+
* `ProcessLocalError`, as a defect that fails the machine.
|
|
8366
|
+
*
|
|
8367
|
+
* **Example** (Stepping a machine that loads a document)
|
|
8368
|
+
*
|
|
8369
|
+
* ```ts import.meta.vitest
|
|
8370
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
8371
|
+
* import { Effect, Exit, Schema } from "effect"
|
|
8372
|
+
*
|
|
8373
|
+
* const Events = Machine.events({ Load: {} })
|
|
8374
|
+
* const machine = Machine.make({
|
|
8375
|
+
* root: Machine.state({
|
|
8376
|
+
* states: { Idle: {}, Loading: {}, Loaded: { fields: { text: Schema.String } } }
|
|
8377
|
+
* }),
|
|
8378
|
+
* events: Events,
|
|
8379
|
+
* effects: { load: Effect.succeed("hello") }
|
|
8380
|
+
* }).handle({
|
|
8381
|
+
* initial: { target: "Idle" },
|
|
8382
|
+
* states: {
|
|
8383
|
+
* Idle: { on: { Load: { target: "Loading" } } },
|
|
8384
|
+
* Loading: { invoke: { src: "load", onDone: { target: "Loaded", data: ({ output }) => ({ text: output }) } } }
|
|
8385
|
+
* }
|
|
8386
|
+
* })
|
|
8387
|
+
*
|
|
8388
|
+
* const self = { id: "loader", sessionId: "loader-1", send: () => Effect.void }
|
|
8389
|
+
* const step = Machine.toStep(machine, { self })
|
|
8390
|
+
*
|
|
8391
|
+
* const program = Effect.gen(function*() {
|
|
8392
|
+
* const started = yield* step.start()
|
|
8393
|
+
* const loading = yield* step.send(started.state, Events.Load())
|
|
8394
|
+
* const [work] = loading.start
|
|
8395
|
+
* if (work?._tag !== "Effect") return "no work"
|
|
8396
|
+
* const effect = work.effect()
|
|
8397
|
+
* if (Exit.isFailure(effect)) return "cannot start"
|
|
8398
|
+
* const loaded = step.settle(loading.state, work, yield* Effect.exit(effect.value))
|
|
8399
|
+
* return loaded.snapshot.state.path
|
|
8400
|
+
* })
|
|
8401
|
+
*
|
|
8402
|
+
* await Effect.runPromise(program) // => "Loaded"
|
|
8403
|
+
* ```
|
|
8404
|
+
*
|
|
8405
|
+
* **Example** (Starting work whose input mapper throws)
|
|
8406
|
+
*
|
|
8407
|
+
* ```ts import.meta.vitest
|
|
8408
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
8409
|
+
* import { Effect, Exit } from "effect"
|
|
8410
|
+
*
|
|
8411
|
+
* const machine = Machine.make({
|
|
8412
|
+
* root: Machine.state({ states: { Loading: {} } }),
|
|
8413
|
+
* events: Machine.events({}),
|
|
8414
|
+
* effects: { load: (_: string) => Effect.void }
|
|
8415
|
+
* }).handle({
|
|
8416
|
+
* initial: { target: "Loading" },
|
|
8417
|
+
* states: {
|
|
8418
|
+
* Loading: {
|
|
8419
|
+
* invoke: {
|
|
8420
|
+
* src: "load",
|
|
8421
|
+
* input: (): string => {
|
|
8422
|
+
* throw new Error("no input")
|
|
8423
|
+
* },
|
|
8424
|
+
* onDone: { stay: true }
|
|
8425
|
+
* }
|
|
8426
|
+
* }
|
|
8427
|
+
* }
|
|
8428
|
+
* })
|
|
8429
|
+
*
|
|
8430
|
+
* const self = { id: "loader", sessionId: "loader-1", send: () => Effect.void }
|
|
8431
|
+
* const step = Machine.toStep(machine, { self })
|
|
8432
|
+
*
|
|
8433
|
+
* // An `Exit` is an Effect, so the step that starts the machine runs as one.
|
|
8434
|
+
* const started = Effect.runSync(step.start())
|
|
8435
|
+
* const [work] = started.start
|
|
8436
|
+
* // The step called no user code: the host evaluates work as it starts it.
|
|
8437
|
+
* const effect = work?._tag === "Effect" ? work.effect() : undefined
|
|
8438
|
+
* const failed = effect !== undefined && Exit.isFailure(effect) ? step.settle(started.state, work!, effect) : started
|
|
8439
|
+
*
|
|
8440
|
+
* failed.exit !== undefined && Exit.isFailure(failed.exit) // => true
|
|
8441
|
+
* ```
|
|
8442
|
+
*
|
|
8443
|
+
* @see {@link plan} for planning one event without work.
|
|
8444
|
+
* @category destructors
|
|
8445
|
+
* @since 0.48.0
|
|
8446
|
+
*/
|
|
8447
|
+
export const toStep: <
|
|
8448
|
+
const States extends Machine.StateSchemas,
|
|
8449
|
+
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8450
|
+
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
8451
|
+
const Input extends Schema.Top = typeof Schema.Void,
|
|
8452
|
+
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
8453
|
+
E = never,
|
|
8454
|
+
R = never,
|
|
8455
|
+
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
8456
|
+
Output = never,
|
|
8457
|
+
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
8458
|
+
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
8459
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
8460
|
+
>(
|
|
8461
|
+
machine:
|
|
8462
|
+
& Machine<
|
|
8463
|
+
States,
|
|
8464
|
+
Events,
|
|
8465
|
+
Input,
|
|
8466
|
+
UnhandledStates,
|
|
8467
|
+
E,
|
|
8468
|
+
R,
|
|
8469
|
+
FinalStates,
|
|
8470
|
+
Output,
|
|
8471
|
+
Emits,
|
|
8472
|
+
OutputStates,
|
|
8473
|
+
InputEvents,
|
|
8474
|
+
ParentEvents
|
|
8475
|
+
>
|
|
8476
|
+
& EnsureExecutable<States, UnhandledStates, OutputStates>,
|
|
8477
|
+
options: MachineStep.Options<
|
|
8478
|
+
Machine<
|
|
8479
|
+
States,
|
|
8480
|
+
Events,
|
|
8481
|
+
Input,
|
|
8482
|
+
UnhandledStates,
|
|
8483
|
+
E,
|
|
8484
|
+
R,
|
|
8485
|
+
FinalStates,
|
|
8486
|
+
Output,
|
|
8487
|
+
Emits,
|
|
8488
|
+
OutputStates,
|
|
8489
|
+
InputEvents,
|
|
8490
|
+
ParentEvents
|
|
8491
|
+
>
|
|
8492
|
+
>
|
|
8493
|
+
) => MachineStep<
|
|
8494
|
+
Machine<
|
|
8495
|
+
States,
|
|
8496
|
+
Events,
|
|
8497
|
+
Input,
|
|
8498
|
+
UnhandledStates,
|
|
8499
|
+
E,
|
|
8500
|
+
R,
|
|
8501
|
+
FinalStates,
|
|
8502
|
+
Output,
|
|
8503
|
+
Emits,
|
|
8504
|
+
OutputStates,
|
|
8505
|
+
InputEvents,
|
|
8506
|
+
ParentEvents
|
|
8507
|
+
>
|
|
8508
|
+
> = internal.toStep as never
|
|
8509
|
+
|
|
8510
|
+
/**
|
|
8511
|
+
* Creates advanced stateful process logic from explicit initialization and
|
|
8512
|
+
* execution methods.
|
|
8513
|
+
*
|
|
8514
|
+
* **When to use**
|
|
8515
|
+
*
|
|
8516
|
+
* Use when you need a machine-scoped process to publish intermediate snapshots
|
|
8517
|
+
* directly.
|
|
8518
|
+
*
|
|
8519
|
+
* **Details**
|
|
8520
|
+
*
|
|
8521
|
+
* Initialization produces the first state before `run` starts. The running
|
|
8522
|
+
* context receives events, reads or updates state, manages child processes,
|
|
8523
|
+
* and can communicate with its owning machine. Errors and service requirements
|
|
8524
|
+
* from both phases remain in the returned `Logic` type.
|
|
8525
|
+
*
|
|
8526
|
+
* **Gotchas**
|
|
8527
|
+
*
|
|
8528
|
+
* This is the low-level process constructor. Parent messages sent directly
|
|
8529
|
+
* through its scope are intentionally `unknown` because the logic does not know
|
|
8530
|
+
* which machine will eventually own it. Prefer typed output, typed child
|
|
8531
|
+
* addresses, or invocation lifecycle transitions when possible.
|
|
8532
|
+
*
|
|
8533
|
+
* For one-shot work, register an Effect in `make({ effects })` and invoke it
|
|
8534
|
+
* with `invoke: { src }` instead. Register logic in `make({ logic })` to run it
|
|
8535
|
+
* for the lifetime of one state.
|
|
8536
|
+
*
|
|
8537
|
+
* @see {@link make} for registering sources that states invoke by name.
|
|
8538
|
+
* @category constructors
|
|
8539
|
+
* @since 0.4.0
|
|
8540
|
+
*/
|
|
8541
|
+
export const logic: <
|
|
8542
|
+
State,
|
|
8543
|
+
Event = never,
|
|
8544
|
+
Output = void,
|
|
8545
|
+
Error = never,
|
|
8546
|
+
Requirements = never,
|
|
8547
|
+
InitialError = never,
|
|
8548
|
+
InitialRequirements = never
|
|
8549
|
+
>(options: {
|
|
8550
|
+
/** The first state, or an Effect that produces it from the initial context before `run` starts. */
|
|
8551
|
+
readonly initial:
|
|
8552
|
+
| State
|
|
8553
|
+
| ((
|
|
8554
|
+
context: Logic.InitialContext<Event>
|
|
8555
|
+
) => Effect.Effect<State, InitialError, InitialRequirements>)
|
|
8556
|
+
readonly run: (
|
|
8557
|
+
context: Logic.RunContext<State, Event>
|
|
8558
|
+
) => Effect.Effect<Output, Error, Requirements>
|
|
8559
|
+
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError> = internal.logic
|
|
8560
|
+
|
|
8561
|
+
/**
|
|
8562
|
+
* Creates a typed descriptor for a complete child machine.
|
|
8563
|
+
*
|
|
8564
|
+
* Descriptors identify a child by id and machine identity, so independently
|
|
8565
|
+
* constructed descriptors for the same pair address the same invoked child.
|
|
8566
|
+
*
|
|
8567
|
+
* @category constructors
|
|
8568
|
+
* @since 0.4.0
|
|
8569
|
+
*/
|
|
8570
|
+
export const child: <const Id extends string, M extends Machine.Any>(id: Id, machine: M) => ChildMachine<Id, M> =
|
|
8571
|
+
internal.child
|
|
8572
|
+
|
|
8573
|
+
/**
|
|
8574
|
+
* Binds one machine definition to an open family of runtime child ids.
|
|
8575
|
+
*
|
|
8576
|
+
* Descriptors created by the returned function are interchangeable with
|
|
8577
|
+
* {@link child} descriptors for the same id and machine definition.
|
|
8209
8578
|
*
|
|
8210
8579
|
* @category constructors
|
|
8211
8580
|
* @since 0.20.0
|
|
@@ -8234,8 +8603,8 @@ export const childAddress: <Event = never>(id: string) => ChildAddress<Event> =
|
|
|
8234
8603
|
*
|
|
8235
8604
|
* **Gotchas**
|
|
8236
8605
|
*
|
|
8237
|
-
* This Effect requires
|
|
8238
|
-
* unique for the current parent until that child stops.
|
|
8606
|
+
* This Effect requires {@link MachineRuntime}, which only some hosts provide. A
|
|
8607
|
+
* named child id must be unique for the current parent until that child stops.
|
|
8239
8608
|
*
|
|
8240
8609
|
* Register logic in `make({ logic })` and use `invoke: { src, id, address, ...outcomes }` for children
|
|
8241
8610
|
* that start and stop with that state.
|
|
@@ -8286,6 +8655,14 @@ export const spawn: {
|
|
|
8286
8655
|
/**
|
|
8287
8656
|
* Sends an event to a named child process of the running machine.
|
|
8288
8657
|
*
|
|
8658
|
+
* **Details**
|
|
8659
|
+
*
|
|
8660
|
+
* With the descriptor of an invoked child machine, it requires only
|
|
8661
|
+
* {@link ChildMachineRuntime}, which `ClusterMachine` provides too. With a
|
|
8662
|
+
* child address, it requires {@link MachineRuntime}. When the addressed child
|
|
8663
|
+
* is a machine whose event schema refuses the event, fails with
|
|
8664
|
+
* {@link MachineSchemaDecodeError} and leaves the child running.
|
|
8665
|
+
*
|
|
8289
8666
|
* @category runtime
|
|
8290
8667
|
* @since 0.4.0
|
|
8291
8668
|
*/
|
|
@@ -8293,27 +8670,36 @@ export const sendTo: {
|
|
|
8293
8670
|
<Child extends ChildMachine.Any>(
|
|
8294
8671
|
child: Child,
|
|
8295
8672
|
event: ChildMachine.Event<Child>
|
|
8296
|
-
): Effect.Effect<void, StoppedError,
|
|
8673
|
+
): Effect.Effect<void, StoppedError | MachineSchemaDecodeError, ChildMachineRuntime>
|
|
8297
8674
|
<Address extends ChildAddress<never>>(
|
|
8298
8675
|
id: Address,
|
|
8299
8676
|
event: ChildAddress.Event<Address>
|
|
8300
|
-
): Effect.Effect<void, StoppedError, MachineRuntime>
|
|
8301
|
-
} = internal.sendTo
|
|
8677
|
+
): Effect.Effect<void, StoppedError | MachineSchemaDecodeError, MachineRuntime>
|
|
8678
|
+
} = internal.sendTo as never
|
|
8302
8679
|
|
|
8303
8680
|
/**
|
|
8304
8681
|
* Stops a named child process of the running machine.
|
|
8305
8682
|
*
|
|
8683
|
+
* **Details**
|
|
8684
|
+
*
|
|
8685
|
+
* With the descriptor of an invoked child machine, it requires only
|
|
8686
|
+
* {@link ChildMachineRuntime}, which `ClusterMachine` provides too. With a
|
|
8687
|
+
* child address, it requires {@link MachineRuntime}.
|
|
8688
|
+
*
|
|
8306
8689
|
* @category runtime
|
|
8307
8690
|
* @since 0.4.0
|
|
8308
8691
|
*/
|
|
8309
8692
|
export const stopChild: {
|
|
8310
8693
|
<Event>(child: ChildAddress<Event>): Effect.Effect<void, never, MachineRuntime>
|
|
8311
|
-
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never,
|
|
8312
|
-
} = internal.stopChild
|
|
8694
|
+
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never, ChildMachineRuntime>
|
|
8695
|
+
} = internal.stopChild as never
|
|
8313
8696
|
|
|
8314
8697
|
/**
|
|
8315
8698
|
* Returns a stream of terminal lifecycle outcomes for a running machine.
|
|
8316
8699
|
*
|
|
8700
|
+
* Reads only the `changes` of the reference, so it works with a reference from
|
|
8701
|
+
* any host.
|
|
8702
|
+
*
|
|
8317
8703
|
* @category combinators
|
|
8318
8704
|
* @since 0.4.0
|
|
8319
8705
|
*/
|
|
@@ -8324,6 +8710,9 @@ export const watch: <State, Event, Error = never, Output = never>(
|
|
|
8324
8710
|
/**
|
|
8325
8711
|
* Waits for the first current or subsequent published snapshot matching a predicate.
|
|
8326
8712
|
*
|
|
8713
|
+
* Reads only the `changes` of the reference, so it works with a reference from
|
|
8714
|
+
* any host.
|
|
8715
|
+
*
|
|
8327
8716
|
* Use for external Effect coordination and tests. Prefer atom selectors for UI
|
|
8328
8717
|
* reads, invocation outcomes for workflow behavior, and `ref.join` for output.
|
|
8329
8718
|
* This observes state; it does not acknowledge or correlate a sent event.
|
|
@@ -8341,7 +8730,7 @@ export const watch: <State, Event, Error = never, Output = never>(
|
|
|
8341
8730
|
* **Example** (Waiting for a state with a timeout)
|
|
8342
8731
|
*
|
|
8343
8732
|
* ```ts import.meta.vitest
|
|
8344
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
8733
|
+
* import { LocalMachine, Machine } from "@typeonce/effect-machine"
|
|
8345
8734
|
* import { Effect } from "effect"
|
|
8346
8735
|
*
|
|
8347
8736
|
* const Events = Machine.events({ Finish: {} })
|
|
@@ -8356,7 +8745,7 @@ export const watch: <State, Event, Error = never, Output = never>(
|
|
|
8356
8745
|
* })
|
|
8357
8746
|
*
|
|
8358
8747
|
* const path = Effect.scoped(Effect.gen(function*() {
|
|
8359
|
-
* const ref = yield*
|
|
8748
|
+
* const ref = yield* LocalMachine.start(machine)
|
|
8360
8749
|
* yield* ref.send(Events.Finish())
|
|
8361
8750
|
* const ready = yield* Machine.waitFor(ref, ({ state }) => state.state.path === "Ready").pipe(Effect.timeout("5 seconds"))
|
|
8362
8751
|
* return ready.state.state.path
|
|
@@ -8389,345 +8778,3 @@ export const waitFor: {
|
|
|
8389
8778
|
predicate: (snapshot: RuntimeSnapshot<State, Error, Output>) => boolean
|
|
8390
8779
|
): Effect.Effect<RuntimeSnapshot<State, Error, Output>, Error | StoppedError | Cause.NoSuchElementError>
|
|
8391
8780
|
} = internal.waitFor
|
|
8392
|
-
|
|
8393
|
-
/**
|
|
8394
|
-
* Prepares a fresh machine without initializing it.
|
|
8395
|
-
*
|
|
8396
|
-
* Use this constructor when observation must be composed before initial-entry
|
|
8397
|
-
* actions run. Subscribe to `prepared.emissions`, then evaluate
|
|
8398
|
-
* `prepared.start`. Ordinary callers can continue to use {@link start}, which
|
|
8399
|
-
* starts directly and does not allocate the prepared lifecycle boundary.
|
|
8400
|
-
*
|
|
8401
|
-
* `prepared.start` is one-shot and scoped: the `Scope` that first evaluates it
|
|
8402
|
-
* owns the machine, and closing that `Scope` is equivalent to `ref.stop`.
|
|
8403
|
-
*
|
|
8404
|
-
* **Example** (Observing emissions before startup)
|
|
8405
|
-
*
|
|
8406
|
-
* ```ts import.meta.vitest
|
|
8407
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
8408
|
-
* import { Effect, Stream } from "effect"
|
|
8409
|
-
*
|
|
8410
|
-
* const Emitted = Machine.emittedEvents({ Started: {} })
|
|
8411
|
-
* const machine = Machine.make({
|
|
8412
|
-
* root: Machine.state({ states: { Idle: {} } }),
|
|
8413
|
-
* events: Machine.events({}),
|
|
8414
|
-
* emittedEvents: Emitted
|
|
8415
|
-
* }).handle({
|
|
8416
|
-
* initial: { target: "Idle" },
|
|
8417
|
-
* states: {
|
|
8418
|
-
* Idle: {
|
|
8419
|
-
* entry: (_, enqueue) => {
|
|
8420
|
-
* enqueue.emit(Emitted.Started())
|
|
8421
|
-
* }
|
|
8422
|
-
* }
|
|
8423
|
-
* }
|
|
8424
|
-
* })
|
|
8425
|
-
*
|
|
8426
|
-
* const emitted = Effect.scoped(Effect.gen(function*() {
|
|
8427
|
-
* const prepared = yield* Machine.prepare(machine)
|
|
8428
|
-
* const seen: Array<string> = []
|
|
8429
|
-
* yield* prepared.emissions.pipe(
|
|
8430
|
-
* Stream.runForEach((event) => Effect.sync(() => seen.push(event._tag))),
|
|
8431
|
-
* Effect.forkScoped({ startImmediately: true })
|
|
8432
|
-
* )
|
|
8433
|
-
* yield* prepared.start
|
|
8434
|
-
* yield* Effect.yieldNow
|
|
8435
|
-
* return seen
|
|
8436
|
-
* }))
|
|
8437
|
-
*
|
|
8438
|
-
* await Effect.runPromise(emitted) // => ["Started"]
|
|
8439
|
-
* ```
|
|
8440
|
-
*
|
|
8441
|
-
* @category constructors
|
|
8442
|
-
* @since 0.11.0
|
|
8443
|
-
*/
|
|
8444
|
-
export const prepare: <
|
|
8445
|
-
const States extends Machine.StateSchemas,
|
|
8446
|
-
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8447
|
-
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
8448
|
-
const Input extends Schema.Top = typeof Schema.Void,
|
|
8449
|
-
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
8450
|
-
E = never,
|
|
8451
|
-
R = never,
|
|
8452
|
-
InitialE = never,
|
|
8453
|
-
InitialR = never,
|
|
8454
|
-
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
8455
|
-
Output = never,
|
|
8456
|
-
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
8457
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
8458
|
-
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
8459
|
-
>(
|
|
8460
|
-
machine:
|
|
8461
|
-
& Machine<
|
|
8462
|
-
States,
|
|
8463
|
-
Events,
|
|
8464
|
-
Input,
|
|
8465
|
-
UnhandledStates,
|
|
8466
|
-
E,
|
|
8467
|
-
R,
|
|
8468
|
-
InitialE,
|
|
8469
|
-
InitialR,
|
|
8470
|
-
FinalStates,
|
|
8471
|
-
Output,
|
|
8472
|
-
Emits,
|
|
8473
|
-
OutputStates,
|
|
8474
|
-
InputEvents,
|
|
8475
|
-
ParentEvents
|
|
8476
|
-
>
|
|
8477
|
-
& EnsureExecutable<States, UnhandledStates, OutputStates>
|
|
8478
|
-
& Machine.RootCompatible<ParentEvents>,
|
|
8479
|
-
...args: [...Machine.InputArgs<Input>]
|
|
8480
|
-
) => Effect.Effect<
|
|
8481
|
-
Prepared<
|
|
8482
|
-
Machine.Snapshot<States>,
|
|
8483
|
-
Machine.EventInputOf<InputEvents>,
|
|
8484
|
-
| E
|
|
8485
|
-
| ActionError<R>
|
|
8486
|
-
| InfiniteTransitionError
|
|
8487
|
-
| MachineSchemaDecodeError
|
|
8488
|
-
| StoppedError,
|
|
8489
|
-
Output,
|
|
8490
|
-
Machine.EmittedEventOf<Emits>,
|
|
8491
|
-
| InitialE
|
|
8492
|
-
| E
|
|
8493
|
-
| ActionError<InitialR | R>
|
|
8494
|
-
| InfiniteTransitionError
|
|
8495
|
-
| MachineSchemaDecodeError
|
|
8496
|
-
| StartupError
|
|
8497
|
-
| StoppedError,
|
|
8498
|
-
| Scope.Scope
|
|
8499
|
-
| ExcludeCompatibleRuntime<
|
|
8500
|
-
ExecutionServices<InitialR | R>,
|
|
8501
|
-
Machine.EventOf<Events>,
|
|
8502
|
-
Machine.EmittedEventOf<Emits>
|
|
8503
|
-
>
|
|
8504
|
-
>
|
|
8505
|
-
> = internal.prepare
|
|
8506
|
-
|
|
8507
|
-
/**
|
|
8508
|
-
* Starts a machine owned by the current `Scope`.
|
|
8509
|
-
*
|
|
8510
|
-
* **When to use**
|
|
8511
|
-
*
|
|
8512
|
-
* Use when you want asynchronous event delivery, lifecycle snapshots, `join`,
|
|
8513
|
-
* and machine-owned spawned or invoked children.
|
|
8514
|
-
*
|
|
8515
|
-
* **Details**
|
|
8516
|
-
*
|
|
8517
|
-
* For each accepted event the runtime plans the complete synchronous
|
|
8518
|
-
* macrostep, executes closed machine commands, stops invokes for exited states,
|
|
8519
|
-
* publishes the new state, delivers emitted events, and then starts invokes
|
|
8520
|
-
* for entered states.
|
|
8521
|
-
*
|
|
8522
|
-
* The machine is a scoped resource, like `Effect.forkScoped`. Closing the
|
|
8523
|
-
* `Scope` is equivalent to `ref.stop`: active invocations are interrupted,
|
|
8524
|
-
* owned children stop, the snapshot becomes `stopped`, and later sends fail
|
|
8525
|
-
* with `StoppedError`. An earlier `ref.stop` or terminal completion leaves the
|
|
8526
|
-
* finalizer with nothing to do. Own a `Scope` explicitly, for example with
|
|
8527
|
-
* `Scope.make` and `Scope.provide`, when the machine must outlive the caller.
|
|
8528
|
-
*
|
|
8529
|
-
* **Gotchas**
|
|
8530
|
-
*
|
|
8531
|
-
* The returned handle's `send` operation only enqueues events. Transition
|
|
8532
|
-
* failures are reported through the runtime snapshot, `changes`, and `join`
|
|
8533
|
-
* rather than being returned by `send`. Sending after the machine reaches any
|
|
8534
|
-
* terminal state fails immediately with `StoppedError`.
|
|
8535
|
-
*
|
|
8536
|
-
* **Example** (Starting a machine in a scope)
|
|
8537
|
-
*
|
|
8538
|
-
* ```ts import.meta.vitest
|
|
8539
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
8540
|
-
* import { Effect } from "effect"
|
|
8541
|
-
*
|
|
8542
|
-
* const States = Machine.state({ states: { Idle: {} } })
|
|
8543
|
-
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
8544
|
-
* initial: { target: "Idle" }
|
|
8545
|
-
* })
|
|
8546
|
-
*
|
|
8547
|
-
* const path = Effect.scoped(Effect.gen(function*() {
|
|
8548
|
-
* const ref = yield* Machine.start(machine)
|
|
8549
|
-
* return (yield* ref.state).state.path
|
|
8550
|
-
* }))
|
|
8551
|
-
*
|
|
8552
|
-
* await Effect.runPromise(path) // => "Idle"
|
|
8553
|
-
* ```
|
|
8554
|
-
*
|
|
8555
|
-
* @see {@link plan} for inspecting the same transition plan without executing it.
|
|
8556
|
-
* @see {@link watch} for classified terminal outcomes.
|
|
8557
|
-
* @category constructors
|
|
8558
|
-
* @since 0.4.0
|
|
8559
|
-
*/
|
|
8560
|
-
export const start: <
|
|
8561
|
-
const States extends Machine.StateSchemas,
|
|
8562
|
-
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8563
|
-
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
8564
|
-
const Input extends Schema.Top = typeof Schema.Void,
|
|
8565
|
-
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
8566
|
-
E = never,
|
|
8567
|
-
R = never,
|
|
8568
|
-
InitialE = never,
|
|
8569
|
-
InitialR = never,
|
|
8570
|
-
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
8571
|
-
Output = never,
|
|
8572
|
-
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
8573
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
8574
|
-
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
8575
|
-
>(
|
|
8576
|
-
machine:
|
|
8577
|
-
& Machine<
|
|
8578
|
-
States,
|
|
8579
|
-
Events,
|
|
8580
|
-
Input,
|
|
8581
|
-
UnhandledStates,
|
|
8582
|
-
E,
|
|
8583
|
-
R,
|
|
8584
|
-
InitialE,
|
|
8585
|
-
InitialR,
|
|
8586
|
-
FinalStates,
|
|
8587
|
-
Output,
|
|
8588
|
-
Emits,
|
|
8589
|
-
OutputStates,
|
|
8590
|
-
InputEvents,
|
|
8591
|
-
ParentEvents
|
|
8592
|
-
>
|
|
8593
|
-
& EnsureExecutable<States, UnhandledStates, OutputStates>
|
|
8594
|
-
& Machine.RootCompatible<ParentEvents>,
|
|
8595
|
-
...args: [...Machine.InputArgs<Input>]
|
|
8596
|
-
) => Effect.Effect<
|
|
8597
|
-
MachineRef<
|
|
8598
|
-
Machine.Snapshot<States>,
|
|
8599
|
-
Machine.EventInputOf<InputEvents>,
|
|
8600
|
-
| E
|
|
8601
|
-
| ActionError<R>
|
|
8602
|
-
| InfiniteTransitionError
|
|
8603
|
-
| MachineSchemaDecodeError
|
|
8604
|
-
| StoppedError,
|
|
8605
|
-
Output,
|
|
8606
|
-
Machine.EmittedEventOf<Emits>
|
|
8607
|
-
>,
|
|
8608
|
-
| InitialE
|
|
8609
|
-
| E
|
|
8610
|
-
| ActionError<InitialR | R>
|
|
8611
|
-
| InfiniteTransitionError
|
|
8612
|
-
| MachineSchemaDecodeError
|
|
8613
|
-
| StartupError
|
|
8614
|
-
| StoppedError,
|
|
8615
|
-
| Scope.Scope
|
|
8616
|
-
| ExcludeCompatibleRuntime<
|
|
8617
|
-
ExecutionServices<InitialR | R>,
|
|
8618
|
-
Machine.EventOf<Events>,
|
|
8619
|
-
Machine.EmittedEventOf<Emits>
|
|
8620
|
-
>
|
|
8621
|
-
> = internal.start
|
|
8622
|
-
|
|
8623
|
-
/**
|
|
8624
|
-
* Starts a fresh managed runtime from a decoded logical snapshot, owned by the
|
|
8625
|
-
* current `Scope`.
|
|
8626
|
-
*
|
|
8627
|
-
* **Details**
|
|
8628
|
-
*
|
|
8629
|
-
* The resumed machine has the same scoped lifetime as {@link start}: closing
|
|
8630
|
-
* the `Scope` is equivalent to `ref.stop`.
|
|
8631
|
-
*
|
|
8632
|
-
* `resume` validates and normalizes the supplied snapshot before publishing it
|
|
8633
|
-
* as the first state. It does not construct the declared initial state, replay
|
|
8634
|
-
* entry or transition actions, re-deliver raised or emitted events, or
|
|
8635
|
-
* re-evaluate historical completion and eventless transitions. Active-state
|
|
8636
|
-
* invokes start once in ancestor and document order with {@link InitialEvent};
|
|
8637
|
-
* timer invocations restart their complete duration and child-machine
|
|
8638
|
-
* invocations start from their own initial state.
|
|
8639
|
-
*
|
|
8640
|
-
* Only logical state, completion, and history metadata are resumed. Queues,
|
|
8641
|
-
* scopes, subscriptions, fibers, spawned children, invoke progress, and prior
|
|
8642
|
-
* runtime status are process-local and are not restored. A final snapshot
|
|
8643
|
-
* immediately produces a completed ref with its current-machine output.
|
|
8644
|
-
*
|
|
8645
|
-
* Decode encoded data explicitly with {@link decodeSnapshot} before calling
|
|
8646
|
-
* this function. Stable snapshots are hosted as supplied; newly enabled
|
|
8647
|
-
* eventless or completion transitions in a changed machine definition are not
|
|
8648
|
-
* evaluated merely because the runtime was resumed; only ordinary subsequent
|
|
8649
|
-
* transition planning can enter and stabilize states.
|
|
8650
|
-
*
|
|
8651
|
-
* **Example** (Resuming from a decoded snapshot)
|
|
8652
|
-
*
|
|
8653
|
-
* ```ts import.meta.vitest
|
|
8654
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
8655
|
-
* import { Effect } from "effect"
|
|
8656
|
-
*
|
|
8657
|
-
* const States = Machine.state({ states: { Idle: {} } })
|
|
8658
|
-
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
8659
|
-
* initial: { target: "Idle" }
|
|
8660
|
-
* })
|
|
8661
|
-
*
|
|
8662
|
-
* const path = Effect.scoped(Effect.gen(function*() {
|
|
8663
|
-
* const initial = yield* Machine.planInitial(machine)
|
|
8664
|
-
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
8665
|
-
* const snapshot = yield* Machine.decodeSnapshot(machine, encoded)
|
|
8666
|
-
* const ref = yield* Machine.resume(machine, snapshot)
|
|
8667
|
-
* return (yield* ref.state).state.path
|
|
8668
|
-
* }))
|
|
8669
|
-
*
|
|
8670
|
-
* await Effect.runPromise(path) // => "Idle"
|
|
8671
|
-
* ```
|
|
8672
|
-
*
|
|
8673
|
-
* @see {@link decodeSnapshot} for the schema and transport boundary.
|
|
8674
|
-
* @see {@link start} for ordinary initial startup.
|
|
8675
|
-
* @category constructors
|
|
8676
|
-
* @since 0.4.0
|
|
8677
|
-
*/
|
|
8678
|
-
export const resume: <
|
|
8679
|
-
const States extends Machine.StateSchemas,
|
|
8680
|
-
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
8681
|
-
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
8682
|
-
const Input extends Schema.Top = typeof Schema.Void,
|
|
8683
|
-
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
8684
|
-
E = never,
|
|
8685
|
-
R = never,
|
|
8686
|
-
InitialE = never,
|
|
8687
|
-
InitialR = never,
|
|
8688
|
-
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
8689
|
-
Output = never,
|
|
8690
|
-
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
8691
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events,
|
|
8692
|
-
ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
8693
|
-
>(
|
|
8694
|
-
machine:
|
|
8695
|
-
& Machine<
|
|
8696
|
-
States,
|
|
8697
|
-
Events,
|
|
8698
|
-
Input,
|
|
8699
|
-
UnhandledStates,
|
|
8700
|
-
E,
|
|
8701
|
-
R,
|
|
8702
|
-
InitialE,
|
|
8703
|
-
InitialR,
|
|
8704
|
-
FinalStates,
|
|
8705
|
-
Output,
|
|
8706
|
-
Emits,
|
|
8707
|
-
OutputStates,
|
|
8708
|
-
InputEvents,
|
|
8709
|
-
ParentEvents
|
|
8710
|
-
>
|
|
8711
|
-
& EnsureExecutable<States, UnhandledStates, OutputStates>
|
|
8712
|
-
& Machine.RootCompatible<ParentEvents>,
|
|
8713
|
-
snapshot: Machine.Snapshot<States>
|
|
8714
|
-
) => Effect.Effect<
|
|
8715
|
-
MachineRef<
|
|
8716
|
-
Machine.Snapshot<States>,
|
|
8717
|
-
Machine.EventInputOf<InputEvents>,
|
|
8718
|
-
| E
|
|
8719
|
-
| ActionError<R>
|
|
8720
|
-
| InfiniteTransitionError
|
|
8721
|
-
| MachineSchemaDecodeError
|
|
8722
|
-
| StoppedError,
|
|
8723
|
-
Output,
|
|
8724
|
-
Machine.EmittedEventOf<Emits>
|
|
8725
|
-
>,
|
|
8726
|
-
MachineSchemaDecodeError,
|
|
8727
|
-
| Scope.Scope
|
|
8728
|
-
| ExcludeCompatibleRuntime<
|
|
8729
|
-
ExecutionServices<R>,
|
|
8730
|
-
Machine.EventOf<Events>,
|
|
8731
|
-
Machine.EmittedEventOf<Emits>
|
|
8732
|
-
>
|
|
8733
|
-
> = internal.resume
|