@typeonce/effect-machine 0.34.0 → 0.36.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 (98) hide show
  1. package/README.md +98 -33
  2. package/dist/Machine.d.ts +408 -483
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +126 -87
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/command.d.ts +0 -1
  7. package/dist/internal/machine/command.d.ts.map +1 -1
  8. package/dist/internal/machine/command.js +0 -14
  9. package/dist/internal/machine/command.js.map +1 -1
  10. package/dist/internal/machine/configuration.d.ts +0 -1
  11. package/dist/internal/machine/configuration.d.ts.map +1 -1
  12. package/dist/internal/machine/configuration.js +15 -21
  13. package/dist/internal/machine/configuration.js.map +1 -1
  14. package/dist/internal/machine/construction.d.ts +9 -0
  15. package/dist/internal/machine/construction.d.ts.map +1 -0
  16. package/dist/internal/machine/construction.js +132 -0
  17. package/dist/internal/machine/construction.js.map +1 -0
  18. package/dist/internal/machine/declaration.d.ts +1 -0
  19. package/dist/internal/machine/declaration.d.ts.map +1 -1
  20. package/dist/internal/machine/declaration.js +3 -8
  21. package/dist/internal/machine/declaration.js.map +1 -1
  22. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  23. package/dist/internal/machine/executionPlan.js +21 -27
  24. package/dist/internal/machine/executionPlan.js.map +1 -1
  25. package/dist/internal/machine/implementation.d.ts +2 -3
  26. package/dist/internal/machine/implementation.d.ts.map +1 -1
  27. package/dist/internal/machine/implementation.js.map +1 -1
  28. package/dist/internal/machine/initialDeclaration.d.ts +14 -0
  29. package/dist/internal/machine/initialDeclaration.d.ts.map +1 -0
  30. package/dist/internal/machine/initialDeclaration.js +137 -0
  31. package/dist/internal/machine/initialDeclaration.js.map +1 -0
  32. package/dist/internal/machine/machine.d.ts +0 -2
  33. package/dist/internal/machine/machine.d.ts.map +1 -1
  34. package/dist/internal/machine/machine.js +101 -282
  35. package/dist/internal/machine/machine.js.map +1 -1
  36. package/dist/internal/machine/planner.d.ts +8 -0
  37. package/dist/internal/machine/planner.d.ts.map +1 -1
  38. package/dist/internal/machine/planner.js +86 -82
  39. package/dist/internal/machine/planner.js.map +1 -1
  40. package/dist/internal/machine/protocol.d.ts +1 -1
  41. package/dist/internal/machine/protocol.d.ts.map +1 -1
  42. package/dist/internal/machine/protocol.js.map +1 -1
  43. package/dist/internal/machine/stateDefinition.d.ts +1 -1
  44. package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
  45. package/dist/internal/machine/stateDefinition.js +1 -13
  46. package/dist/internal/machine/stateDefinition.js.map +1 -1
  47. package/dist/internal/machine/targetReference.d.ts.map +1 -1
  48. package/dist/internal/machine/targetReference.js +14 -4
  49. package/dist/internal/machine/targetReference.js.map +1 -1
  50. package/dist/internal/machine/topology.d.ts +6 -0
  51. package/dist/internal/machine/topology.d.ts.map +1 -1
  52. package/dist/internal/machine/topology.js +3 -2
  53. package/dist/internal/machine/topology.js.map +1 -1
  54. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  55. package/dist/internal/testing/machine/finiteModel.js +51 -82
  56. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  57. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  58. package/dist/internal/testing/machine/verification.js +7 -1
  59. package/dist/internal/testing/machine/verification.js.map +1 -1
  60. package/dist/testing/MachineTest.d.ts +105 -73
  61. package/dist/testing/MachineTest.d.ts.map +1 -1
  62. package/dist/testing/MachineTest.js +105 -73
  63. package/dist/testing/MachineTest.js.map +1 -1
  64. package/dist/unstable/cluster/ClusterMachine.d.ts +13 -8
  65. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
  66. package/dist/unstable/cluster/ClusterMachine.js +13 -8
  67. package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
  68. package/dist/unstable/reactivity/AtomMachine.d.ts +41 -24
  69. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  70. package/dist/unstable/reactivity/AtomMachine.js +41 -24
  71. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  72. package/docs/agent-guide.md +37 -34
  73. package/docs/root-api.md +143 -190
  74. package/package.json +1 -1
  75. package/src/Machine.ts +631 -872
  76. package/src/internal/machine/command.ts +0 -16
  77. package/src/internal/machine/configuration.ts +13 -30
  78. package/src/internal/machine/construction.ts +147 -0
  79. package/src/internal/machine/declaration.ts +4 -7
  80. package/src/internal/machine/executionPlan.ts +20 -25
  81. package/src/internal/machine/implementation.ts +2 -3
  82. package/src/internal/machine/initialDeclaration.ts +157 -0
  83. package/src/internal/machine/machine.ts +118 -396
  84. package/src/internal/machine/planner.ts +97 -99
  85. package/src/internal/machine/protocol.ts +3 -3
  86. package/src/internal/machine/stateDefinition.ts +1 -15
  87. package/src/internal/machine/targetReference.ts +19 -4
  88. package/src/internal/machine/topology.ts +7 -2
  89. package/src/internal/testing/machine/finiteModel.ts +60 -132
  90. package/src/internal/testing/machine/verification.ts +7 -1
  91. package/src/testing/MachineTest.ts +105 -73
  92. package/src/unstable/cluster/ClusterMachine.ts +13 -8
  93. package/src/unstable/reactivity/AtomMachine.ts +41 -24
  94. package/dist/internal/machine/targetBuilder.d.ts +0 -16
  95. package/dist/internal/machine/targetBuilder.d.ts.map +0 -1
  96. package/dist/internal/machine/targetBuilder.js +0 -333
  97. package/dist/internal/machine/targetBuilder.js.map +0 -1
  98. package/src/internal/machine/targetBuilder.ts +0 -525
package/dist/Machine.d.ts CHANGED
@@ -100,20 +100,19 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
100
100
  * ```ts
101
101
  * import { Machine } from "@typeonce/effect-machine"
102
102
  * import { Schema } from "effect"
103
- *
104
103
  * const events = Machine.events({ Add: { by: Schema.Number } })
105
104
  * const Root = Machine.state({ fields: { count: Schema.Number } })
106
105
  * const targets = Machine.targets(Root)
107
106
  * export const counter = Machine.make({
108
107
  * root: Root,
109
- * events,
110
- * initial: (root) => root.from(() => ({ count: 0 }))
108
+ * events
111
109
  * }).handle({
110
+ * root: () => ({ count: 0 }),
112
111
  * on: {
113
112
  * Add: {
114
113
  * update: targets.root,
115
114
  * guard: ({ event }) => event.by > 0,
116
- * from: ({ root, event }) => ({ count: root.count + event.by })
115
+ * data: ({ root, event }) => ({ count: root.count + event.by })
117
116
  * }
118
117
  * }
119
118
  * })
@@ -181,8 +180,6 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
181
180
  /** @internal */
182
181
  readonly stateNodes: Machine.StateNodes;
183
182
  /** @internal */
184
- readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
185
- /** @internal */
186
183
  readonly handlers: Readonly<Record<string, unknown>>;
187
184
  /** @internal */
188
185
  readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
@@ -203,7 +200,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
203
200
  * @category models
204
201
  * @since 0.15.0
205
202
  */
206
- export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], Registrations extends Machine.Registrations = {}> extends Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents> {
203
+ export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], Registrations extends Machine.Registrations = {}> extends Omit<Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents>, TypeId | "stateNodes" | "handlers" | "initial" | "initialDefinition"> {
207
204
  /**
208
205
  * Adds typed state handlers and returns an independent machine
209
206
  * implementation. Event dispatch maps and transition descriptors are
@@ -243,7 +240,7 @@ export declare namespace Definition {
243
240
  * @category models
244
241
  * @since 0.15.0
245
242
  */
246
- interface Any extends Machine.Any {
243
+ interface Any extends Omit<Machine.Any, TypeId | "stateNodes" | "handlers" | "initial" | "initialDefinition"> {
247
244
  readonly handle: any;
248
245
  }
249
246
  }
@@ -516,7 +513,6 @@ export declare namespace Runtime {
516
513
  }
517
514
  type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? never : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : never;
518
515
  declare const InvokeTypeId: typeof internal.InvokeTypeId;
519
- declare const InitialBuilderTypeId: unique symbol;
520
516
  type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
521
517
  readonly "~effect/Machine/DefinitionError": Message;
522
518
  readonly path: Path;
@@ -569,11 +565,9 @@ type ValidateStateNodeWithChildren<Node extends Machine.StateNodeConfig, Childre
569
565
  } ? ValidateInitialSelectorChild<Children, Path> & ("initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
570
566
  readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
571
567
  } & ValidateOutputSchema<Node>) : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : ValidateCompoundStateNode<Node, Children, Path> : StateDefinitionError<"Child states must be a state tree">;
572
- type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
573
- readonly initial: infer Initial;
574
- } ? Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? ValidateInitialSelectorChild<Children, Path> & ValidateWithSelectorChild<Node, Children, Path> & {
568
+ type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> = "initial" extends keyof Node ? StateDefinitionError<"Declare initial edges in handle", Path> : ValidateInitialSelectorChild<Children, Path> & ValidateWithSelectorChild<Node, Children, Path> & {
575
569
  readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
576
- } : StateDefinitionError<"Compound initial must be one of its direct child keys", Path, Extract<Initial, PropertyKey>> : StateDefinitionError<"Compound states must declare an initial child", Path>;
570
+ };
577
571
  type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
578
572
  readonly type: infer Type;
579
573
  } ? Type extends "final" ? ValidateOutputSchema<Node> : Type extends "active" | undefined ? "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown : StateDefinitionError<"State node type must be active, final, or parallel"> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown;
@@ -712,55 +706,6 @@ type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input
712
706
  <Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
713
707
  <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
714
708
  } : <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected) => Machine.StateConstruction<UnwrapConstruction<Selected>>;
715
- type InitialSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
716
- readonly [Key in ActiveStateKey<States>]: InitialSnapshotMethod<States, Key, Prefix>;
717
- } & {
718
- readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
719
- };
720
- type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>> : DecodedMethod<InitialSnapshotArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>> & FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>>;
721
- type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
722
- readonly type: "parallel";
723
- readonly states: infer Children extends Machine.StateSchemas;
724
- } ? WithNodeValue<Node, [
725
- states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>>
726
- ]> : Node extends {
727
- readonly states: infer Children extends Machine.StateSchemas;
728
- } ? Node extends {
729
- readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
730
- } ? WithNodeValue<Node, [
731
- state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSelectableResult<Children, Initial, Path>
732
- ]> : never : WithNodeValue<Node, []> : never;
733
- type InitialSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
734
- readonly type: "parallel";
735
- readonly states: infer Children extends Machine.StateSchemas;
736
- } ? WithNodeInput<Node, [
737
- states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
738
- ]> : Node extends {
739
- readonly states: infer Children extends Machine.StateSchemas;
740
- } ? Node extends {
741
- readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
742
- } ? WithNodeInput<Node, [
743
- state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
744
- ]> : never : WithNodeInput<Node, []> : never;
745
- type InitialSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
746
- readonly type: "parallel";
747
- readonly states: infer Children extends Machine.StateSchemas;
748
- } ? Machine.ParallelSnapshot<Path, NodeValue<Node>, InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
749
- readonly states: infer Children extends Machine.StateSchemas;
750
- } ? Node extends {
751
- readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
752
- } ? Machine.CompoundSnapshot<Path, NodeValue<Node>, InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, NodeValue<Node>> : never;
753
- type InitialSelectableResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States> | ChoiceStateKey<States>, Prefix extends string> = StateId extends ChoiceStateKey<States> ? Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, StateId>> : StateId extends ActiveStateKey<States> ? InitialSnapshotResult<States, StateId, Prefix> : never;
754
- type InitialSnapshotRegionsWithPrefix<States extends Machine.StateSchemas, Prefix extends string> = {
755
- readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>;
756
- };
757
- type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
758
- readonly [Key in Remaining]: NodeBuilderMethod<States[Key], InitialSnapshotArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
759
- readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
760
- }, Constructed>, InitialSnapshotFromArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
761
- readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
762
- }, true>>;
763
- };
764
709
  type FullSnapshotBuilderWithPrefix<in out States extends Machine.StateSchemas, in out Prefix extends string = ""> = {
765
710
  readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]: Key extends ActiveStateKey<States> ? FullSnapshotMethod<States, Key, Prefix> : () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
766
711
  };
@@ -805,55 +750,18 @@ type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends str
805
750
  readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
806
751
  }, true>>;
807
752
  };
808
- type HistorySnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
809
- readonly type: "parallel";
810
- readonly states: infer Children extends Machine.StateSchemas;
811
- } ? WithNodeValue<Node, [
812
- states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
813
- ]> : Node extends {
814
- readonly states: infer Children extends Machine.StateSchemas;
815
- } ? WithNodeValue<Node, [
816
- state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
817
- ]> : never : never;
818
- type HistorySnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotFromArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
819
- readonly type: "parallel";
820
- readonly states: infer Children extends Machine.StateSchemas;
821
- } ? WithNodeInput<Node, [
822
- states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
823
- ]> : Node extends {
824
- readonly states: infer Children extends Machine.StateSchemas;
825
- } ? WithNodeInput<Node, [
826
- state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
827
- ]> : never : never;
828
753
  type HistorySnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotResult<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
829
754
  readonly type: "parallel";
830
755
  readonly states: infer Children extends Machine.StateSchemas;
831
756
  } ? Machine.ParallelSnapshot<Path, NodeValue<Node>, HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
832
757
  readonly states: infer Children extends Machine.StateSchemas;
833
758
  } ? Machine.CompoundSnapshot<Path, NodeValue<Node>, HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
834
- type HistorySnapshotMethod<in out States extends Machine.StateSchemas, in out StateId extends ActiveStateKey<States>, in out Prefix extends string, in out Owner extends string> = {
835
- readonly [Key in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"]: Key extends "from" ? FromCallable<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, Machine.StateConstruction<HistorySnapshotResult<States, StateId, Prefix, Owner>>> : (...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>;
836
- };
837
759
  type HistorySnapshotWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string> = {
838
760
  readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
839
761
  }[ActiveStateKey<States>];
840
- type HistorySnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string = ""> = {
841
- readonly [Key in ActiveStateKey<States> as Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? Key : never]: HistorySnapshotMethod<States, Key, Prefix, Owner>;
842
- };
843
762
  type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends string, Owner extends string> = {
844
763
  readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
845
764
  };
846
- type HistoryParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Owner extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
847
- readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? NodeBuilderMethod<States[Key], HistorySnapshotArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
848
- readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
849
- }, Constructed>, HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
850
- readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
851
- }, true>> : NodeBuilderMethod<States[Key], FullSnapshotArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
852
- readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
853
- }, Constructed>, FullSnapshotFromArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
854
- readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
855
- }, true>>;
856
- };
857
765
  type ParentPath<Path extends string> = Machine.ImmediateParentStateIdentifier<Path>;
858
766
  type IsCompoundNode<Node> = Node extends {
859
767
  readonly type: "parallel";
@@ -954,8 +862,7 @@ type InitializerClosureForNode<AllStates extends Machine.StateSchemas, Node, Pat
954
862
  readonly states: infer Children extends Machine.StateSchemas;
955
863
  } ? (HasRequiredActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never) | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
956
864
  readonly states: infer Children extends Machine.StateSchemas;
957
- readonly initial: infer Initial;
958
- } ? (Initial extends ActiveStateKey<Children> ? RequiresInitialValue<Children[Initial]> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never : never) | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<AllStates, Children[Initial], Machine.JoinPath<Path, Initial>> : never) : never : never;
865
+ } ? Extract<Path, Machine.StateIdentifier<AllStates>> | InitializerClosuresForChildren<AllStates, Children, Path> : never : never;
959
866
  type InitializerClosuresForChildren<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
960
867
  readonly [Key in ActiveStateKey<States>]: InitializerClosureForNode<AllStates, States[Key], Machine.JoinPath<Prefix, Key>>;
961
868
  }[ActiveStateKey<States>];
@@ -1644,7 +1551,6 @@ export declare namespace Machine {
1644
1551
  /** @internal */
1645
1552
  readonly stateNodes: StateNodes;
1646
1553
  /** @internal */
1647
- readonly makeTargetBuilder: any;
1648
1554
  /** @internal */
1649
1555
  readonly handlers: any;
1650
1556
  /** @internal */
@@ -1953,7 +1859,6 @@ export declare namespace Machine {
1953
1859
  /** Compound states are ordinary active states. */
1954
1860
  readonly type?: "active";
1955
1861
  /** Direct child selected when the compound state is entered initially. */
1956
- readonly initial: string;
1957
1862
  /** Nested state nodes owned by this compound state. */
1958
1863
  readonly states: StateTree;
1959
1864
  /** Schema-backed states take their annotations from the schema. */
@@ -1961,7 +1866,6 @@ export declare namespace Machine {
1961
1866
  } | {
1962
1867
  readonly schema?: never;
1963
1868
  readonly type?: "active";
1964
- readonly initial: string;
1965
1869
  readonly states: StateTree;
1966
1870
  /** Descriptive metadata for a schema-less state. */
1967
1871
  readonly annotations?: SchemaLessStateAnnotations;
@@ -2073,7 +1977,6 @@ export declare namespace Machine {
2073
1977
  * @category utility types
2074
1978
  * @since 0.4.0
2075
1979
  */
2076
- type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>;
2077
1980
  /**
2078
1981
  * Typed snapshot access shared by state descriptors.
2079
1982
  *
@@ -2458,12 +2361,10 @@ export declare namespace Machine {
2458
2361
  type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = IsAny<States> extends true ? unknown : ([HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
2459
2362
  readonly "~effect/Machine/MissingHistoryImplementation": MissingHistoryImplementations<States, UnhandledStates>;
2460
2363
  }) & EnsureChoiceImplementations<States, UnhandledStates>;
2461
- /** Owners whose declared default descendants require supplied values. */
2462
- type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never : "" extends keyof States ? States[""] extends {
2463
- readonly "~effect/Machine/ExplicitInitial": true;
2464
- } ? never : InitializerClosureForNode<States, States[""], ""> : never;
2364
+ /** Owners that require a handler-owned initial edge or region data. */
2365
+ type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never : "" extends keyof States ? InitializerClosureForNode<States, States[""], ""> : never;
2465
2366
  /** Proof that initialization can construct every required default value. */
2466
- type EnsureInitialImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown : {
2367
+ type EnsureInitialImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [UnhandledStates] extends [never] ? unknown : [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown : {
2467
2368
  readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>;
2468
2369
  };
2469
2370
  /**
@@ -3033,11 +2934,7 @@ export declare namespace Machine {
3033
2934
  * @category utility types
3034
2935
  * @since 0.4.0
3035
2936
  */
3036
- type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotMethod<{
3037
- readonly "": Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig>;
3038
- }, "" & ActiveStateKey<{
3039
- readonly "": Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig>;
3040
- }>, "", Owner>;
2937
+ type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = (construction: HistoryConstruction<States[""], Owner>) => StateConstruction<CompleteSnapshotContaining<States, Owner>>;
3041
2938
  /**
3042
2939
  * Builder for source-local transition targets.
3043
2940
  *
@@ -3143,14 +3040,6 @@ export declare namespace Machine {
3143
3040
  type RootBuilder<Builder> = Builder extends {
3144
3041
  readonly "": infer Root;
3145
3042
  } ? Root : never;
3146
- /** Definition-time selector that can choose only a valid top-level initial entry. */
3147
- type InitialTargetSelector<States extends StateSchemas> = {
3148
- readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends {
3149
- readonly states: StateSchemas;
3150
- } ? {
3151
- readonly initial: SelectionValue<InitialBuilder<States>[Key], Key, "initial", "initial">;
3152
- } : SelectionMethod<InitialBuilder<States>[Key], Key, "state", "initial">;
3153
- };
3154
3043
  /**
3155
3044
  * Context passed to a state/event handler.
3156
3045
  *
@@ -3399,11 +3288,7 @@ export declare namespace Machine {
3399
3288
  * @category utility types
3400
3289
  * @since 0.4.0
3401
3290
  */
3402
- type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> | InitialSnapshot<States> | InitialTarget<StateIdentifier<States>> | StateConstruction<Snapshot<States> | InitialSnapshot<States> | InitialTarget<StateIdentifier<States>>>;
3403
- /** Initial snapshots may transiently terminate in a declared choice node. */
3404
- type InitialSnapshot<States extends StateSchemas> = {
3405
- readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">;
3406
- }[ActiveStateKey<States>];
3291
+ type InitialResult<States extends StateSchemas, E, R> = InitialTarget<StateIdentifier<States>>;
3407
3292
  /**
3408
3293
  * Return value accepted from transition handlers.
3409
3294
  *
@@ -3456,10 +3341,6 @@ export declare namespace Machine {
3456
3341
  * @since 0.4.0
3457
3342
  */
3458
3343
  type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never : never;
3459
- /** Extracts the return value from an implicit initial child implementation. */
3460
- type StateInitializeReturn<Config> = Config extends {
3461
- readonly initialize?: infer Initialize;
3462
- } ? NonNullable<Initialize> extends (...args: any) => infer Ret ? Ret : never : never;
3463
3344
  /** Extracts the return values from a state's history defaults. */
3464
3345
  type HistoryDefaultReturn<Config> = Config extends {
3465
3346
  readonly history?: infer History;
@@ -3651,7 +3532,7 @@ export declare namespace Machine {
3651
3532
  * @category utility types
3652
3533
  * @since 0.4.0
3653
3534
  */
3654
- type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config>;
3535
+ type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config> : never;
3655
3536
  /** The only transition value accepted by machine handler APIs. */
3656
3537
  type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = Transition<States, StateId, Context, Events, Emits, {}, Reenter, Acceptance>;
3657
3538
  type SelectionBuilder<Selection> = Selection extends TargetSelection<infer Builder, any, any, any> ? Builder : never;
@@ -3740,56 +3621,6 @@ export declare namespace Machine {
3740
3621
  type TransitionBranchesResolveContext<Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = Omit<Context, "target"> & {
3741
3622
  readonly select: BranchSelectors<Branches>;
3742
3623
  };
3743
- type ConstructionCallbacks<Context, Builder, Result> = {
3744
- readonly [Method in Extract<keyof Builder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown ? Args extends readonly [unknown?] ? Method : never : never]: Builder[Method] extends (...args: infer Args) => unknown ? (value: (context: Context) => Args[0]) => Result : never;
3745
- };
3746
- /** @internal Type evidence retained by a machine initial-entry declaration. */
3747
- interface InitialBuilderEvidence<out Selection> {
3748
- readonly [InitialBuilderTypeId]: Types.Covariant<Selection>;
3749
- }
3750
- /** Decoded input shared by initial construction callbacks. */
3751
- interface InitialContext<Input> {
3752
- /** Decoded value supplied when the machine is started. */
3753
- readonly input: Input;
3754
- }
3755
- /** A selected machine initial entry with its exact resolver target. */
3756
- type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> = Selection & ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<Selection>, InitialBuilderEvidence<Selection>> & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {}) & {
3757
- /** Lazily constructs the selected initial state from decoded machine input. */
3758
- readonly resolve: (resolve: (context: {
3759
- /** Decoded value supplied when the machine is started. */
3760
- readonly input: Input;
3761
- /** Builder specialized to the selected initial destination. */
3762
- readonly target: SelectionBuilder<Selection>;
3763
- }) => SelectedTargetResult<Selection>) => InitialBuilderEvidence<Selection>;
3764
- };
3765
- type InitialSelectorNode<Input, Node> = Node extends (...args: infer Args) => infer Selection ? Selection extends TargetSelection<any, any, any> ? ((...args: Args) => InitialTransitionTarget<Input, Selection>) & {
3766
- readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>;
3767
- } : never : Node extends TargetSelection<any, any, any> ? InitialTransitionTarget<Input, Node> : {
3768
- readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>;
3769
- };
3770
- /** Definition-time selector for a machine's top-level initial entry. */
3771
- type InitialSelector<States extends StateSchemas, Input = void> = InitialSelectorNode<Input, InitialTargetSelector<States>>;
3772
- /** Target-first initial-entry declaration accepted by {@link make}. */
3773
- type InitialBuilderInput<States extends StateSchemas, Input> = (to: InitialSelector<States, Input>) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
3774
- /** Initializes the root and its declared default descendants. */
3775
- type RootInitialBuilderInput<Root extends StateNodeConfig, Input> = (root: InitialTransitionTarget<Input, SelectionValue<InitialTargetFactory<Root, "">, "", "initial", "initial">>) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
3776
- interface RootConfigurationSelection<in out Root extends StateNodeConfig> extends TargetSelection<FullSnapshotMethod<{
3777
- readonly "": Root;
3778
- }, "" & ActiveStateKey<{
3779
- readonly "": Root;
3780
- }>, "">, "", "state", "initial"> {
3781
- }
3782
- /** Explicitly constructs a complete starting configuration. */
3783
- type RootConfigurationBuilderInput<Root extends StateNodeConfig, Input> = (root: ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<RootConfigurationSelection<Root>>, InitialBuilderEvidence<RootConfigurationSelection<Root>>> & {
3784
- readonly resolve: (resolve: (context: {
3785
- /** Decoded startup input. */
3786
- readonly input: Input;
3787
- /** Builder for the complete root configuration. */
3788
- readonly target: SelectionBuilder<RootConfigurationSelection<Root>>;
3789
- }) => ConstructionResult<Snapshot<{
3790
- readonly "": Root;
3791
- }>>) => InitialBuilderEvidence<RootConfigurationSelection<Root>>;
3792
- }) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
3793
3624
  type InvokeTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context> = TransitionConfig<States, Events, Emits, StateId, Context, true, TransitionAcceptance>;
3794
3625
  type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
3795
3626
  /** Inline state-owned work that runs for the lifetime of its active state. */
@@ -3887,67 +3718,23 @@ export declare namespace Machine {
3887
3718
  } ? OutputHandlerConfig<States, Events, StateId, ParallelOutputContext<States, Events, StateId>> : {
3888
3719
  readonly output?: never;
3889
3720
  };
3890
- /**
3891
- * Values constructed for a state's schema-valued direct initial children.
3892
- *
3893
- * @category utility types
3894
- * @since 0.13.0
3895
- */
3896
- type StateInitializeValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
3897
- readonly type: "parallel";
3721
+ type HistoryConstruction<Node, Owner extends string> = ConstructionData<Node> & (Node extends {
3898
3722
  readonly states: infer Children extends StateSchemas;
3899
3723
  } ? {
3900
- readonly [Key in ActiveStateKey<Children> as NodeSchema<Children[Key]> extends never ? never : Key]: NodeValue<Children[Key]>;
3901
- } : Node extends {
3902
- readonly states: infer Children extends StateSchemas;
3903
- readonly initial: infer Initial;
3904
- } ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : {
3905
- readonly [Key in Initial]: NodeValue<Children[Initial]>;
3906
- } : never : never : never;
3907
- type StateInitializeCompoundBuilder<Node, Initial extends PropertyKey> = Node extends {
3908
- readonly states: infer Children extends StateSchemas;
3909
- } ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : NodeBuilderMethod<Children[Initial], readonly [value: NodeValue<Children[Initial]>], SnapshotBuilderComplete<{
3910
- readonly [Key in Initial]: NodeValue<Children[Initial]>;
3911
- }>, readonly [input: NodeMakeInput<Children[Initial]>], SnapshotBuilderComplete<{
3912
- readonly [Key in Initial]: NodeValue<Children[Initial]>;
3913
- }, true>> : never : never;
3914
- type StateInitializeParallelBuilder<Children extends StateSchemas, Remaining extends ActiveStateKey<Children> = {
3915
- readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]> extends never ? never : Key;
3916
- }[ActiveStateKey<Children>], Values = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Values, Constructed> & {
3917
- readonly [Key in Remaining]: NodeBuilderMethod<Children[Key], readonly [value: NodeValue<Children[Key]>], StateInitializeParallelBuilder<Children, Exclude<Remaining, Key>, Values & {
3918
- readonly [Region in Key]: NodeValue<Children[Key]>;
3919
- }, Constructed>, readonly [input: NodeMakeInput<Children[Key]>], StateInitializeParallelBuilder<Children, Exclude<Remaining, Key>, Values & {
3920
- readonly [Region in Key]: NodeValue<Children[Key]>;
3921
- }, true>>;
3922
- };
3923
- /**
3924
- * Builder bound to the direct initial child or regions owned by a state.
3925
- *
3926
- * @category utility types
3927
- * @since 0.13.0
3928
- */
3929
- type StateInitializeBuilder<States extends StateSchemas, StateId extends StateIdentifier<States>, Node = NodeByIdentifier<States, StateId>> = Node extends {
3930
- readonly type: "parallel";
3931
- readonly states: infer Children extends StateSchemas;
3932
- } ? StateInitializeParallelBuilder<Children> : Node extends {
3933
- readonly initial: infer Initial;
3934
- } ? StateInitializeCompoundBuilder<Node, Initial & PropertyKey> : never;
3935
- /**
3936
- * Context passed to an implicit child-state initializer.
3937
- *
3938
- * @category models
3939
- * @since 0.13.0
3940
- */
3941
- type StateInitializeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
3942
- readonly builder: StateInitializeBuilder<States, StateId>;
3943
- };
3944
- /**
3945
- * Initial child value implementation for a compound or parallel state.
3946
- *
3947
- * @category models
3948
- * @since 0.13.0
3949
- */
3950
- type StateInitializeHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = (context: StateInitializeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>;
3724
+ readonly states: Node extends {
3725
+ readonly type: "parallel";
3726
+ } ? {
3727
+ readonly [K in (ActiveStateKey<Children> | ChoiceStateKey<Children>)]: HistoryConstruction<Children[K], Owner extends `${K}.${infer Rest}` ? Rest : "">;
3728
+ } : {
3729
+ readonly [K in (ActiveStateKey<Children> | ChoiceStateKey<Children>)]: Owner extends "" | K | `${K}.${string}` ? {
3730
+ readonly [P in K]: HistoryConstruction<Children[P], Owner extends `${K}.${infer Rest}` ? Rest : "">;
3731
+ } & {
3732
+ readonly [P in Exclude<(ActiveStateKey<Children> | ChoiceStateKey<Children>), K>]?: never;
3733
+ } : never;
3734
+ }[(ActiveStateKey<Children> | ChoiceStateKey<Children>)];
3735
+ } : {
3736
+ readonly states?: never;
3737
+ });
3951
3738
  /** Context used only when a history node has no previously captured record. */
3952
3739
  interface HistoryDefaultContext<in out States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, in out ParentId extends StateIdentifier<States>> {
3953
3740
  /** Lifecycle event that attempted to restore this history node. */
@@ -3993,13 +3780,12 @@ export declare namespace Machine {
3993
3780
  readonly on?: never;
3994
3781
  readonly onDone?: never;
3995
3782
  readonly output?: never;
3996
- readonly initialize?: never;
3997
3783
  }
3998
3784
  type HandlerChildren<Node> = Node extends {
3999
3785
  readonly states: infer Children extends StateSchemas;
4000
3786
  } ? Children : never;
4001
3787
  type HandlerConfigPart<Config> = {
4002
- readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key];
3788
+ readonly [Key in keyof Config as Key extends "states" | "initial" | "root" ? never : Key]: Config[Key];
4003
3789
  };
4004
3790
  type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
4005
3791
  readonly states?: infer Children;
@@ -4017,7 +3803,7 @@ export declare namespace Machine {
4017
3803
  } : {
4018
3804
  readonly [Key in Path]?: Validation;
4019
3805
  };
4020
- type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initialize" | "invoke" | "on" | "onDone" | "output" | "states";
3806
+ type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initial" | "root" | "invoke" | "on" | "onDone" | "output" | "states";
4021
3807
  type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
4022
3808
  readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
4023
3809
  };
@@ -4088,10 +3874,10 @@ export declare namespace Machine {
4088
3874
  ] extends [never] ? unknown : {
4089
3875
  readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
4090
3876
  } : unknown : unknown);
4091
- type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "initialize" extends keyof Config ? unknown : {
4092
- readonly initialize: HandlerValidationError<"State requires initialize for shallow history restoration", StateId>;
3877
+ type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "initial" extends keyof Config ? unknown : {
3878
+ readonly initial: HandlerValidationError<"State requires an initial declaration for shallow history restoration", StateId>;
4093
3879
  } : unknown;
4094
- type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerInvokeParentEventsValidation<InputEvents, StateId, Config> & HandlerChildrenValidation<Node, StateId, Config> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRequiredHistoryInitializeValidation<AllStates, StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : unknown;
3880
+ type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerInvokeParentEventsValidation<InputEvents, StateId, Config> & HandlerChildrenValidation<Node, StateId, Config> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRequiredHistoryInitializeValidation<AllStates, StateId, Config> & ValidateConstructionDeclarations<Node, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : unknown;
4095
3881
  type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
4096
3882
  readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
4097
3883
  };
@@ -4105,7 +3891,7 @@ export declare namespace Machine {
4105
3891
  readonly "": Config;
4106
3892
  }, Required> extends infer NodeConfig ? [
4107
3893
  NodeConfig
4108
- ] extends [never] ? RootInitializeError<Required> : "initialize" extends keyof NodeConfig ? never : RootInitializeError<Required> : never : unknown> : unknown;
3894
+ ] extends [never] ? RootInitializeError<Required> : "initial" extends keyof NodeConfig ? never : RootInitializeError<Required> : never : unknown> : unknown;
4109
3895
  type RootInitializeError<Path extends string> = Path extends "" ? {
4110
3896
  readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
4111
3897
  } : {
@@ -4113,14 +3899,21 @@ export declare namespace Machine {
4113
3899
  readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
4114
3900
  }>;
4115
3901
  };
4116
- type RootHandlerValidation<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, OutputStates extends StateIdentifier<States>> = HandlerNodeValidation<States, States[""], Events, InputEvents, Emits, Extract<"", StateNodeIdentifier<States>>, Config, OutputStates> & RootInitialTargetValidation<States, Config> & Types.UnionToIntersection<Exclude<StateNodeIdentifier<States>, ""> extends infer Path ? Path extends StateNodeIdentifier<States> ? HandlerConfigAtPath<{
4117
- readonly "": Config;
4118
- }, Path> extends infer NodeConfig ? [
4119
- NodeConfig
4120
- ] extends [never] ? never : HandlerNodeValidation<States, HandlerNodeByPath<States, Path>, Events, InputEvents, Emits, Path, NodeConfig, OutputStates> extends infer Validation ? unknown extends Validation ? never : {
4121
- readonly states: HandlerValidationAtPath<Path, Validation>;
4122
- } : never : never : never : never>;
4123
- type HandlerHasRequiredInitial<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "initialize" extends keyof Config ? true : false : true;
3902
+ type HandlerTreeValidation<States extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, Config, OutputStates extends StateIdentifier<States>> = HandlerNodeValidation<States, Node, Events, InputEvents, Emits, Path, Config, OutputStates> & (Config extends {
3903
+ readonly states: infer Handlers;
3904
+ } ? Node extends {
3905
+ readonly states: infer Children extends StateSchemas;
3906
+ } ? {
3907
+ readonly states: {
3908
+ readonly [K in keyof Handlers]: K extends keyof Children ? HandlerTreeValidation<States, Children[K], Events, InputEvents, Emits, Extract<JoinPath<Path, Extract<K, string>>, StateNodeIdentifier<States>>, Handlers[K], OutputStates> : unknown;
3909
+ };
3910
+ } : unknown : unknown);
3911
+ type RootHandlerValidation<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, OutputStates extends StateIdentifier<States>> = HandlerTreeValidation<States, States[""], Events, InputEvents, Emits, Extract<"", StateNodeIdentifier<States>>, Config, OutputStates>;
3912
+ type HandlerHasRequiredInitial<Node, Config> = Node extends {
3913
+ readonly states: infer Children extends StateSchemas;
3914
+ } ? Node extends {
3915
+ readonly type: "parallel";
3916
+ } ? HasRequiredActiveChild<Children> extends true ? "initial" extends keyof Config ? true : false : true : "initial" extends keyof Config ? true : false : true;
4124
3917
  type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
4125
3918
  readonly states: infer Children extends StateSchemas;
4126
3919
  } ? [HistoryStateKey<Children>] extends [never] ? true : Config extends {
@@ -4135,15 +3928,21 @@ export declare namespace Machine {
4135
3928
  } ? [
4136
3929
  Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
4137
3930
  ] extends [never] ? true : false : false : true;
4138
- type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates> | RequiredInitializers<AllStates>] extends [never] ? StateId : HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
4139
- type HandlerConfigError<Config> = Effect.Error<EventHandlerReturn<Config>> | Effect.Error<AlwaysReturn<Config>> | Effect.Error<DoneReturn<Config>> | Effect.Error<StateActionReturn<Config, "entry">> | Effect.Error<StateActionReturn<Config, "exit">> | Effect.Error<HistoryDefaultReturn<Config>> | Effect.Error<ChoiceReturn<Config>> | InvokeError<Config>;
4140
- type HandlerNodeEvidence<AllStates extends StateSchemas, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : {
4141
- readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, HandlerNodeByPath<AllStates, StateId>, StateId, NodeConfig> : never;
3931
+ type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = HandlerHasRequiredInitial<Node, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
3932
+ type HandlerConfigError<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : Effect.Error<EventHandlerReturn<Config>> | Effect.Error<AlwaysReturn<Config>> | Effect.Error<DoneReturn<Config>> | Effect.Error<StateActionReturn<Config, "entry">> | Effect.Error<StateActionReturn<Config, "exit">> | Effect.Error<HistoryDefaultReturn<Config>> | Effect.Error<ChoiceReturn<Config>> | InvokeError<Config> : never;
3933
+ type HandlerNodeEvidence<AllStates extends StateSchemas, Node, StateId extends StateNodeIdentifier<AllStates>, NodeConfig> = [NodeConfig] extends [never] ? never : {
3934
+ readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, Node, StateId, NodeConfig> : never;
4142
3935
  readonly error: HandlerConfigError<HandlerConfigPart<NodeConfig>>;
4143
3936
  readonly services: ConfigServices<HandlerConfigPart<NodeConfig>>;
4144
3937
  readonly outputState: StateId extends StateIdentifier<AllStates> ? HandlerOutputStates<AllStates, StateId, HandlerConfigPart<NodeConfig>> : never;
4145
3938
  };
4146
- type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId> : never : never;
3939
+ type HandlerTreeEvidence<AllStates extends StateSchemas, Config, Nodes extends StateSchemas = AllStates, Prefix extends string = ""> = {
3940
+ readonly [K in Extract<keyof Config & keyof Nodes, string>]: HandlerNodeEvidence<AllStates, Nodes[K], Extract<JoinPath<Prefix, K>, StateNodeIdentifier<AllStates>>, Config[K]> | (Nodes[K] extends {
3941
+ readonly states: infer Children extends StateSchemas;
3942
+ } ? Config[K] extends {
3943
+ readonly states: infer Handlers;
3944
+ } ? HandlerTreeEvidence<AllStates, Handlers, Children, JoinPath<Prefix, K>> : never : never);
3945
+ }[Extract<keyof Config & keyof Nodes, string>];
4147
3946
  type HandleTreeResult<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<AllStates>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<AllStates>, Output, OutputStates extends StateIdentifier<AllStates>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Config> = Machine<AllStates, Events, Input, Exclude<UnhandledStates, HandlerTreeEvidence<AllStates, Config>["stateId"]>, E | HandlerTreeEvidence<AllStates, Config>["error"], ExcludeCompatibleRuntime<R | HandlerTreeEvidence<AllStates, Config>["services"], EventOf<Events>, EmittedEventOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>, InputEvents, ParentEvents>;
4148
3947
  type ObjectCompoundPath<S extends StateSchemas> = {
4149
3948
  readonly [P in StateIdentifier<S>]: NodeByIdentifier<S, P> extends {
@@ -4169,7 +3968,7 @@ export declare namespace Machine {
4169
3968
  type ValidatePrograms<Sources> = {
4170
3969
  readonly [K in keyof Sources]: Sources[K] extends LazyProgramValue ? unknown : Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never : unknown;
4171
3970
  };
4172
- type ReferenceRoot<S extends StateSchemas> = "~effect/Machine/ExplicitInitial" extends keyof S[""] ? Extract<Omit<S[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig> : Extract<S[""], StateNodeConfig>;
3971
+ type ReferenceRoot<S extends StateSchemas> = Extract<S[""], StateNodeConfig>;
4173
3972
  type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = TargetReference<ReferenceRoot<S>, P, P extends HistoryIdentifier<S> ? "history" : P extends ChoiceIdentifier<S> ? "choice" : "state">;
4174
3973
  type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = {
4175
3974
  readonly [P in Paths]: ReferenceAt<S, P>;
@@ -4183,8 +3982,8 @@ export declare namespace Machine {
4183
3982
  /** Optional presentation label for this named branch. */
4184
3983
  readonly title?: string;
4185
3984
  } & ({
4186
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4187
- readonly target: ReferenceUnion<S, DestinationPath<S>>;
3985
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
3986
+ readonly target: ReferenceUnion<S, DestinationPath<S>> | TargetReference<Root, "", "state">;
4188
3987
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4189
3988
  readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>;
4190
3989
  /** Enters a compound or parallel subtree through its declared initialization. */
@@ -4196,7 +3995,7 @@ export declare namespace Machine {
4196
3995
  } | {
4197
3996
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4198
3997
  readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>;
4199
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
3998
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4200
3999
  readonly target?: never;
4201
4000
  /** Enters a compound or parallel subtree through its declared initialization. */
4202
4001
  readonly initial?: never;
@@ -4204,21 +4003,10 @@ export declare namespace Machine {
4204
4003
  readonly history?: never;
4205
4004
  /** Accepts the event without selecting a new destination. */
4206
4005
  readonly none?: never;
4207
- } | {
4208
- /** Enters a compound or parallel subtree through its declared initialization. */
4209
- readonly initial: ReferenceUnion<S, Exclude<ObjectCompoundPath<S>, "">>;
4210
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4211
- readonly target?: never;
4212
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4213
- readonly update?: never;
4214
- /** Restores the declared history reference, using its fallback on first entry. */
4215
- readonly history?: never;
4216
- /** Accepts the event without selecting a new destination. */
4217
- readonly none?: never;
4218
4006
  } | {
4219
4007
  /** Restores the declared history reference, using its fallback on first entry. */
4220
4008
  readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
4221
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4009
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4222
4010
  readonly target?: never;
4223
4011
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4224
4012
  readonly update?: never;
@@ -4229,7 +4017,7 @@ export declare namespace Machine {
4229
4017
  } | {
4230
4018
  /** Accepts the event without selecting a new destination. */
4231
4019
  readonly none: true;
4232
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4020
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4233
4021
  readonly target?: never;
4234
4022
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4235
4023
  readonly update?: never;
@@ -4254,30 +4042,70 @@ export declare namespace Machine {
4254
4042
  /** Named groups of inspectable destinations used by transition resolvers. */
4255
4043
  readonly branches?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
4256
4044
  }
4045
+ type RegisteredInput<R> = R extends {
4046
+ readonly "~input": infer I extends Schema.Top;
4047
+ } ? I : typeof Schema.Void;
4257
4048
  type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {};
4258
- type AtBuilder<T, P extends string> = P extends "" ? T : P extends `${infer H}.${infer Rest}` ? H extends keyof T ? AtBuilder<T[H], Rest> : never : P extends keyof T ? T[P] : never;
4259
- type BranchBuilderAt<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = AtBuilder<RootBuilder<BranchTargetBuilder<S, Src>>, P>;
4260
4049
  type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never;
4261
- type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D> = D extends {
4262
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4050
+ type ConstructionData<Node> = [NodeSchema<Node>] extends [never] ? {
4051
+ readonly data?: never;
4052
+ readonly decoded?: never;
4053
+ } : ({
4054
+ readonly decoded?: false;
4055
+ } & ({} extends NodeMakeInput<Node> ? {
4056
+ readonly data?: NodeMakeInput<Node>;
4057
+ } : {
4058
+ readonly data: NodeMakeInput<Node>;
4059
+ })) | {
4060
+ readonly decoded: true;
4061
+ readonly data: NodeValue<Node>;
4062
+ };
4063
+ type ConstructionChildren<Children extends StateSchemas, Parallel extends boolean, Source extends string = never> = Parallel extends true ? {
4064
+ readonly [K in ActiveStateKey<Children>]: ConstructionObject<Children[K], Source extends `${K}.${infer Rest}` ? Rest : Source extends K ? "" : never>;
4065
+ } : {
4066
+ readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: {
4067
+ readonly [P in K]: ConstructionObject<Children[P], Source extends `${P}.${infer Rest}` ? Rest : Source extends P ? "" : never>;
4068
+ } & {
4069
+ readonly [P in Exclude<ActiveStateKey<Children> | ChoiceStateKey<Children>, K>]?: never;
4070
+ };
4071
+ }[ActiveStateKey<Children> | ChoiceStateKey<Children>];
4072
+ /** Values for one state and, optionally, its explicitly selected descendants. */
4073
+ type ConstructionObject<Node, Source extends string = never> = {
4074
+ readonly input?: never;
4075
+ } & ConstructionData<Node> & (Node extends {
4076
+ readonly states: infer Children extends StateSchemas;
4077
+ } ? {
4078
+ readonly states?: ConstructionChildren<Children, Node extends {
4079
+ readonly type: "parallel";
4080
+ } ? [Source] extends [never] ? true : false : false, Source>;
4081
+ } : {
4082
+ readonly states?: never;
4083
+ });
4084
+ type ConstructionCall<A, Result> = {} extends A ? (construction?: A) => Result : (construction: A) => Result;
4085
+ type RootInput<R> = {
4086
+ readonly data?: never;
4087
+ readonly decoded?: never;
4088
+ readonly states?: never;
4089
+ readonly update?: never;
4090
+ } & (RegisteredInput<R> extends typeof Schema.Void ? {
4091
+ readonly input?: never;
4092
+ } : {
4093
+ /** Fresh machine input used by root construction and root initial callbacks. */ readonly input: RegisteredInput<R>["Type"];
4094
+ });
4095
+ type ObjectSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends StateNodeIdentifier<S>, R> = P extends "" ? ConstructionCall<RootInput<R>, InitialTarget<P>> : P extends ChoiceIdentifier<S> ? () => ChoiceTarget<S, P> : P extends StateIdentifier<S> ? ConstructionCall<ConstructionObject<NodeByIdentifier<S, P>, Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never> & {
4096
+ readonly update?: never;
4097
+ }, Target<S, P>> : never;
4098
+ type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D, R = {}> = D extends {
4263
4099
  readonly target: infer Ref;
4264
4100
  } ? RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ? D extends {
4265
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4266
4101
  readonly update: infer Update;
4267
- } ? RefPath<Update> extends infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>> ? TargetSelection<UpdatingTargetBuilder<BranchBuilderAt<S, Src, P>, S, Owner>, P, "state", "branch"> : never : TargetSelection<BranchBuilderAt<S, Src, P>, P, P extends ChoiceIdentifier<S> ? "choice" : "state", "branch"> : never : D extends {
4268
- /** Enters a compound or parallel subtree through its declared initialization. */
4269
- readonly initial: infer Ref;
4270
- } ? RefPath<Ref> extends infer P extends string ? BranchBuilderAt<S, Src, P> extends {
4271
- /** Enters a compound or parallel subtree through its declared initialization. */
4272
- readonly initial: infer B;
4273
- } ? TargetSelection<B, P, "initial", "branch"> : never : never : D extends {
4274
- /** Restores the declared history reference, using its fallback on first entry. */
4102
+ } ? RefPath<Update> extends infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>> ? P extends StateIdentifier<S> ? TargetSelection<ConstructionCall<ConstructionObject<NodeByIdentifier<S, P>, Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never> & {
4103
+ readonly update: ConstructionData<NodeByIdentifier<S, Owner>>;
4104
+ }, CombinedTarget<Target<S, P>, S, Owner>>, P, "state", "branch"> : never : never : TargetSelection<ObjectSelection<S, Src, P, R>, P, P extends ChoiceIdentifier<S> ? "choice" : "state", "branch"> : never : D extends {
4275
4105
  readonly history: infer Ref;
4276
- } ? RefPath<Ref> extends infer P extends string ? TargetSelection<AtBuilder<RootBuilder<HistoryTargetBuilder<S>>, P>, P, "history", "full"> : never : D extends {
4277
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4106
+ } ? RefPath<Ref> extends infer P extends HistoryIdentifier<S> ? TargetSelection<() => HistoryTarget<S, P>, P, "history", "full"> : never : D extends {
4278
4107
  readonly update: infer Ref;
4279
- } ? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>> ? TargetSelection<StateUpdateBuilder<S, P>, P, "update", "branch"> : never : D extends {
4280
- /** Accepts the event without selecting a new destination. */
4108
+ } ? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>> ? TargetSelection<ConstructionCall<ConstructionData<NodeByIdentifier<S, P>>, StateUpdate<S, P>>, P, "update", "branch"> : never : D extends {
4281
4109
  readonly none: true;
4282
4110
  } ? TargetSelection<() => NoTarget, never, "none", "local"> : never;
4283
4111
  type BuilderArgs<B, K extends PropertyKey> = K extends keyof B ? B[K] extends (...args: infer A) => unknown ? A : never : never;
@@ -4288,14 +4116,6 @@ export declare namespace Machine {
4288
4116
  readonly [K in Exclude<"from" | "decoded", M>]?: never;
4289
4117
  } : never;
4290
4118
  }[Extract<keyof B, "from" | "decoded">];
4291
- type ObjectDefault<B> = B extends {
4292
- /** Constructs schema make input from the typed source context. */
4293
- readonly from: () => unknown;
4294
- } | (() => unknown) ? {
4295
- /** Constructs schema make input from the typed source context. */
4296
- readonly from?: never; /** Supplies an already decoded schema value from the typed source context. */
4297
- readonly decoded?: never;
4298
- } : never;
4299
4119
  type ObjectPolicy<C, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
4300
4120
  /** Set to true to exit and reenter the handler source. */
4301
4121
  readonly reenter?: Reenter extends true ? boolean : never;
@@ -4318,12 +4138,22 @@ export declare namespace Machine {
4318
4138
  type InlineDestinationConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends DestinationPath<S>, C> = P extends ChoiceIdentifier<S> ? {
4319
4139
  readonly from?: never;
4320
4140
  readonly decoded?: never;
4321
- } : P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
4322
- readonly states: StateSchemas;
4323
- } ? [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? ObjectConstruction<C, BranchBuilderAt<S, Src, P>> | ObjectDefault<BranchBuilderAt<S, Src, P>> : never : InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
4141
+ } : P extends StateIdentifier<S> ? InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
4142
+ type InlineRoot<S extends StateSchemas, C, R> = {
4143
+ readonly target: ReferenceAt<S, Extract<"", StateNodeIdentifier<S>>>;
4144
+ readonly update?: never;
4145
+ readonly branches?: never;
4146
+ readonly resolve?: never;
4147
+ readonly history?: never;
4148
+ readonly none?: never;
4149
+ } & (RegisteredInput<R> extends typeof Schema.Void ? {
4150
+ readonly input?: never;
4151
+ } : {
4152
+ /** Fresh machine input used to reconstruct root and its initial children. */ readonly input: DataValue<C, RegisteredInput<R>["Type"]>;
4153
+ });
4324
4154
  type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
4325
4155
  readonly [P in DestinationPath<S>]: {
4326
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4156
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4327
4157
  readonly target: ReferenceAt<S, P>;
4328
4158
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4329
4159
  readonly update?: never;
@@ -4341,20 +4171,7 @@ export declare namespace Machine {
4341
4171
  readonly declinable?: never;
4342
4172
  } & InlineDestinationConstruction<S, Src, P, C>;
4343
4173
  }[DestinationPath<S>];
4344
- type InlinePairConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string, Owner extends ValuedStateIdentifier<S>, C> = P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
4345
- readonly states: StateSchemas;
4346
- } ? {
4347
- readonly [M in Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">]: BuilderArgs<BranchBuilderAt<S, Src, P>, M> extends readonly [unknown?] ? {
4348
- readonly [K in M]: (context: C) => {
4349
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4350
- readonly target: BuilderArgs<BranchBuilderAt<S, Src, P>, M>[0];
4351
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4352
- readonly update: BuilderArgs<StateUpdateBuilder<S, Owner>, M>[0];
4353
- };
4354
- } & {
4355
- readonly [K in Exclude<"from" | "decoded", M>]?: never;
4356
- } : never;
4357
- }[Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">] : {
4174
+ type InlinePairConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string, Owner extends ValuedStateIdentifier<S>, C> = P extends StateIdentifier<S> ? {
4358
4175
  readonly from: (context: C) => {
4359
4176
  readonly target: [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? undefined : NodeMakeInput<NodeByIdentifier<S, P>>;
4360
4177
  readonly update: SchemaByIdentifier<S, Owner>["~type.make.in"];
@@ -4372,7 +4189,7 @@ export declare namespace Machine {
4372
4189
  ] extends [never] ? never : {
4373
4190
  readonly [P in DestinationPath<S>]: {
4374
4191
  readonly [Owner in Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>]: {
4375
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4192
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4376
4193
  readonly target: ReferenceAt<S, P>;
4377
4194
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4378
4195
  readonly update: ReferenceAt<S, Owner>;
@@ -4397,7 +4214,7 @@ export declare namespace Machine {
4397
4214
  readonly reenter?: P extends Src ? never : boolean;
4398
4215
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4399
4216
  readonly update: ReferenceAt<S, P>;
4400
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4217
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4401
4218
  readonly target?: never;
4402
4219
  /** Enters a compound or parallel subtree through its declared initialization. */
4403
4220
  readonly initial?: never;
@@ -4413,51 +4230,29 @@ export declare namespace Machine {
4413
4230
  readonly declinable?: never;
4414
4231
  } & ObjectConstruction<C, StateUpdateBuilder<S, P>>;
4415
4232
  }[Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>];
4416
- type InlineInitial<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = [
4417
- Exclude<ObjectCompoundPath<S>, "">
4418
- ] extends [never] ? never : {
4419
- readonly [P in Exclude<ObjectCompoundPath<S>, "">]: InitialTargetFactory<NodeByIdentifier<S, P>, P> extends infer B ? {
4420
- /** Enters a compound or parallel subtree through its declared initialization. */
4421
- readonly initial: ReferenceAt<S, P>;
4422
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4423
- readonly target?: never;
4424
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4425
- readonly update?: never;
4426
- /** Restores the declared history reference, using its fallback on first entry. */
4427
- readonly history?: never;
4428
- /** Accepts the event without selecting a new destination. */
4429
- readonly none?: never;
4430
- /** Named groups of inspectable destinations used by transition resolvers. */
4431
- readonly branches?: never;
4432
- /** Selects one declared branch and may enqueue synchronous commands. */
4433
- readonly resolve?: never;
4434
- /** Set to true when the resolver can explicitly return decline(). */
4435
- readonly declinable?: never;
4436
- } & (ObjectConstruction<C, B> | ObjectDefault<B>) : never;
4437
- }[Exclude<ObjectCompoundPath<S>, "">];
4438
- type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
4233
+ type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
4439
4234
  readonly [K in Extract<keyof Group, string>]: {
4440
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4441
- readonly target: SelectionOf<S, Src, Group[K]>;
4235
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4236
+ readonly target: SelectionOf<S, Src, Group[K], R>;
4442
4237
  };
4443
4238
  };
4444
4239
  type ObjectBranchResolver<Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, C, B extends Readonly<Record<string, TransitionBranchInput>>, Declinable extends boolean> = (context: C & {
4445
4240
  readonly select: BranchSelectors<B>;
4446
4241
  } & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => BranchSelectionResult<B> | (Declinable extends true ? Declined : never);
4447
- type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
4242
+ type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
4448
4243
  readonly [K in keyof Group]: Src extends ChoiceIdentifier<S> ? Group[K] extends {
4449
4244
  /** Accepts the event without selecting a new destination. */
4450
4245
  readonly none: true;
4451
4246
  } | {
4452
4247
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4453
4248
  readonly update: unknown;
4454
- } ? K : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never;
4249
+ } ? K : [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K : never : [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K : never;
4455
4250
  }[keyof Group];
4456
4251
  type ObjectBranches<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Acceptance extends TransitionAcceptance> = {
4457
- readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K]>] extends [never] ? unknown : never) & {
4252
+ readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K], R>] extends [never] ? unknown : never) & {
4458
4253
  /** Named groups of inspectable destinations used by transition resolvers. */
4459
4254
  readonly branches: K;
4460
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4255
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4461
4256
  readonly target?: never;
4462
4257
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4463
4258
  readonly update?: never;
@@ -4475,19 +4270,34 @@ export declare namespace Machine {
4475
4270
  /** Set to true when the resolver can explicitly return decline(). */
4476
4271
  readonly declinable?: "declinable" extends Acceptance ? boolean : false;
4477
4272
  /** Selects one declared branch and may enqueue synchronous commands. */
4478
- readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K]>, true>;
4273
+ readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K], R>, true>;
4479
4274
  };
4480
4275
  }[Extract<keyof Registered<R, "branches">, string>];
4276
+ type DataValue<C, A> = A | ((context: C) => A);
4277
+ type DeclarationData<T> = T extends {
4278
+ readonly from: (context: infer C) => infer A;
4279
+ } ? Omit<T, "from" | "decoded"> & {
4280
+ readonly data: DataValue<C, A>;
4281
+ readonly decoded?: false;
4282
+ } : T extends {
4283
+ readonly decoded: (context: infer C) => infer A;
4284
+ } ? Omit<T, "from" | "decoded"> & {
4285
+ readonly data: DataValue<C, A>;
4286
+ readonly decoded: true;
4287
+ } : T extends unknown ? Omit<T, "from" | "decoded"> & {
4288
+ readonly data?: never;
4289
+ readonly decoded?: never;
4290
+ } : never;
4481
4291
  /**
4482
4292
  * A transition with an inspectable destination and source-specific construction.
4483
4293
  *
4484
4294
  * @category models
4485
4295
  * @since 0.34.0
4486
4296
  */
4487
- type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> & (InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineInitial<S, Src, C> | {
4297
+ type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> & DeclarationData<(InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineRoot<S, C, R> | {
4488
4298
  /** Restores the declared history reference, using its fallback on first entry. */
4489
4299
  readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
4490
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4300
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4491
4301
  readonly target?: never;
4492
4302
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4493
4303
  readonly update?: never;
@@ -4508,7 +4318,7 @@ export declare namespace Machine {
4508
4318
  } | (Src extends ChoiceIdentifier<S> ? never : {
4509
4319
  /** Accepts the event without selecting a new destination. */
4510
4320
  readonly none: true;
4511
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
4321
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4512
4322
  readonly target?: never;
4513
4323
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4514
4324
  readonly update?: never;
@@ -4526,7 +4336,7 @@ export declare namespace Machine {
4526
4336
  readonly declinable?: "declinable" extends Acceptance ? boolean : false;
4527
4337
  /** Selects one declared branch and may enqueue synchronous commands. */
4528
4338
  readonly resolve?: (context: C & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => undefined | Declined;
4529
- }) | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>);
4339
+ }) | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>)>;
4530
4340
  type SourceValue<R, K extends PropertyKey> = {
4531
4341
  readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Registered<R, Kind>[K] : never;
4532
4342
  }["effects" | "streams" | "timers" | "logic" | "children"];
@@ -4609,6 +4419,101 @@ export declare namespace Machine {
4609
4419
  readonly address?: never;
4610
4420
  }) & (SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? M extends EnsureExecutable<States<M>, UnhandledStates<M>, OutputStates<M>> ? unknown : never : never : unknown) & RegisteredInvocationInput<R, K, InvokeContext<S, Ev, Em, Src, In, Pa>> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, InvokeOutput<ResolvedInvoke<R, K>>, "onDone"> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, RegisteredInvokeError<R, K>, "onFailure"> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, SourceKind<R, K> extends "streams" ? Stream.Success<Extract<InvokeResolvedSource<SourceValue<R, K>>, Stream.Stream<any, any, any>>> : never, "onElement"> & (SourceKind<R, K> extends "logic" | "children" ? Partial<ObjectOutcome<S, Ev, Em, Src, In, Pa, R, LogicStateOf<InvokeLogic<ResolvedInvoke<R, K>>>, "onSnapshot">> : {})>;
4611
4421
  }[Extract<SourceKeys<R>, string>];
4422
+ type OrdinaryData<A> = A extends unknown ? A & ({
4423
+ readonly decoded?: false | undefined;
4424
+ } | {
4425
+ readonly data?: never;
4426
+ }) : never;
4427
+ type ShortConstruction<C, Node> = [NodeSchema<Node>] extends [never] ? never : OrdinaryData<NodeMakeInput<Node>> | ((context: C) => NodeMakeInput<Node>) | {
4428
+ readonly decoded: true;
4429
+ readonly data: DataValue<C, NodeValue<Node>>;
4430
+ };
4431
+ type InitialData<C, Node> = [NodeSchema<Node>] extends [never] ? {
4432
+ readonly data?: never;
4433
+ readonly decoded?: never;
4434
+ } : ({
4435
+ readonly decoded?: false;
4436
+ } & ({} extends NodeMakeInput<Node> ? {
4437
+ readonly data?: DataValue<C, NodeMakeInput<Node>>;
4438
+ } : {
4439
+ readonly data: DataValue<C, NodeMakeInput<Node>>;
4440
+ })) | {
4441
+ readonly decoded: true;
4442
+ readonly data: DataValue<C, NodeValue<Node>>;
4443
+ };
4444
+ type InitialEdge<S extends StateSchemas, Node, Src extends StateNodeIdentifier<S>, C> = Node extends {
4445
+ readonly states: infer Children extends StateSchemas;
4446
+ } ? {
4447
+ readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: {
4448
+ readonly target: TargetReference<ReferenceRoot<S>, JoinPath<Src, K>, Children[K] extends ChoiceStateNodeConfig ? "choice" : "state">;
4449
+ } & InitialData<C, Children[K]>;
4450
+ }[ActiveStateKey<Children> | ChoiceStateKey<Children>] : never;
4451
+ type InitialRegions<C, Children extends StateSchemas> = {
4452
+ readonly [K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? K : never]?: never;
4453
+ } & {
4454
+ readonly [K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? never : {} extends NodeMakeInput<Children[K]> ? never : K]: ShortConstruction<C, Children[K]>;
4455
+ } & {
4456
+ readonly [K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? never : {} extends NodeMakeInput<Children[K]> ? K : never]?: ShortConstruction<C, Children[K]>;
4457
+ };
4458
+ type RequiresInitialHandler<Node> = Node extends {
4459
+ readonly states: StateSchemas;
4460
+ } ? true : false;
4461
+ type ChildHandlerMap<S extends StateSchemas, Children extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = {
4462
+ readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children> as RequiresInitialHandler<Children[K]> extends true ? K : never]: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>;
4463
+ } & {
4464
+ readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children> as RequiresInitialHandler<Children[K]> extends true ? never : K]?: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>;
4465
+ };
4466
+ type ChildHandlers<S extends StateSchemas, Children extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = [
4467
+ {
4468
+ [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: RequiresInitialHandler<Children[K]> extends true ? K : never;
4469
+ }[ActiveStateKey<Children> | ChoiceStateKey<Children>]
4470
+ ] extends [never] ? {
4471
+ readonly states?: ChildHandlerMap<S, Children, Ev, Em, Src, In, Pa, R>;
4472
+ } : {
4473
+ readonly states: ChildHandlerMap<S, Children, Ev, Em, Src, In, Pa, R>;
4474
+ };
4475
+ type InitialHandler<S extends StateSchemas, Node, Src extends StateNodeIdentifier<S>, C> = Node extends {
4476
+ readonly type: "parallel";
4477
+ readonly states: infer Children extends StateSchemas;
4478
+ } ? {} extends InitialRegions<C, Children> ? {
4479
+ readonly initial?: InitialRegions<C, Children>;
4480
+ } : {
4481
+ readonly initial: InitialRegions<C, Children>;
4482
+ } : Node extends {
4483
+ readonly states: StateSchemas;
4484
+ } ? {
4485
+ readonly initial: InitialEdge<S, Node, Src, C>;
4486
+ } : {
4487
+ readonly initial?: never;
4488
+ };
4489
+ type RootConstruction<Node, Input> = [NodeSchema<Node>] extends [never] ? {
4490
+ readonly root?: never;
4491
+ } : {} extends NodeMakeInput<Node> ? {
4492
+ /** Constructs root-owned data from startup or fresh root-target input. */ readonly root?: ShortConstruction<{
4493
+ readonly input: Input;
4494
+ }, Node>;
4495
+ } : {
4496
+ /** Constructs root-owned data from startup or fresh root-target input. */ readonly root: ShortConstruction<{
4497
+ readonly input: Input;
4498
+ }, Node>;
4499
+ };
4500
+ type ExactConstruction<C> = C extends {
4501
+ readonly decoded: true;
4502
+ readonly data: unknown;
4503
+ } ? {
4504
+ readonly [K in Exclude<keyof C, "decoded" | "data">]: never;
4505
+ } : unknown;
4506
+ type ValidateInitialDeclaration<Node, C> = Node extends {
4507
+ readonly type: "parallel";
4508
+ readonly states: infer Children extends StateSchemas;
4509
+ } ? {
4510
+ readonly [K in keyof C]: K extends ActiveStateKey<Children> ? ExactConstruction<C[K]> : never;
4511
+ } : {
4512
+ readonly [K in Exclude<keyof C, "target" | "data" | "decoded">]: never;
4513
+ };
4514
+ type ValidateConstructionDeclarations<Node, C> = {
4515
+ readonly [K in Extract<keyof C, "root" | "initial">]: K extends "root" ? ExactConstruction<C[K]> : K extends "initial" ? ValidateInitialDeclaration<Node, C[K]> : unknown;
4516
+ };
4612
4517
  type ObjectLifecycle<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>> = Src extends StateIdentifier<S> ? {
4613
4518
  /** Runs synchronously on entry and may enqueue commands. */
4614
4519
  readonly entry?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
@@ -4616,18 +4521,14 @@ export declare namespace Machine {
4616
4521
  readonly type: "final";
4617
4522
  } ? {
4618
4523
  /** Runs synchronously on exit and may enqueue commands. */
4619
- readonly exit?: never; /** Constructs required values for the declared initial child or parallel regions. */
4620
- readonly initialize?: never;
4524
+ readonly exit?: never;
4621
4525
  } & OutputHandlerConfig<S, Ev, Src, FinalOutputContext<S, Ev, Src>> : {
4622
4526
  /** Runs synchronously on exit and may enqueue commands. */
4623
4527
  readonly exit?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
4624
- /** Constructs required values for the declared initial child or parallel regions. */
4625
- readonly initialize?: StateInitializeHandler<S, Ev, Em, Src, In, Pa>;
4626
4528
  } & ActiveOutputHandlerConfig<S, Ev, Src>) : {
4627
4529
  /** Runs synchronously on entry and may enqueue commands. */
4628
4530
  readonly entry?: never; /** Runs synchronously on exit and may enqueue commands. */
4629
- readonly exit?: never; /** Constructs required values for the declared initial child or parallel regions. */
4630
- readonly initialize?: never; /** Constructs the decoded output declared by the state schema. */
4531
+ readonly exit?: never; /** Constructs the decoded output declared by the state schema. */
4631
4532
  readonly output?: never;
4632
4533
  };
4633
4534
  /**
@@ -4636,7 +4537,12 @@ export declare namespace Machine {
4636
4537
  * @category models
4637
4538
  * @since 0.34.0
4638
4539
  */
4639
- type StateHandler<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa> & (Src extends ChoiceIdentifier<S> ? {
4540
+ type StateHandler<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa> & InitialHandler<S, Node, Src, StateActionContext<S, Ev, Em, Extract<Src, StateIdentifier<S>>, In, Pa> & {
4541
+ /** Root-owned data constructed before initial descendant values. */
4542
+ readonly root: StateByIdentifier<S, Extract<"", StateIdentifier<S>>>;
4543
+ } & (Src extends "" ? {
4544
+ /** Fresh machine input used by root construction and root initial callbacks. */ readonly input: RegisteredInput<R>["Type"];
4545
+ } : {})> & (Src extends ChoiceIdentifier<S> ? {
4640
4546
  /** Required total transition for a transient choice state. */
4641
4547
  readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>;
4642
4548
  /** Event handlers keyed by the public or internal event tag. */
@@ -4689,18 +4595,19 @@ export declare namespace Machine {
4689
4595
  readonly states: infer Children extends StateSchemas;
4690
4596
  } ? {
4691
4597
  /** Child handlers nested according to the declared root topology. */
4692
- readonly states?: {
4693
- readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]?: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>;
4694
- };
4695
4598
  /** Restores the declared history reference, using its fallback on first entry. */
4696
4599
  readonly history?: HistoryDefaultConfig<S, Ev, Em, Src, Children>;
4697
- } : {
4600
+ } & ChildHandlers<S, Children, Ev, Em, Src, In, Pa, R> : {
4698
4601
  /** Child handlers nested according to the declared root topology. */
4699
4602
  readonly states?: never; /** Restores the declared history reference, using its fallback on first entry. */
4700
4603
  readonly history?: never;
4701
4604
  }) : never);
4702
- type ValidateObjectTransition<T> = {
4703
- readonly [K in Exclude<keyof T, "target" | "update" | "initial" | "history" | "none" | "branches" | "from" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
4605
+ type ValidateObjectTransition<T> = ("input" extends keyof T ? T extends {
4606
+ readonly target: TargetReference<any, "", "state">;
4607
+ } ? unknown : {
4608
+ readonly input: never;
4609
+ } : unknown) & {
4610
+ readonly [K in Exclude<keyof T, "target" | "update" | "input" | "history" | "none" | "branches" | "data" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
4704
4611
  } & (T extends {
4705
4612
  /** Set to true when the resolver can explicitly return decline(). */
4706
4613
  readonly declinable: infer D;
@@ -4761,7 +4668,9 @@ export declare namespace Machine {
4761
4668
  * @since 0.34.0
4762
4669
  */
4763
4670
  interface Handler<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, I extends Schema.Top, IE, IR, Final extends StateIdentifier<S>, Out, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> {
4764
- <const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & ([Ev[number] | keyof Registered<R, "branches"> | SourceKeys<R>] extends [never] ? StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R> : HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R>>) & ValidateObjectConfig<NoInfer<C>, R> & RootHandlerValidation<S, Ev, In, Em, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
4671
+ <const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R & {
4672
+ readonly "~input": I;
4673
+ }> & RootConstruction<S[""], I["Type"]>> & RootConstruction<S[""], I["Type"]> & ValidateObjectConfig<NoInfer<C>, R> & RootHandlerValidation<S, Ev, In, Em, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
4765
4674
  readonly "": NormalizeObjectConfig<NoInfer<C>, R>;
4766
4675
  }>["outputState"], StateIdentifier<S>>>): HandleTreeResult<S, Ev, Em, I, StateIdentifier<S>, never, never, IE, IR, Final, Out, never, In, Pa, {
4767
4676
  readonly "": NormalizeObjectConfig<C, R>;
@@ -4884,24 +4793,23 @@ export declare const isMachine: (u: unknown) => u is Machine.Any;
4884
4793
  */
4885
4794
  export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, state: Machine.Snapshot<States>) => state is Machine.SnapshotContainingFinal<States, FinalStates>;
4886
4795
  /**
4887
- * Defines one reusable active state while preserving its exact child topology.
4796
+ * Defines root or nested state schemas while preserving the exact child topology.
4888
4797
  *
4889
- * Prefer declaring state nodes inline in {@link states}. Use this constructor
4890
- * only when the same state definition is mounted more than once.
4891
- * Tagged schemas are already reusable and do not need this constructor.
4798
+ * Pass the root descriptor to {@link make} and {@link targets}. Nested states
4799
+ * can be declared inline or reused by mounting a descriptor in multiple places.
4800
+ * Initial edges and value constructors belong in the handler tree.
4892
4801
  *
4893
4802
  * **Example** (Repeated compound state)
4894
4803
  *
4895
4804
  * ```ts
4896
- * import { Schema } from "effect"
4897
4805
  * import { Machine } from "@typeonce/effect-machine"
4806
+ * import { Schema } from "effect"
4898
4807
  *
4899
4808
  * const TradingState = Schema.TaggedUnion({
4900
4809
  * InSession: {},
4901
4810
  * Applying: {}
4902
4811
  * })
4903
4812
  * const TradingSlot = Machine.state({
4904
- * initial: "Idle",
4905
4813
  * states: {
4906
4814
  * Idle: {},
4907
4815
  * InSession: TradingState.cases.InSession,
@@ -4909,10 +4817,12 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
4909
4817
  * }
4910
4818
  * })
4911
4819
  *
4912
- * const States = Machine.state({ initial: "slot1", states: {
4913
- * slot1: TradingSlot,
4914
- * slot2: TradingSlot
4915
- * } })
4820
+ * const States = Machine.state({
4821
+ * states: {
4822
+ * slot1: TradingSlot,
4823
+ * slot2: TradingSlot
4824
+ * }
4825
+ * })
4916
4826
  * ```
4917
4827
  *
4918
4828
  * @category constructors
@@ -5022,33 +4932,10 @@ type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends Readon
5022
4932
  /** Named groups of inspectable destinations used by transition resolvers. */
5023
4933
  readonly branches: Branches;
5024
4934
  }>;
5025
- type RootInitialization<Root extends Machine.StateNodeConfig, Input> = {
5026
- readonly initialConfiguration?: never;
5027
- } & (Machine.NodeSchema<Root> extends never ? {
5028
- /** Enters a compound or parallel subtree through its declared initialization. */
5029
- readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
5030
- } : {} extends NodeMakeInput<Root> ? {
5031
- /** Enters a compound or parallel subtree through its declared initialization. */
5032
- readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
5033
- } : {
5034
- /** Enters a compound or parallel subtree through its declared initialization. */
5035
- readonly initial: Machine.RootInitialBuilderInput<Root, Input>;
5036
- });
5037
4935
  /** @inline */
5038
4936
  interface Make {
5039
- /** @param config Complete starting configuration, including root and descendant values. */
5040
- <const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>> & {
5041
- /** Mutually exclusive with a complete initial configuration. */
5042
- readonly initial?: never;
5043
- /** Constructs the complete initial root configuration, overriding child defaults. */
5044
- readonly initialConfiguration: Machine.RootConfigurationBuilderInput<NoInfer<Root>, Input["Type"]>;
5045
- }): MakeResult<Root & {
5046
- readonly "~effect/Machine/ExplicitInitial": true;
5047
- }, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
5048
4937
  /** @param config Complete schema-first machine definition. */
5049
- <const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>> & Exclude<RootInitialization<NoInfer<Root>, Input["Type"]>, {
5050
- readonly initialConfiguration: unknown;
5051
- }>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
4938
+ <const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
5052
4939
  }
5053
4940
  /**
5054
4941
  * Creates a schema-first machine definition.
@@ -5078,35 +4965,40 @@ interface Make {
5078
4965
  * **Example** (Typed counter machine)
5079
4966
  *
5080
4967
  * ```ts
5081
- * import { Schema } from "effect"
5082
4968
  * import { Machine } from "@typeonce/effect-machine"
5083
- *
4969
+ * import { Schema } from "effect"
5084
4970
  * class Count extends Schema.TaggedClass<Count>("Count")("Count", {
5085
4971
  * value: Schema.Number
5086
- * }) {}
5087
- *
4972
+ * }) {
4973
+ * }
5088
4974
  * class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
5089
4975
  * by: Schema.Number
5090
- * }) {}
5091
- *
5092
- * const States = Machine.state({ initial: "Count", states: { Count } })
4976
+ * }) {
4977
+ * }
4978
+ * const States = Machine.state({ states: { Count } })
5093
4979
  * const Events = Machine.eventsFromSchemas(Increment)
5094
4980
  * const targets = Machine.targets(States)
5095
- *
5096
4981
  * const counter = Machine.make({
5097
4982
  * root: States,
5098
- * events: Events,
5099
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Count.decoded(new Count({ value: 0 }))))
5100
- * }).handle({ states: {
5101
- * Count: {
5102
- * on: {
5103
- * Increment: {
5104
- * update: targets.root.Count,
5105
- * decoded: ({ event, state }) => new Count({ value: state.value + event.by })
4983
+ * events: Events
4984
+ * }).handle({
4985
+ * initial: {
4986
+ * target: Machine.targets(States).root.Count,
4987
+ * decoded: true,
4988
+ * data: new Count({ value: 0 })
4989
+ * },
4990
+ * states: {
4991
+ * Count: {
4992
+ * on: {
4993
+ * Increment: {
4994
+ * update: targets.root.Count,
4995
+ * decoded: true,
4996
+ * data: ({ event, state }) => new Count({ value: state.value + event.by })
4997
+ * }
5106
4998
  * }
5107
4999
  * }
5108
5000
  * }
5109
- * } })
5001
+ * })
5110
5002
  * ```
5111
5003
  *
5112
5004
  * @see {@link state} for typed state-tree helpers.
@@ -5287,17 +5179,22 @@ export declare const emittedEventsFromSchemas: {
5287
5179
  * **Example**
5288
5180
  *
5289
5181
  * ```ts
5290
- * import { Effect, Schema } from "effect"
5291
5182
  * import { Machine } from "@typeonce/effect-machine"
5292
- *
5293
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
5294
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
5183
+ * import { Effect, Schema } from "effect"
5184
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
5185
+ * }
5186
+ * const States = Machine.state({ states: { Idle } })
5295
5187
  * const machine = Machine.make({
5296
5188
  * root: States,
5297
- * events: Machine.eventsFromSchemas(),
5298
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
5299
- * }).handle({ states: { Idle: {} } })
5300
- *
5189
+ * events: Machine.eventsFromSchemas()
5190
+ * }).handle({
5191
+ * initial: {
5192
+ * target: Machine.targets(States).root.Idle
5193
+ * },
5194
+ * states: {
5195
+ * Idle: {}
5196
+ * }
5197
+ * })
5301
5198
  * const encoded = Effect.gen(function*() {
5302
5199
  * const initial = yield* Machine.planInitial(machine)
5303
5200
  * return yield* Machine.encodeSnapshot(machine, initial.state)
@@ -5331,17 +5228,22 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
5331
5228
  * **Example**
5332
5229
  *
5333
5230
  * ```ts
5334
- * import { Effect, Schema } from "effect"
5335
5231
  * import { Machine } from "@typeonce/effect-machine"
5336
- *
5337
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
5338
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
5232
+ * import { Effect, Schema } from "effect"
5233
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
5234
+ * }
5235
+ * const States = Machine.state({ states: { Idle } })
5339
5236
  * const machine = Machine.make({
5340
5237
  * root: States,
5341
- * events: Machine.eventsFromSchemas(),
5342
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
5343
- * }).handle({ states: { Idle: {} } })
5344
- *
5238
+ * events: Machine.eventsFromSchemas()
5239
+ * }).handle({
5240
+ * initial: {
5241
+ * target: Machine.targets(States).root.Idle
5242
+ * },
5243
+ * states: {
5244
+ * Idle: {}
5245
+ * }
5246
+ * })
5345
5247
  * const roundTrip = Effect.gen(function*() {
5346
5248
  * const initial = yield* Machine.planInitial(machine)
5347
5249
  * const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
@@ -5389,17 +5291,22 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
5389
5291
  * **Example**
5390
5292
  *
5391
5293
  * ```ts
5392
- * import { Effect, Schema } from "effect"
5393
5294
  * import { Machine } from "@typeonce/effect-machine"
5394
- *
5395
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
5396
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
5295
+ * import { Effect, Schema } from "effect"
5296
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
5297
+ * }
5298
+ * const States = Machine.state({ states: { Idle } })
5397
5299
  * const machine = Machine.make({
5398
5300
  * root: States,
5399
- * events: Machine.eventsFromSchemas(),
5400
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
5401
- * }).handle({ states: { Idle: {} } })
5402
- *
5301
+ * events: Machine.eventsFromSchemas()
5302
+ * }).handle({
5303
+ * initial: {
5304
+ * target: Machine.targets(States).root.Idle
5305
+ * },
5306
+ * states: {
5307
+ * Idle: {}
5308
+ * }
5309
+ * })
5403
5310
  * const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
5404
5311
  * ```
5405
5312
  *
@@ -5561,12 +5468,15 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
5561
5468
  * import { Effect, Schema } from "effect"
5562
5469
  *
5563
5470
  * const internalEvents = Machine.internalEventsFromSchemas(Schema.TaggedStruct("Loaded", {}))
5471
+ * const Root = Machine.state({ states: { Idle: {} } })
5564
5472
  * const machine = Machine.make({
5565
- * root: Machine.state({ initial: "Idle", states: { Idle: {} } }),
5473
+ * root: Root,
5566
5474
  * events: Machine.eventsFromSchemas(),
5567
- * internalEvents,
5568
- * initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.from()))
5569
- * }).handle({ states: { Idle: { on: { Loaded: { none: true } } } } })
5475
+ * internalEvents
5476
+ * }).handle({
5477
+ * initial: { target: Machine.targets(Root).root.Idle },
5478
+ * states: { Idle: { on: { Loaded: { none: true } } } }
5479
+ * })
5570
5480
  *
5571
5481
  * export const canLoad = Effect.gen(function*() {
5572
5482
  * const initial = yield* Machine.planInitial(machine)
@@ -5601,27 +5511,32 @@ export declare const can: {
5601
5511
  * **Example**
5602
5512
  *
5603
5513
  * ```ts
5604
- * import { Effect, Schema } from "effect"
5605
5514
  * import { Machine } from "@typeonce/effect-machine"
5606
- *
5607
- * class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {}
5608
- * class On extends Schema.TaggedClass<On>("On")("On", {}) {}
5609
- * class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
5610
- * const States = Machine.state({ initial: "Off", states: { Off, On } })
5515
+ * import { Effect, Schema } from "effect"
5516
+ * class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {
5517
+ * }
5518
+ * class On extends Schema.TaggedClass<On>("On")("On", {}) {
5519
+ * }
5520
+ * class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {
5521
+ * }
5522
+ * const States = Machine.state({ states: { Off, On } })
5611
5523
  * const targets = Machine.targets(States)
5612
5524
  * const machine = Machine.make({
5613
5525
  * root: States,
5614
- * events: Machine.eventsFromSchemas(Toggle),
5615
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Off.from()))
5616
- * }).handle({ states: {
5617
- * Off: {
5618
- * on: {
5619
- * Toggle: { target: targets.root.On }
5620
- * }
5526
+ * events: Machine.eventsFromSchemas(Toggle)
5527
+ * }).handle({
5528
+ * initial: {
5529
+ * target: Machine.targets(States).root.Off
5621
5530
  * },
5622
- * On: {}
5623
- * } })
5624
- *
5531
+ * states: {
5532
+ * Off: {
5533
+ * on: {
5534
+ * Toggle: { target: targets.root.On }
5535
+ * }
5536
+ * },
5537
+ * On: {}
5538
+ * }
5539
+ * })
5625
5540
  * const nextState = Effect.gen(function*() {
5626
5541
  * const initial = yield* Machine.planInitial(machine)
5627
5542
  * return (yield* Machine.plan(machine, initial.state, new Toggle({}))).next
@@ -5820,17 +5735,22 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
5820
5735
  * **Example**
5821
5736
  *
5822
5737
  * ```ts
5823
- * import { Effect, Schema } from "effect"
5824
5738
  * import { Machine } from "@typeonce/effect-machine"
5825
- *
5826
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
5827
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
5739
+ * import { Effect, Schema } from "effect"
5740
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
5741
+ * }
5742
+ * const States = Machine.state({ states: { Idle } })
5828
5743
  * const machine = Machine.make({
5829
5744
  * root: States,
5830
- * events: Machine.eventsFromSchemas(),
5831
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
5832
- * }).handle({ states: { Idle: {} } })
5833
- *
5745
+ * events: Machine.eventsFromSchemas()
5746
+ * }).handle({
5747
+ * initial: {
5748
+ * target: Machine.targets(States).root.Idle
5749
+ * },
5750
+ * states: {
5751
+ * Idle: {}
5752
+ * }
5753
+ * })
5834
5754
  * const state = Effect.gen(function*() {
5835
5755
  * const ref = yield* Machine.start(machine)
5836
5756
  * return yield* ref.state
@@ -5870,17 +5790,22 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
5870
5790
  * **Example**
5871
5791
  *
5872
5792
  * ```ts
5873
- * import { Effect, Schema } from "effect"
5874
5793
  * import { Machine } from "@typeonce/effect-machine"
5875
- *
5876
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
5877
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
5794
+ * import { Effect, Schema } from "effect"
5795
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
5796
+ * }
5797
+ * const States = Machine.state({ states: { Idle } })
5878
5798
  * const machine = Machine.make({
5879
5799
  * root: States,
5880
- * events: Machine.eventsFromSchemas(),
5881
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
5882
- * }).handle({ states: { Idle: {} } })
5883
- *
5800
+ * events: Machine.eventsFromSchemas()
5801
+ * }).handle({
5802
+ * initial: {
5803
+ * target: Machine.targets(States).root.Idle
5804
+ * },
5805
+ * states: {
5806
+ * Idle: {}
5807
+ * }
5808
+ * })
5884
5809
  * const resumed = Effect.gen(function*() {
5885
5810
  * const initial = yield* Machine.planInitial(machine)
5886
5811
  * const encoded = yield* Machine.encodeSnapshot(machine, initial.state)