@typeonce/effect-machine 0.47.1 → 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 +1120 -812
- 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 +1379 -1334
- 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/dist/Machine.d.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
|
*/
|
|
@@ -13,12 +18,11 @@ import type * as Schema from "effect/Schema";
|
|
|
13
18
|
import type * as Scope from "effect/Scope";
|
|
14
19
|
import type * as Stream from "effect/Stream";
|
|
15
20
|
import type * as Types from "effect/Types";
|
|
16
|
-
import type
|
|
21
|
+
import type { ChildMachineRuntime, MachineRuntime } from "./internal/machine/capability.js";
|
|
22
|
+
import type * as InvocationDefinitions from "./internal/machine/invocationDefinitions.js";
|
|
17
23
|
import type { ChildAlreadyExistsError, InfiniteTransitionError, MachineSchemaDecodeError, MachineSchemaEncodeError, StartupError, StoppedError } from "./internal/machine/machine.js";
|
|
18
|
-
import { InitialEventTypeId } from "./internal/machine/machine.js";
|
|
24
|
+
import { InitialEventTypeId, InvocationEventTypeId } from "./internal/machine/machine.js";
|
|
19
25
|
import type { EnsureExecutable } from "./internal/machine/readiness.js";
|
|
20
|
-
import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js";
|
|
21
|
-
import type { MachineRuntime } from "./internal/machine/runtimeProtocol.js";
|
|
22
26
|
import type * as StateDefinition from "./internal/machine/stateDefinition.js";
|
|
23
27
|
import type * as Topology from "./internal/machine/topology.js";
|
|
24
28
|
/**
|
|
@@ -38,12 +42,14 @@ export type TypeId = "~effect/Machine";
|
|
|
38
42
|
export declare const TypeId: TypeId;
|
|
39
43
|
declare const MachineOutputStatesTypeId: "~effect/Machine/OutputStates";
|
|
40
44
|
declare const MachineTypeId: "~effect/Machine/TypeCarrier";
|
|
45
|
+
declare const MachineEffectResultsTypeId: "~effect/Machine/EffectResults";
|
|
41
46
|
declare const EventConstructionTypeId: "~effect/Machine/EventConstruction";
|
|
42
47
|
declare const EmittedEventConstructionTypeId: "~effect/Machine/EmittedEventConstruction";
|
|
43
48
|
declare const EventProtocolTypeId: "~effect/Machine/EventProtocol";
|
|
44
49
|
declare const ParentModeTypeId: "~effect/Machine/ParentMode";
|
|
45
|
-
declare const ChildMachineLogicTypeId: "~effect/Machine/ChildMachineLogic";
|
|
46
50
|
declare const InvokeTypeId: "~effect/Machine/Invoke";
|
|
51
|
+
declare const InvocationSupportTypeId: "~effect/Machine/InvocationSupport";
|
|
52
|
+
declare const MachineStepStateTypeId: "~effect/Machine/MachineStep/State";
|
|
47
53
|
declare const StateConstructionTypeId: "~effect/Machine/StateConstruction";
|
|
48
54
|
declare const TargetSnapshotTypeId: "~effect/Machine/TargetSnapshot";
|
|
49
55
|
declare const HistoryTargetTypeId: "~effect/Machine/HistoryTarget";
|
|
@@ -87,6 +93,52 @@ export declare const InitialEvent: InitialEvent;
|
|
|
87
93
|
* @since 0.4.0
|
|
88
94
|
*/
|
|
89
95
|
export declare const isInitialEvent: (u: unknown) => u is InitialEvent;
|
|
96
|
+
/**
|
|
97
|
+
* Type identifier used for the synthetic event of a step caused by invoked work.
|
|
98
|
+
*
|
|
99
|
+
* @category type IDs
|
|
100
|
+
* @since 0.48.0
|
|
101
|
+
*/
|
|
102
|
+
export { InvocationEventTypeId };
|
|
103
|
+
/**
|
|
104
|
+
* Synthetic event passed to lifecycle callbacks of a step that invoked work
|
|
105
|
+
* caused: its output, typed failure, stream element, or child snapshot.
|
|
106
|
+
*
|
|
107
|
+
* **Details**
|
|
108
|
+
*
|
|
109
|
+
* An outcome is not an event of the machine's protocol, so the states that its
|
|
110
|
+
* transition enters and exits, and the work they start, receive this marker as
|
|
111
|
+
* their `event`, as they receive `InitialEvent` while the initial state
|
|
112
|
+
* settles. `path` and `id` name the state that invoked the work and the
|
|
113
|
+
* invocation, and `kind` names what the work reported. The reported value
|
|
114
|
+
* itself is available to the transition that handles it, as `output`,
|
|
115
|
+
* `error`, `element`, or `snapshot`.
|
|
116
|
+
*
|
|
117
|
+
* **Gotchas**
|
|
118
|
+
*
|
|
119
|
+
* A host that restarts work after a recovery, such as `ClusterMachine`, passes
|
|
120
|
+
* `InitialEvent` to the input mapper of the restarted work, not this event.
|
|
121
|
+
*
|
|
122
|
+
* @category models
|
|
123
|
+
* @since 0.48.0
|
|
124
|
+
*/
|
|
125
|
+
export interface InvocationEvent {
|
|
126
|
+
readonly _tag: typeof InvocationEventTypeId;
|
|
127
|
+
/** Path of the state that invoked the work. */
|
|
128
|
+
readonly path: string;
|
|
129
|
+
/** Id of the invocation within that state. */
|
|
130
|
+
readonly id: string;
|
|
131
|
+
/** What the work reported. */
|
|
132
|
+
readonly kind: "Done" | "Failure" | "Element" | "Snapshot";
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Returns `true` if a value is the synthetic event of a step caused by invoked
|
|
136
|
+
* work.
|
|
137
|
+
*
|
|
138
|
+
* @category guards
|
|
139
|
+
* @since 0.48.0
|
|
140
|
+
*/
|
|
141
|
+
export declare const isInvocationEvent: (u: unknown) => u is InvocationEvent;
|
|
90
142
|
type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
91
143
|
/**
|
|
92
144
|
* A schema-first machine implementation.
|
|
@@ -139,10 +191,10 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
139
191
|
* @category models
|
|
140
192
|
* @since 0.4.0
|
|
141
193
|
*/
|
|
142
|
-
export interface Machine<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
194
|
+
export interface Machine<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []> extends Pipeable {
|
|
143
195
|
readonly [TypeId]: TypeId;
|
|
144
196
|
/** @internal Stable type-level carrier for machine protocol extraction. */
|
|
145
|
-
readonly [MachineTypeId]: Machine.TypeCarrier<States, Events, Input, UnhandledStates, E, R,
|
|
197
|
+
readonly [MachineTypeId]: Machine.TypeCarrier<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>;
|
|
146
198
|
/** @internal Prevents output implementation evidence from being widened. */
|
|
147
199
|
readonly [MachineOutputStatesTypeId]: Readonly<Record<OutputStates, true>>;
|
|
148
200
|
/**
|
|
@@ -200,7 +252,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
200
252
|
/** @internal */
|
|
201
253
|
readonly handlers: Readonly<Record<string, unknown>>;
|
|
202
254
|
/** @internal */
|
|
203
|
-
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States
|
|
255
|
+
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States>;
|
|
204
256
|
/** @internal */
|
|
205
257
|
readonly initialDefinition: Machine.InitialDefinition;
|
|
206
258
|
}
|
|
@@ -218,7 +270,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
218
270
|
* @category models
|
|
219
271
|
* @since 0.15.0
|
|
220
272
|
*/
|
|
221
|
-
export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void,
|
|
273
|
+
export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], Registrations extends Machine.Registrations = {}> extends Omit<Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, FinalStates, Output, Emits, never, InputEvents, ParentEvents>, TypeId | "stateNodes" | "handlers" | "initial" | "initialDefinition"> {
|
|
222
274
|
/**
|
|
223
275
|
* Adds typed state handlers and returns an independent machine
|
|
224
276
|
* implementation. Event dispatch maps and transition descriptors are
|
|
@@ -250,7 +302,7 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
|
|
|
250
302
|
*
|
|
251
303
|
* @since 0.4.0
|
|
252
304
|
*/
|
|
253
|
-
readonly handle: Machine.Handler<States, Events, Emits, Input,
|
|
305
|
+
readonly handle: Machine.Handler<States, Events, Emits, Input, FinalStates, Output, InputEvents, ParentEvents, Registrations>;
|
|
254
306
|
}
|
|
255
307
|
/**
|
|
256
308
|
* Namespace containing type-level members associated with {@link Definition}.
|
|
@@ -303,8 +355,17 @@ MachineSchemaDecodeError,
|
|
|
303
355
|
*/
|
|
304
356
|
MachineSchemaEncodeError,
|
|
305
357
|
/**
|
|
306
|
-
* Error
|
|
307
|
-
*
|
|
358
|
+
* Error raised when invoked work uses an operation that requires a local
|
|
359
|
+
* machine process, on a host that does not provide one.
|
|
360
|
+
*
|
|
361
|
+
* **Details**
|
|
362
|
+
*
|
|
363
|
+
* `ClusterMachine` raises it when work reads `self.sessionId`, calls
|
|
364
|
+
* `self.send`, or calls an operation of `children`. The step functions of
|
|
365
|
+
* {@link toStep} raise it when work calls an operation on children and the
|
|
366
|
+
* host passed no `children`. It is a defect rather than a typed failure,
|
|
367
|
+
* because the same work runs correctly on a local machine.
|
|
368
|
+
* `operation` names the refused operation.
|
|
308
369
|
*
|
|
309
370
|
* @category errors
|
|
310
371
|
* @since 0.4.0
|
|
@@ -328,8 +389,9 @@ StartupError,
|
|
|
328
389
|
StoppedError } from "./internal/machine/machine.js";
|
|
329
390
|
export type {
|
|
330
391
|
/**
|
|
331
|
-
*
|
|
332
|
-
*
|
|
392
|
+
* Capability to act on the child machines that the states of the running
|
|
393
|
+
* machine invoke, required by `sendTo` and `stopChild` with the descriptor of
|
|
394
|
+
* a child machine.
|
|
333
395
|
*
|
|
334
396
|
* **When to use**
|
|
335
397
|
*
|
|
@@ -338,93 +400,126 @@ export type {
|
|
|
338
400
|
*
|
|
339
401
|
* **Details**
|
|
340
402
|
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
403
|
+
* The model declares this capability, and a host provides it to the work it
|
|
404
|
+
* runs. `LocalMachine` and `ClusterMachine` provide it, also when `AtomMachine`
|
|
405
|
+
* hosts the machine. Unlike {@link MachineRuntime}, it starts no process, so a
|
|
406
|
+
* host that runs child machines provides it.
|
|
407
|
+
*
|
|
408
|
+
* `Machine.Machine.Services` contains it when the work that a state invokes
|
|
409
|
+
* requires it, or when the machine of an invoked child does.
|
|
410
|
+
* `LocalMachine.RequiredServices` removes it.
|
|
411
|
+
*
|
|
412
|
+
* **Gotchas**
|
|
413
|
+
*
|
|
414
|
+
* Only the type is public: hosts of this library provide the service, and it
|
|
415
|
+
* cannot be constructed elsewhere.
|
|
345
416
|
*
|
|
346
417
|
* @category services
|
|
347
|
-
* @since 0.
|
|
418
|
+
* @since 0.48.0
|
|
348
419
|
*/
|
|
349
|
-
|
|
350
|
-
declare const RuntimeRequirementTypeId = "~effect/Machine/RuntimeRequirement";
|
|
351
|
-
declare const ActionRequirementTypeId = "~effect/Machine/ActionRequirement";
|
|
420
|
+
ChildMachineRuntime,
|
|
352
421
|
/**
|
|
353
|
-
*
|
|
354
|
-
*
|
|
422
|
+
* Capability to act on the processes of the running machine, required by
|
|
423
|
+
* `spawn`, and by `sendTo` and `stopChild` with a child address.
|
|
424
|
+
*
|
|
425
|
+
* **When to use**
|
|
426
|
+
*
|
|
427
|
+
* Name this requirement when annotating a reusable helper built from those
|
|
428
|
+
* operations, or when exporting a value whose inferred type includes it.
|
|
429
|
+
*
|
|
430
|
+
* **Details**
|
|
431
|
+
*
|
|
432
|
+
* The model declares this capability, and a host provides it to the work it
|
|
433
|
+
* runs. `LocalMachine` provides it, also when `AtomMachine` hosts the machine.
|
|
434
|
+
*
|
|
435
|
+
* `Machine.Machine.Services` contains it when the Effect, Stream, or `Logic` that
|
|
436
|
+
* a state invokes requires it, or when the machine of an invoked child does. A
|
|
437
|
+
* host that provides it runs every process that the work spawns, whatever that
|
|
438
|
+
* process invokes. `LocalMachine.RequiredServices` removes it.
|
|
439
|
+
*
|
|
440
|
+
* **Gotchas**
|
|
441
|
+
*
|
|
442
|
+
* `ClusterMachine` does not provide it, so `ClusterMachine.make` does not compile
|
|
443
|
+
* for a machine whose services contain it.
|
|
444
|
+
*
|
|
445
|
+
* Only the type is public: hosts of this library provide the service, and it
|
|
446
|
+
* cannot be constructed elsewhere.
|
|
355
447
|
*
|
|
356
448
|
* @category services
|
|
357
|
-
* @since 0.
|
|
449
|
+
* @since 0.47.0
|
|
358
450
|
*/
|
|
359
|
-
|
|
360
|
-
readonly [ActionRequirementTypeId]: {
|
|
361
|
-
readonly error: Types.Covariant<Error>;
|
|
362
|
-
readonly requirements: Types.Covariant<Requirements>;
|
|
363
|
-
};
|
|
364
|
-
}
|
|
451
|
+
MachineRuntime } from "./internal/machine/capability.js";
|
|
365
452
|
/**
|
|
366
|
-
*
|
|
453
|
+
* Requirement that a machine runs on a host which supports one kind of
|
|
454
|
+
* invocation.
|
|
367
455
|
*
|
|
368
|
-
*
|
|
369
|
-
* @since 0.4.0
|
|
370
|
-
*/
|
|
371
|
-
export type ActionError<Requirements> = Requirements extends ActionRequirement<infer Error, any> ? Error : never;
|
|
372
|
-
/**
|
|
373
|
-
* Extracts the service requirements of staged machine actions.
|
|
456
|
+
* **When to use**
|
|
374
457
|
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
|
|
378
|
-
export type ActionServices<Requirements> = Requirements extends ActionRequirement<any, infer Services> ? Services : never;
|
|
379
|
-
/**
|
|
380
|
-
* Removes staged action requirements from machine planning services.
|
|
458
|
+
* Name this requirement when annotating a machine that invokes a Stream, a
|
|
459
|
+
* `Logic`, or a child machine, or when a host states in its types which
|
|
460
|
+
* invocations it runs.
|
|
381
461
|
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
*
|
|
462
|
+
* **Details**
|
|
463
|
+
*
|
|
464
|
+
* `Machine.Machine.Services` contains one for each kind that the states of a
|
|
465
|
+
* machine invoke. Registering a source without invoking it adds nothing. A
|
|
466
|
+
* machine that invokes a child machine also carries the requirements of that
|
|
467
|
+
* child.
|
|
468
|
+
*
|
|
469
|
+
* Every host runs Effects and timers, so no requirement stands for them.
|
|
470
|
+
* `LocalMachine` supports every kind, also when `AtomMachine` hosts the machine,
|
|
471
|
+
* and `LocalMachine.RequiredServices` removes them all. `ClusterMachine` supports
|
|
472
|
+
* child machines, which it runs as entities of their own, and
|
|
473
|
+
* `ClusterMachine.make` does not compile for a machine that invokes a Stream or
|
|
474
|
+
* a `Logic`, whose progress it cannot store.
|
|
475
|
+
*
|
|
476
|
+
* **Gotchas**
|
|
477
|
+
*
|
|
478
|
+
* This exists in types only. Nothing constructs it, and it is not provided as a
|
|
479
|
+
* service.
|
|
388
480
|
*
|
|
389
481
|
* @category utility types
|
|
390
|
-
* @since 0.
|
|
482
|
+
* @since 0.48.0
|
|
391
483
|
*/
|
|
392
|
-
export
|
|
484
|
+
export interface InvocationSupport<out Kind extends InvocationSupport.Kind> {
|
|
485
|
+
readonly [InvocationSupportTypeId]: Kind;
|
|
486
|
+
}
|
|
393
487
|
/**
|
|
394
|
-
*
|
|
395
|
-
*
|
|
488
|
+
* Namespace containing type-level members associated with
|
|
489
|
+
* {@link InvocationSupport}.
|
|
396
490
|
*
|
|
397
|
-
* @category
|
|
398
|
-
* @since 0.
|
|
491
|
+
* @category utility types
|
|
492
|
+
* @since 0.48.0
|
|
399
493
|
*/
|
|
400
|
-
export
|
|
401
|
-
/**
|
|
402
|
-
* Queues an event for the current machine macrostep.
|
|
403
|
-
*
|
|
404
|
-
* @since 0.4.0
|
|
405
|
-
*/
|
|
406
|
-
readonly raise: (event: Machine.EventInput<Events>) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
494
|
+
export declare namespace InvocationSupport {
|
|
407
495
|
/**
|
|
408
|
-
*
|
|
496
|
+
* Kinds of invocation that a host may not support.
|
|
409
497
|
*
|
|
410
|
-
* @
|
|
498
|
+
* @category models
|
|
499
|
+
* @since 0.48.0
|
|
411
500
|
*/
|
|
412
|
-
|
|
501
|
+
type Kind = "Stream" | "Logic" | "Child";
|
|
413
502
|
}
|
|
414
503
|
/**
|
|
415
504
|
* Minimal typed target accepted by inter-machine send commands.
|
|
416
505
|
*
|
|
417
|
-
* `send` reports whether the event was accepted for delivery.
|
|
418
|
-
*
|
|
419
|
-
* strengthens that guarantee.
|
|
506
|
+
* `send` reports whether the event was accepted for delivery. When the target
|
|
507
|
+
* processes it is up to the host that runs the target.
|
|
420
508
|
*
|
|
421
509
|
* @category models
|
|
422
510
|
* @since 0.12.0
|
|
423
511
|
*/
|
|
424
512
|
export interface MachineTarget<in Event> {
|
|
513
|
+
/** Id of the target, such as its machine definition id or child address. */
|
|
425
514
|
readonly id: string;
|
|
515
|
+
/** Unique identity of the running target. */
|
|
426
516
|
readonly sessionId: string;
|
|
427
|
-
|
|
517
|
+
/**
|
|
518
|
+
* Accepts an event for delivery. Fails with `StoppedError` once the target has
|
|
519
|
+
* terminated, and with `MachineSchemaDecodeError` when the target rejects an
|
|
520
|
+
* event that its schema refuses.
|
|
521
|
+
*/
|
|
522
|
+
readonly send: (event: Event) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>;
|
|
428
523
|
}
|
|
429
524
|
/**
|
|
430
525
|
* Availability declared for an owning-machine target.
|
|
@@ -481,7 +576,7 @@ export type MachineReferences<InputEvents extends ReadonlyArray<Machine.TaggedSc
|
|
|
481
576
|
* @category models
|
|
482
577
|
* @since 0.4.0
|
|
483
578
|
*/
|
|
484
|
-
export interface
|
|
579
|
+
export interface Commands<in Events, in Emits> {
|
|
485
580
|
/** Raises an event inside the current macrostep. */
|
|
486
581
|
readonly raise: (event: Machine.EventInput<Events>) => void;
|
|
487
582
|
/** Publishes an ephemeral notification to this machine's observers. */
|
|
@@ -501,6 +596,8 @@ export interface Enqueue<in Events, in Emits> {
|
|
|
501
596
|
/**
|
|
502
597
|
* A closed machine command recorded by a synchronous transition.
|
|
503
598
|
*
|
|
599
|
+
* Planning only records commands. The host that runs the machine executes them.
|
|
600
|
+
*
|
|
504
601
|
* @category models
|
|
505
602
|
* @since 0.4.0
|
|
506
603
|
*/
|
|
@@ -512,27 +609,6 @@ export type Command = {
|
|
|
512
609
|
readonly _tag: "Stop";
|
|
513
610
|
readonly child: ChildMachine.Any | ChildAddress<never>;
|
|
514
611
|
};
|
|
515
|
-
/**
|
|
516
|
-
* Namespace containing type-level members associated with `Runtime`.
|
|
517
|
-
*
|
|
518
|
-
* @category models
|
|
519
|
-
* @since 0.4.0
|
|
520
|
-
*/
|
|
521
|
-
export declare namespace Runtime {
|
|
522
|
-
/**
|
|
523
|
-
* Opaque service requirement for a machine runtime capability.
|
|
524
|
-
*
|
|
525
|
-
* @category services
|
|
526
|
-
* @since 0.4.0
|
|
527
|
-
*/
|
|
528
|
-
interface Requirement<Events, Emits> {
|
|
529
|
-
readonly [RuntimeRequirementTypeId]: {
|
|
530
|
-
readonly events: Events;
|
|
531
|
-
readonly emits: Emits;
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? never : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : never;
|
|
536
612
|
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
537
613
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
538
614
|
readonly path: Path;
|
|
@@ -730,7 +806,8 @@ type SpawnIdError<Options extends SpawnOptions> = "id" extends keyof Options ? O
|
|
|
730
806
|
type SpawnError<Options extends SpawnOptions> = SpawnIdError<Options>;
|
|
731
807
|
type SpawnResult<State, Event, Error, Requirements, Output, SpawnError, InitialError = never> = Effect.Effect<MachineRef<State, Event, Error, Output>, SpawnError | InitialError, MachineRuntime | SpawnRequirements<Requirements>>;
|
|
732
808
|
/**
|
|
733
|
-
* Represents the active or terminal lifecycle state of a running machine
|
|
809
|
+
* Represents the active or terminal lifecycle state of a running machine, as its
|
|
810
|
+
* host publishes it.
|
|
734
811
|
*
|
|
735
812
|
* **Details**
|
|
736
813
|
*
|
|
@@ -749,174 +826,13 @@ export type RuntimeSnapshot<State, Error = never, Output = never> = {
|
|
|
749
826
|
readonly state: State;
|
|
750
827
|
readonly output: Output;
|
|
751
828
|
} | {
|
|
752
|
-
readonly status: "
|
|
829
|
+
readonly status: "failed";
|
|
753
830
|
readonly state: State;
|
|
754
831
|
readonly cause: Cause.Cause<Error>;
|
|
755
832
|
} | {
|
|
756
833
|
readonly status: "stopped";
|
|
757
834
|
readonly state: State;
|
|
758
835
|
};
|
|
759
|
-
/**
|
|
760
|
-
* Live, root-scoped records describing one prepared machine tree.
|
|
761
|
-
*
|
|
762
|
-
* Inspection records deliberately erase machine-specific values to `unknown`:
|
|
763
|
-
* one stream may contain unrelated root, child-machine, and `Logic` protocols.
|
|
764
|
-
* The record structure remains a closed discriminated union, while typed
|
|
765
|
-
* application observation continues through `changes` and `emissions`.
|
|
766
|
-
* Records retain decoded local events and snapshots and are not themselves a
|
|
767
|
-
* stable JSON export format. Telemetry exporters must project process-local
|
|
768
|
-
* values into an explicit portable representation.
|
|
769
|
-
*
|
|
770
|
-
* @category models
|
|
771
|
-
* @since 0.13.0
|
|
772
|
-
*/
|
|
773
|
-
export declare namespace Inspection {
|
|
774
|
-
/** Read-only identity of a local machine endpoint. */
|
|
775
|
-
interface Endpoint {
|
|
776
|
-
readonly id: string;
|
|
777
|
-
readonly sessionId: string;
|
|
778
|
-
}
|
|
779
|
-
/** Read-only identity of a runtime represented in the inspection tree. */
|
|
780
|
-
interface Subject extends Endpoint {
|
|
781
|
-
readonly kind: "Machine" | "Logic";
|
|
782
|
-
}
|
|
783
|
-
/** Causal origin of an inspected runtime. */
|
|
784
|
-
type Origin = {
|
|
785
|
-
readonly _tag: "Root";
|
|
786
|
-
} | {
|
|
787
|
-
readonly _tag: "Invoke";
|
|
788
|
-
readonly ownerPath: string;
|
|
789
|
-
readonly invokeId: string;
|
|
790
|
-
} | {
|
|
791
|
-
readonly _tag: "Spawn";
|
|
792
|
-
readonly address: string | undefined;
|
|
793
|
-
};
|
|
794
|
-
/** Causal owner of a send or emission. */
|
|
795
|
-
type Causation = {
|
|
796
|
-
readonly _tag: "Initialization";
|
|
797
|
-
} | {
|
|
798
|
-
readonly _tag: "Macrostep";
|
|
799
|
-
readonly macrostepId: number;
|
|
800
|
-
} | {
|
|
801
|
-
readonly _tag: "Activity";
|
|
802
|
-
readonly activitySessionId: string;
|
|
803
|
-
};
|
|
804
|
-
/** Closed command projection safe for observation. */
|
|
805
|
-
type Command = {
|
|
806
|
-
readonly _tag: "SendTo";
|
|
807
|
-
readonly target: Endpoint | {
|
|
808
|
-
readonly id: string;
|
|
809
|
-
};
|
|
810
|
-
readonly event: unknown;
|
|
811
|
-
} | {
|
|
812
|
-
readonly _tag: "Stop";
|
|
813
|
-
readonly target: Endpoint | {
|
|
814
|
-
readonly id: string;
|
|
815
|
-
};
|
|
816
|
-
};
|
|
817
|
-
/** One statechart microstep in a committed macrostep. */
|
|
818
|
-
interface Microstep {
|
|
819
|
-
readonly event: unknown;
|
|
820
|
-
readonly transitions: ReadonlyArray<Machine.RetainedTransition>;
|
|
821
|
-
readonly raisedEvents: ReadonlyArray<unknown>;
|
|
822
|
-
readonly emittedEvents: ReadonlyArray<unknown>;
|
|
823
|
-
readonly commands: ReadonlyArray<Command>;
|
|
824
|
-
readonly exitPaths: ReadonlyArray<string>;
|
|
825
|
-
readonly entryPaths: ReadonlyArray<string>;
|
|
826
|
-
readonly changed: boolean;
|
|
827
|
-
}
|
|
828
|
-
/** Common ordering and identity fields for every record. */
|
|
829
|
-
interface Base {
|
|
830
|
-
/** Total publication order within this prepared root. */
|
|
831
|
-
readonly sequence: number;
|
|
832
|
-
/** Session id of the prepared root that owns this inspection stream. */
|
|
833
|
-
readonly rootSessionId: string;
|
|
834
|
-
/** Runtime instance described by this record. */
|
|
835
|
-
readonly subject: Subject;
|
|
836
|
-
}
|
|
837
|
-
/** Announces allocation of a root or owned process identity. */
|
|
838
|
-
interface Created extends Base {
|
|
839
|
-
readonly _tag: "Created";
|
|
840
|
-
readonly parent: Subject | undefined;
|
|
841
|
-
readonly origin: Origin;
|
|
842
|
-
/** Compiled statechart definition; absent for generic `Logic`. */
|
|
843
|
-
readonly definition: Machine.Any | undefined;
|
|
844
|
-
}
|
|
845
|
-
/** Announces successful initialization. */
|
|
846
|
-
interface Initialized extends Base {
|
|
847
|
-
readonly _tag: "Initialized";
|
|
848
|
-
readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown>;
|
|
849
|
-
readonly initialEntryPaths: ReadonlyArray<string>;
|
|
850
|
-
readonly microsteps: ReadonlyArray<Microstep>;
|
|
851
|
-
}
|
|
852
|
-
/** Announces failure before an initial runtime snapshot exists. */
|
|
853
|
-
interface StartFailed extends Base {
|
|
854
|
-
readonly _tag: "StartFailed";
|
|
855
|
-
readonly cause: Cause.Cause<unknown>;
|
|
856
|
-
}
|
|
857
|
-
/** Announces acceptance of an event by a local mailbox. */
|
|
858
|
-
interface EventSent extends Base {
|
|
859
|
-
readonly _tag: "EventSent";
|
|
860
|
-
readonly deliveryId: number;
|
|
861
|
-
readonly source: Subject | undefined;
|
|
862
|
-
readonly target: Endpoint;
|
|
863
|
-
readonly event: unknown;
|
|
864
|
-
readonly causedBy: Causation | undefined;
|
|
865
|
-
}
|
|
866
|
-
/** Announces complete processing of one statechart mailbox event. */
|
|
867
|
-
interface EventProcessed extends Base {
|
|
868
|
-
readonly _tag: "EventProcessed";
|
|
869
|
-
readonly macrostepId: number;
|
|
870
|
-
readonly deliveryId: number;
|
|
871
|
-
readonly source: Subject | undefined;
|
|
872
|
-
readonly event: unknown;
|
|
873
|
-
readonly before: RuntimeSnapshot<unknown, unknown, unknown>;
|
|
874
|
-
readonly after: RuntimeSnapshot<unknown, unknown, unknown>;
|
|
875
|
-
readonly handled: boolean;
|
|
876
|
-
readonly configurationChanged: boolean;
|
|
877
|
-
readonly microsteps: ReadonlyArray<Microstep>;
|
|
878
|
-
}
|
|
879
|
-
/** Announces a direct state update made by generic `Logic`. */
|
|
880
|
-
interface StateChanged extends Base {
|
|
881
|
-
readonly _tag: "StateChanged";
|
|
882
|
-
readonly before: unknown;
|
|
883
|
-
readonly after: unknown;
|
|
884
|
-
readonly causedByDeliveryId: number | undefined;
|
|
885
|
-
}
|
|
886
|
-
/** Announces actual publication on a machine's domain emission stream. */
|
|
887
|
-
interface Emitted extends Base {
|
|
888
|
-
readonly _tag: "Emitted";
|
|
889
|
-
readonly emission: unknown;
|
|
890
|
-
readonly causedBy: Causation | undefined;
|
|
891
|
-
}
|
|
892
|
-
/** Identity of one Effect or timer invocation run. */
|
|
893
|
-
interface Activity {
|
|
894
|
-
readonly id: string;
|
|
895
|
-
readonly sessionId: string;
|
|
896
|
-
readonly owner: Subject;
|
|
897
|
-
readonly ownerPath: string;
|
|
898
|
-
readonly kind: "Effect" | "Stream" | "Timer";
|
|
899
|
-
}
|
|
900
|
-
/** Announces an Effect, Stream, or timer invocation starting. */
|
|
901
|
-
interface ActivityStarted extends Base {
|
|
902
|
-
readonly _tag: "ActivityStarted";
|
|
903
|
-
readonly activity: Activity;
|
|
904
|
-
}
|
|
905
|
-
/** Announces an Effect or timer invocation outcome. */
|
|
906
|
-
interface ActivityStopped extends Base {
|
|
907
|
-
readonly _tag: "ActivityStopped";
|
|
908
|
-
readonly activity: Activity;
|
|
909
|
-
/** Success or failure from the invoke; interruption means its owner stopped it. */
|
|
910
|
-
readonly exit: Exit.Exit<unknown, unknown>;
|
|
911
|
-
}
|
|
912
|
-
/** Announces a terminal local runtime snapshot. */
|
|
913
|
-
interface Terminated extends Base {
|
|
914
|
-
readonly _tag: "Terminated";
|
|
915
|
-
readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown>;
|
|
916
|
-
}
|
|
917
|
-
/** Complete live inspection protocol. */
|
|
918
|
-
type Event = Created | Initialized | StartFailed | EventSent | EventProcessed | StateChanged | Emitted | ActivityStarted | ActivityStopped | Terminated;
|
|
919
|
-
}
|
|
920
836
|
/**
|
|
921
837
|
* Represents a classified terminal outcome derived from a runtime snapshot.
|
|
922
838
|
*
|
|
@@ -934,26 +850,26 @@ export type RuntimeOutcome<State, Error = never, Output = never> = {
|
|
|
934
850
|
readonly error: Error;
|
|
935
851
|
readonly cause: Cause.Cause<Error>;
|
|
936
852
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
937
|
-
readonly status: "
|
|
853
|
+
readonly status: "failed";
|
|
938
854
|
}>;
|
|
939
855
|
} | {
|
|
940
856
|
readonly _tag: "Defect";
|
|
941
857
|
readonly defect: unknown;
|
|
942
858
|
readonly cause: Cause.Cause<Error>;
|
|
943
859
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
944
|
-
readonly status: "
|
|
860
|
+
readonly status: "failed";
|
|
945
861
|
}>;
|
|
946
862
|
} | {
|
|
947
863
|
readonly _tag: "Interrupted";
|
|
948
864
|
readonly cause: Cause.Cause<Error>;
|
|
949
865
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
950
|
-
readonly status: "
|
|
866
|
+
readonly status: "failed";
|
|
951
867
|
}>;
|
|
952
868
|
} | {
|
|
953
869
|
readonly _tag: "Cause";
|
|
954
870
|
readonly cause: Cause.Cause<Error>;
|
|
955
871
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
956
|
-
readonly status: "
|
|
872
|
+
readonly status: "failed";
|
|
957
873
|
}>;
|
|
958
874
|
} | {
|
|
959
875
|
readonly _tag: "Stopped";
|
|
@@ -961,58 +877,23 @@ export type RuntimeOutcome<State, Error = never, Output = never> = {
|
|
|
961
877
|
readonly status: "stopped";
|
|
962
878
|
}>;
|
|
963
879
|
};
|
|
964
|
-
/**
|
|
965
|
-
* A fresh machine whose observable streams exist before initialization.
|
|
966
|
-
*
|
|
967
|
-
* Subscribe to `emissions` before evaluating `start` when initial-entry
|
|
968
|
-
* emissions must be observed. `start` is one-shot: concurrent and repeated
|
|
969
|
-
* evaluations share the same initialization and running reference, and the
|
|
970
|
-
* `Scope` of the first evaluation owns the machine.
|
|
971
|
-
*
|
|
972
|
-
* @category models
|
|
973
|
-
* @since 0.11.0
|
|
974
|
-
*/
|
|
975
|
-
export interface Prepared<out State, in Event, out Error, out Output, out Emitted, out StartError, StartRequirements> {
|
|
976
|
-
/** Stable machine definition id, or a generated fallback when none was declared. */
|
|
977
|
-
readonly id: string;
|
|
978
|
-
/** Unique identity reserved for this prepared machine instance. */
|
|
979
|
-
readonly sessionId: string;
|
|
980
|
-
/** Waits for startup, then streams the initial lifecycle snapshot and later changes. */
|
|
981
|
-
readonly changes: Stream.Stream<RuntimeSnapshot<State, Error, Output>, StartError>;
|
|
982
|
-
/** Streams ephemeral notifications published after subscription. */
|
|
983
|
-
readonly emissions: Stream.Stream<Emitted>;
|
|
984
|
-
/**
|
|
985
|
-
* Streams ordered operational records for this root and every locally owned
|
|
986
|
-
* descendant. The stream is hot, non-replayed, never fails, and completes
|
|
987
|
-
* after the prepared root terminates. Subscribe before evaluating `start` to
|
|
988
|
-
* observe initialization.
|
|
989
|
-
*/
|
|
990
|
-
readonly inspection: Stream.Stream<Inspection.Event>;
|
|
991
|
-
/** Initializes this machine once, owned by the first evaluating `Scope`, and returns its running reference. */
|
|
992
|
-
readonly start: Effect.Effect<MachineRef<State, Event, Error, Output, Emitted>, StartError, StartRequirements>;
|
|
993
|
-
}
|
|
994
880
|
/**
|
|
995
881
|
* Provides access to a running machine's state, lifecycle, event input, and
|
|
996
882
|
* termination operations.
|
|
997
883
|
*
|
|
884
|
+
* **Details**
|
|
885
|
+
*
|
|
886
|
+
* This is the contract every host's reference satisfies. `send` reports whether
|
|
887
|
+
* an event was accepted for delivery. Errors that occur while processing an
|
|
888
|
+
* accepted event are observed through `snapshot`, `changes`, or `join`. Sending
|
|
889
|
+
* after termination fails with `StoppedError`.
|
|
890
|
+
*
|
|
998
891
|
* **Gotchas**
|
|
999
892
|
*
|
|
1000
|
-
*
|
|
1001
|
-
*
|
|
1002
|
-
*
|
|
1003
|
-
*
|
|
1004
|
-
* starts in the sender's turn and runs until it first suspends, so browser
|
|
1005
|
-
* APIs that require user activation, such as `window.open`, can run in the
|
|
1006
|
-
* first step of an invoked Effect. Work that suspends continues in the
|
|
1007
|
-
* background, and its outcome is handled in a later turn, even when the work
|
|
1008
|
-
* completes without suspending, so the entered state is always observed
|
|
1009
|
-
* before the outcome leaves it. An event sent while the machine is processing
|
|
1010
|
-
* is queued behind the current work. `changes` subscribers receive every committed
|
|
1011
|
-
* snapshot in order once the sender yields, with consecutive sends delivered
|
|
1012
|
-
* together. This guarantee belongs to `MachineRef`; a `MachineTarget` only
|
|
1013
|
-
* promises delivery. Errors that occur while processing an accepted event are
|
|
1014
|
-
* observed through `snapshot`, `changes`, or `join`. Sending after
|
|
1015
|
-
* termination fails with `StoppedError`.
|
|
893
|
+
* When an accepted event is processed is up to the host. Code written against
|
|
894
|
+
* `MachineRef` cannot assume that `snapshot` reflects an event once `send`
|
|
895
|
+
* returns. `LocalMachine.start` documents the delivery order that a reference to
|
|
896
|
+
* a local machine adds to this contract.
|
|
1016
897
|
*
|
|
1017
898
|
* @category models
|
|
1018
899
|
* @since 0.4.0
|
|
@@ -1035,15 +916,21 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
1035
916
|
readonly emissions: Stream.Stream<Emitted>;
|
|
1036
917
|
/** Waits for machine output or fails when execution fails or is stopped. */
|
|
1037
918
|
readonly join: Effect.Effect<Output, Error | StoppedError>;
|
|
1038
|
-
/** Stops this machine instance and
|
|
919
|
+
/** Stops this machine instance and the children it owns. */
|
|
1039
920
|
readonly stop: Effect.Effect<void>;
|
|
1040
921
|
/**
|
|
1041
|
-
* Accepts an event for
|
|
1042
|
-
*
|
|
1043
|
-
* `
|
|
1044
|
-
*
|
|
922
|
+
* Accepts an event for delivery. When the machine processes it is up to its
|
|
923
|
+
* host. An event that the schema of the machine refuses is rejected with
|
|
924
|
+
* `MachineSchemaDecodeError`, and the machine keeps running; once the machine
|
|
925
|
+
* has ended, `send` fails with `StoppedError`.
|
|
926
|
+
*
|
|
927
|
+
* A transition that throws follows one rule on every host: the error goes to
|
|
928
|
+
* the sender when one waits for the event to be processed, and otherwise the
|
|
929
|
+
* machine fails with it. A `send` of `LocalMachine` returns before its event
|
|
930
|
+
* is processed, so the machine fails; a `ClusterMachine` client waits, so it
|
|
931
|
+
* is rejected and the machine goes on.
|
|
1045
932
|
*/
|
|
1046
|
-
readonly send: (event: Event) => Effect.Effect<void, StoppedError>;
|
|
933
|
+
readonly send: (event: Event) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>;
|
|
1047
934
|
/**
|
|
1048
935
|
* Returns the current directly owned child for a typed descriptor.
|
|
1049
936
|
*
|
|
@@ -1058,39 +945,48 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
1058
945
|
readonly childChanges: <Child extends ChildMachine.Any>(child: Child) => Stream.Stream<Option.Option<ChildMachine.Ref<Child>>>;
|
|
1059
946
|
}
|
|
1060
947
|
/**
|
|
1061
|
-
*
|
|
948
|
+
* Stateful process logic used by `spawn` and state-owned invocations.
|
|
949
|
+
*
|
|
950
|
+
* Logic describes a process by what it needs from a host: the capabilities of
|
|
951
|
+
* `Logic.InitialContext` and `Logic.RunContext`. `LocalMachine` runs it as a process owned by
|
|
952
|
+
* the machine. `ClusterMachine.make` does not compile for a machine that invokes
|
|
953
|
+
* it.
|
|
1062
954
|
*
|
|
1063
955
|
* @category models
|
|
1064
956
|
* @since 0.4.0
|
|
1065
957
|
*/
|
|
1066
958
|
export interface Logic<State, Event, out Error = never, out Requirements = never, out Output = never, out InitialError = never> {
|
|
1067
959
|
/** Creates the initial process state and may spawn scoped child processes. */
|
|
1068
|
-
initial(
|
|
960
|
+
initial(context: Logic.InitialContext<Event>): Effect.Effect<State, InitialError, Requirements>;
|
|
1069
961
|
/** Runs the stateful process loop until it produces output or fails. */
|
|
1070
|
-
run(context: Logic.
|
|
962
|
+
run(context: Logic.RunContext<State, Event>): Effect.Effect<Output, Error, Requirements>;
|
|
1071
963
|
}
|
|
1072
964
|
/**
|
|
1073
|
-
*
|
|
965
|
+
* Capabilities a host gives to process logic.
|
|
1074
966
|
*
|
|
1075
967
|
* @category models
|
|
1076
968
|
* @since 0.4.0
|
|
1077
969
|
*/
|
|
1078
970
|
export declare namespace Logic {
|
|
1079
971
|
/**
|
|
1080
|
-
*
|
|
972
|
+
* Endpoint of a process that can receive events and be stopped.
|
|
1081
973
|
*
|
|
1082
974
|
* @category models
|
|
1083
975
|
* @since 0.4.0
|
|
1084
976
|
*/
|
|
1085
|
-
interface
|
|
977
|
+
interface Endpoint<in Event> {
|
|
1086
978
|
/** Parent-local address id. */
|
|
1087
979
|
readonly id: string;
|
|
1088
980
|
/** Unique identity for this running child instance. */
|
|
1089
981
|
readonly sessionId: string;
|
|
1090
982
|
/** Stops the addressed child process. */
|
|
1091
983
|
readonly stop: Effect.Effect<void>;
|
|
1092
|
-
/**
|
|
1093
|
-
|
|
984
|
+
/**
|
|
985
|
+
* Sends an event to the addressed process. When the endpoint belongs to a
|
|
986
|
+
* machine whose event schema refuses the event, fails with
|
|
987
|
+
* {@link MachineSchemaDecodeError} and leaves the machine running.
|
|
988
|
+
*/
|
|
989
|
+
readonly send: (event: Event) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>;
|
|
1094
990
|
}
|
|
1095
991
|
/**
|
|
1096
992
|
* Starts child process logic owned by the current machine process.
|
|
@@ -1104,33 +1000,39 @@ export declare namespace Logic {
|
|
|
1104
1000
|
<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, Options extends SpawnOptions, ChildInitialError = never>(logic: Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, options: Options & ChildAddress.OptionsCompatibility<Options, ChildEvent>): Effect.Effect<MachineRef<ChildState, ChildEvent, ChildError, ChildOutput>, SpawnIdError<Options> | ChildInitialError, Exclude<ChildRequirements, Scope.Scope>>;
|
|
1105
1001
|
}
|
|
1106
1002
|
/**
|
|
1107
|
-
*
|
|
1003
|
+
* Capabilities available while process logic initializes.
|
|
1108
1004
|
*
|
|
1109
1005
|
* @category models
|
|
1110
1006
|
* @since 0.4.0
|
|
1111
1007
|
*/
|
|
1112
|
-
interface
|
|
1113
|
-
/**
|
|
1114
|
-
readonly self:
|
|
1115
|
-
/**
|
|
1116
|
-
readonly parent:
|
|
1117
|
-
/** Starts a child process owned by this
|
|
1008
|
+
interface InitialContext<Event> {
|
|
1009
|
+
/** Endpoint of the process being initialized. */
|
|
1010
|
+
readonly self: Endpoint<Event>;
|
|
1011
|
+
/** Endpoint of the owning process, when one exists. */
|
|
1012
|
+
readonly parent: Endpoint<unknown> | undefined;
|
|
1013
|
+
/** Starts a child process owned by this process. */
|
|
1118
1014
|
readonly spawn: Spawn<Event>;
|
|
1119
|
-
/**
|
|
1015
|
+
/**
|
|
1016
|
+
* Sends an event to a process endpoint, machine target, or typed
|
|
1017
|
+
* parent-local child address. When the addressed receiver is a machine
|
|
1018
|
+
* whose event schema refuses the event, fails with
|
|
1019
|
+
* {@link MachineSchemaDecodeError} and leaves the receiver running.
|
|
1020
|
+
*/
|
|
1120
1021
|
readonly sendTo: {
|
|
1121
|
-
<TargetEvent>(target:
|
|
1122
|
-
<
|
|
1022
|
+
<TargetEvent>(target: Endpoint<TargetEvent>, event: TargetEvent): Effect.Effect<void, StoppedError | MachineSchemaDecodeError>;
|
|
1023
|
+
<TargetEvent>(target: MachineTarget<TargetEvent>, event: TargetEvent): Effect.Effect<void, StoppedError | MachineSchemaDecodeError>;
|
|
1024
|
+
<Address extends ChildAddress<never>>(id: Address, event: ChildAddress.Event<Address>): Effect.Effect<void, StoppedError | MachineSchemaDecodeError>;
|
|
1123
1025
|
};
|
|
1124
1026
|
/** Stops a child process selected by its parent-local address. */
|
|
1125
1027
|
readonly stopChild: <Event>(id: ChildAddress<Event>) => Effect.Effect<void>;
|
|
1126
1028
|
}
|
|
1127
1029
|
/**
|
|
1128
|
-
*
|
|
1030
|
+
* Capabilities available while stateful process logic runs.
|
|
1129
1031
|
*
|
|
1130
1032
|
* @category models
|
|
1131
1033
|
* @since 0.4.0
|
|
1132
1034
|
*/
|
|
1133
|
-
interface
|
|
1035
|
+
interface RunContext<State, Event> extends InitialContext<Event> {
|
|
1134
1036
|
/** Waits for the next event delivered to this process. */
|
|
1135
1037
|
readonly receive: Effect.Effect<Event>;
|
|
1136
1038
|
/** Reads the current process state. */
|
|
@@ -1153,8 +1055,8 @@ type InvokeLifecycleId = string & {
|
|
|
1153
1055
|
*
|
|
1154
1056
|
* **Details**
|
|
1155
1057
|
*
|
|
1156
|
-
* The descriptor
|
|
1157
|
-
* Register it in `make({ children })` to invoke it by `src`, and pass a
|
|
1058
|
+
* The descriptor holds the child's id and machine definition, and nothing a host
|
|
1059
|
+
* 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
|
|
1158
1060
|
* descriptor for the same id and machine to `sendTo` and child lookup APIs, so
|
|
1159
1061
|
* state, event, error, and output types are inferred without separate
|
|
1160
1062
|
* annotations.
|
|
@@ -1168,8 +1070,6 @@ export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
|
1168
1070
|
readonly id: Id;
|
|
1169
1071
|
/** Complete machine definition carried by this descriptor. */
|
|
1170
1072
|
readonly machine: M;
|
|
1171
|
-
/** @internal Brand of descriptors built by `child` and `childFamily`. */
|
|
1172
|
-
readonly [ChildMachineLogicTypeId]: typeof ChildMachineLogicTypeId;
|
|
1173
1073
|
}
|
|
1174
1074
|
/**
|
|
1175
1075
|
* Namespace containing type-level members associated with `ChildMachine`.
|
|
@@ -1239,21 +1139,27 @@ export declare namespace ChildMachine {
|
|
|
1239
1139
|
* @category utility types
|
|
1240
1140
|
* @since 0.20.0
|
|
1241
1141
|
*/
|
|
1242
|
-
type StartError<Child extends Any> = Child extends ChildMachine<string, infer M> ? Machine.
|
|
1142
|
+
type StartError<Child extends Any> = Child extends ChildMachine<string, infer M> ? Machine.Error<M> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError : never;
|
|
1243
1143
|
/**
|
|
1244
|
-
* Services needed to initialize a spawned child machine
|
|
1144
|
+
* Services needed to initialize a spawned child machine, without
|
|
1145
|
+
* {@link MachineRuntime} and {@link InvocationSupport}.
|
|
1146
|
+
*
|
|
1147
|
+
* **Details**
|
|
1148
|
+
*
|
|
1149
|
+
* The process that spawns the child already runs on a host that spawns, and such
|
|
1150
|
+
* a host runs a child whatever that invokes.
|
|
1245
1151
|
*
|
|
1246
1152
|
* @category utility types
|
|
1247
1153
|
* @since 0.20.0
|
|
1248
1154
|
*/
|
|
1249
|
-
type StartRequirements<Child extends Any> = Child extends ChildMachine<string, infer M> ? Exclude<
|
|
1155
|
+
type StartRequirements<Child extends Any> = Child extends ChildMachine<string, infer M> ? Exclude<Machine.Services<M>, MachineRuntime | ChildMachineRuntime | InvocationSupport<InvocationSupport.Kind> | Scope.Scope> : never;
|
|
1250
1156
|
/**
|
|
1251
1157
|
* Running machine reference selected by a child descriptor.
|
|
1252
1158
|
*
|
|
1253
1159
|
* @category utility types
|
|
1254
1160
|
* @since 0.4.0
|
|
1255
1161
|
*/
|
|
1256
|
-
type Ref<Child> = Child extends ChildMachine<string, infer M> ? MachineRef<Machine.Snapshot<Machine.States<M>>, Machine.EventInput<Machine.InputEvent<M>>, Machine.Error<M> |
|
|
1162
|
+
type Ref<Child> = Child extends ChildMachine<string, infer M> ? MachineRef<Machine.Snapshot<Machine.States<M>>, Machine.EventInput<Machine.InputEvent<M>>, Machine.Error<M> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Machine.Output<M>, Machine.EmittedEvent<M>> : never;
|
|
1257
1163
|
/**
|
|
1258
1164
|
* Event accepted by the child selected by a descriptor.
|
|
1259
1165
|
*
|
|
@@ -1263,8 +1169,12 @@ export declare namespace ChildMachine {
|
|
|
1263
1169
|
type Event<Child> = Child extends ChildMachine<string, infer M> ? Machine.EventInput<Machine.InputEvent<M>> : never;
|
|
1264
1170
|
}
|
|
1265
1171
|
/**
|
|
1266
|
-
* Effectful operations for child machines owned directly by the
|
|
1267
|
-
* machine
|
|
1172
|
+
* Effectful operations for child machines owned directly by the running
|
|
1173
|
+
* machine.
|
|
1174
|
+
*
|
|
1175
|
+
* Input mappers receive it from the host. `LocalMachine` runs each child as an
|
|
1176
|
+
* owned local machine. The owner that `ClusterMachine` supplies refuses every
|
|
1177
|
+
* operation with {@link ProcessLocalError}.
|
|
1268
1178
|
*
|
|
1269
1179
|
* @category models
|
|
1270
1180
|
* @since 0.20.0
|
|
@@ -1272,13 +1182,17 @@ export declare namespace ChildMachine {
|
|
|
1272
1182
|
export interface ChildOwner<OwnerEvent> {
|
|
1273
1183
|
/** Starts a process-owned child and returns once initialization succeeds. */
|
|
1274
1184
|
readonly spawn: <const Child extends ChildMachine.Any>(child: Child & ChildMachine.Executable<Child> & ChildMachine.ParentCompatibility<Child, OwnerEvent>, ...options: ChildMachine.SpawnArgs<Child>) => Effect.Effect<ChildMachine.Ref<Child>, ChildAlreadyExistsError | ChildMachine.StartError<Child>, ChildMachine.StartRequirements<Child>>;
|
|
1275
|
-
/**
|
|
1276
|
-
|
|
1185
|
+
/**
|
|
1186
|
+
* Sends an event to one active child. Missing children are ignored. An event
|
|
1187
|
+
* that the child's event schema refuses fails with
|
|
1188
|
+
* {@link MachineSchemaDecodeError} and leaves the child running.
|
|
1189
|
+
*/
|
|
1190
|
+
readonly sendTo: <Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>;
|
|
1277
1191
|
/** Stops one active child. Missing children are ignored. */
|
|
1278
1192
|
readonly stop: <Child extends ChildMachine.Any>(child: Child) => Effect.Effect<void>;
|
|
1279
1193
|
}
|
|
1280
1194
|
/**
|
|
1281
|
-
*
|
|
1195
|
+
* Typed address of a child, unique within the machine that owns it.
|
|
1282
1196
|
*
|
|
1283
1197
|
* @category models
|
|
1284
1198
|
* @since 0.4.0
|
|
@@ -1342,6 +1256,7 @@ export declare namespace ChildAddress {
|
|
|
1342
1256
|
* @since 0.4.0
|
|
1343
1257
|
*/
|
|
1344
1258
|
export interface SpawnOptions {
|
|
1259
|
+
/** Address of the child, unique among the active children of its owner. */
|
|
1345
1260
|
readonly id?: string;
|
|
1346
1261
|
}
|
|
1347
1262
|
/**
|
|
@@ -1356,15 +1271,13 @@ export declare namespace Machine {
|
|
|
1356
1271
|
*
|
|
1357
1272
|
* @internal
|
|
1358
1273
|
*/
|
|
1359
|
-
export interface TypeCarrier<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R,
|
|
1274
|
+
export interface TypeCarrier<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, FinalStates extends StateIdentifier<States>, Output, Emits extends ReadonlyArray<TaggedSchema>, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> {
|
|
1360
1275
|
readonly states: States;
|
|
1361
1276
|
readonly events: Events;
|
|
1362
1277
|
readonly input: Input;
|
|
1363
1278
|
readonly unhandledStates: UnhandledStates;
|
|
1364
1279
|
readonly error: E;
|
|
1365
1280
|
readonly services: R;
|
|
1366
|
-
readonly initialError: InitialE;
|
|
1367
|
-
readonly initialServices: InitialR;
|
|
1368
1281
|
readonly finalStates: FinalStates;
|
|
1369
1282
|
readonly output: Output;
|
|
1370
1283
|
readonly emittedEvents: Emits;
|
|
@@ -1413,7 +1326,7 @@ export declare namespace Machine {
|
|
|
1413
1326
|
export interface Any extends Pipeable {
|
|
1414
1327
|
readonly [TypeId]: TypeId;
|
|
1415
1328
|
/** @internal */
|
|
1416
|
-
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any
|
|
1329
|
+
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
1417
1330
|
readonly states: StateSchemas;
|
|
1418
1331
|
readonly root: Pick<State<Machine.StateNodeConfig>, typeof StateTypeId | "node">;
|
|
1419
1332
|
readonly events: EventProtocol.Any<"public">;
|
|
@@ -1477,26 +1390,18 @@ export declare namespace Machine {
|
|
|
1477
1390
|
*/
|
|
1478
1391
|
export type Error<M extends Any> = M[typeof MachineTypeId]["error"];
|
|
1479
1392
|
/**
|
|
1480
|
-
* Extracts
|
|
1393
|
+
* Extracts what a machine definition requires of the host that runs it.
|
|
1481
1394
|
*
|
|
1482
|
-
*
|
|
1483
|
-
* @since 0.4.0
|
|
1484
|
-
*/
|
|
1485
|
-
export type Services<M extends Any> = M[typeof MachineTypeId]["services"];
|
|
1486
|
-
/**
|
|
1487
|
-
* Extracts the startup error channel carried by a machine definition.
|
|
1395
|
+
* **Details**
|
|
1488
1396
|
*
|
|
1489
|
-
*
|
|
1490
|
-
* @
|
|
1491
|
-
|
|
1492
|
-
export type InitialError<M extends Any> = M[typeof MachineTypeId]["initialError"];
|
|
1493
|
-
/**
|
|
1494
|
-
* Extracts startup service requirements carried by a machine definition.
|
|
1397
|
+
* The requirements are the services of the work its states invoke,
|
|
1398
|
+
* {@link MachineRuntime} when that work uses it, and one
|
|
1399
|
+
* {@link InvocationSupport} for each invoked kind that not every host runs.
|
|
1495
1400
|
*
|
|
1496
1401
|
* @category utility types
|
|
1497
1402
|
* @since 0.4.0
|
|
1498
1403
|
*/
|
|
1499
|
-
export type
|
|
1404
|
+
export type Services<M extends Any> = M[typeof MachineTypeId]["services"];
|
|
1500
1405
|
/**
|
|
1501
1406
|
* Extracts final state paths carried by a machine definition.
|
|
1502
1407
|
*
|
|
@@ -1534,6 +1439,54 @@ export declare namespace Machine {
|
|
|
1534
1439
|
export type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"];
|
|
1535
1440
|
/** Extracts the public input protocol required from an owning machine. */
|
|
1536
1441
|
export type ParentEvents<M extends Any> = M[typeof MachineTypeId]["parentEvents"];
|
|
1442
|
+
/**
|
|
1443
|
+
* The value an Effect source succeeds with and the typed error it fails with.
|
|
1444
|
+
*
|
|
1445
|
+
* @category utility types
|
|
1446
|
+
* @since 0.48.0
|
|
1447
|
+
*/
|
|
1448
|
+
export interface EffectResult<Done, Failure> {
|
|
1449
|
+
readonly done: Done;
|
|
1450
|
+
readonly failure: Failure;
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Extracts the result types of every Effect source a machine registers,
|
|
1454
|
+
* keyed by source name.
|
|
1455
|
+
*
|
|
1456
|
+
* **Details**
|
|
1457
|
+
*
|
|
1458
|
+
* The machine returned by `handle` carries these types, and only as types:
|
|
1459
|
+
* nothing is added to the machine value. A source that takes input
|
|
1460
|
+
* contributes the Effect its function returns.
|
|
1461
|
+
*
|
|
1462
|
+
* **Gotchas**
|
|
1463
|
+
*
|
|
1464
|
+
* A machine whose type was widened, for example by annotating it as a
|
|
1465
|
+
* `Machine.Machine<...>` or as `Machine.Machine.Any`, no longer carries them,
|
|
1466
|
+
* and this type is `never`.
|
|
1467
|
+
*
|
|
1468
|
+
* @category utility types
|
|
1469
|
+
* @since 0.48.0
|
|
1470
|
+
*/
|
|
1471
|
+
export type EffectResults<M extends Any> = M extends {
|
|
1472
|
+
readonly [MachineEffectResultsTypeId]?: infer Results extends Readonly<Record<string, EffectResult<any, any>>>;
|
|
1473
|
+
} ? Results : never;
|
|
1474
|
+
/**
|
|
1475
|
+
* Type-only evidence of the result types of a machine's Effect sources, read
|
|
1476
|
+
* through {@link EffectResults}.
|
|
1477
|
+
*
|
|
1478
|
+
* @category models
|
|
1479
|
+
* @since 0.48.0
|
|
1480
|
+
*/
|
|
1481
|
+
export interface EffectResultsEvidence<Results> {
|
|
1482
|
+
/**
|
|
1483
|
+
* @internal Optional, so a machine type rebuilt from its parameters stays
|
|
1484
|
+
* assignable to and from the type that `handle` returned.
|
|
1485
|
+
*/
|
|
1486
|
+
readonly [MachineEffectResultsTypeId]?: Results;
|
|
1487
|
+
}
|
|
1488
|
+
/** The result types of one registered Effect source. */
|
|
1489
|
+
export type EffectResultOf<Source> = InvokeResolvedSource<Source> extends Effect.Effect<infer Done, infer Failure, infer _R> ? EffectResult<Done, Failure> : never;
|
|
1537
1490
|
/** Extracts whether a machine requires or optionally accepts an owner. */
|
|
1538
1491
|
export type ParentAvailability<M extends Any> = ParentModeOf<M[typeof MachineTypeId]["parentEvents"]>;
|
|
1539
1492
|
/** Extracts an internal event schema tuple from the complete and public protocols. */
|
|
@@ -2100,7 +2053,7 @@ export declare namespace Machine {
|
|
|
2100
2053
|
* @category models
|
|
2101
2054
|
* @since 0.4.0
|
|
2102
2055
|
*/
|
|
2103
|
-
export type
|
|
2056
|
+
export type InvocationDefinition<SourcePath extends string = string> = InvocationDefinitions.InvocationDefinition<SourcePath>;
|
|
2104
2057
|
/**
|
|
2105
2058
|
* Transition retained after hierarchy precedence and conflict resolution for
|
|
2106
2059
|
* one planned microstep.
|
|
@@ -2292,12 +2245,14 @@ export declare namespace Machine {
|
|
|
2292
2245
|
*/
|
|
2293
2246
|
export type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"];
|
|
2294
2247
|
/**
|
|
2295
|
-
* Event values received by lifecycle callbacks
|
|
2248
|
+
* Event values received by lifecycle callbacks: a declared event,
|
|
2249
|
+
* `InitialEvent` while the initial state settles, or `InvocationEvent` for a
|
|
2250
|
+
* step caused by invoked work.
|
|
2296
2251
|
*
|
|
2297
2252
|
* @category utility types
|
|
2298
2253
|
* @since 0.4.0
|
|
2299
2254
|
*/
|
|
2300
|
-
export type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> = EventOf<Events> | InitialEvent;
|
|
2255
|
+
export type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> = EventOf<Events> | InitialEvent | InvocationEvent;
|
|
2301
2256
|
/**
|
|
2302
2257
|
* Extracts a state value from a state definition by identifier.
|
|
2303
2258
|
*
|
|
@@ -2700,7 +2655,7 @@ export declare namespace Machine {
|
|
|
2700
2655
|
* value without changing its active descendants.
|
|
2701
2656
|
*
|
|
2702
2657
|
* @category models
|
|
2703
|
-
* @since 0.
|
|
2658
|
+
* @since 0.48.0
|
|
2704
2659
|
*/
|
|
2705
2660
|
export interface StateUpdate<States extends StateSchemas, StateId extends ValuedStateIdentifier<States>> {
|
|
2706
2661
|
readonly [StateUpdateTypeId]: {
|
|
@@ -2810,7 +2765,7 @@ export declare namespace Machine {
|
|
|
2810
2765
|
* @category models
|
|
2811
2766
|
* @since 0.4.0
|
|
2812
2767
|
*/
|
|
2813
|
-
export type HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>,
|
|
2768
|
+
export type HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2814
2769
|
/** Value owned by the state whose handler is running. */
|
|
2815
2770
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2816
2771
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
@@ -3045,14 +3000,14 @@ export declare namespace Machine {
|
|
|
3045
3000
|
* @category utility types
|
|
3046
3001
|
* @since 0.4.0
|
|
3047
3002
|
*/
|
|
3048
|
-
export type StateActionResult
|
|
3003
|
+
export type StateActionResult = undefined;
|
|
3049
3004
|
/**
|
|
3050
3005
|
* Initial target that a machine resolves at startup.
|
|
3051
3006
|
*
|
|
3052
3007
|
* @category utility types
|
|
3053
3008
|
* @since 0.4.0
|
|
3054
3009
|
*/
|
|
3055
|
-
export type InitialResult<States extends StateSchemas
|
|
3010
|
+
export type InitialResult<States extends StateSchemas> = InitialTarget<StateIdentifier<States>>;
|
|
3056
3011
|
/**
|
|
3057
3012
|
* Result that a transition declaration resolves to.
|
|
3058
3013
|
*
|
|
@@ -3066,7 +3021,7 @@ export declare namespace Machine {
|
|
|
3066
3021
|
* @category utility types
|
|
3067
3022
|
* @since 0.4.0
|
|
3068
3023
|
*/
|
|
3069
|
-
export type HandlerResult<States extends StateSchemas
|
|
3024
|
+
export type HandlerResult<States extends StateSchemas> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateUpdate<States, ValuedStateIdentifier<States>> | CombinedTarget<Target<States, StateIdentifier<States>> | Snapshot<States> | ChoiceTarget<States, ChoiceIdentifier<States>>, States, ValuedStateIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateUpdate<States, ValuedStateIdentifier<States>>> | NoTarget;
|
|
3070
3025
|
/**
|
|
3071
3026
|
* Extracts the return value from an entry or exit action.
|
|
3072
3027
|
*
|
|
@@ -3082,30 +3037,6 @@ export declare namespace Machine {
|
|
|
3082
3037
|
readonly default: (...args: any) => infer Ret;
|
|
3083
3038
|
} ? Ret : never;
|
|
3084
3039
|
}[keyof NonNullable<History>] : never;
|
|
3085
|
-
/** Extracts the return value from a choice resolver. */
|
|
3086
|
-
export type ChoiceReturn<Config> = Config extends {
|
|
3087
|
-
readonly choice: infer Choice;
|
|
3088
|
-
} ? EventTransitionReturn<Choice> : never;
|
|
3089
|
-
/**
|
|
3090
|
-
* Extracts the return value from an event transition config.
|
|
3091
|
-
*
|
|
3092
|
-
* @category utility types
|
|
3093
|
-
* @since 0.4.0
|
|
3094
|
-
*/
|
|
3095
|
-
export type EventTransitionReturn<Transition> = Transition extends {
|
|
3096
|
-
readonly resolve?: infer Resolve;
|
|
3097
|
-
} ? NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3098
|
-
/**
|
|
3099
|
-
* Extracts the return value from a state's event handlers.
|
|
3100
|
-
*
|
|
3101
|
-
* @category utility types
|
|
3102
|
-
* @since 0.4.0
|
|
3103
|
-
*/
|
|
3104
|
-
export type EventHandlerReturn<Config> = Config extends {
|
|
3105
|
-
readonly on?: infer On;
|
|
3106
|
-
} ? {
|
|
3107
|
-
readonly [EventTag in keyof On]: EventTransitionReturn<NonNullable<On[EventTag]>>;
|
|
3108
|
-
}[keyof On] : never;
|
|
3109
3040
|
/**
|
|
3110
3041
|
* Extracts the invoke config or configs from a state config.
|
|
3111
3042
|
*
|
|
@@ -3114,7 +3045,7 @@ export declare namespace Machine {
|
|
|
3114
3045
|
*/
|
|
3115
3046
|
export type InvokeReturn<Config> = "invoke" extends keyof Config ? Config extends {
|
|
3116
3047
|
readonly invoke?: infer Invoke;
|
|
3117
|
-
} ? NonNullable<Invoke> extends
|
|
3048
|
+
} ? NonNullable<Invoke> extends ReadonlyArray<infer One> ? One : NonNullable<Invoke> : never : never;
|
|
3118
3049
|
/**
|
|
3119
3050
|
* Extracts the child process logic returned by an invoke source.
|
|
3120
3051
|
*
|
|
@@ -3123,7 +3054,7 @@ export declare namespace Machine {
|
|
|
3123
3054
|
*/
|
|
3124
3055
|
export type InvokeResolvedSource<Source> = Source extends LazyProgramValue ? Source : Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3125
3056
|
type InvokeFactoryResult<Source> = Source extends (...args: any) => infer Resolved ? Resolved : never;
|
|
3126
|
-
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> |
|
|
3057
|
+
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Services<M>, Output<M>, Error<M> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError> : never;
|
|
3127
3058
|
export type InvokeLogic<Invoke> = Invoke extends {
|
|
3128
3059
|
readonly effect: infer Source;
|
|
3129
3060
|
} ? InvokeFactoryResult<Source> extends infer Fx extends Effect.Effect<any, any, any> ? Logic<void, never, Effect.Error<Fx>, Effect.Services<Fx>, Effect.Success<Fx>> : never : Invoke extends {
|
|
@@ -3138,14 +3069,16 @@ export declare namespace Machine {
|
|
|
3138
3069
|
/**
|
|
3139
3070
|
* Extracts the startup error from an invoke source child process logic.
|
|
3140
3071
|
*
|
|
3072
|
+
* **Details**
|
|
3073
|
+
*
|
|
3074
|
+
* Invoked logic contributes its startup error. A child machine declares none.
|
|
3075
|
+
*
|
|
3141
3076
|
* @category utility types
|
|
3142
3077
|
* @since 0.4.0
|
|
3143
3078
|
*/
|
|
3144
|
-
export type InvokeInitialError<Invoke> = Invoke extends {
|
|
3145
|
-
readonly
|
|
3146
|
-
|
|
3147
|
-
};
|
|
3148
|
-
} ? InitialError : LogicInitialErrorOf<InvokeLogic<Invoke>>;
|
|
3079
|
+
export type InvokeInitialError<Invoke> = IsAny<Invoke> extends true ? unknown : Invoke extends {
|
|
3080
|
+
readonly child: unknown;
|
|
3081
|
+
} ? never : LogicInitialErrorOf<InvokeLogic<Invoke>>;
|
|
3149
3082
|
/**
|
|
3150
3083
|
* Extracts the runtime error from an invoked child process.
|
|
3151
3084
|
*
|
|
@@ -3163,11 +3096,7 @@ export declare namespace Machine {
|
|
|
3163
3096
|
* @category utility types
|
|
3164
3097
|
* @since 0.4.0
|
|
3165
3098
|
*/
|
|
3166
|
-
export type InvokeOutput<Invoke> = Invoke
|
|
3167
|
-
readonly [InvokeTypeId]: {
|
|
3168
|
-
readonly output: Types.Covariant<infer Output>;
|
|
3169
|
-
};
|
|
3170
|
-
} ? Output : LogicOutputOf<InvokeLogic<Invoke>>;
|
|
3099
|
+
export type InvokeOutput<Invoke> = LogicOutputOf<InvokeLogic<Invoke>>;
|
|
3171
3100
|
/**
|
|
3172
3101
|
* Extracts the service requirements from an invoke source child process logic.
|
|
3173
3102
|
*
|
|
@@ -3180,29 +3109,9 @@ export declare namespace Machine {
|
|
|
3180
3109
|
};
|
|
3181
3110
|
} ? Requirements : LogicServicesOf<InvokeLogic<Invoke>>;
|
|
3182
3111
|
/** Public parent inputs required by an invoked child machine. */
|
|
3183
|
-
export type InvokeParentEvents<Invoke> = Invoke extends {
|
|
3184
|
-
readonly [InvokeTypeId]: {
|
|
3185
|
-
readonly parentEvents: Types.Covariant<infer ParentEvent>;
|
|
3186
|
-
};
|
|
3187
|
-
} ? ParentEvent : IsAny<Invoke> extends true ? never : Invoke extends {
|
|
3112
|
+
export type InvokeParentEvents<Invoke> = IsAny<Invoke> extends true ? never : Invoke extends {
|
|
3188
3113
|
readonly child: ChildMachine<string, infer M>;
|
|
3189
3114
|
} ? EventOf<ParentEvents<M>> : never;
|
|
3190
|
-
/** Extracts transition results returned by invocation lifecycle handlers. */
|
|
3191
|
-
export type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ? (Invoke extends {
|
|
3192
|
-
readonly [InvokeTypeId]: {
|
|
3193
|
-
readonly outcomes: Types.Covariant<infer Outcomes>;
|
|
3194
|
-
};
|
|
3195
|
-
} ? EventTransitionReturn<Outcomes> : never) | (Invoke extends {
|
|
3196
|
-
readonly onDone?: infer Handler;
|
|
3197
|
-
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
3198
|
-
readonly onFailure?: infer Handler;
|
|
3199
|
-
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
3200
|
-
readonly onElement?: infer Handler;
|
|
3201
|
-
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
3202
|
-
readonly onSnapshot?: infer Handler;
|
|
3203
|
-
} ? EventTransitionReturn<NonNullable<Handler>> : never) : never;
|
|
3204
|
-
type InvokeOutcomeError<Invoke> = IsAny<InvokeOutcomeReturn<Invoke>> extends true ? never : Effect.Error<InvokeOutcomeReturn<Invoke>>;
|
|
3205
|
-
type InvokeOutcomeServices<Invoke> = IsAny<InvokeOutcomeReturn<Invoke>> extends true ? never : Effect.Services<InvokeOutcomeReturn<Invoke>>;
|
|
3206
3115
|
type InvokeCollisionError<Invoke> = Invoke extends {
|
|
3207
3116
|
readonly logic: unknown;
|
|
3208
3117
|
} | {
|
|
@@ -3223,41 +3132,41 @@ export declare namespace Machine {
|
|
|
3223
3132
|
* @category utility types
|
|
3224
3133
|
* @since 0.4.0
|
|
3225
3134
|
*/
|
|
3226
|
-
export type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : InvokeCollisionError<InvokeReturn<Config>> | InvokeInitialError<InvokeReturn<Config
|
|
3135
|
+
export type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : InvokeCollisionError<InvokeReturn<Config>> | InvokeInitialError<InvokeReturn<Config>>;
|
|
3136
|
+
type InvokeSupport<Invoke> = IsAny<Invoke> extends true ? never : Invoke extends {
|
|
3137
|
+
readonly stream: unknown;
|
|
3138
|
+
} ? InvocationSupport<"Stream"> : Invoke extends {
|
|
3139
|
+
readonly logic: unknown;
|
|
3140
|
+
} ? InvocationSupport<"Logic"> : Invoke extends {
|
|
3141
|
+
readonly child: unknown;
|
|
3142
|
+
} ? InvocationSupport<"Child"> : never;
|
|
3227
3143
|
/**
|
|
3228
|
-
* Extracts the
|
|
3144
|
+
* Extracts the requirements that the invocations of a state handler config add
|
|
3145
|
+
* to its machine.
|
|
3229
3146
|
*
|
|
3230
|
-
*
|
|
3231
|
-
* @since 0.4.0
|
|
3232
|
-
*/
|
|
3233
|
-
export type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntime | InvokeServices<InvokeReturn<Config>> | InvokeOutcomeServices<InvokeReturn<Config>>;
|
|
3234
|
-
/**
|
|
3235
|
-
* Extracts the return value from an eventless transition.
|
|
3147
|
+
* **Details**
|
|
3236
3148
|
*
|
|
3237
|
-
*
|
|
3238
|
-
* @
|
|
3239
|
-
|
|
3240
|
-
export type AlwaysReturn<Config> = Config extends {
|
|
3241
|
-
readonly always?: infer Always;
|
|
3242
|
-
} ? EventTransitionReturn<NonNullable<Always>> : never;
|
|
3243
|
-
/**
|
|
3244
|
-
* Extracts the return value from a state completion transition.
|
|
3149
|
+
* The contribution contains the services of every invoked source, and one
|
|
3150
|
+
* {@link InvocationSupport} for each invoked kind that not every host runs. An
|
|
3151
|
+
* invoked child machine contributes all the requirements of its machine.
|
|
3245
3152
|
*
|
|
3246
3153
|
* @category utility types
|
|
3247
3154
|
* @since 0.4.0
|
|
3248
3155
|
*/
|
|
3249
|
-
export type
|
|
3250
|
-
readonly onDone?: infer OnDone;
|
|
3251
|
-
} ? EventTransitionReturn<NonNullable<OnDone>> : never;
|
|
3156
|
+
export type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : InvokeSupport<InvokeReturn<Config>> | InvokeServices<InvokeReturn<Config>>;
|
|
3252
3157
|
/**
|
|
3253
3158
|
* Extracts all service requirements contributed by a state handler config.
|
|
3254
3159
|
*
|
|
3160
|
+
* **Details**
|
|
3161
|
+
*
|
|
3162
|
+
* Transitions and actions are synchronous, so only invocations contribute
|
|
3163
|
+
* services. An action or history default whose return type is `any` contributes
|
|
3164
|
+
* `unknown`.
|
|
3165
|
+
*
|
|
3255
3166
|
* @category utility types
|
|
3256
3167
|
* @since 0.4.0
|
|
3257
3168
|
*/
|
|
3258
|
-
export type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : Effect.Services<
|
|
3259
|
-
/** The only transition value accepted by machine handler APIs. */
|
|
3260
|
-
type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = Transition<States, StateId, Context, Events, Emits, {}, Reenter, Acceptance>;
|
|
3169
|
+
export type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<HistoryDefaultReturn<Config>> | InvokeRequirements<Config> : never;
|
|
3261
3170
|
/** Opaque evidence that `resolve` selected one declared branch. */
|
|
3262
3171
|
export interface SelectedBranch<out Key extends string, out Result> {
|
|
3263
3172
|
readonly [SelectedBranchTypeId]: {
|
|
@@ -3265,86 +3174,6 @@ export declare namespace Machine {
|
|
|
3265
3174
|
readonly result: Types.Covariant<Result>;
|
|
3266
3175
|
};
|
|
3267
3176
|
}
|
|
3268
|
-
export type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
3269
|
-
/**
|
|
3270
|
-
* State-owned work that runs for the lifetime of its active state.
|
|
3271
|
-
*
|
|
3272
|
-
* **Details**
|
|
3273
|
-
*
|
|
3274
|
-
* Every `invoke` entry carries this type-level marker, which records the
|
|
3275
|
-
* state that owns the entry together with the machine's state schemas and
|
|
3276
|
-
* event protocols. The marker property is optional and is never set at
|
|
3277
|
-
* runtime.
|
|
3278
|
-
*
|
|
3279
|
-
* @category models
|
|
3280
|
-
* @since 0.23.0
|
|
3281
|
-
*/
|
|
3282
|
-
export interface InvokeOwned<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3283
|
-
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId, InputEvents, ParentEvents]>;
|
|
3284
|
-
}
|
|
3285
|
-
type StoredInvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & ({
|
|
3286
|
-
readonly id: string;
|
|
3287
|
-
readonly effect: (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<any, any, any>;
|
|
3288
|
-
readonly stream?: never;
|
|
3289
|
-
readonly after?: never;
|
|
3290
|
-
readonly logic?: never;
|
|
3291
|
-
readonly child?: never;
|
|
3292
|
-
readonly address?: never;
|
|
3293
|
-
readonly onDone?: unknown;
|
|
3294
|
-
readonly onFailure?: unknown;
|
|
3295
|
-
readonly onElement?: never;
|
|
3296
|
-
readonly onSnapshot?: never;
|
|
3297
|
-
} | {
|
|
3298
|
-
readonly id: string;
|
|
3299
|
-
readonly stream: (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<any, any, any>;
|
|
3300
|
-
readonly effect?: never;
|
|
3301
|
-
readonly after?: never;
|
|
3302
|
-
readonly logic?: never;
|
|
3303
|
-
readonly child?: never;
|
|
3304
|
-
readonly address?: never;
|
|
3305
|
-
readonly onElement?: unknown;
|
|
3306
|
-
readonly onDone: unknown;
|
|
3307
|
-
readonly onFailure?: unknown;
|
|
3308
|
-
readonly onSnapshot?: never;
|
|
3309
|
-
} | {
|
|
3310
|
-
readonly id: string;
|
|
3311
|
-
readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3312
|
-
readonly effect?: never;
|
|
3313
|
-
readonly stream?: never;
|
|
3314
|
-
readonly logic?: never;
|
|
3315
|
-
readonly child?: never;
|
|
3316
|
-
readonly address?: never;
|
|
3317
|
-
readonly onDone: unknown;
|
|
3318
|
-
readonly onFailure?: never;
|
|
3319
|
-
readonly onElement?: never;
|
|
3320
|
-
readonly onSnapshot?: never;
|
|
3321
|
-
} | {
|
|
3322
|
-
readonly id: string;
|
|
3323
|
-
readonly address: string;
|
|
3324
|
-
readonly logic: InvokeSource<Logic<any, any, any, any, any, any>, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3325
|
-
readonly effect?: never;
|
|
3326
|
-
readonly stream?: never;
|
|
3327
|
-
readonly after?: never;
|
|
3328
|
-
readonly child?: never;
|
|
3329
|
-
readonly onDone?: unknown;
|
|
3330
|
-
readonly onFailure?: unknown;
|
|
3331
|
-
readonly onElement?: never;
|
|
3332
|
-
readonly onSnapshot?: unknown;
|
|
3333
|
-
} | {
|
|
3334
|
-
readonly child: ChildMachine.Any;
|
|
3335
|
-
readonly input?: {} | null | ((context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown);
|
|
3336
|
-
readonly id?: never;
|
|
3337
|
-
readonly address?: never;
|
|
3338
|
-
readonly effect?: never;
|
|
3339
|
-
readonly stream?: never;
|
|
3340
|
-
readonly after?: never;
|
|
3341
|
-
readonly logic?: never;
|
|
3342
|
-
readonly onDone?: unknown;
|
|
3343
|
-
readonly onFailure?: unknown;
|
|
3344
|
-
readonly onElement?: never;
|
|
3345
|
-
readonly onSnapshot?: unknown;
|
|
3346
|
-
});
|
|
3347
|
-
type StoredInvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = StoredInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> | ReadonlyArray<StoredInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3348
3177
|
type LogicInitialEffectOf<Value> = Value extends {
|
|
3349
3178
|
readonly initial: infer Initial;
|
|
3350
3179
|
} ? Initial extends (...args: ReadonlyArray<any>) => infer Result ? Result : never : never;
|
|
@@ -3354,13 +3183,13 @@ export declare namespace Machine {
|
|
|
3354
3183
|
export type LogicStateOf<Value> = Effect.Success<LogicInitialEffectOf<Value>>;
|
|
3355
3184
|
export type LogicEventOf<Value> = Value extends {
|
|
3356
3185
|
readonly initial: infer Initial;
|
|
3357
|
-
} ? Initial extends (
|
|
3186
|
+
} ? Initial extends (context: infer LogicInitialContext, ...args: ReadonlyArray<any>) => any ? LogicInitialContext extends Logic.InitialContext<infer Event> ? Event : never : never : never;
|
|
3358
3187
|
export type LogicErrorOf<Value> = Effect.Error<LogicRunEffectOf<Value>>;
|
|
3359
3188
|
export type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>;
|
|
3360
3189
|
export type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>;
|
|
3361
3190
|
export type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>;
|
|
3362
3191
|
/** Output construction available to final and output-producing parallel states. */
|
|
3363
|
-
type OutputHandlerConfig<States extends StateSchemas,
|
|
3192
|
+
type OutputHandlerConfig<States extends StateSchemas, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
3364
3193
|
readonly output: Schema.Top;
|
|
3365
3194
|
} ? {
|
|
3366
3195
|
/** Constructs the decoded output declared by the state's `output` schema. */
|
|
@@ -3370,7 +3199,7 @@ export declare namespace Machine {
|
|
|
3370
3199
|
};
|
|
3371
3200
|
type ActiveOutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends {
|
|
3372
3201
|
readonly type: "parallel";
|
|
3373
|
-
} ? OutputHandlerConfig<States,
|
|
3202
|
+
} ? OutputHandlerConfig<States, StateId, ParallelOutputContext<States, Events, StateId>> : {
|
|
3374
3203
|
readonly output?: never;
|
|
3375
3204
|
};
|
|
3376
3205
|
type HistoryConstruction<Node, Owner extends string> = ConstructionData<Node> & (Node extends {
|
|
@@ -3406,7 +3235,7 @@ export declare namespace Machine {
|
|
|
3406
3235
|
* history owner. This makes the default independent of the transition source
|
|
3407
3236
|
* and provides every inactive ancestor and required parallel region.
|
|
3408
3237
|
*/
|
|
3409
|
-
export type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue:
|
|
3238
|
+
export type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Commands<EventOf<Events>, EmittedEventOf<Emits>>) => CompleteSnapshotContaining<States, ParentId> | StateConstruction<CompleteSnapshotContaining<States, ParentId>>;
|
|
3410
3239
|
/**
|
|
3411
3240
|
* Fallback implementation for one direct history pseudo-state.
|
|
3412
3241
|
*
|
|
@@ -3431,28 +3260,6 @@ export declare namespace Machine {
|
|
|
3431
3260
|
export type HistoryDefaultConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>, Children extends StateSchemas> = {
|
|
3432
3261
|
readonly [Key in HistoryStateKey<Children>]?: HistoryDefaultEntry<States, Events, Emits, ParentId>;
|
|
3433
3262
|
};
|
|
3434
|
-
/**
|
|
3435
|
-
* Required implementation for a choice pseudo-state.
|
|
3436
|
-
*
|
|
3437
|
-
* **Details**
|
|
3438
|
-
*
|
|
3439
|
-
* A choice state declares only `choice`, the transition that resolves it to
|
|
3440
|
-
* a concrete destination. Every other handler key is rejected.
|
|
3441
|
-
*
|
|
3442
|
-
* @category models
|
|
3443
|
-
* @since 0.23.0
|
|
3444
|
-
*/
|
|
3445
|
-
export interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3446
|
-
/** Required transition that resolves this transient choice to a concrete destination. */
|
|
3447
|
-
readonly choice: TransitionConfig<States, Events, Emits, ChoiceId, ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>>;
|
|
3448
|
-
readonly entry?: never;
|
|
3449
|
-
readonly exit?: never;
|
|
3450
|
-
readonly invoke?: never;
|
|
3451
|
-
readonly always?: never;
|
|
3452
|
-
readonly on?: never;
|
|
3453
|
-
readonly onDone?: never;
|
|
3454
|
-
readonly output?: never;
|
|
3455
|
-
}
|
|
3456
3263
|
type HandlerChildren<Node> = Node extends {
|
|
3457
3264
|
readonly states: infer Children extends StateSchemas;
|
|
3458
3265
|
} ? Children : never;
|
|
@@ -3520,24 +3327,23 @@ export declare namespace Machine {
|
|
|
3520
3327
|
type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "initial" extends keyof Config ? unknown : {
|
|
3521
3328
|
readonly initial: HandlerValidationError<"State requires an initial declaration for shallow history restoration", StateId>;
|
|
3522
3329
|
} : unknown;
|
|
3523
|
-
type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
3330
|
+
type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerInvokeParentEventsValidation<InputEvents, StateId, Config> & HandlerChildrenValidation<Node, StateId, Config> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRequiredHistoryInitializeValidation<AllStates, StateId, Config> & ValidateConstructionDeclarations<Node, Config> : unknown;
|
|
3524
3331
|
type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
|
|
3525
3332
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
|
|
3526
3333
|
};
|
|
3527
3334
|
type HandlerInvokeParentEventsValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown : {
|
|
3528
3335
|
readonly invoke: HandlerValidationError<"Invoked child expects parent events not accepted by this machine", StateId, Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
3529
3336
|
};
|
|
3530
|
-
type
|
|
3531
|
-
type HandlerTreeValidation<States extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, Config, OutputStates extends StateIdentifier<States>> = HandlerNodeValidation<States, Node, Events, InputEvents, Emits, Path, Config, OutputStates> & (Config extends {
|
|
3337
|
+
type HandlerTreeValidation<States extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, Config, OutputStates extends StateIdentifier<States>> = HandlerNodeValidation<States, Node, Events, InputEvents, Path, Config, OutputStates> & (Config extends {
|
|
3532
3338
|
readonly states: infer Handlers;
|
|
3533
3339
|
} ? Node extends {
|
|
3534
3340
|
readonly states: infer Children extends StateSchemas;
|
|
3535
3341
|
} ? {
|
|
3536
3342
|
readonly states: {
|
|
3537
|
-
readonly [K in keyof Handlers]: K extends keyof Children ? HandlerTreeValidation<States, Children[K], Events, InputEvents,
|
|
3343
|
+
readonly [K in keyof Handlers]: K extends keyof Children ? HandlerTreeValidation<States, Children[K], Events, InputEvents, Extract<JoinPath<Path, Extract<K, string>>, StateNodeIdentifier<States>>, Handlers[K], OutputStates> : unknown;
|
|
3538
3344
|
};
|
|
3539
3345
|
} : unknown : unknown);
|
|
3540
|
-
type RootHandlerValidation<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>,
|
|
3346
|
+
type RootHandlerValidation<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Config, OutputStates extends StateIdentifier<States>> = HandlerTreeValidation<States, States[""], Events, InputEvents, Extract<"", StateNodeIdentifier<States>>, Config, OutputStates>;
|
|
3541
3347
|
type HandlerHasRequiredInitial<Node, Config> = Node extends {
|
|
3542
3348
|
readonly states: infer Children extends StateSchemas;
|
|
3543
3349
|
} ? Node extends {
|
|
@@ -3558,7 +3364,7 @@ export declare namespace Machine {
|
|
|
3558
3364
|
Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
|
|
3559
3365
|
] extends [never] ? true : false : false : true;
|
|
3560
3366
|
type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = HandlerHasRequiredInitial<Node, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
|
|
3561
|
-
type HandlerConfigError<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : Effect.Error<
|
|
3367
|
+
type HandlerConfigError<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : Effect.Error<StateActionReturn<Config, "entry">> | Effect.Error<StateActionReturn<Config, "exit">> | Effect.Error<HistoryDefaultReturn<Config>> | InvokeError<Config> : never;
|
|
3562
3368
|
type HandlerNodeEvidence<AllStates extends StateSchemas, Node, StateId extends StateNodeIdentifier<AllStates>, NodeConfig> = [NodeConfig] extends [never] ? never : {
|
|
3563
3369
|
readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, Node, StateId, NodeConfig> : never;
|
|
3564
3370
|
readonly error: HandlerConfigError<HandlerConfigPart<NodeConfig>>;
|
|
@@ -3725,7 +3531,7 @@ export declare namespace Machine {
|
|
|
3725
3531
|
readonly from?: never;
|
|
3726
3532
|
readonly decoded?: never;
|
|
3727
3533
|
} : never);
|
|
3728
|
-
type InlineDestinationConstruction<S extends StateSchemas,
|
|
3534
|
+
type InlineDestinationConstruction<S extends StateSchemas, P extends DestinationPath<S>, C> = P extends ChoiceIdentifier<S> ? {
|
|
3729
3535
|
readonly from?: never;
|
|
3730
3536
|
readonly decoded?: never;
|
|
3731
3537
|
} : P extends StateIdentifier<S> ? InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
|
|
@@ -3772,7 +3578,7 @@ export declare namespace Machine {
|
|
|
3772
3578
|
readonly branches?: never;
|
|
3773
3579
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
3774
3580
|
readonly resolve?: never;
|
|
3775
|
-
} & InlineDestinationConstruction<S,
|
|
3581
|
+
} & InlineDestinationConstruction<S, P, C>;
|
|
3776
3582
|
}[DestinationPath<S>];
|
|
3777
3583
|
type InlineUnknownTarget<S extends StateSchemas> = {
|
|
3778
3584
|
/** Selects a declared descendant, constructing the values it requires. */
|
|
@@ -3840,7 +3646,7 @@ export declare namespace Machine {
|
|
|
3840
3646
|
readonly resolve?: (context: C & {
|
|
3841
3647
|
/** Selects one of the declared `branches`. */
|
|
3842
3648
|
readonly select: BranchSelect<S, Src, R>;
|
|
3843
|
-
}, enqueue:
|
|
3649
|
+
}, enqueue: Commands<EventOf<Ev>, EmittedEventOf<Em>>) => unknown;
|
|
3844
3650
|
/** Set to true to exit and reenter the handler source. */
|
|
3845
3651
|
readonly reenter?: Reenter extends true ? boolean : never;
|
|
3846
3652
|
/** Branch on the condition inside `resolve`, returning `select.decline()`. */
|
|
@@ -3885,7 +3691,7 @@ export declare namespace Machine {
|
|
|
3885
3691
|
*/
|
|
3886
3692
|
export type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = (ObjectPolicy<C, Reenter, Acceptance> & {
|
|
3887
3693
|
/** Enqueues synchronous commands when this transition is selected. */
|
|
3888
|
-
readonly commands?: (context: C, enqueue:
|
|
3694
|
+
readonly commands?: (context: C, enqueue: Commands<EventOf<Ev>, EmittedEventOf<Em>>) => void;
|
|
3889
3695
|
} & DeclarationData<InlineDestination<S, Src, C> | InlineUnknownTarget<S> | InlineUpdate<S, Src, C> | InlineRoot<C, R> | {
|
|
3890
3696
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
3891
3697
|
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
@@ -3952,7 +3758,8 @@ export declare namespace Machine {
|
|
|
3952
3758
|
/** Maps the owning state context to the registered source input. */
|
|
3953
3759
|
readonly input?: never;
|
|
3954
3760
|
};
|
|
3955
|
-
type ResolvedInvoke<R, K extends PropertyKey> =
|
|
3761
|
+
type ResolvedInvoke<R, K extends PropertyKey> = K extends PropertyKey ? ResolvedSource<R, K> : never;
|
|
3762
|
+
type ResolvedSource<R, K extends PropertyKey> = SourceKind<R, K> extends "effects" ? {
|
|
3956
3763
|
readonly effect: () => InvokeResolvedSource<SourceValue<R, K>>;
|
|
3957
3764
|
} : SourceKind<R, K> extends "streams" ? {
|
|
3958
3765
|
readonly stream: () => InvokeResolvedSource<SourceValue<R, K>>;
|
|
@@ -3965,8 +3772,7 @@ export declare namespace Machine {
|
|
|
3965
3772
|
readonly child: SourceValue<R, K>;
|
|
3966
3773
|
} & (SourceValue<R, K> extends ChildMachine<string, infer M> ? {
|
|
3967
3774
|
readonly [InvokeTypeId]: {
|
|
3968
|
-
readonly error: Types.Covariant<Error<M
|
|
3969
|
-
readonly initialError: Types.Covariant<InitialError<M>>;
|
|
3775
|
+
readonly error: Types.Covariant<Error<M>>;
|
|
3970
3776
|
readonly requirements: Types.Covariant<Services<M>>;
|
|
3971
3777
|
};
|
|
3972
3778
|
} : never) : never;
|
|
@@ -3990,7 +3796,7 @@ export declare namespace Machine {
|
|
|
3990
3796
|
/** Optionally handles active snapshots of invoked logic or a child machine. */
|
|
3991
3797
|
readonly onSnapshot: Transition<S, Src, InvokeSnapshotContext<S, Ev, Em, Src, V, never, never, In, Pa>, Ev, Em, R, true, "required">;
|
|
3992
3798
|
};
|
|
3993
|
-
type RegisteredInvokeError<R, K extends PropertyKey> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? Error<M>
|
|
3799
|
+
type RegisteredInvokeError<R, K extends PropertyKey> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? Error<M> : never : InvokeRuntimeError<ResolvedInvoke<R, K>>;
|
|
3994
3800
|
/**
|
|
3995
3801
|
* A registered source invocation with its required input and reachable outcomes.
|
|
3996
3802
|
*
|
|
@@ -4113,15 +3919,15 @@ export declare namespace Machine {
|
|
|
4113
3919
|
};
|
|
4114
3920
|
type ObjectLifecycle<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>> = Src extends StateIdentifier<S> ? {
|
|
4115
3921
|
/** Runs synchronously on entry and may enqueue commands. */
|
|
4116
|
-
readonly entry?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue:
|
|
3922
|
+
readonly entry?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Commands<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult;
|
|
4117
3923
|
} & (Node extends {
|
|
4118
3924
|
readonly type: "final";
|
|
4119
3925
|
} ? {
|
|
4120
3926
|
/** Runs synchronously on exit and may enqueue commands. */
|
|
4121
3927
|
readonly exit?: never;
|
|
4122
|
-
} & OutputHandlerConfig<S,
|
|
3928
|
+
} & OutputHandlerConfig<S, Src, FinalOutputContext<S, Ev, Src>> : {
|
|
4123
3929
|
/** Runs synchronously on exit and may enqueue commands. */
|
|
4124
|
-
readonly exit?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue:
|
|
3930
|
+
readonly exit?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Commands<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult;
|
|
4125
3931
|
} & ActiveOutputHandlerConfig<S, Ev, Src>) : {
|
|
4126
3932
|
/** Runs synchronously on entry and may enqueue commands. */
|
|
4127
3933
|
readonly entry?: never; /** Runs synchronously on exit and may enqueue commands. */
|
|
@@ -4175,7 +3981,7 @@ export declare namespace Machine {
|
|
|
4175
3981
|
} : {
|
|
4176
3982
|
/** Event handlers keyed by the public or internal event tag. */
|
|
4177
3983
|
readonly on?: {
|
|
4178
|
-
readonly [Tag in TagOf<Ev[number]>]?: Transition<S, Src, HandlerContext<S, Ev, Em, Src, Tag,
|
|
3984
|
+
readonly [Tag in TagOf<Ev[number]>]?: Transition<S, Src, HandlerContext<S, Ev, Em, Src, Tag, In, Pa>, Ev, Em, R, true, "declinable">;
|
|
4179
3985
|
};
|
|
4180
3986
|
/** Eventless transition evaluated during stabilization. */
|
|
4181
3987
|
readonly always?: Transition<S, Src, AlwaysContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, "declinable">;
|
|
@@ -4441,48 +4247,14 @@ export declare namespace Machine {
|
|
|
4441
4247
|
* @category combinators
|
|
4442
4248
|
* @since 0.34.0
|
|
4443
4249
|
*/
|
|
4444
|
-
export interface Handler<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, I extends Schema.Top,
|
|
4250
|
+
export interface Handler<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, I extends Schema.Top, Final extends StateIdentifier<S>, Out, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> {
|
|
4445
4251
|
<const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & ValidateObjectConfig<NoInfer<C>, R, S> & HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R & {
|
|
4446
4252
|
readonly "~input": I;
|
|
4447
|
-
}> & RootConstruction<S[""], I["Type"]>, R> & RootConstruction<S[""], I["Type"]> & RootHandlerValidation<S, Ev, In,
|
|
4253
|
+
}> & RootConstruction<S[""], I["Type"]>, R> & RootConstruction<S[""], I["Type"]> & RootHandlerValidation<S, Ev, In, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
|
|
4448
4254
|
readonly "": NormalizeObjectConfig<NoInfer<C>, R>;
|
|
4449
|
-
}>["outputState"], StateIdentifier<S>>>): Machine<S, Ev, I, Exclude<StateIdentifier<S>, HandleEvidence<S, C, R>["stateId"]>, HandleEvidence<S, C, R>["error"],
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
* Any state config.
|
|
4453
|
-
*
|
|
4454
|
-
* @category utility types
|
|
4455
|
-
* @since 0.4.0
|
|
4456
|
-
*/
|
|
4457
|
-
export type AnyStateConfig = StateConfig<any, any, any, any, any, any, any> | ChoiceStateConfig<any, any, any, any>;
|
|
4458
|
-
/**
|
|
4459
|
-
* Runtime event-handler map stored for a single state tag.
|
|
4460
|
-
*
|
|
4461
|
-
* @category models
|
|
4462
|
-
* @since 0.4.0
|
|
4463
|
-
*/
|
|
4464
|
-
export type EventHandlerMap<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, true, TransitionAcceptance>>>;
|
|
4465
|
-
/**
|
|
4466
|
-
* Runtime state config stored for a single state tag.
|
|
4467
|
-
*
|
|
4468
|
-
* @category models
|
|
4469
|
-
* @since 0.4.0
|
|
4470
|
-
*/
|
|
4471
|
-
export interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
4472
|
-
/** Runs synchronously on entry and may enqueue commands. */
|
|
4473
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4474
|
-
/** Runs synchronously on exit and may enqueue commands. */
|
|
4475
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4476
|
-
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4477
|
-
readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>;
|
|
4478
|
-
/** Eventless transition evaluated during stabilization. */
|
|
4479
|
-
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4480
|
-
/** Handles successful invocation or state completion with its exact output type. */
|
|
4481
|
-
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4482
|
-
/** Constructs the decoded output declared by the state schema. */
|
|
4483
|
-
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
|
|
4484
|
-
/** Event handlers keyed by the public or internal event tag. */
|
|
4485
|
-
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
|
|
4255
|
+
}>["outputState"], StateIdentifier<S>>>): Machine<S, Ev, I, Exclude<StateIdentifier<S>, HandleEvidence<S, C, R>["stateId"]>, HandleEvidence<S, C, R>["error"], HandleEvidence<S, C, R>["services"], Final, Out, Em, Extract<HandleEvidence<S, C, R>["outputState"], StateIdentifier<S>>, In, Pa> & EffectResultsEvidence<{
|
|
4256
|
+
readonly [K in keyof Registered<R, "effects"> & string]: EffectResultOf<Registered<R, "effects">[K]>;
|
|
4257
|
+
}>;
|
|
4486
4258
|
}
|
|
4487
4259
|
export {};
|
|
4488
4260
|
}
|
|
@@ -4556,7 +4328,7 @@ export declare const isMachine: (u: unknown) => u is Machine.Any;
|
|
|
4556
4328
|
* @category guards
|
|
4557
4329
|
* @since 0.4.0
|
|
4558
4330
|
*/
|
|
4559
|
-
export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
4331
|
+
export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, state: Machine.Snapshot<States>) => state is Machine.SnapshotContainingFinal<States, FinalStates>;
|
|
4560
4332
|
/**
|
|
4561
4333
|
* Defines root or nested state schemas while preserving the exact child topology.
|
|
4562
4334
|
*
|
|
@@ -4609,7 +4381,7 @@ type ReservedRootName<Root> = Root extends {
|
|
|
4609
4381
|
} ? "root" extends keyof Children ? {
|
|
4610
4382
|
readonly "~effect/Machine/ReservedRootStateName": never;
|
|
4611
4383
|
} : unknown : unknown;
|
|
4612
|
-
type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top,
|
|
4384
|
+
type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources> = {
|
|
4613
4385
|
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
4614
4386
|
readonly effects?: Effects & Machine.ValidatePrograms<Effects>;
|
|
4615
4387
|
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
@@ -4638,9 +4410,9 @@ type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends Readon
|
|
|
4638
4410
|
/** Schema used to decode input before initial-state construction. */
|
|
4639
4411
|
readonly input?: Input;
|
|
4640
4412
|
};
|
|
4641
|
-
type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top,
|
|
4413
|
+
type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources> = Definition<{
|
|
4642
4414
|
readonly "": Root;
|
|
4643
|
-
}, readonly [...InputEvents, ...InternalEvents], Input,
|
|
4415
|
+
}, readonly [...InputEvents, ...InternalEvents], Input, Machine.FinalStateFromDefinition<{
|
|
4644
4416
|
readonly "": Root;
|
|
4645
4417
|
}>, Machine.TerminalOutput<{
|
|
4646
4418
|
readonly "": Root;
|
|
@@ -4659,7 +4431,7 @@ type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends Readon
|
|
|
4659
4431
|
/** @inline */
|
|
4660
4432
|
type Make = {
|
|
4661
4433
|
/** @param config Complete schema-first machine definition. */
|
|
4662
|
-
<const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void,
|
|
4434
|
+
<const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>): MakeResult<Root, InputEvents, Emits, Input, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children>;
|
|
4663
4435
|
};
|
|
4664
4436
|
/**
|
|
4665
4437
|
* Creates a schema-first machine definition.
|
|
@@ -4677,6 +4449,13 @@ type Make = {
|
|
|
4677
4449
|
* registered source by name with `invoke: { src }`, and only invoked sources
|
|
4678
4450
|
* add to the machine's requirements.
|
|
4679
4451
|
*
|
|
4452
|
+
* Each run of invoked work owns a `Scope`, which every host closes when the run
|
|
4453
|
+
* ends or is stopped. An Effect and a Stream get a new one for each run, and
|
|
4454
|
+
* logic gets one from its `initial` through the end of its `run`. Finalizers
|
|
4455
|
+
* added with `Effect.addFinalizer` or `Effect.acquireRelease` therefore run with
|
|
4456
|
+
* the work, not when the machine stops. A timer acquires nothing, and a child
|
|
4457
|
+
* machine has no scope of its own: its invoked work follows the same rule.
|
|
4458
|
+
*
|
|
4680
4459
|
* `Machine.events` defines the public input protocol. `Machine.internalEvents`
|
|
4681
4460
|
* adds raised events and other machine-local deliveries.
|
|
4682
4461
|
* `Machine.emittedEvents` defines outward ephemeral notifications. The
|
|
@@ -4694,7 +4473,7 @@ type Make = {
|
|
|
4694
4473
|
* **Example** (Invoking a registered Effect)
|
|
4695
4474
|
*
|
|
4696
4475
|
* ```ts import.meta.vitest
|
|
4697
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
4476
|
+
* import { LocalMachine, Machine } from "@typeonce/effect-machine"
|
|
4698
4477
|
* import { Effect, Option, Schema } from "effect"
|
|
4699
4478
|
*
|
|
4700
4479
|
* const Lookup = Schema.TaggedUnion({ Loading: { id: Schema.String }, Ready: { name: Schema.String } })
|
|
@@ -4720,7 +4499,7 @@ type Make = {
|
|
|
4720
4499
|
* })
|
|
4721
4500
|
*
|
|
4722
4501
|
* const name = Effect.scoped(Effect.gen(function*() {
|
|
4723
|
-
* const ref = yield*
|
|
4502
|
+
* const ref = yield* LocalMachine.start(machine)
|
|
4724
4503
|
* yield* ref.send(Events.Load({ id: "1" }))
|
|
4725
4504
|
* const ready = yield* Machine.waitFor(ref, ({ state }) => state.state.path === "Ready").pipe(Effect.timeout("5 seconds"))
|
|
4726
4505
|
* return States.get(ready.state, "Ready").pipe(Option.map((state) => state.name))
|
|
@@ -4821,7 +4600,7 @@ export declare const events: <const Cases extends Readonly<Record<string, Schema
|
|
|
4821
4600
|
* **Example** (Reusing a tagged union as the event protocol)
|
|
4822
4601
|
*
|
|
4823
4602
|
* ```ts import.meta.vitest
|
|
4824
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
4603
|
+
* import { LocalMachine, Machine } from "@typeonce/effect-machine"
|
|
4825
4604
|
* import { Effect, Schema } from "effect"
|
|
4826
4605
|
*
|
|
4827
4606
|
* const Event = Machine.eventsFromSchemas(
|
|
@@ -4839,7 +4618,7 @@ export declare const events: <const Cases extends Readonly<Record<string, Schema
|
|
|
4839
4618
|
* })
|
|
4840
4619
|
*
|
|
4841
4620
|
* const count = Effect.scoped(Effect.gen(function*() {
|
|
4842
|
-
* const ref = yield*
|
|
4621
|
+
* const ref = yield* LocalMachine.start(machine)
|
|
4843
4622
|
* yield* ref.send(Event.Increment({ by: 1 }))
|
|
4844
4623
|
* return (yield* ref.state).value.count
|
|
4845
4624
|
* }))
|
|
@@ -4985,7 +4764,7 @@ export declare const emittedEventsFromSchemas: {
|
|
|
4985
4764
|
* **When to use**
|
|
4986
4765
|
*
|
|
4987
4766
|
* Use when you need to store or transport a statechart snapshot independently
|
|
4988
|
-
* of
|
|
4767
|
+
* of the host that runs the machine.
|
|
4989
4768
|
*
|
|
4990
4769
|
* **Details**
|
|
4991
4770
|
*
|
|
@@ -5029,7 +4808,7 @@ export declare const emittedEventsFromSchemas: {
|
|
|
5029
4808
|
* @category encoding
|
|
5030
4809
|
* @since 0.4.0
|
|
5031
4810
|
*/
|
|
5032
|
-
export declare const encodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
4811
|
+
export declare const encodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, snapshot: Machine.Snapshot<States>) => Effect.Effect<Machine.EncodedSnapshot, MachineSchemaEncodeError, Machine.SnapshotEncodingServices<States>>;
|
|
5033
4812
|
/**
|
|
5034
4813
|
* Decodes a normalized data representation into a validated machine snapshot.
|
|
5035
4814
|
*
|
|
@@ -5074,7 +4853,7 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
5074
4853
|
* @category decoding
|
|
5075
4854
|
* @since 0.4.0
|
|
5076
4855
|
*/
|
|
5077
|
-
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
4856
|
+
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
5078
4857
|
/**
|
|
5079
4858
|
* Plans the initial state for a machine without executing machine commands.
|
|
5080
4859
|
*
|
|
@@ -5089,9 +4868,9 @@ export declare const decodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
5089
4868
|
*
|
|
5090
4869
|
* **Gotchas**
|
|
5091
4870
|
*
|
|
5092
|
-
*
|
|
5093
|
-
* protocol. Manual planners may inspect commands
|
|
5094
|
-
* to execute child-addressed operations.
|
|
4871
|
+
* Planning does not execute the closed command list. A host such as `LocalMachine`
|
|
4872
|
+
* executes it as part of its commit protocol. Manual planners may inspect commands
|
|
4873
|
+
* but need running machine targets to execute child-addressed operations.
|
|
5095
4874
|
*
|
|
5096
4875
|
* **Example** (Planning startup without running the machine)
|
|
5097
4876
|
*
|
|
@@ -5110,11 +4889,10 @@ export declare const decodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
5110
4889
|
* ```
|
|
5111
4890
|
*
|
|
5112
4891
|
* @see {@link plan} for planning a received event.
|
|
5113
|
-
* @see {@link start} for the managed runtime protocol.
|
|
5114
4892
|
* @category constructors
|
|
5115
4893
|
* @since 0.4.0
|
|
5116
4894
|
*/
|
|
5117
|
-
export declare const planInitial: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
4895
|
+
export declare const planInitial: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<{
|
|
5118
4896
|
readonly startingState: Machine.Snapshot<States>;
|
|
5119
4897
|
readonly initialEntryPaths: ReadonlyArray<Machine.StateIdentifier<States>>;
|
|
5120
4898
|
readonly state: Machine.Snapshot<States>;
|
|
@@ -5139,7 +4917,7 @@ export declare const planInitial: <const States extends Machine.StateSchemas, co
|
|
|
5139
4917
|
readonly done: false;
|
|
5140
4918
|
/** Constructs the decoded output declared by the state schema. */
|
|
5141
4919
|
readonly output: undefined;
|
|
5142
|
-
}),
|
|
4920
|
+
}), E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, never>;
|
|
5143
4921
|
/**
|
|
5144
4922
|
* Returns every compiled state node in definition order.
|
|
5145
4923
|
*
|
|
@@ -5198,7 +4976,7 @@ export declare const inputEventSchemas: <M extends Machine.Any>(machine: M) => M
|
|
|
5198
4976
|
*/
|
|
5199
4977
|
export declare const transitionDefinitions: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.TransitionDefinition<Machine.StateNodeIdentifier<Machine.States<M>>, Machine.TagOf<Machine.Events<M>[number]>, Machine.StateNodeIdentifier<Machine.States<M>>>>;
|
|
5200
4978
|
/**
|
|
5201
|
-
* Returns serializable descriptions of every state-owned
|
|
4979
|
+
* Returns serializable descriptions of every state-owned invocation.
|
|
5202
4980
|
*
|
|
5203
4981
|
* **Details**
|
|
5204
4982
|
*
|
|
@@ -5209,7 +4987,7 @@ export declare const transitionDefinitions: <M extends Machine.Any>(machine: M)
|
|
|
5209
4987
|
* @category getters
|
|
5210
4988
|
* @since 0.4.0
|
|
5211
4989
|
*/
|
|
5212
|
-
export declare const
|
|
4990
|
+
export declare const invocationDefinitions: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.InvocationDefinition<Machine.StateIdentifier<Machine.States<M>>>>;
|
|
5213
4991
|
/**
|
|
5214
4992
|
* Returns every state node active in a decoded snapshot, in definition order.
|
|
5215
4993
|
*
|
|
@@ -5234,7 +5012,7 @@ export declare const configuration: <M extends Machine.Any>(machine: M, state: M
|
|
|
5234
5012
|
* @category getters
|
|
5235
5013
|
* @since 0.4.0
|
|
5236
5014
|
*/
|
|
5237
|
-
export declare const enabled: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
5015
|
+
export declare const enabled: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, state: Machine.Snapshot<States>) => ReadonlyArray<Machine.TagOf<Events[number]>>;
|
|
5238
5016
|
/**
|
|
5239
5017
|
* Tests whether a concrete event would select at least one transition from a
|
|
5240
5018
|
* decoded snapshot.
|
|
@@ -5291,8 +5069,8 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5291
5069
|
* @since 0.30.0
|
|
5292
5070
|
*/
|
|
5293
5071
|
export declare const can: {
|
|
5294
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
5295
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
5072
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>): (state: Machine.Snapshot<States>, event: Machine.EventInputOf<Events>) => Effect.Effect<boolean, MachineSchemaDecodeError>;
|
|
5073
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, state: Machine.Snapshot<States>, event: Machine.EventInputOf<Events>): Effect.Effect<boolean, MachineSchemaDecodeError>;
|
|
5296
5074
|
};
|
|
5297
5075
|
/**
|
|
5298
5076
|
* Returns an Effect that plans the next state snapshot without running command effects.
|
|
@@ -5306,8 +5084,8 @@ export declare const can: {
|
|
|
5306
5084
|
*
|
|
5307
5085
|
* **Gotchas**
|
|
5308
5086
|
*
|
|
5309
|
-
* `plan` returns data; it does not implement
|
|
5310
|
-
* `
|
|
5087
|
+
* `plan` returns data; it does not implement a commit protocol. A host such as
|
|
5088
|
+
* `LocalMachine` executes child commands, publishes `next`, and then delivers
|
|
5311
5089
|
* `emittedEvents`. Events with no enabled transition are ignored and produce
|
|
5312
5090
|
* an unchanged plan.
|
|
5313
5091
|
*
|
|
@@ -5338,11 +5116,10 @@ export declare const can: {
|
|
|
5338
5116
|
* ```
|
|
5339
5117
|
*
|
|
5340
5118
|
* @see {@link planInitial} for planning machine startup.
|
|
5341
|
-
* @see {@link start} for managed execution and lifecycle observation.
|
|
5342
5119
|
* @category combinators
|
|
5343
5120
|
* @since 0.4.0
|
|
5344
5121
|
*/
|
|
5345
|
-
export declare const plan: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never,
|
|
5122
|
+
export declare const plan: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, state: Machine.Snapshot<States>, event: Machine.EventInputOf<InputEvents>) => Effect.Effect<{
|
|
5346
5123
|
readonly event: Machine.EventOf<InputEvents>;
|
|
5347
5124
|
readonly next: Machine.Snapshot<States>;
|
|
5348
5125
|
readonly commands: ReadonlyArray<Command>;
|
|
@@ -5367,6 +5144,679 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
5367
5144
|
/** Constructs the decoded output declared by the state schema. */
|
|
5368
5145
|
readonly output: undefined;
|
|
5369
5146
|
}), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
|
|
5147
|
+
/**
|
|
5148
|
+
* The pure form of a machine, returned by {@link toStep}: functions that say
|
|
5149
|
+
* what the next state is, and which work to start and stop, without running
|
|
5150
|
+
* anything.
|
|
5151
|
+
*
|
|
5152
|
+
* **Details**
|
|
5153
|
+
*
|
|
5154
|
+
* Every function is synchronous and returns a value. Equal arguments give equal
|
|
5155
|
+
* results, and no call changes a value a caller holds, so a caller may keep an
|
|
5156
|
+
* earlier {@link MachineStep.State} and step from it again.
|
|
5157
|
+
*
|
|
5158
|
+
* - `start` starts the machine from its input, as `LocalMachine.start` does.
|
|
5159
|
+
* - `send` takes one public event. A failed `Exit` means the step did not
|
|
5160
|
+
* happen and the state passed in still holds: the event does not match its
|
|
5161
|
+
* schema (`MachineSchemaDecodeError`), or the machine has ended
|
|
5162
|
+
* (`StoppedError`).
|
|
5163
|
+
* - `settle` reports the end of work that a step started, with its `Exit`, and
|
|
5164
|
+
* that work could not start, with the failure of its evaluation.
|
|
5165
|
+
* - `element` reports one element of a running Stream.
|
|
5166
|
+
* - `report` reports the state of a running `Logic` or child machine.
|
|
5167
|
+
* - `stop` stops the machine as its owner, as `MachineRef.stop` does.
|
|
5168
|
+
* - `resume` starts the machine from a decoded snapshot, as `LocalMachine.resume`
|
|
5169
|
+
* does. A durable host passes the {@link MachineStep.Progress} of the work of
|
|
5170
|
+
* the active states, so that work which ended does not run again and work
|
|
5171
|
+
* which still runs is not started twice.
|
|
5172
|
+
*
|
|
5173
|
+
* A machine that fails or ends still takes a step. The step carries the last
|
|
5174
|
+
* state, the work to stop, and its {@link MachineStep.Step} `exit`.
|
|
5175
|
+
*
|
|
5176
|
+
* **Gotchas**
|
|
5177
|
+
*
|
|
5178
|
+
* The result of `settle`, `element`, or `report` for work whose state was
|
|
5179
|
+
* exited is a step that changes nothing, also when the same state was entered
|
|
5180
|
+
* again since. So is the result for work that already ended, and for any work
|
|
5181
|
+
* of a machine that has ended.
|
|
5182
|
+
*
|
|
5183
|
+
* These functions take the work object that a step listed, and compare it by
|
|
5184
|
+
* identity. A copy of it changes nothing. Neither does work that was listed
|
|
5185
|
+
* before a `resume`, or by another step taken from the same state, even though
|
|
5186
|
+
* its `path`, `id`, and `run` are equal.
|
|
5187
|
+
*
|
|
5188
|
+
* @category models
|
|
5189
|
+
* @since 0.48.0
|
|
5190
|
+
*/
|
|
5191
|
+
export interface MachineStep<in out M extends Machine.Any> {
|
|
5192
|
+
/** Starts the machine from its decoded input. */
|
|
5193
|
+
readonly start: (...input: [...Machine.InputArgs<Machine.InputSchema<M>>]) => Exit.Exit<MachineStep.Step<M>, MachineStep.StartError>;
|
|
5194
|
+
/**
|
|
5195
|
+
* Takes one public event. A failure means that the event was rejected and
|
|
5196
|
+
* `state` still holds.
|
|
5197
|
+
*/
|
|
5198
|
+
readonly send: (state: MachineStep.State<M>, event: Machine.EventInputOf<Machine.InputEvents<M>>) => Exit.Exit<MachineStep.Step<M>, MachineStep.Rejection>;
|
|
5199
|
+
/**
|
|
5200
|
+
* Reports the end of work that a step started, or the failure of its
|
|
5201
|
+
* evaluation when it could not start.
|
|
5202
|
+
*/
|
|
5203
|
+
readonly settle: (state: MachineStep.State<M>, work: MachineStep.Work<M>, exit: Exit.Exit<unknown, unknown>) => MachineStep.Step<M>;
|
|
5204
|
+
/**
|
|
5205
|
+
* Reports one element of a running Stream. The element is taken before the
|
|
5206
|
+
* next one is pulled.
|
|
5207
|
+
*/
|
|
5208
|
+
readonly element: (state: MachineStep.State<M>, work: MachineStep.Work.Stream<M>, element: unknown) => MachineStep.Step<M>;
|
|
5209
|
+
/**
|
|
5210
|
+
* Reports the state of a running `Logic` or child machine while it is
|
|
5211
|
+
* active: the state that the `Logic` sets, or the snapshot that a step of the
|
|
5212
|
+
* child publishes. Its owner reads it as the `state` of the snapshot that
|
|
5213
|
+
* `onSnapshot` receives.
|
|
5214
|
+
*/
|
|
5215
|
+
readonly report: (state: MachineStep.State<M>, work: MachineStep.Work.Logic<M> | MachineStep.Work.Child<M>, snapshot: unknown) => MachineStep.Step<M>;
|
|
5216
|
+
/** Stops the machine as its owner. Its `exit` fails with `StoppedError`. */
|
|
5217
|
+
readonly stop: (state: MachineStep.State<M>) => MachineStep.Step<M>;
|
|
5218
|
+
/**
|
|
5219
|
+
* Starts the machine from a decoded snapshot. `progress` names the work of
|
|
5220
|
+
* the active states that ended or still runs; any other work starts.
|
|
5221
|
+
*/
|
|
5222
|
+
readonly resume: (snapshot: Machine.Snapshot<Machine.States<M>>, progress?: ReadonlyArray<MachineStep.Progress<M>>) => Exit.Exit<MachineStep.Step<M>, MachineSchemaDecodeError>;
|
|
5223
|
+
}
|
|
5224
|
+
/**
|
|
5225
|
+
* Types of the values that a {@link MachineStep} takes and returns.
|
|
5226
|
+
*
|
|
5227
|
+
* @category models
|
|
5228
|
+
* @since 0.48.0
|
|
5229
|
+
*/
|
|
5230
|
+
export declare namespace MachineStep {
|
|
5231
|
+
/**
|
|
5232
|
+
* The state of a machine, as a host passes it from one step to the next.
|
|
5233
|
+
*
|
|
5234
|
+
* **Details**
|
|
5235
|
+
*
|
|
5236
|
+
* It is an immutable value. It holds the logical state, the work that runs,
|
|
5237
|
+
* and which entry of each invoking state the work belongs to, which is how a
|
|
5238
|
+
* step tells current work from work of an earlier entry.
|
|
5239
|
+
*
|
|
5240
|
+
* **Gotchas**
|
|
5241
|
+
*
|
|
5242
|
+
* Only the steps of the same machine construct it. Encode
|
|
5243
|
+
* {@link Step} `snapshot` with `Machine.encodeSnapshot` to store it, and
|
|
5244
|
+
* `resume` from the decoded snapshot.
|
|
5245
|
+
*
|
|
5246
|
+
* @category models
|
|
5247
|
+
* @since 0.48.0
|
|
5248
|
+
*/
|
|
5249
|
+
interface State<in out M extends Machine.Any> {
|
|
5250
|
+
readonly [MachineStepStateTypeId]: Types.Invariant<M>;
|
|
5251
|
+
}
|
|
5252
|
+
/**
|
|
5253
|
+
* What one step did, and what its host does next.
|
|
5254
|
+
*
|
|
5255
|
+
* **Details**
|
|
5256
|
+
*
|
|
5257
|
+
* A host carries a step out in this order, which is the order of
|
|
5258
|
+
* `LocalMachine`: it carries out `commands`, interrupts `stop`, publishes
|
|
5259
|
+
* `snapshot`, delivers `emitted`, starts `start`, and interrupts `stopAfter`.
|
|
5260
|
+
*
|
|
5261
|
+
* `snapshot` and `microsteps` are built when they are first read, so a host
|
|
5262
|
+
* that publishes neither pays for neither.
|
|
5263
|
+
*
|
|
5264
|
+
* @category models
|
|
5265
|
+
* @since 0.48.0
|
|
5266
|
+
*/
|
|
5267
|
+
interface Step<in out M extends Machine.Any> {
|
|
5268
|
+
/** The state to pass to the next step. */
|
|
5269
|
+
readonly state: State<M>;
|
|
5270
|
+
/** The logical state, as a view reads it and `Machine.encodeSnapshot` stores it. */
|
|
5271
|
+
readonly snapshot: Machine.Snapshot<Machine.States<M>>;
|
|
5272
|
+
/**
|
|
5273
|
+
* The event this step planned, as transitions received it: a decoded
|
|
5274
|
+
* public event, the lifecycle event of work, or the initial event of `start`
|
|
5275
|
+
* and `resume`. It is set also when planning it failed the machine.
|
|
5276
|
+
* `undefined` when the step planned no event, as for `stop`, a result that
|
|
5277
|
+
* is ignored, or a result that fails the machine without a transition.
|
|
5278
|
+
*/
|
|
5279
|
+
readonly event: Machine.LifecycleEvent<Machine.Events<M>> | undefined;
|
|
5280
|
+
/** The microsteps of the plan, in order, as `Machine.plan` returns them. Empty when nothing changed. */
|
|
5281
|
+
readonly microsteps: ReadonlyArray<Microstep<M>>;
|
|
5282
|
+
/** What transitions asked of the host with `enqueue.sendTo` and `enqueue.stop`, in order. */
|
|
5283
|
+
readonly commands: ReadonlyArray<Command<M>>;
|
|
5284
|
+
/**
|
|
5285
|
+
* Running work to interrupt before publishing `snapshot`, in order: work of
|
|
5286
|
+
* exited states, or all remaining work when the machine fails or is
|
|
5287
|
+
* stopped. Its `Exit` is not reported.
|
|
5288
|
+
*/
|
|
5289
|
+
readonly stop: ReadonlyArray<Work<M>>;
|
|
5290
|
+
/** Events emitted to the observers of the machine, in order. */
|
|
5291
|
+
readonly emitted: ReadonlyArray<Machine.EmittedEvent<M>>;
|
|
5292
|
+
/** Work to start, in order. Report its end with `settle`. */
|
|
5293
|
+
readonly start: ReadonlyArray<Work<M>>;
|
|
5294
|
+
/**
|
|
5295
|
+
* Running work of states that were not exited, to interrupt after
|
|
5296
|
+
* publishing `snapshot` and delivering `emitted` when this step reaches a
|
|
5297
|
+
* final state, latest first. Empty on every non-final, failed, or owner-stopped
|
|
5298
|
+
* step. Its `Exit` is not reported.
|
|
5299
|
+
*/
|
|
5300
|
+
readonly stopAfter: ReadonlyArray<Work<M>>;
|
|
5301
|
+
/**
|
|
5302
|
+
* Every piece of work that runs once this step is carried out, in start
|
|
5303
|
+
* order: the work that runs on, and then `start`. After `resume`, it also
|
|
5304
|
+
* holds the work that {@link Progress} names as running.
|
|
5305
|
+
*/
|
|
5306
|
+
readonly running: ReadonlyArray<Work<M>>;
|
|
5307
|
+
/**
|
|
5308
|
+
* Paths of the states that this step exited, in exit order, each once. A
|
|
5309
|
+
* durable host forgets what it stored about the work of these states. A
|
|
5310
|
+
* state that the step exited and entered again is in `exited` and in
|
|
5311
|
+
* `entered`. `start`, `resume`, `stop`, and a result that is ignored exit
|
|
5312
|
+
* nothing.
|
|
5313
|
+
*/
|
|
5314
|
+
readonly exited: ReadonlyArray<Machine.StateIdentifier<Machine.States<M>>>;
|
|
5315
|
+
/**
|
|
5316
|
+
* Paths of the states that this step entered, in entry order, each once.
|
|
5317
|
+
* `start` enters the states of the initial state. `resume` restores its
|
|
5318
|
+
* states and enters none.
|
|
5319
|
+
*/
|
|
5320
|
+
readonly entered: ReadonlyArray<Machine.StateIdentifier<Machine.States<M>>>;
|
|
5321
|
+
/**
|
|
5322
|
+
* How the machine ended, once it has: its output, or why it failed or
|
|
5323
|
+
* stopped. A machine that has ended runs no work and takes no event.
|
|
5324
|
+
*/
|
|
5325
|
+
readonly exit: Exit.Exit<Machine.Output<M>, Error<M>> | undefined;
|
|
5326
|
+
}
|
|
5327
|
+
/**
|
|
5328
|
+
* One microstep of a {@link Step}.
|
|
5329
|
+
*
|
|
5330
|
+
* @category models
|
|
5331
|
+
* @since 0.48.0
|
|
5332
|
+
*/
|
|
5333
|
+
interface Microstep<M extends Machine.Any> {
|
|
5334
|
+
readonly next: Machine.Snapshot<Machine.States<M>>;
|
|
5335
|
+
readonly event: Machine.LifecycleEvent<Machine.Events<M>>;
|
|
5336
|
+
readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<Machine.States<M>>, Machine.TagOf<Machine.Events<M>[number]>, Machine.StateNodeIdentifier<Machine.States<M>>>>;
|
|
5337
|
+
readonly commands: ReadonlyArray<Command>;
|
|
5338
|
+
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Machine.Events<M>>>;
|
|
5339
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEvent<M>>;
|
|
5340
|
+
readonly exitPaths: ReadonlyArray<string>;
|
|
5341
|
+
readonly entryPaths: ReadonlyArray<string>;
|
|
5342
|
+
readonly changed: boolean;
|
|
5343
|
+
}
|
|
5344
|
+
/**
|
|
5345
|
+
* What a transition asked of its host with `enqueue.sendTo` or
|
|
5346
|
+
* `enqueue.stop`.
|
|
5347
|
+
*
|
|
5348
|
+
* **Details**
|
|
5349
|
+
*
|
|
5350
|
+
* - `Send` sends `event` to a target with `target.send(event)`. An event sent
|
|
5351
|
+
* to `self` reaches the `self` target of the host, which plans it in a
|
|
5352
|
+
* later step.
|
|
5353
|
+
* - `SendToChild` sends `event` to a child of the machine. `work` is the
|
|
5354
|
+
* running `Logic` or child machine that `child` selects, when one runs.
|
|
5355
|
+
* Otherwise the host sends it to a child that work spawned with that
|
|
5356
|
+
* address, and ignores it when there is none.
|
|
5357
|
+
* - `StopChild` stops a child of the machine. `work` is the running `Logic`
|
|
5358
|
+
* or child machine that `child` selects, which no longer runs after this
|
|
5359
|
+
* step: the host stops it, and reports nothing of it. Otherwise the host
|
|
5360
|
+
* stops a child that work spawned with that address, if there is one.
|
|
5361
|
+
*
|
|
5362
|
+
* @category models
|
|
5363
|
+
* @since 0.48.0
|
|
5364
|
+
*/
|
|
5365
|
+
type Command<M extends Machine.Any = Machine.Any> = Command.Send | Command.SendToChild<M> | Command.StopChild<M>;
|
|
5366
|
+
/**
|
|
5367
|
+
* The kinds of {@link Command}.
|
|
5368
|
+
*
|
|
5369
|
+
* @category models
|
|
5370
|
+
* @since 0.48.0
|
|
5371
|
+
*/
|
|
5372
|
+
namespace Command {
|
|
5373
|
+
/**
|
|
5374
|
+
* Sends an event to a target outside the machine.
|
|
5375
|
+
*
|
|
5376
|
+
* @category models
|
|
5377
|
+
* @since 0.48.0
|
|
5378
|
+
*/
|
|
5379
|
+
interface Send {
|
|
5380
|
+
readonly _tag: "Send";
|
|
5381
|
+
readonly target: MachineTarget<unknown>;
|
|
5382
|
+
readonly event: unknown;
|
|
5383
|
+
}
|
|
5384
|
+
/**
|
|
5385
|
+
* Sends an event to a child of the machine.
|
|
5386
|
+
*
|
|
5387
|
+
* @category models
|
|
5388
|
+
* @since 0.48.0
|
|
5389
|
+
*/
|
|
5390
|
+
interface SendToChild<M extends Machine.Any> {
|
|
5391
|
+
readonly _tag: "SendToChild";
|
|
5392
|
+
readonly child: ChildMachine.Any | ChildAddress<never>;
|
|
5393
|
+
readonly work: Work.Logic<M> | Work.Child<M> | undefined;
|
|
5394
|
+
readonly event: unknown;
|
|
5395
|
+
}
|
|
5396
|
+
/**
|
|
5397
|
+
* Stops a child of the machine.
|
|
5398
|
+
*
|
|
5399
|
+
* @category models
|
|
5400
|
+
* @since 0.48.0
|
|
5401
|
+
*/
|
|
5402
|
+
interface StopChild<M extends Machine.Any> {
|
|
5403
|
+
readonly _tag: "StopChild";
|
|
5404
|
+
readonly child: ChildMachine.Any | ChildAddress<never>;
|
|
5405
|
+
readonly work: Work.Logic<M> | Work.Child<M> | undefined;
|
|
5406
|
+
}
|
|
5407
|
+
}
|
|
5408
|
+
/**
|
|
5409
|
+
* One piece of work that an entry of a state starts.
|
|
5410
|
+
*
|
|
5411
|
+
* **Details**
|
|
5412
|
+
*
|
|
5413
|
+
* Work is described, not evaluated. A host evaluates it when it starts it,
|
|
5414
|
+
* with the accessor of its kind: `effect`, `duration`, `stream`, `logic`, or
|
|
5415
|
+
* `input`. Each accessor calls the source and the input mapper of the work at
|
|
5416
|
+
* most once, however often it is called, and returns an `Exit` instead of
|
|
5417
|
+
* throwing.
|
|
5418
|
+
*
|
|
5419
|
+
* A host starts the work of a step in order. A failed `Exit` of an accessor
|
|
5420
|
+
* means that the work could not start: the host settles the work with that
|
|
5421
|
+
* `Exit` at once. That fails the machine, which then runs no work, so the
|
|
5422
|
+
* rest of the step does not start. This is what `LocalMachine` does when a
|
|
5423
|
+
* source throws.
|
|
5424
|
+
*
|
|
5425
|
+
* @category models
|
|
5426
|
+
* @since 0.48.0
|
|
5427
|
+
*/
|
|
5428
|
+
type Work<M extends Machine.Any> = Work.Effect<M> | Work.Timer<M> | Work.Stream<M> | Work.Logic<M> | Work.Child<M>;
|
|
5429
|
+
/**
|
|
5430
|
+
* The kinds of {@link Work}.
|
|
5431
|
+
*
|
|
5432
|
+
* @category models
|
|
5433
|
+
* @since 0.48.0
|
|
5434
|
+
*/
|
|
5435
|
+
namespace Work {
|
|
5436
|
+
/**
|
|
5437
|
+
* What every kind of work names.
|
|
5438
|
+
*
|
|
5439
|
+
* @category models
|
|
5440
|
+
* @since 0.48.0
|
|
5441
|
+
*/
|
|
5442
|
+
interface Proto<M extends Machine.Any> {
|
|
5443
|
+
/** Path of the state that invokes the work. */
|
|
5444
|
+
readonly path: Machine.StateIdentifier<Machine.States<M>>;
|
|
5445
|
+
/** Id of the invocation within its state. */
|
|
5446
|
+
readonly id: string;
|
|
5447
|
+
/** Name of the registered source, when the work has one. */
|
|
5448
|
+
readonly source: string | undefined;
|
|
5449
|
+
/** The entry of its state that started the work, counted from `0`. */
|
|
5450
|
+
readonly run: number;
|
|
5451
|
+
}
|
|
5452
|
+
/**
|
|
5453
|
+
* An Effect to run. It owns a `Scope`, closed with its `Exit`.
|
|
5454
|
+
*
|
|
5455
|
+
* @category models
|
|
5456
|
+
* @since 0.48.0
|
|
5457
|
+
*/
|
|
5458
|
+
interface Effect<M extends Machine.Any> extends Proto<M> {
|
|
5459
|
+
readonly _tag: "Effect";
|
|
5460
|
+
/** Evaluates the Effect to run, at most once. */
|
|
5461
|
+
readonly effect: () => Exit.Exit<StepEffect<unknown, Requirements<M>>>;
|
|
5462
|
+
}
|
|
5463
|
+
/**
|
|
5464
|
+
* A timer. It waits for its duration, and its host then settles it with a
|
|
5465
|
+
* successful `Exit`.
|
|
5466
|
+
*
|
|
5467
|
+
* **Details**
|
|
5468
|
+
*
|
|
5469
|
+
* `duration` evaluates how long the timer waits, at most once. It follows
|
|
5470
|
+
* the rule of every kind of work: a failure means that the timer could not
|
|
5471
|
+
* start, whether its input mapper or source threw, or its input names no
|
|
5472
|
+
* duration. A host that keeps timers of its own, or stores a due time
|
|
5473
|
+
* before it commits a step, reads `duration` in the step that enters the
|
|
5474
|
+
* state, and settles the timer with that failure where it would have
|
|
5475
|
+
* started.
|
|
5476
|
+
*
|
|
5477
|
+
* `effect` is the timer as an Effect that sleeps for the duration, for a
|
|
5478
|
+
* host whose timers wait on fibers. It fails as `duration` fails.
|
|
5479
|
+
*
|
|
5480
|
+
* @category models
|
|
5481
|
+
* @since 0.48.0
|
|
5482
|
+
*/
|
|
5483
|
+
interface Timer<M extends Machine.Any> extends Proto<M> {
|
|
5484
|
+
readonly _tag: "Timer";
|
|
5485
|
+
/** Evaluates how long the timer waits, at most once. */
|
|
5486
|
+
readonly duration: () => Exit.Exit<Duration.Duration>;
|
|
5487
|
+
/** Evaluates the timer as an Effect that waits for its duration. */
|
|
5488
|
+
readonly effect: () => Exit.Exit<StepEffect<void, never>>;
|
|
5489
|
+
}
|
|
5490
|
+
/**
|
|
5491
|
+
* A Stream to run. It owns a `Scope`, closed with its end. The host reports
|
|
5492
|
+
* each element with `element`, pulls the next element once that step is
|
|
5493
|
+
* carried out, and settles the Stream with the `Exit` of its run.
|
|
5494
|
+
*
|
|
5495
|
+
* @category models
|
|
5496
|
+
* @since 0.48.0
|
|
5497
|
+
*/
|
|
5498
|
+
interface Stream<M extends Machine.Any> extends Proto<M> {
|
|
5499
|
+
readonly _tag: "Stream";
|
|
5500
|
+
/** Evaluates the Stream to run, at most once. */
|
|
5501
|
+
readonly stream: () => Exit.Exit<StepStream<Requirements<M>>>;
|
|
5502
|
+
}
|
|
5503
|
+
/**
|
|
5504
|
+
* Process logic to run as a child of the machine, at its `address`.
|
|
5505
|
+
*
|
|
5506
|
+
* **Details**
|
|
5507
|
+
*
|
|
5508
|
+
* The host runs `initial` and then `run`, with contexts of its own: the
|
|
5509
|
+
* `parent` endpoint is the machine. It reports each state that the logic
|
|
5510
|
+
* sets with `report`, and settles the logic with the `Exit` of `run`, or
|
|
5511
|
+
* with the failure of `initial`. Both run in one `Scope`, forked from the
|
|
5512
|
+
* `Scope` that `initial` runs in and closed when `run` ends.
|
|
5513
|
+
*
|
|
5514
|
+
* @category models
|
|
5515
|
+
* @since 0.48.0
|
|
5516
|
+
*/
|
|
5517
|
+
interface Logic<M extends Machine.Any> extends Proto<M> {
|
|
5518
|
+
readonly _tag: "Logic";
|
|
5519
|
+
/** Address of the logic among the children of the machine. */
|
|
5520
|
+
readonly address: ChildAddress<never>;
|
|
5521
|
+
/** Evaluates the logic to run, at most once. */
|
|
5522
|
+
readonly logic: () => Exit.Exit<StepLogic<Requirements<M> | Scope.Scope>>;
|
|
5523
|
+
}
|
|
5524
|
+
/**
|
|
5525
|
+
* A child machine to run, with the machine as its parent.
|
|
5526
|
+
*
|
|
5527
|
+
* **Details**
|
|
5528
|
+
*
|
|
5529
|
+
* A host runs it as a machine of its own, such as one more `Machine.toStep`
|
|
5530
|
+
* of `child.machine` with `parent` set to a target of this machine. It
|
|
5531
|
+
* reports each snapshot of the child with `report`, and settles it with the
|
|
5532
|
+
* output of the child or with why it failed.
|
|
5533
|
+
*
|
|
5534
|
+
* @category models
|
|
5535
|
+
* @since 0.48.0
|
|
5536
|
+
*/
|
|
5537
|
+
interface Child<M extends Machine.Any> extends Proto<M> {
|
|
5538
|
+
readonly _tag: "Child";
|
|
5539
|
+
/** The descriptor of the child, which commands select it by. */
|
|
5540
|
+
readonly child: ChildMachine.Any;
|
|
5541
|
+
/**
|
|
5542
|
+
* Evaluates the arguments of the child's `start`, at most once: empty when
|
|
5543
|
+
* the invocation declares no input, and the input it maps otherwise.
|
|
5544
|
+
*/
|
|
5545
|
+
readonly input: () => Exit.Exit<ReadonlyArray<unknown>>;
|
|
5546
|
+
}
|
|
5547
|
+
}
|
|
5548
|
+
/**
|
|
5549
|
+
* How far a piece of work of an active state got, as a durable host stored
|
|
5550
|
+
* it, for `resume`.
|
|
5551
|
+
*
|
|
5552
|
+
* **Details**
|
|
5553
|
+
*
|
|
5554
|
+
* `Ended` work is not listed again: its end was applied, and running it again
|
|
5555
|
+
* would apply it twice. `Running` work is not listed in {@link Step} `start`,
|
|
5556
|
+
* because the host still runs it. It is in {@link Step} `running`, as the work
|
|
5557
|
+
* object that the host settles once it ends. Any work of an active state that
|
|
5558
|
+
* no progress names starts.
|
|
5559
|
+
*
|
|
5560
|
+
* @category models
|
|
5561
|
+
* @since 0.48.0
|
|
5562
|
+
*/
|
|
5563
|
+
interface Progress<M extends Machine.Any> {
|
|
5564
|
+
/** Path of the state that invokes the work. */
|
|
5565
|
+
readonly path: Machine.StateIdentifier<Machine.States<M>>;
|
|
5566
|
+
/** Id of the invocation within its state. */
|
|
5567
|
+
readonly id: string;
|
|
5568
|
+
readonly status: "Ended" | "Running";
|
|
5569
|
+
}
|
|
5570
|
+
/**
|
|
5571
|
+
* The children of a running machine, which its host owns.
|
|
5572
|
+
*
|
|
5573
|
+
* **Details**
|
|
5574
|
+
*
|
|
5575
|
+
* Work acts on the children of its machine through these operations: the
|
|
5576
|
+
* `children` of an input mapper, and `Machine.spawn`, `Machine.sendTo`, and
|
|
5577
|
+
* `Machine.stopChild`. A child is selected by its descriptor, or by the
|
|
5578
|
+
* address it was spawned or invoked at.
|
|
5579
|
+
*
|
|
5580
|
+
* A host that runs the `Logic` and child machines of the states also routes
|
|
5581
|
+
* `sendTo` and `stop` to them, and refuses to `spawn` a child at an address
|
|
5582
|
+
* that one of them holds, with `ChildAlreadyExistsError`.
|
|
5583
|
+
*
|
|
5584
|
+
* @category models
|
|
5585
|
+
* @since 0.48.0
|
|
5586
|
+
*/
|
|
5587
|
+
interface Children {
|
|
5588
|
+
/** Starts a child machine, as `ChildOwner.spawn` does. */
|
|
5589
|
+
readonly spawn: (child: ChildMachine.Any, options: {
|
|
5590
|
+
readonly input: unknown;
|
|
5591
|
+
} | undefined) => StepEffect<MachineRef<unknown, never, unknown, unknown, unknown>, unknown>;
|
|
5592
|
+
/** Starts process logic, as `Machine.spawn` does. */
|
|
5593
|
+
readonly spawnLogic: (logic: StepLogic<unknown>, options: SpawnOptions | undefined) => StepEffect<MachineRef<unknown, never, unknown, unknown, unknown>, unknown>;
|
|
5594
|
+
/**
|
|
5595
|
+
* Sends an event to a child. A child that does not run is ignored. When the
|
|
5596
|
+
* child is a machine whose event schema refuses the event, fails with
|
|
5597
|
+
* {@link MachineSchemaDecodeError} and leaves the child running.
|
|
5598
|
+
*/
|
|
5599
|
+
readonly sendTo: (child: ChildMachine.Any | ChildAddress<never>, event: unknown) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError>;
|
|
5600
|
+
/** Stops a child. A child that does not run is ignored. */
|
|
5601
|
+
readonly stop: (child: ChildMachine.Any | ChildAddress<never>) => Effect.Effect<void>;
|
|
5602
|
+
}
|
|
5603
|
+
/**
|
|
5604
|
+
* What {@link toStep} asks of a host for a machine.
|
|
5605
|
+
*
|
|
5606
|
+
* **Details**
|
|
5607
|
+
*
|
|
5608
|
+
* - `self` is the target of the running machine, through which the host takes
|
|
5609
|
+
* the events that the machine and its work send to it.
|
|
5610
|
+
* - `parent` is the target of the owner of a machine that declares a parent,
|
|
5611
|
+
* and is required when that parent is. Transitions and input mappers receive
|
|
5612
|
+
* it as `parent`.
|
|
5613
|
+
* - `children` are the children of the machine. They are required when work
|
|
5614
|
+
* of the machine requires `Machine.MachineRuntime` or
|
|
5615
|
+
* `Machine.ChildMachineRuntime`. Without them, every operation on children
|
|
5616
|
+
* fails the machine with `ProcessLocalError`.
|
|
5617
|
+
*
|
|
5618
|
+
* @category models
|
|
5619
|
+
* @since 0.48.0
|
|
5620
|
+
*/
|
|
5621
|
+
type Options<M extends Machine.Any> = {
|
|
5622
|
+
readonly self: MachineTarget<Machine.EventInputOf<Machine.InputEvents<M>>>;
|
|
5623
|
+
} & ParentOption<Machine.ParentEvents<M>> & ChildrenOption<Machine.Services<M>>;
|
|
5624
|
+
/**
|
|
5625
|
+
* Refuses, at compile time, a machine that a host cannot run.
|
|
5626
|
+
*
|
|
5627
|
+
* **When to use**
|
|
5628
|
+
*
|
|
5629
|
+
* Intersect it with the machine parameter of a host that runs only some
|
|
5630
|
+
* kinds of work: `machine: M & MachineStep.Supported<M, "Stream", never>`.
|
|
5631
|
+
*
|
|
5632
|
+
* **Details**
|
|
5633
|
+
*
|
|
5634
|
+
* `Kinds` are the kinds of {@link InvocationSupport} that the host runs, and
|
|
5635
|
+
* `Capabilities` are the services of children that it supplies as
|
|
5636
|
+
* {@link Children}. Effects and timers need no kind. A machine that needs
|
|
5637
|
+
* more resolves to an object whose property
|
|
5638
|
+
* `~effect/Machine/MachineStep/Unsupported` names what is missing.
|
|
5639
|
+
*
|
|
5640
|
+
* @category utility types
|
|
5641
|
+
* @since 0.48.0
|
|
5642
|
+
*/
|
|
5643
|
+
type Supported<M extends Machine.Any, Kinds extends InvocationSupport.Kind, Capabilities extends MachineRuntime | ChildMachineRuntime = never> = IsAny<Machine.Services<M>> extends true ? unknown : [
|
|
5644
|
+
UnsupportedInvocation<Machine.Services<M>, Kinds> | UnsupportedCapability<Machine.Services<M>, Capabilities>
|
|
5645
|
+
] extends [never] ? unknown : {
|
|
5646
|
+
readonly "~effect/Machine/MachineStep/Unsupported": {
|
|
5647
|
+
readonly invocations: UnsupportedInvocation<Machine.Services<M>, Kinds>;
|
|
5648
|
+
readonly capabilities: UnsupportedCapability<Machine.Services<M>, Capabilities>;
|
|
5649
|
+
};
|
|
5650
|
+
};
|
|
5651
|
+
/**
|
|
5652
|
+
* Services that the work of a machine requires of its host. The services of
|
|
5653
|
+
* children come from {@link Children}.
|
|
5654
|
+
*
|
|
5655
|
+
* @category utility types
|
|
5656
|
+
* @since 0.48.0
|
|
5657
|
+
*/
|
|
5658
|
+
type Requirements<M extends Machine.Any> = Exclude<Machine.Services<M>, InvocationSupport<InvocationSupport.Kind> | MachineRuntime | ChildMachineRuntime | Scope.Scope>;
|
|
5659
|
+
/**
|
|
5660
|
+
* Why a machine failed, or that its owner stopped it, as `MachineRef.join`
|
|
5661
|
+
* of `LocalMachine` reports it.
|
|
5662
|
+
*
|
|
5663
|
+
* @category errors
|
|
5664
|
+
* @since 0.48.0
|
|
5665
|
+
*/
|
|
5666
|
+
type Error<M extends Machine.Any> = Machine.Error<M> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError;
|
|
5667
|
+
/**
|
|
5668
|
+
* Why a machine could not start, as `LocalMachine.start` reports it.
|
|
5669
|
+
*
|
|
5670
|
+
* @category errors
|
|
5671
|
+
* @since 0.48.0
|
|
5672
|
+
*/
|
|
5673
|
+
type StartError = InfiniteTransitionError | MachineSchemaDecodeError | StartupError;
|
|
5674
|
+
/**
|
|
5675
|
+
* Why `send` did not take an event. The state passed to it still holds.
|
|
5676
|
+
*
|
|
5677
|
+
* @category errors
|
|
5678
|
+
* @since 0.48.0
|
|
5679
|
+
*/
|
|
5680
|
+
type Rejection = MachineSchemaDecodeError | StoppedError;
|
|
5681
|
+
}
|
|
5682
|
+
type StepEffect<A, R> = Effect.Effect<A, unknown, R>;
|
|
5683
|
+
type StepStream<R> = Stream.Stream<unknown, unknown, R>;
|
|
5684
|
+
type StepLogic<R> = Logic<unknown, unknown, unknown, R, unknown, unknown>;
|
|
5685
|
+
type ParentOption<ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> = Machine.ParentModeOf<ParentEvents> extends "required" ? {
|
|
5686
|
+
readonly parent: MachineTarget<Machine.EventInputOf<ParentEvents>>;
|
|
5687
|
+
} : Machine.ParentModeOf<ParentEvents> extends "optional" ? {
|
|
5688
|
+
readonly parent?: MachineTarget<Machine.EventInputOf<ParentEvents>> | undefined;
|
|
5689
|
+
} : {
|
|
5690
|
+
readonly parent?: undefined;
|
|
5691
|
+
};
|
|
5692
|
+
type ChildrenOption<R> = IsAny<R> extends true ? {
|
|
5693
|
+
readonly children?: MachineStep.Children | undefined;
|
|
5694
|
+
} : [Extract<R, MachineRuntime | ChildMachineRuntime>] extends [never] ? {
|
|
5695
|
+
readonly children?: MachineStep.Children | undefined;
|
|
5696
|
+
} : {
|
|
5697
|
+
readonly children: MachineStep.Children;
|
|
5698
|
+
};
|
|
5699
|
+
type UnsupportedInvocation<R, Kinds> = R extends InvocationSupport<infer Kind> ? Exclude<Kind, Kinds> : never;
|
|
5700
|
+
type UnsupportedCapability<R, Capabilities> = R extends MachineRuntime ? [MachineRuntime] extends [Capabilities] ? never : "MachineRuntime" : R extends ChildMachineRuntime ? [ChildMachineRuntime] extends [Capabilities] ? never : "ChildMachineRuntime" : never;
|
|
5701
|
+
/**
|
|
5702
|
+
* Extracts the step function of a machine: its pure form, for code that runs
|
|
5703
|
+
* a machine on a new host.
|
|
5704
|
+
*
|
|
5705
|
+
* **When to use**
|
|
5706
|
+
*
|
|
5707
|
+
* Applications run machines with `LocalMachine`, `AtomMachine`, or
|
|
5708
|
+
* `ClusterMachine`. Use `toStep` to write a host for a new runtime, such as a
|
|
5709
|
+
* UI framework or a store, that keeps the state itself, runs the work of the
|
|
5710
|
+
* machine, and reports back how it ended.
|
|
5711
|
+
*
|
|
5712
|
+
* **Details**
|
|
5713
|
+
*
|
|
5714
|
+
* The returned {@link MachineStep} runs nothing, and calls no user code for the
|
|
5715
|
+
* work it lists. Each of its functions returns the next state, as a value,
|
|
5716
|
+
* together with the commands to carry out, the work to stop and to start, in
|
|
5717
|
+
* the order the host carries them out. Work is an Effect, a timer, a Stream, a
|
|
5718
|
+
* `Logic`, or a child machine, described as data that the host evaluates when
|
|
5719
|
+
* it starts it. The current entry of a state is part of the state value, so a
|
|
5720
|
+
* result of work whose state was exited is ignored without the host comparing
|
|
5721
|
+
* anything.
|
|
5722
|
+
*
|
|
5723
|
+
* `toStep` accepts every machine that `LocalMachine.start` accepts, and also a
|
|
5724
|
+
* machine that declares a parent. A host states in its own types which kinds of
|
|
5725
|
+
* work it runs, with {@link MachineStep.Supported}. The options are the
|
|
5726
|
+
* {@link MachineStep.Options} of the machine: `self`, the `parent` of a machine
|
|
5727
|
+
* that has one, and the `children` that its work acts on.
|
|
5728
|
+
*
|
|
5729
|
+
* `send` rejects an event that does not match its schema, and keeps the
|
|
5730
|
+
* machine, as `send` of every host does.
|
|
5731
|
+
*
|
|
5732
|
+
* **Gotchas**
|
|
5733
|
+
*
|
|
5734
|
+
* The compiler reads only the requirements of a machine, and an input mapper
|
|
5735
|
+
* receives `children` whatever its machine requires. A host that passes no
|
|
5736
|
+
* `children` refuses every operation on them at run time with
|
|
5737
|
+
* `ProcessLocalError`, as a defect that fails the machine.
|
|
5738
|
+
*
|
|
5739
|
+
* **Example** (Stepping a machine that loads a document)
|
|
5740
|
+
*
|
|
5741
|
+
* ```ts import.meta.vitest
|
|
5742
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
5743
|
+
* import { Effect, Exit, Schema } from "effect"
|
|
5744
|
+
*
|
|
5745
|
+
* const Events = Machine.events({ Load: {} })
|
|
5746
|
+
* const machine = Machine.make({
|
|
5747
|
+
* root: Machine.state({
|
|
5748
|
+
* states: { Idle: {}, Loading: {}, Loaded: { fields: { text: Schema.String } } }
|
|
5749
|
+
* }),
|
|
5750
|
+
* events: Events,
|
|
5751
|
+
* effects: { load: Effect.succeed("hello") }
|
|
5752
|
+
* }).handle({
|
|
5753
|
+
* initial: { target: "Idle" },
|
|
5754
|
+
* states: {
|
|
5755
|
+
* Idle: { on: { Load: { target: "Loading" } } },
|
|
5756
|
+
* Loading: { invoke: { src: "load", onDone: { target: "Loaded", data: ({ output }) => ({ text: output }) } } }
|
|
5757
|
+
* }
|
|
5758
|
+
* })
|
|
5759
|
+
*
|
|
5760
|
+
* const self = { id: "loader", sessionId: "loader-1", send: () => Effect.void }
|
|
5761
|
+
* const step = Machine.toStep(machine, { self })
|
|
5762
|
+
*
|
|
5763
|
+
* const program = Effect.gen(function*() {
|
|
5764
|
+
* const started = yield* step.start()
|
|
5765
|
+
* const loading = yield* step.send(started.state, Events.Load())
|
|
5766
|
+
* const [work] = loading.start
|
|
5767
|
+
* if (work?._tag !== "Effect") return "no work"
|
|
5768
|
+
* const effect = work.effect()
|
|
5769
|
+
* if (Exit.isFailure(effect)) return "cannot start"
|
|
5770
|
+
* const loaded = step.settle(loading.state, work, yield* Effect.exit(effect.value))
|
|
5771
|
+
* return loaded.snapshot.state.path
|
|
5772
|
+
* })
|
|
5773
|
+
*
|
|
5774
|
+
* await Effect.runPromise(program) // => "Loaded"
|
|
5775
|
+
* ```
|
|
5776
|
+
*
|
|
5777
|
+
* **Example** (Starting work whose input mapper throws)
|
|
5778
|
+
*
|
|
5779
|
+
* ```ts import.meta.vitest
|
|
5780
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
5781
|
+
* import { Effect, Exit } from "effect"
|
|
5782
|
+
*
|
|
5783
|
+
* const machine = Machine.make({
|
|
5784
|
+
* root: Machine.state({ states: { Loading: {} } }),
|
|
5785
|
+
* events: Machine.events({}),
|
|
5786
|
+
* effects: { load: (_: string) => Effect.void }
|
|
5787
|
+
* }).handle({
|
|
5788
|
+
* initial: { target: "Loading" },
|
|
5789
|
+
* states: {
|
|
5790
|
+
* Loading: {
|
|
5791
|
+
* invoke: {
|
|
5792
|
+
* src: "load",
|
|
5793
|
+
* input: (): string => {
|
|
5794
|
+
* throw new Error("no input")
|
|
5795
|
+
* },
|
|
5796
|
+
* onDone: { stay: true }
|
|
5797
|
+
* }
|
|
5798
|
+
* }
|
|
5799
|
+
* }
|
|
5800
|
+
* })
|
|
5801
|
+
*
|
|
5802
|
+
* const self = { id: "loader", sessionId: "loader-1", send: () => Effect.void }
|
|
5803
|
+
* const step = Machine.toStep(machine, { self })
|
|
5804
|
+
*
|
|
5805
|
+
* // An `Exit` is an Effect, so the step that starts the machine runs as one.
|
|
5806
|
+
* const started = Effect.runSync(step.start())
|
|
5807
|
+
* const [work] = started.start
|
|
5808
|
+
* // The step called no user code: the host evaluates work as it starts it.
|
|
5809
|
+
* const effect = work?._tag === "Effect" ? work.effect() : undefined
|
|
5810
|
+
* const failed = effect !== undefined && Exit.isFailure(effect) ? step.settle(started.state, work!, effect) : started
|
|
5811
|
+
*
|
|
5812
|
+
* failed.exit !== undefined && Exit.isFailure(failed.exit) // => true
|
|
5813
|
+
* ```
|
|
5814
|
+
*
|
|
5815
|
+
* @see {@link plan} for planning one event without work.
|
|
5816
|
+
* @category destructors
|
|
5817
|
+
* @since 0.48.0
|
|
5818
|
+
*/
|
|
5819
|
+
export declare const toStep: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, options: MachineStep.Options<Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>>) => MachineStep<Machine<States, Events, Input, UnhandledStates, E, R, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>>;
|
|
5370
5820
|
/**
|
|
5371
5821
|
* Creates advanced stateful process logic from explicit initialization and
|
|
5372
5822
|
* execution methods.
|
|
@@ -5399,9 +5849,9 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
5399
5849
|
* @since 0.4.0
|
|
5400
5850
|
*/
|
|
5401
5851
|
export declare const logic: <State, Event = never, Output = void, Error = never, Requirements = never, InitialError = never, InitialRequirements = never>(options: {
|
|
5402
|
-
/** The first state, or an Effect that produces it from the
|
|
5403
|
-
readonly initial: State | ((
|
|
5404
|
-
readonly run: (context: Logic.
|
|
5852
|
+
/** The first state, or an Effect that produces it from the initial context before `run` starts. */
|
|
5853
|
+
readonly initial: State | ((context: Logic.InitialContext<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
|
|
5854
|
+
readonly run: (context: Logic.RunContext<State, Event>) => Effect.Effect<Output, Error, Requirements>;
|
|
5405
5855
|
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError>;
|
|
5406
5856
|
/**
|
|
5407
5857
|
* Creates a typed descriptor for a complete child machine.
|
|
@@ -5444,8 +5894,8 @@ export declare const childAddress: <Event = never>(id: string) => ChildAddress<E
|
|
|
5444
5894
|
*
|
|
5445
5895
|
* **Gotchas**
|
|
5446
5896
|
*
|
|
5447
|
-
* This Effect requires
|
|
5448
|
-
* unique for the current parent until that child stops.
|
|
5897
|
+
* This Effect requires {@link MachineRuntime}, which only some hosts provide. A
|
|
5898
|
+
* named child id must be unique for the current parent until that child stops.
|
|
5449
5899
|
*
|
|
5450
5900
|
* Register logic in `make({ logic })` and use `invoke: { src, id, address, ...outcomes }` for children
|
|
5451
5901
|
* that start and stop with that state.
|
|
@@ -5460,26 +5910,43 @@ export declare const spawn: {
|
|
|
5460
5910
|
/**
|
|
5461
5911
|
* Sends an event to a named child process of the running machine.
|
|
5462
5912
|
*
|
|
5913
|
+
* **Details**
|
|
5914
|
+
*
|
|
5915
|
+
* With the descriptor of an invoked child machine, it requires only
|
|
5916
|
+
* {@link ChildMachineRuntime}, which `ClusterMachine` provides too. With a
|
|
5917
|
+
* child address, it requires {@link MachineRuntime}. When the addressed child
|
|
5918
|
+
* is a machine whose event schema refuses the event, fails with
|
|
5919
|
+
* {@link MachineSchemaDecodeError} and leaves the child running.
|
|
5920
|
+
*
|
|
5463
5921
|
* @category runtime
|
|
5464
5922
|
* @since 0.4.0
|
|
5465
5923
|
*/
|
|
5466
5924
|
export declare const sendTo: {
|
|
5467
|
-
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): Effect.Effect<void, StoppedError,
|
|
5468
|
-
<Address extends ChildAddress<never>>(id: Address, event: ChildAddress.Event<Address>): Effect.Effect<void, StoppedError, MachineRuntime>;
|
|
5925
|
+
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): Effect.Effect<void, StoppedError | MachineSchemaDecodeError, ChildMachineRuntime>;
|
|
5926
|
+
<Address extends ChildAddress<never>>(id: Address, event: ChildAddress.Event<Address>): Effect.Effect<void, StoppedError | MachineSchemaDecodeError, MachineRuntime>;
|
|
5469
5927
|
};
|
|
5470
5928
|
/**
|
|
5471
5929
|
* Stops a named child process of the running machine.
|
|
5472
5930
|
*
|
|
5931
|
+
* **Details**
|
|
5932
|
+
*
|
|
5933
|
+
* With the descriptor of an invoked child machine, it requires only
|
|
5934
|
+
* {@link ChildMachineRuntime}, which `ClusterMachine` provides too. With a
|
|
5935
|
+
* child address, it requires {@link MachineRuntime}.
|
|
5936
|
+
*
|
|
5473
5937
|
* @category runtime
|
|
5474
5938
|
* @since 0.4.0
|
|
5475
5939
|
*/
|
|
5476
5940
|
export declare const stopChild: {
|
|
5477
5941
|
<Event>(child: ChildAddress<Event>): Effect.Effect<void, never, MachineRuntime>;
|
|
5478
|
-
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never,
|
|
5942
|
+
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never, ChildMachineRuntime>;
|
|
5479
5943
|
};
|
|
5480
5944
|
/**
|
|
5481
5945
|
* Returns a stream of terminal lifecycle outcomes for a running machine.
|
|
5482
5946
|
*
|
|
5947
|
+
* Reads only the `changes` of the reference, so it works with a reference from
|
|
5948
|
+
* any host.
|
|
5949
|
+
*
|
|
5483
5950
|
* @category combinators
|
|
5484
5951
|
* @since 0.4.0
|
|
5485
5952
|
*/
|
|
@@ -5487,6 +5954,9 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
5487
5954
|
/**
|
|
5488
5955
|
* Waits for the first current or subsequent published snapshot matching a predicate.
|
|
5489
5956
|
*
|
|
5957
|
+
* Reads only the `changes` of the reference, so it works with a reference from
|
|
5958
|
+
* any host.
|
|
5959
|
+
*
|
|
5490
5960
|
* Use for external Effect coordination and tests. Prefer atom selectors for UI
|
|
5491
5961
|
* reads, invocation outcomes for workflow behavior, and `ref.join` for output.
|
|
5492
5962
|
* This observes state; it does not acknowledge or correlate a sent event.
|
|
@@ -5504,7 +5974,7 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
5504
5974
|
* **Example** (Waiting for a state with a timeout)
|
|
5505
5975
|
*
|
|
5506
5976
|
* ```ts import.meta.vitest
|
|
5507
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
5977
|
+
* import { LocalMachine, Machine } from "@typeonce/effect-machine"
|
|
5508
5978
|
* import { Effect } from "effect"
|
|
5509
5979
|
*
|
|
5510
5980
|
* const Events = Machine.events({ Finish: {} })
|
|
@@ -5519,7 +5989,7 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
5519
5989
|
* })
|
|
5520
5990
|
*
|
|
5521
5991
|
* const path = Effect.scoped(Effect.gen(function*() {
|
|
5522
|
-
* const ref = yield*
|
|
5992
|
+
* const ref = yield* LocalMachine.start(machine)
|
|
5523
5993
|
* yield* ref.send(Events.Finish())
|
|
5524
5994
|
* const ready = yield* Machine.waitFor(ref, ({ state }) => state.state.path === "Ready").pipe(Effect.timeout("5 seconds"))
|
|
5525
5995
|
* return ready.state.state.path
|
|
@@ -5536,166 +6006,4 @@ export declare const waitFor: {
|
|
|
5536
6006
|
<State, Event, Error, Output, Emitted, Narrowed extends RuntimeSnapshot<State, Error, Output>>(ref: MachineRef<State, Event, Error, Output, Emitted>, predicate: (snapshot: RuntimeSnapshot<State, Error, Output>) => snapshot is Narrowed): Effect.Effect<Narrowed, Error | StoppedError | Cause.NoSuchElementError>;
|
|
5537
6007
|
<State, Event, Error, Output, Emitted>(ref: MachineRef<State, Event, Error, Output, Emitted>, predicate: (snapshot: RuntimeSnapshot<State, Error, Output>) => boolean): Effect.Effect<RuntimeSnapshot<State, Error, Output>, Error | StoppedError | Cause.NoSuchElementError>;
|
|
5538
6008
|
};
|
|
5539
|
-
/**
|
|
5540
|
-
* Prepares a fresh machine without initializing it.
|
|
5541
|
-
*
|
|
5542
|
-
* Use this constructor when observation must be composed before initial-entry
|
|
5543
|
-
* actions run. Subscribe to `prepared.emissions`, then evaluate
|
|
5544
|
-
* `prepared.start`. Ordinary callers can continue to use {@link start}, which
|
|
5545
|
-
* starts directly and does not allocate the prepared lifecycle boundary.
|
|
5546
|
-
*
|
|
5547
|
-
* `prepared.start` is one-shot and scoped: the `Scope` that first evaluates it
|
|
5548
|
-
* owns the machine, and closing that `Scope` is equivalent to `ref.stop`.
|
|
5549
|
-
*
|
|
5550
|
-
* **Example** (Observing emissions before startup)
|
|
5551
|
-
*
|
|
5552
|
-
* ```ts import.meta.vitest
|
|
5553
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
5554
|
-
* import { Effect, Stream } from "effect"
|
|
5555
|
-
*
|
|
5556
|
-
* const Emitted = Machine.emittedEvents({ Started: {} })
|
|
5557
|
-
* const machine = Machine.make({
|
|
5558
|
-
* root: Machine.state({ states: { Idle: {} } }),
|
|
5559
|
-
* events: Machine.events({}),
|
|
5560
|
-
* emittedEvents: Emitted
|
|
5561
|
-
* }).handle({
|
|
5562
|
-
* initial: { target: "Idle" },
|
|
5563
|
-
* states: {
|
|
5564
|
-
* Idle: {
|
|
5565
|
-
* entry: (_, enqueue) => {
|
|
5566
|
-
* enqueue.emit(Emitted.Started())
|
|
5567
|
-
* }
|
|
5568
|
-
* }
|
|
5569
|
-
* }
|
|
5570
|
-
* })
|
|
5571
|
-
*
|
|
5572
|
-
* const emitted = Effect.scoped(Effect.gen(function*() {
|
|
5573
|
-
* const prepared = yield* Machine.prepare(machine)
|
|
5574
|
-
* const seen: Array<string> = []
|
|
5575
|
-
* yield* prepared.emissions.pipe(
|
|
5576
|
-
* Stream.runForEach((event) => Effect.sync(() => seen.push(event._tag))),
|
|
5577
|
-
* Effect.forkScoped({ startImmediately: true })
|
|
5578
|
-
* )
|
|
5579
|
-
* yield* prepared.start
|
|
5580
|
-
* yield* Effect.yieldNow
|
|
5581
|
-
* return seen
|
|
5582
|
-
* }))
|
|
5583
|
-
*
|
|
5584
|
-
* await Effect.runPromise(emitted) // => ["Started"]
|
|
5585
|
-
* ```
|
|
5586
|
-
*
|
|
5587
|
-
* @category constructors
|
|
5588
|
-
* @since 0.11.0
|
|
5589
|
-
*/
|
|
5590
|
-
export declare const prepare: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<Prepared<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Scope.Scope | ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmittedEventOf<Emits>>>>;
|
|
5591
|
-
/**
|
|
5592
|
-
* Starts a machine owned by the current `Scope`.
|
|
5593
|
-
*
|
|
5594
|
-
* **When to use**
|
|
5595
|
-
*
|
|
5596
|
-
* Use when you want asynchronous event delivery, lifecycle snapshots, `join`,
|
|
5597
|
-
* and machine-owned spawned or invoked children.
|
|
5598
|
-
*
|
|
5599
|
-
* **Details**
|
|
5600
|
-
*
|
|
5601
|
-
* For each accepted event the runtime plans the complete synchronous
|
|
5602
|
-
* macrostep, executes closed machine commands, stops invokes for exited states,
|
|
5603
|
-
* publishes the new state, delivers emitted events, and then starts invokes
|
|
5604
|
-
* for entered states.
|
|
5605
|
-
*
|
|
5606
|
-
* The machine is a scoped resource, like `Effect.forkScoped`. Closing the
|
|
5607
|
-
* `Scope` is equivalent to `ref.stop`: active invocations are interrupted,
|
|
5608
|
-
* owned children stop, the snapshot becomes `stopped`, and later sends fail
|
|
5609
|
-
* with `StoppedError`. An earlier `ref.stop` or terminal completion leaves the
|
|
5610
|
-
* finalizer with nothing to do. Own a `Scope` explicitly, for example with
|
|
5611
|
-
* `Scope.make` and `Scope.provide`, when the machine must outlive the caller.
|
|
5612
|
-
*
|
|
5613
|
-
* **Gotchas**
|
|
5614
|
-
*
|
|
5615
|
-
* The returned handle's `send` operation only enqueues events. Transition
|
|
5616
|
-
* failures are reported through the runtime snapshot, `changes`, and `join`
|
|
5617
|
-
* rather than being returned by `send`. Sending after the machine reaches any
|
|
5618
|
-
* terminal state fails immediately with `StoppedError`.
|
|
5619
|
-
*
|
|
5620
|
-
* **Example** (Starting a machine in a scope)
|
|
5621
|
-
*
|
|
5622
|
-
* ```ts import.meta.vitest
|
|
5623
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
5624
|
-
* import { Effect } from "effect"
|
|
5625
|
-
*
|
|
5626
|
-
* const States = Machine.state({ states: { Idle: {} } })
|
|
5627
|
-
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
5628
|
-
* initial: { target: "Idle" }
|
|
5629
|
-
* })
|
|
5630
|
-
*
|
|
5631
|
-
* const path = Effect.scoped(Effect.gen(function*() {
|
|
5632
|
-
* const ref = yield* Machine.start(machine)
|
|
5633
|
-
* return (yield* ref.state).state.path
|
|
5634
|
-
* }))
|
|
5635
|
-
*
|
|
5636
|
-
* await Effect.runPromise(path) // => "Idle"
|
|
5637
|
-
* ```
|
|
5638
|
-
*
|
|
5639
|
-
* @see {@link plan} for inspecting the same transition plan without executing it.
|
|
5640
|
-
* @see {@link watch} for classified terminal outcomes.
|
|
5641
|
-
* @category constructors
|
|
5642
|
-
* @since 0.4.0
|
|
5643
|
-
*/
|
|
5644
|
-
export declare const start: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Scope.Scope | ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmittedEventOf<Emits>>>;
|
|
5645
|
-
/**
|
|
5646
|
-
* Starts a fresh managed runtime from a decoded logical snapshot, owned by the
|
|
5647
|
-
* current `Scope`.
|
|
5648
|
-
*
|
|
5649
|
-
* **Details**
|
|
5650
|
-
*
|
|
5651
|
-
* The resumed machine has the same scoped lifetime as {@link start}: closing
|
|
5652
|
-
* the `Scope` is equivalent to `ref.stop`.
|
|
5653
|
-
*
|
|
5654
|
-
* `resume` validates and normalizes the supplied snapshot before publishing it
|
|
5655
|
-
* as the first state. It does not construct the declared initial state, replay
|
|
5656
|
-
* entry or transition actions, re-deliver raised or emitted events, or
|
|
5657
|
-
* re-evaluate historical completion and eventless transitions. Active-state
|
|
5658
|
-
* invokes start once in ancestor and document order with {@link InitialEvent};
|
|
5659
|
-
* timer invocations restart their complete duration and child-machine
|
|
5660
|
-
* invocations start from their own initial state.
|
|
5661
|
-
*
|
|
5662
|
-
* Only logical state, completion, and history metadata are resumed. Queues,
|
|
5663
|
-
* scopes, subscriptions, fibers, spawned children, invoke progress, and prior
|
|
5664
|
-
* runtime status are process-local and are not restored. A final snapshot
|
|
5665
|
-
* immediately produces a completed ref with its current-machine output.
|
|
5666
|
-
*
|
|
5667
|
-
* Decode encoded data explicitly with {@link decodeSnapshot} before calling
|
|
5668
|
-
* this function. Stable snapshots are hosted as supplied; newly enabled
|
|
5669
|
-
* eventless or completion transitions in a changed machine definition are not
|
|
5670
|
-
* evaluated merely because the runtime was resumed; only ordinary subsequent
|
|
5671
|
-
* transition planning can enter and stabilize states.
|
|
5672
|
-
*
|
|
5673
|
-
* **Example** (Resuming from a decoded snapshot)
|
|
5674
|
-
*
|
|
5675
|
-
* ```ts import.meta.vitest
|
|
5676
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
5677
|
-
* import { Effect } from "effect"
|
|
5678
|
-
*
|
|
5679
|
-
* const States = Machine.state({ states: { Idle: {} } })
|
|
5680
|
-
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
5681
|
-
* initial: { target: "Idle" }
|
|
5682
|
-
* })
|
|
5683
|
-
*
|
|
5684
|
-
* const path = Effect.scoped(Effect.gen(function*() {
|
|
5685
|
-
* const initial = yield* Machine.planInitial(machine)
|
|
5686
|
-
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
5687
|
-
* const snapshot = yield* Machine.decodeSnapshot(machine, encoded)
|
|
5688
|
-
* const ref = yield* Machine.resume(machine, snapshot)
|
|
5689
|
-
* return (yield* ref.state).state.path
|
|
5690
|
-
* }))
|
|
5691
|
-
*
|
|
5692
|
-
* await Effect.runPromise(path) // => "Idle"
|
|
5693
|
-
* ```
|
|
5694
|
-
*
|
|
5695
|
-
* @see {@link decodeSnapshot} for the schema and transport boundary.
|
|
5696
|
-
* @see {@link start} for ordinary initial startup.
|
|
5697
|
-
* @category constructors
|
|
5698
|
-
* @since 0.4.0
|
|
5699
|
-
*/
|
|
5700
|
-
export declare const resume: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, snapshot: Machine.Snapshot<States>) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>>, MachineSchemaDecodeError, Scope.Scope | ExcludeCompatibleRuntime<ExecutionServices<R>, Machine.EventOf<Events>, Machine.EmittedEventOf<Emits>>>;
|
|
5701
6009
|
//# sourceMappingURL=Machine.d.ts.map
|