@typeonce/effect-machine 0.12.0 → 0.13.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 (80) hide show
  1. package/README.md +56 -4
  2. package/dist/Machine.d.ts +353 -84
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +12 -10
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/atom.d.ts +1 -0
  7. package/dist/internal/machine/atom.d.ts.map +1 -1
  8. package/dist/internal/machine/atom.js +23 -0
  9. package/dist/internal/machine/atom.js.map +1 -1
  10. package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
  11. package/dist/internal/machine/commandRuntime.js +2 -5
  12. package/dist/internal/machine/commandRuntime.js.map +1 -1
  13. package/dist/internal/machine/configuration.d.ts +5 -0
  14. package/dist/internal/machine/configuration.d.ts.map +1 -1
  15. package/dist/internal/machine/configuration.js +6 -2
  16. package/dist/internal/machine/configuration.js.map +1 -1
  17. package/dist/internal/machine/executionPlan.d.ts +1 -0
  18. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  19. package/dist/internal/machine/executionPlan.js +43 -18
  20. package/dist/internal/machine/executionPlan.js.map +1 -1
  21. package/dist/internal/machine/initialization.d.ts +5 -0
  22. package/dist/internal/machine/initialization.d.ts.map +1 -0
  23. package/dist/internal/machine/initialization.js +61 -0
  24. package/dist/internal/machine/initialization.js.map +1 -0
  25. package/dist/internal/machine/inspectionRuntime.d.ts +25 -0
  26. package/dist/internal/machine/inspectionRuntime.d.ts.map +1 -0
  27. package/dist/internal/machine/inspectionRuntime.js +79 -0
  28. package/dist/internal/machine/inspectionRuntime.js.map +1 -0
  29. package/dist/internal/machine/invocation.d.ts +2 -1
  30. package/dist/internal/machine/invocation.d.ts.map +1 -1
  31. package/dist/internal/machine/invocation.js +17 -10
  32. package/dist/internal/machine/invocation.js.map +1 -1
  33. package/dist/internal/machine/machine.d.ts +1 -2
  34. package/dist/internal/machine/machine.d.ts.map +1 -1
  35. package/dist/internal/machine/machine.js +21 -6
  36. package/dist/internal/machine/machine.js.map +1 -1
  37. package/dist/internal/machine/planner.d.ts +15 -0
  38. package/dist/internal/machine/planner.d.ts.map +1 -1
  39. package/dist/internal/machine/planner.js +117 -44
  40. package/dist/internal/machine/planner.js.map +1 -1
  41. package/dist/internal/machine/process.d.ts.map +1 -1
  42. package/dist/internal/machine/process.js +4 -2
  43. package/dist/internal/machine/process.js.map +1 -1
  44. package/dist/internal/machine/runtime.d.ts +27 -3
  45. package/dist/internal/machine/runtime.d.ts.map +1 -1
  46. package/dist/internal/machine/runtime.js +440 -64
  47. package/dist/internal/machine/runtime.js.map +1 -1
  48. package/dist/internal/machine/symbols.d.ts +2 -0
  49. package/dist/internal/machine/symbols.d.ts.map +1 -1
  50. package/dist/internal/machine/symbols.js +2 -0
  51. package/dist/internal/machine/symbols.js.map +1 -1
  52. package/dist/internal/machine/topology.d.ts +13 -0
  53. package/dist/internal/machine/topology.d.ts.map +1 -1
  54. package/dist/internal/machine/topology.js +9 -0
  55. package/dist/internal/machine/topology.js.map +1 -1
  56. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  57. package/dist/internal/testing/machine/finiteModel.js +3 -3
  58. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  59. package/dist/unstable/reactivity/AtomMachine.d.ts +9 -0
  60. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  61. package/dist/unstable/reactivity/AtomMachine.js +9 -0
  62. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  63. package/docs/agent-guide.md +102 -9
  64. package/package.json +5 -5
  65. package/src/Machine.ts +505 -174
  66. package/src/internal/machine/atom.ts +26 -0
  67. package/src/internal/machine/commandRuntime.ts +2 -9
  68. package/src/internal/machine/configuration.ts +28 -3
  69. package/src/internal/machine/executionPlan.ts +50 -17
  70. package/src/internal/machine/initialization.ts +73 -0
  71. package/src/internal/machine/inspectionRuntime.ts +102 -0
  72. package/src/internal/machine/invocation.ts +37 -12
  73. package/src/internal/machine/machine.ts +31 -6
  74. package/src/internal/machine/planner.ts +136 -42
  75. package/src/internal/machine/process.ts +4 -2
  76. package/src/internal/machine/runtime.ts +661 -89
  77. package/src/internal/machine/symbols.ts +3 -0
  78. package/src/internal/machine/topology.ts +27 -0
  79. package/src/internal/testing/machine/finiteModel.ts +8 -7
  80. package/src/unstable/reactivity/AtomMachine.ts +12 -0
package/src/Machine.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  import type * as Cause from "effect/Cause"
8
8
  import type * as Duration from "effect/Duration"
9
9
  import type * as Effect from "effect/Effect"
10
+ import type * as Exit from "effect/Exit"
10
11
  import type * as Option from "effect/Option"
11
12
  import type { Pipeable } from "effect/Pipeable"
12
13
  import { hasProperty } from "effect/Predicate"
@@ -840,6 +841,42 @@ type NodeMethod<
840
841
  > = Machine.NodeSchema<Node> extends never ? FromMethod<FromArguments, Result>
841
842
  : ((...args: Arguments) => Result) & FromMethod<FromArguments, Result>
842
843
 
844
+ type NodeMethodWithInitial<
845
+ Node,
846
+ Arguments extends ReadonlyArray<unknown>,
847
+ Result,
848
+ FromArguments extends ReadonlyArray<unknown>,
849
+ Path extends string
850
+ > = Machine.NodeSchema<Node> extends never ? {
851
+ readonly from: FromCallable<FromArguments, Machine.StateConstruction<Result>>
852
+ readonly initial: InitialTargetFactory<Node, Path>
853
+ }
854
+ :
855
+ & ((...args: Arguments) => Result)
856
+ & {
857
+ readonly from: FromCallable<FromArguments, Machine.StateConstruction<Result>>
858
+ readonly initial: InitialTargetFactory<Node, Path>
859
+ }
860
+
861
+ interface InitialTargetMethod<
862
+ Node,
863
+ Path extends string
864
+ > {
865
+ /** Enters this state through its declared initial configuration. */
866
+ readonly initial: InitialTargetFactory<Node, Path>
867
+ }
868
+
869
+ interface InitialTargetFactory<
870
+ Node,
871
+ Path extends string
872
+ > {
873
+ (...args: WithNodeValue<Node, readonly []>): Machine.InitialTarget<Path>
874
+ readonly from: FromCallable<
875
+ WithNodeInput<Node, readonly []>,
876
+ Machine.StateConstruction<Machine.InitialTarget<Path>>
877
+ >
878
+ }
879
+
843
880
  type NodeConstructionSelectorFromCallable<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
844
881
  <Selected extends ConstructionResult<Result>>(
845
882
  state: (builder: Builder) => Selected
@@ -847,15 +884,19 @@ type NodeConstructionSelectorFromCallable<Node, Builder, Result> = Machine.NodeS
847
884
  }
848
885
  : ConstructionSelectorFromCallable<NodeMakeInput<Node>, Builder, Result>
849
886
 
850
- type NestedTargetMethod<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
887
+ type NestedTargetMethod<Node, Builder, Result, Path extends string> = Machine.NodeSchema<Node> extends never ? {
851
888
  readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>
889
+ readonly initial: InitialTargetFactory<Node, Path>
852
890
  }
853
891
  :
854
892
  & (<Selected extends ConstructionResult<Result>>(
855
893
  value: NodeValue<Node>,
856
894
  state: (builder: Builder) => Selected
857
895
  ) => Selected)
858
- & { readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result> }
896
+ & {
897
+ readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>
898
+ readonly initial: InitialTargetFactory<Node, Path>
899
+ }
859
900
 
860
901
  type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input ? {
861
902
  <Selected extends ConstructionResult<Result>>(
@@ -1093,6 +1134,14 @@ type FullSnapshotResult<
1093
1134
  Path extends string = Machine.JoinPath<Prefix, StateId>
1094
1135
  > = Machine.SnapshotByIdentifierWithPath<States, StateId, Path>
1095
1136
 
1137
+ type InitialEntryStateKey<States extends Machine.StateSchemas> = {
1138
+ readonly [Key in ActiveStateKey<States>]: States[Key] extends { readonly states: Machine.StateSchemas } ? Key : never
1139
+ }[ActiveStateKey<States>]
1140
+
1141
+ type FullInitialTargetBuilder<States extends Machine.StateSchemas> = {
1142
+ readonly [Key in InitialEntryStateKey<States>]: InitialTargetMethod<States[Key], Key>
1143
+ }
1144
+
1096
1145
  type FullParallelBuilder<
1097
1146
  States extends Machine.StateSchemas,
1098
1147
  Prefix extends string,
@@ -1383,9 +1432,10 @@ type LocalTargetMethod<
1383
1432
  Source extends Path | `${Path}.${string}` ? NestedTargetMethod<
1384
1433
  Node,
1385
1434
  LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1386
- LocalTargetResultWithPrefix<AllStates, Children, Path>
1435
+ LocalTargetResultWithPrefix<AllStates, Children, Path>,
1436
+ Path
1387
1437
  >
1388
- : NodeMethod<
1438
+ : NodeMethodWithInitial<
1389
1439
  Node,
1390
1440
  WithNodeValue<Node, [
1391
1441
  states: (
@@ -1397,12 +1447,14 @@ type LocalTargetMethod<
1397
1447
  states: (
1398
1448
  builder: FullParallelBuilder<Children, Path>
1399
1449
  ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
1400
- ]>
1450
+ ]>,
1451
+ Path
1401
1452
  >
1402
1453
  : Node extends { readonly states: infer Children extends Machine.StateSchemas } ? NestedTargetMethod<
1403
1454
  Node,
1404
1455
  LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1405
- LocalTargetResultWithPrefix<AllStates, Children, Path>
1456
+ LocalTargetResultWithPrefix<AllStates, Children, Path>,
1457
+ Path
1406
1458
  >
1407
1459
  : NodeMethod<
1408
1460
  Node,
@@ -1497,10 +1549,11 @@ type BranchTargetMethod<
1497
1549
  & NestedTargetMethod<
1498
1550
  Node,
1499
1551
  BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1500
- BranchTargetResultWithPrefix<AllStates, Children, Path>
1552
+ BranchTargetResultWithPrefix<AllStates, Children, Path>,
1553
+ Path
1501
1554
  >
1502
1555
  & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>
1503
- : NodeMethod<
1556
+ : NodeMethodWithInitial<
1504
1557
  Node,
1505
1558
  WithNodeValue<Node, [
1506
1559
  states: (
@@ -1512,13 +1565,15 @@ type BranchTargetMethod<
1512
1565
  states: (
1513
1566
  builder: FullParallelBuilder<Children, Path>
1514
1567
  ) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
1515
- ]>
1568
+ ]>,
1569
+ Path
1516
1570
  >
1517
1571
  : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
1518
1572
  & NestedTargetMethod<
1519
1573
  Node,
1520
1574
  BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>,
1521
- BranchTargetResultWithPrefix<AllStates, Children, Path>
1575
+ BranchTargetResultWithPrefix<AllStates, Children, Path>,
1576
+ Path
1522
1577
  >
1523
1578
  & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>
1524
1579
  : NodeMethod<
@@ -1664,6 +1719,187 @@ export type RuntimeSnapshot<State, Error = never, Output = never> =
1664
1719
  readonly state: State
1665
1720
  }
1666
1721
 
1722
+ /**
1723
+ * Live, root-scoped records describing one prepared machine tree.
1724
+ *
1725
+ * Inspection records deliberately erase machine-specific values to `unknown`:
1726
+ * one stream may contain unrelated root, child-machine, and `Logic` protocols.
1727
+ * The record structure remains a closed discriminated union, while typed
1728
+ * application observation continues through `changes` and `emissions`.
1729
+ *
1730
+ * @category models
1731
+ * @since 0.13.0
1732
+ */
1733
+ export declare namespace Inspection {
1734
+ /** Read-only identity of a local machine endpoint. */
1735
+ export interface Endpoint {
1736
+ readonly id: string
1737
+ readonly sessionId: string
1738
+ }
1739
+
1740
+ /** Read-only identity of a runtime represented in the inspection tree. */
1741
+ export interface Subject extends Endpoint {
1742
+ readonly kind: "Machine" | "Logic"
1743
+ }
1744
+
1745
+ /** Causal origin of an inspected runtime. */
1746
+ export type Origin =
1747
+ | { readonly _tag: "Root" }
1748
+ | {
1749
+ readonly _tag: "Invoke"
1750
+ readonly ownerPath: string
1751
+ readonly invokeId: string
1752
+ }
1753
+ | {
1754
+ readonly _tag: "Spawn"
1755
+ readonly address: string | undefined
1756
+ }
1757
+
1758
+ /** Causal owner of a send or emission. */
1759
+ export type Causation =
1760
+ | { readonly _tag: "Initialization" }
1761
+ | { readonly _tag: "Macrostep"; readonly macrostepId: number }
1762
+ | { readonly _tag: "Activity"; readonly activitySessionId: string }
1763
+
1764
+ /** Closed command projection safe for observation. */
1765
+ export type Command =
1766
+ | {
1767
+ readonly _tag: "SendTo"
1768
+ readonly target: Endpoint | { readonly id: string }
1769
+ readonly event: unknown
1770
+ }
1771
+ | {
1772
+ readonly _tag: "Stop"
1773
+ readonly target: Endpoint | { readonly id: string }
1774
+ }
1775
+
1776
+ /** One statechart microstep in a committed macrostep. */
1777
+ export interface Microstep {
1778
+ readonly event: unknown
1779
+ readonly transitions: ReadonlyArray<Machine.RetainedTransition>
1780
+ readonly raisedEvents: ReadonlyArray<unknown>
1781
+ readonly emittedEvents: ReadonlyArray<unknown>
1782
+ readonly commands: ReadonlyArray<Command>
1783
+ readonly exitPaths: ReadonlyArray<string>
1784
+ readonly entryPaths: ReadonlyArray<string>
1785
+ readonly changed: boolean
1786
+ }
1787
+
1788
+ /** Common ordering and identity fields for every record. */
1789
+ export interface Base {
1790
+ /** Total publication order within this prepared root. */
1791
+ readonly sequence: number
1792
+ /** Session id of the prepared root that owns this inspection stream. */
1793
+ readonly rootSessionId: string
1794
+ /** Runtime instance described by this record. */
1795
+ readonly subject: Subject
1796
+ }
1797
+
1798
+ /** Announces allocation of a root or owned process identity. */
1799
+ export interface Created extends Base {
1800
+ readonly _tag: "Created"
1801
+ readonly parent: Subject | undefined
1802
+ readonly origin: Origin
1803
+ /** Compiled statechart definition; absent for generic `Logic`. */
1804
+ readonly definition: Machine.Any | undefined
1805
+ }
1806
+
1807
+ /** Announces successful initialization. */
1808
+ export interface Initialized extends Base {
1809
+ readonly _tag: "Initialized"
1810
+ readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown>
1811
+ readonly initialEntryPaths: ReadonlyArray<string>
1812
+ readonly microsteps: ReadonlyArray<Microstep>
1813
+ }
1814
+
1815
+ /** Announces failure before an initial runtime snapshot exists. */
1816
+ export interface StartFailed extends Base {
1817
+ readonly _tag: "StartFailed"
1818
+ readonly cause: Cause.Cause<unknown>
1819
+ }
1820
+
1821
+ /** Announces acceptance of an event by a local mailbox. */
1822
+ export interface EventSent extends Base {
1823
+ readonly _tag: "EventSent"
1824
+ readonly deliveryId: number
1825
+ readonly source: Subject | undefined
1826
+ readonly target: Endpoint
1827
+ readonly event: unknown
1828
+ readonly causedBy: Causation | undefined
1829
+ }
1830
+
1831
+ /** Announces complete processing of one statechart mailbox event. */
1832
+ export interface EventProcessed extends Base {
1833
+ readonly _tag: "EventProcessed"
1834
+ readonly macrostepId: number
1835
+ readonly deliveryId: number
1836
+ readonly source: Subject | undefined
1837
+ readonly event: unknown
1838
+ readonly before: RuntimeSnapshot<unknown, unknown, unknown>
1839
+ readonly after: RuntimeSnapshot<unknown, unknown, unknown>
1840
+ readonly handled: boolean
1841
+ readonly configurationChanged: boolean
1842
+ readonly microsteps: ReadonlyArray<Microstep>
1843
+ }
1844
+
1845
+ /** Announces a direct state update made by generic `Logic`. */
1846
+ export interface StateChanged extends Base {
1847
+ readonly _tag: "StateChanged"
1848
+ readonly before: unknown
1849
+ readonly after: unknown
1850
+ readonly causedByDeliveryId: number | undefined
1851
+ }
1852
+
1853
+ /** Announces actual publication on a machine's domain emission stream. */
1854
+ export interface Emitted extends Base {
1855
+ readonly _tag: "Emitted"
1856
+ readonly emission: unknown
1857
+ readonly causedBy: Causation | undefined
1858
+ }
1859
+
1860
+ /** Identity of one Effect or timer invocation run. */
1861
+ export interface Activity {
1862
+ readonly id: string
1863
+ readonly sessionId: string
1864
+ readonly owner: Subject
1865
+ readonly ownerPath: string
1866
+ readonly kind: "Effect" | "Timer"
1867
+ }
1868
+
1869
+ /** Announces an Effect or timer invocation starting. */
1870
+ export interface ActivityStarted extends Base {
1871
+ readonly _tag: "ActivityStarted"
1872
+ readonly activity: Activity
1873
+ }
1874
+
1875
+ /** Announces an Effect or timer invocation outcome. */
1876
+ export interface ActivityStopped extends Base {
1877
+ readonly _tag: "ActivityStopped"
1878
+ readonly activity: Activity
1879
+ /** Success or failure from the invoke; interruption means its owner stopped it. */
1880
+ readonly exit: Exit.Exit<unknown, unknown>
1881
+ }
1882
+
1883
+ /** Announces a terminal local runtime snapshot. */
1884
+ export interface Terminated extends Base {
1885
+ readonly _tag: "Terminated"
1886
+ readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown>
1887
+ }
1888
+
1889
+ /** Complete live inspection protocol. */
1890
+ export type Event =
1891
+ | Created
1892
+ | Initialized
1893
+ | StartFailed
1894
+ | EventSent
1895
+ | EventProcessed
1896
+ | StateChanged
1897
+ | Emitted
1898
+ | ActivityStarted
1899
+ | ActivityStopped
1900
+ | Terminated
1901
+ }
1902
+
1667
1903
  /**
1668
1904
  * Represents a classified terminal outcome derived from a runtime snapshot.
1669
1905
  *
@@ -1726,6 +1962,14 @@ export interface Prepared<out State, in Event, out Error, out Output, out Emitte
1726
1962
  /** Streams ephemeral notifications published after subscription. */
1727
1963
  readonly emissions: Stream.Stream<Emitted>
1728
1964
 
1965
+ /**
1966
+ * Streams ordered operational records for this root and every locally owned
1967
+ * descendant. The stream is hot, non-replayed, never fails, and completes
1968
+ * after the prepared root terminates. Subscribe before evaluating `start` to
1969
+ * observe initialization.
1970
+ */
1971
+ readonly inspection: Stream.Stream<Inspection.Event>
1972
+
1729
1973
  /** Initializes this machine once and returns its running reference. */
1730
1974
  readonly start: Effect.Effect<MachineRef<State, Event, Error, Output, Emitted>, StartError, StartRequirements>
1731
1975
  }
@@ -3843,6 +4087,23 @@ export declare namespace Machine {
3843
4087
  readonly parent: Extract<ParentPath<HistoryId>, StateIdentifier<States>>
3844
4088
  }
3845
4089
 
4090
+ /**
4091
+ * Transition instruction that enters a compound or parallel state through
4092
+ * its declared initial configuration.
4093
+ *
4094
+ * @category models
4095
+ * @since 0.13.0
4096
+ */
4097
+ export interface InitialTarget<StateId extends string> {
4098
+ readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId
4099
+ readonly [Topology.TargetSnapshotTypeId]?: never
4100
+ readonly [Topology.InitialTargetTypeId]: typeof Topology.InitialTargetTypeId
4101
+ readonly _tag: "InitialTarget"
4102
+ readonly path: StateId
4103
+ readonly value: never
4104
+ readonly values?: never
4105
+ }
4106
+
3846
4107
  /** Branded transient target instruction used while constructing initial states. */
3847
4108
  export interface ChoiceTargetInstruction<ChoiceId extends string = string> {
3848
4109
  readonly [Topology.ChoiceTargetTypeId]: typeof Topology.ChoiceTargetTypeId
@@ -3873,7 +4134,9 @@ export declare namespace Machine {
3873
4134
  * @category utility types
3874
4135
  * @since 0.4.0
3875
4136
  */
3876
- export type FullTargetBuilder<States extends StateSchemas> = FullSnapshotBuilderWithPrefix<States>
4137
+ export type FullTargetBuilder<States extends StateSchemas> = [InitialEntryStateKey<States>] extends [never] ?
4138
+ FullSnapshotBuilderWithPrefix<States>
4139
+ : FullSnapshotBuilderWithPrefix<States> & FullInitialTargetBuilder<States>
3877
4140
 
3878
4141
  /**
3879
4142
  * Builder for a complete fallback configuration containing a history owner.
@@ -4376,8 +4639,8 @@ export declare namespace Machine {
4376
4639
  ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never
4377
4640
  : never
4378
4641
  /** Extracts the return value from an implicit initial child implementation. */
4379
- export type StateInitialReturn<Config> = Config extends { readonly initial?: infer Initial }
4380
- ? NonNullable<Initial> extends (...args: any) => infer Ret ? Ret : never
4642
+ export type StateInitializeReturn<Config> = Config extends { readonly initialize?: infer Initialize }
4643
+ ? NonNullable<Initialize> extends (...args: any) => infer Ret ? Ret : never
4381
4644
  : never
4382
4645
  /** Extracts the return values from a state's history defaults. */
4383
4646
  export type HistoryDefaultReturn<Config> = Config extends { readonly history?: infer History } ? {
@@ -4434,6 +4697,8 @@ export declare namespace Machine {
4434
4697
  */
4435
4698
  export type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source
4436
4699
 
4700
+ type InvokeFactoryResult<Source> = Source extends (...args: any) => infer Resolved ? Resolved : never
4701
+
4437
4702
  type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<
4438
4703
  Snapshot<States<M>>,
4439
4704
  EventInput<InputEvent<M>>,
@@ -4455,7 +4720,7 @@ export declare namespace Machine {
4455
4720
  : never
4456
4721
 
4457
4722
  export type InvokeLogic<Invoke> = Invoke extends { readonly effect: infer Source } ?
4458
- InvokeResolvedSource<Source> extends infer Fx extends Effect.Effect<any, any, any> ? Logic<
4723
+ InvokeFactoryResult<Source> extends infer Fx extends Effect.Effect<any, any, any> ? Logic<
4459
4724
  void,
4460
4725
  never,
4461
4726
  Effect.Error<Fx>,
@@ -4600,7 +4865,6 @@ export declare namespace Machine {
4600
4865
  | Effect.Services<DoneReturn<Config>>
4601
4866
  | Effect.Services<StateActionReturn<Config, "entry">>
4602
4867
  | Effect.Services<StateActionReturn<Config, "exit">>
4603
- | Effect.Services<StateInitialReturn<Config>>
4604
4868
  | Effect.Services<HistoryDefaultReturn<Config>>
4605
4869
  | Effect.Services<ChoiceReturn<Config>>
4606
4870
  | InvokeRequirements<Config>
@@ -4611,12 +4875,12 @@ export declare namespace Machine {
4611
4875
  Emits extends ReadonlyArray<TaggedSchema>,
4612
4876
  Context
4613
4877
  > =
4614
- | ((context: Context, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>)
4878
+ | ((context: NoInfer<Context>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>)
4615
4879
  | {
4616
4880
  readonly reenter?: boolean
4617
4881
  readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>
4618
4882
  readonly transition: (
4619
- context: Context,
4883
+ context: NoInfer<Context>,
4620
4884
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
4621
4885
  ) => HandlerResult<States, any, any>
4622
4886
  }
@@ -4662,10 +4926,9 @@ export declare namespace Machine {
4662
4926
  & (
4663
4927
  | {
4664
4928
  readonly id: string
4665
- readonly effect: InvokeSource<
4666
- Effect.Effect<any, any, any>,
4667
- InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
4668
- >
4929
+ readonly effect: (
4930
+ context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
4931
+ ) => Effect.Effect<any, any, any>
4669
4932
  readonly after?: never
4670
4933
  readonly logic?: never
4671
4934
  readonly child?: never
@@ -4749,60 +5012,6 @@ export declare namespace Machine {
4749
5012
  : { readonly onFailure?: never }
4750
5013
  : never
4751
5014
 
4752
- export type EffectInvokeArgs<
4753
- States extends StateSchemas,
4754
- Events extends ReadonlyArray<TaggedSchema>,
4755
- Emits extends ReadonlyArray<TaggedSchema>,
4756
- StateId extends StateIdentifier<States>,
4757
- Fx extends Effect.Effect<any, any, any>,
4758
- Source = Fx,
4759
- InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4760
- ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4761
- > =
4762
- & {
4763
- readonly id: InvokeLifecycleId
4764
- readonly effect: Source
4765
- readonly after?: never
4766
- readonly logic?: never
4767
- readonly child?: never
4768
- readonly address?: never
4769
- readonly onSnapshot?: never
4770
- }
4771
- & InvokeDoneRequirement<
4772
- Effect.Success<NoInfer<Fx>>,
4773
- InvokeTransition<
4774
- States,
4775
- Events,
4776
- Emits,
4777
- InvokeDoneContext<
4778
- States,
4779
- Events,
4780
- Emits,
4781
- StateId,
4782
- Effect.Success<NoInfer<Fx>>,
4783
- InputEvents,
4784
- ParentEvents
4785
- >
4786
- >
4787
- >
4788
- & InvokeFailureRequirement<
4789
- Effect.Error<NoInfer<Fx>>,
4790
- InvokeTransition<
4791
- States,
4792
- Events,
4793
- Emits,
4794
- InvokeFailureContext<
4795
- States,
4796
- Events,
4797
- Emits,
4798
- StateId,
4799
- Effect.Error<NoInfer<Fx>>,
4800
- InputEvents,
4801
- ParentEvents
4802
- >
4803
- >
4804
- >
4805
-
4806
5015
  export type TimerInvokeArgs<
4807
5016
  States extends StateSchemas,
4808
5017
  Events extends ReadonlyArray<TaggedSchema>,
@@ -4988,7 +5197,7 @@ export declare namespace Machine {
4988
5197
  Raw
4989
5198
  > = Raw extends InvokeTyped<any, any, any, any, any> ? unknown
4990
5199
  : Raw extends { readonly effect: infer Source } ?
4991
- InvokeResolvedSource<Source> extends infer Fx extends Effect.Effect<any, any, any> ?
5200
+ InvokeFactoryResult<Source> extends infer Fx extends Effect.Effect<any, any, any> ?
4992
5201
  & InvokeDoneRequirement<
4993
5202
  Effect.Success<Fx>,
4994
5203
  InvokeTransition<
@@ -5255,11 +5464,16 @@ export declare namespace Machine {
5255
5464
  ) => HandlerResult<States, any, any>
5256
5465
  }
5257
5466
  }
5258
- readonly initial?: StateInitialHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>
5467
+ readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>
5259
5468
  } & ActiveOutputHandlerConfig<States, Events, StateId>
5260
5469
 
5261
- /** Values supplied when a statechart implicitly enters a state's initial children. */
5262
- export type StateInitialValue<
5470
+ /**
5471
+ * Values constructed for a state's schema-valued direct initial children.
5472
+ *
5473
+ * @category utility types
5474
+ * @since 0.13.0
5475
+ */
5476
+ export type StateInitializeValue<
5263
5477
  States extends StateSchemas,
5264
5478
  StateId extends StateIdentifier<States>
5265
5479
  > = NodeByIdentifier<States, StateId> extends infer Node ?
@@ -5270,23 +5484,92 @@ export declare namespace Machine {
5270
5484
  }
5271
5485
  : Node extends { readonly states: infer Children extends StateSchemas; readonly initial: infer Initial } ?
5272
5486
  Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never
5273
- : NodeValue<Children[Initial]>
5487
+ : { readonly [Key in Initial]: NodeValue<Children[Initial]> }
5274
5488
  : never
5275
5489
  : never
5276
5490
  : never
5277
5491
 
5278
- /** Context passed to an implicit child-state initializer. */
5279
- export type StateInitialContext<
5492
+ type StateInitializeCompoundBuilder<Node, Initial extends PropertyKey> = Node extends {
5493
+ readonly states: infer Children extends StateSchemas
5494
+ } ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never
5495
+ : NodeBuilderMethod<
5496
+ Children[Initial],
5497
+ readonly [value: NodeValue<Children[Initial]>],
5498
+ SnapshotBuilderComplete<{ readonly [Key in Initial]: NodeValue<Children[Initial]> }>,
5499
+ readonly [input: NodeMakeInput<Children[Initial]>],
5500
+ SnapshotBuilderComplete<{ readonly [Key in Initial]: NodeValue<Children[Initial]> }, true>
5501
+ >
5502
+ : never
5503
+ : never
5504
+
5505
+ type StateInitializeParallelBuilder<
5506
+ Children extends StateSchemas,
5507
+ Remaining extends ActiveStateKey<Children> = {
5508
+ readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]> extends never ? never : Key
5509
+ }[ActiveStateKey<Children>],
5510
+ Values = {},
5511
+ Constructed extends boolean = false
5512
+ > =
5513
+ & SnapshotBuilderComplete<Values, Constructed>
5514
+ & {
5515
+ readonly [Key in Remaining]: NodeBuilderMethod<
5516
+ Children[Key],
5517
+ readonly [value: NodeValue<Children[Key]>],
5518
+ StateInitializeParallelBuilder<
5519
+ Children,
5520
+ Exclude<Remaining, Key>,
5521
+ Values & { readonly [Region in Key]: NodeValue<Children[Key]> },
5522
+ Constructed
5523
+ >,
5524
+ readonly [input: NodeMakeInput<Children[Key]>],
5525
+ StateInitializeParallelBuilder<
5526
+ Children,
5527
+ Exclude<Remaining, Key>,
5528
+ Values & { readonly [Region in Key]: NodeValue<Children[Key]> },
5529
+ true
5530
+ >
5531
+ >
5532
+ }
5533
+
5534
+ /**
5535
+ * Builder bound to the direct initial child or regions owned by a state.
5536
+ *
5537
+ * @category utility types
5538
+ * @since 0.13.0
5539
+ */
5540
+ export type StateInitializeBuilder<
5541
+ States extends StateSchemas,
5542
+ StateId extends StateIdentifier<States>,
5543
+ Node = NodeByIdentifier<States, StateId>
5544
+ > = Node extends { readonly type: "parallel"; readonly states: infer Children extends StateSchemas } ?
5545
+ StateInitializeParallelBuilder<Children>
5546
+ : Node extends { readonly initial: infer Initial } ? StateInitializeCompoundBuilder<Node, Initial & PropertyKey>
5547
+ : never
5548
+
5549
+ /**
5550
+ * Context passed to an implicit child-state initializer.
5551
+ *
5552
+ * @category models
5553
+ * @since 0.13.0
5554
+ */
5555
+ export type StateInitializeContext<
5280
5556
  States extends StateSchemas,
5281
5557
  Events extends ReadonlyArray<TaggedSchema>,
5282
5558
  Emits extends ReadonlyArray<TaggedSchema>,
5283
5559
  StateId extends StateIdentifier<States>,
5284
5560
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5285
5561
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
5286
- > = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
5562
+ > = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
5563
+ readonly builder: StateInitializeBuilder<States, StateId>
5564
+ }
5287
5565
 
5288
- /** Initial child value implementation for a compound or parallel state. */
5289
- export type StateInitialHandler<
5566
+ /**
5567
+ * Initial child value implementation for a compound or parallel state.
5568
+ *
5569
+ * @category models
5570
+ * @since 0.13.0
5571
+ */
5572
+ export type StateInitializeHandler<
5290
5573
  States extends StateSchemas,
5291
5574
  Events extends ReadonlyArray<TaggedSchema>,
5292
5575
  Emits extends ReadonlyArray<TaggedSchema>,
@@ -5294,9 +5577,9 @@ export declare namespace Machine {
5294
5577
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5295
5578
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
5296
5579
  > = (
5297
- context: StateInitialContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
5580
+ context: StateInitializeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
5298
5581
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
5299
- ) => StateInitialValue<States, StateId>
5582
+ ) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>
5300
5583
 
5301
5584
  /** Context used only when a history node has no previously captured record. */
5302
5585
  export interface HistoryDefaultContext<
@@ -5366,7 +5649,7 @@ export declare namespace Machine {
5366
5649
  readonly on?: never
5367
5650
  readonly onDone?: never
5368
5651
  readonly output?: never
5369
- readonly initial?: never
5652
+ readonly initialize?: never
5370
5653
  }
5371
5654
 
5372
5655
  /**
@@ -5589,7 +5872,7 @@ export declare namespace Machine {
5589
5872
  | "entry"
5590
5873
  | "exit"
5591
5874
  | "history"
5592
- | "initial"
5875
+ | "initialize"
5593
5876
  | "invoke"
5594
5877
  | "on"
5595
5878
  | "onDone"
@@ -5702,6 +5985,75 @@ export declare namespace Machine {
5702
5985
  : Result extends { readonly path: infer Path extends string } ? Path
5703
5986
  : never
5704
5987
 
5988
+ type TransitionResultInitialTargetPath<Result> = IsAny<Result> extends true ? never
5989
+ : Result extends Effect.Effect<infer Success, any, any> ? TransitionResultInitialTargetPath<Success>
5990
+ : Result extends StateConstruction<infer Constructed> ? TransitionResultInitialTargetPath<Constructed>
5991
+ : Result extends {
5992
+ readonly [Topology.InitialTargetTypeId]: typeof Topology.InitialTargetTypeId
5993
+ readonly _tag: "InitialTarget"
5994
+ } ? Result extends { readonly path: infer Path extends string } ? Path : never
5995
+ : never
5996
+
5997
+ type HandlerConfigInitialTargetPath<Config> = TransitionResultInitialTargetPath<
5998
+ | EventHandlerReturn<Config>
5999
+ | AlwaysReturn<Config>
6000
+ | DoneReturn<Config>
6001
+ | ChoiceReturn<Config>
6002
+ | InvokeOutcomeReturn<InvokeReturn<Config>>
6003
+ >
6004
+
6005
+ type RequiredInitializersForTargetPath<
6006
+ AllStates extends StateSchemas,
6007
+ Path
6008
+ > = string extends Path ? never : Path extends StateIdentifier<AllStates> ? InitializerClosureForNode<
6009
+ AllStates,
6010
+ NodeByIdentifier<AllStates, Path>,
6011
+ Path
6012
+ >
6013
+ : never
6014
+
6015
+ type HandlerInitializeValidationAtPath<Config, Path extends string> = HandlerConfigAtPath<Config, Path> extends
6016
+ infer StateConfig ? [StateConfig] extends [never] ? HandlerValidationAtPath<Path, {
6017
+ readonly initialize: HandlerValidationError<
6018
+ "State requires initialize because a transition enters its declared initial configuration",
6019
+ Path
6020
+ >
6021
+ }>
6022
+ : "initialize" extends keyof StateConfig ? never
6023
+ : HandlerValidationAtPath<Path, {
6024
+ readonly initialize: HandlerValidationError<
6025
+ "State requires initialize because a transition enters its declared initial configuration",
6026
+ Path
6027
+ >
6028
+ }>
6029
+ : never
6030
+
6031
+ type HandlerInitialTargetValidationForPaths<
6032
+ AllStates extends StateSchemas,
6033
+ Config,
6034
+ Required
6035
+ > = Types.UnionToIntersection<
6036
+ Required extends string ? HandlerInitializeValidationAtPath<Config, Required> : unknown
6037
+ >
6038
+
6039
+ type HandlerTreeInitialTargetPath<Config> = string extends keyof Config ? never
6040
+ : Config extends object ? {
6041
+ readonly [Key in keyof Config]:
6042
+ | HandlerConfigInitialTargetPath<HandlerConfigPart<Config[Key]>>
6043
+ | (Config[Key] extends { readonly states: infer Children } ? HandlerTreeInitialTargetPath<Children> : never)
6044
+ }[keyof Config]
6045
+ : never
6046
+
6047
+ type HandlerInitialTargetValidation<
6048
+ AllStates extends StateSchemas,
6049
+ Config
6050
+ > = HandlerTreeInitialTargetPath<Config> extends infer TargetPath ? HandlerInitialTargetValidationForPaths<
6051
+ AllStates,
6052
+ Config,
6053
+ RequiredInitializersForTargetPath<AllStates, TargetPath>
6054
+ >
6055
+ : unknown
6056
+
5705
6057
  type DeclaredTransitionTarget<Transition> = Transition extends {
5706
6058
  readonly targets: infer Targets extends ReadonlyArray<string>
5707
6059
  } ? Targets[number]
@@ -5809,6 +6161,19 @@ export declare namespace Machine {
5809
6161
  : unknown
5810
6162
  : unknown)
5811
6163
 
6164
+ type HandlerRequiredHistoryInitializeValidation<
6165
+ AllStates extends StateSchemas,
6166
+ StateId extends StateIdentifier<AllStates>,
6167
+ Config
6168
+ > = [HistoryIdentifier<AllStates>] extends [never] ? unknown
6169
+ : StateId extends RequiredHistoryInitializers<AllStates> ? "initialize" extends keyof Config ? unknown : {
6170
+ readonly initialize: HandlerValidationError<
6171
+ "State requires initialize for shallow history restoration",
6172
+ StateId
6173
+ >
6174
+ }
6175
+ : unknown
6176
+
5812
6177
  type HandlerNodeValidation<
5813
6178
  AllStates extends StateSchemas,
5814
6179
  Node,
@@ -5831,6 +6196,7 @@ export declare namespace Machine {
5831
6196
  & HandlerInvokeParentEventsValidation<InputEvents, StateId, Config>
5832
6197
  & HandlerChildrenValidation<Node, StateId, Config>
5833
6198
  & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config>
6199
+ & HandlerRequiredHistoryInitializeValidation<AllStates, StateId, Config>
5834
6200
  & HandlerRuntimeValidation<Events, Emits, StateId, Config>
5835
6201
  : unknown
5836
6202
 
@@ -5944,7 +6310,7 @@ export declare namespace Machine {
5944
6310
  AllStates extends StateSchemas,
5945
6311
  StateId extends StateIdentifier<AllStates>,
5946
6312
  Config
5947
- > = StateId extends RequiredHistoryInitializers<AllStates> ? "initial" extends keyof Config ? true : false : true
6313
+ > = StateId extends RequiredHistoryInitializers<AllStates> ? "initialize" extends keyof Config ? true : false : true
5948
6314
 
5949
6315
  type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
5950
6316
  readonly states: infer Children extends StateSchemas
@@ -5984,7 +6350,6 @@ export declare namespace Machine {
5984
6350
  | Effect.Error<DoneReturn<Config>>
5985
6351
  | Effect.Error<StateActionReturn<Config, "entry">>
5986
6352
  | Effect.Error<StateActionReturn<Config, "exit">>
5987
- | Effect.Error<StateInitialReturn<Config>>
5988
6353
  | Effect.Error<HistoryDefaultReturn<Config>>
5989
6354
  | Effect.Error<ChoiceReturn<Config>>
5990
6355
  | InvokeError<Config>
@@ -6107,6 +6472,11 @@ export declare namespace Machine {
6107
6472
  StateIdentifier<States>
6108
6473
  >
6109
6474
  >
6475
+ & ([StateIdentifier<States>] extends [UnhandledStates] ? HandlerInitialTargetValidation<
6476
+ States,
6477
+ NoInfer<Config>
6478
+ >
6479
+ : unknown)
6110
6480
  ): HandleTreeResult<
6111
6481
  States,
6112
6482
  Events,
@@ -6728,7 +7098,7 @@ export const decodeSnapshot: <
6728
7098
  Machine.SnapshotDecodingServices<States>
6729
7099
  > = internal.decodeSnapshot as any
6730
7100
 
6731
- type DynamicEffectInvokeSource<
7101
+ type EffectInvokeSource<
6732
7102
  States extends Machine.StateSchemas,
6733
7103
  Events extends ReadonlyArray<Machine.TaggedSchema>,
6734
7104
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
@@ -6746,7 +7116,7 @@ type DynamicEffectInvokeSource<
6746
7116
  readonly onSnapshot?: never
6747
7117
  }
6748
7118
 
6749
- type DynamicEffectDoneHandler<
7119
+ type EffectDoneHandler<
6750
7120
  States extends Machine.StateSchemas,
6751
7121
  Events extends ReadonlyArray<Machine.TaggedSchema>,
6752
7122
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
@@ -6767,7 +7137,7 @@ type DynamicEffectDoneHandler<
6767
7137
  >
6768
7138
  >
6769
7139
 
6770
- type DynamicEffectFailureHandler<
7140
+ type EffectFailureHandler<
6771
7141
  States extends Machine.StateSchemas,
6772
7142
  Events extends ReadonlyArray<Machine.TaggedSchema>,
6773
7143
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
@@ -6788,7 +7158,7 @@ type DynamicEffectFailureHandler<
6788
7158
  >
6789
7159
  >
6790
7160
 
6791
- type DynamicEffectInvokeResult<
7161
+ type EffectInvokeResult<
6792
7162
  States extends Machine.StateSchemas,
6793
7163
  Events extends ReadonlyArray<Machine.TaggedSchema>,
6794
7164
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
@@ -6805,7 +7175,7 @@ type DynamicEffectInvokeResult<
6805
7175
 
6806
7176
  type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false
6807
7177
 
6808
- type BoundDynamicEffectInvokeSource<
7178
+ type BoundEffectInvokeSource<
6809
7179
  States extends Machine.StateSchemas,
6810
7180
  Events extends ReadonlyArray<Machine.TaggedSchema>,
6811
7181
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
@@ -6825,7 +7195,7 @@ type BoundDynamicEffectInvokeSource<
6825
7195
  readonly onSnapshot?: never
6826
7196
  }
6827
7197
 
6828
- type BoundDynamicEffectDoneHandler<
7198
+ type BoundEffectDoneHandler<
6829
7199
  States extends Machine.StateSchemas,
6830
7200
  Events extends ReadonlyArray<Machine.TaggedSchema>,
6831
7201
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
@@ -6848,7 +7218,7 @@ type BoundDynamicEffectDoneHandler<
6848
7218
  >
6849
7219
  >
6850
7220
 
6851
- type BoundDynamicEffectFailureHandler<
7221
+ type BoundEffectFailureHandler<
6852
7222
  States extends Machine.StateSchemas,
6853
7223
  Events extends ReadonlyArray<Machine.TaggedSchema>,
6854
7224
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
@@ -6871,7 +7241,7 @@ type BoundDynamicEffectFailureHandler<
6871
7241
  >
6872
7242
  >
6873
7243
 
6874
- type BoundDynamicEffectInvokeResult<
7244
+ type BoundEffectInvokeResult<
6875
7245
  States extends Machine.StateSchemas,
6876
7246
  Events extends ReadonlyArray<Machine.TaggedSchema>,
6877
7247
  Emits extends ReadonlyArray<Machine.TaggedSchema>,
@@ -6909,9 +7279,9 @@ export interface Invoker<
6909
7279
  ) => Effect.Effect<unknown, unknown, unknown>
6910
7280
  >(
6911
7281
  config:
6912
- & BoundDynamicEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7282
+ & BoundEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6913
7283
  & {
6914
- readonly onDone: BoundDynamicEffectDoneHandler<
7284
+ readonly onDone: BoundEffectDoneHandler<
6915
7285
  States,
6916
7286
  Events,
6917
7287
  Emits,
@@ -6920,7 +7290,7 @@ export interface Invoker<
6920
7290
  StateId,
6921
7291
  Source
6922
7292
  >
6923
- readonly onFailure: BoundDynamicEffectFailureHandler<
7293
+ readonly onFailure: BoundEffectFailureHandler<
6924
7294
  States,
6925
7295
  Events,
6926
7296
  Emits,
@@ -6937,7 +7307,7 @@ export interface Invoker<
6937
7307
  "onFailure must be omitted when the Effect error is never"
6938
7308
  ]
6939
7309
  : []
6940
- ): BoundDynamicEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7310
+ ): BoundEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6941
7311
  <
6942
7312
  StateId extends Machine.StateIdentifier<States>,
6943
7313
  const Source extends (
@@ -6945,9 +7315,9 @@ export interface Invoker<
6945
7315
  ) => Effect.Effect<unknown, never, unknown>
6946
7316
  >(
6947
7317
  config:
6948
- & BoundDynamicEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7318
+ & BoundEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6949
7319
  & {
6950
- readonly onDone: BoundDynamicEffectDoneHandler<
7320
+ readonly onDone: BoundEffectDoneHandler<
6951
7321
  States,
6952
7322
  Events,
6953
7323
  Emits,
@@ -6962,7 +7332,7 @@ export interface Invoker<
6962
7332
  "onDone must be omitted when the Effect output is never"
6963
7333
  ]
6964
7334
  : []
6965
- ): BoundDynamicEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7335
+ ): BoundEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6966
7336
  <
6967
7337
  StateId extends Machine.StateIdentifier<States>,
6968
7338
  const Source extends (
@@ -6970,10 +7340,10 @@ export interface Invoker<
6970
7340
  ) => Effect.Effect<never, unknown, unknown>
6971
7341
  >(
6972
7342
  config:
6973
- & BoundDynamicEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7343
+ & BoundEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6974
7344
  & {
6975
7345
  readonly onDone?: never
6976
- readonly onFailure: BoundDynamicEffectFailureHandler<
7346
+ readonly onFailure: BoundEffectFailureHandler<
6977
7347
  States,
6978
7348
  Events,
6979
7349
  Emits,
@@ -6987,7 +7357,7 @@ export interface Invoker<
6987
7357
  "onFailure must be omitted when the Effect error is never"
6988
7358
  ]
6989
7359
  : []
6990
- ): BoundDynamicEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7360
+ ): BoundEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6991
7361
  <
6992
7362
  StateId extends Machine.StateIdentifier<States>,
6993
7363
  const Source extends (
@@ -6995,33 +7365,12 @@ export interface Invoker<
6995
7365
  ) => Effect.Effect<never, never, unknown>
6996
7366
  >(
6997
7367
  config:
6998
- & BoundDynamicEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7368
+ & BoundEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
6999
7369
  & {
7000
7370
  readonly onDone?: never
7001
7371
  readonly onFailure?: never
7002
7372
  }
7003
- ): BoundDynamicEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7004
- <
7005
- StateId extends Machine.StateIdentifier<States>,
7006
- const Fx extends Effect.Effect<any, any, any>,
7007
- const Config extends object
7008
- >(
7009
- config:
7010
- & Config
7011
- & Machine.EffectInvokeArgs<
7012
- States,
7013
- Events,
7014
- Emits,
7015
- StateId,
7016
- Fx,
7017
- Fx,
7018
- InputEvents,
7019
- ParentEvents
7020
- >
7021
- ):
7022
- & Config
7023
- & Machine.InvokeOwned<States, Events, Emits, StateId>
7024
- & Machine.InvokeTyped<Effect.Success<Fx>, Effect.Error<Fx>, Effect.Services<Fx>, never>
7373
+ ): BoundEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
7025
7374
  <StateId extends Machine.StateIdentifier<States>, const Config extends object>(
7026
7375
  config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, InputEvents, ParentEvents>
7027
7376
  ): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>
@@ -7133,12 +7482,13 @@ export interface Invoker<
7133
7482
  * is required only when the source has a typed failure channel.
7134
7483
  *
7135
7484
  * This constructor is an identity at runtime, but preserves lifecycle callback
7136
- * inference through published declarations. Effects and durations may be
7137
- * supplied directly or derived from the owning state's entry context. Dynamic
7138
- * Effect sources infer the owner context, output, error, and service channels
7139
- * together without a return annotation. Logic invocations require both a
7140
- * lifecycle `id` and a typed communication `address`. Child descriptors already
7141
- * own their identity, so `id` and `address` must not be repeated.
7485
+ * inference through published declarations. Effect factories run when their
7486
+ * owning state is entered and infer the owner context, output, error, and
7487
+ * service channels together without a return annotation. Durations may be
7488
+ * supplied directly or derived from the owning state's entry context. Logic
7489
+ * invocations require both a lifecycle `id` and a typed communication
7490
+ * `address`. Child descriptors already own their identity, so `id` and
7491
+ * `address` must not be repeated.
7142
7492
  *
7143
7493
  * Owner references are intentionally non-sendable here because this standalone
7144
7494
  * constructor does not know the owning definition. When a callback sends to
@@ -7149,10 +7499,11 @@ export interface Invoker<
7149
7499
  * ```ts
7150
7500
  * invoke: Machine.invoke({
7151
7501
  * id: "load",
7152
- * effect: Effect.tryPromise({
7153
- * try: () => fetch("/api/data").then((response) => response.json()),
7154
- * catch: (cause) => new LoadError({ cause })
7155
- * }),
7502
+ * effect: () =>
7503
+ * Effect.tryPromise({
7504
+ * try: () => fetch("/api/data").then((response) => response.json()),
7505
+ * catch: (cause) => new LoadError({ cause })
7506
+ * }),
7156
7507
  * onDone: ({ output, target }) => target.full.Ready({ data: output }),
7157
7508
  * onFailure: ({ error, target }) => target.full.Failed({ error })
7158
7509
  * })
@@ -7172,10 +7523,10 @@ export const invoke: {
7172
7523
  ) => Effect.Effect<unknown, unknown, unknown>
7173
7524
  >(
7174
7525
  config:
7175
- & DynamicEffectInvokeSource<States, Events, Emits, StateId, Source>
7526
+ & EffectInvokeSource<States, Events, Emits, StateId, Source>
7176
7527
  & {
7177
- readonly onDone: DynamicEffectDoneHandler<States, Events, Emits, StateId, Source>
7178
- readonly onFailure: DynamicEffectFailureHandler<States, Events, Emits, StateId, Source>
7528
+ readonly onDone: EffectDoneHandler<States, Events, Emits, StateId, Source>
7529
+ readonly onFailure: EffectFailureHandler<States, Events, Emits, StateId, Source>
7179
7530
  },
7180
7531
  ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
7181
7532
  "onDone must be omitted when the Effect output is never"
@@ -7184,7 +7535,7 @@ export const invoke: {
7184
7535
  "onFailure must be omitted when the Effect error is never"
7185
7536
  ]
7186
7537
  : []
7187
- ): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>
7538
+ ): EffectInvokeResult<States, Events, Emits, StateId, Source>
7188
7539
  <
7189
7540
  const States extends Machine.StateSchemas,
7190
7541
  const Events extends ReadonlyArray<Machine.TaggedSchema>,
@@ -7195,16 +7546,16 @@ export const invoke: {
7195
7546
  ) => Effect.Effect<unknown, never, unknown>
7196
7547
  >(
7197
7548
  config:
7198
- & DynamicEffectInvokeSource<States, Events, Emits, StateId, Source>
7549
+ & EffectInvokeSource<States, Events, Emits, StateId, Source>
7199
7550
  & {
7200
- readonly onDone: DynamicEffectDoneHandler<States, Events, Emits, StateId, Source>
7551
+ readonly onDone: EffectDoneHandler<States, Events, Emits, StateId, Source>
7201
7552
  readonly onFailure?: never
7202
7553
  },
7203
7554
  ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
7204
7555
  "onDone must be omitted when the Effect output is never"
7205
7556
  ]
7206
7557
  : []
7207
- ): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>
7558
+ ): EffectInvokeResult<States, Events, Emits, StateId, Source>
7208
7559
  <
7209
7560
  const States extends Machine.StateSchemas,
7210
7561
  const Events extends ReadonlyArray<Machine.TaggedSchema>,
@@ -7215,16 +7566,16 @@ export const invoke: {
7215
7566
  ) => Effect.Effect<never, unknown, unknown>
7216
7567
  >(
7217
7568
  config:
7218
- & DynamicEffectInvokeSource<States, Events, Emits, StateId, Source>
7569
+ & EffectInvokeSource<States, Events, Emits, StateId, Source>
7219
7570
  & {
7220
7571
  readonly onDone?: never
7221
- readonly onFailure: DynamicEffectFailureHandler<States, Events, Emits, StateId, Source>
7572
+ readonly onFailure: EffectFailureHandler<States, Events, Emits, StateId, Source>
7222
7573
  },
7223
7574
  ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
7224
7575
  "onFailure must be omitted when the Effect error is never"
7225
7576
  ]
7226
7577
  : []
7227
- ): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>
7578
+ ): EffectInvokeResult<States, Events, Emits, StateId, Source>
7228
7579
  <
7229
7580
  const States extends Machine.StateSchemas,
7230
7581
  const Events extends ReadonlyArray<Machine.TaggedSchema>,
@@ -7235,32 +7586,12 @@ export const invoke: {
7235
7586
  ) => Effect.Effect<never, never, unknown>
7236
7587
  >(
7237
7588
  config:
7238
- & DynamicEffectInvokeSource<States, Events, Emits, StateId, Source>
7589
+ & EffectInvokeSource<States, Events, Emits, StateId, Source>
7239
7590
  & {
7240
7591
  readonly onDone?: never
7241
7592
  readonly onFailure?: never
7242
7593
  }
7243
- ): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>
7244
- <
7245
- const States extends Machine.StateSchemas,
7246
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
7247
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
7248
- StateId extends Machine.StateIdentifier<States>,
7249
- const Fx extends Effect.Effect<any, any, any>,
7250
- const Config extends object
7251
- >(
7252
- config:
7253
- & Config
7254
- & Machine.EffectInvokeArgs<States, Events, Emits, StateId, Fx, Fx, readonly [], readonly []>
7255
- ):
7256
- & Config
7257
- & Machine.InvokeOwned<States, Events, Emits, StateId>
7258
- & Machine.InvokeTyped<
7259
- Effect.Success<Fx>,
7260
- Effect.Error<Fx>,
7261
- Effect.Services<Fx>,
7262
- never
7263
- >
7594
+ ): EffectInvokeResult<States, Events, Emits, StateId, Source>
7264
7595
  <
7265
7596
  const States extends Machine.StateSchemas,
7266
7597
  const Events extends ReadonlyArray<Machine.TaggedSchema>,