@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
|
@@ -25,6 +25,8 @@ interface MachineProtocolSchemas {
|
|
|
25
25
|
readonly emit: Schema.Top
|
|
26
26
|
readonly eventConstructors: ReadonlySet<object>
|
|
27
27
|
readonly emissionConstructors: ReadonlySet<object>
|
|
28
|
+
eventResultDecoder?: BoundaryResultDecoder
|
|
29
|
+
emitResultDecoder?: BoundaryResultDecoder
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
interface EventProtocolDefinition {
|
|
@@ -209,7 +211,10 @@ const makeEventConstruction = (
|
|
|
209
211
|
}
|
|
210
212
|
|
|
211
213
|
const isEventConstruction = (value: unknown): value is EventConstruction =>
|
|
212
|
-
typeof value === "object" &&
|
|
214
|
+
typeof value === "object" &&
|
|
215
|
+
value !== null &&
|
|
216
|
+
(value as { readonly [EventConstructionTypeId]?: unknown })[EventConstructionTypeId] === EventConstructionTypeId &&
|
|
217
|
+
eventConstructionDefinitions.has(value)
|
|
213
218
|
|
|
214
219
|
const eventConstructors = (
|
|
215
220
|
kind: Machine.EventProtocolKind,
|
|
@@ -447,13 +452,6 @@ const decodeEventConstructionSync = (
|
|
|
447
452
|
return event
|
|
448
453
|
}
|
|
449
454
|
|
|
450
|
-
export const decodeInput = <Input extends Schema.Top>(
|
|
451
|
-
machine: Machine.Any,
|
|
452
|
-
schema: Input,
|
|
453
|
-
value: unknown
|
|
454
|
-
): Effect.Effect<Input["Type"], MachineSchemaDecodeError> =>
|
|
455
|
-
decodeBoundary<Input["Type"]>(machine, schema, value, { boundary: "input" })
|
|
456
|
-
|
|
457
455
|
export const decodeEvent = <const Events extends ReadonlyArray<Machine.TaggedSchema>>(
|
|
458
456
|
machine: Machine.Any,
|
|
459
457
|
event: unknown
|
|
@@ -476,21 +474,53 @@ export const decodeEvent = <const Events extends ReadonlyArray<Machine.TaggedSch
|
|
|
476
474
|
)
|
|
477
475
|
}
|
|
478
476
|
|
|
477
|
+
const decodeEventWith = (
|
|
478
|
+
machine: Machine.Any,
|
|
479
|
+
protocol: MachineProtocolSchemas,
|
|
480
|
+
decoder: BoundaryResultDecoder,
|
|
481
|
+
event: unknown
|
|
482
|
+
): unknown => {
|
|
483
|
+
if (isEventConstruction(event)) {
|
|
484
|
+
return decodeEventConstructionSync(machine, protocol, event, "event")
|
|
485
|
+
}
|
|
486
|
+
const decoded = decoder(event)
|
|
487
|
+
if (Result.isFailure(decoded)) {
|
|
488
|
+
const eventName = getEventName(event)
|
|
489
|
+
throw new MachineSchemaDecodeError({
|
|
490
|
+
machineId: machine.id,
|
|
491
|
+
boundary: "event",
|
|
492
|
+
cause: decoded.failure,
|
|
493
|
+
...(eventName === undefined ? {} : { event: eventName })
|
|
494
|
+
})
|
|
495
|
+
}
|
|
496
|
+
return decoded.success
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export const makeEventDecoderSync = (
|
|
500
|
+
machine: Machine.Any
|
|
501
|
+
): (event: unknown) => Machine.EventOf<any> => {
|
|
502
|
+
const protocol = getProtocolSchemas(machine)
|
|
503
|
+
let decoder = protocol.eventResultDecoder
|
|
504
|
+
return (event: unknown) =>
|
|
505
|
+
decodeEventWith(
|
|
506
|
+
machine,
|
|
507
|
+
protocol,
|
|
508
|
+
decoder ??= protocol.eventResultDecoder ??= getBoundaryResultDecoder(protocol.event),
|
|
509
|
+
event
|
|
510
|
+
) as Machine.EventOf<any>
|
|
511
|
+
}
|
|
512
|
+
|
|
479
513
|
export const decodeEventSync = <const Events extends ReadonlyArray<Machine.TaggedSchema>>(
|
|
480
514
|
machine: Machine.Any,
|
|
481
515
|
event: unknown
|
|
482
516
|
): Machine.EventOf<Events> => {
|
|
483
517
|
const protocol = getProtocolSchemas(machine)
|
|
484
|
-
|
|
485
|
-
return decodeEventConstructionSync(machine, protocol, event, "event") as Machine.EventOf<Events>
|
|
486
|
-
}
|
|
487
|
-
const eventName = getEventName(event)
|
|
488
|
-
return decodeBoundarySync<Machine.EventOf<Events>>(
|
|
518
|
+
return decodeEventWith(
|
|
489
519
|
machine,
|
|
490
|
-
protocol
|
|
491
|
-
event,
|
|
492
|
-
|
|
493
|
-
)
|
|
520
|
+
protocol,
|
|
521
|
+
protocol.eventResultDecoder ??= getBoundaryResultDecoder(protocol.event),
|
|
522
|
+
event
|
|
523
|
+
) as Machine.EventOf<Events>
|
|
494
524
|
}
|
|
495
525
|
|
|
496
526
|
export const decodeEmit = <const Emits extends ReadonlyArray<Machine.TaggedSchema>>(
|
|
@@ -521,13 +551,17 @@ export const decodeEmitSync = <const Emits extends ReadonlyArray<Machine.TaggedS
|
|
|
521
551
|
if (isEventConstruction(event)) {
|
|
522
552
|
return decodeEventConstructionSync(machine, protocol, event, "emission") as Machine.EmittedEventOf<Emits>
|
|
523
553
|
}
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
554
|
+
const decoded = (protocol.emitResultDecoder ??= getBoundaryResultDecoder(protocol.emit))(event)
|
|
555
|
+
if (Result.isFailure(decoded)) {
|
|
556
|
+
const eventName = getEventName(event)
|
|
557
|
+
throw new MachineSchemaDecodeError({
|
|
558
|
+
machineId: machine.id,
|
|
559
|
+
boundary: "emission",
|
|
560
|
+
cause: decoded.failure,
|
|
561
|
+
...(eventName === undefined ? {} : { event: eventName })
|
|
562
|
+
})
|
|
563
|
+
}
|
|
564
|
+
return decoded.success as Machine.EmittedEventOf<Emits>
|
|
531
565
|
}
|
|
532
566
|
|
|
533
567
|
export const decodeInputSync = <Input extends Schema.Top>(
|
|
@@ -559,10 +593,20 @@ export const decodeStateValueSync = (
|
|
|
559
593
|
node: Machine.StateNode,
|
|
560
594
|
value: unknown
|
|
561
595
|
): unknown => {
|
|
596
|
+
const schema = getStateNodeSchema(node)
|
|
562
597
|
if (!isStateInput(value)) {
|
|
563
|
-
|
|
598
|
+
const decoded = getBoundaryResultDecoder(schema)(value)
|
|
599
|
+
if (Result.isFailure(decoded)) {
|
|
600
|
+
throw new MachineSchemaDecodeError({
|
|
601
|
+
machineId: machine.id,
|
|
602
|
+
boundary: "state",
|
|
603
|
+
state: node.path,
|
|
604
|
+
cause: decoded.failure
|
|
605
|
+
})
|
|
606
|
+
}
|
|
607
|
+
return decoded.success
|
|
564
608
|
}
|
|
565
|
-
return makeBoundarySync(machine,
|
|
609
|
+
return makeBoundarySync(machine, schema, value.input, {
|
|
566
610
|
boundary: "state",
|
|
567
611
|
state: node.path
|
|
568
612
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Local process startup and
|
|
1
|
+
/** Local process startup, scope ownership, and prepared process lifecycle. */
|
|
2
2
|
|
|
3
3
|
import * as Deferred from "effect/Deferred"
|
|
4
4
|
import * as Effect from "effect/Effect"
|
|
@@ -6,9 +6,9 @@ import * as Scope from "effect/Scope"
|
|
|
6
6
|
import * as Stream from "effect/Stream"
|
|
7
7
|
import * as InspectionRuntime from "./inspectionRuntime.js"
|
|
8
8
|
import { startCompactCompiledInternal, startCompiledSync } from "./runtimeCompiled.js"
|
|
9
|
-
import { startGenericInternal } from "./runtimeGeneric.js"
|
|
10
9
|
import {
|
|
11
10
|
type MachineRef,
|
|
11
|
+
type MakeChildLogic,
|
|
12
12
|
makeEmissionRuntime,
|
|
13
13
|
makeProcessRuntime,
|
|
14
14
|
type PreparedProcess,
|
|
@@ -17,15 +17,8 @@ import {
|
|
|
17
17
|
type StartProcess
|
|
18
18
|
} from "./runtimeProtocol.js"
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
options: StartInternalOptions
|
|
23
|
-
) =>
|
|
24
|
-
logic.execution?._tag === "Compiled"
|
|
25
|
-
? startCompactCompiledInternal(logic, options)
|
|
26
|
-
: startGenericInternal(logic, options)) as StartProcess
|
|
27
|
-
|
|
28
|
-
const makeRuntime = makeProcessRuntime(startLogicInternal, startCompiledSync)
|
|
20
|
+
// Every logic runs on one local process.
|
|
21
|
+
const startLogicInternal: StartProcess = startCompactCompiledInternal
|
|
29
22
|
|
|
30
23
|
export type ProcessRuntimeStrategy = "generic" | "compiled" | "auto"
|
|
31
24
|
|
|
@@ -89,199 +82,209 @@ const ownedByScope = <State, Event, Error, Output, Emitted, StartError, Requirem
|
|
|
89
82
|
return Effect.andThen(Scope.addFinalizer(parent, stopLive(ownership)), start(ownership.hooks))
|
|
90
83
|
})
|
|
91
84
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
: {
|
|
106
|
-
...options,
|
|
107
|
-
detached: true,
|
|
108
|
-
runtime
|
|
85
|
+
/**
|
|
86
|
+
* The process runtime, bound to the way it builds the logic of a child machine.
|
|
87
|
+
* Compiling a machine definition into process logic belongs to the layer above.
|
|
88
|
+
*/
|
|
89
|
+
export const make = (makeChildLogic: MakeChildLogic) => {
|
|
90
|
+
const makeRuntime = makeProcessRuntime(startLogicInternal, startCompiledSync, makeChildLogic)
|
|
91
|
+
|
|
92
|
+
const startProcessWithStrategy = Effect.fnUntraced(function*(
|
|
93
|
+
logic: ProcessLogic<any, any, any, any, any, any>,
|
|
94
|
+
strategy: ProcessRuntimeStrategy,
|
|
95
|
+
options?: {
|
|
96
|
+
readonly id?: string
|
|
109
97
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
) {
|
|
99
|
+
const runtime = yield* makeRuntime
|
|
100
|
+
const internalOptions: StartInternalOptions = options === undefined
|
|
101
|
+
? {
|
|
102
|
+
detached: true,
|
|
103
|
+
runtime
|
|
104
|
+
}
|
|
105
|
+
: {
|
|
106
|
+
...options,
|
|
107
|
+
detached: true,
|
|
108
|
+
runtime
|
|
109
|
+
}
|
|
110
|
+
if (strategy === "compiled") {
|
|
111
|
+
if (logic.execution?._tag !== "Compiled") {
|
|
112
|
+
return yield* Effect.die(new Error("Machine cannot force the compiled runtime for generic process logic"))
|
|
113
|
+
}
|
|
114
|
+
return yield* ownedByScope((hooks) => startCompactCompiledInternal(logic, { ...internalOptions, ...hooks }))
|
|
116
115
|
}
|
|
117
|
-
return yield* ownedByScope((hooks) =>
|
|
118
|
-
}
|
|
119
|
-
return yield* ownedByScope((hooks) => startLogicInternal(logic, { ...internalOptions, ...hooks }))
|
|
120
|
-
})
|
|
116
|
+
return yield* ownedByScope((hooks) => startLogicInternal(logic, { ...internalOptions, ...hooks }))
|
|
117
|
+
})
|
|
121
118
|
|
|
122
|
-
/** @internal Test-only startup strategy selection. */
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
>(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
): Effect.Effect<
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
> => startProcessWithStrategy(logic, strategy, options) as any
|
|
119
|
+
/** @internal Test-only startup strategy selection. */
|
|
120
|
+
const startProcessWithStrategyForTesting = <
|
|
121
|
+
State,
|
|
122
|
+
Event,
|
|
123
|
+
Error = never,
|
|
124
|
+
Requirements = never,
|
|
125
|
+
Output = never,
|
|
126
|
+
InitialError = never
|
|
127
|
+
>(
|
|
128
|
+
logic: ProcessLogic<State, Event, Error, Requirements, Output, InitialError>,
|
|
129
|
+
strategy: ProcessRuntimeStrategy,
|
|
130
|
+
options?: {
|
|
131
|
+
readonly id?: string
|
|
132
|
+
}
|
|
133
|
+
): Effect.Effect<
|
|
134
|
+
MachineRef<State, Event, Error, Output>,
|
|
135
|
+
InitialError,
|
|
136
|
+
Requirements | Scope.Scope
|
|
137
|
+
> => startProcessWithStrategy(logic, strategy, options) as any
|
|
141
138
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
>(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
) => Effect.Effect<
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
> = Effect.fnUntraced(function*<State, Event, Error, Requirements, Output, InitialError>(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
139
|
+
const startProcess: <
|
|
140
|
+
State,
|
|
141
|
+
Event,
|
|
142
|
+
Error = never,
|
|
143
|
+
Requirements = never,
|
|
144
|
+
Output = never,
|
|
145
|
+
InitialError = never
|
|
146
|
+
>(
|
|
147
|
+
logic: ProcessLogic<State, Event, Error, Requirements, Output, InitialError>,
|
|
148
|
+
options?: {
|
|
149
|
+
readonly id?: string
|
|
150
|
+
}
|
|
151
|
+
) => Effect.Effect<
|
|
152
|
+
MachineRef<State, Event, Error, Output>,
|
|
153
|
+
InitialError,
|
|
154
|
+
Requirements | Scope.Scope
|
|
155
|
+
> = Effect.fnUntraced(function*<State, Event, Error, Requirements, Output, InitialError>(
|
|
156
|
+
logic: ProcessLogic<State, Event, Error, Requirements, Output, InitialError>,
|
|
157
|
+
options?: {
|
|
158
|
+
readonly id?: string
|
|
159
|
+
}
|
|
160
|
+
) {
|
|
161
|
+
const runtime = yield* makeRuntime
|
|
162
|
+
return yield* ownedByScope((hooks) =>
|
|
163
|
+
startLogicInternal(
|
|
164
|
+
logic,
|
|
165
|
+
options === undefined
|
|
166
|
+
? {
|
|
167
|
+
detached: true,
|
|
168
|
+
runtime,
|
|
169
|
+
...hooks
|
|
170
|
+
}
|
|
171
|
+
: {
|
|
172
|
+
...options,
|
|
173
|
+
detached: true,
|
|
174
|
+
runtime,
|
|
175
|
+
...hooks
|
|
176
|
+
}
|
|
177
|
+
)
|
|
180
178
|
)
|
|
181
|
-
)
|
|
182
|
-
})
|
|
179
|
+
})
|
|
183
180
|
|
|
184
|
-
const prepareProcessWithStrategy = Effect.fnUntraced(function*<
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
>(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
) {
|
|
199
|
-
const runtime = yield* makeRuntime
|
|
200
|
-
const sessionId = yield* runtime.nextSessionId
|
|
201
|
-
const inspection = yield* InspectionRuntime.make(sessionId)
|
|
202
|
-
runtime.inspection = inspection
|
|
203
|
-
const emissions = makeEmissionRuntime()
|
|
204
|
-
const started = yield* Deferred.make<MachineRef<State, Event, Error, Output, Emitted>, InitialError>()
|
|
205
|
-
const internalOptions: StartInternalOptions = options === undefined
|
|
206
|
-
? {
|
|
207
|
-
detached: true,
|
|
208
|
-
emissions,
|
|
209
|
-
runtime,
|
|
210
|
-
sessionId,
|
|
211
|
-
inspectionRoot: true,
|
|
212
|
-
origin: { _tag: "Root" }
|
|
181
|
+
const prepareProcessWithStrategy = Effect.fnUntraced(function*<
|
|
182
|
+
State,
|
|
183
|
+
Event,
|
|
184
|
+
Error,
|
|
185
|
+
Requirements,
|
|
186
|
+
Output,
|
|
187
|
+
InitialError,
|
|
188
|
+
Emitted
|
|
189
|
+
>(
|
|
190
|
+
logic: ProcessLogic<State, Event, Error, Requirements, Output, InitialError>,
|
|
191
|
+
strategy: ProcessRuntimeStrategy,
|
|
192
|
+
options?: {
|
|
193
|
+
readonly id?: string
|
|
213
194
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
195
|
+
) {
|
|
196
|
+
const runtime = yield* makeRuntime
|
|
197
|
+
const sessionId = yield* runtime.nextSessionId
|
|
198
|
+
const inspection = yield* InspectionRuntime.make(sessionId)
|
|
199
|
+
runtime.inspection = inspection
|
|
200
|
+
const emissions = makeEmissionRuntime()
|
|
201
|
+
const started = yield* Deferred.make<MachineRef<State, Event, Error, Output, Emitted>, InitialError>()
|
|
202
|
+
const internalOptions: StartInternalOptions = options === undefined
|
|
203
|
+
? {
|
|
204
|
+
detached: true,
|
|
205
|
+
emissions,
|
|
206
|
+
runtime,
|
|
207
|
+
sessionId,
|
|
208
|
+
inspectionRoot: true,
|
|
209
|
+
origin: { _tag: "Root" }
|
|
210
|
+
}
|
|
211
|
+
: {
|
|
212
|
+
...options,
|
|
213
|
+
detached: true,
|
|
214
|
+
emissions,
|
|
215
|
+
runtime,
|
|
216
|
+
sessionId,
|
|
217
|
+
inspectionRoot: true,
|
|
218
|
+
origin: { _tag: "Root" }
|
|
219
|
+
}
|
|
220
|
+
const initialize = (hooks: OwnershipHooks) => {
|
|
221
|
+
const startOptions = { ...internalOptions, ...hooks }
|
|
222
|
+
return strategy === "compiled"
|
|
223
|
+
? logic.execution?._tag === "Compiled"
|
|
224
|
+
? startCompactCompiledInternal(logic, startOptions)
|
|
225
|
+
: Effect.die(new Error("Machine cannot force the compiled runtime for generic process logic"))
|
|
226
|
+
: startLogicInternal(logic, startOptions)
|
|
222
227
|
}
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
? logic.execution?._tag === "Compiled"
|
|
229
|
-
? startCompactCompiledInternal(logic, startOptions)
|
|
230
|
-
: Effect.die(new Error("Machine cannot force the compiled runtime for generic process logic"))
|
|
231
|
-
: startLogicInternal(logic, startOptions)
|
|
232
|
-
}
|
|
233
|
-
// `start` is one-shot: the Scope that first evaluates it owns the machine.
|
|
234
|
-
const start = yield* Effect.cached(
|
|
235
|
-
ownedByScope(initialize).pipe(
|
|
236
|
-
Effect.onExit((exit) => Deferred.done(started, exit))
|
|
228
|
+
// `start` is one-shot: the Scope that first evaluates it owns the machine.
|
|
229
|
+
const start = yield* Effect.cached(
|
|
230
|
+
ownedByScope(initialize).pipe(
|
|
231
|
+
Effect.onExit((exit) => Deferred.done(started, exit))
|
|
232
|
+
)
|
|
237
233
|
)
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
})
|
|
234
|
+
return {
|
|
235
|
+
id: options?.id ?? sessionId,
|
|
236
|
+
sessionId,
|
|
237
|
+
changes: Stream.unwrap(
|
|
238
|
+
Deferred.await(started).pipe(Effect.map((ref) => ref.changes))
|
|
239
|
+
),
|
|
240
|
+
emissions: emissions.stream as Stream.Stream<Emitted>,
|
|
241
|
+
inspection: inspection.stream,
|
|
242
|
+
start
|
|
243
|
+
}
|
|
244
|
+
})
|
|
250
245
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
>(
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
) => Effect.Effect<
|
|
265
|
-
|
|
266
|
-
> =
|
|
267
|
-
|
|
268
|
-
|
|
246
|
+
const prepareProcess: <
|
|
247
|
+
State,
|
|
248
|
+
Event,
|
|
249
|
+
Error = never,
|
|
250
|
+
Requirements = never,
|
|
251
|
+
Output = never,
|
|
252
|
+
InitialError = never,
|
|
253
|
+
Emitted = never
|
|
254
|
+
>(
|
|
255
|
+
logic: ProcessLogic<State, Event, Error, Requirements, Output, InitialError>,
|
|
256
|
+
options?: {
|
|
257
|
+
readonly id?: string
|
|
258
|
+
}
|
|
259
|
+
) => Effect.Effect<
|
|
260
|
+
PreparedProcess<State, Event, Error, Output, Emitted, InitialError, Requirements | Scope.Scope>
|
|
261
|
+
> =
|
|
262
|
+
((logic: ProcessLogic<any, any, any, any, any, any>, options?: { readonly id?: string }) =>
|
|
263
|
+
prepareProcessWithStrategy(logic, "auto", options)) as any
|
|
269
264
|
|
|
270
|
-
/** @internal Test-only prepared startup strategy selection. */
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
>(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
265
|
+
/** @internal Test-only prepared startup strategy selection. */
|
|
266
|
+
const prepareProcessWithStrategyForTesting = <
|
|
267
|
+
State,
|
|
268
|
+
Event,
|
|
269
|
+
Error = never,
|
|
270
|
+
Requirements = never,
|
|
271
|
+
Output = never,
|
|
272
|
+
InitialError = never,
|
|
273
|
+
Emitted = never
|
|
274
|
+
>(
|
|
275
|
+
logic: ProcessLogic<State, Event, Error, Requirements, Output, InitialError>,
|
|
276
|
+
strategy: ProcessRuntimeStrategy,
|
|
277
|
+
options?: {
|
|
278
|
+
readonly id?: string
|
|
279
|
+
}
|
|
280
|
+
): Effect.Effect<
|
|
281
|
+
PreparedProcess<State, Event, Error, Output, Emitted, InitialError, Requirements | Scope.Scope>
|
|
282
|
+
> => prepareProcessWithStrategy(logic, strategy, options) as any
|
|
283
|
+
|
|
284
|
+
return {
|
|
285
|
+
startProcess,
|
|
286
|
+
prepareProcess,
|
|
287
|
+
startProcessWithStrategyForTesting,
|
|
288
|
+
prepareProcessWithStrategyForTesting
|
|
284
289
|
}
|
|
285
|
-
|
|
286
|
-
PreparedProcess<State, Event, Error, Output, Emitted, InitialError, Requirements | Scope.Scope>
|
|
287
|
-
> => prepareProcessWithStrategy(logic, strategy, options) as any
|
|
290
|
+
}
|