@typeonce/effect-machine 0.38.1 → 0.39.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.
Files changed (61) hide show
  1. package/README.md +42 -35
  2. package/dist/Machine.d.ts +62 -88
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +11 -24
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/atom.d.ts.map +1 -1
  7. package/dist/internal/machine/atom.js.map +1 -1
  8. package/dist/internal/machine/declaration.d.ts +10 -3
  9. package/dist/internal/machine/declaration.d.ts.map +1 -1
  10. package/dist/internal/machine/declaration.js +47 -16
  11. package/dist/internal/machine/declaration.js.map +1 -1
  12. package/dist/internal/machine/errors.d.ts +15 -1
  13. package/dist/internal/machine/errors.d.ts.map +1 -1
  14. package/dist/internal/machine/errors.js +10 -0
  15. package/dist/internal/machine/errors.js.map +1 -1
  16. package/dist/internal/machine/initialDeclaration.d.ts +2 -2
  17. package/dist/internal/machine/initialDeclaration.d.ts.map +1 -1
  18. package/dist/internal/machine/initialDeclaration.js +8 -9
  19. package/dist/internal/machine/initialDeclaration.js.map +1 -1
  20. package/dist/internal/machine/machine.d.ts +26 -76
  21. package/dist/internal/machine/machine.d.ts.map +1 -1
  22. package/dist/internal/machine/machine.js +21 -16
  23. package/dist/internal/machine/machine.js.map +1 -1
  24. package/dist/internal/machine/planner.d.ts +216 -31
  25. package/dist/internal/machine/planner.d.ts.map +1 -1
  26. package/dist/internal/machine/planner.js +6 -12
  27. package/dist/internal/machine/planner.js.map +1 -1
  28. package/dist/internal/machine/process.d.ts +5 -9
  29. package/dist/internal/machine/process.d.ts.map +1 -1
  30. package/dist/internal/machine/process.js +19 -32
  31. package/dist/internal/machine/process.js.map +1 -1
  32. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  33. package/dist/internal/testing/machine/finiteModel.js +9 -12
  34. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  35. package/dist/testing/MachineTest.d.ts +7 -7
  36. package/dist/testing/MachineTest.js +7 -7
  37. package/dist/unstable/cluster/ClusterMachine.d.ts +1 -1
  38. package/dist/unstable/cluster/ClusterMachine.js +1 -1
  39. package/dist/unstable/reactivity/AtomMachine.d.ts +3 -3
  40. package/dist/unstable/reactivity/AtomMachine.js +3 -3
  41. package/docs/agent-guide.md +23 -30
  42. package/docs/machine-review.md +5 -6
  43. package/docs/root-api.md +27 -19
  44. package/package.json +1 -1
  45. package/src/Machine.ts +125 -163
  46. package/src/internal/machine/atom.ts +4 -7
  47. package/src/internal/machine/declaration.ts +56 -17
  48. package/src/internal/machine/errors.ts +22 -1
  49. package/src/internal/machine/initialDeclaration.ts +10 -12
  50. package/src/internal/machine/machine.ts +85 -465
  51. package/src/internal/machine/planner.ts +84 -190
  52. package/src/internal/machine/process.ts +80 -279
  53. package/src/internal/testing/machine/finiteModel.ts +7 -11
  54. package/src/testing/MachineTest.ts +7 -7
  55. package/src/unstable/cluster/ClusterMachine.ts +1 -1
  56. package/src/unstable/reactivity/AtomMachine.ts +3 -3
  57. package/dist/internal/machine/targetReference.d.ts +0 -15
  58. package/dist/internal/machine/targetReference.d.ts.map +0 -1
  59. package/dist/internal/machine/targetReference.js +0 -41
  60. package/dist/internal/machine/targetReference.js.map +0 -1
  61. package/src/internal/machine/targetReference.ts +0 -55
@@ -7,13 +7,9 @@ import * as Schema from "effect/Schema"
7
7
  import type * as Scope from "effect/Scope"
8
8
  import type * as Stream from "effect/Stream"
9
9
  import type {
10
- ActionError,
11
10
  ChildAddress,
12
11
  ChildMachine,
13
- Command,
14
12
  Definition,
15
- ExecutionServices,
16
- InitialEvent as InitialEventModel,
17
13
  Logic,
18
14
  Machine,
19
15
  MachineRef,
@@ -30,7 +26,7 @@ import * as Activities from "./activities.js"
30
26
  import * as Configuration from "./configuration.js"
31
27
  import * as Construction from "./construction.js"
32
28
  import * as Declaration from "./declaration.js"
33
- import type { ChildAlreadyExistsError, InfiniteTransitionError, StartupError } from "./errors.js"
29
+ import type { ChildAlreadyExistsError, PlanningError, StartupError } from "./errors.js"
34
30
  import type { CapturedStateConfig } from "./implementation.js"
35
31
  import * as InitialDeclaration from "./initialDeclaration.js"
36
32
  import * as InvocationDefinition from "./invocationDefinition.js"
@@ -38,13 +34,10 @@ import * as Observation from "./observation.js"
38
34
  import * as internalPlanner from "./planner.js"
39
35
  import * as internalProcess from "./process.js"
40
36
  import * as Protocol from "./protocol.js"
41
- import type { EnsureExecutable } from "./readiness.js"
42
- import type { ExcludeCompatibleRuntime } from "./requirements.js"
43
37
  import * as internalRuntime from "./runtimeProtocol.js"
44
38
  import * as Serialization from "./serialization.js"
45
39
  import * as StateDefinition from "./stateDefinition.js"
46
40
  import { ChildMachineLogicTypeId } from "./symbols.js"
47
- import * as TargetReference from "./targetReference.js"
48
41
  import * as Topology from "./topology.js"
49
42
 
50
43
  export {
@@ -59,9 +52,6 @@ export {
59
52
  export { ChildMachineLogicTypeId, InitialEventTypeId, SnapshotBuilderStateTypeId } from "./symbols.js"
60
53
 
61
54
  /** Internal seam for the public target-reference factory and its opaque brand. */
62
- export const TargetReferenceTypeId: typeof TargetReference.TypeId = TargetReference.TypeId
63
- export const targets: (root: State<Machine.StateNodeConfig>) => { readonly root: TargetReference.Reference } =
64
- TargetReference.make
65
55
 
66
56
  const TypeId = "~effect/Machine"
67
57
  const ParentTypeId = "~effect/Machine/Parent"
@@ -317,7 +307,7 @@ const constructBranch = (
317
307
  if (selection.kind === "update") return Construction.update(stateNodes, selection.path!, config)
318
308
  if (selection.path === "") {
319
309
  if (Reflect.ownKeys(config).some((key) => key !== "input")) {
320
- throw new Error("Machine root targets accept input only")
310
+ throw new Error("Machine initialize branches accept input only")
321
311
  }
322
312
  if (declaration.initialize === undefined) throw new Error("Machine root initialization is unavailable")
323
313
  return declaration.initialize(config.input)
@@ -386,7 +376,7 @@ const normalizeObjectTransition = (
386
376
  const allowed = [
387
377
  "target",
388
378
  "update",
389
- "input",
379
+ "initialize",
390
380
  "history",
391
381
  "none",
392
382
  "branches",
@@ -425,7 +415,7 @@ const normalizeObjectTransition = (
425
415
  throw new Error("Machine branching transition requires a registered group and resolver")
426
416
  }
427
417
  if (
428
- ["target", "update", "input", "history", "none", "data", "decoded"].some((key) => config[key] !== undefined)
418
+ ["target", "update", "initialize", "history", "none", "data", "decoded"].some((key) => config[key] !== undefined)
429
419
  ) throw new Error("Machine branching transition cannot redeclare its destination")
430
420
  const entries = Object.fromEntries(
431
421
  Object.entries(group).map(([key, spec]) => [key, {
@@ -452,14 +442,19 @@ const normalizeObjectTransition = (
452
442
  if (resolve !== undefined && selection.kind !== "none") {
453
443
  throw new Error("Machine advanced construction requires a declared branch group")
454
444
  }
455
- const input = config.input
456
- const constructInput = typeof input === "function" ? input : () => input
457
- if (selection.path !== "" && Object.hasOwn(config, "input")) {
458
- throw new Error("Machine input belongs only to root targets")
445
+ const initialize = config.initialize
446
+ const initializes = initialize !== undefined
447
+ if (initializes && (hasData || config.decoded !== undefined)) {
448
+ throw new Error("Machine initialize accepts machine input instead of data")
459
449
  }
460
- if (selection.path === "" && selection.kind !== "update" && (hasData || config.decoded !== undefined)) {
461
- throw new Error("Machine root targets accept input instead of data")
450
+ if (initializes && !declaration.input && initialize !== true) {
451
+ throw new Error("Machine initialize requires true when the machine declares no input")
462
452
  }
453
+ const constructInput = !declaration.input
454
+ ? () => undefined
455
+ : typeof initialize === "function"
456
+ ? initialize
457
+ : () => initialize
463
458
  return {
464
459
  target: () => selection,
465
460
  reenter: config.reenter,
@@ -467,7 +462,7 @@ const normalizeObjectTransition = (
467
462
  resolve: (context: Record<string, any>, enqueue: unknown) => {
468
463
  if (guarded && !guard(context)) return Topology.makeDeclined()
469
464
  if (resolve !== undefined) return resolve(context, enqueue)
470
- if (selection.path === "" && selection.kind !== "update") {
465
+ if (initializes) {
471
466
  return constructBranch(selection, stateNodes, declaration, { input: constructInput(context) })
472
467
  }
473
468
  const value = construct(context)
@@ -733,7 +728,10 @@ const makeHandle = (self: Definition.Any, declaration: Declaration.Declaration):
733
728
  const handlers: Record<PropertyKey, CapturedStateConfig> = Object.create(null)
734
729
  flattenHandlers(handlers, compiled.stateNodes, compiled.states, "", {
735
730
  ...declaration,
736
- initialize: (input) => compiled.initial(Protocol.decodeInputSync(compiled, compiled.input, input))
731
+ initialize: (input) =>
732
+ compiled.initial(
733
+ compiled.input === undefined ? undefined : Protocol.decodeInputSync(compiled, compiled.input, input)
734
+ )
737
735
  }, { "": captured.handlers })
738
736
  return makeWithHandlers(compiled, handlers)
739
737
  }) as Definition.Any["handle"]
@@ -742,38 +740,11 @@ export const isMachine = (
742
740
  u: unknown
743
741
  ): u is Machine.Any => hasProperty(u, TypeId) && u[TypeId] === TypeId
744
742
 
745
- export const isFinal = <
746
- const States extends Machine.StateSchemas,
747
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
748
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
749
- const Input extends Schema.Top = typeof Schema.Void,
750
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
751
- E = never,
752
- R = never,
753
- InitialE = never,
754
- InitialR = never,
755
- FinalStates extends Machine.StateIdentifier<States> = never,
756
- Output = never,
757
- OutputStates extends Machine.StateIdentifier<States> = never,
758
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
759
- >(
760
- machine: Machine<
761
- States,
762
- Events,
763
- Input,
764
- UnhandledStates,
765
- E,
766
- R,
767
- InitialE,
768
- InitialR,
769
- FinalStates,
770
- Output,
771
- Emits,
772
- OutputStates,
773
- InputEvents
774
- >,
775
- state: Machine.Snapshot<States>
776
- ): state is Machine.SnapshotContainingFinal<States, FinalStates> => internalPlanner.isFinal(machine as any, state)
743
+ // Erased machine operations. `any` marks the positions whose types the public
744
+ // `Machine` module computes from the machine's generic parameters; the public
745
+ // module specializes each operation without a cast.
746
+
747
+ export const isFinal: (machine: Machine.Any, state: any) => state is any = internalPlanner.isFinal
777
748
 
778
749
  export const state = (node: unknown): State<Machine.StateNodeConfig> => {
779
750
  const captured = StateDefinition.captureRoot(node) as Machine.StateNodeConfig
@@ -806,54 +777,23 @@ const makeStateHelpers = (): Machine.StateAccessors<{ readonly "": Machine.State
806
777
  }
807
778
  }
808
779
 
809
- type MakeResult<
810
- States extends Machine.StateSchemas,
811
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
812
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
813
- Input extends Schema.Top,
814
- InitialE,
815
- InitialR,
816
- InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
817
- ParentDeclaration extends Parent.Any | undefined
818
- > = Definition<
819
- States,
820
- readonly [...InputEvents, ...InternalEvents],
821
- Input,
822
- InitialE,
823
- InitialR,
824
- Machine.FinalStateFromDefinition<States>,
825
- Machine.TerminalOutput<States>,
826
- Emits,
827
- InputEvents,
828
- Machine.ParentEventsOf<ParentDeclaration>
829
- >
830
-
831
- export const make = <
832
- const States extends Machine.StateSchemas,
833
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
834
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
835
- const Input extends Schema.Top = typeof Schema.Void,
836
- InitialE = never,
837
- InitialR = never,
838
- const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
839
- const ParentDeclaration extends Parent.Any | undefined = undefined
840
- >(
780
+ export const make = (
841
781
  config: {
842
782
  readonly id?: string
843
- readonly root: State<Machine.StateNodeConfig>
783
+ readonly root: Machine.Any["root"]
844
784
  readonly effects?: unknown
845
785
  readonly streams?: unknown
846
786
  readonly timers?: unknown
847
787
  readonly logic?: unknown
848
788
  readonly children?: unknown
849
789
  readonly branches?: unknown
850
- readonly events: Machine.EventProtocol<"public", InputEvents>
851
- readonly internalEvents?: Machine.EventProtocol<"internal", InternalEvents>
852
- readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>
853
- readonly parent?: ParentDeclaration
854
- readonly input?: Input
790
+ readonly events: Machine.EventProtocol<"public", any>
791
+ readonly internalEvents?: Machine.EventProtocol<"internal", any>
792
+ readonly emittedEvents?: Machine.EventProtocol<"emitted", any>
793
+ readonly parent?: Parent.Any | undefined
794
+ readonly input?: Schema.Top
855
795
  }
856
- ): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration> => {
796
+ ): any => {
857
797
  if (Object.hasOwn(config, "initial") || Object.hasOwn(config, "initialConfiguration")) {
858
798
  throw new Error("Machine initial edges and root data belong in handle")
859
799
  }
@@ -900,12 +840,15 @@ const eventFieldSchemas = (
900
840
  return Object.keys(cases).length === 0 ? [] : [Schema.TaggedUnion(cases)]
901
841
  }
902
842
 
903
- export const eventsFromFields = (cases: Readonly<Record<string, Schema.Struct.Fields>>) =>
904
- Protocol.makeEventProtocol("public", eventFieldSchemas(cases))
905
- export const internalEventsFromFields = (cases: Readonly<Record<string, Schema.Struct.Fields>>) =>
906
- Protocol.makeEventProtocol("internal", eventFieldSchemas(cases))
907
- export const emittedEventsFromFields = (cases: Readonly<Record<string, Schema.Struct.Fields>>) =>
908
- Protocol.makeEventProtocol("emitted", eventFieldSchemas(cases))
843
+ export const eventsFromFields = (
844
+ cases: Readonly<Record<string, Schema.Struct.Fields>>
845
+ ): Machine.EventProtocol<"public", any> => Protocol.makeEventProtocol("public", eventFieldSchemas(cases))
846
+ export const internalEventsFromFields = (
847
+ cases: Readonly<Record<string, Schema.Struct.Fields>>
848
+ ): Machine.EventProtocol<"internal", any> => Protocol.makeEventProtocol("internal", eventFieldSchemas(cases))
849
+ export const emittedEventsFromFields = (
850
+ cases: Readonly<Record<string, Schema.Struct.Fields>>
851
+ ): Machine.EventProtocol<"emitted", any> => Protocol.makeEventProtocol("emitted", eventFieldSchemas(cases))
909
852
 
910
853
  const makeParent = <
911
854
  const Mode extends ParentMode,
@@ -944,151 +887,20 @@ export const emittedEvents = <const Inputs extends ReadonlyArray<Machine.EventPr
944
887
  flattenEventProtocolInputs("emitted", inputs)
945
888
  ) as Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>>
946
889
 
947
- export const encodeSnapshot: <
948
- const States extends Machine.StateSchemas,
949
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
950
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
951
- const Input extends Schema.Top = typeof Schema.Void,
952
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
953
- E = never,
954
- R = never,
955
- InitialE = never,
956
- InitialR = never,
957
- FinalStates extends Machine.StateIdentifier<States> = never,
958
- Output = never,
959
- OutputStates extends Machine.StateIdentifier<States> = never,
960
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
961
- >(
962
- machine: Machine<
963
- States,
964
- Events,
965
- Input,
966
- UnhandledStates,
967
- E,
968
- R,
969
- InitialE,
970
- InitialR,
971
- FinalStates,
972
- Output,
973
- Emits,
974
- OutputStates,
975
- InputEvents
976
- >,
977
- snapshot: Machine.Snapshot<States>
978
- ) => Effect.Effect<
979
- Machine.EncodedSnapshot,
980
- MachineSchemaEncodeError,
981
- Machine.SnapshotEncodingServices<States>
982
- > = Serialization.encodeSnapshot as any
983
-
984
- export const decodeSnapshot: <
985
- const States extends Machine.StateSchemas,
986
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
987
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
988
- const Input extends Schema.Top = typeof Schema.Void,
989
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
990
- E = never,
991
- R = never,
992
- InitialE = never,
993
- InitialR = never,
994
- FinalStates extends Machine.StateIdentifier<States> = never,
995
- Output = never,
996
- OutputStates extends Machine.StateIdentifier<States> = never,
997
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
998
- >(
999
- machine: Machine<
1000
- States,
1001
- Events,
1002
- Input,
1003
- UnhandledStates,
1004
- E,
1005
- R,
1006
- InitialE,
1007
- InitialR,
1008
- FinalStates,
1009
- Output,
1010
- Emits,
1011
- OutputStates,
1012
- InputEvents
1013
- >,
890
+ export const encodeSnapshot: (
891
+ machine: Machine.Any,
892
+ snapshot: any
893
+ ) => Effect.Effect<Machine.EncodedSnapshot, MachineSchemaEncodeError, any> = Serialization.encodeSnapshot
894
+
895
+ export const decodeSnapshot: (
896
+ machine: Machine.Any,
1014
897
  encoded: unknown
1015
- ) => Effect.Effect<
1016
- Machine.Snapshot<States>,
1017
- MachineSchemaDecodeError,
1018
- Machine.SnapshotDecodingServices<States>
1019
- > = Serialization.decodeSnapshot as any
1020
-
1021
- export const planInitial: <
1022
- const States extends Machine.StateSchemas,
1023
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
1024
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
1025
- const Input extends Schema.Top = typeof Schema.Void,
1026
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
1027
- E = never,
1028
- R = never,
1029
- InitialE = never,
1030
- InitialR = never,
1031
- FinalStates extends Machine.StateIdentifier<States> = never,
1032
- Output = never,
1033
- OutputStates extends Machine.StateIdentifier<States> = never,
1034
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
1035
- >(
1036
- machine:
1037
- & Machine<
1038
- States,
1039
- Events,
1040
- Input,
1041
- UnhandledStates,
1042
- E,
1043
- R,
1044
- InitialE,
1045
- InitialR,
1046
- FinalStates,
1047
- Output,
1048
- Emits,
1049
- OutputStates,
1050
- InputEvents
1051
- >
1052
- & EnsureExecutable<States, UnhandledStates, OutputStates>,
1053
- ...args: [...Machine.InputArgs<Input>]
1054
- ) => Effect.Effect<
1055
- & {
1056
- readonly startingState: Machine.Snapshot<States>
1057
- readonly initialEntryPaths: ReadonlyArray<Machine.StateIdentifier<States>>
1058
- readonly state: Machine.Snapshot<States>
1059
- readonly commands: ReadonlyArray<Command>
1060
- readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>
1061
- readonly microsteps: ReadonlyArray<{
1062
- readonly next: Machine.Snapshot<States>
1063
- readonly event: Machine.EventOf<Events> | InitialEventModel
1064
- readonly transitions: ReadonlyArray<
1065
- Machine.RetainedTransition<
1066
- Machine.StateNodeIdentifier<States>,
1067
- Machine.TagOf<Events[number]>,
1068
- Machine.StateNodeIdentifier<States>
1069
- >
1070
- >
1071
- readonly commands: ReadonlyArray<Command>
1072
- readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>
1073
- readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>
1074
- readonly exitPaths: ReadonlyArray<string>
1075
- readonly entryPaths: ReadonlyArray<string>
1076
- readonly changed: boolean
1077
- }>
1078
- }
1079
- & (
1080
- | {
1081
- readonly done: true
1082
- readonly output: Output
1083
- }
1084
- | {
1085
- readonly done: false
1086
- readonly output: undefined
1087
- }
1088
- ),
1089
- InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError,
1090
- never
1091
- > = internalPlanner.planInitial as any
898
+ ) => Effect.Effect<any, MachineSchemaDecodeError, any> = Serialization.decodeSnapshot
899
+
900
+ export const planInitial: (
901
+ machine: Machine.Any,
902
+ ...args: ReadonlyArray<any>
903
+ ) => Effect.Effect<any, PlanningError | StartupError> = internalPlanner.planInitial
1092
904
 
1093
905
  export const stateNodes = <M extends Machine.Any>(
1094
906
  machine: M
@@ -1162,111 +974,18 @@ export const configuration = <M extends Machine.Any>(
1162
974
  )
1163
975
  }
1164
976
 
1165
- export const enabled = <
1166
- const States extends Machine.StateSchemas,
1167
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
1168
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
1169
- const Input extends Schema.Top = typeof Schema.Void,
1170
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
1171
- E = never,
1172
- R = never,
1173
- InitialE = never,
1174
- InitialR = never,
1175
- FinalStates extends Machine.StateIdentifier<States> = never,
1176
- Output = never,
1177
- OutputStates extends Machine.StateIdentifier<States> = never,
1178
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
1179
- >(
1180
- machine: Machine<
1181
- States,
1182
- Events,
1183
- Input,
1184
- UnhandledStates,
1185
- E,
1186
- R,
1187
- InitialE,
1188
- InitialR,
1189
- FinalStates,
1190
- Output,
1191
- Emits,
1192
- OutputStates,
1193
- InputEvents
1194
- >,
1195
- state: Machine.Snapshot<States>
1196
- ): ReadonlyArray<Machine.TagOf<Events[number]>> => internalPlanner.enabled(machine as any, state)
1197
-
1198
- export const can = internalPlanner.can
1199
-
1200
- export const plan: <
1201
- const States extends Machine.StateSchemas,
1202
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
1203
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
1204
- const Input extends Schema.Top = typeof Schema.Void,
1205
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
1206
- E = never,
1207
- R = never,
1208
- InitialE = never,
1209
- InitialR = never,
1210
- FinalStates extends Machine.StateIdentifier<States> = never,
1211
- Output = never,
1212
- OutputStates extends Machine.StateIdentifier<States> = never,
1213
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
1214
- >(
1215
- machine:
1216
- & Machine<
1217
- States,
1218
- Events,
1219
- Input,
1220
- UnhandledStates,
1221
- E,
1222
- R,
1223
- InitialE,
1224
- InitialR,
1225
- FinalStates,
1226
- Output,
1227
- Emits,
1228
- OutputStates,
1229
- InputEvents
1230
- >
1231
- & EnsureExecutable<States, UnhandledStates, OutputStates>,
1232
- state: Machine.Snapshot<States>,
1233
- event: Machine.EventInputOf<InputEvents>
1234
- ) => Effect.Effect<
1235
- & {
1236
- readonly next: Machine.Snapshot<States>
1237
- readonly commands: ReadonlyArray<Command>
1238
- readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>
1239
- readonly microsteps: ReadonlyArray<{
1240
- readonly next: Machine.Snapshot<States>
1241
- readonly event: Machine.EventOf<Events> | InitialEventModel
1242
- readonly transitions: ReadonlyArray<
1243
- Machine.RetainedTransition<
1244
- Machine.StateNodeIdentifier<States>,
1245
- Machine.TagOf<Events[number]>,
1246
- Machine.StateNodeIdentifier<States>
1247
- >
1248
- >
1249
- readonly commands: ReadonlyArray<Command>
1250
- readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>
1251
- readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>
1252
- readonly exitPaths: ReadonlyArray<string>
1253
- readonly entryPaths: ReadonlyArray<string>
1254
- readonly changed: boolean
1255
- }>
1256
- }
1257
- & (
1258
- | {
1259
- readonly done: true
1260
- readonly output: Output
1261
- }
1262
- | {
1263
- readonly done: false
1264
- readonly output: undefined
1265
- }
1266
- ),
1267
- E | InfiniteTransitionError | MachineSchemaDecodeError,
1268
- never
1269
- > = internalPlanner.plan as any
977
+ export const enabled: (machine: Machine.Any, state: any) => ReadonlyArray<any> = internalPlanner.enabled
978
+
979
+ export const can: {
980
+ (machine: Machine.Any): (state: any, event: any) => Effect.Effect<boolean, MachineSchemaDecodeError>
981
+ (machine: Machine.Any, state: any, event: any): Effect.Effect<boolean, MachineSchemaDecodeError>
982
+ } = internalPlanner.can
983
+
984
+ export const plan: (
985
+ machine: Machine.Any,
986
+ state: any,
987
+ event: any
988
+ ) => Effect.Effect<any, PlanningError> = internalPlanner.plan
1270
989
 
1271
990
  export const logic = <
1272
991
  State,
@@ -1316,8 +1035,8 @@ export const child = <const Id extends string, M extends Machine.Any>(
1316
1035
  ): ChildMachine<Id, M> =>
1317
1036
  makeChild(id, machine, (input) =>
1318
1037
  machine.input === undefined
1319
- ? (internalProcess.toProcessLogic as any)(machine)
1320
- : (internalProcess.toProcessLogic as any)(machine, input))
1038
+ ? internalProcess.toProcessLogic(machine)
1039
+ : internalProcess.toProcessLogic(machine, input))
1321
1040
 
1322
1041
  const makeChild = <const Id extends string, M extends Machine.Any>(
1323
1042
  id: Id,
@@ -1333,8 +1052,8 @@ const makeChild = <const Id extends string, M extends Machine.Any>(
1333
1052
  export const childFamily = <M extends Machine.Any>(machine: M): ChildMachine.Family<M> => {
1334
1053
  const makeLogic = (input?: unknown): Logic<any, any, any, any, any, any> =>
1335
1054
  machine.input === undefined
1336
- ? (internalProcess.toProcessLogic as any)(machine)
1337
- : (internalProcess.toProcessLogic as any)(machine, input)
1055
+ ? internalProcess.toProcessLogic(machine)
1056
+ : internalProcess.toProcessLogic(machine, input)
1338
1057
  return (id) => makeChild(id, machine, makeLogic)
1339
1058
  }
1340
1059
 
@@ -1414,116 +1133,17 @@ export const watch = <State, Event, Error = never, Output = never>(
1414
1133
 
1415
1134
  export const waitFor = Observation.waitFor
1416
1135
 
1417
- export const prepare = internalProcess.prepare
1418
-
1419
- export const start: <
1420
- const States extends Machine.StateSchemas,
1421
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
1422
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
1423
- const Input extends Schema.Top = typeof Schema.Void,
1424
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
1425
- E = never,
1426
- R = never,
1427
- InitialE = never,
1428
- InitialR = never,
1429
- FinalStates extends Machine.StateIdentifier<States> = never,
1430
- Output = never,
1431
- OutputStates extends Machine.StateIdentifier<States> = never,
1432
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
1433
- >(
1434
- machine:
1435
- & Machine<
1436
- States,
1437
- Events,
1438
- Input,
1439
- UnhandledStates,
1440
- E,
1441
- R,
1442
- InitialE,
1443
- InitialR,
1444
- FinalStates,
1445
- Output,
1446
- Emits,
1447
- OutputStates,
1448
- InputEvents
1449
- >
1450
- & EnsureExecutable<States, UnhandledStates, OutputStates>,
1451
- ...args: [...Machine.InputArgs<Input>]
1452
- ) => Effect.Effect<
1453
- MachineRef<
1454
- Machine.Snapshot<States>,
1455
- Machine.EventInputOf<InputEvents>,
1456
- | E
1457
- | ActionError<R>
1458
- | InfiniteTransitionError
1459
- | MachineSchemaDecodeError
1460
- | StoppedError,
1461
- Output,
1462
- Machine.EmittedEventOf<Emits>
1463
- >,
1464
- | InitialE
1465
- | E
1466
- | ActionError<InitialR | R>
1467
- | InfiniteTransitionError
1468
- | MachineSchemaDecodeError
1469
- | StartupError
1470
- | StoppedError,
1471
- ExcludeCompatibleRuntime<
1472
- ExecutionServices<InitialR | R>,
1473
- Machine.EventOf<Events>,
1474
- Machine.EmittedEventOf<Emits>
1475
- >
1476
- > = internalProcess.start as any
1477
-
1478
- export const resume: <
1479
- const States extends Machine.StateSchemas,
1480
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
1481
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
1482
- const Input extends Schema.Top = typeof Schema.Void,
1483
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
1484
- E = never,
1485
- R = never,
1486
- InitialE = never,
1487
- InitialR = never,
1488
- FinalStates extends Machine.StateIdentifier<States> = never,
1489
- Output = never,
1490
- OutputStates extends Machine.StateIdentifier<States> = never,
1491
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
1492
- >(
1493
- machine:
1494
- & Machine<
1495
- States,
1496
- Events,
1497
- Input,
1498
- UnhandledStates,
1499
- E,
1500
- R,
1501
- InitialE,
1502
- InitialR,
1503
- FinalStates,
1504
- Output,
1505
- Emits,
1506
- OutputStates,
1507
- InputEvents
1508
- >
1509
- & EnsureExecutable<States, UnhandledStates, OutputStates>,
1510
- snapshot: Machine.Snapshot<States>
1511
- ) => Effect.Effect<
1512
- MachineRef<
1513
- Machine.Snapshot<States>,
1514
- Machine.EventInputOf<InputEvents>,
1515
- | E
1516
- | ActionError<R>
1517
- | InfiniteTransitionError
1518
- | MachineSchemaDecodeError
1519
- | StoppedError,
1520
- Output,
1521
- Machine.EmittedEventOf<Emits>
1522
- >,
1523
- MachineSchemaDecodeError,
1524
- ExcludeCompatibleRuntime<
1525
- ExecutionServices<R>,
1526
- Machine.EventOf<Events>,
1527
- Machine.EmittedEventOf<Emits>
1528
- >
1529
- > = internalProcess.resume as any
1136
+ export const prepare: (
1137
+ machine: Machine.Any,
1138
+ ...args: ReadonlyArray<any>
1139
+ ) => Effect.Effect<internalRuntime.PreparedProcess<any, any, any, any, any, any, any>> = internalProcess.prepare
1140
+
1141
+ export const start: (
1142
+ machine: Machine.Any,
1143
+ ...args: ReadonlyArray<any>
1144
+ ) => Effect.Effect<MachineRef<any, any, any, any, any>, any, any> = internalProcess.start
1145
+
1146
+ export const resume: (
1147
+ machine: Machine.Any,
1148
+ snapshot: any
1149
+ ) => Effect.Effect<MachineRef<any, any, any, any, any>, MachineSchemaDecodeError, any> = internalProcess.resume