@typeonce/effect-machine 0.7.0 → 0.9.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 (77) hide show
  1. package/README.md +85 -24
  2. package/dist/Machine.d.ts +545 -444
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +69 -172
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/activities.d.ts +5 -12
  7. package/dist/internal/machine/activities.d.ts.map +1 -1
  8. package/dist/internal/machine/activities.js +47 -17
  9. package/dist/internal/machine/activities.js.map +1 -1
  10. package/dist/internal/machine/atom.d.ts +10 -4
  11. package/dist/internal/machine/atom.d.ts.map +1 -1
  12. package/dist/internal/machine/atom.js.map +1 -1
  13. package/dist/internal/machine/configuration.d.ts.map +1 -1
  14. package/dist/internal/machine/configuration.js +103 -20
  15. package/dist/internal/machine/configuration.js.map +1 -1
  16. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  17. package/dist/internal/machine/executionPlan.js +31 -0
  18. package/dist/internal/machine/executionPlan.js.map +1 -1
  19. package/dist/internal/machine/invocation.d.ts +10 -2
  20. package/dist/internal/machine/invocation.d.ts.map +1 -1
  21. package/dist/internal/machine/invocation.js +93 -34
  22. package/dist/internal/machine/invocation.js.map +1 -1
  23. package/dist/internal/machine/invocationEvent.d.ts +39 -0
  24. package/dist/internal/machine/invocationEvent.d.ts.map +1 -0
  25. package/dist/internal/machine/invocationEvent.js +43 -0
  26. package/dist/internal/machine/invocationEvent.js.map +1 -0
  27. package/dist/internal/machine/machine.d.ts +6 -50
  28. package/dist/internal/machine/machine.d.ts.map +1 -1
  29. package/dist/internal/machine/machine.js +30 -81
  30. package/dist/internal/machine/machine.js.map +1 -1
  31. package/dist/internal/machine/planner.d.ts +12 -1
  32. package/dist/internal/machine/planner.d.ts.map +1 -1
  33. package/dist/internal/machine/planner.js +90 -37
  34. package/dist/internal/machine/planner.js.map +1 -1
  35. package/dist/internal/machine/protocol.d.ts +9 -0
  36. package/dist/internal/machine/protocol.d.ts.map +1 -1
  37. package/dist/internal/machine/protocol.js +114 -0
  38. package/dist/internal/machine/protocol.js.map +1 -1
  39. package/dist/internal/machine/serialization.d.ts.map +1 -1
  40. package/dist/internal/machine/serialization.js +53 -21
  41. package/dist/internal/machine/serialization.js.map +1 -1
  42. package/dist/internal/machine/stateDefinition.d.ts +4 -4
  43. package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
  44. package/dist/internal/machine/stateDefinition.js +18 -11
  45. package/dist/internal/machine/stateDefinition.js.map +1 -1
  46. package/dist/internal/machine/symbols.d.ts +2 -0
  47. package/dist/internal/machine/symbols.d.ts.map +1 -1
  48. package/dist/internal/machine/symbols.js +2 -0
  49. package/dist/internal/machine/symbols.js.map +1 -1
  50. package/dist/internal/machine/topology.d.ts +5 -5
  51. package/dist/internal/machine/topology.d.ts.map +1 -1
  52. package/dist/internal/machine/topology.js +39 -13
  53. package/dist/internal/machine/topology.js.map +1 -1
  54. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  55. package/dist/internal/testing/machine/verification.js +10 -3
  56. package/dist/internal/testing/machine/verification.js.map +1 -1
  57. package/dist/unstable/reactivity/AtomMachine.d.ts +11 -5
  58. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  59. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  60. package/docs/agent-guide.md +174 -121
  61. package/package.json +3 -3
  62. package/src/Machine.ts +1336 -872
  63. package/src/internal/machine/activities.ts +48 -33
  64. package/src/internal/machine/atom.ts +13 -6
  65. package/src/internal/machine/configuration.ts +102 -23
  66. package/src/internal/machine/executionPlan.ts +35 -0
  67. package/src/internal/machine/invocation.ts +180 -49
  68. package/src/internal/machine/invocationEvent.ts +72 -0
  69. package/src/internal/machine/machine.ts +105 -403
  70. package/src/internal/machine/planner.ts +110 -48
  71. package/src/internal/machine/protocol.ts +149 -0
  72. package/src/internal/machine/serialization.ts +56 -31
  73. package/src/internal/machine/stateDefinition.ts +22 -11
  74. package/src/internal/machine/symbols.ts +3 -0
  75. package/src/internal/machine/topology.ts +44 -18
  76. package/src/internal/testing/machine/verification.ts +13 -3
  77. package/src/unstable/reactivity/AtomMachine.ts +12 -5
package/src/Machine.ts CHANGED
@@ -49,6 +49,9 @@ export const TypeId: TypeId = "~effect/Machine"
49
49
 
50
50
  declare const MachineOutputStatesTypeId: unique symbol
51
51
  declare const MachineTypeId: unique symbol
52
+ declare const EventConstructionTypeId: unique symbol
53
+
54
+ const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId = internal.ChildMachineLogicTypeId
52
55
 
53
56
  /**
54
57
  * Type identifier used for the synthetic event passed to startup lifecycle
@@ -158,7 +161,8 @@ export interface Machine<
158
161
  readonly events: InputEvents
159
162
 
160
163
  /**
161
- * Events reserved for invokes, child emissions, and other machine-local work.
164
+ * Events reserved for raised events, child emissions, and other machine-local
165
+ * work.
162
166
  *
163
167
  * @since 0.4.0
164
168
  */
@@ -350,7 +354,7 @@ export interface Runtime<in Events, in Emits> {
350
354
  *
351
355
  * @since 0.4.0
352
356
  */
353
- readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
357
+ readonly raise: (event: Machine.EventInput<Events>) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>
354
358
 
355
359
  /**
356
360
  * Emits an event through the running machine's parent boundary.
@@ -370,7 +374,7 @@ export interface Runtime<in Events, in Emits> {
370
374
  */
371
375
  export interface Enqueue<in Events, in Emits> {
372
376
  /** Raises an event inside the current macrostep. */
373
- readonly raise: (event: Events) => void
377
+ readonly raise: (event: Machine.EventInput<Events>) => void
374
378
 
375
379
  /** Emits an event through the machine's parent boundary. */
376
380
  readonly emit: (event: Emits) => void
@@ -558,7 +562,7 @@ type ValidateStateNode<Node, AllowHistory extends boolean, Path extends Property
558
562
  & ValidatePseudoStateAnnotations<Node, Path>
559
563
  & (AllowHistory extends true ? ValidateChoiceStateNode<Node>
560
564
  : StateDefinitionError<"Choice states must be declared below an active parent state", Path>)
561
- : Node extends { readonly schema: Machine.TaggedSchema } ? ValidateStateNodeConfig<Node, Path>
565
+ : Node extends Machine.StateNodeConfig ? ValidateStateNodeConfig<Node, Path>
562
566
  : StateDefinitionError<"State nodes must be tagged schemas or state node configs", Path>
563
567
 
564
568
  type ValidateHistoryStateNode<Node extends Machine.HistoryStateNodeConfig> = [
@@ -572,27 +576,31 @@ type ValidateChoiceStateNode<Node extends Machine.ChoiceStateNodeConfig> = [
572
576
  : StateDefinitionError<"Choice states cannot declare schemas, children, initial states, output, or history">
573
577
 
574
578
  type ValidateStateNodeConfig<
575
- Node extends { readonly schema: Machine.TaggedSchema },
579
+ Node extends Machine.StateNodeConfig,
576
580
  Path extends PropertyKey
577
581
  > = Node extends { readonly type: "parallel" } ?
578
582
  & ValidateExactStateNodeProperties<Node, "parallel", Path>
579
583
  & ValidateStateNodeWithChildren<Node, Node extends { readonly states: infer Children } ? Children : never, Path>
584
+ & ValidatePseudoStateAnnotations<Node, Path>
580
585
  : Node extends { readonly type: "final" } ?
581
586
  & ValidateExactStateNodeProperties<Node, "final", Path>
582
587
  & ValidateStateNodeWithoutChildren<Node>
588
+ & ValidatePseudoStateAnnotations<Node, Path>
583
589
  : Node extends { readonly states: infer Children } ?
584
590
  & ValidateExactStateNodeProperties<Node, "compound", Path>
585
591
  & ValidateStateNodeWithChildren<Node, Children, Path>
592
+ & ValidatePseudoStateAnnotations<Node, Path>
586
593
  :
587
594
  & ValidateExactStateNodeProperties<Node, "atomic", Path>
588
595
  & ValidateStateNodeWithoutChildren<Node>
596
+ & ValidatePseudoStateAnnotations<Node, Path>
589
597
 
590
598
  type ValidateOutputSchema<Node> = "output" extends keyof Node ? Node extends { readonly output: Schema.Top } ? unknown
591
599
  : StateDefinitionError<"State output must be a schema">
592
600
  : unknown
593
601
 
594
602
  type ValidateStateNodeWithChildren<
595
- Node extends { readonly schema: Machine.TaggedSchema },
603
+ Node extends Machine.StateNodeConfig,
596
604
  Children,
597
605
  Path extends PropertyKey
598
606
  > = Children extends Machine.StateSchemas ?
@@ -605,7 +613,7 @@ type ValidateStateNodeWithChildren<
605
613
  : StateDefinitionError<"Child states must be a state tree">
606
614
 
607
615
  type ValidateCompoundStateNode<
608
- Node extends { readonly schema: Machine.TaggedSchema },
616
+ Node extends Machine.StateNodeConfig,
609
617
  Children extends Machine.StateSchemas,
610
618
  Path extends PropertyKey
611
619
  > = Node extends { readonly initial: infer Initial } ?
@@ -615,8 +623,8 @@ type ValidateCompoundStateNode<
615
623
  : StateDefinitionError<"Compound initial must be one of its direct child keys">
616
624
  : StateDefinitionError<"Compound states must declare an initial child">
617
625
 
618
- type ValidateStateNodeWithoutChildren<Node extends { readonly schema: Machine.TaggedSchema }> = "initial" extends
619
- keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child">
626
+ type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ?
627
+ StateDefinitionError<"Atomic states cannot declare an initial child">
620
628
  : Node extends { readonly type: infer Type } ? Type extends "final" ? ValidateOutputSchema<Node>
621
629
  : Type extends "active" | undefined ?
622
630
  "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output">
@@ -722,6 +730,56 @@ type ConstructionResult<Result> = Result | Machine.StateConstruction<Result>
722
730
 
723
731
  type UnwrapConstruction<Result> = Result extends Machine.StateConstruction<infer Value> ? Value : Result
724
732
 
733
+ type NodeValue<Node> = [Machine.NodeSchema<Node>] extends [never] ? undefined
734
+ : Machine.NodeSchema<Node>["Type"]
735
+
736
+ type NodeMakeInput<Node> = [Machine.NodeSchema<Node>] extends [never] ? never
737
+ : Machine.NodeSchema<Node>["~type.make.in"]
738
+
739
+ type WithNodeValue<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest
740
+ : readonly [value: NodeValue<Node>, ...Rest]
741
+
742
+ type WithNodeInput<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest
743
+ : readonly [input: NodeMakeInput<Node>, ...Rest]
744
+
745
+ type NodeBuilderMethod<
746
+ Node,
747
+ Arguments extends ReadonlyArray<unknown>,
748
+ Result,
749
+ FromArguments extends ReadonlyArray<unknown>,
750
+ FromResult
751
+ > = Machine.NodeSchema<Node> extends never ? {
752
+ readonly from: FromCallable<FromArguments, FromResult>
753
+ }
754
+ :
755
+ & ((...args: Arguments) => Result)
756
+ & { readonly from: FromCallable<FromArguments, FromResult> }
757
+
758
+ type NodeMethod<
759
+ Node,
760
+ Arguments extends ReadonlyArray<unknown>,
761
+ Result,
762
+ FromArguments extends ReadonlyArray<unknown>
763
+ > = Machine.NodeSchema<Node> extends never ? FromMethod<FromArguments, Result>
764
+ : ((...args: Arguments) => Result) & FromMethod<FromArguments, Result>
765
+
766
+ type NodeConstructionSelectorFromCallable<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
767
+ <Selected extends ConstructionResult<Result>>(
768
+ state: (builder: Builder) => Selected
769
+ ): Machine.StateConstruction<UnwrapConstruction<Selected>>
770
+ }
771
+ : ConstructionSelectorFromCallable<NodeMakeInput<Node>, Builder, Result>
772
+
773
+ type NestedTargetMethod<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
774
+ readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>
775
+ }
776
+ :
777
+ & (<Selected extends ConstructionResult<Result>>(
778
+ value: NodeValue<Node>,
779
+ state: (builder: Builder) => Selected
780
+ ) => Selected)
781
+ & { readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result> }
782
+
725
783
  type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input ? {
726
784
  <Selected extends ConstructionResult<Result>>(
727
785
  state: (builder: Builder) => Selected
@@ -751,14 +809,18 @@ type InitialSnapshotMethod<
751
809
  States extends Machine.StateSchemas,
752
810
  StateId extends ActiveStateKey<States>,
753
811
  Prefix extends string
754
- > =
755
- & ((
756
- ...args: InitialSnapshotArguments<States, StateId, Prefix>
757
- ) => InitialSnapshotResult<States, StateId, Prefix>)
758
- & FromMethod<
812
+ > = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<
759
813
  InitialSnapshotFromArguments<States, StateId, Prefix>,
760
814
  InitialSnapshotResult<States, StateId, Prefix>
761
815
  >
816
+ :
817
+ & ((
818
+ ...args: InitialSnapshotArguments<States, StateId, Prefix>
819
+ ) => InitialSnapshotResult<States, StateId, Prefix>)
820
+ & FromMethod<
821
+ InitialSnapshotFromArguments<States, StateId, Prefix>,
822
+ InitialSnapshotResult<States, StateId, Prefix>
823
+ >
762
824
 
763
825
  type InitialSnapshotArguments<
764
826
  States extends Machine.StateSchemas,
@@ -766,21 +828,21 @@ type InitialSnapshotArguments<
766
828
  Prefix extends string,
767
829
  Path extends string = Machine.JoinPath<Prefix, StateId>
768
830
  > = States[StateId] extends infer Node ?
769
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ? [
770
- value: Machine.NodeSchema<Node>["Type"],
831
+ Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
832
+ WithNodeValue<Node, [
771
833
  states: (
772
834
  builder: InitialParallelBuilder<Children, Path>
773
835
  ) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>>
774
- ]
836
+ ]>
775
837
  : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
776
- Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ? [
777
- value: Machine.NodeSchema<Node>["Type"],
838
+ Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
839
+ WithNodeValue<Node, [
778
840
  state: (
779
841
  builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>
780
842
  ) => InitialSelectableResult<Children, Initial, Path>
781
- ]
843
+ ]>
782
844
  : never
783
- : [value: Machine.NodeSchema<Node>["Type"]]
845
+ : WithNodeValue<Node, []>
784
846
  : never
785
847
 
786
848
  type InitialSnapshotFromArguments<
@@ -789,21 +851,21 @@ type InitialSnapshotFromArguments<
789
851
  Prefix extends string,
790
852
  Path extends string = Machine.JoinPath<Prefix, StateId>
791
853
  > = States[StateId] extends infer Node ?
792
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ? [
793
- input: Machine.NodeSchema<Node>["~type.make.in"],
854
+ Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
855
+ WithNodeInput<Node, [
794
856
  states: (
795
857
  builder: InitialParallelBuilder<Children, Path>
796
858
  ) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
797
- ]
859
+ ]>
798
860
  : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
799
- Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ? [
800
- input: Machine.NodeSchema<Node>["~type.make.in"],
861
+ Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
862
+ WithNodeInput<Node, [
801
863
  state: (
802
864
  builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>
803
865
  ) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
804
- ]
866
+ ]>
805
867
  : never
806
- : [input: Machine.NodeSchema<Node>["~type.make.in"]]
868
+ : WithNodeInput<Node, []>
807
869
  : never
808
870
 
809
871
  type InitialSnapshotResult<
@@ -815,18 +877,18 @@ type InitialSnapshotResult<
815
877
  Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
816
878
  Machine.ParallelSnapshot<
817
879
  Path,
818
- Machine.NodeSchema<Node>["Type"],
880
+ NodeValue<Node>,
819
881
  InitialSnapshotRegionsWithPrefix<Children, Path>
820
882
  >
821
883
  : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
822
884
  Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
823
885
  Machine.CompoundSnapshot<
824
886
  Path,
825
- Machine.NodeSchema<Node>["Type"],
887
+ NodeValue<Node>,
826
888
  InitialSelectableResult<Children, Initial, Path>
827
889
  >
828
890
  : never
829
- : Machine.AtomicSnapshot<Path, Machine.NodeSchema<Node>["Type"]>
891
+ : Machine.AtomicSnapshot<Path, NodeValue<Node>>
830
892
  : never
831
893
 
832
894
  type InitialSelectableResult<
@@ -853,28 +915,25 @@ type InitialParallelBuilder<
853
915
  > =
854
916
  & SnapshotBuilderComplete<Regions, Constructed>
855
917
  & {
856
- readonly [Key in Remaining]:
857
- & ((
858
- ...args: InitialSnapshotArguments<States, Key, Prefix>
859
- ) => InitialParallelBuilder<
918
+ readonly [Key in Remaining]: NodeBuilderMethod<
919
+ States[Key],
920
+ InitialSnapshotArguments<States, Key, Prefix>,
921
+ InitialParallelBuilder<
860
922
  States,
861
923
  Prefix,
862
924
  Exclude<Remaining, Key>,
863
925
  Regions & { readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix> },
864
926
  Constructed
865
- >)
866
- & {
867
- readonly from: FromCallable<
868
- InitialSnapshotFromArguments<States, Key, Prefix>,
869
- InitialParallelBuilder<
870
- States,
871
- Prefix,
872
- Exclude<Remaining, Key>,
873
- Regions & { readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix> },
874
- true
875
- >
876
- >
877
- }
927
+ >,
928
+ InitialSnapshotFromArguments<States, Key, Prefix>,
929
+ InitialParallelBuilder<
930
+ States,
931
+ Prefix,
932
+ Exclude<Remaining, Key>,
933
+ Regions & { readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix> },
934
+ true
935
+ >
936
+ >
878
937
  }
879
938
 
880
939
  type FullSnapshotBuilderWithPrefix<
@@ -892,14 +951,18 @@ type FullSnapshotMethod<
892
951
  States extends Machine.StateSchemas,
893
952
  StateId extends ActiveStateKey<States>,
894
953
  Prefix extends string
895
- > =
896
- & ((
897
- ...args: FullSnapshotArguments<States, StateId, Prefix>
898
- ) => FullSnapshotResult<States, StateId, Prefix>)
899
- & FromMethod<
954
+ > = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<
900
955
  FullSnapshotFromArguments<States, StateId, Prefix>,
901
956
  FullSnapshotResult<States, StateId, Prefix>
902
957
  >
958
+ :
959
+ & ((
960
+ ...args: FullSnapshotArguments<States, StateId, Prefix>
961
+ ) => FullSnapshotResult<States, StateId, Prefix>)
962
+ & FromMethod<
963
+ FullSnapshotFromArguments<States, StateId, Prefix>,
964
+ FullSnapshotResult<States, StateId, Prefix>
965
+ >
903
966
 
904
967
  type FullSnapshotArguments<
905
968
  States extends Machine.StateSchemas,
@@ -907,21 +970,20 @@ type FullSnapshotArguments<
907
970
  Prefix extends string,
908
971
  Path extends string = Machine.JoinPath<Prefix, StateId>
909
972
  > = States[StateId] extends infer Node ?
910
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ? [
911
- value: Machine.NodeSchema<Node>["Type"],
973
+ Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
974
+ WithNodeValue<Node, [
912
975
  states: (
913
976
  builder: FullParallelBuilder<Children, Path>
914
977
  ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
915
- ]
916
- : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? [
917
- value: Machine.NodeSchema<Node>["Type"],
978
+ ]>
979
+ : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? WithNodeValue<Node, [
918
980
  state: (
919
981
  builder: FullSnapshotBuilderWithPrefix<Children, Path>
920
982
  ) =>
921
983
  | Machine.SnapshotWithPrefix<Children, Path>
922
984
  | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
923
- ]
924
- : [value: Machine.NodeSchema<Node>["Type"]]
985
+ ]>
986
+ : WithNodeValue<Node, []>
925
987
  : never
926
988
 
927
989
  type FullSnapshotFromArguments<
@@ -930,22 +992,21 @@ type FullSnapshotFromArguments<
930
992
  Prefix extends string,
931
993
  Path extends string = Machine.JoinPath<Prefix, StateId>
932
994
  > = States[StateId] extends infer Node ?
933
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ? [
934
- input: Machine.NodeSchema<Node>["~type.make.in"],
995
+ Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
996
+ WithNodeInput<Node, [
935
997
  states: (
936
998
  builder: FullParallelBuilder<Children, Path>
937
999
  ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
938
- ]
939
- : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? [
940
- input: Machine.NodeSchema<Node>["~type.make.in"],
1000
+ ]>
1001
+ : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? WithNodeInput<Node, [
941
1002
  state: (
942
1003
  builder: FullSnapshotBuilderWithPrefix<Children, Path>
943
1004
  ) => ConstructionResult<
944
1005
  | Machine.SnapshotWithPrefix<Children, Path>
945
1006
  | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
946
1007
  >
947
- ]
948
- : [input: Machine.NodeSchema<Node>["~type.make.in"]]
1008
+ ]>
1009
+ : WithNodeInput<Node, []>
949
1010
  : never
950
1011
 
951
1012
  type FullSnapshotResult<
@@ -964,28 +1025,25 @@ type FullParallelBuilder<
964
1025
  > =
965
1026
  & SnapshotBuilderComplete<Regions, Constructed>
966
1027
  & {
967
- readonly [Key in Remaining]:
968
- & ((
969
- ...args: FullSnapshotArguments<States, Key, Prefix>
970
- ) => FullParallelBuilder<
1028
+ readonly [Key in Remaining]: NodeBuilderMethod<
1029
+ States[Key],
1030
+ FullSnapshotArguments<States, Key, Prefix>,
1031
+ FullParallelBuilder<
971
1032
  States,
972
1033
  Prefix,
973
1034
  Exclude<Remaining, Key>,
974
1035
  Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
975
1036
  Constructed
976
- >)
977
- & {
978
- readonly from: FromCallable<
979
- FullSnapshotFromArguments<States, Key, Prefix>,
980
- FullParallelBuilder<
981
- States,
982
- Prefix,
983
- Exclude<Remaining, Key>,
984
- Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
985
- true
986
- >
987
- >
988
- }
1037
+ >,
1038
+ FullSnapshotFromArguments<States, Key, Prefix>,
1039
+ FullParallelBuilder<
1040
+ States,
1041
+ Prefix,
1042
+ Exclude<Remaining, Key>,
1043
+ Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
1044
+ true
1045
+ >
1046
+ >
989
1047
  }
990
1048
 
991
1049
  type HistorySnapshotArguments<
@@ -996,18 +1054,17 @@ type HistorySnapshotArguments<
996
1054
  Path extends string = Machine.JoinPath<Prefix, StateId>
997
1055
  > = Path extends Owner ? FullSnapshotArguments<States, StateId, Prefix>
998
1056
  : States[StateId] extends infer Node ?
999
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ? [
1000
- value: Machine.NodeSchema<Node>["Type"],
1057
+ Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1058
+ WithNodeValue<Node, [
1001
1059
  states: (
1002
1060
  builder: HistoryParallelBuilder<Children, Path, Owner>
1003
1061
  ) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
1004
- ]
1005
- : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? [
1006
- value: Machine.NodeSchema<Node>["Type"],
1062
+ ]>
1063
+ : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? WithNodeValue<Node, [
1007
1064
  state: (
1008
1065
  builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>
1009
1066
  ) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
1010
- ]
1067
+ ]>
1011
1068
  : never
1012
1069
  : never
1013
1070
 
@@ -1019,18 +1076,17 @@ type HistorySnapshotFromArguments<
1019
1076
  Path extends string = Machine.JoinPath<Prefix, StateId>
1020
1077
  > = Path extends Owner ? FullSnapshotFromArguments<States, StateId, Prefix>
1021
1078
  : States[StateId] extends infer Node ?
1022
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ? [
1023
- input: Machine.NodeSchema<Node>["~type.make.in"],
1079
+ Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1080
+ WithNodeInput<Node, [
1024
1081
  states: (
1025
1082
  builder: HistoryParallelBuilder<Children, Path, Owner>
1026
1083
  ) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
1027
- ]
1028
- : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? [
1029
- input: Machine.NodeSchema<Node>["~type.make.in"],
1084
+ ]>
1085
+ : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? WithNodeInput<Node, [
1030
1086
  state: (
1031
1087
  builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>
1032
1088
  ) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
1033
- ]
1089
+ ]>
1034
1090
  : never
1035
1091
  : never
1036
1092
 
@@ -1045,12 +1101,12 @@ type HistorySnapshotResult<
1045
1101
  Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1046
1102
  Machine.ParallelSnapshot<
1047
1103
  Path,
1048
- Machine.NodeSchema<Node>["Type"],
1104
+ NodeValue<Node>,
1049
1105
  HistorySnapshotRegions<Children, Path, Owner>
1050
1106
  >
1051
1107
  : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? Machine.CompoundSnapshot<
1052
1108
  Path,
1053
- Machine.NodeSchema<Node>["Type"],
1109
+ NodeValue<Node>,
1054
1110
  HistorySnapshotWithPrefix<Children, Owner, Path>
1055
1111
  >
1056
1112
  : never
@@ -1061,14 +1117,18 @@ type HistorySnapshotMethod<
1061
1117
  StateId extends ActiveStateKey<States>,
1062
1118
  Prefix extends string,
1063
1119
  Owner extends string
1064
- > =
1065
- & ((
1066
- ...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>
1067
- ) => HistorySnapshotResult<States, StateId, Prefix, Owner>)
1068
- & FromMethod<
1120
+ > = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<
1069
1121
  HistorySnapshotFromArguments<States, StateId, Prefix, Owner>,
1070
1122
  HistorySnapshotResult<States, StateId, Prefix, Owner>
1071
1123
  >
1124
+ :
1125
+ & ((
1126
+ ...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>
1127
+ ) => HistorySnapshotResult<States, StateId, Prefix, Owner>)
1128
+ & FromMethod<
1129
+ HistorySnapshotFromArguments<States, StateId, Prefix, Owner>,
1130
+ HistorySnapshotResult<States, StateId, Prefix, Owner>
1131
+ >
1072
1132
 
1073
1133
  type HistorySnapshotWithPrefix<
1074
1134
  States extends Machine.StateSchemas,
@@ -1117,50 +1177,48 @@ type HistoryParallelBuilder<
1117
1177
  & {
1118
1178
  readonly [Key in Remaining]: Owner extends
1119
1179
  | Machine.JoinPath<Prefix, Key>
1120
- | `${Machine.JoinPath<Prefix, Key>}.${string}` ?
1121
- & ((...args: HistorySnapshotArguments<States, Key, Prefix, Owner>) => HistoryParallelBuilder<
1180
+ | `${Machine.JoinPath<Prefix, Key>}.${string}` ? NodeBuilderMethod<
1181
+ States[Key],
1182
+ HistorySnapshotArguments<States, Key, Prefix, Owner>,
1183
+ HistoryParallelBuilder<
1122
1184
  States,
1123
1185
  Prefix,
1124
1186
  Owner,
1125
1187
  Exclude<Remaining, Key>,
1126
1188
  Regions & { readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner> },
1127
1189
  Constructed
1128
- >)
1129
- & {
1130
- readonly from: FromCallable<
1131
- HistorySnapshotFromArguments<States, Key, Prefix, Owner>,
1132
- HistoryParallelBuilder<
1133
- States,
1134
- Prefix,
1135
- Owner,
1136
- Exclude<Remaining, Key>,
1137
- Regions & { readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner> },
1138
- true
1139
- >
1140
- >
1141
- }
1142
- :
1143
- & ((...args: FullSnapshotArguments<States, Key, Prefix>) => HistoryParallelBuilder<
1190
+ >,
1191
+ HistorySnapshotFromArguments<States, Key, Prefix, Owner>,
1192
+ HistoryParallelBuilder<
1193
+ States,
1194
+ Prefix,
1195
+ Owner,
1196
+ Exclude<Remaining, Key>,
1197
+ Regions & { readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner> },
1198
+ true
1199
+ >
1200
+ >
1201
+ : NodeBuilderMethod<
1202
+ States[Key],
1203
+ FullSnapshotArguments<States, Key, Prefix>,
1204
+ HistoryParallelBuilder<
1144
1205
  States,
1145
1206
  Prefix,
1146
1207
  Owner,
1147
1208
  Exclude<Remaining, Key>,
1148
1209
  Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
1149
1210
  Constructed
1150
- >)
1151
- & {
1152
- readonly from: FromCallable<
1153
- FullSnapshotFromArguments<States, Key, Prefix>,
1154
- HistoryParallelBuilder<
1155
- States,
1156
- Prefix,
1157
- Owner,
1158
- Exclude<Remaining, Key>,
1159
- Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
1160
- true
1161
- >
1162
- >
1163
- }
1211
+ >,
1212
+ FullSnapshotFromArguments<States, Key, Prefix>,
1213
+ HistoryParallelBuilder<
1214
+ States,
1215
+ Prefix,
1216
+ Owner,
1217
+ Exclude<Remaining, Key>,
1218
+ Regions & { readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix> },
1219
+ true
1220
+ >
1221
+ >
1164
1222
  }
1165
1223
 
1166
1224
  type ParentPath<Path extends string> = Path extends `${infer Parent}.${infer Child}`
@@ -1245,59 +1303,36 @@ type LocalTargetMethod<
1245
1303
  Path extends string = Machine.JoinPath<Prefix, StateId>
1246
1304
  > = States[StateId] extends infer Node ?
1247
1305
  Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1248
- Source extends Path | `${Path}.${string}` ?
1249
- & (<Result extends ConstructionResult<LocalTargetResultWithPrefix<AllStates, Children, Path>>>(
1250
- value: Machine.NodeSchema<Node>["Type"],
1251
- state: (
1252
- builder: LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>
1253
- ) => Result
1254
- ) => Result)
1255
- & {
1256
- readonly from: ConstructionSelectorFromCallable<
1257
- Machine.NodeSchema<Node>["~type.make.in"],
1258
- LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1259
- LocalTargetResultWithPrefix<AllStates, Children, Path>
1260
- >
1261
- }
1262
- :
1263
- & ((
1264
- value: Machine.NodeSchema<Node>["Type"],
1306
+ Source extends Path | `${Path}.${string}` ? NestedTargetMethod<
1307
+ Node,
1308
+ LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1309
+ LocalTargetResultWithPrefix<AllStates, Children, Path>
1310
+ >
1311
+ : NodeMethod<
1312
+ Node,
1313
+ WithNodeValue<Node, [
1265
1314
  states: (
1266
1315
  builder: FullParallelBuilder<Children, Path>
1267
1316
  ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
1268
- ) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>)
1269
- & FromMethod<
1270
- [
1271
- input: Machine.NodeSchema<Node>["~type.make.in"],
1272
- states: (
1273
- builder: FullParallelBuilder<Children, Path>
1274
- ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
1275
- ],
1276
- Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>
1277
- >
1278
- : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
1279
- & (<Result extends ConstructionResult<LocalTargetResultWithPrefix<AllStates, Children, Path>>>(
1280
- value: Machine.NodeSchema<Node>["Type"],
1281
- state: (
1282
- builder: LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>
1283
- ) => Result
1284
- ) => Result)
1285
- & {
1286
- readonly from: ConstructionSelectorFromCallable<
1287
- Machine.NodeSchema<Node>["~type.make.in"],
1288
- LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1289
- LocalTargetResultWithPrefix<AllStates, Children, Path>
1290
- >
1291
- }
1292
- :
1293
- & ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<
1294
- AllStates,
1295
- StateIdentifierFromPath<AllStates, Path>
1296
- >)
1297
- & FromMethod<
1298
- [input: Machine.NodeSchema<Node>["~type.make.in"]],
1299
- Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>
1317
+ ]>,
1318
+ Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>,
1319
+ WithNodeInput<Node, [
1320
+ states: (
1321
+ builder: FullParallelBuilder<Children, Path>
1322
+ ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
1323
+ ]>
1300
1324
  >
1325
+ : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? NestedTargetMethod<
1326
+ Node,
1327
+ LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1328
+ LocalTargetResultWithPrefix<AllStates, Children, Path>
1329
+ >
1330
+ : NodeMethod<
1331
+ Node,
1332
+ WithNodeValue<Node, []>,
1333
+ Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>,
1334
+ WithNodeInput<Node, []>
1335
+ >
1301
1336
  : never
1302
1337
 
1303
1338
  type LocalTargetBuilderForScope<
@@ -1306,28 +1341,29 @@ type LocalTargetBuilderForScope<
1306
1341
  Source extends Machine.StateNodeIdentifier<States>
1307
1342
  > = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ?
1308
1343
  & LocalTargetBuilderWithPrefix<States, Children, Scope, Source>
1309
- & {
1310
- /**
1311
- * Updates the value of the state containing the local group and moves to
1312
- * one of the states inside it. Values in other active branches are kept.
1313
- *
1314
- * @since 0.4.0
1315
- */
1316
- readonly with:
1317
- & (<Result extends ConstructionResult<LocalTargetResultWithPrefix<States, Children, Scope>>>(
1318
- value: Machine.StateByIdentifier<States, Scope>,
1319
- state: (
1320
- builder: LocalTargetBuilderWithPrefix<States, Children, Scope, Source>
1321
- ) => Result
1322
- ) => Result)
1323
- & {
1324
- readonly from: ConstructionSelectorFromCallable<
1325
- Machine.SchemaByIdentifier<States, Scope>["~type.make.in"],
1326
- LocalTargetBuilderWithPrefix<States, Children, Scope, Source>,
1327
- LocalTargetResultWithPrefix<States, Children, Scope>
1328
- >
1329
- }
1330
- }
1344
+ & (Scope extends Machine.ValuedStateIdentifier<States> ? {
1345
+ /**
1346
+ * Updates the value of the state containing the local group and moves to
1347
+ * one of the states inside it. Values in other active branches are kept.
1348
+ *
1349
+ * @since 0.4.0
1350
+ */
1351
+ readonly with:
1352
+ & (<Result extends ConstructionResult<LocalTargetResultWithPrefix<States, Children, Scope>>>(
1353
+ value: Machine.StateByIdentifier<States, Scope>,
1354
+ state: (
1355
+ builder: LocalTargetBuilderWithPrefix<States, Children, Scope, Source>
1356
+ ) => Result
1357
+ ) => Result)
1358
+ & {
1359
+ readonly from: ConstructionSelectorFromCallable<
1360
+ Machine.SchemaByIdentifier<States, Scope>["~type.make.in"],
1361
+ LocalTargetBuilderWithPrefix<States, Children, Scope, Source>,
1362
+ LocalTargetResultWithPrefix<States, Children, Scope>
1363
+ >
1364
+ }
1365
+ } :
1366
+ {})
1331
1367
  : {}
1332
1368
 
1333
1369
  type BranchTargetResult<
@@ -1381,60 +1417,39 @@ type BranchTargetMethod<
1381
1417
  > = States[StateId] extends infer Node ?
1382
1418
  Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1383
1419
  Source extends Path | `${Path}.${string}` ?
1384
- & (<Result extends ConstructionResult<BranchTargetResultWithPrefix<AllStates, Children, Path>>>(
1385
- value: Machine.NodeSchema<Node>["Type"],
1386
- state: (
1387
- builder: BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>
1388
- ) => Result
1389
- ) => Result)
1390
- & {
1391
- readonly from: ConstructionSelectorFromCallable<
1392
- Machine.NodeSchema<Node>["~type.make.in"],
1393
- BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1394
- BranchTargetResultWithPrefix<AllStates, Children, Path>
1395
- >
1396
- }
1420
+ & NestedTargetMethod<
1421
+ Node,
1422
+ BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1423
+ BranchTargetResultWithPrefix<AllStates, Children, Path>
1424
+ >
1397
1425
  & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>
1398
- :
1399
- & ((
1400
- value: Machine.NodeSchema<Node>["Type"],
1426
+ : NodeMethod<
1427
+ Node,
1428
+ WithNodeValue<Node, [
1401
1429
  states: (
1402
1430
  builder: FullParallelBuilder<Children, Path>
1403
1431
  ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
1404
- ) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>)
1405
- & FromMethod<
1406
- [
1407
- input: Machine.NodeSchema<Node>["~type.make.in"],
1408
- states: (
1409
- builder: FullParallelBuilder<Children, Path>
1410
- ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
1411
- ],
1412
- Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>
1413
- >
1432
+ ]>,
1433
+ Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>,
1434
+ WithNodeInput<Node, [
1435
+ states: (
1436
+ builder: FullParallelBuilder<Children, Path>
1437
+ ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
1438
+ ]>
1439
+ >
1414
1440
  : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
1415
- & (<Result extends ConstructionResult<BranchTargetResultWithPrefix<AllStates, Children, Path>>>(
1416
- value: Machine.NodeSchema<Node>["Type"],
1417
- state: (
1418
- builder: BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>
1419
- ) => Result
1420
- ) => Result)
1421
- & {
1422
- readonly from: ConstructionSelectorFromCallable<
1423
- Machine.NodeSchema<Node>["~type.make.in"],
1424
- BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1425
- BranchTargetResultWithPrefix<AllStates, Children, Path>
1426
- >
1427
- }
1441
+ & NestedTargetMethod<
1442
+ Node,
1443
+ BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1444
+ BranchTargetResultWithPrefix<AllStates, Children, Path>
1445
+ >
1428
1446
  & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>
1429
- :
1430
- & ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<
1431
- AllStates,
1432
- StateIdentifierFromPath<AllStates, Path>
1433
- >)
1434
- & FromMethod<
1435
- [input: Machine.NodeSchema<Node>["~type.make.in"]],
1436
- Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>
1437
- >
1447
+ : NodeMethod<
1448
+ Node,
1449
+ WithNodeValue<Node, []>,
1450
+ Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>,
1451
+ WithNodeInput<Node, []>
1452
+ >
1438
1453
  : never
1439
1454
 
1440
1455
  type BranchTargetBuilderForRoot<
@@ -1471,15 +1486,21 @@ type HasDirectShallowHistory<States extends Machine.StateSchemas> = {
1471
1486
  readonly [Key in HistoryStateKey<States>]: States[Key] extends { readonly history: "deep" } ? never : Key
1472
1487
  }[HistoryStateKey<States>] extends never ? false : true
1473
1488
 
1489
+ type HasValuedActiveChild<States extends Machine.StateSchemas> = {
1490
+ readonly [Key in ActiveStateKey<States>]: Machine.NodeSchema<States[Key]> extends never ? never : Key
1491
+ }[ActiveStateKey<States>] extends never ? false : true
1492
+
1474
1493
  type InitializerClosureForNode<
1475
1494
  AllStates extends Machine.StateSchemas,
1476
1495
  Node,
1477
1496
  Path extends string
1478
1497
  > = Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1479
- | Extract<Path, Machine.StateIdentifier<AllStates>>
1498
+ | (HasValuedActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never)
1480
1499
  | InitializerClosuresForChildren<AllStates, Children, Path>
1481
1500
  : Node extends { readonly states: infer Children extends Machine.StateSchemas; readonly initial: infer Initial } ?
1482
- | Extract<Path, Machine.StateIdentifier<AllStates>>
1501
+ | (Initial extends ActiveStateKey<Children> ? Machine.NodeSchema<Children[Initial]> extends never ? never
1502
+ : Extract<Path, Machine.StateIdentifier<AllStates>>
1503
+ : never)
1483
1504
  | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<
1484
1505
  AllStates,
1485
1506
  Children[Initial],
@@ -1750,7 +1771,8 @@ export declare namespace Logic {
1750
1771
  *
1751
1772
  * `sendParent` accepts `unknown` because process logic is independent from
1752
1773
  * the parent that eventually owns it. Prefer typed process output or an
1753
- * invoke snapshot mapper when either can represent the communication.
1774
+ * invocation lifecycle transition when either can represent the
1775
+ * communication.
1754
1776
  *
1755
1777
  * @category models
1756
1778
  * @since 0.4.0
@@ -1812,8 +1834,9 @@ type InvokeLifecycleId = string & { readonly [ChildAddressTypeId]?: never }
1812
1834
  * **Details**
1813
1835
  *
1814
1836
  * The descriptor carries the child's address and complete machine type. Pass
1815
- * the same value to `invokeMachine`, `sendTo`, and child lookup APIs so state,
1816
- * event, error, and output types are inferred without separate annotations.
1837
+ * a descriptor for the same id and machine to inline `invoke`, `sendTo`, and
1838
+ * child lookup APIs so state, event, error, and output types are inferred
1839
+ * without separate annotations.
1817
1840
  *
1818
1841
  * @category models
1819
1842
  * @since 0.4.0
@@ -1826,6 +1849,9 @@ export interface ChildMachine<Id extends string, M extends Machine.Any> {
1826
1849
 
1827
1850
  /** Complete machine definition carried by this descriptor. */
1828
1851
  readonly machine: M
1852
+
1853
+ /** @internal */
1854
+ readonly [ChildMachineLogicTypeId]: (input?: unknown) => Logic<any, any, any, any, any, any>
1829
1855
  }
1830
1856
 
1831
1857
  /**
@@ -1851,7 +1877,7 @@ export declare namespace ChildMachine {
1851
1877
  */
1852
1878
  export type Ref<Child> = Child extends ChildMachine<string, infer M> ? MachineRef<
1853
1879
  Machine.Snapshot<Machine.States<M>>,
1854
- Machine.InputEvent<M>,
1880
+ Machine.EventInput<Machine.InputEvent<M>>,
1855
1881
  | Machine.Error<M>
1856
1882
  | ActionError<Machine.Services<M>>
1857
1883
  | InfiniteTransitionError
@@ -2135,6 +2161,13 @@ export declare namespace Machine {
2135
2161
  */
2136
2162
  export type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"]
2137
2163
 
2164
+ /** Extracts the internal event schema tuple carried by a machine definition. */
2165
+ export type InternalEvents<M extends Any> = Events<M> extends readonly [
2166
+ ...InputEvents<M>,
2167
+ ...infer Internal extends ReadonlyArray<TaggedSchema>
2168
+ ] ? Internal
2169
+ : readonly []
2170
+
2138
2171
  /**
2139
2172
  * Extracts the complete event protocol handled inside a machine.
2140
2173
  *
@@ -2151,6 +2184,53 @@ export declare namespace Machine {
2151
2184
  */
2152
2185
  export type InputEvent<M extends Any> = EventOf<InputEvents<M>>
2153
2186
 
2187
+ /**
2188
+ * Opaque event construction returned by {@link events} and
2189
+ * {@link internalEvents}.
2190
+ *
2191
+ * The machine resolves the instruction through its event schema when it is
2192
+ * delivered. Only the discriminator is available before decoding succeeds.
2193
+ */
2194
+ export interface EventConstruction<out Event extends { readonly _tag: PropertyKey }> {
2195
+ readonly [EventConstructionTypeId]: Event
2196
+ readonly _tag: Event["_tag"]
2197
+ }
2198
+
2199
+ /** A decoded event or a deferred machine-bound construction of that event. */
2200
+ export type EventInput<Event> =
2201
+ | Event
2202
+ | (Event extends { readonly _tag: PropertyKey } ? EventConstruction<Event> : never)
2203
+
2204
+ /** Event inputs accepted for a schema tuple at machine delivery boundaries. */
2205
+ export type EventInputOf<Events extends ReadonlyArray<TaggedSchema>> = EventInput<EventOf<Events>>
2206
+
2207
+ type EventConstructorInput<EventSchema extends TaggedSchema> = Omit<EventSchema["~type.make.in"], "_tag">
2208
+
2209
+ type EventConstructor<
2210
+ EventSchema extends TaggedSchema,
2211
+ Tag extends EventSchema["Type"]["_tag"]
2212
+ > = {} extends EventConstructorInput<EventSchema> ?
2213
+ (input?: EventConstructorInput<EventSchema>) => EventConstruction<EventByTag<readonly [EventSchema], Tag>>
2214
+ : (input: EventConstructorInput<EventSchema>) => EventConstruction<EventByTag<readonly [EventSchema], Tag>>
2215
+
2216
+ type EventConstructorsForSchema<EventSchema extends TaggedSchema> = EventSchema extends {
2217
+ readonly cases: infer Cases extends Readonly<Record<PropertyKey, TaggedSchema>>
2218
+ } ? {
2219
+ readonly [Tag in keyof Cases]: Tag extends Cases[Tag]["Type"]["_tag"] ? EventConstructor<Cases[Tag], Tag>
2220
+ : never
2221
+ }
2222
+ : EventSchema extends { readonly members: infer Members extends ReadonlyArray<TaggedSchema> } ?
2223
+ Types.UnionToIntersection<EventConstructorsForSchema<Members[number]>>
2224
+ : {
2225
+ readonly [Tag in EventSchema["Type"]["_tag"]]: EventConstructor<EventSchema, Tag>
2226
+ }
2227
+
2228
+ /** Protocol-bound constructors keyed by each configured event tag. */
2229
+ export type EventConstructors<Events extends ReadonlyArray<TaggedSchema>> = {
2230
+ readonly [Tag in keyof Types.UnionToIntersection<EventConstructorsForSchema<Events[number]>>]:
2231
+ Types.UnionToIntersection<EventConstructorsForSchema<Events[number]>>[Tag]
2232
+ }
2233
+
2154
2234
  /**
2155
2235
  * Extracts the event protocol emitted by a machine.
2156
2236
  *
@@ -2175,8 +2255,9 @@ export declare namespace Machine {
2175
2255
  * Descriptive annotations exposed for compiled state nodes.
2176
2256
  *
2177
2257
  * Schema-backed states resolve their complete Effect Schema annotation map.
2178
- * Pseudo-states accept only the descriptive fields below. Annotations never
2179
- * affect state identity, targeting, or runtime behavior.
2258
+ * Schema-less active states and pseudo-states accept only the descriptive
2259
+ * fields below. Annotations never affect state identity, targeting, or
2260
+ * runtime behavior.
2180
2261
  *
2181
2262
  * @category models
2182
2263
  * @since 0.4.0
@@ -2187,14 +2268,18 @@ export declare namespace Machine {
2187
2268
  readonly documentation?: string | undefined
2188
2269
  }
2189
2270
 
2190
- /** Descriptive annotations accepted by schema-less pseudo-states. */
2191
- export type PseudoStateAnnotations = Pick<
2271
+ /** Descriptive annotations accepted by schema-less active and pseudo-states. */
2272
+ export type SchemaLessStateAnnotations = Pick<
2192
2273
  StateNodeAnnotations,
2193
2274
  "title" | "description" | "documentation"
2194
2275
  >
2195
2276
 
2277
+ /** @deprecated Use {@link SchemaLessStateAnnotations}. */
2278
+ export type PseudoStateAnnotations = SchemaLessStateAnnotations
2279
+
2196
2280
  /**
2197
- * Configuration accepted for an atomic object state node.
2281
+ * Configuration accepted for an atomic object state node. Omit `schema` when
2282
+ * the state owns no value; a schema-less final may still declare `output`.
2198
2283
  *
2199
2284
  * @category models
2200
2285
  * @since 0.4.0
@@ -2204,38 +2289,72 @@ export declare namespace Machine {
2204
2289
  readonly schema: TaggedSchema
2205
2290
  readonly type?: "active"
2206
2291
  readonly output?: never
2292
+ readonly annotations?: never
2207
2293
  }
2208
2294
  | {
2209
2295
  readonly schema: TaggedSchema
2210
2296
  readonly type: "final"
2211
2297
  readonly output?: Schema.Top
2298
+ readonly annotations?: never
2299
+ }
2300
+ | {
2301
+ readonly schema?: never
2302
+ readonly type?: "active"
2303
+ readonly output?: never
2304
+ readonly annotations?: SchemaLessStateAnnotations
2305
+ }
2306
+ | {
2307
+ readonly schema?: never
2308
+ readonly type: "final"
2309
+ readonly output?: Schema.Top
2310
+ readonly annotations?: SchemaLessStateAnnotations
2212
2311
  }
2213
2312
 
2214
2313
  /**
2215
- * Configuration accepted for a compound object state node.
2314
+ * Configuration accepted for a compound object state node. Omit `schema`
2315
+ * when the compound state exists only to own control topology.
2216
2316
  *
2217
2317
  * @category models
2218
2318
  * @since 0.4.0
2219
2319
  */
2220
- export interface CompoundStateNodeConfig {
2221
- readonly schema: TaggedSchema
2222
- readonly type?: "active"
2223
- readonly initial: string
2224
- readonly states: StateTree
2225
- }
2320
+ export type CompoundStateNodeConfig =
2321
+ | {
2322
+ readonly schema: TaggedSchema
2323
+ readonly type?: "active"
2324
+ readonly initial: string
2325
+ readonly states: StateTree
2326
+ readonly annotations?: never
2327
+ }
2328
+ | {
2329
+ readonly schema?: never
2330
+ readonly type?: "active"
2331
+ readonly initial: string
2332
+ readonly states: StateTree
2333
+ readonly annotations?: SchemaLessStateAnnotations
2334
+ }
2226
2335
 
2227
2336
  /**
2228
- * Configuration accepted for a parallel object state node.
2337
+ * Configuration accepted for a parallel object state node. Omit `schema`
2338
+ * when the parallel state exists only to own its regions.
2229
2339
  *
2230
2340
  * @category models
2231
2341
  * @since 0.4.0
2232
2342
  */
2233
- export interface ParallelStateNodeConfig {
2234
- readonly schema: TaggedSchema
2235
- readonly type: "parallel"
2236
- readonly output?: Schema.Top
2237
- readonly states: StateTree
2238
- }
2343
+ export type ParallelStateNodeConfig =
2344
+ | {
2345
+ readonly schema: TaggedSchema
2346
+ readonly type: "parallel"
2347
+ readonly output?: Schema.Top
2348
+ readonly states: StateTree
2349
+ readonly annotations?: never
2350
+ }
2351
+ | {
2352
+ readonly schema?: never
2353
+ readonly type: "parallel"
2354
+ readonly output?: Schema.Top
2355
+ readonly states: StateTree
2356
+ readonly annotations?: SchemaLessStateAnnotations
2357
+ }
2239
2358
 
2240
2359
  /**
2241
2360
  * Pseudo-state that restores the last active configuration of its parent.
@@ -2253,7 +2372,7 @@ export declare namespace Machine {
2253
2372
  readonly type: "history"
2254
2373
  /** Defaults to shallow history. */
2255
2374
  readonly history?: "shallow" | "deep"
2256
- readonly annotations?: PseudoStateAnnotations
2375
+ readonly annotations?: SchemaLessStateAnnotations
2257
2376
  }
2258
2377
 
2259
2378
  /**
@@ -2268,7 +2387,7 @@ export declare namespace Machine {
2268
2387
  */
2269
2388
  export interface ChoiceStateNodeConfig {
2270
2389
  readonly type: "choice"
2271
- readonly annotations?: PseudoStateAnnotations
2390
+ readonly annotations?: SchemaLessStateAnnotations
2272
2391
  }
2273
2392
 
2274
2393
  /**
@@ -2349,13 +2468,13 @@ export declare namespace Machine {
2349
2468
  * @since 0.4.0
2350
2469
  */
2351
2470
  readonly get: {
2352
- <Path extends StateIdentifier<States>>(
2471
+ <Path extends ValuedStateIdentifier<States>>(
2353
2472
  snapshot: Snapshot<States>,
2354
2473
  path: Path
2355
2474
  ): Option.Option<StateByIdentifier<States, Path>>
2356
2475
  <
2357
2476
  const From extends StateIdentifier<States>,
2358
- const Path extends StateIdentifier<States>
2477
+ const Path extends ValuedStateIdentifier<States>
2359
2478
  >(
2360
2479
  snapshot: SnapshotByIdentifier<States, From>,
2361
2480
  path: Path & (Path extends NoInfer<From> | `${NoInfer<From>}.${string}` ? unknown : never)
@@ -2372,7 +2491,7 @@ export declare namespace Machine {
2372
2491
  *
2373
2492
  * @since 0.4.0
2374
2493
  */
2375
- readonly getWithParents: <Path extends StateIdentifier<States>>(
2494
+ readonly getWithParents: <Path extends ValuedStateIdentifier<States>>(
2376
2495
  snapshot: Snapshot<States>,
2377
2496
  path: Path
2378
2497
  ) => Option.Option<StateWithParents<States, Path>>
@@ -2434,7 +2553,7 @@ export declare namespace Machine {
2434
2553
  export interface StateNodeBase<Path extends string = string> {
2435
2554
  readonly path: Path
2436
2555
  readonly key: string
2437
- /** Resolved Effect Schema annotations, or descriptive pseudo-state annotations. */
2556
+ /** Resolved schema annotations, or descriptive schema-less-state annotations. */
2438
2557
  readonly annotations: Readonly<StateNodeAnnotations> | undefined
2439
2558
  readonly order: number
2440
2559
  }
@@ -2444,7 +2563,7 @@ export declare namespace Machine {
2444
2563
  extends StateNodeBase<OwnPath>
2445
2564
  {
2446
2565
  readonly type: "atomic"
2447
- readonly schema: TaggedSchema
2566
+ readonly schema: TaggedSchema | undefined
2448
2567
  readonly output: undefined
2449
2568
  readonly history: undefined
2450
2569
  readonly parent: ActivePath | undefined
@@ -2459,7 +2578,7 @@ export declare namespace Machine {
2459
2578
  ChoicePath extends string = ActivePath
2460
2579
  > extends StateNodeBase<OwnPath> {
2461
2580
  readonly type: "compound"
2462
- readonly schema: TaggedSchema
2581
+ readonly schema: TaggedSchema | undefined
2463
2582
  readonly output: undefined
2464
2583
  readonly history: undefined
2465
2584
  readonly parent: ActivePath | undefined
@@ -2473,7 +2592,7 @@ export declare namespace Machine {
2473
2592
  extends StateNodeBase<OwnPath>
2474
2593
  {
2475
2594
  readonly type: "parallel"
2476
- readonly schema: TaggedSchema
2595
+ readonly schema: TaggedSchema | undefined
2477
2596
  readonly output: Schema.Top | undefined
2478
2597
  readonly history: undefined
2479
2598
  readonly parent: ActivePath | undefined
@@ -2487,7 +2606,7 @@ export declare namespace Machine {
2487
2606
  extends StateNodeBase<OwnPath>
2488
2607
  {
2489
2608
  readonly type: "final"
2490
- readonly schema: TaggedSchema
2609
+ readonly schema: TaggedSchema | undefined
2491
2610
  readonly output: Schema.Top | undefined
2492
2611
  readonly history: undefined
2493
2612
  readonly parent: ActivePath | undefined
@@ -2580,6 +2699,11 @@ export declare namespace Machine {
2580
2699
  | {
2581
2700
  readonly type: "choice"
2582
2701
  }
2702
+ | {
2703
+ readonly type: "invoke"
2704
+ readonly id: string
2705
+ readonly outcome: "done" | "failure" | "snapshot"
2706
+ }
2583
2707
 
2584
2708
  /**
2585
2709
  * Statically inspectable destination paths for a transition handler.
@@ -2602,10 +2726,10 @@ export declare namespace Machine {
2602
2726
  *
2603
2727
  * **Details**
2604
2728
  *
2605
- * Event, eventless, and completion handlers may declare an upper bound of
2606
- * possible target paths. A handler without that declaration is explicitly
2607
- * reported as dynamic. The source, trigger, and reentry behavior are
2608
- * available without executing the handler.
2729
+ * Event, eventless, completion, and invocation lifecycle handlers may
2730
+ * declare an upper bound of possible target paths. A handler without that
2731
+ * declaration is explicitly reported as dynamic. The source, trigger, and
2732
+ * reentry behavior are available without executing the handler.
2609
2733
  *
2610
2734
  * @category models
2611
2735
  * @since 0.4.0
@@ -2624,9 +2748,9 @@ export declare namespace Machine {
2624
2748
  /**
2625
2749
  * Serializable description of state-owned work.
2626
2750
  *
2627
- * Static invoke descriptors expose their lifecycle id and kind without
2628
- * retaining Effects, closures, services, or child runtimes. A function-valued
2629
- * invoke factory is reported as dynamic and is never evaluated by inspection.
2751
+ * Static invoke definitions expose their lifecycle id and kind without
2752
+ * retaining Effects, closures, services, or child runtimes. Function-valued
2753
+ * sources are reported as dynamic and are never evaluated by inspection.
2630
2754
  *
2631
2755
  * @category models
2632
2756
  * @since 0.4.0
@@ -2697,6 +2821,19 @@ export declare namespace Machine {
2697
2821
  */
2698
2822
  export type StateIdentifier<States extends StateSchemas> = StateIdentifierWithPrefix<States>
2699
2823
 
2824
+ /** Extracts active state paths whose definitions declare a state value schema. */
2825
+ export type ValuedStateIdentifier<States extends StateSchemas> = StateIdentifier<States> extends infer StateId
2826
+ ? StateId extends StateIdentifier<States> ? NodeSchema<NodeByIdentifier<States, StateId>> extends never ? never
2827
+ : StateId
2828
+ : never
2829
+ : never
2830
+
2831
+ /** Extracts active state paths whose definitions intentionally omit a state value schema. */
2832
+ export type StructuralStateIdentifier<States extends StateSchemas> = Exclude<
2833
+ StateIdentifier<States>,
2834
+ ValuedStateIdentifier<States>
2835
+ >
2836
+
2700
2837
  /**
2701
2838
  * Extracts the state path values represented by a state definition under a
2702
2839
  * parent path prefix.
@@ -2907,7 +3044,7 @@ export declare namespace Machine {
2907
3044
  export type StateByIdentifier<
2908
3045
  States extends StateSchemas,
2909
3046
  StateId extends StateIdentifier<States>
2910
- > = Extract<StateOf<States>, SchemaByIdentifier<States, StateId>["Type"]>
3047
+ > = StateId extends ValuedStateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : undefined
2911
3048
 
2912
3049
  /**
2913
3050
  * Extracts every parent state path from a state identifier.
@@ -2940,7 +3077,7 @@ export declare namespace Machine {
2940
3077
  States extends StateSchemas,
2941
3078
  StateId extends StateIdentifier<States>
2942
3079
  > = StateId extends StateIdentifier<States> ? {
2943
- readonly [Parent in Extract<ParentStateIdentifier<StateId>, StateIdentifier<States>>]: StateByIdentifier<
3080
+ readonly [Parent in Extract<ParentStateIdentifier<StateId>, ValuedStateIdentifier<States>>]: StateByIdentifier<
2944
3081
  States,
2945
3082
  Parent
2946
3083
  >
@@ -2959,7 +3096,7 @@ export declare namespace Machine {
2959
3096
  > = StateId extends StateIdentifier<States> ?
2960
3097
  Extract<ImmediateParentStateIdentifier<StateId>, StateIdentifier<States>> extends infer Parent
2961
3098
  ? [Parent] extends [never] ? undefined
2962
- : Parent extends StateIdentifier<States> ? StateByIdentifier<States, Parent>
3099
+ : Parent extends ValuedStateIdentifier<States> ? StateByIdentifier<States, Parent>
2963
3100
  : undefined
2964
3101
  : undefined
2965
3102
  : never
@@ -3144,7 +3281,7 @@ export declare namespace Machine {
3144
3281
  */
3145
3282
  export interface EncodedSnapshotState {
3146
3283
  readonly path: string
3147
- readonly value: unknown
3284
+ readonly value?: unknown
3148
3285
  }
3149
3286
 
3150
3287
  /**
@@ -3329,17 +3466,17 @@ export declare namespace Machine {
3329
3466
  > = States[StateId] extends { readonly type: "parallel"; readonly states: infer Children }
3330
3467
  ? Children extends StateSchemas ? ParallelSnapshot<
3331
3468
  Path,
3332
- NodeSchema<States[StateId]>["Type"],
3469
+ NodeValue<States[StateId]>,
3333
3470
  SnapshotRegionsWithPrefix<Children, Path>
3334
3471
  >
3335
- : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]>
3472
+ : AtomicSnapshot<Path, NodeValue<States[StateId]>>
3336
3473
  : States[StateId] extends { readonly states: infer Children } ? Children extends StateSchemas ? CompoundSnapshot<
3337
3474
  Path,
3338
- NodeSchema<States[StateId]>["Type"],
3475
+ NodeValue<States[StateId]>,
3339
3476
  SnapshotWithPrefix<Children, Path>
3340
3477
  >
3341
- : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]>
3342
- : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]>
3478
+ : AtomicSnapshot<Path, NodeValue<States[StateId]>>
3479
+ : AtomicSnapshot<Path, NodeValue<States[StateId]>>
3343
3480
 
3344
3481
  /**
3345
3482
  * Extracts a complete root snapshot whose selected configuration contains a
@@ -3455,7 +3592,7 @@ export declare namespace Machine {
3455
3592
  readonly value: StateByIdentifier<States, StateId>
3456
3593
  readonly values?: Partial<
3457
3594
  {
3458
- readonly [AncestorStateId in StateIdentifier<States>]: StateByIdentifier<States, AncestorStateId>
3595
+ readonly [AncestorStateId in ValuedStateIdentifier<States>]: StateByIdentifier<States, AncestorStateId>
3459
3596
  }
3460
3597
  >
3461
3598
  }
@@ -3669,7 +3806,7 @@ export declare namespace Machine {
3669
3806
  }
3670
3807
 
3671
3808
  /**
3672
- * Context passed to an invoked child process source.
3809
+ * Context passed to a function-valued invocation source.
3673
3810
  *
3674
3811
  * @category models
3675
3812
  * @since 0.4.0
@@ -3687,27 +3824,67 @@ export declare namespace Machine {
3687
3824
  }
3688
3825
 
3689
3826
  /**
3690
- * Context passed to an invoked child process active snapshot mapper.
3827
+ * Context passed to an invocation's active-snapshot transition.
3691
3828
  *
3692
3829
  * @category models
3693
3830
  * @since 0.4.0
3694
3831
  */
3695
- export interface InvokeSnapshotContext<State, Error, Output> {
3832
+ export interface InvokeSnapshotContext<
3833
+ States extends StateSchemas,
3834
+ Events extends ReadonlyArray<TaggedSchema>,
3835
+ Emits extends ReadonlyArray<TaggedSchema>,
3836
+ StateId extends StateIdentifier<States>,
3837
+ State,
3838
+ Error,
3839
+ Output
3840
+ > {
3696
3841
  readonly id: string
3842
+ readonly state: StateByIdentifier<States, StateId>
3843
+ readonly parent: ParentStateValue<States, StateId>
3844
+ readonly parents: ParentStateValues<States, StateId>
3845
+ readonly target: TargetBuilder<States, StateId>
3697
3846
  readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "active" }>
3698
3847
  }
3699
3848
 
3700
3849
  /**
3701
- * Context passed to an invoked machine terminal output mapper.
3850
+ * Context passed to an invocation's successful completion transition.
3702
3851
  *
3703
3852
  * @category models
3704
3853
  * @since 0.4.0
3705
3854
  */
3706
- export interface InvokeDoneContext<Output> {
3855
+ export interface InvokeDoneContext<
3856
+ States extends StateSchemas,
3857
+ Events extends ReadonlyArray<TaggedSchema>,
3858
+ Emits extends ReadonlyArray<TaggedSchema>,
3859
+ StateId extends StateIdentifier<States>,
3860
+ Output
3861
+ > {
3707
3862
  readonly id: string
3863
+ readonly state: StateByIdentifier<States, StateId>
3864
+ readonly parent: ParentStateValue<States, StateId>
3865
+ readonly parents: ParentStateValues<States, StateId>
3866
+ readonly snapshot: Snapshot<States>
3867
+ readonly target: TargetBuilder<States, StateId>
3708
3868
  readonly output: Output
3709
3869
  }
3710
3870
 
3871
+ /** Context passed to an invocation typed-failure transition. */
3872
+ export interface InvokeFailureContext<
3873
+ States extends StateSchemas,
3874
+ Events extends ReadonlyArray<TaggedSchema>,
3875
+ Emits extends ReadonlyArray<TaggedSchema>,
3876
+ StateId extends StateIdentifier<States>,
3877
+ Error
3878
+ > {
3879
+ readonly id: string
3880
+ readonly state: StateByIdentifier<States, StateId>
3881
+ readonly parent: ParentStateValue<States, StateId>
3882
+ readonly parents: ParentStateValues<States, StateId>
3883
+ readonly snapshot: Snapshot<States>
3884
+ readonly target: TargetBuilder<States, StateId>
3885
+ readonly error: Error
3886
+ }
3887
+
3711
3888
  /**
3712
3889
  * Context passed to an eventless transition handler.
3713
3890
  *
@@ -3779,7 +3956,7 @@ export declare namespace Machine {
3779
3956
  Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>
3780
3957
  >
3781
3958
  readonly parents: {
3782
- readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, StateIdentifier<States>>]: StateByIdentifier<
3959
+ readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<
3783
3960
  States,
3784
3961
  Parent
3785
3962
  >
@@ -3997,7 +4174,41 @@ export declare namespace Machine {
3997
4174
  * @category utility types
3998
4175
  * @since 0.4.0
3999
4176
  */
4000
- export type InvokeLogic<Invoke> = Invoke extends { readonly src: (...args: any) => infer Logic } ? Logic : never
4177
+ export type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source
4178
+
4179
+ type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<
4180
+ Snapshot<States<M>>,
4181
+ EventInput<InputEvent<M>>,
4182
+ Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
4183
+ ExcludeCompatibleRuntime<
4184
+ Exclude<ExecutionServices<InitialServices<M> | Services<M>>, internalRuntime.MachineRuntime>,
4185
+ Event<M>,
4186
+ Emit<M>
4187
+ >,
4188
+ Output<M>,
4189
+ | InitialError<M>
4190
+ | Error<M>
4191
+ | ActionError<InitialServices<M> | Services<M>>
4192
+ | InfiniteTransitionError
4193
+ | MachineSchemaDecodeError
4194
+ | StartupError
4195
+ | StoppedError
4196
+ >
4197
+ : never
4198
+
4199
+ export type InvokeLogic<Invoke> = Invoke extends { readonly effect: infer Source } ?
4200
+ InvokeResolvedSource<Source> extends infer Fx extends Effect.Effect<any, any, any> ? Logic<
4201
+ void,
4202
+ never,
4203
+ Effect.Error<Fx>,
4204
+ Effect.Services<Fx>,
4205
+ Effect.Success<Fx>
4206
+ >
4207
+ : never
4208
+ : Invoke extends { readonly after: unknown } ? Logic<void, never, never, never, void>
4209
+ : Invoke extends { readonly logic: infer Source } ? InvokeResolvedSource<Source>
4210
+ : Invoke extends { readonly child: infer Child } ? ChildMachineLogic<Child>
4211
+ : never
4001
4212
  /**
4002
4213
  * Extracts the startup error from an invoke source child process logic.
4003
4214
  *
@@ -4049,35 +4260,40 @@ export declare namespace Machine {
4049
4260
  * @since 0.4.0
4050
4261
  */
4051
4262
  export type InvokeEmits<Invoke> = Invoke extends {
4052
- readonly [InvokeTypeId]: { readonly emits: Types.Covariant<infer Emits> }
4053
- } ? Emits :
4054
- never
4263
+ readonly [InvokeTypeId]: { readonly emits: Types.Covariant<infer Emitted> }
4264
+ } ? Emitted
4265
+ : Invoke extends { readonly child: ChildMachine<string, infer M> } ? Emit<M>
4266
+ : never
4267
+ /** Extracts transition results returned by invocation lifecycle handlers. */
4268
+ export type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ?
4269
+ | (Invoke extends { readonly onDone?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
4270
+ | (Invoke extends { readonly onFailure?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
4271
+ | (Invoke extends { readonly onSnapshot?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
4272
+ : never
4055
4273
  /**
4056
- * Extracts events returned by an invoked child snapshot mapper.
4274
+ * Extracts the parent transition error contribution from invoked children.
4057
4275
  *
4058
4276
  * @category utility types
4059
4277
  * @since 0.4.0
4060
4278
  */
4061
- export type InvokeSnapshotEvent<Invoke> = Invoke extends {
4062
- readonly [InvokeTypeId]: { readonly snapshotEvent: Types.Covariant<infer Event> }
4063
- } ? Event :
4064
- never
4279
+ export type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never
4280
+ :
4281
+ | ChildAlreadyExistsError
4282
+ | InvokeInitialError<InvokeReturn<Config>>
4283
+ | Effect.Error<InvokeOutcomeReturn<InvokeReturn<Config>>>
4065
4284
  /**
4066
- * Extracts the parent transition error contribution from invoked children.
4067
- *
4068
- * @category utility types
4069
- * @since 0.4.0
4070
- */
4071
- export type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never
4072
- : ChildAlreadyExistsError | InvokeInitialError<InvokeReturn<Config>> | InvokeRuntimeError<InvokeReturn<Config>>
4073
- /**
4074
- * Extracts the parent service requirement contribution from invoked children.
4285
+ * Extracts the parent service requirement contribution from invoked children.
4075
4286
  *
4076
4287
  * @category utility types
4077
4288
  * @since 0.4.0
4078
4289
  */
4079
4290
  export type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never
4080
- : MachineRuntimeRequirement | InvokeServices<InvokeReturn<Config>>
4291
+ :
4292
+ | MachineRuntimeRequirement
4293
+ | InvokeServices<InvokeReturn<Config>>
4294
+ | Effect.Services<
4295
+ InvokeOutcomeReturn<InvokeReturn<Config>>
4296
+ >
4081
4297
  /**
4082
4298
  * Extracts the return value from an eventless transition.
4083
4299
  *
@@ -4123,106 +4339,436 @@ export declare namespace Machine {
4123
4339
  | Effect.Services<ChoiceReturn<Config>>
4124
4340
  | InvokeRequirements<Config>
4125
4341
 
4126
- /**
4127
- * Configuration for invoking a child process while a state is active.
4128
- *
4129
- * @category models
4130
- * @since 0.4.0
4131
- */
4132
- export interface InvokeConfig<
4342
+ export type InvokeTransition<
4133
4343
  States extends StateSchemas,
4134
4344
  Events extends ReadonlyArray<TaggedSchema>,
4135
4345
  Emits extends ReadonlyArray<TaggedSchema>,
4136
- StateId extends StateIdentifier<States>,
4137
- Event,
4138
- ChildState,
4139
- ChildEvent,
4140
- ChildError,
4141
- ChildRequirements,
4142
- ChildOutput,
4143
- ChildInitialError,
4144
- ChildEmits = never,
4145
- DeliveredOutput = ChildOutput
4146
- > {
4147
- readonly [InvokeTypeId]: {
4148
- readonly output: Types.Covariant<DeliveredOutput>
4149
- readonly emits: Types.Covariant<ChildEmits>
4150
- readonly snapshotEvent: Types.Covariant<Event>
4151
- readonly error: Types.Covariant<ChildError>
4152
- readonly requirements: Types.Covariant<ChildRequirements>
4153
- readonly initialError: Types.Covariant<ChildInitialError>
4346
+ Context
4347
+ > =
4348
+ | ((context: Context, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>)
4349
+ | {
4350
+ readonly reenter?: boolean
4351
+ readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
4352
+ readonly transition: (
4353
+ context: Context,
4354
+ enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4355
+ ) => HandlerResult<States, any, any>
4154
4356
  }
4155
- /** @internal Serializable descriptor metadata used by inspection. */
4156
- readonly [Activities.ActivityMetadataTypeId]?: Activities.StaticActivityMetadata
4157
- readonly id: string
4158
- /**
4159
- * Optional parent-local address for sending events to this invocation.
4160
- *
4161
- * The invocation `id` is only its state-local lifecycle key. Use an
4162
- * explicit typed address when the parent must communicate with it.
4163
- */
4164
- readonly address?: string
4165
- /** @internal */
4166
- readonly descriptor?: ChildMachine.Any
4167
- src(): Logic<
4168
- ChildState,
4169
- ChildEvent,
4170
- ChildError,
4171
- ChildRequirements,
4172
- ChildOutput,
4173
- ChildInitialError
4174
- >
4175
- snapshot?(
4176
- context: InvokeSnapshotContext<ChildState, ChildError, ChildOutput>
4177
- ): Event | undefined
4178
- onDone?(context: InvokeDoneContext<ChildOutput>): DeliveredOutput | undefined
4357
+
4358
+ export type InvokeSource<Value, Context> = Value | ((context: Context) => Value)
4359
+
4360
+ interface AnyLogicSource {
4361
+ initial(...args: ReadonlyArray<any>): Effect.Effect<any, any, any>
4362
+ run(...args: ReadonlyArray<any>): Effect.Effect<any, any, any>
4179
4363
  }
4180
4364
 
4181
- /** @internal */
4182
- export interface AnyInvokeConfig<
4183
- Output = unknown,
4184
- Error = unknown,
4185
- Requirements = unknown,
4186
- InitialError = unknown,
4187
- Emits = never,
4188
- SnapshotEvent = never
4365
+ /** Inline state-owned work that runs for the lifetime of its active state. */
4366
+ export interface InvokeOwned<
4367
+ States extends StateSchemas,
4368
+ Events extends ReadonlyArray<TaggedSchema>,
4369
+ Emits extends ReadonlyArray<TaggedSchema>,
4370
+ StateId extends StateIdentifier<States>
4189
4371
  > {
4372
+ readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId]>
4373
+ }
4374
+
4375
+ /** Type evidence retained by {@link invoke} without affecting runtime data. */
4376
+ export interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never> {
4190
4377
  readonly [InvokeTypeId]: {
4191
4378
  readonly output: Types.Covariant<Output>
4192
- readonly emits: Types.Covariant<Emits>
4193
- readonly snapshotEvent: Types.Covariant<SnapshotEvent>
4194
4379
  readonly error: Types.Covariant<Error>
4195
4380
  readonly requirements: Types.Covariant<Requirements>
4196
4381
  readonly initialError: Types.Covariant<InitialError>
4382
+ readonly emits: Types.Covariant<Emits>
4197
4383
  }
4198
4384
  }
4199
4385
 
4200
- interface InvokeDefinitionValue {
4201
- readonly [InvokeTypeId]: unknown
4202
- }
4386
+ export type InvokeConfig<
4387
+ States extends StateSchemas,
4388
+ Events extends ReadonlyArray<TaggedSchema>,
4389
+ Emits extends ReadonlyArray<TaggedSchema>,
4390
+ StateId extends StateIdentifier<States>
4391
+ > =
4392
+ & InvokeOwned<States, Events, Emits, StateId>
4393
+ & (
4394
+ | {
4395
+ readonly id: string
4396
+ readonly effect: InvokeSource<Effect.Effect<any, any, any>, InvokeContext<States, Events, Emits, StateId>>
4397
+ readonly after?: never
4398
+ readonly logic?: never
4399
+ readonly child?: never
4400
+ readonly address?: never
4401
+ readonly onDone?: unknown
4402
+ readonly onFailure?: unknown
4403
+ readonly onSnapshot?: never
4404
+ }
4405
+ | {
4406
+ readonly id: string
4407
+ readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId>>
4408
+ readonly effect?: never
4409
+ readonly logic?: never
4410
+ readonly child?: never
4411
+ readonly address?: never
4412
+ readonly onDone: unknown
4413
+ readonly onFailure?: never
4414
+ readonly onSnapshot?: never
4415
+ }
4416
+ | {
4417
+ readonly id: string
4418
+ readonly address: string
4419
+ readonly logic: InvokeSource<AnyLogicSource, InvokeContext<States, Events, Emits, StateId>>
4420
+ readonly effect?: never
4421
+ readonly after?: never
4422
+ readonly child?: never
4423
+ readonly onDone?: unknown
4424
+ readonly onFailure?: unknown
4425
+ readonly onSnapshot?: unknown
4426
+ }
4427
+ | {
4428
+ readonly child: ChildMachine.Any
4429
+ readonly input?: {} | null | ((context: InvokeContext<States, Events, Emits, StateId>) => unknown)
4430
+ readonly id?: never
4431
+ readonly address?: never
4432
+ readonly effect?: never
4433
+ readonly after?: never
4434
+ readonly logic?: never
4435
+ readonly onDone?: unknown
4436
+ readonly onFailure?: unknown
4437
+ readonly onSnapshot?: unknown
4438
+ }
4439
+ )
4203
4440
 
4204
- /**
4205
- * State-bound configuration for invoked child processes.
4206
- *
4207
- * **Details**
4208
- *
4209
- * A function form receives the owning state's typed value and lifecycle
4210
- * event before constructing one or more invoke configurations.
4211
- *
4212
- * @category models
4213
- * @since 0.4.0
4214
- */
4441
+ /** State-bound inline invocation configuration. */
4215
4442
  export type InvokeDefinition<
4216
4443
  States extends StateSchemas,
4217
4444
  Events extends ReadonlyArray<TaggedSchema>,
4218
4445
  Emits extends ReadonlyArray<TaggedSchema>,
4219
4446
  StateId extends StateIdentifier<States>
4220
4447
  > =
4221
- | InvokeDefinitionValue
4222
- | ReadonlyArray<InvokeDefinitionValue>
4223
- | ((context: InvokeContext<States, Events, Emits, StateId>) =>
4224
- | InvokeDefinitionValue
4225
- | ReadonlyArray<InvokeDefinitionValue>)
4448
+ | InvokeConfig<States, Events, Emits, StateId>
4449
+ | ReadonlyArray<InvokeConfig<States, Events, Emits, StateId>>
4450
+
4451
+ type InvokeHandlerRequirement<Value, Handler> = IsAny<Value> extends true ? { readonly handler: Handler }
4452
+ : [Value] extends [never] ? { readonly handler?: never }
4453
+ : { readonly handler: Handler }
4454
+
4455
+ export type InvokeDoneRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends
4456
+ infer Requirement ? Requirement extends { readonly handler: infer Required } ? { readonly onDone: Required }
4457
+ : { readonly onDone?: never }
4458
+ : never
4459
+
4460
+ export type InvokeFailureRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends
4461
+ infer Requirement ? Requirement extends { readonly handler: infer Required } ? { readonly onFailure: Required }
4462
+ : { readonly onFailure?: never }
4463
+ : never
4464
+
4465
+ export type EffectInvokeArgs<
4466
+ States extends StateSchemas,
4467
+ Events extends ReadonlyArray<TaggedSchema>,
4468
+ Emits extends ReadonlyArray<TaggedSchema>,
4469
+ StateId extends StateIdentifier<States>,
4470
+ Fx extends Effect.Effect<any, any, any>,
4471
+ Source = Fx
4472
+ > =
4473
+ & {
4474
+ readonly id: InvokeLifecycleId
4475
+ readonly effect: Source
4476
+ readonly after?: never
4477
+ readonly logic?: never
4478
+ readonly child?: never
4479
+ readonly address?: never
4480
+ readonly onSnapshot?: never
4481
+ }
4482
+ & InvokeDoneRequirement<
4483
+ Effect.Success<NoInfer<Fx>>,
4484
+ InvokeTransition<
4485
+ States,
4486
+ Events,
4487
+ Emits,
4488
+ InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<NoInfer<Fx>>>
4489
+ >
4490
+ >
4491
+ & InvokeFailureRequirement<
4492
+ Effect.Error<NoInfer<Fx>>,
4493
+ InvokeTransition<
4494
+ States,
4495
+ Events,
4496
+ Emits,
4497
+ InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<NoInfer<Fx>>>
4498
+ >
4499
+ >
4500
+
4501
+ export type TimerInvokeArgs<
4502
+ States extends StateSchemas,
4503
+ Events extends ReadonlyArray<TaggedSchema>,
4504
+ Emits extends ReadonlyArray<TaggedSchema>,
4505
+ StateId extends StateIdentifier<States>
4506
+ > = {
4507
+ readonly id: InvokeLifecycleId
4508
+ readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId>>
4509
+ readonly effect?: never
4510
+ readonly logic?: never
4511
+ readonly child?: never
4512
+ readonly address?: never
4513
+ readonly onFailure?: never
4514
+ readonly onSnapshot?: never
4515
+ readonly onDone: InvokeTransition<
4516
+ States,
4517
+ Events,
4518
+ Emits,
4519
+ InvokeDoneContext<States, Events, Emits, StateId, void>
4520
+ >
4521
+ }
4522
+
4523
+ export type LogicInvokeArgs<
4524
+ States extends StateSchemas,
4525
+ Events extends ReadonlyArray<TaggedSchema>,
4526
+ Emits extends ReadonlyArray<TaggedSchema>,
4527
+ StateId extends StateIdentifier<States>,
4528
+ ChildState,
4529
+ ChildEvent,
4530
+ ChildError,
4531
+ ChildRequirements,
4532
+ ChildOutput,
4533
+ ChildInitialError,
4534
+ Address extends ChildAddress<never>,
4535
+ Source = Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>
4536
+ > =
4537
+ & {
4538
+ readonly id: InvokeLifecycleId
4539
+ readonly address: Address & ChildAddress.Compatibility<Address, ChildEvent>
4540
+ readonly logic: Source
4541
+ readonly effect?: never
4542
+ readonly after?: never
4543
+ readonly child?: never
4544
+ readonly onSnapshot?: InvokeTransition<
4545
+ States,
4546
+ Events,
4547
+ Emits,
4548
+ InvokeSnapshotContext<States, Events, Emits, StateId, ChildState, ChildError, ChildOutput>
4549
+ >
4550
+ }
4551
+ & InvokeDoneRequirement<
4552
+ ChildOutput,
4553
+ InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, ChildOutput>>
4554
+ >
4555
+ & InvokeFailureRequirement<
4556
+ ChildError,
4557
+ InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, ChildError>>
4558
+ >
4559
+
4560
+ export type ChildInvokeArgs<
4561
+ States extends StateSchemas,
4562
+ Events extends ReadonlyArray<TaggedSchema>,
4563
+ Emits extends ReadonlyArray<TaggedSchema>,
4564
+ StateId extends StateIdentifier<States>,
4565
+ ChildDefinition extends Machine.Any,
4566
+ Child extends ChildMachine<string, ChildDefinition>
4567
+ > =
4568
+ & {
4569
+ readonly child:
4570
+ & Child
4571
+ & (ChildDefinition extends EnsureExecutable<
4572
+ Machine.States<ChildDefinition>,
4573
+ Machine.UnhandledStates<ChildDefinition>,
4574
+ Machine.OutputStates<ChildDefinition>
4575
+ > ? unknown :
4576
+ never)
4577
+ readonly id?: never
4578
+ readonly address?: never
4579
+ readonly effect?: never
4580
+ readonly after?: never
4581
+ readonly logic?: never
4582
+ readonly onSnapshot?: InvokeTransition<
4583
+ States,
4584
+ Events,
4585
+ Emits,
4586
+ InvokeSnapshotContext<
4587
+ States,
4588
+ Events,
4589
+ Emits,
4590
+ StateId,
4591
+ Snapshot<Machine.States<ChildDefinition>>,
4592
+ Error<ChildDefinition>,
4593
+ Output<ChildDefinition>
4594
+ >
4595
+ >
4596
+ }
4597
+ & (Input<ChildDefinition> extends typeof Schema.Void ? { readonly input?: never } : {
4598
+ readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId>>
4599
+ })
4600
+ & InvokeDoneRequirement<
4601
+ Output<ChildDefinition>,
4602
+ InvokeTransition<
4603
+ States,
4604
+ Events,
4605
+ Emits,
4606
+ InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>>
4607
+ >
4608
+ >
4609
+ & InvokeFailureRequirement<
4610
+ Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
4611
+ InvokeTransition<
4612
+ States,
4613
+ Events,
4614
+ Emits,
4615
+ InvokeFailureContext<
4616
+ States,
4617
+ Events,
4618
+ Emits,
4619
+ StateId,
4620
+ Error<ChildDefinition> | ActionError<Services<ChildDefinition>>
4621
+ >
4622
+ >
4623
+ >
4624
+
4625
+ export type LogicStateOf<Value> = Value extends Logic<infer State, any, any, any, any, any> ? State : never
4626
+ export type LogicEventOf<Value> = Value extends Logic<any, infer Event, any, any, any, any> ? Event : never
4627
+ export type LogicErrorOf<Value> = Value extends Logic<any, any, infer Error, any, any, any> ? Error : never
4628
+ export type LogicServicesOf<Value> = Value extends Logic<any, any, any, infer Services, any, any> ? Services : never
4629
+ export type LogicOutputOf<Value> = Value extends Logic<any, any, any, any, infer Output, any> ? Output : never
4630
+ export type LogicInitialErrorOf<Value> = Value extends Logic<any, any, any, any, any, infer Error> ? Error : never
4631
+
4632
+ type ContextualInvokeConfig<
4633
+ States extends StateSchemas,
4634
+ Events extends ReadonlyArray<TaggedSchema>,
4635
+ Emits extends ReadonlyArray<TaggedSchema>,
4636
+ StateId extends StateIdentifier<States>,
4637
+ Raw
4638
+ > = Raw extends InvokeTyped<any, any, any, any, any> ? unknown
4639
+ : Raw extends { readonly effect: infer Source } ?
4640
+ InvokeResolvedSource<Source> extends infer Fx extends Effect.Effect<any, any, any> ?
4641
+ & InvokeDoneRequirement<
4642
+ Effect.Success<Fx>,
4643
+ InvokeTransition<
4644
+ States,
4645
+ Events,
4646
+ Emits,
4647
+ InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<Fx>>
4648
+ >
4649
+ >
4650
+ & InvokeFailureRequirement<
4651
+ Effect.Error<Fx>,
4652
+ InvokeTransition<
4653
+ States,
4654
+ Events,
4655
+ Emits,
4656
+ InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<Fx>>
4657
+ >
4658
+ >
4659
+ & { readonly onSnapshot?: never }
4660
+ : never
4661
+ : Raw extends { readonly after: unknown } ? {
4662
+ readonly onDone: InvokeTransition<
4663
+ States,
4664
+ Events,
4665
+ Emits,
4666
+ InvokeDoneContext<States, Events, Emits, StateId, void>
4667
+ >
4668
+ readonly onFailure?: never
4669
+ readonly onSnapshot?: never
4670
+ }
4671
+ : Raw extends { readonly logic: infer Source; readonly address: infer Address } ?
4672
+ InvokeResolvedSource<Source> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ?
4673
+ & InvokeDoneRequirement<
4674
+ InvokeOutput<Raw>,
4675
+ InvokeTransition<
4676
+ States,
4677
+ Events,
4678
+ Emits,
4679
+ InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>>
4680
+ >
4681
+ >
4682
+ & InvokeFailureRequirement<
4683
+ InvokeRuntimeError<Raw>,
4684
+ InvokeTransition<
4685
+ States,
4686
+ Events,
4687
+ Emits,
4688
+ InvokeFailureContext<States, Events, Emits, StateId, InvokeRuntimeError<Raw>>
4689
+ >
4690
+ >
4691
+ & {
4692
+ readonly address:
4693
+ & ChildAddress<never>
4694
+ & ChildAddress.Compatibility<
4695
+ Address,
4696
+ ChildLogic extends Logic<any, infer ChildEvent, any, any, any, any> ? ChildEvent : never
4697
+ >
4698
+ readonly onSnapshot?: InvokeTransition<
4699
+ States,
4700
+ Events,
4701
+ Emits,
4702
+ InvokeSnapshotContext<
4703
+ States,
4704
+ Events,
4705
+ Emits,
4706
+ StateId,
4707
+ ChildLogic extends Logic<infer ChildState, any, any, any, any, any> ? ChildState : never,
4708
+ InvokeRuntimeError<Raw>,
4709
+ InvokeOutput<Raw>
4710
+ >
4711
+ >
4712
+ }
4713
+ : never
4714
+ : Raw extends { readonly child: infer Child extends ChildMachine<string, infer ChildDefinition> } ?
4715
+ ChildMachineLogic<Child> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ?
4716
+ & InvokeDoneRequirement<
4717
+ Output<ChildDefinition>,
4718
+ InvokeTransition<
4719
+ States,
4720
+ Events,
4721
+ Emits,
4722
+ InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>>
4723
+ >
4724
+ >
4725
+ & InvokeFailureRequirement<
4726
+ Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
4727
+ InvokeTransition<
4728
+ States,
4729
+ Events,
4730
+ Emits,
4731
+ InvokeFailureContext<
4732
+ States,
4733
+ Events,
4734
+ Emits,
4735
+ StateId,
4736
+ Error<ChildDefinition> | ActionError<Services<ChildDefinition>>
4737
+ >
4738
+ >
4739
+ >
4740
+ & (Input<ChildDefinition> extends typeof Schema.Void ? { readonly input?: never } : {
4741
+ readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId>>
4742
+ })
4743
+ & {
4744
+ readonly onSnapshot?: InvokeTransition<
4745
+ States,
4746
+ Events,
4747
+ Emits,
4748
+ InvokeSnapshotContext<
4749
+ States,
4750
+ Events,
4751
+ Emits,
4752
+ StateId,
4753
+ Snapshot<Machine.States<ChildDefinition>>,
4754
+ Error<ChildDefinition>,
4755
+ Output<ChildDefinition>
4756
+ >
4757
+ >
4758
+ }
4759
+ : never
4760
+ : never
4761
+
4762
+ type ContextualInvokeDefinition<
4763
+ States extends StateSchemas,
4764
+ Events extends ReadonlyArray<TaggedSchema>,
4765
+ Emits extends ReadonlyArray<TaggedSchema>,
4766
+ StateId extends StateIdentifier<States>,
4767
+ Raw
4768
+ > = Raw extends ReadonlyArray<any> ? {
4769
+ readonly [Index in keyof Raw]: ContextualInvokeConfig<States, Events, Emits, StateId, Raw[Index]>
4770
+ }
4771
+ : ContextualInvokeConfig<States, Events, Emits, StateId, Raw>
4226
4772
 
4227
4773
  type OutputHandlerConfig<
4228
4774
  States extends StateSchemas,
@@ -4328,10 +4874,14 @@ export declare namespace Machine {
4328
4874
  StateId extends StateIdentifier<States>
4329
4875
  > = NodeByIdentifier<States, StateId> extends infer Node ?
4330
4876
  Node extends { readonly type: "parallel"; readonly states: infer Children extends StateSchemas } ? {
4331
- readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]>["Type"]
4877
+ readonly [Key in ActiveStateKey<Children> as NodeSchema<Children[Key]> extends never ? never : Key]: NodeValue<
4878
+ Children[Key]
4879
+ >
4332
4880
  }
4333
4881
  : Node extends { readonly states: infer Children extends StateSchemas; readonly initial: infer Initial } ?
4334
- Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]>["Type"] : never
4882
+ Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never
4883
+ : NodeValue<Children[Initial]>
4884
+ : never
4335
4885
  : never
4336
4886
  : never
4337
4887
 
@@ -4504,6 +5054,39 @@ export declare namespace Machine {
4504
5054
  : Path extends keyof Config ? Config[Path]
4505
5055
  : never
4506
5056
 
5057
+ type HandlerInvokeContextAtPath<
5058
+ AllStates extends StateSchemas,
5059
+ Events extends ReadonlyArray<TaggedSchema>,
5060
+ Emits extends ReadonlyArray<TaggedSchema>,
5061
+ Config,
5062
+ StateId extends StateNodeIdentifier<AllStates>,
5063
+ NodeConfig = HandlerConfigAtPath<Config, StateId>
5064
+ > = StateId extends StateIdentifier<AllStates> ?
5065
+ NodeConfig extends { readonly invoke: infer Invoke } ? HandlerValidationAtPath<
5066
+ StateId,
5067
+ { readonly invoke: ContextualInvokeDefinition<AllStates, Events, Emits, StateId, Invoke> }
5068
+ >
5069
+ : unknown
5070
+ : unknown
5071
+
5072
+ type HandlerInvokeContexts<
5073
+ AllStates extends StateSchemas,
5074
+ Events extends ReadonlyArray<TaggedSchema>,
5075
+ Emits extends ReadonlyArray<TaggedSchema>,
5076
+ Config
5077
+ > = Types.UnionToIntersection<
5078
+ StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ?
5079
+ StateId extends StateNodeIdentifier<AllStates> ? HandlerInvokeContextAtPath<
5080
+ AllStates,
5081
+ Events,
5082
+ Emits,
5083
+ Config,
5084
+ StateId
5085
+ >
5086
+ : never
5087
+ : never
5088
+ >
5089
+
4507
5090
  // Rebuild the public nested handler shape so branded validation errors stay
4508
5091
  // attached to the exact property that introduced them.
4509
5092
  type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
@@ -4818,9 +5401,7 @@ export declare namespace Machine {
4818
5401
  & HandlerOnTargetValidation<StateId, Config>
4819
5402
  & HandlerDirectTargetValidation<StateId, Config, "always">
4820
5403
  & HandlerDirectTargetValidation<StateId, Config, "onDone">
4821
- & HandlerInvokeOutputValidation<Events, StateId, Config>
4822
5404
  & HandlerInvokeEmitsValidation<Events, StateId, Config>
4823
- & HandlerInvokeSnapshotValidation<Events, StateId, Config>
4824
5405
  & HandlerChildrenValidation<Node, StateId, Config>
4825
5406
  & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config>
4826
5407
  & HandlerRuntimeValidation<Events, Emits, StateId, Config>
@@ -4849,20 +5430,6 @@ export declare namespace Machine {
4849
5430
  }
4850
5431
  : unknown
4851
5432
 
4852
- type HandlerInvokeOutputValidation<
4853
- Events extends ReadonlyArray<TaggedSchema>,
4854
- StateId extends string,
4855
- Config
4856
- > = [InvokeReturn<Config>] extends [never] ? unknown
4857
- : [Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>] extends [never] ? unknown
4858
- : {
4859
- readonly invoke: HandlerValidationError<
4860
- "Invoked child output must be a machine event or void",
4861
- StateId,
4862
- Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>
4863
- >
4864
- }
4865
-
4866
5433
  type HandlerInvokeEmitsValidation<
4867
5434
  Events extends ReadonlyArray<TaggedSchema>,
4868
5435
  StateId extends string,
@@ -4877,21 +5444,6 @@ export declare namespace Machine {
4877
5444
  >
4878
5445
  }
4879
5446
 
4880
- type HandlerInvokeSnapshotValidation<
4881
- Events extends ReadonlyArray<TaggedSchema>,
4882
- StateId extends string,
4883
- Config
4884
- > = [InvokeReturn<Config>] extends [never] ? unknown
4885
- : IsAny<InvokeSnapshotEvent<InvokeReturn<Config>>> extends true ? unknown
4886
- : [Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>] extends [never] ? unknown
4887
- : {
4888
- readonly invoke: HandlerValidationError<
4889
- "Invoked child snapshot mapper must return a machine event or undefined",
4890
- StateId,
4891
- Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>
4892
- >
4893
- }
4894
-
4895
5447
  type HandlerRuntimeValidation<
4896
5448
  Events extends ReadonlyArray<TaggedSchema>,
4897
5449
  Emits extends ReadonlyArray<TaggedSchema>,
@@ -5095,6 +5647,7 @@ export declare namespace Machine {
5095
5647
  <const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(
5096
5648
  config:
5097
5649
  & Config
5650
+ & HandlerInvokeContexts<States, Events, Emits, NoInfer<Config>>
5098
5651
  & HandlerTreeValidation<
5099
5652
  States,
5100
5653
  Events,
@@ -5303,7 +5856,9 @@ export const isFinal: <
5303
5856
  *
5304
5857
  * The returned `states` property is the same object passed to `defineStates`.
5305
5858
  * The returned `initial` builder creates snapshots without user-authored path
5306
- * strings and enforces compound and parallel initial-state rules.
5859
+ * strings and enforces compound and parallel initial-state rules. Active nodes
5860
+ * may omit `schema` when they own no value; those builders expose `.from(...)`
5861
+ * and still participate fully in targeting, matching, and snapshots.
5307
5862
  *
5308
5863
  * **Example** (Atomic initial snapshot)
5309
5864
  *
@@ -5414,8 +5969,8 @@ interface Make {
5414
5969
  * to implement state behavior with ordinary TypeScript control flow.
5415
5970
  *
5416
5971
  * Schemas in `events` define the public input protocol. Schemas in
5417
- * `internalEvents` are added to the complete handler protocol for invoke
5418
- * results, child emissions, and other machine-local deliveries. Their tags
5972
+ * `internalEvents` are added to the complete handler protocol for raised
5973
+ * events, child emissions, and other machine-local deliveries. Their tags
5419
5974
  * must be disjoint.
5420
5975
  *
5421
5976
  * **Example** (Typed counter machine)
@@ -5469,6 +6024,9 @@ type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends
5469
6024
  * Events supplied through ordinary `send` and `plan` calls remain untrusted
5470
6025
  * and continue through full runtime schema validation.
5471
6026
  * Treat the returned event as immutable after construction.
6027
+ * This eager low-level constructor throws `MachineSchemaDecodeError` when
6028
+ * construction fails. Prefer {@link events} and {@link internalEvents} for
6029
+ * ordinary delivery so construction remains inside the machine error channel.
5472
6030
  *
5473
6031
  * The schema must be one of the machine's configured public or internal event
5474
6032
  * schemas, or a case schema belonging to a configured `Schema.TaggedUnion`.
@@ -5504,12 +6062,49 @@ export const event: <const M extends Machine.Any, const EventSchema extends Mach
5504
6062
  ) => EventSchema["Type"] = internal.event
5505
6063
 
5506
6064
  /**
5507
- * Encodes a decoded machine snapshot into a normalized data representation.
6065
+ * Returns deferred constructors for every public event in a machine protocol.
5508
6066
  *
5509
- * **When to use**
6067
+ * Constructor inputs retain their schema-derived required fields, defaults,
6068
+ * and transformations. Construction is deferred until delivery so failures
6069
+ * enter the machine's `MachineSchemaDecodeError` channel rather than throwing
6070
+ * at the call site.
5510
6071
  *
5511
- * Use when you need to store or transport a statechart snapshot independently
5512
- * of its local machine runtime.
6072
+ * **Example**
6073
+ *
6074
+ * ```ts
6075
+ * const Event = Machine.events(counter)
6076
+ * yield* ref.send(Event.Increment({ by: 1 }))
6077
+ * ```
6078
+ *
6079
+ * @category constructors
6080
+ * @since 0.9.0
6081
+ */
6082
+ export const events: <const M extends Machine.Any>(
6083
+ machine: M
6084
+ ) => Machine.EventConstructors<Machine.InputEvents<M>> = internal.events
6085
+
6086
+ /**
6087
+ * Returns deferred constructors for every internal event in a machine
6088
+ * protocol.
6089
+ *
6090
+ * Use these constructors for raised events and other machine-local deliveries.
6091
+ * Construction failures are reported through the
6092
+ * owning machine's `MachineSchemaDecodeError` channel.
6093
+ *
6094
+ * @category constructors
6095
+ * @since 0.9.0
6096
+ */
6097
+ export const internalEvents: <const M extends Machine.Any>(
6098
+ machine: M
6099
+ ) => Machine.EventConstructors<Machine.InternalEvents<M>> = internal.internalEvents
6100
+
6101
+ /**
6102
+ * Encodes a decoded machine snapshot into a normalized data representation.
6103
+ *
6104
+ * **When to use**
6105
+ *
6106
+ * Use when you need to store or transport a statechart snapshot independently
6107
+ * of its local machine runtime.
5513
6108
  *
5514
6109
  * **Details**
5515
6110
  *
@@ -5668,63 +6263,231 @@ export const decodeSnapshot: <
5668
6263
  Machine.SnapshotDecodingServices<States>
5669
6264
  > = internal.decodeSnapshot
5670
6265
 
6266
+ type DynamicEffectInvokeSource<
6267
+ States extends Machine.StateSchemas,
6268
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6269
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6270
+ StateId extends Machine.StateIdentifier<States>,
6271
+ Source extends (
6272
+ context: Machine.InvokeContext<States, Events, Emits, StateId>
6273
+ ) => Effect.Effect<unknown, unknown, unknown>
6274
+ > = {
6275
+ readonly id: InvokeLifecycleId
6276
+ readonly effect: Source
6277
+ readonly after?: never
6278
+ readonly logic?: never
6279
+ readonly child?: never
6280
+ readonly address?: never
6281
+ readonly onSnapshot?: never
6282
+ }
6283
+
6284
+ type DynamicEffectDoneHandler<
6285
+ States extends Machine.StateSchemas,
6286
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6287
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6288
+ StateId extends Machine.StateIdentifier<States>,
6289
+ Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
6290
+ > = Machine.InvokeTransition<
6291
+ States,
6292
+ Events,
6293
+ Emits,
6294
+ Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>>
6295
+ >
6296
+
6297
+ type DynamicEffectFailureHandler<
6298
+ States extends Machine.StateSchemas,
6299
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6300
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6301
+ StateId extends Machine.StateIdentifier<States>,
6302
+ Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
6303
+ > = Machine.InvokeTransition<
6304
+ States,
6305
+ Events,
6306
+ Emits,
6307
+ Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>>
6308
+ >
6309
+
6310
+ type DynamicEffectInvokeResult<
6311
+ States extends Machine.StateSchemas,
6312
+ Events extends ReadonlyArray<Machine.TaggedSchema>,
6313
+ Emits extends ReadonlyArray<Machine.TaggedSchema>,
6314
+ StateId extends Machine.StateIdentifier<States>,
6315
+ Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
6316
+ > =
6317
+ & Machine.InvokeConfig<States, Events, Emits, StateId>
6318
+ & Machine.InvokeTyped<
6319
+ Effect.Success<ReturnType<Source>>,
6320
+ Effect.Error<ReturnType<Source>>,
6321
+ Effect.Services<ReturnType<Source>>,
6322
+ never
6323
+ >
6324
+
6325
+ type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false
6326
+
5671
6327
  /**
5672
- * Creates an invoked child process configuration for an active state.
6328
+ * Preserves inference for a state-owned invocation configuration.
5673
6329
  *
5674
- * **When to use**
6330
+ * Use `effect` for one-shot work, `after` for a cancellable timer, `logic` for
6331
+ * reusable process logic, or `child` for a complete child machine. `onDone` is
6332
+ * required whenever the source can complete with an output, while `onFailure`
6333
+ * is required only when the source has a typed failure channel.
5675
6334
  *
5676
- * Use to run a child process while a machine remains in a state. Successful
5677
- * outputs are sent directly to the parent machine as events; `void` sends
5678
- * nothing. Unrecovered child failures fail the owning machine. Active
5679
- * snapshots can optionally be mapped to progress events.
5680
- *
5681
- * **Gotchas**
5682
- *
5683
- * Invoked child processes run while their owning state is active and are
5684
- * stopped before the state exits. An unrecovered child failure fails the owning
5685
- * machine; recover inside the child Effect when failure should become an event.
5686
- * The `id` is a state-local lifecycle key, not a communication address. To
5687
- * send events to the invocation, pass a typed `childAddress` as `address`.
5688
- * The `src` callback is intentionally independent from its parent state. When
5689
- * construction depends on the typed state, lifecycle event, or runtime, use
5690
- * the state config factory form `invoke: (context) => Machine.invoke(...)` and
5691
- * close over that context from `src`.
5692
- *
5693
- * **Example** (Effect output as a parent event)
6335
+ * This constructor is an identity at runtime, but preserves lifecycle callback
6336
+ * inference through published declarations. Effects and durations may be
6337
+ * supplied directly or derived from the owning state's entry context. Dynamic
6338
+ * Effect sources infer the owner context, output, error, and service channels
6339
+ * together without a return annotation. Logic invocations require both a
6340
+ * lifecycle `id` and a typed communication `address`. Child descriptors already
6341
+ * own their identity, so `id` and `address` must not be repeated.
5694
6342
  *
5695
6343
  * ```ts
5696
- * import { Effect, Schema } from "effect"
5697
- * import { Machine } from "@typeonce/effect-machine"
5698
- *
5699
- * class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
5700
- * value: Schema.String
5701
- * }) {}
5702
- *
5703
- * const load = Machine.invoke({
6344
+ * invoke: Machine.invoke({
5704
6345
  * id: "load",
5705
- * src: () => Machine.effect(Effect.succeed(new Loaded({ value: "ready" })))
6346
+ * effect: Effect.tryPromise({
6347
+ * try: () => fetch("/api/data").then((response) => response.json()),
6348
+ * catch: (cause) => new LoadError({ cause })
6349
+ * }),
6350
+ * onDone: ({ output, target }) => target.full.Ready({ data: output }),
6351
+ * onFailure: ({ error, target }) => target.full.Failed({ error })
5706
6352
  * })
5707
6353
  * ```
5708
6354
  *
5709
- * @see {@link effect} for one-shot child effects.
5710
- * @see {@link spawn} for children whose lifetime is controlled by actions.
5711
6355
  * @category constructors
5712
- * @since 0.4.0
6356
+ * @since 0.9.0
5713
6357
  */
5714
- export const invoke: <
5715
- ChildState,
5716
- ChildEvent,
5717
- ChildError = never,
5718
- ChildRequirements = never,
5719
- ChildOutput = never,
5720
- ChildInitialError = never,
5721
- Event = never,
5722
- Address extends ChildAddress<never> | undefined = undefined
5723
- >(
5724
- config:
5725
- & {
5726
- readonly id: InvokeLifecycleId
5727
- readonly src: () => Logic<
6358
+ export const invoke: {
6359
+ <
6360
+ const States extends Machine.StateSchemas,
6361
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6362
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6363
+ StateId extends Machine.StateIdentifier<States>,
6364
+ const Source extends (
6365
+ context: Machine.InvokeContext<States, Events, Emits, StateId>
6366
+ ) => Effect.Effect<unknown, unknown, unknown>
6367
+ >(
6368
+ config:
6369
+ & DynamicEffectInvokeSource<States, Events, Emits, StateId, Source>
6370
+ & {
6371
+ readonly onDone: DynamicEffectDoneHandler<States, Events, Emits, StateId, Source>
6372
+ readonly onFailure: DynamicEffectFailureHandler<States, Events, Emits, StateId, Source>
6373
+ },
6374
+ ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
6375
+ "onDone must be omitted when the Effect output is never"
6376
+ ]
6377
+ : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
6378
+ "onFailure must be omitted when the Effect error is never"
6379
+ ]
6380
+ : []
6381
+ ): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>
6382
+ <
6383
+ const States extends Machine.StateSchemas,
6384
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6385
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6386
+ StateId extends Machine.StateIdentifier<States>,
6387
+ const Source extends (
6388
+ context: Machine.InvokeContext<States, Events, Emits, StateId>
6389
+ ) => Effect.Effect<unknown, never, unknown>
6390
+ >(
6391
+ config:
6392
+ & DynamicEffectInvokeSource<States, Events, Emits, StateId, Source>
6393
+ & {
6394
+ readonly onDone: DynamicEffectDoneHandler<States, Events, Emits, StateId, Source>
6395
+ readonly onFailure?: never
6396
+ },
6397
+ ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
6398
+ "onDone must be omitted when the Effect output is never"
6399
+ ]
6400
+ : []
6401
+ ): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>
6402
+ <
6403
+ const States extends Machine.StateSchemas,
6404
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6405
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6406
+ StateId extends Machine.StateIdentifier<States>,
6407
+ const Source extends (
6408
+ context: Machine.InvokeContext<States, Events, Emits, StateId>
6409
+ ) => Effect.Effect<never, unknown, unknown>
6410
+ >(
6411
+ config:
6412
+ & DynamicEffectInvokeSource<States, Events, Emits, StateId, Source>
6413
+ & {
6414
+ readonly onDone?: never
6415
+ readonly onFailure: DynamicEffectFailureHandler<States, Events, Emits, StateId, Source>
6416
+ },
6417
+ ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
6418
+ "onFailure must be omitted when the Effect error is never"
6419
+ ]
6420
+ : []
6421
+ ): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>
6422
+ <
6423
+ const States extends Machine.StateSchemas,
6424
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6425
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6426
+ StateId extends Machine.StateIdentifier<States>,
6427
+ const Source extends (
6428
+ context: Machine.InvokeContext<States, Events, Emits, StateId>
6429
+ ) => Effect.Effect<never, never, unknown>
6430
+ >(
6431
+ config:
6432
+ & DynamicEffectInvokeSource<States, Events, Emits, StateId, Source>
6433
+ & {
6434
+ readonly onDone?: never
6435
+ readonly onFailure?: never
6436
+ }
6437
+ ): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>
6438
+ <
6439
+ const States extends Machine.StateSchemas,
6440
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6441
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6442
+ StateId extends Machine.StateIdentifier<States>,
6443
+ const Fx extends Effect.Effect<any, any, any>,
6444
+ const Config extends object
6445
+ >(
6446
+ config: Config & Machine.EffectInvokeArgs<States, Events, Emits, StateId, Fx>
6447
+ ):
6448
+ & Config
6449
+ & Machine.InvokeOwned<States, Events, Emits, StateId>
6450
+ & Machine.InvokeTyped<
6451
+ Effect.Success<Fx>,
6452
+ Effect.Error<Fx>,
6453
+ Effect.Services<Fx>,
6454
+ never
6455
+ >
6456
+ <
6457
+ const States extends Machine.StateSchemas,
6458
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6459
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6460
+ StateId extends Machine.StateIdentifier<States>,
6461
+ const Config extends object
6462
+ >(
6463
+ config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId>
6464
+ ): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>
6465
+ <
6466
+ const States extends Machine.StateSchemas,
6467
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6468
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6469
+ StateId extends Machine.StateIdentifier<States>,
6470
+ ChildState,
6471
+ ChildEvent,
6472
+ ChildError,
6473
+ ChildRequirements,
6474
+ ChildOutput,
6475
+ ChildInitialError,
6476
+ Address extends ChildAddress<never>
6477
+ >(
6478
+ config: Machine.LogicInvokeArgs<
6479
+ States,
6480
+ Events,
6481
+ Emits,
6482
+ StateId,
6483
+ ChildState,
6484
+ ChildEvent,
6485
+ ChildError,
6486
+ ChildRequirements,
6487
+ ChildOutput,
6488
+ ChildInitialError,
6489
+ Address,
6490
+ (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Logic<
5728
6491
  ChildState,
5729
6492
  ChildEvent,
5730
6493
  ChildError,
@@ -5732,136 +6495,73 @@ export const invoke: <
5732
6495
  ChildOutput,
5733
6496
  ChildInitialError
5734
6497
  >
5735
- readonly snapshot?: (
5736
- context: Machine.InvokeSnapshotContext<ChildState, ChildError, ChildOutput>
5737
- ) => Event | undefined
5738
- }
5739
- & ([Address] extends [undefined] ? {
5740
- readonly address?: never
5741
- }
5742
- : {
5743
- readonly address: Exclude<Address, undefined>
5744
- } & ChildAddress.Compatibility<Exclude<Address, undefined>, NoInfer<ChildEvent>>)
5745
- ) => Machine.InvokeConfig<
5746
- any,
5747
- any,
5748
- any,
5749
- any,
5750
- Event,
5751
- ChildState,
5752
- ChildEvent,
5753
- ChildError,
5754
- ChildRequirements,
5755
- ChildOutput,
5756
- ChildInitialError
5757
- > = internal.invoke
5758
-
5759
- type InvokeEffectResult<Requirements, Event> = Machine.InvokeConfig<
5760
- any,
5761
- any,
5762
- any,
5763
- any,
5764
- never,
5765
- void,
5766
- never,
5767
- never,
5768
- Requirements,
5769
- Event | void,
5770
- never
5771
- >
5772
-
5773
- type InvokeEffectIsInfallible<Fx extends Effect.Effect<any, any, any>> = IsAny<Effect.Error<Fx>> extends true ? false
5774
- : [Effect.Error<Fx>] extends [never] ? true
5775
- : false
5776
-
5777
- type InvokeEffectConfig<
5778
- Fx extends Effect.Effect<any, any, any>,
5779
- SuccessEvent,
5780
- FailureEvent
5781
- > =
5782
- & {
5783
- readonly id: InvokeLifecycleId
5784
- readonly effect: Fx
5785
- readonly onSuccess: (value: NoInfer<Effect.Success<Fx>>) => SuccessEvent | void
5786
- }
5787
- & (
5788
- InvokeEffectIsInfallible<Fx> extends true ? {
5789
- readonly onFailure?: never
5790
- }
5791
- : {
5792
- readonly onFailure: (error: NoInfer<Effect.Error<Fx>>) => FailureEvent | void
5793
- }
5794
- )
5795
-
5796
- /**
5797
- * Invokes one Effect and maps its typed outcome into machine-local events.
5798
- *
5799
- * **Details**
5800
- *
5801
- * This is the high-level one-shot counterpart to `invoke`. Success and typed
5802
- * failure values are mapped independently, so callers do not need to recover
5803
- * an Effect into a common event union by hand. Defects and interruption remain
5804
- * failures of the owning machine.
5805
- *
5806
- * Declare mapped outcomes in `internalEvents` unless they are also legitimate
5807
- * public commands.
5808
- *
5809
- * **Example**
5810
- *
5811
- * ```ts
5812
- * import { Effect, Schema } from "effect"
5813
- * import { Machine } from "@typeonce/effect-machine"
5814
- *
5815
- * class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
5816
- * value: Schema.String
5817
- * }) {}
5818
- *
5819
- * const load = Machine.invokeEffect({
5820
- * id: "load",
5821
- * effect: Effect.succeed("ready"),
5822
- * onSuccess: (value) => new Loaded({ value })
5823
- * })
5824
- * ```
5825
- *
5826
- * @see {@link invoke} for arbitrary child process logic.
5827
- * @see {@link after} for a state-scoped delayed event.
5828
- * @category constructors
5829
- * @since 0.4.0
5830
- */
5831
- export const invokeEffect: <const Fx extends Effect.Effect<any, any, any>, SuccessEvent, FailureEvent = never>(
5832
- config: InvokeEffectConfig<Fx, SuccessEvent, FailureEvent>
5833
- ) => InvokeEffectResult<
5834
- Effect.Services<Fx>,
5835
- SuccessEvent | (InvokeEffectIsInfallible<Fx> extends true ? never : FailureEvent)
5836
- > = internal.invokeEffect
5837
-
5838
- /**
5839
- * Creates a cancellable state-scoped delayed event.
5840
- *
5841
- * The timer starts when its owning state is entered and is interrupted when
5842
- * that state exits. The delayed value should normally be declared in
5843
- * `internalEvents`.
5844
- *
5845
- * **Example**
5846
- *
5847
- * ```ts
5848
- * import { Schema } from "effect"
5849
- * import { Machine } from "@typeonce/effect-machine"
5850
- *
5851
- * class TimedOut extends Schema.TaggedClass<TimedOut>("TimedOut")("TimedOut", {}) {}
5852
- *
5853
- * const timeout = Machine.after("5 seconds", new TimedOut({}))
5854
- * ```
5855
- *
5856
- * @category constructors
5857
- * @since 0.4.0
5858
- */
5859
- export const after: <Event extends { readonly _tag: PropertyKey }>(
5860
- duration: Duration.Input,
5861
- event: Event,
5862
- options?: { readonly id?: InvokeLifecycleId }
5863
- ) => InvokeEffectResult<never, Event> = internal.after
5864
-
6498
+ >
6499
+ ):
6500
+ & Machine.InvokeConfig<States, Events, Emits, StateId>
6501
+ & Machine.InvokeTyped<
6502
+ ChildOutput,
6503
+ ChildError,
6504
+ ChildRequirements,
6505
+ ChildInitialError
6506
+ >
6507
+ <
6508
+ const States extends Machine.StateSchemas,
6509
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6510
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6511
+ StateId extends Machine.StateIdentifier<States>,
6512
+ ChildState,
6513
+ ChildEvent,
6514
+ ChildError,
6515
+ ChildRequirements,
6516
+ ChildOutput,
6517
+ ChildInitialError,
6518
+ Address extends ChildAddress<never>,
6519
+ const Config extends object
6520
+ >(
6521
+ config:
6522
+ & Config
6523
+ & Machine.LogicInvokeArgs<
6524
+ States,
6525
+ Events,
6526
+ Emits,
6527
+ StateId,
6528
+ ChildState,
6529
+ ChildEvent,
6530
+ ChildError,
6531
+ ChildRequirements,
6532
+ ChildOutput,
6533
+ ChildInitialError,
6534
+ Address
6535
+ >
6536
+ ):
6537
+ & Config
6538
+ & Machine.InvokeOwned<States, Events, Emits, StateId>
6539
+ & Machine.InvokeTyped<
6540
+ ChildOutput,
6541
+ ChildError,
6542
+ ChildRequirements,
6543
+ ChildInitialError
6544
+ >
6545
+ <
6546
+ const States extends Machine.StateSchemas,
6547
+ const Events extends ReadonlyArray<Machine.TaggedSchema>,
6548
+ const Emits extends ReadonlyArray<Machine.TaggedSchema>,
6549
+ StateId extends Machine.StateIdentifier<States>,
6550
+ const Child extends ChildMachine.Any,
6551
+ const Config extends object
6552
+ >(
6553
+ config: Config & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child>
6554
+ ):
6555
+ & Config
6556
+ & Machine.InvokeOwned<States, Events, Emits, StateId>
6557
+ & Machine.InvokeTyped<
6558
+ Machine.Output<Child["machine"]>,
6559
+ Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>,
6560
+ Machine.Services<Child["machine"]>,
6561
+ Machine.InitialError<Child["machine"]>,
6562
+ Machine.Emit<Child["machine"]>
6563
+ >
6564
+ } = ((config: unknown) => config) as any
5865
6565
  type RetagFields<Target extends Machine.TaggedSchema> = Omit<Target["~type.make.in"], "_tag">
5866
6566
 
5867
6567
  type RetagTargetCompatibility<Target extends Machine.TaggedSchema> = Target extends {
@@ -5913,195 +6613,6 @@ export const retag: <const Target extends Machine.TaggedSchema, const Source ext
5913
6613
  ...args: RetagArgs<Target, Source>
5914
6614
  ) => Target["Type"] = internal.retag
5915
6615
 
5916
- type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.Void ? {
5917
- readonly input?: never
5918
- }
5919
- : {
5920
- readonly input: Input["Type"]
5921
- }
5922
-
5923
- /**
5924
- * Creates an invoked child process from a complete statechart machine.
5925
- *
5926
- * **When to use**
5927
- *
5928
- * Use when a state should own another statechart machine and communicate with
5929
- * it through typed child events, emissions, snapshots, or terminal output.
5930
- *
5931
- * **Details**
5932
- *
5933
- * Child emissions are delivered directly to the parent as events. Active
5934
- * snapshots and terminal output can be mapped to parent events. The owning
5935
- * state controls the child lifetime.
5936
- *
5937
- * **Gotchas**
5938
- *
5939
- * Active invoked machines must have unique child addresses. A machine starts
5940
- * after its owning state's entry actions, so those actions cannot send events
5941
- * to a newly entered child. Unrecovered child failures fail the parent.
5942
- *
5943
- * @see {@link invoke} for invoking lower-level process logic.
5944
- * @see {@link sendTo} for sending events to the invoked machine.
5945
- * @category constructors
5946
- * @since 0.4.0
5947
- */
5948
- export const invokeMachine: {
5949
- <
5950
- const States extends Machine.StateSchemas,
5951
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
5952
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
5953
- const Input extends Schema.Top = typeof Schema.Void,
5954
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
5955
- E = never,
5956
- R = never,
5957
- InitialE = never,
5958
- InitialR = never,
5959
- FinalStates extends Machine.StateIdentifier<States> = never,
5960
- Output = never,
5961
- SnapshotEvent = never,
5962
- DoneEvent = never,
5963
- Id extends string = string,
5964
- OutputStates extends Machine.StateIdentifier<States> = never,
5965
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
5966
- >(
5967
- config:
5968
- & {
5969
- readonly child: ChildMachine<
5970
- Id,
5971
- & Machine<
5972
- States,
5973
- Events,
5974
- Input,
5975
- UnhandledStates,
5976
- E,
5977
- R,
5978
- InitialE,
5979
- InitialR,
5980
- FinalStates,
5981
- Output,
5982
- Emits,
5983
- OutputStates,
5984
- InputEvents
5985
- >
5986
- & EnsureExecutable<States, UnhandledStates, OutputStates>
5987
- >
5988
- readonly snapshot?: (
5989
- context: Machine.InvokeSnapshotContext<
5990
- Machine.Snapshot<States>,
5991
- | E
5992
- | ActionError<R>
5993
- | InfiniteTransitionError
5994
- | MachineSchemaDecodeError
5995
- | StoppedError,
5996
- Output
5997
- >
5998
- ) => SnapshotEvent | undefined
5999
- readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined
6000
- }
6001
- & InvokeMachineInput<Input>
6002
- ): Machine.InvokeConfig<
6003
- any,
6004
- any,
6005
- any,
6006
- any,
6007
- SnapshotEvent,
6008
- Machine.Snapshot<States>,
6009
- Machine.EventOf<InputEvents>,
6010
- E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
6011
- ExcludeCompatibleRuntime<
6012
- Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>,
6013
- Machine.EventOf<Events>,
6014
- Machine.EmitOf<Emits>
6015
- >,
6016
- Output,
6017
- | InitialE
6018
- | E
6019
- | ActionError<InitialR | R>
6020
- | InfiniteTransitionError
6021
- | MachineSchemaDecodeError
6022
- | StartupError
6023
- | StoppedError,
6024
- Machine.EmitOf<Emits>,
6025
- DoneEvent
6026
- >
6027
- <
6028
- const States extends Machine.StateSchemas,
6029
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
6030
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
6031
- const Input extends Schema.Top = typeof Schema.Void,
6032
- UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>,
6033
- E = never,
6034
- R = never,
6035
- InitialE = never,
6036
- InitialR = never,
6037
- FinalStates extends Machine.StateIdentifier<States> = never,
6038
- Output = never,
6039
- SnapshotEvent = never,
6040
- Id extends string = string,
6041
- OutputStates extends Machine.StateIdentifier<States> = never,
6042
- InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events
6043
- >(
6044
- config:
6045
- & {
6046
- readonly child: ChildMachine<
6047
- Id,
6048
- & Machine<
6049
- States,
6050
- Events,
6051
- Input,
6052
- UnhandledStates,
6053
- E,
6054
- R,
6055
- InitialE,
6056
- InitialR,
6057
- FinalStates,
6058
- Output,
6059
- Emits,
6060
- OutputStates,
6061
- InputEvents
6062
- >
6063
- & EnsureExecutable<States, UnhandledStates, OutputStates>
6064
- >
6065
- readonly snapshot?: (
6066
- context: Machine.InvokeSnapshotContext<
6067
- Machine.Snapshot<States>,
6068
- | E
6069
- | ActionError<R>
6070
- | InfiniteTransitionError
6071
- | MachineSchemaDecodeError
6072
- | StoppedError,
6073
- Output
6074
- >
6075
- ) => SnapshotEvent | undefined
6076
- readonly onDone?: never
6077
- }
6078
- & InvokeMachineInput<Input>
6079
- ): Machine.InvokeConfig<
6080
- any,
6081
- any,
6082
- any,
6083
- any,
6084
- SnapshotEvent,
6085
- Machine.Snapshot<States>,
6086
- Machine.EventOf<InputEvents>,
6087
- E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError,
6088
- ExcludeCompatibleRuntime<
6089
- Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>,
6090
- Machine.EventOf<Events>,
6091
- Machine.EmitOf<Emits>
6092
- >,
6093
- Output,
6094
- | InitialE
6095
- | E
6096
- | ActionError<InitialR | R>
6097
- | InfiniteTransitionError
6098
- | MachineSchemaDecodeError
6099
- | StartupError
6100
- | StoppedError,
6101
- Machine.EmitOf<Emits>
6102
- >
6103
- } = internal.invokeMachine
6104
-
6105
6616
  /**
6106
6617
  * Plans the initial state for a machine without executing actor commands.
6107
6618
  *
@@ -6263,10 +6774,9 @@ export const transitionDefinitions: <M extends Machine.Any>(machine: M) => Reado
6263
6774
  *
6264
6775
  * **Details**
6265
6776
  *
6266
- * Static `invoke`, `invokeEffect`, `after`, and `invokeMachine` descriptors
6267
- * expose stable ownership and lifecycle metadata without serializing runtime
6268
- * values. Function-valued invoke factories are represented as dynamic and are
6269
- * never evaluated during inspection.
6777
+ * Static inline invocation definitions expose stable ownership and lifecycle
6778
+ * metadata without serializing runtime values. Function-valued sources are
6779
+ * represented as dynamic and are never evaluated during inspection.
6270
6780
  *
6271
6781
  * @category getters
6272
6782
  * @since 0.4.0
@@ -6414,7 +6924,7 @@ export const plan: <
6414
6924
  >
6415
6925
  & EnsureExecutable<States, UnhandledStates, OutputStates>,
6416
6926
  state: Machine.Snapshot<States>,
6417
- event: Machine.EventOf<InputEvents>
6927
+ event: Machine.EventInputOf<InputEvents>
6418
6928
  ) => Effect.Effect<
6419
6929
  & {
6420
6930
  readonly next: Machine.Snapshot<States>
@@ -6452,52 +6962,6 @@ export const plan: <
6452
6962
  never
6453
6963
  > = internal.plan
6454
6964
 
6455
- /**
6456
- * Creates a one-shot child process from an Effect.
6457
- *
6458
- * **When to use**
6459
- *
6460
- * Use when you need side effects that produce one typed output or error.
6461
- *
6462
- * **Details**
6463
- *
6464
- * The Effect may run arbitrary side effects. Its success value is the process
6465
- * output, its typed error is preserved, and its services are inferred. When
6466
- * invoked, the output is sent to the owning machine as an event unless it is
6467
- * `void`.
6468
- *
6469
- * **Gotchas**
6470
- *
6471
- * This process has no incoming event protocol. Its Effect runs once. Use
6472
- * `transition` for a process that receives events over time and `logic` for
6473
- * direct machine-local communication or intermediate snapshots.
6474
- *
6475
- * **Example** (Recover a child failure as output)
6476
- *
6477
- * ```ts
6478
- * import { Effect, Schema } from "effect"
6479
- * import { Machine } from "@typeonce/effect-machine"
6480
- *
6481
- * class LoadFailed extends Schema.TaggedClass<LoadFailed>("LoadFailed")("LoadFailed", {
6482
- * reason: Schema.String
6483
- * }) {}
6484
- *
6485
- * const load = Machine.effect(
6486
- * Effect.fail("unavailable").pipe(
6487
- * Effect.catch((reason) => Effect.succeed(new LoadFailed({ reason })))
6488
- * )
6489
- * )
6490
- * ```
6491
- *
6492
- * @see {@link transition} for event-driven state.
6493
- * @see {@link logic} for direct control over intermediate snapshots.
6494
- * @category constructors
6495
- * @since 0.4.0
6496
- */
6497
- export const effect: <Output, Error = never, Requirements = never>(
6498
- effect: Effect.Effect<Output, Error, Requirements>
6499
- ) => Logic<void, never, Error, Requirements, Output> = internal.effect
6500
-
6501
6965
  /**
6502
6966
  * Creates advanced stateful process logic from explicit initialization and
6503
6967
  * execution methods.
@@ -6519,9 +6983,9 @@ export const effect: <Output, Error = never, Requirements = never>(
6519
6983
  * This is the low-level process constructor. Parent messages sent directly
6520
6984
  * through its scope are intentionally `unknown` because the logic does not know
6521
6985
  * which machine will eventually own it. Prefer typed output, typed child
6522
- * addresses, or invoke snapshot mapping when possible.
6986
+ * addresses, or invocation lifecycle transitions when possible.
6523
6987
  *
6524
- * @see {@link effect} for one-shot work.
6988
+ * Use an inline `invoke` with an `effect` source for one-shot work.
6525
6989
  * @see {@link transition} for event-driven state.
6526
6990
  * @category constructors
6527
6991
  * @since 0.4.0
@@ -6570,7 +7034,7 @@ export const logic: <
6570
7034
  * )
6571
7035
  * ```
6572
7036
  *
6573
- * @see {@link effect} for one-shot work.
7037
+ * Use an inline `invoke` with an `effect` source for one-shot work.
6574
7038
  * @see {@link logic} for direct process lifecycle control.
6575
7039
  * @category constructors
6576
7040
  * @since 0.4.0
@@ -6783,7 +7247,7 @@ export const start: <
6783
7247
  ) => Effect.Effect<
6784
7248
  MachineRef<
6785
7249
  Machine.Snapshot<States>,
6786
- Machine.EventOf<InputEvents>,
7250
+ Machine.EventInputOf<InputEvents>,
6787
7251
  | E
6788
7252
  | ActionError<R>
6789
7253
  | InfiniteTransitionError
@@ -6815,8 +7279,8 @@ export const start: <
6815
7279
  * entry or transition actions, re-deliver raised or emitted events, or
6816
7280
  * re-evaluate historical completion and eventless transitions. Active-state
6817
7281
  * invokes start once in ancestor and document order with {@link InitialEvent};
6818
- * delayed invokes restart their complete duration and invoked machines start
6819
- * from their own initial state.
7282
+ * timer invocations restart their complete duration and child-machine
7283
+ * invocations start from their own initial state.
6820
7284
  *
6821
7285
  * Only logical state, completion, and history metadata are resumed. Queues,
6822
7286
  * scopes, subscriptions, fibers, spawned children, invoke progress, and prior
@@ -6892,7 +7356,7 @@ export const resume: <
6892
7356
  ) => Effect.Effect<
6893
7357
  MachineRef<
6894
7358
  Machine.Snapshot<States>,
6895
- Machine.EventOf<InputEvents>,
7359
+ Machine.EventInputOf<InputEvents>,
6896
7360
  | E
6897
7361
  | ActionError<R>
6898
7362
  | InfiniteTransitionError