@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
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-neutral meaning of what invoked work reports.
|
|
3
|
+
*
|
|
4
|
+
* Every function is synchronous and decides for the moment it is called, so a
|
|
5
|
+
* host asks in the turn that would deliver the result and then performs the
|
|
6
|
+
* decision: it plans a delivered event through its own mailbox, fails its
|
|
7
|
+
* machine, or does nothing.
|
|
8
|
+
*
|
|
9
|
+
* @since 0.47.2
|
|
10
|
+
*/
|
|
11
|
+
import * as Cause from "effect/Cause";
|
|
12
|
+
import * as Exit from "effect/Exit";
|
|
13
|
+
import * as InvocationEvent from "./invocationEvent.js";
|
|
14
|
+
import type { ResolvedInvocation, StreamInvocation } from "./invocationResolution.js";
|
|
15
|
+
/**
|
|
16
|
+
* How invoked work ended. `Stopped` means its host stopped it.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type Outcome = {
|
|
21
|
+
readonly _tag: "Done";
|
|
22
|
+
readonly output: unknown;
|
|
23
|
+
} | {
|
|
24
|
+
readonly _tag: "Failure";
|
|
25
|
+
readonly error: unknown;
|
|
26
|
+
readonly cause: Cause.Cause<unknown>;
|
|
27
|
+
} | {
|
|
28
|
+
readonly _tag: "Defect" | "Interrupted" | "Cause";
|
|
29
|
+
readonly cause: Cause.Cause<unknown>;
|
|
30
|
+
} | {
|
|
31
|
+
readonly _tag: "Stopped";
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Plan this event on the owning machine.
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
export interface Deliver {
|
|
39
|
+
readonly _tag: "Deliver";
|
|
40
|
+
readonly event: InvocationEvent.InvocationEvent;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Fail the owning machine with this cause.
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export interface Fail {
|
|
48
|
+
readonly _tag: "Fail";
|
|
49
|
+
readonly cause: Cause.Cause<unknown>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Discard the report.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export interface Ignore {
|
|
57
|
+
readonly _tag: "Ignore";
|
|
58
|
+
}
|
|
59
|
+
/** @internal */
|
|
60
|
+
export type Decision = Deliver | Fail | Ignore;
|
|
61
|
+
/**
|
|
62
|
+
* The outcome of work a host ran as an effect. A typed failure takes precedence
|
|
63
|
+
* over the other reasons of its cause, as it does for a local process. A host
|
|
64
|
+
* that interrupts the work itself reports `Stopped` instead.
|
|
65
|
+
*
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
export declare const fromExit: (exit: Exit.Exit<unknown, unknown>) => Outcome;
|
|
69
|
+
/**
|
|
70
|
+
* Decides what the end of invoked work means to the machine that owns it.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export declare const decide: (invocation: ResolvedInvocation, generation: InvocationEvent.Generation, outcome: Outcome) => Decision;
|
|
75
|
+
/**
|
|
76
|
+
* Decides what an active snapshot of invoked work means to its owner.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export declare const decideSnapshot: (invocation: ResolvedInvocation, generation: InvocationEvent.Generation, snapshot: unknown) => Deliver | Ignore;
|
|
81
|
+
/**
|
|
82
|
+
* Decides what a stream element means to the owner of its stream. An element is
|
|
83
|
+
* delivered even when `onElement` is not declared: the owner's acknowledgement
|
|
84
|
+
* paces the stream. A host stops pulling a stream whose element is ignored.
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export declare const decideElement: (invocation: StreamInvocation, generation: InvocationEvent.Generation, element: unknown) => Deliver | Ignore;
|
|
89
|
+
//# sourceMappingURL=invocationOutcome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocationOutcome.d.ts","sourceRoot":"","sources":["../../../src/internal/machine/invocationOutcome.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,IAAI,MA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AAC,KAAG,OAM5D,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,GACjB,YAAY,kBAAkB,EAC9B,YAAY,eAAe,CAAC,UAAU,EACtC,SAAS,OAAO,KACf,QAoBF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,YAAY,kBAAkB,EAC9B,YAAY,eAAe,CAAC,UAAU,EACtC,UAAU,OAAO,KAChB,OAAO,GAAG,MAGD,CAAA;AAEZ;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GACxB,YAAY,gBAAgB,EAC5B,YAAY,eAAe,CAAC,UAAU,EACtC,SAAS,OAAO,KACf,OAAO,GAAG,MAGD,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-neutral meaning of what invoked work reports.
|
|
3
|
+
*
|
|
4
|
+
* Every function is synchronous and decides for the moment it is called, so a
|
|
5
|
+
* host asks in the turn that would deliver the result and then performs the
|
|
6
|
+
* decision: it plans a delivered event through its own mailbox, fails its
|
|
7
|
+
* machine, or does nothing.
|
|
8
|
+
*
|
|
9
|
+
* @since 0.47.2
|
|
10
|
+
*/
|
|
11
|
+
import * as Cause from "effect/Cause";
|
|
12
|
+
import * as Exit from "effect/Exit";
|
|
13
|
+
import { InfiniteTransitionError, MachineSchemaDecodeError, StoppedError } from "./errors.js";
|
|
14
|
+
import * as InvocationEvent from "./invocationEvent.js";
|
|
15
|
+
const ignore = Object.freeze({ _tag: "Ignore" });
|
|
16
|
+
const deliver = (event) => ({ _tag: "Deliver", event });
|
|
17
|
+
const fail = (cause) => ({ _tag: "Fail", cause });
|
|
18
|
+
// A framework failure of a child machine is not one of its declared errors.
|
|
19
|
+
const isFrameworkFailure = (error) => error instanceof InfiniteTransitionError || error instanceof MachineSchemaDecodeError || error instanceof StoppedError;
|
|
20
|
+
/**
|
|
21
|
+
* The outcome of work a host ran as an effect. A typed failure takes precedence
|
|
22
|
+
* over the other reasons of its cause, as it does for a local process. A host
|
|
23
|
+
* that interrupts the work itself reports `Stopped` instead.
|
|
24
|
+
*
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
export const fromExit = (exit) => {
|
|
28
|
+
if (Exit.isSuccess(exit))
|
|
29
|
+
return { _tag: "Done", output: exit.value };
|
|
30
|
+
const failure = exit.cause.reasons.find(Cause.isFailReason);
|
|
31
|
+
return failure === undefined
|
|
32
|
+
? { _tag: "Cause", cause: exit.cause }
|
|
33
|
+
: { _tag: "Failure", error: failure.error, cause: exit.cause };
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Decides what the end of invoked work means to the machine that owns it.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export const decide = (invocation, generation, outcome) => {
|
|
41
|
+
if (outcome._tag === "Stopped" || !generation.current)
|
|
42
|
+
return ignore;
|
|
43
|
+
switch (outcome._tag) {
|
|
44
|
+
case "Done":
|
|
45
|
+
return invocation.channels.done
|
|
46
|
+
? deliver(InvocationEvent.done(invocation.path, invocation.id, generation, outcome.output))
|
|
47
|
+
: fail(Cause.die(new Error(`Invocation "${invocation.id}" completed without the required onDone handler`)));
|
|
48
|
+
case "Failure":
|
|
49
|
+
return invocation.channels.failure && (invocation._tag !== "Child" || !isFrameworkFailure(outcome.error))
|
|
50
|
+
? deliver(InvocationEvent.failure(invocation.path, invocation.id, generation, outcome.error))
|
|
51
|
+
: fail(outcome.cause);
|
|
52
|
+
case "Defect":
|
|
53
|
+
case "Interrupted":
|
|
54
|
+
case "Cause":
|
|
55
|
+
return fail(outcome.cause);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Decides what an active snapshot of invoked work means to its owner.
|
|
60
|
+
*
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export const decideSnapshot = (invocation, generation, snapshot) => invocation.channels.snapshot && generation.current
|
|
64
|
+
? deliver(InvocationEvent.snapshot(invocation.path, invocation.id, generation, snapshot))
|
|
65
|
+
: ignore;
|
|
66
|
+
/**
|
|
67
|
+
* Decides what a stream element means to the owner of its stream. An element is
|
|
68
|
+
* delivered even when `onElement` is not declared: the owner's acknowledgement
|
|
69
|
+
* paces the stream. A host stops pulling a stream whose element is ignored.
|
|
70
|
+
*
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
export const decideElement = (invocation, generation, element) => generation.current
|
|
74
|
+
? deliver(InvocationEvent.element(invocation.path, invocation.id, generation, element))
|
|
75
|
+
: ignore;
|
|
76
|
+
//# sourceMappingURL=invocationOutcome.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocationOutcome.js","sourceRoot":"","sources":["../../../src/internal/machine/invocationOutcome.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC7F,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AA8CvD,MAAM,MAAM,GAAW,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;AAExD,MAAM,OAAO,GAAG,CAAC,KAAsC,EAAW,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAA;AAEjG,MAAM,IAAI,GAAG,CAAC,KAA2B,EAAQ,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;AAE7E,4EAA4E;AAC5E,MAAM,kBAAkB,GAAG,CAAC,KAAc,EAAW,EAAE,CACrD,KAAK,YAAY,uBAAuB,IAAI,KAAK,YAAY,wBAAwB,IAAI,KAAK,YAAY,YAAY,CAAA;AAExH;;;;;;GAMG;AACH,MAAM,CAAC,MA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AkB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBACvG,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;gBAC7F,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACzB,KAAK,QAAQ,CAAC;QACd,KAAK,aAAa,CAAC;QACnB,KAAK,OAAO;YACV,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC9B,CAAC;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,UAA8B,EAC9B,UAAsC,EACtC,QAAiB,EACC,EAAE,CACpB,UAAU,CAAC,QAAQ,CAAC,QAAQ,IAAI,UAAU,CAAC,OAAO;IAChD,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IACzF,CAAC,CAAC,MAAM,CAAA;AAEZ;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,UAA4B,EAC5B,UAAsC,EACtC,OAAgB,EACE,EAAE,CACpB,UAAU,CAAC,OAAO;IAChB,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IACvF,CAAC,CAAC,MAAM,CAAA"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-neutral resolution of the work owned by entered states.
|
|
3
|
+
*
|
|
4
|
+
* `resolve` answers which invocations a step starts, in which order, and what
|
|
5
|
+
* each one is. It runs nothing. `step.ts` is its one caller: it resolves the
|
|
6
|
+
* work of entered states against the configuration the step settled in, stops
|
|
7
|
+
* the work of exited paths before it starts the work of entered ones, evaluates
|
|
8
|
+
* each lazy source at most once per start, and routes what the work reports
|
|
9
|
+
* through `InvocationOutcome`. Every host, the local runtime included, starts
|
|
10
|
+
* and owns the work that a step lists.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.47.2
|
|
13
|
+
*/
|
|
14
|
+
import * as Duration from "effect/Duration";
|
|
15
|
+
import type * as Effect from "effect/Effect";
|
|
16
|
+
import type * as Stream from "effect/Stream";
|
|
17
|
+
import type { ChildMachine, ChildOwner, Logic, Machine, MachineTarget } from "../../Machine.js";
|
|
18
|
+
import * as Configuration from "./configuration.js";
|
|
19
|
+
/**
|
|
20
|
+
* Outcome channels an invocation declares a transition for.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface OutcomeChannels {
|
|
25
|
+
readonly done: boolean;
|
|
26
|
+
readonly failure: boolean;
|
|
27
|
+
readonly element: boolean;
|
|
28
|
+
readonly snapshot: boolean;
|
|
29
|
+
}
|
|
30
|
+
interface Base {
|
|
31
|
+
/** Path of the state that owns the invocation. */
|
|
32
|
+
readonly path: string;
|
|
33
|
+
/** Lifecycle id that routes the invocation's outcomes within its state. */
|
|
34
|
+
readonly id: string;
|
|
35
|
+
readonly channels: OutcomeChannels;
|
|
36
|
+
}
|
|
37
|
+
interface NamedBase extends Base {
|
|
38
|
+
/** Name the source is registered with, when it has one. */
|
|
39
|
+
readonly sourceName: string | undefined;
|
|
40
|
+
}
|
|
41
|
+
/** @internal */
|
|
42
|
+
export interface EffectInvocation extends NamedBase {
|
|
43
|
+
readonly _tag: "Effect";
|
|
44
|
+
/** Constructs the effect with its input applied. */
|
|
45
|
+
readonly effect: () => Effect.Effect<unknown, unknown, unknown>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A timer completes with `undefined` once its duration has elapsed.
|
|
49
|
+
*
|
|
50
|
+
* `duration` is lazy because a parameterized timer runs its input mapper and
|
|
51
|
+
* source function. It throws when the timer cannot start: when either throws,
|
|
52
|
+
* and when the input names no duration. A throw belongs to the host's startup
|
|
53
|
+
* boundary, so a timer that cannot start fails in one way.
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export interface TimerInvocation extends NamedBase {
|
|
58
|
+
readonly _tag: "Timer";
|
|
59
|
+
readonly duration: () => Duration.Duration;
|
|
60
|
+
}
|
|
61
|
+
/** @internal */
|
|
62
|
+
export interface StreamInvocation extends NamedBase {
|
|
63
|
+
readonly _tag: "Stream";
|
|
64
|
+
/** Constructs the stream with its input applied. */
|
|
65
|
+
readonly stream: () => Stream.Stream<unknown, unknown, unknown>;
|
|
66
|
+
}
|
|
67
|
+
/** @internal */
|
|
68
|
+
export interface LogicInvocation extends NamedBase {
|
|
69
|
+
readonly _tag: "Logic";
|
|
70
|
+
/** Caller-chosen address of the started process within its owner. */
|
|
71
|
+
readonly address: string;
|
|
72
|
+
/** Constructs the logic with its input applied. */
|
|
73
|
+
readonly logic: () => Logic<any, any, any, any, any>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A child machine is named by its descriptor rather than by its source.
|
|
77
|
+
*
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
export interface ChildInvocation extends Base {
|
|
81
|
+
readonly _tag: "Child";
|
|
82
|
+
readonly child: ChildMachine.Any;
|
|
83
|
+
/** Constructs the child's input, or `undefined` when none is declared. */
|
|
84
|
+
readonly input: (() => unknown) | undefined;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* One invocation to start, described without any host capability.
|
|
88
|
+
*
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export type ResolvedInvocation = EffectInvocation | TimerInvocation | StreamInvocation | LogicInvocation | ChildInvocation;
|
|
92
|
+
/**
|
|
93
|
+
* The invocations started by one entry of a state, in start order. They share
|
|
94
|
+
* one generation.
|
|
95
|
+
*
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
export interface InvocationGroup {
|
|
99
|
+
readonly path: string;
|
|
100
|
+
readonly invocations: ReadonlyArray<ResolvedInvocation>;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Host capabilities exposed to input mappers.
|
|
104
|
+
*
|
|
105
|
+
* @internal
|
|
106
|
+
*/
|
|
107
|
+
export interface InvocationCapabilities {
|
|
108
|
+
readonly self: MachineTarget<any>;
|
|
109
|
+
readonly parent?: MachineTarget<any> | undefined;
|
|
110
|
+
readonly children: ChildOwner<any>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Resolves the invocations started by the states a step entered.
|
|
114
|
+
*
|
|
115
|
+
* Groups follow the planner's entry order and contain only paths active in the
|
|
116
|
+
* configuration. Invocations keep their declaration order. A state without
|
|
117
|
+
* invocations has no group.
|
|
118
|
+
*
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
export declare const resolve: (machine: Machine.Any, configuration: Configuration.ActiveConfiguration, entryPaths: ReadonlyArray<string>, event: Machine.LifecycleEvent<any>, capabilities: InvocationCapabilities | (() => InvocationCapabilities)) => ReadonlyArray<InvocationGroup>;
|
|
122
|
+
/**
|
|
123
|
+
* Resolves the groups started by several entries of one step, in start order:
|
|
124
|
+
* each entry's groups follow `resolve`, and entries keep their order.
|
|
125
|
+
*
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
export declare const resolveEntries: (machine: Machine.Any, configuration: Configuration.ActiveConfiguration, entries: Iterable<readonly [ReadonlyArray<string>, Machine.LifecycleEvent<any>]>, capabilities: InvocationCapabilities | (() => InvocationCapabilities)) => ReadonlyArray<InvocationGroup>;
|
|
129
|
+
/**
|
|
130
|
+
* The entries a machine starts in: every active path of the configuration,
|
|
131
|
+
* entered with `InitialEvent`, as when a machine starts or resumes.
|
|
132
|
+
*
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
135
|
+
export declare const initialEntries: (machine: Machine.Any, configuration: Configuration.ActiveConfiguration) => ReadonlyArray<readonly [ReadonlyArray<string>, Machine.LifecycleEvent<any>]>;
|
|
136
|
+
export {};
|
|
137
|
+
//# sourceMappingURL=invocationResolution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocationResolution.d.ts","sourceRoot":"","sources":["../../../src/internal/machine/invocationResolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAE/F,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AAGnD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;CAC3B;AAED,UAAU,IAAI;IACZ,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;CACnC;AAED,UAAU,SAAU,SAAQ,IAAI;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CACxC;AAED,gBAAgB;AAChB,MAAM,WAAW,gBAAiB,SAAQ,SAAS;IACjD,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,oDAAoD;IACpD,QAAQ,CAAC,MAA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ts, in which order, and what
|
|
5
|
+
* each one is. It runs nothing. `step.ts` is its one caller: it resolves the
|
|
6
|
+
* work of entered states against the configuration the step settled in, stops
|
|
7
|
+
* the work of exited paths before it starts the work of entered ones, evaluates
|
|
8
|
+
* each lazy source at most once per start, and routes what the work reports
|
|
9
|
+
* through `InvocationOutcome`. Every host, the local runtime included, starts
|
|
10
|
+
* and owns the work that a step lists.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.47.2
|
|
13
|
+
*/
|
|
14
|
+
import * as Duration from "effect/Duration";
|
|
15
|
+
import * as CapturedInvocation from "./capturedInvocation.js";
|
|
16
|
+
import * as Configuration from "./configuration.js";
|
|
17
|
+
import * as Planner from "./planner.js";
|
|
18
|
+
const channelCombinations = Array.from({ length: 16 }, (_, bits) => Object.freeze({
|
|
19
|
+
done: (bits & 1) !== 0,
|
|
20
|
+
failure: (bits & 2) !== 0,
|
|
21
|
+
element: (bits & 4) !== 0,
|
|
22
|
+
snapshot: (bits & 8) !== 0
|
|
23
|
+
}));
|
|
24
|
+
// Descriptions live as long as the work they start, so equal channels share one
|
|
25
|
+
// immutable value.
|
|
26
|
+
const outcomeChannels = (definition) => channelCombinations[(definition.onDone === undefined ? 0 : 1) |
|
|
27
|
+
(definition.onFailure === undefined ? 0 : 2) |
|
|
28
|
+
(definition.onElement === undefined ? 0 : 4) |
|
|
29
|
+
(definition.onSnapshot === undefined ? 0 : 8)];
|
|
30
|
+
const staticChildInvocations = new WeakMap();
|
|
31
|
+
// A child without input does not depend on its entry context, so neither
|
|
32
|
+
// building nor retaining one is worthwhile.
|
|
33
|
+
const resolveChild = (definition, path, input) => ({
|
|
34
|
+
_tag: "Child",
|
|
35
|
+
path,
|
|
36
|
+
id: CapturedInvocation.lifecycleId(definition),
|
|
37
|
+
channels: outcomeChannels(definition),
|
|
38
|
+
child: definition.child,
|
|
39
|
+
input
|
|
40
|
+
});
|
|
41
|
+
const resolveStaticChild = (definition, path) => {
|
|
42
|
+
const cached = staticChildInvocations.get(definition);
|
|
43
|
+
if (cached !== undefined && cached.path === path)
|
|
44
|
+
return cached;
|
|
45
|
+
const resolved = resolveChild(definition, path, undefined);
|
|
46
|
+
if (cached === undefined)
|
|
47
|
+
staticChildInvocations.set(definition, resolved);
|
|
48
|
+
return resolved;
|
|
49
|
+
};
|
|
50
|
+
const resolveDefinition = (definition, path, context) => {
|
|
51
|
+
const id = CapturedInvocation.lifecycleId(definition);
|
|
52
|
+
const sourceName = definition.sourceName;
|
|
53
|
+
const channels = outcomeChannels(definition);
|
|
54
|
+
if ("effect" in definition) {
|
|
55
|
+
return { _tag: "Effect", path, id, sourceName, channels, effect: () => definition.effect(context) };
|
|
56
|
+
}
|
|
57
|
+
if ("after" in definition) {
|
|
58
|
+
return {
|
|
59
|
+
_tag: "Timer",
|
|
60
|
+
path,
|
|
61
|
+
id,
|
|
62
|
+
sourceName,
|
|
63
|
+
channels,
|
|
64
|
+
duration: () => Duration.fromInputUnsafe(typeof definition.after === "function" ? definition.after(context) : definition.after)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if ("stream" in definition) {
|
|
68
|
+
return { _tag: "Stream", path, id, sourceName, channels, stream: () => definition.stream(context) };
|
|
69
|
+
}
|
|
70
|
+
if ("logic" in definition) {
|
|
71
|
+
return {
|
|
72
|
+
_tag: "Logic",
|
|
73
|
+
path,
|
|
74
|
+
id,
|
|
75
|
+
sourceName,
|
|
76
|
+
channels,
|
|
77
|
+
address: definition.address,
|
|
78
|
+
logic: () => typeof definition.logic === "function" ? definition.logic(context) : definition.logic
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if ("child" in definition) {
|
|
82
|
+
return resolveChild(definition, path, () => typeof definition.input === "function" ? definition.input(context) : definition.input);
|
|
83
|
+
}
|
|
84
|
+
const unsupported = definition;
|
|
85
|
+
throw new Error(`Unsupported captured machine invocation: ${String(unsupported)}`);
|
|
86
|
+
};
|
|
87
|
+
const noGroups = [];
|
|
88
|
+
/**
|
|
89
|
+
* Resolves the invocations started by the states a step entered.
|
|
90
|
+
*
|
|
91
|
+
* Groups follow the planner's entry order and contain only paths active in the
|
|
92
|
+
* configuration. Invocations keep their declaration order. A state without
|
|
93
|
+
* invocations has no group.
|
|
94
|
+
*
|
|
95
|
+
* @internal
|
|
96
|
+
*/
|
|
97
|
+
export const resolve = (machine, configuration, entryPaths, event, capabilities) => {
|
|
98
|
+
let groups;
|
|
99
|
+
let resolvedCapabilities;
|
|
100
|
+
const ordered = entryPaths.length <= 1 ? entryPaths : Planner.sortEntryPaths(machine, entryPaths);
|
|
101
|
+
for (const path of ordered) {
|
|
102
|
+
if (!configuration.active.has(path))
|
|
103
|
+
continue;
|
|
104
|
+
const definitions = CapturedInvocation.list(Configuration.getStateConfigByPath(machine, path)?.invoke);
|
|
105
|
+
if (definitions.length === 0)
|
|
106
|
+
continue;
|
|
107
|
+
let context;
|
|
108
|
+
(groups ??= []).push({
|
|
109
|
+
path,
|
|
110
|
+
invocations: definitions.map((definition) => "child" in definition && !("input" in definition)
|
|
111
|
+
? resolveStaticChild(definition, path)
|
|
112
|
+
: resolveDefinition(definition, path, context ??= {
|
|
113
|
+
...(resolvedCapabilities ??= typeof capabilities === "function" ? capabilities() : capabilities),
|
|
114
|
+
state: configuration.values.get(path),
|
|
115
|
+
containingState: Configuration.getParentValue(machine, configuration, path),
|
|
116
|
+
ancestors: Configuration.getParentValues(machine, configuration, path),
|
|
117
|
+
event
|
|
118
|
+
}))
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return groups ?? noGroups;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Resolves the groups started by several entries of one step, in start order:
|
|
125
|
+
* each entry's groups follow `resolve`, and entries keep their order.
|
|
126
|
+
*
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
export const resolveEntries = (machine, configuration, entries, capabilities) => {
|
|
130
|
+
let groups;
|
|
131
|
+
let resolvedCapabilities;
|
|
132
|
+
const getCapabilities = () => resolvedCapabilities ??= typeof capabilities === "function" ? capabilities() : capabilities;
|
|
133
|
+
for (const [paths, event] of entries) {
|
|
134
|
+
const resolved = resolve(machine, configuration, paths, event, getCapabilities);
|
|
135
|
+
if (resolved.length > 0)
|
|
136
|
+
(groups ??= []).push(...resolved);
|
|
137
|
+
}
|
|
138
|
+
return groups ?? noGroups;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* The entries a machine starts in: every active path of the configuration,
|
|
142
|
+
* entered with `InitialEvent`, as when a machine starts or resumes.
|
|
143
|
+
*
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
export const initialEntries = (machine, configuration) => [[
|
|
147
|
+
Configuration.getInitialEntryPaths(machine, configuration),
|
|
148
|
+
Planner.InitialEvent
|
|
149
|
+
]];
|
|
150
|
+
//# sourceMappingURL=invocationResolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invocationResolution.js","sourceRoot":"","sources":["../../../src/internal/machine/invocationResolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAI3C,OAAO,KAAK,kBAAkB,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AA+GvC,MAAM,mBAAmB,GAAmC,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CACjG,MAAM,CAAC,MAAM,CAAC;IACZ,IAAI,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC;IACtB,OAAO,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC;IACzB,OAAO,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC;IACzB,QAAQ,EAAE,CAAC,IAAI,GAAG,CAAC,C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AAY,CAAA;IAC7F,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,CAAC,CAAA;QAC/E,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC;YAAE,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAA;IAC5D,CAAC;IACD,OAAO,MAAM,IAAI,QAAQ,CAAA;AAC3B,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,OAAoB,EACpB,aAAgD,EAC8B,EAAE,CAAC,CAAC;QAClF,aAAa,CAAC,oBAAoB,CAAC,OAAO,EAAE,aAAa,CAAC;QAC1D,OAAO,CAAC,YAAY;KACrB,CAAC,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Scope` that a `Logic` process owns, for every host that runs one.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.48.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
/** The members of process logic that run, whatever else a host attaches to it. */
|
|
8
|
+
interface Runnable {
|
|
9
|
+
initial(context: never): Effect.Effect<unknown, unknown, unknown>;
|
|
10
|
+
run(context: never): Effect.Effect<unknown, unknown, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Gives a `Logic` process one `Scope` from its `initial` through the end of its
|
|
14
|
+
* `run`. The scope is forked from the one that `initial` runs in, so a process
|
|
15
|
+
* stopped before its `run` starts is still released when that scope closes.
|
|
16
|
+
*
|
|
17
|
+
* Each call returns logic for one process: its `initial` and `run` share the
|
|
18
|
+
* scope of that process.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare const scoped: <L extends Runnable>(logic: L) => L;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=logicScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logicScope.d.ts","sourceRoot":"","sources":["../../../src/internal/machine/logicScope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAIvC,kFAAkF;AAClF,UAAU,QAAQ;IAChB,OAAO,CAAC,OAAO,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IACjE,GAAG,CAAC,OAAO,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;CAC9D;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,QAAQ,EAAE,OAAO,CAAC,KAAG,CAoBrD,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Scope` that a `Logic` process owns, for every host that runs one.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.48.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Exit from "effect/Exit";
|
|
8
|
+
import * as Scope from "effect/Scope";
|
|
9
|
+
/**
|
|
10
|
+
* Gives a `Logic` process one `Scope` from its `initial` through the end of its
|
|
11
|
+
* `run`. The scope is forked from the one that `initial` runs in, so a process
|
|
12
|
+
* stopped before its `run` starts is still released when that scope closes.
|
|
13
|
+
*
|
|
14
|
+
* Each call returns logic for one process: its `initial` and `run` share the
|
|
15
|
+
* scope of that process.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export const scoped = (logic) => {
|
|
20
|
+
let scope;
|
|
21
|
+
return {
|
|
22
|
+
...logic,
|
|
23
|
+
initial: (context) => Effect.flatMap(Effect.scope, (owner) => {
|
|
24
|
+
const own = scope = Scope.forkUnsafe(owner, "sequential");
|
|
25
|
+
return logic.initial(context).pipe(Scope.provide(own), Effect.onError((cause) => Scope.close(own, Exit.failCause(cause))));
|
|
26
|
+
}),
|
|
27
|
+
run: (context) => {
|
|
28
|
+
const own = scope;
|
|
29
|
+
return logic.run(context).pipe(Scope.provide(own), Effect.onExit((exit) => Scope.close(own, exit)));
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=logicScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logicScope.js","sourceRoot":"","sources":["../../../src/internal/machine/logicScope.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAQrC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAqB,KAAQ,EAAK,EAAE;IACxD,IAAI,KAAkC,CAAA;IACtC,OAAO;QACL,GAAG,KAAK;QACR,OAAO,EAAE,CAAC,OAAc,EAAE,EAAE,CAC1B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;YACrC,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;YACzD,OAAO,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAChC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAClB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CACnE,CAAA;QACH,CAAC,CAAC;QACJ,GAAG,EAAE,CAAC,OAAc,EAAE,EAAE;YACtB,MAAM,GAAG,GAAG,KAAM,CAAA;YAClB,OAAO,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAC5B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAClB,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAChD,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as Effect from "effect/Effect";
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
|
-
import type
|
|
4
|
-
import
|
|
3
|
+
import type { ChildAddress, ChildMachine, Logic, Machine, MachineSchemaDecodeError, MachineSchemaEncodeError, Parent, SpawnOptions, State, StoppedError } from "../../Machine.js";
|
|
4
|
+
import { ChildMachineRuntime, MachineRuntime } from "./capability.js";
|
|
5
5
|
import type { PlanningError, StartupError } from "./errors.js";
|
|
6
|
-
import * as
|
|
6
|
+
import * as Step from "./step.js";
|
|
7
|
+
export { child, childAddress, childFamily } from "./child.js";
|
|
7
8
|
export { ChildAlreadyExistsError, InfiniteTransitionError, MachineSchemaDecodeError, MachineSchemaEncodeError, ProcessLocalError, StartupError, StoppedError } from "./errors.js";
|
|
8
|
-
export { InitialEventTypeId } from "./symbols.js";
|
|
9
|
-
type MachineRuntimeRequirement = internalRuntime.MachineRuntime;
|
|
9
|
+
export { InitialEventTypeId, InvocationEventTypeId } from "./symbols.js";
|
|
10
10
|
export declare const isMachine: (u: unknown) => u is Machine.Any;
|
|
11
11
|
export declare const isFinal: (machine: Machine.Any, state: any) => state is any;
|
|
12
12
|
export declare const state: (node: unknown) => State<Machine.StateNodeConfig>;
|
|
@@ -40,7 +40,7 @@ export declare const stateNodes: <M extends Machine.Any>(machine: M) => Readonly
|
|
|
40
40
|
export declare const initialDefinition: <M extends Machine.Any>(machine: M) => Machine.InitialDefinition<Machine.RootStateIdentifier<Machine.StateIdentifier<Machine.States<M>>>>;
|
|
41
41
|
export declare const inputEventSchemas: <M extends Machine.Any>(machine: M) => Machine.InputEvents<M>;
|
|
42
42
|
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>>>>;
|
|
43
|
-
export declare const
|
|
43
|
+
export declare const invocationDefinitions: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.InvocationDefinition<Machine.StateIdentifier<Machine.States<M>>>>;
|
|
44
44
|
export declare const configuration: <M extends Machine.Any>(machine: M, state: Machine.Snapshot<Machine.States<M>>) => ReadonlyArray<Machine.ActiveStateNode<Machine.StateIdentifier<Machine.States<M>>, Machine.ChoiceIdentifier<Machine.States<M>>>>;
|
|
45
45
|
export declare const enabled: (machine: Machine.Any, state: any) => ReadonlyArray<any>;
|
|
46
46
|
export declare const can: {
|
|
@@ -48,25 +48,19 @@ export declare const can: {
|
|
|
48
48
|
(machine: Machine.Any, state: any, event: any): Effect.Effect<boolean, MachineSchemaDecodeError>;
|
|
49
49
|
};
|
|
50
50
|
export declare const plan: (machine: Machine.Any, state: any, event: any) => Effect.Effect<any, PlanningError>;
|
|
51
|
+
export declare const toStep: (machine: Machine.Any, options: Step.Options) => Step.MachineStep;
|
|
51
52
|
export declare const logic: <State, Event = never, Output = void, Error = never, Requirements = never, InitialError = never, InitialRequirements = never>(options: {
|
|
52
|
-
readonly initial: State | ((scope: Logic.
|
|
53
|
-
readonly run: (context: Logic.
|
|
53
|
+
readonly initial: State | ((scope: Logic.InitialContext<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
|
|
54
|
+
readonly run: (context: Logic.RunContext<State, Event>) => Effect.Effect<Output, Error, Requirements>;
|
|
54
55
|
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError>;
|
|
55
|
-
export declare const
|
|
56
|
-
export declare const child: <
|
|
57
|
-
export declare const
|
|
58
|
-
export declare const
|
|
59
|
-
export declare const spawn: (logic: Logic<any, any, any, any, any, any>, options?: SpawnOptions) => Effect.Effect<internalRuntime.MachineRef<any, any, any, any, never>, any, any>;
|
|
60
|
-
export declare const sendTo: (child: string | ChildMachine.Any, event: unknown) => Effect.Effect<void, StoppedError, MachineRuntimeRequirement>;
|
|
61
|
-
export declare const stopChild: (child: string | ChildMachine.Any) => Effect.Effect<void, never, MachineRuntimeRequirement>;
|
|
62
|
-
export declare const watch: <State, Event, Error = never, Output = never>(ref: MachineRef<State, Event, Error, Output>) => Stream.Stream<RuntimeOutcome<State, Error, Output>>;
|
|
56
|
+
export declare const spawn: (logic: Logic<any, any, any, any, any, any>, options?: SpawnOptions) => Effect.Effect<import("../../Machine.js").MachineRef<any, any, any, any, never>, any, any>;
|
|
57
|
+
export declare const sendTo: (child: ChildAddress<never> | ChildMachine.Any, event: unknown) => Effect.Effect<void, StoppedError | MachineSchemaDecodeError, MachineRuntime | ChildMachineRuntime>;
|
|
58
|
+
export declare const stopChild: (child: ChildAddress<never> | ChildMachine.Any) => Effect.Effect<void, never, MachineRuntime | ChildMachineRuntime>;
|
|
59
|
+
export declare const watch: <State, Event, Error = never, Output = never>(ref: import("../../Machine.js").MachineRef<State, Event, Error, Output>) => import("effect/Stream").Stream<import("../../Machine.js").RuntimeOutcome<State, Error, Output>>;
|
|
63
60
|
export declare const waitFor: {
|
|
64
|
-
<State, Error, Output, Narrowed extends import("../../Machine.js").RuntimeSnapshot<State, Error, Output>>(predicate: (snapshot: import("../../Machine.js").RuntimeSnapshot<State, Error, Output>) => snapshot is Narrowed): <Event, Emitted>(ref: MachineRef<State, Event, Error, Output, Emitted>) => Effect.Effect<Narrowed, Error | StoppedError | import("effect/Cause").NoSuchElementError>;
|
|
65
|
-
<State, Error, Output>(predicate: (snapshot: import("../../Machine.js").RuntimeSnapshot<State, Error, Output>) => boolean): <Event, Emitted>(ref: MachineRef<State, Event, Error, Output, Emitted>) => Effect.Effect<import("../../Machine.js").RuntimeSnapshot<State, Error, Output>, Error | StoppedError | import("effect/Cause").NoSuchElementError>;
|
|
66
|
-
<State, Event, Error, Output, Emitted, Narrowed extends import("../../Machine.js").RuntimeSnapshot<State, Error, Output>>(ref: MachineRef<State, Event, Error, Output, Emitted>, predicate: (snapshot: import("../../Machine.js").RuntimeSnapshot<State, Error, Output>) => snapshot is Narrowed): Effect.Effect<Narrowed, Error | StoppedError | import("effect/Cause").NoSuchElementError>;
|
|
67
|
-
<State, Event, Error, Output, Emitted>(ref: MachineRef<State, Event, Error, Output, Emitted>, predicate: (snapshot: import("../../Machine.js").RuntimeSnapshot<State, Error, Output>) => boolean): Effect.Effect<import("../../Machine.js").RuntimeSnapshot<State, Error, Output>, Error | StoppedError | import("effect/Cause").NoSuchElementError>;
|
|
61
|
+
<State, Error, Output, Narrowed extends import("../../Machine.js").RuntimeSnapshot<State, Error, Output>>(predicate: (snapshot: import("../../Machine.js").RuntimeSnapshot<State, Error, Output>) => snapshot is Narrowed): <Event, Emitted>(ref: import("../../Machine.js").MachineRef<State, Event, Error, Output, Emitted>) => Effect.Effect<Narrowed, Error | StoppedError | import("effect/Cause").NoSuchElementError>;
|
|
62
|
+
<State, Error, Output>(predicate: (snapshot: import("../../Machine.js").RuntimeSnapshot<State, Error, Output>) => boolean): <Event, Emitted>(ref: import("../../Machine.js").MachineRef<State, Event, Error, Output, Emitted>) => Effect.Effect<import("../../Machine.js").RuntimeSnapshot<State, Error, Output>, Error | StoppedError | import("effect/Cause").NoSuchElementError>;
|
|
63
|
+
<State, Event, Error, Output, Emitted, Narrowed extends import("../../Machine.js").RuntimeSnapshot<State, Error, Output>>(ref: import("../../Machine.js").MachineRef<State, Event, Error, Output, Emitted>, predicate: (snapshot: import("../../Machine.js").RuntimeSnapshot<State, Error, Output>) => snapshot is Narrowed): Effect.Effect<Narrowed, Error | StoppedError | import("effect/Cause").NoSuchElementError>;
|
|
64
|
+
<State, Event, Error, Output, Emitted>(ref: import("../../Machine.js").MachineRef<State, Event, Error, Output, Emitted>, predicate: (snapshot: import("../../Machine.js").RuntimeSnapshot<State, Error, Output>) => boolean): Effect.Effect<import("../../Machine.js").RuntimeSnapshot<State, Error, Output>, Error | StoppedError | import("effect/Cause").NoSuchElementError>;
|
|
68
65
|
};
|
|
69
|
-
export declare const prepare: (machine: Machine.Any, ...args: ReadonlyArray<any>) => Effect.Effect<internalRuntime.PreparedProcess<any, any, any, any, any, any, any>>;
|
|
70
|
-
export declare const start: (machine: Machine.Any, ...args: ReadonlyArray<any>) => Effect.Effect<MachineRef<any, any, any, any, any>, any, any>;
|
|
71
|
-
export declare const resume: (machine: Machine.Any, snapshot: any) => Effect.Effect<MachineRef<any, any, any, any, any>, MachineSchemaDecodeError, any>;
|
|
72
66
|
//# sourceMappingURL=machine.d.ts.map
|