@typeonce/effect-machine 0.8.0 → 0.10.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/README.md +180 -40
- package/dist/Machine.d.ts +659 -481
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +86 -222
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/activities.d.ts +5 -12
- package/dist/internal/machine/activities.d.ts.map +1 -1
- package/dist/internal/machine/activities.js +47 -17
- package/dist/internal/machine/activities.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +6 -2
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +5 -0
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js +2 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/command.js +2 -2
- package/dist/internal/machine/command.js.map +1 -1
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.js +6 -3
- package/dist/internal/machine/commandRuntime.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +8 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +9 -4
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/errors.d.ts +1 -1
- package/dist/internal/machine/errors.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +3 -3
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +74 -24
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts +10 -2
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +94 -34
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationEvent.d.ts +39 -0
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -0
- package/dist/internal/machine/invocationEvent.js +43 -0
- package/dist/internal/machine/invocationEvent.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +16 -65
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +18 -73
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +4 -2
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +104 -24
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +8 -8
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +8 -5
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +207 -15
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +8 -2
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +86 -8
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/symbols.d.ts +2 -0
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js +2 -0
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +7 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +29 -0
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +1 -1
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +2 -1
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +5 -3
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +7 -7
- package/dist/testing/MachineTest.js +7 -7
- package/dist/unstable/cluster/ClusterMachine.d.ts +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +25 -8
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +18 -3
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +242 -122
- package/package.json +2 -2
- package/src/Machine.ts +1453 -812
- package/src/internal/machine/activities.ts +48 -33
- package/src/internal/machine/atom.ts +38 -13
- package/src/internal/machine/cluster.ts +2 -1
- package/src/internal/machine/command.ts +2 -2
- package/src/internal/machine/commandRuntime.ts +9 -4
- package/src/internal/machine/configuration.ts +23 -5
- package/src/internal/machine/errors.ts +1 -1
- package/src/internal/machine/executionPlan.ts +102 -28
- package/src/internal/machine/invocation.ts +182 -50
- package/src/internal/machine/invocationEvent.ts +72 -0
- package/src/internal/machine/machine.ts +80 -387
- package/src/internal/machine/planner.ts +127 -32
- package/src/internal/machine/process.ts +18 -8
- package/src/internal/machine/protocol.ts +313 -25
- package/src/internal/machine/runtime.ts +135 -9
- package/src/internal/machine/symbols.ts +3 -0
- package/src/internal/machine/topology.ts +38 -0
- package/src/internal/testing/machine/finiteModel.ts +1 -1
- package/src/internal/testing/machine/runtime.ts +2 -1
- package/src/internal/testing/machine/verification.ts +5 -3
- package/src/testing/MachineTest.ts +7 -7
- package/src/unstable/cluster/ClusterMachine.ts +1 -1
- package/src/unstable/reactivity/AtomMachine.ts +45 -13
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as Duration from "effect/Duration"
|
|
2
1
|
import * as Effect from "effect/Effect"
|
|
3
2
|
import * as Inspectable from "effect/Inspectable"
|
|
4
3
|
import * as Option from "effect/Option"
|
|
@@ -34,6 +33,7 @@ import type { EnsureExecutable } from "./readiness.js"
|
|
|
34
33
|
import * as internalRuntime from "./runtime.js"
|
|
35
34
|
import * as Serialization from "./serialization.js"
|
|
36
35
|
import * as StateDefinition from "./stateDefinition.js"
|
|
36
|
+
import { ChildMachineLogicTypeId } from "./symbols.js"
|
|
37
37
|
import * as Topology from "./topology.js"
|
|
38
38
|
|
|
39
39
|
export {
|
|
@@ -45,13 +45,12 @@ export {
|
|
|
45
45
|
StartupError,
|
|
46
46
|
StoppedError
|
|
47
47
|
} from "./errors.js"
|
|
48
|
-
export { InitialEventTypeId } from "./symbols.js"
|
|
48
|
+
export { ChildMachineLogicTypeId, InitialEventTypeId } from "./symbols.js"
|
|
49
49
|
|
|
50
50
|
const TypeId = "~effect/Machine"
|
|
51
51
|
export const SnapshotBuilderStateTypeId: unique symbol = Symbol("effect/Machine/SnapshotBuilderState")
|
|
52
52
|
export const InvokeTypeId: unique symbol = Symbol.for("effect/Machine/Invoke")
|
|
53
53
|
const ChildMachineTypeId = "~effect/Machine/ChildMachine"
|
|
54
|
-
type InvokeLifecycleId = string
|
|
55
54
|
type IsAny<A> = 0 extends 1 & A ? true : false
|
|
56
55
|
type MachineRuntimeRequirement = internalRuntime.MachineRuntime
|
|
57
56
|
type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<
|
|
@@ -87,7 +86,8 @@ interface DefineStates {
|
|
|
87
86
|
): Machine.DefinedStates<States>
|
|
88
87
|
<const States extends Machine.StateSchemas>(states: InvalidDefinedStateTreeInput<States>): never
|
|
89
88
|
}
|
|
90
|
-
type ValidateInputEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>> = InputEvents
|
|
89
|
+
type ValidateInputEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>> = InputEvents extends
|
|
90
|
+
ReadonlyArray<Machine.TaggedSchema> ? unknown : never
|
|
91
91
|
type ValidateInternalEventProtocol<
|
|
92
92
|
InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
93
93
|
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>
|
|
@@ -112,7 +112,8 @@ const cloneWithHandlers = (
|
|
|
112
112
|
machine.states = self.states
|
|
113
113
|
machine.events = self.events
|
|
114
114
|
machine.internalEvents = self.internalEvents
|
|
115
|
-
machine.
|
|
115
|
+
machine.emittedEvents = self.emittedEvents
|
|
116
|
+
machine.parentEvents = self.parentEvents
|
|
116
117
|
machine.input = self.input
|
|
117
118
|
machine.id = self.id
|
|
118
119
|
machine.initial = self.initial
|
|
@@ -727,6 +728,7 @@ const makeTargetBuilder = <const States extends Machine.StateSchemas>(
|
|
|
727
728
|
const history = makeHistoryTargetBuilder(states, "") as Machine.HistoryTargetBuilder<States>
|
|
728
729
|
return <Source extends Machine.StateNodeIdentifier<States>>(source: Source): Machine.TargetBuilder<States, Source> =>
|
|
729
730
|
({
|
|
731
|
+
none: Topology.makeNoTarget,
|
|
730
732
|
local: makeLocalTargetBuilder(states, stateNodes, source),
|
|
731
733
|
branch: makeBranchTargetBuilder(states, stateNodes, source),
|
|
732
734
|
full,
|
|
@@ -766,18 +768,22 @@ type MakeConfig<
|
|
|
766
768
|
Input extends Schema.Top,
|
|
767
769
|
InitialE,
|
|
768
770
|
InitialR,
|
|
769
|
-
InternalEvents extends ReadonlyArray<Machine.TaggedSchema
|
|
771
|
+
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
772
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
|
|
770
773
|
> = {
|
|
771
774
|
readonly id?: string
|
|
772
775
|
readonly states: States & DefineStateTreeInput<NoInfer<States>>
|
|
773
|
-
readonly events:
|
|
776
|
+
readonly events:
|
|
777
|
+
& Machine.EventProtocol<"public", InputEvents>
|
|
778
|
+
& ValidateInputEventProtocol<NoInfer<InputEvents>>
|
|
774
779
|
readonly internalEvents?:
|
|
775
|
-
& InternalEvents
|
|
780
|
+
& Machine.EventProtocol<"internal", InternalEvents>
|
|
776
781
|
& ValidateInternalEventProtocol<
|
|
777
782
|
NoInfer<InputEvents>,
|
|
778
783
|
NoInfer<InternalEvents>
|
|
779
784
|
>
|
|
780
|
-
readonly
|
|
785
|
+
readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>
|
|
786
|
+
readonly parentEvents?: Machine.EventProtocol<"public", ParentEvents>
|
|
781
787
|
readonly input?: Input
|
|
782
788
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>
|
|
783
789
|
}
|
|
@@ -789,7 +795,8 @@ type MakeResult<
|
|
|
789
795
|
Input extends Schema.Top,
|
|
790
796
|
InitialE,
|
|
791
797
|
InitialR,
|
|
792
|
-
InternalEvents extends ReadonlyArray<Machine.TaggedSchema
|
|
798
|
+
InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
799
|
+
ParentEvents extends ReadonlyArray<Machine.TaggedSchema>
|
|
793
800
|
> = Machine<
|
|
794
801
|
States,
|
|
795
802
|
readonly [...InputEvents, ...InternalEvents],
|
|
@@ -803,7 +810,8 @@ type MakeResult<
|
|
|
803
810
|
Machine.TerminalOutput<States>,
|
|
804
811
|
Emits,
|
|
805
812
|
never,
|
|
806
|
-
InputEvents
|
|
813
|
+
InputEvents,
|
|
814
|
+
ParentEvents
|
|
807
815
|
>
|
|
808
816
|
|
|
809
817
|
interface Make {
|
|
@@ -814,11 +822,12 @@ interface Make {
|
|
|
814
822
|
const Input extends Schema.Top = typeof Schema.Void,
|
|
815
823
|
InitialE = never,
|
|
816
824
|
InitialR = never,
|
|
817
|
-
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
825
|
+
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
826
|
+
const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
818
827
|
>(
|
|
819
|
-
config: MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>,
|
|
828
|
+
config: MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>,
|
|
820
829
|
..._validation: ValidateDefinedStates<NoInfer<States>>
|
|
821
|
-
): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>
|
|
830
|
+
): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>
|
|
822
831
|
<
|
|
823
832
|
const States extends Machine.StateSchemas,
|
|
824
833
|
const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -826,10 +835,11 @@ interface Make {
|
|
|
826
835
|
const Input extends Schema.Top = typeof Schema.Void,
|
|
827
836
|
InitialE = never,
|
|
828
837
|
InitialR = never,
|
|
829
|
-
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
838
|
+
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
839
|
+
const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
830
840
|
>(
|
|
831
841
|
config:
|
|
832
|
-
& Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>, "states">
|
|
842
|
+
& Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>, "states">
|
|
833
843
|
& { readonly states: InvalidDefinedStateTreeInput<States> }
|
|
834
844
|
): never
|
|
835
845
|
}
|
|
@@ -841,24 +851,27 @@ export const make: Make = (<
|
|
|
841
851
|
const Input extends Schema.Top = typeof Schema.Void,
|
|
842
852
|
InitialE = never,
|
|
843
853
|
InitialR = never,
|
|
844
|
-
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
854
|
+
const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
855
|
+
const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
845
856
|
>(
|
|
846
857
|
config: {
|
|
847
858
|
readonly id?: string
|
|
848
859
|
readonly states: States
|
|
849
|
-
readonly events: InputEvents
|
|
850
|
-
readonly internalEvents?: InternalEvents
|
|
851
|
-
readonly
|
|
860
|
+
readonly events: Machine.EventProtocol<"public", InputEvents>
|
|
861
|
+
readonly internalEvents?: Machine.EventProtocol<"internal", InternalEvents>
|
|
862
|
+
readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>
|
|
863
|
+
readonly parentEvents?: Machine.EventProtocol<"public", ParentEvents>
|
|
852
864
|
readonly input?: Input
|
|
853
865
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>
|
|
854
866
|
}
|
|
855
|
-
): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents> => {
|
|
867
|
+
): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents> => {
|
|
856
868
|
StateDefinition.validateStateDefinitions(config.states, "Machine.make")
|
|
857
869
|
const self = Object.create(Proto)
|
|
858
870
|
self.states = config.states
|
|
859
871
|
self.events = config.events
|
|
860
|
-
self.internalEvents = config.internalEvents ?? []
|
|
861
|
-
self.
|
|
872
|
+
self.internalEvents = config.internalEvents ?? Protocol.makeEventProtocol("internal", [] as const)
|
|
873
|
+
self.emittedEvents = config.emittedEvents ?? Protocol.makeEventProtocol("emitted", [] as const)
|
|
874
|
+
self.parentEvents = config.parentEvents ?? Protocol.makeEventProtocol("public", [] as const)
|
|
862
875
|
self.input = config.input
|
|
863
876
|
self.id = config.id
|
|
864
877
|
self.initial = config.initial
|
|
@@ -870,18 +883,39 @@ export const make: Make = (<
|
|
|
870
883
|
return self
|
|
871
884
|
}) as Make
|
|
872
885
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
:
|
|
886
|
+
const flattenEventProtocolInputs = <Kind extends Machine.EventProtocolKind>(
|
|
887
|
+
kind: Kind,
|
|
888
|
+
inputs: ReadonlyArray<Machine.EventProtocolInput<Kind>>
|
|
889
|
+
): ReadonlyArray<Machine.TaggedSchema> =>
|
|
890
|
+
inputs.flatMap((input) =>
|
|
891
|
+
Protocol.isEventProtocol(input, kind)
|
|
892
|
+
? Protocol.eventProtocolSchemas(input)
|
|
893
|
+
: [input as Machine.TaggedSchema]
|
|
894
|
+
)
|
|
876
895
|
|
|
877
|
-
export const
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
896
|
+
export const events = <const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"public">>>(
|
|
897
|
+
...inputs: Inputs
|
|
898
|
+
): Machine.EventProtocol<"public", Machine.EventProtocolInputSchemasOf<"public", Inputs>> =>
|
|
899
|
+
Protocol.makeEventProtocol(
|
|
900
|
+
"public",
|
|
901
|
+
flattenEventProtocolInputs("public", inputs)
|
|
902
|
+
) as Machine.EventProtocol<"public", Machine.EventProtocolInputSchemasOf<"public", Inputs>>
|
|
903
|
+
|
|
904
|
+
export const internalEvents = <const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"internal">>>(
|
|
905
|
+
...inputs: Inputs
|
|
906
|
+
): Machine.EventProtocol<"internal", Machine.EventProtocolInputSchemasOf<"internal", Inputs>> =>
|
|
907
|
+
Protocol.makeEventProtocol(
|
|
908
|
+
"internal",
|
|
909
|
+
flattenEventProtocolInputs("internal", inputs)
|
|
910
|
+
) as Machine.EventProtocol<"internal", Machine.EventProtocolInputSchemasOf<"internal", Inputs>>
|
|
911
|
+
|
|
912
|
+
export const emittedEvents = <const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"emitted">>>(
|
|
913
|
+
...inputs: Inputs
|
|
914
|
+
): Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>> =>
|
|
915
|
+
Protocol.makeEventProtocol(
|
|
916
|
+
"emitted",
|
|
917
|
+
flattenEventProtocolInputs("emitted", inputs)
|
|
918
|
+
) as Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>>
|
|
885
919
|
|
|
886
920
|
export const encodeSnapshot: <
|
|
887
921
|
const States extends Machine.StateSchemas,
|
|
@@ -957,346 +991,6 @@ export const decodeSnapshot: <
|
|
|
957
991
|
Machine.SnapshotDecodingServices<States>
|
|
958
992
|
> = Serialization.decodeSnapshot as any
|
|
959
993
|
|
|
960
|
-
export const invoke = <
|
|
961
|
-
ChildState,
|
|
962
|
-
ChildEvent,
|
|
963
|
-
ChildError = never,
|
|
964
|
-
ChildRequirements = never,
|
|
965
|
-
ChildOutput = never,
|
|
966
|
-
ChildInitialError = never,
|
|
967
|
-
Event = never,
|
|
968
|
-
Address extends ChildAddress<never> | undefined = undefined
|
|
969
|
-
>(
|
|
970
|
-
config:
|
|
971
|
-
& {
|
|
972
|
-
readonly id: InvokeLifecycleId
|
|
973
|
-
readonly src: () => Logic<
|
|
974
|
-
ChildState,
|
|
975
|
-
ChildEvent,
|
|
976
|
-
ChildError,
|
|
977
|
-
ChildRequirements,
|
|
978
|
-
ChildOutput,
|
|
979
|
-
ChildInitialError
|
|
980
|
-
>
|
|
981
|
-
readonly snapshot?: (
|
|
982
|
-
context: Machine.InvokeSnapshotContext<ChildState, ChildError, ChildOutput>
|
|
983
|
-
) => Event | undefined
|
|
984
|
-
}
|
|
985
|
-
& ([Address] extends [undefined] ? {
|
|
986
|
-
readonly address?: never
|
|
987
|
-
}
|
|
988
|
-
: {
|
|
989
|
-
readonly address: Exclude<Address, undefined>
|
|
990
|
-
} & ChildAddress.Compatibility<Exclude<Address, undefined>, NoInfer<ChildEvent>>)
|
|
991
|
-
): Machine.InvokeConfig<
|
|
992
|
-
any,
|
|
993
|
-
any,
|
|
994
|
-
any,
|
|
995
|
-
any,
|
|
996
|
-
Event,
|
|
997
|
-
ChildState,
|
|
998
|
-
ChildEvent,
|
|
999
|
-
ChildError,
|
|
1000
|
-
ChildRequirements,
|
|
1001
|
-
ChildOutput,
|
|
1002
|
-
ChildInitialError
|
|
1003
|
-
> => ({
|
|
1004
|
-
...config,
|
|
1005
|
-
[InvokeTypeId]: undefined as any,
|
|
1006
|
-
[Activities.ActivityMetadataTypeId]: { type: "process" }
|
|
1007
|
-
})
|
|
1008
|
-
|
|
1009
|
-
type InvokeEffectResult<Requirements, Event> = Machine.InvokeConfig<
|
|
1010
|
-
any,
|
|
1011
|
-
any,
|
|
1012
|
-
any,
|
|
1013
|
-
any,
|
|
1014
|
-
never,
|
|
1015
|
-
void,
|
|
1016
|
-
never,
|
|
1017
|
-
never,
|
|
1018
|
-
Requirements,
|
|
1019
|
-
Event | void,
|
|
1020
|
-
never
|
|
1021
|
-
>
|
|
1022
|
-
|
|
1023
|
-
type InvokeEffectIsInfallible<Fx extends Effect.Effect<any, any, any>> = IsAny<Effect.Error<Fx>> extends true ? false
|
|
1024
|
-
: [Effect.Error<Fx>] extends [never] ? true
|
|
1025
|
-
: false
|
|
1026
|
-
|
|
1027
|
-
type InvokeEffectConfig<
|
|
1028
|
-
Fx extends Effect.Effect<any, any, any>,
|
|
1029
|
-
SuccessEvent,
|
|
1030
|
-
FailureEvent
|
|
1031
|
-
> =
|
|
1032
|
-
& {
|
|
1033
|
-
readonly id: InvokeLifecycleId
|
|
1034
|
-
readonly effect: Fx
|
|
1035
|
-
readonly onSuccess: (value: NoInfer<Effect.Success<Fx>>) => SuccessEvent | void
|
|
1036
|
-
}
|
|
1037
|
-
& (
|
|
1038
|
-
InvokeEffectIsInfallible<Fx> extends true ? {
|
|
1039
|
-
readonly onFailure?: never
|
|
1040
|
-
}
|
|
1041
|
-
: {
|
|
1042
|
-
readonly onFailure: (error: NoInfer<Effect.Error<Fx>>) => FailureEvent | void
|
|
1043
|
-
}
|
|
1044
|
-
)
|
|
1045
|
-
|
|
1046
|
-
export const invokeEffect = <
|
|
1047
|
-
const Fx extends Effect.Effect<any, any, any>,
|
|
1048
|
-
SuccessEvent,
|
|
1049
|
-
FailureEvent = never
|
|
1050
|
-
>(
|
|
1051
|
-
config: InvokeEffectConfig<Fx, SuccessEvent, FailureEvent>
|
|
1052
|
-
): InvokeEffectResult<
|
|
1053
|
-
Effect.Services<Fx>,
|
|
1054
|
-
SuccessEvent | (InvokeEffectIsInfallible<Fx> extends true ? never : FailureEvent)
|
|
1055
|
-
> =>
|
|
1056
|
-
((config: {
|
|
1057
|
-
readonly id: string
|
|
1058
|
-
readonly effect: Effect.Effect<unknown, unknown, unknown>
|
|
1059
|
-
readonly onSuccess: (value: unknown) => unknown
|
|
1060
|
-
readonly onFailure?: (error: unknown) => unknown
|
|
1061
|
-
}) => ({
|
|
1062
|
-
...invoke({
|
|
1063
|
-
id: config.id,
|
|
1064
|
-
src: () =>
|
|
1065
|
-
effect(
|
|
1066
|
-
config.onFailure === undefined
|
|
1067
|
-
? Effect.map(config.effect, config.onSuccess)
|
|
1068
|
-
: Effect.matchEffect(config.effect, {
|
|
1069
|
-
onFailure: (error) => Effect.succeed(config.onFailure!(error)),
|
|
1070
|
-
onSuccess: (value) => Effect.succeed(config.onSuccess(value))
|
|
1071
|
-
})
|
|
1072
|
-
)
|
|
1073
|
-
}),
|
|
1074
|
-
[Activities.ActivityMetadataTypeId]: {
|
|
1075
|
-
type: "effect",
|
|
1076
|
-
outcomes: {
|
|
1077
|
-
success: "dynamic",
|
|
1078
|
-
failure: config.onFailure === undefined ? "none" : "dynamic"
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
}))(config as any) as any
|
|
1082
|
-
|
|
1083
|
-
export const after = <Event extends { readonly _tag: PropertyKey }>(
|
|
1084
|
-
duration: Duration.Input,
|
|
1085
|
-
event: Event,
|
|
1086
|
-
options?: { readonly id?: InvokeLifecycleId }
|
|
1087
|
-
): InvokeEffectResult<never, Event> => ({
|
|
1088
|
-
...invoke({
|
|
1089
|
-
id: options?.id ?? `Machine.after:${String(event._tag)}`,
|
|
1090
|
-
src: () => effect(Effect.as(Effect.sleep(duration), event))
|
|
1091
|
-
}),
|
|
1092
|
-
[Activities.ActivityMetadataTypeId]: {
|
|
1093
|
-
type: "timer",
|
|
1094
|
-
duration: Duration.format(Duration.fromInputUnsafe(duration)),
|
|
1095
|
-
event: String(event._tag)
|
|
1096
|
-
}
|
|
1097
|
-
})
|
|
1098
|
-
|
|
1099
|
-
export const retag = (
|
|
1100
|
-
target: Machine.TaggedSchema,
|
|
1101
|
-
source: { readonly _tag: PropertyKey },
|
|
1102
|
-
patch?: unknown
|
|
1103
|
-
): any => {
|
|
1104
|
-
const { _tag: _, ...fields } = source
|
|
1105
|
-
return target.make({ ...fields, ...((patch ?? {}) as object) } as never)
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.Void ? {
|
|
1109
|
-
readonly input?: never
|
|
1110
|
-
}
|
|
1111
|
-
: {
|
|
1112
|
-
readonly input: Input["Type"]
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
export const invokeMachine: {
|
|
1116
|
-
<
|
|
1117
|
-
const States extends Machine.StateSchemas,
|
|
1118
|
-
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
1119
|
-
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
1120
|
-
const Input extends Schema.Top = typeof Schema.Void,
|
|
1121
|
-
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
1122
|
-
E = never,
|
|
1123
|
-
R = never,
|
|
1124
|
-
InitialE = never,
|
|
1125
|
-
InitialR = never,
|
|
1126
|
-
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
1127
|
-
Output = never,
|
|
1128
|
-
SnapshotEvent = never,
|
|
1129
|
-
DoneEvent = never,
|
|
1130
|
-
Id extends string = string,
|
|
1131
|
-
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
1132
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
1133
|
-
>(
|
|
1134
|
-
config:
|
|
1135
|
-
& {
|
|
1136
|
-
readonly child: ChildMachine<
|
|
1137
|
-
Id,
|
|
1138
|
-
& Machine<
|
|
1139
|
-
States,
|
|
1140
|
-
Events,
|
|
1141
|
-
Input,
|
|
1142
|
-
UnhandledStates,
|
|
1143
|
-
E,
|
|
1144
|
-
R,
|
|
1145
|
-
InitialE,
|
|
1146
|
-
InitialR,
|
|
1147
|
-
FinalStates,
|
|
1148
|
-
Output,
|
|
1149
|
-
Emits,
|
|
1150
|
-
OutputStates,
|
|
1151
|
-
InputEvents
|
|
1152
|
-
>
|
|
1153
|
-
& EnsureExecutable<States, UnhandledStates, OutputStates>
|
|
1154
|
-
>
|
|
1155
|
-
readonly snapshot?: (
|
|
1156
|
-
context: Machine.InvokeSnapshotContext<
|
|
1157
|
-
Machine.Snapshot<States>,
|
|
1158
|
-
| E
|
|
1159
|
-
| ActionError<R>
|
|
1160
|
-
| InfiniteTransitionError
|
|
1161
|
-
| MachineSchemaDecodeError
|
|
1162
|
-
| StoppedError,
|
|
1163
|
-
Output
|
|
1164
|
-
>
|
|
1165
|
-
) => SnapshotEvent | undefined
|
|
1166
|
-
readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined
|
|
1167
|
-
}
|
|
1168
|
-
& InvokeMachineInput<Input>
|
|
1169
|
-
): Machine.InvokeConfig<
|
|
1170
|
-
any,
|
|
1171
|
-
any,
|
|
1172
|
-
any,
|
|
1173
|
-
any,
|
|
1174
|
-
SnapshotEvent,
|
|
1175
|
-
Machine.Snapshot<States>,
|
|
1176
|
-
Machine.EventOf<InputEvents>,
|
|
1177
|
-
E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
|
|
1178
|
-
ExcludeCompatibleRuntime<
|
|
1179
|
-
Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>,
|
|
1180
|
-
Machine.EventOf<Events>,
|
|
1181
|
-
Machine.EmitOf<Emits>
|
|
1182
|
-
>,
|
|
1183
|
-
Output,
|
|
1184
|
-
| InitialE
|
|
1185
|
-
| E
|
|
1186
|
-
| ActionError<InitialR | R>
|
|
1187
|
-
| InfiniteTransitionError
|
|
1188
|
-
| MachineSchemaDecodeError
|
|
1189
|
-
| StartupError
|
|
1190
|
-
| StoppedError,
|
|
1191
|
-
Machine.EmitOf<Emits>,
|
|
1192
|
-
DoneEvent
|
|
1193
|
-
>
|
|
1194
|
-
<
|
|
1195
|
-
const States extends Machine.StateSchemas,
|
|
1196
|
-
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
1197
|
-
const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
|
|
1198
|
-
const Input extends Schema.Top = typeof Schema.Void,
|
|
1199
|
-
UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
|
|
1200
|
-
E = never,
|
|
1201
|
-
R = never,
|
|
1202
|
-
InitialE = never,
|
|
1203
|
-
InitialR = never,
|
|
1204
|
-
FinalStates extends Machine.StateIdentifier<States> = never,
|
|
1205
|
-
Output = never,
|
|
1206
|
-
SnapshotEvent = never,
|
|
1207
|
-
Id extends string = string,
|
|
1208
|
-
OutputStates extends Machine.StateIdentifier<States> = never,
|
|
1209
|
-
InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
|
|
1210
|
-
>(
|
|
1211
|
-
config:
|
|
1212
|
-
& {
|
|
1213
|
-
readonly child: ChildMachine<
|
|
1214
|
-
Id,
|
|
1215
|
-
& Machine<
|
|
1216
|
-
States,
|
|
1217
|
-
Events,
|
|
1218
|
-
Input,
|
|
1219
|
-
UnhandledStates,
|
|
1220
|
-
E,
|
|
1221
|
-
R,
|
|
1222
|
-
InitialE,
|
|
1223
|
-
InitialR,
|
|
1224
|
-
FinalStates,
|
|
1225
|
-
Output,
|
|
1226
|
-
Emits,
|
|
1227
|
-
OutputStates,
|
|
1228
|
-
InputEvents
|
|
1229
|
-
>
|
|
1230
|
-
& EnsureExecutable<States, UnhandledStates, OutputStates>
|
|
1231
|
-
>
|
|
1232
|
-
readonly snapshot?: (
|
|
1233
|
-
context: Machine.InvokeSnapshotContext<
|
|
1234
|
-
Machine.Snapshot<States>,
|
|
1235
|
-
| E
|
|
1236
|
-
| ActionError<R>
|
|
1237
|
-
| InfiniteTransitionError
|
|
1238
|
-
| MachineSchemaDecodeError
|
|
1239
|
-
| StoppedError,
|
|
1240
|
-
Output
|
|
1241
|
-
>
|
|
1242
|
-
) => SnapshotEvent | undefined
|
|
1243
|
-
readonly onDone?: never
|
|
1244
|
-
}
|
|
1245
|
-
& InvokeMachineInput<Input>
|
|
1246
|
-
): Machine.InvokeConfig<
|
|
1247
|
-
any,
|
|
1248
|
-
any,
|
|
1249
|
-
any,
|
|
1250
|
-
any,
|
|
1251
|
-
SnapshotEvent,
|
|
1252
|
-
Machine.Snapshot<States>,
|
|
1253
|
-
Machine.EventOf<InputEvents>,
|
|
1254
|
-
E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
|
|
1255
|
-
ExcludeCompatibleRuntime<
|
|
1256
|
-
Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>,
|
|
1257
|
-
Machine.EventOf<Events>,
|
|
1258
|
-
Machine.EmitOf<Emits>
|
|
1259
|
-
>,
|
|
1260
|
-
Output,
|
|
1261
|
-
| InitialE
|
|
1262
|
-
| E
|
|
1263
|
-
| ActionError<InitialR | R>
|
|
1264
|
-
| InfiniteTransitionError
|
|
1265
|
-
| MachineSchemaDecodeError
|
|
1266
|
-
| StartupError
|
|
1267
|
-
| StoppedError,
|
|
1268
|
-
Machine.EmitOf<Emits>
|
|
1269
|
-
>
|
|
1270
|
-
} = ((config: {
|
|
1271
|
-
readonly child: ChildMachine.Any
|
|
1272
|
-
readonly input?: unknown
|
|
1273
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<any, any, any>) => unknown
|
|
1274
|
-
readonly onDone?: (context: Machine.InvokeDoneContext<any>) => unknown
|
|
1275
|
-
}) => {
|
|
1276
|
-
const machine = config.child.machine
|
|
1277
|
-
// An invoke descriptor fixes both its machine and input. Compile its process
|
|
1278
|
-
// logic once; all mutable execution state belongs to the process instance.
|
|
1279
|
-
const logic = machine.input === undefined
|
|
1280
|
-
? (internalProcess.toProcessLogic as any)(machine)
|
|
1281
|
-
: (internalProcess.toProcessLogic as any)(machine, config.input)
|
|
1282
|
-
return {
|
|
1283
|
-
id: config.child.id,
|
|
1284
|
-
address: config.child.id,
|
|
1285
|
-
descriptor: config.child,
|
|
1286
|
-
src: () => logic,
|
|
1287
|
-
snapshot: config.snapshot,
|
|
1288
|
-
onDone: config.onDone,
|
|
1289
|
-
[Activities.ActivityMetadataTypeId]: {
|
|
1290
|
-
type: "machine",
|
|
1291
|
-
child: {
|
|
1292
|
-
id: config.child.id,
|
|
1293
|
-
machineId: machine.id ?? null
|
|
1294
|
-
}
|
|
1295
|
-
},
|
|
1296
|
-
[InvokeTypeId]: undefined as any
|
|
1297
|
-
}
|
|
1298
|
-
}) as any
|
|
1299
|
-
|
|
1300
994
|
export const planInitial: <
|
|
1301
995
|
const States extends Machine.StateSchemas,
|
|
1302
996
|
const Events extends ReadonlyArray<Machine.TaggedSchema>,
|
|
@@ -1494,7 +1188,7 @@ export const plan: <
|
|
|
1494
1188
|
>
|
|
1495
1189
|
& EnsureExecutable<States, UnhandledStates, OutputStates>,
|
|
1496
1190
|
state: Machine.Snapshot<States>,
|
|
1497
|
-
event: Machine.
|
|
1191
|
+
event: Machine.EventInputOf<InputEvents>
|
|
1498
1192
|
) => Effect.Effect<
|
|
1499
1193
|
& {
|
|
1500
1194
|
readonly next: Machine.Snapshot<States>
|
|
@@ -1532,13 +1226,6 @@ export const plan: <
|
|
|
1532
1226
|
never
|
|
1533
1227
|
> = internalPlanner.plan as any
|
|
1534
1228
|
|
|
1535
|
-
export const effect = <Output, Error = never, Requirements = never>(
|
|
1536
|
-
effect: Effect.Effect<Output, Error, Requirements>
|
|
1537
|
-
): Logic<void, never, Error, Requirements, Output> => ({
|
|
1538
|
-
initial: () => Effect.void,
|
|
1539
|
-
run: () => effect
|
|
1540
|
-
})
|
|
1541
|
-
|
|
1542
1229
|
export const logic = <
|
|
1543
1230
|
State,
|
|
1544
1231
|
Event = never,
|
|
@@ -1587,7 +1274,11 @@ export const child = <const Id extends string, M extends Machine.Any>(
|
|
|
1587
1274
|
): ChildMachine<Id, M> => ({
|
|
1588
1275
|
[ChildMachineTypeId]: ChildMachineTypeId,
|
|
1589
1276
|
id,
|
|
1590
|
-
machine
|
|
1277
|
+
machine,
|
|
1278
|
+
[ChildMachineLogicTypeId]: (input) =>
|
|
1279
|
+
machine.input === undefined
|
|
1280
|
+
? (internalProcess.toProcessLogic as any)(machine)
|
|
1281
|
+
: (internalProcess.toProcessLogic as any)(machine, input)
|
|
1591
1282
|
})
|
|
1592
1283
|
|
|
1593
1284
|
export const childAddress = <Event = never>(id: string): ChildAddress<Event> => id as ChildAddress<Event>
|
|
@@ -1703,13 +1394,14 @@ export const start: <
|
|
|
1703
1394
|
) => Effect.Effect<
|
|
1704
1395
|
MachineRef<
|
|
1705
1396
|
Machine.Snapshot<States>,
|
|
1706
|
-
Machine.
|
|
1397
|
+
Machine.EventInputOf<InputEvents>,
|
|
1707
1398
|
| E
|
|
1708
1399
|
| ActionError<R>
|
|
1709
1400
|
| InfiniteTransitionError
|
|
1710
1401
|
| MachineSchemaDecodeError
|
|
1711
1402
|
| StoppedError,
|
|
1712
|
-
Output
|
|
1403
|
+
Output,
|
|
1404
|
+
Machine.EmittedEventOf<Emits>
|
|
1713
1405
|
>,
|
|
1714
1406
|
| InitialE
|
|
1715
1407
|
| E
|
|
@@ -1761,13 +1453,14 @@ export const resume: <
|
|
|
1761
1453
|
) => Effect.Effect<
|
|
1762
1454
|
MachineRef<
|
|
1763
1455
|
Machine.Snapshot<States>,
|
|
1764
|
-
Machine.
|
|
1456
|
+
Machine.EventInputOf<InputEvents>,
|
|
1765
1457
|
| E
|
|
1766
1458
|
| ActionError<R>
|
|
1767
1459
|
| InfiniteTransitionError
|
|
1768
1460
|
| MachineSchemaDecodeError
|
|
1769
1461
|
| StoppedError,
|
|
1770
|
-
Output
|
|
1462
|
+
Output,
|
|
1463
|
+
Machine.EmittedEventOf<Emits>
|
|
1771
1464
|
>,
|
|
1772
1465
|
MachineSchemaDecodeError,
|
|
1773
1466
|
ExcludeCompatibleRuntime<
|