@typeonce/effect-machine 0.17.0 → 0.19.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 (45) hide show
  1. package/README.md +133 -80
  2. package/dist/Machine.d.ts +434 -297
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +13 -55
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/cluster.d.ts +2 -2
  7. package/dist/internal/machine/cluster.d.ts.map +1 -1
  8. package/dist/internal/machine/cluster.js +2 -1
  9. package/dist/internal/machine/cluster.js.map +1 -1
  10. package/dist/internal/machine/invocation.d.ts.map +1 -1
  11. package/dist/internal/machine/invocation.js +1 -1
  12. package/dist/internal/machine/invocation.js.map +1 -1
  13. package/dist/internal/machine/machine.d.ts.map +1 -1
  14. package/dist/internal/machine/machine.js +48 -10
  15. package/dist/internal/machine/machine.js.map +1 -1
  16. package/dist/internal/machine/serialization.d.ts.map +1 -1
  17. package/dist/internal/machine/serialization.js +75 -18
  18. package/dist/internal/machine/serialization.js.map +1 -1
  19. package/dist/internal/testing/machine/verification.d.ts +1 -1
  20. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  21. package/dist/internal/testing/machine/verification.js +9 -6
  22. package/dist/internal/testing/machine/verification.js.map +1 -1
  23. package/dist/testing/MachineTest.d.ts +13 -10
  24. package/dist/testing/MachineTest.d.ts.map +1 -1
  25. package/dist/testing/MachineTest.js +5 -3
  26. package/dist/testing/MachineTest.js.map +1 -1
  27. package/dist/unstable/cluster/ClusterMachine.d.ts +22 -2
  28. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
  29. package/dist/unstable/cluster/ClusterMachine.js +4 -0
  30. package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
  31. package/dist/unstable/reactivity/AtomMachine.d.ts +1 -1
  32. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  33. package/docs/agent-guide.md +189 -83
  34. package/package.json +4 -4
  35. package/src/Machine.ts +845 -1051
  36. package/src/internal/machine/cluster.ts +4 -1
  37. package/src/internal/machine/invocation.ts +1 -1
  38. package/src/internal/machine/machine.ts +64 -8
  39. package/src/internal/machine/serialization.ts +100 -25
  40. package/src/internal/testing/machine/exploration.ts +1 -1
  41. package/src/internal/testing/machine/trace.ts +1 -1
  42. package/src/internal/testing/machine/verification.ts +16 -11
  43. package/src/testing/MachineTest.ts +13 -10
  44. package/src/unstable/cluster/ClusterMachine.ts +51 -1
  45. package/src/unstable/reactivity/AtomMachine.ts +1 -1
package/src/Machine.ts CHANGED
@@ -278,6 +278,20 @@ export interface Definition<
278
278
  * captured by value, so later mutation of the supplied objects cannot alter
279
279
  * the resulting machine.
280
280
  *
281
+ * **Example**
282
+ *
283
+ * ```ts
284
+ * const counter = definition.handle({
285
+ * Count: {
286
+ * on: {
287
+ * Increment: (to) =>
288
+ * to.full.Count().resolve(({ event, state, target }) =>
289
+ * target(new Count({ value: state.value + event.by })))
290
+ * }
291
+ * }
292
+ * })
293
+ * ```
294
+ *
281
295
  * @since 0.4.0
282
296
  */
283
297
  readonly handle: Machine.Handler<
@@ -523,8 +537,10 @@ export type MachineReferences<
523
537
 
524
538
  /**
525
539
  * Synchronous commands available while a machine transition is being
526
- * selected. Enqueuing only records statechart and machine operations; it never
527
- * executes an Effect.
540
+ * selected.
541
+ *
542
+ * Enqueuing records statechart and machine operations for the selected
543
+ * transition. It never executes an Effect while the transition is evaluated.
528
544
  *
529
545
  * @category models
530
546
  * @since 0.4.0
@@ -634,6 +650,7 @@ type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Run
634
650
  const InvokeTypeId: typeof internal.InvokeTypeId = internal.InvokeTypeId
635
651
  const TransitionTypeId: typeof internal.TransitionTypeId = internal.TransitionTypeId
636
652
  declare const TransitionBuilderTypeId: unique symbol
653
+ declare const InvokeBuilderTypeId: unique symbol
637
654
  declare const InitialBuilderTypeId: unique symbol
638
655
 
639
656
  type StateDefinitionError<
@@ -1877,6 +1894,9 @@ export type RuntimeSnapshot<State, Error = never, Output = never> =
1877
1894
  * one stream may contain unrelated root, child-machine, and `Logic` protocols.
1878
1895
  * The record structure remains a closed discriminated union, while typed
1879
1896
  * application observation continues through `changes` and `emissions`.
1897
+ * Records retain decoded local events and snapshots and are not themselves a
1898
+ * stable JSON export format. Telemetry exporters must project process-local
1899
+ * values into an explicit portable representation.
1880
1900
  *
1881
1901
  * @category models
1882
1902
  * @since 0.13.0
@@ -2192,7 +2212,7 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
2192
2212
  }
2193
2213
 
2194
2214
  /**
2195
- * Machine-specific process logic used by `spawn` and `invoke`.
2215
+ * Machine-specific process logic used by `spawn` and state-owned invocations.
2196
2216
  *
2197
2217
  * @category models
2198
2218
  * @since 0.4.0
@@ -2608,12 +2628,26 @@ export declare namespace Machine {
2608
2628
  export type Events<M extends Any> = M[typeof MachineTypeId]["events"]
2609
2629
 
2610
2630
  /**
2611
- * Extracts the input schema carried by a machine definition.
2631
+ * Extracts the startup input schema carried by a machine definition.
2612
2632
  *
2613
2633
  * @category utility types
2614
- * @since 0.4.0
2634
+ * @since 0.18.0
2635
+ */
2636
+ export type InputSchema<M extends Any> = M[typeof MachineTypeId]["input"]
2637
+
2638
+ /**
2639
+ * Extracts the decoded startup input accepted by a machine definition.
2640
+ *
2641
+ * Machines declared with `Schema.Void` do not accept a startup input, so
2642
+ * their extracted input type is `never`.
2643
+ *
2644
+ * @category utility types
2645
+ * @since 0.18.0
2615
2646
  */
2616
- export type Input<M extends Any> = M[typeof MachineTypeId]["input"]
2647
+ export type Input<M extends Any> = InputSchema<M> extends infer Input extends Schema.Top
2648
+ ? Input extends typeof Schema.Void ? never
2649
+ : Input["Type"]
2650
+ : never
2617
2651
 
2618
2652
  /**
2619
2653
  * Extracts state paths that do not yet have handlers.
@@ -2897,8 +2931,11 @@ export declare namespace Machine {
2897
2931
  * @since 0.4.0
2898
2932
  */
2899
2933
  export interface StateNodeAnnotations extends Schema.Annotations.Annotations {
2934
+ /** Human-readable label used by visualization and documentation tooling. */
2900
2935
  readonly title?: string | undefined
2936
+ /** Short explanation of the state node's domain meaning. */
2901
2937
  readonly description?: string | undefined
2938
+ /** Longer documentation text associated with the state node. */
2902
2939
  readonly documentation?: string | undefined
2903
2940
  }
2904
2941
 
@@ -2912,22 +2949,29 @@ export declare namespace Machine {
2912
2949
  export type PseudoStateAnnotations = SchemaLessStateAnnotations
2913
2950
 
2914
2951
  /**
2915
- * Configuration accepted for an atomic object state node. Omit `schema` when
2916
- * the state owns no value; a schema-less final may still declare `output`.
2952
+ * Configuration accepted for an atomic object state node.
2953
+ *
2954
+ * Omit `schema` when the state owns no value. A schema-less final may still
2955
+ * declare `output`.
2917
2956
  *
2918
2957
  * @category models
2919
2958
  * @since 0.4.0
2920
2959
  */
2921
2960
  export type AtomicStateNodeConfig =
2922
2961
  | {
2962
+ /** Tagged schema that owns the state's decoded value. */
2923
2963
  readonly schema: TaggedSchema
2964
+ /** Declares an ordinary active state. Omitted values default to `"active"`. */
2924
2965
  readonly type?: "active"
2966
+ /** Atomic active states cannot declare terminal output. */
2925
2967
  readonly output?: never
2968
+ /** Schema-backed states take their annotations from the schema. */
2926
2969
  readonly annotations?: never
2927
2970
  }
2928
2971
  | {
2929
2972
  readonly schema: TaggedSchema
2930
2973
  readonly type: "final"
2974
+ /** Optional schema describing the terminal value produced by this final state. */
2931
2975
  readonly output?: Schema.Top
2932
2976
  readonly annotations?: never
2933
2977
  }
@@ -2935,12 +2979,15 @@ export declare namespace Machine {
2935
2979
  readonly schema?: never
2936
2980
  readonly type?: "active"
2937
2981
  readonly output?: never
2982
+ /** Descriptive metadata for a schema-less state. */
2938
2983
  readonly annotations?: SchemaLessStateAnnotations
2939
2984
  }
2940
2985
  | {
2941
2986
  readonly schema?: never
2942
2987
  readonly type: "final"
2988
+ /** Optional schema describing the terminal value produced by this final state. */
2943
2989
  readonly output?: Schema.Top
2990
+ /** Descriptive metadata for a schema-less state. */
2944
2991
  readonly annotations?: SchemaLessStateAnnotations
2945
2992
  }
2946
2993
 
@@ -2953,10 +3000,15 @@ export declare namespace Machine {
2953
3000
  */
2954
3001
  export type CompoundStateNodeConfig =
2955
3002
  | {
3003
+ /** Tagged schema that owns the compound state's decoded value. */
2956
3004
  readonly schema: TaggedSchema
3005
+ /** Compound states are ordinary active states. */
2957
3006
  readonly type?: "active"
3007
+ /** Direct child selected when the compound state is entered initially. */
2958
3008
  readonly initial: string
3009
+ /** Nested state nodes owned by this compound state. */
2959
3010
  readonly states: StateTree
3011
+ /** Schema-backed states take their annotations from the schema. */
2960
3012
  readonly annotations?: never
2961
3013
  }
2962
3014
  | {
@@ -2964,6 +3016,7 @@ export declare namespace Machine {
2964
3016
  readonly type?: "active"
2965
3017
  readonly initial: string
2966
3018
  readonly states: StateTree
3019
+ /** Descriptive metadata for a schema-less state. */
2967
3020
  readonly annotations?: SchemaLessStateAnnotations
2968
3021
  }
2969
3022
 
@@ -2976,10 +3029,15 @@ export declare namespace Machine {
2976
3029
  */
2977
3030
  export type ParallelStateNodeConfig =
2978
3031
  | {
3032
+ /** Tagged schema that owns the parallel state's decoded value. */
2979
3033
  readonly schema: TaggedSchema
3034
+ /** Selects parallel-region semantics for the node. */
2980
3035
  readonly type: "parallel"
3036
+ /** Optional schema describing the value produced after every region completes. */
2981
3037
  readonly output?: Schema.Top
3038
+ /** Child regions that are entered and remain active simultaneously. */
2982
3039
  readonly states: StateTree
3040
+ /** Schema-backed states take their annotations from the schema. */
2983
3041
  readonly annotations?: never
2984
3042
  }
2985
3043
  | {
@@ -2987,6 +3045,7 @@ export declare namespace Machine {
2987
3045
  readonly type: "parallel"
2988
3046
  readonly output?: Schema.Top
2989
3047
  readonly states: StateTree
3048
+ /** Descriptive metadata for a schema-less state. */
2990
3049
  readonly annotations?: SchemaLessStateAnnotations
2991
3050
  }
2992
3051
 
@@ -3003,9 +3062,16 @@ export declare namespace Machine {
3003
3062
  * @since 0.4.0
3004
3063
  */
3005
3064
  export interface HistoryStateNodeConfig {
3065
+ /** Selects history pseudo-state semantics. */
3006
3066
  readonly type: "history"
3007
- /** Defaults to shallow history. */
3067
+ /**
3068
+ * Restores only the direct child for shallow history or the complete
3069
+ * descendant configuration for deep history.
3070
+ *
3071
+ * @defaultValue `"shallow"`
3072
+ */
3008
3073
  readonly history?: "shallow" | "deep"
3074
+ /** Descriptive metadata used by visualization and documentation tooling. */
3009
3075
  readonly annotations?: SchemaLessStateAnnotations
3010
3076
  }
3011
3077
 
@@ -3020,7 +3086,9 @@ export declare namespace Machine {
3020
3086
  * @since 0.4.0
3021
3087
  */
3022
3088
  export interface ChoiceStateNodeConfig {
3089
+ /** Selects transient choice pseudo-state semantics. */
3023
3090
  readonly type: "choice"
3091
+ /** Descriptive metadata used by visualization and documentation tooling. */
3024
3092
  readonly annotations?: SchemaLessStateAnnotations
3025
3093
  }
3026
3094
 
@@ -3948,26 +4016,28 @@ export declare namespace Machine {
3948
4016
  */
3949
4017
  export interface EncodedSnapshotState {
3950
4018
  readonly path: string
3951
- readonly value?: unknown
4019
+ readonly value?: Schema.Json
3952
4020
  }
3953
4021
 
3954
4022
  /**
3955
4023
  * Encoded output for one completed state path in a normalized machine
3956
- * snapshot. An omitted output represents `undefined`.
4024
+ * snapshot. An omitted output means the final state declares no output
4025
+ * schema; a declared `Schema.Void` or `Schema.Undefined` output encodes as
4026
+ * canonical JSON `null`.
3957
4027
  *
3958
4028
  * @category models
3959
4029
  * @since 0.4.0
3960
4030
  */
3961
4031
  export interface EncodedSnapshotCompletion {
3962
4032
  readonly path: string
3963
- readonly output?: unknown
4033
+ readonly output?: Schema.Json
3964
4034
  }
3965
4035
 
3966
4036
  /** Encoded values and paths retained by one history pseudo-state. */
3967
4037
  export interface EncodedSnapshotHistoryEntry {
3968
4038
  readonly mode: "shallow" | "deep"
3969
4039
  readonly active: ReadonlyArray<string>
3970
- readonly values: Readonly<Record<string, unknown>>
4040
+ readonly values: Readonly<Record<string, Schema.Json>>
3971
4041
  }
3972
4042
 
3973
4043
  /**
@@ -3975,9 +4045,10 @@ export declare namespace Machine {
3975
4045
  *
3976
4046
  * **Details**
3977
4047
  *
3978
- * Active state and completion values use the encoded representations of
3979
- * their declared schemas. Runtime process state such as children, fibers,
3980
- * scopes, queues, and subscriptions is not included.
4048
+ * Active state and completion values use the canonical JSON representations
4049
+ * derived from their declared schemas. A successfully encoded snapshot is
4050
+ * safe to pass to JSON-backed persistence and transport. Runtime process state
4051
+ * such as children, fibers, scopes, queues, and subscriptions is not included.
3981
4052
  *
3982
4053
  * @category models
3983
4054
  * @since 0.4.0
@@ -4621,18 +4692,26 @@ export declare namespace Machine {
4621
4692
 
4622
4693
  /**
4623
4694
  * Definition-time topology selector available to an ordinary transition.
4695
+ *
4624
4696
  * Topology-only instructions (`none`, declared `initial` and history
4625
- * selections, and `local.with`) are values. State and choice destinations
4626
- * remain callable selection methods.
4697
+ * selections, and `local.with`) are values.
4698
+ *
4699
+ * State and choice destinations remain callable selection methods so their
4700
+ * target-specific resolver APIs retain exact inference.
4627
4701
  */
4628
4702
  export interface TargetSelector<
4629
4703
  States extends StateSchemas,
4630
4704
  Source extends StateNodeIdentifier<States>
4631
4705
  > {
4706
+ /** Handles the trigger without selecting a destination. */
4632
4707
  readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none">
4708
+ /** Selects a destination inside the nearest active compound scope. */
4633
4709
  readonly local: LocalTargetSelector<States, Source>
4710
+ /** Selects a destination elsewhere under the currently active root. */
4634
4711
  readonly branch: BranchTargetSelector<States, Source>
4712
+ /** Selects a complete destination under any top-level state. */
4635
4713
  readonly full: FullTargetSelector<States>
4714
+ /** Restores a shallow or deep history pseudo-state. */
4636
4715
  readonly history: HistorySelectionTree<States, States, "", HistoryTargetBuilder<States>>
4637
4716
  }
4638
4717
 
@@ -4662,11 +4741,15 @@ export declare namespace Machine {
4662
4741
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4663
4742
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4664
4743
  > = MachineReferences<InputEvents, ParentEvents> & {
4744
+ /** Value owned by the state whose handler is running. */
4665
4745
  readonly state: StateByIdentifier<States, StateId>
4746
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4666
4747
  readonly containingState: ParentStateValue<States, StateId>
4748
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4667
4749
  readonly ancestors: ParentStateValues<States, StateId>
4668
4750
  /** Complete logical configuration captured at the start of this microstep. */
4669
4751
  readonly snapshot: Snapshot<States>
4752
+ /** Event that selected this handler, narrowed by its `_tag`. */
4670
4753
  readonly event: EventByTag<Events, EventTag>
4671
4754
 
4672
4755
  /**
@@ -4692,9 +4775,13 @@ export declare namespace Machine {
4692
4775
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4693
4776
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4694
4777
  > = MachineReferences<InputEvents, ParentEvents> & {
4778
+ /** Value owned by the state entering or exiting. */
4695
4779
  readonly state: StateByIdentifier<States, StateId>
4780
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4696
4781
  readonly containingState: ParentStateValue<States, StateId>
4782
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4697
4783
  readonly ancestors: ParentStateValues<States, StateId>
4784
+ /** Event or initial-entry marker responsible for the lifecycle action. */
4698
4785
  readonly event: LifecycleEvent<Events>
4699
4786
  }
4700
4787
 
@@ -4712,9 +4799,13 @@ export declare namespace Machine {
4712
4799
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4713
4800
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4714
4801
  > = MachineReferences<InputEvents, ParentEvents> & {
4802
+ /** Value owned by the state that owns this invocation. */
4715
4803
  readonly state: StateByIdentifier<States, StateId>
4804
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4716
4805
  readonly containingState: ParentStateValue<States, StateId>
4806
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4717
4807
  readonly ancestors: ParentStateValues<States, StateId>
4808
+ /** Event or initial-entry marker responsible for starting the invocation. */
4718
4809
  readonly event: LifecycleEvent<Events>
4719
4810
  }
4720
4811
 
@@ -4735,11 +4826,17 @@ export declare namespace Machine {
4735
4826
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4736
4827
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4737
4828
  > = MachineReferences<InputEvents, ParentEvents> & {
4829
+ /** Parent-local invocation identifier. */
4738
4830
  readonly id: string
4831
+ /** Current value of the state that owns the invocation. */
4739
4832
  readonly state: StateByIdentifier<States, StateId>
4833
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4740
4834
  readonly containingState: ParentStateValue<States, StateId>
4835
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4741
4836
  readonly ancestors: ParentStateValues<States, StateId>
4837
+ /** Builders for selecting the owning machine's next state. */
4742
4838
  readonly target: TargetBuilder<States, StateId>
4839
+ /** Latest active lifecycle snapshot published by the invoked logic or child. */
4743
4840
  readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "active" }>
4744
4841
  }
4745
4842
 
@@ -4758,12 +4855,19 @@ export declare namespace Machine {
4758
4855
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4759
4856
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4760
4857
  > = MachineReferences<InputEvents, ParentEvents> & {
4858
+ /** Parent-local invocation identifier. */
4761
4859
  readonly id: string
4860
+ /** Current value of the state that owns the invocation. */
4762
4861
  readonly state: StateByIdentifier<States, StateId>
4862
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4763
4863
  readonly containingState: ParentStateValue<States, StateId>
4864
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4764
4865
  readonly ancestors: ParentStateValues<States, StateId>
4866
+ /** Complete owning-machine configuration captured for this transition. */
4765
4867
  readonly snapshot: Snapshot<States>
4868
+ /** Builders for selecting the owning machine's next state. */
4766
4869
  readonly target: TargetBuilder<States, StateId>
4870
+ /** Successful output produced by the invocation. */
4767
4871
  readonly output: Output
4768
4872
  }
4769
4873
 
@@ -4777,12 +4881,19 @@ export declare namespace Machine {
4777
4881
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4778
4882
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4779
4883
  > = MachineReferences<InputEvents, ParentEvents> & {
4884
+ /** Parent-local invocation identifier. */
4780
4885
  readonly id: string
4886
+ /** Current value of the state that owns the Stream invocation. */
4781
4887
  readonly state: StateByIdentifier<States, StateId>
4888
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4782
4889
  readonly containingState: ParentStateValue<States, StateId>
4890
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4783
4891
  readonly ancestors: ParentStateValues<States, StateId>
4892
+ /** Complete owning-machine configuration captured for this transition. */
4784
4893
  readonly snapshot: Snapshot<States>
4894
+ /** Builders for selecting the owning machine's next state. */
4785
4895
  readonly target: TargetBuilder<States, StateId>
4896
+ /** Next element emitted by the invoked Stream. */
4786
4897
  readonly element: Element
4787
4898
  }
4788
4899
 
@@ -4796,12 +4907,19 @@ export declare namespace Machine {
4796
4907
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4797
4908
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4798
4909
  > = MachineReferences<InputEvents, ParentEvents> & {
4910
+ /** Parent-local invocation identifier. */
4799
4911
  readonly id: string
4912
+ /** Current value of the state that owns the invocation. */
4800
4913
  readonly state: StateByIdentifier<States, StateId>
4914
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4801
4915
  readonly containingState: ParentStateValue<States, StateId>
4916
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4802
4917
  readonly ancestors: ParentStateValues<States, StateId>
4918
+ /** Complete owning-machine configuration captured for this transition. */
4803
4919
  readonly snapshot: Snapshot<States>
4920
+ /** Builders for selecting the owning machine's next state. */
4804
4921
  readonly target: TargetBuilder<States, StateId>
4922
+ /** Typed failure produced by the invocation. */
4805
4923
  readonly error: Error
4806
4924
  }
4807
4925
 
@@ -4819,11 +4937,15 @@ export declare namespace Machine {
4819
4937
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4820
4938
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4821
4939
  > = MachineReferences<InputEvents, ParentEvents> & {
4940
+ /** Current value of the state evaluating the eventless transition. */
4822
4941
  readonly state: StateByIdentifier<States, StateId>
4942
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4823
4943
  readonly containingState: ParentStateValue<States, StateId>
4944
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4824
4945
  readonly ancestors: ParentStateValues<States, StateId>
4825
4946
  /** Complete logical configuration captured at the start of this microstep. */
4826
4947
  readonly snapshot: Snapshot<States>
4948
+ /** Lifecycle event retained while the eventless transition is evaluated. */
4827
4949
  readonly event: LifecycleEvent<Events>
4828
4950
 
4829
4951
  /**
@@ -4850,12 +4972,17 @@ export declare namespace Machine {
4850
4972
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4851
4973
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4852
4974
  > = MachineReferences<InputEvents, ParentEvents> & {
4975
+ /** Current value of the state whose child configuration completed. */
4853
4976
  readonly state: StateByIdentifier<States, StateId>
4977
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4854
4978
  readonly containingState: ParentStateValue<States, StateId>
4979
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4855
4980
  readonly ancestors: ParentStateValues<States, StateId>
4856
4981
  /** Complete logical configuration captured at the start of this microstep. */
4857
4982
  readonly snapshot: Snapshot<States>
4983
+ /** Lifecycle event retained while state completion is processed. */
4858
4984
  readonly event: LifecycleEvent<Events>
4985
+ /** Output produced by the completed final child or parallel regions. */
4859
4986
  readonly output: CompletionOutputByIdentifier<States, StateId>
4860
4987
 
4861
4988
  /**
@@ -4877,17 +5004,21 @@ export declare namespace Machine {
4877
5004
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4878
5005
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4879
5006
  > = MachineReferences<InputEvents, ParentEvents> & {
5007
+ /** Value owned by the choice node's immediate schema-backed parent. */
4880
5008
  readonly containingState: StateByIdentifier<
4881
5009
  States,
4882
5010
  Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>
4883
5011
  >
5012
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4884
5013
  readonly ancestors: {
4885
5014
  readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<
4886
5015
  States,
4887
5016
  Parent
4888
5017
  >
4889
5018
  }
5019
+ /** Lifecycle event that led to the transient choice. */
4890
5020
  readonly event: LifecycleEvent<Events>
5021
+ /** Builders for selecting the concrete destination of this choice. */
4891
5022
  readonly target: TargetBuilder<States, ChoiceId>
4892
5023
  }
4893
5024
 
@@ -4902,9 +5033,13 @@ export declare namespace Machine {
4902
5033
  Events extends ReadonlyArray<TaggedSchema>,
4903
5034
  StateId extends StateIdentifier<States>
4904
5035
  > {
5036
+ /** Decoded value owned by the final state. */
4905
5037
  readonly state: StateByIdentifier<States, StateId>
5038
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4906
5039
  readonly containingState: ParentStateValue<States, StateId>
5040
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4907
5041
  readonly ancestors: ParentStateValues<States, StateId>
5042
+ /** Lifecycle event responsible for entering the final state. */
4908
5043
  readonly event: LifecycleEvent<Events>
4909
5044
  }
4910
5045
 
@@ -4937,10 +5072,15 @@ export declare namespace Machine {
4937
5072
  Events extends ReadonlyArray<TaggedSchema>,
4938
5073
  StateId extends StateIdentifier<States>
4939
5074
  > {
5075
+ /** Decoded value owned by the completed parallel state. */
4940
5076
  readonly state: StateByIdentifier<States, StateId>
5077
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4941
5078
  readonly containingState: ParentStateValue<States, StateId>
5079
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4942
5080
  readonly ancestors: ParentStateValues<States, StateId>
5081
+ /** Lifecycle event retained while parallel completion is processed. */
4943
5082
  readonly event: LifecycleEvent<Events>
5083
+ /** Completion output from every direct parallel region. */
4944
5084
  readonly outputs: ParallelOutputRegions<States, StateId>
4945
5085
  }
4946
5086
 
@@ -5213,11 +5353,19 @@ export declare namespace Machine {
5213
5353
  : never
5214
5354
  /** Extracts transition results returned by invocation lifecycle handlers. */
5215
5355
  export type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ?
5356
+ | (Invoke extends {
5357
+ readonly [InvokeTypeId]: { readonly outcomes: Types.Covariant<infer Outcomes> }
5358
+ } ? EventTransitionReturn<Outcomes> :
5359
+ never)
5216
5360
  | (Invoke extends { readonly onDone?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
5217
5361
  | (Invoke extends { readonly onFailure?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
5218
5362
  | (Invoke extends { readonly onElement?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
5219
5363
  | (Invoke extends { readonly onSnapshot?: infer Handler } ? EventTransitionReturn<NonNullable<Handler>> : never)
5220
5364
  : never
5365
+ type InvokeOutcomeError<Invoke> = IsAny<InvokeOutcomeReturn<Invoke>> extends true ? never
5366
+ : Effect.Error<InvokeOutcomeReturn<Invoke>>
5367
+ type InvokeOutcomeServices<Invoke> = IsAny<InvokeOutcomeReturn<Invoke>> extends true ? never
5368
+ : Effect.Services<InvokeOutcomeReturn<Invoke>>
5221
5369
  /**
5222
5370
  * Extracts the parent transition error contribution from invoked children.
5223
5371
  *
@@ -5228,7 +5376,7 @@ export declare namespace Machine {
5228
5376
  :
5229
5377
  | ChildAlreadyExistsError
5230
5378
  | InvokeInitialError<InvokeReturn<Config>>
5231
- | Effect.Error<InvokeOutcomeReturn<InvokeReturn<Config>>>
5379
+ | InvokeOutcomeError<InvokeReturn<Config>>
5232
5380
  /**
5233
5381
  * Extracts the parent service requirement contribution from invoked children.
5234
5382
  *
@@ -5239,9 +5387,7 @@ export declare namespace Machine {
5239
5387
  :
5240
5388
  | MachineRuntimeRequirement
5241
5389
  | InvokeServices<InvokeReturn<Config>>
5242
- | Effect.Services<
5243
- InvokeOutcomeReturn<InvokeReturn<Config>>
5244
- >
5390
+ | InvokeOutcomeServices<InvokeReturn<Config>>
5245
5391
  /**
5246
5392
  * Extracts the return value from an eventless transition.
5247
5393
  *
@@ -5339,6 +5485,7 @@ export declare namespace Machine {
5339
5485
 
5340
5486
  /** Context capability available only to explicitly declinable resolvers. */
5341
5487
  export interface DeclineCapability {
5488
+ /** Declines this candidate and continues hierarchical transition selection. */
5342
5489
  readonly decline: () => Declined
5343
5490
  }
5344
5491
 
@@ -5368,7 +5515,9 @@ export declare namespace Machine {
5368
5515
  export interface TransitionBranchInput<
5369
5516
  Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>
5370
5517
  > {
5518
+ /** Exact topology destination available to the branching resolver. */
5371
5519
  readonly target: Selection
5520
+ /** Optional human-readable branch label used by visualization tooling. */
5372
5521
  readonly title?: string
5373
5522
  }
5374
5523
 
@@ -5448,16 +5597,25 @@ export declare namespace Machine {
5448
5597
  }
5449
5598
  }
5450
5599
 
5451
- type TransitionReenterOption<Reenter extends boolean> = [Reenter] extends [true] ? { readonly reenter?: boolean }
5600
+ type TransitionReenterOption<Reenter extends boolean> = [Reenter] extends [true] ? {
5601
+ /** Forces the source state to exit and enter even when active paths remain unchanged. */
5602
+ readonly reenter?: boolean
5603
+ }
5452
5604
  : { readonly reenter?: never }
5453
5605
 
5454
5606
  type TransitionRequiredOptions<Reenter extends boolean> =
5455
5607
  & TransitionReenterOption<Reenter>
5456
- & { readonly declinable?: false }
5608
+ & {
5609
+ /** Keeps the transition required. The resolver cannot return `decline()`. */
5610
+ readonly declinable?: false
5611
+ }
5457
5612
 
5458
5613
  type TransitionDeclinableOptions<Reenter extends boolean> =
5459
5614
  & TransitionReenterOption<Reenter>
5460
- & { readonly declinable: true }
5615
+ & {
5616
+ /** Adds `decline()` to the resolver context and permits declining this candidate. */
5617
+ readonly declinable: true
5618
+ }
5461
5619
 
5462
5620
  type BuiltTransition<
5463
5621
  States extends StateSchemas,
@@ -5521,7 +5679,23 @@ export declare namespace Machine {
5521
5679
  >
5522
5680
  }
5523
5681
 
5524
- /** A selected transition target with target-specific resolver operations. */
5682
+ /**
5683
+ * A selected transition target with target-specific resolver operations.
5684
+ *
5685
+ * **Example** (Updating state while reentering)
5686
+ *
5687
+ * ```ts
5688
+ * Reset: (to) =>
5689
+ * to.full.Ready().resolve(
5690
+ * ({ target }) => target.from(),
5691
+ * { reenter: true }
5692
+ * )
5693
+ * ```
5694
+ *
5695
+ * @inlineType TransitionRequiredOptions
5696
+ * @inlineType TransitionDeclinableOptions
5697
+ * @inlineType TransitionReenterOption
5698
+ */
5525
5699
  export type TransitionTarget<
5526
5700
  States extends StateSchemas,
5527
5701
  Events extends ReadonlyArray<TaggedSchema>,
@@ -5545,6 +5719,10 @@ export declare namespace Machine {
5545
5719
  >
5546
5720
  : {})
5547
5721
  & {
5722
+ /**
5723
+ * Evaluates state construction and queued commands only after this
5724
+ * transition has been selected.
5725
+ */
5548
5726
  readonly resolve:
5549
5727
  & TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection>
5550
5728
  & ("declinable" extends Acceptance ? TransitionResolveDeclinable<
@@ -5559,6 +5737,7 @@ export declare namespace Machine {
5559
5737
  : {})
5560
5738
  }
5561
5739
  & ([Reenter] extends [true] ? SelectionSupportsDefaultConstruction<Selection> extends true ? {
5740
+ /** Reenters the source using the selected target's default construction. */
5562
5741
  readonly reenter: () => BuiltTransition<
5563
5742
  States,
5564
5743
  Events,
@@ -5583,9 +5762,12 @@ export declare namespace Machine {
5583
5762
  & Selection
5584
5763
  & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {})
5585
5764
  & {
5765
+ /** Lazily constructs the selected initial state from decoded machine input. */
5586
5766
  readonly resolve: (
5587
5767
  resolve: (context: {
5768
+ /** Decoded value supplied when the machine is started. */
5588
5769
  readonly input: Input
5770
+ /** Builder specialized to the selected initial destination. */
5589
5771
  readonly target: SelectionBuilder<Selection>
5590
5772
  }) => SelectedTargetResult<Selection>
5591
5773
  ) => InitialBuilderEvidence<Selection>
@@ -5739,9 +5921,11 @@ export declare namespace Machine {
5739
5921
  TargetSelector<States, StateId>
5740
5922
  >
5741
5923
  & {
5924
+ /** Declares a closed set of named destinations for one resolver. */
5742
5925
  readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(
5743
5926
  branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>
5744
5927
  ) => {
5928
+ /** Resolves exactly one declared branch after this transition is selected. */
5745
5929
  readonly resolve:
5746
5930
  & TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches>
5747
5931
  & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<
@@ -5796,8 +5980,16 @@ export declare namespace Machine {
5796
5980
  >
5797
5981
  }
5798
5982
 
5799
- /** Type evidence retained by {@link invoke} without affecting runtime data. */
5800
- export interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never> {
5983
+ /** Type evidence retained by a completed state-owned invocation. */
5984
+ export interface InvokeTyped<
5985
+ Output,
5986
+ Error,
5987
+ Requirements,
5988
+ InitialError,
5989
+ Emits = never,
5990
+ ParentEvent = never,
5991
+ Outcomes = never
5992
+ > {
5801
5993
  readonly [InvokeTypeId]: {
5802
5994
  readonly output: Types.Covariant<Output>
5803
5995
  readonly error: Types.Covariant<Error>
@@ -5805,10 +5997,11 @@ export declare namespace Machine {
5805
5997
  readonly initialError: Types.Covariant<InitialError>
5806
5998
  readonly emits: Types.Covariant<Emits>
5807
5999
  readonly parentEvents: Types.Covariant<ParentEvent>
6000
+ readonly outcomes: Types.Covariant<Outcomes>
5808
6001
  }
5809
6002
  }
5810
6003
 
5811
- export type InvokeConfig<
6004
+ type StoredInvokeConfig<
5812
6005
  States extends StateSchemas,
5813
6006
  Events extends ReadonlyArray<TaggedSchema>,
5814
6007
  Emits extends ReadonlyArray<TaggedSchema>,
@@ -5899,8 +6092,7 @@ export declare namespace Machine {
5899
6092
  }
5900
6093
  )
5901
6094
 
5902
- /** State-bound inline invocation configuration. */
5903
- export type InvokeDefinition<
6095
+ type StoredInvokeDefinition<
5904
6096
  States extends StateSchemas,
5905
6097
  Events extends ReadonlyArray<TaggedSchema>,
5906
6098
  Emits extends ReadonlyArray<TaggedSchema>,
@@ -5908,475 +6100,584 @@ export declare namespace Machine {
5908
6100
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5909
6101
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
5910
6102
  > =
5911
- | InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
5912
- | ReadonlyArray<InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>>
6103
+ | StoredInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>
6104
+ | ReadonlyArray<StoredInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents>>
5913
6105
 
5914
- type TypedInvokeDefinition =
5915
- | InvokeTyped<any, any, any, any, any, any>
5916
- | ReadonlyArray<InvokeTyped<any, any, any, any, any, any>>
5917
-
5918
- type InvokeHandlerRequirement<Value, Handler> = IsAny<Value> extends true ? { readonly handler: Handler }
5919
- : [Value] extends [never] ? { readonly handler?: never }
5920
- : { readonly handler: Handler }
5921
-
5922
- export type InvokeDoneRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends
5923
- infer Requirement ? Requirement extends { readonly handler: infer Required } ? { readonly onDone: Required }
5924
- : { readonly onDone?: never }
6106
+ type LogicInitialEffectOf<Value> = Value extends { readonly initial: infer Initial } ?
6107
+ Initial extends (...args: ReadonlyArray<any>) => infer Result ? Result : never
5925
6108
  : never
5926
6109
 
5927
- export type InvokeFailureRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends
5928
- infer Requirement ? Requirement extends { readonly handler: infer Required } ? { readonly onFailure: Required }
5929
- : { readonly onFailure?: never }
6110
+ type LogicRunEffectOf<Value> = Value extends { readonly run: infer Run } ?
6111
+ Run extends (...args: ReadonlyArray<any>) => infer Result ? Result : never
5930
6112
  : never
5931
6113
 
5932
- export type InvokeElementRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends
5933
- infer Requirement ? Requirement extends { readonly handler: infer Required } ? { readonly onElement: Required }
5934
- : { readonly onElement?: never }
6114
+ export type LogicStateOf<Value> = Effect.Success<LogicInitialEffectOf<Value>>
6115
+ export type LogicEventOf<Value> = Value extends { readonly initial: infer Initial } ?
6116
+ Initial extends (scope: infer LogicScope, ...args: ReadonlyArray<any>) => any ?
6117
+ LogicScope extends Logic.Scope<infer Event> ? Event : never
5935
6118
  : never
6119
+ : never
6120
+ export type LogicErrorOf<Value> = Effect.Error<LogicRunEffectOf<Value>>
6121
+ export type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>
6122
+ export type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>
6123
+ export type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>
6124
+
6125
+ type RequiredInvokeChannel<Value, Channel extends string> = IsAny<Value> extends true ? Channel
6126
+ : [Value] extends [never] ? never
6127
+ : Channel
5936
6128
 
5937
- export type TimerInvokeArgs<
6129
+ type InvokeBuilderResult<
5938
6130
  States extends StateSchemas,
5939
6131
  Events extends ReadonlyArray<TaggedSchema>,
5940
6132
  Emits extends ReadonlyArray<TaggedSchema>,
5941
6133
  StateId extends StateIdentifier<States>,
5942
- InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5943
- ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
5944
- > = {
5945
- readonly id: InvokeLifecycleId
5946
- readonly after: InvokeSource<
5947
- Duration.Input,
5948
- InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
5949
- >
5950
- readonly effect?: never
5951
- readonly stream?: never
5952
- readonly logic?: never
5953
- readonly child?: never
5954
- readonly address?: never
5955
- readonly onFailure?: never
5956
- readonly onElement?: never
5957
- readonly onSnapshot?: never
5958
- readonly onDone: InvokeTransition<
5959
- States,
5960
- Events,
5961
- Emits,
5962
- StateId,
5963
- InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>
5964
- >
5965
- }
6134
+ InputEvents extends ReadonlyArray<TaggedSchema>,
6135
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
6136
+ Output,
6137
+ Error,
6138
+ Requirements,
6139
+ InitialError,
6140
+ ChildEmits,
6141
+ ChildParentEvent,
6142
+ Outcomes
6143
+ > =
6144
+ & InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents>
6145
+ & InvokeTyped<Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes>
6146
+ & { readonly [InvokeBuilderTypeId]: true }
5966
6147
 
5967
- export type LogicInvokeArgs<
6148
+ /** Lifecycle handlers exposed according to the selected invocation source. */
6149
+ type InvokeBuilder<
5968
6150
  States extends StateSchemas,
5969
6151
  Events extends ReadonlyArray<TaggedSchema>,
5970
6152
  Emits extends ReadonlyArray<TaggedSchema>,
5971
6153
  StateId extends StateIdentifier<States>,
5972
- ChildState,
5973
- ChildEvent,
5974
- ChildError,
5975
- ChildRequirements,
5976
- ChildOutput,
5977
- ChildInitialError,
5978
- Address extends ChildAddress<never>,
5979
- Source = Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>,
5980
- InputEvents extends ReadonlyArray<TaggedSchema> = Events,
5981
- ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6154
+ InputEvents extends ReadonlyArray<TaggedSchema>,
6155
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
6156
+ Output,
6157
+ Error,
6158
+ Requirements,
6159
+ InitialError,
6160
+ ChildEmits,
6161
+ ChildParentEvent,
6162
+ Element,
6163
+ Pending extends string,
6164
+ SnapshotHandler,
6165
+ Outcomes = never
5982
6166
  > =
5983
- & {
5984
- readonly id: InvokeLifecycleId
5985
- readonly address: Address & ChildAddress.Compatibility<Address, ChildEvent>
5986
- readonly logic: Source
5987
- readonly effect?: never
5988
- readonly stream?: never
5989
- readonly after?: never
5990
- readonly child?: never
5991
- readonly onElement?: never
5992
- readonly onSnapshot?: InvokeTransition<
6167
+ & ([Pending] extends [never] ? InvokeBuilderResult<
5993
6168
  States,
5994
6169
  Events,
5995
6170
  Emits,
5996
6171
  StateId,
5997
- InvokeSnapshotContext<
6172
+ InputEvents,
6173
+ ParentEvents,
6174
+ Output,
6175
+ Error,
6176
+ Requirements,
6177
+ InitialError,
6178
+ ChildEmits,
6179
+ ChildParentEvent,
6180
+ Outcomes
6181
+ >
6182
+ : {})
6183
+ & ("done" extends Pending ? {
6184
+ /** Handles successful completion and exposes the invocation output. */
6185
+ readonly onDone: <
6186
+ const Handler extends InvokeTransition<
6187
+ States,
6188
+ Events,
6189
+ Emits,
6190
+ StateId,
6191
+ InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>
6192
+ >
6193
+ >(
6194
+ handler:
6195
+ & Handler
6196
+ & InvokeTransition<
6197
+ States,
6198
+ Events,
6199
+ Emits,
6200
+ StateId,
6201
+ InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>
6202
+ >
6203
+ ) => InvokeBuilder<
5998
6204
  States,
5999
6205
  Events,
6000
6206
  Emits,
6001
6207
  StateId,
6002
- NoInfer<ChildState>,
6003
- NoInfer<ChildError>,
6004
- NoInfer<ChildOutput>,
6005
6208
  InputEvents,
6006
- ParentEvents
6209
+ ParentEvents,
6210
+ Output,
6211
+ Error,
6212
+ Requirements,
6213
+ InitialError,
6214
+ ChildEmits,
6215
+ ChildParentEvent,
6216
+ Element,
6217
+ Exclude<Pending, "done">,
6218
+ SnapshotHandler,
6219
+ Outcomes | Handler
6007
6220
  >
6008
- >
6009
- }
6010
- & InvokeDoneRequirement<
6011
- NoInfer<ChildOutput>,
6012
- InvokeTransition<
6013
- States,
6014
- Events,
6015
- Emits,
6016
- StateId,
6017
- InvokeDoneContext<States, Events, Emits, StateId, NoInfer<ChildOutput>, InputEvents, ParentEvents>
6018
- >
6019
- >
6020
- & InvokeFailureRequirement<
6021
- NoInfer<ChildError>,
6022
- InvokeTransition<
6023
- States,
6024
- Events,
6025
- Emits,
6026
- StateId,
6027
- InvokeFailureContext<States, Events, Emits, StateId, NoInfer<ChildError>, InputEvents, ParentEvents>
6028
- >
6029
- >
6030
-
6031
- export type ChildInvokeArgs<
6032
- States extends StateSchemas,
6033
- Events extends ReadonlyArray<TaggedSchema>,
6034
- Emits extends ReadonlyArray<TaggedSchema>,
6035
- StateId extends StateIdentifier<States>,
6036
- ChildDefinition extends Machine.Any,
6037
- Child extends ChildMachine<string, ChildDefinition>,
6038
- InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6039
- ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6040
- > =
6041
- & {
6042
- readonly child:
6043
- & Child
6044
- & (ChildDefinition extends EnsureExecutable<
6045
- Machine.States<ChildDefinition>,
6046
- Machine.UnhandledStates<ChildDefinition>,
6047
- Machine.OutputStates<ChildDefinition>
6048
- > ? unknown :
6049
- never)
6050
- readonly id?: never
6051
- readonly address?: never
6052
- readonly effect?: never
6053
- readonly stream?: never
6054
- readonly after?: never
6055
- readonly logic?: never
6056
- readonly onElement?: never
6057
- readonly onSnapshot?: InvokeTransition<
6058
- States,
6059
- Events,
6060
- Emits,
6061
- StateId,
6062
- InvokeSnapshotContext<
6221
+ }
6222
+ : {})
6223
+ & ("failure" extends Pending ? {
6224
+ /** Handles typed failure and exposes the invocation error. */
6225
+ readonly onFailure: <
6226
+ const Handler extends InvokeTransition<
6227
+ States,
6228
+ Events,
6229
+ Emits,
6230
+ StateId,
6231
+ InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>
6232
+ >
6233
+ >(
6234
+ handler:
6235
+ & Handler
6236
+ & InvokeTransition<
6237
+ States,
6238
+ Events,
6239
+ Emits,
6240
+ StateId,
6241
+ InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>
6242
+ >
6243
+ ) => InvokeBuilder<
6063
6244
  States,
6064
6245
  Events,
6065
6246
  Emits,
6066
6247
  StateId,
6067
- Snapshot<Machine.States<ChildDefinition>>,
6068
- Error<ChildDefinition>,
6069
- Output<ChildDefinition>,
6070
6248
  InputEvents,
6071
- ParentEvents
6249
+ ParentEvents,
6250
+ Output,
6251
+ Error,
6252
+ Requirements,
6253
+ InitialError,
6254
+ ChildEmits,
6255
+ ChildParentEvent,
6256
+ Element,
6257
+ Exclude<Pending, "failure">,
6258
+ SnapshotHandler,
6259
+ Outcomes | Handler
6072
6260
  >
6073
- >
6074
- }
6075
- & (Input<ChildDefinition> extends typeof Schema.Void ? { readonly input?: never } : {
6076
- readonly input: InvokeSource<
6077
- Input<ChildDefinition>["Type"],
6078
- InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6079
- >
6080
- })
6081
- & InvokeDoneRequirement<
6082
- Output<ChildDefinition>,
6083
- InvokeTransition<
6084
- States,
6085
- Events,
6086
- Emits,
6087
- StateId,
6088
- InvokeDoneContext<
6261
+ }
6262
+ : {})
6263
+ & ("element" extends Pending ? {
6264
+ /** Handles each backpressured element emitted by an invoked Stream. */
6265
+ readonly onElement: <
6266
+ const Handler extends InvokeTransition<
6267
+ States,
6268
+ Events,
6269
+ Emits,
6270
+ StateId,
6271
+ InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>
6272
+ >
6273
+ >(
6274
+ handler:
6275
+ & Handler
6276
+ & InvokeTransition<
6277
+ States,
6278
+ Events,
6279
+ Emits,
6280
+ StateId,
6281
+ InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>
6282
+ >
6283
+ ) => InvokeBuilder<
6089
6284
  States,
6090
6285
  Events,
6091
6286
  Emits,
6092
6287
  StateId,
6093
- Output<ChildDefinition>,
6094
6288
  InputEvents,
6095
- ParentEvents
6289
+ ParentEvents,
6290
+ Output,
6291
+ Error,
6292
+ Requirements,
6293
+ InitialError,
6294
+ ChildEmits,
6295
+ ChildParentEvent,
6296
+ Element,
6297
+ Exclude<Pending, "element">,
6298
+ SnapshotHandler,
6299
+ Outcomes | Handler
6096
6300
  >
6097
- >
6098
- >
6099
- & InvokeFailureRequirement<
6100
- Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
6101
- InvokeTransition<
6301
+ }
6302
+ : {})
6303
+ & ([SnapshotHandler] extends [never] ? {} : {
6304
+ /** Handles each active snapshot published by invoked logic or a child machine. */
6305
+ readonly onSnapshot: <const Handler extends SnapshotHandler>(handler: Handler & SnapshotHandler) => InvokeBuilder<
6102
6306
  States,
6103
6307
  Events,
6104
6308
  Emits,
6105
6309
  StateId,
6106
- InvokeFailureContext<
6107
- States,
6108
- Events,
6109
- Emits,
6110
- StateId,
6111
- Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
6112
- InputEvents,
6113
- ParentEvents
6114
- >
6310
+ InputEvents,
6311
+ ParentEvents,
6312
+ Output,
6313
+ Error,
6314
+ Requirements,
6315
+ InitialError,
6316
+ ChildEmits,
6317
+ ChildParentEvent,
6318
+ Element,
6319
+ Pending,
6320
+ never,
6321
+ Outcomes | Handler
6115
6322
  >
6116
- >
6323
+ })
6117
6324
 
6118
- type LogicInitialEffectOf<Value> = Value extends { readonly initial: infer Initial } ?
6119
- Initial extends (...args: ReadonlyArray<any>) => infer Result ? Result : never
6120
- : never
6325
+ type EffectInvokeBuilder<
6326
+ States extends StateSchemas,
6327
+ Events extends ReadonlyArray<TaggedSchema>,
6328
+ Emits extends ReadonlyArray<TaggedSchema>,
6329
+ StateId extends StateIdentifier<States>,
6330
+ InputEvents extends ReadonlyArray<TaggedSchema>,
6331
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
6332
+ Source extends (...args: ReadonlyArray<any>) => Effect.Effect<any, any, any>
6333
+ > = InvokeBuilder<
6334
+ States,
6335
+ Events,
6336
+ Emits,
6337
+ StateId,
6338
+ InputEvents,
6339
+ ParentEvents,
6340
+ Effect.Success<ReturnType<Source>>,
6341
+ Effect.Error<ReturnType<Source>>,
6342
+ Effect.Services<ReturnType<Source>>,
6343
+ never,
6344
+ never,
6345
+ never,
6346
+ never,
6347
+ | RequiredInvokeChannel<Effect.Success<ReturnType<Source>>, "done">
6348
+ | RequiredInvokeChannel<Effect.Error<ReturnType<Source>>, "failure">,
6349
+ never
6350
+ >
6121
6351
 
6122
- type LogicRunEffectOf<Value> = Value extends { readonly run: infer Run } ?
6123
- Run extends (...args: ReadonlyArray<any>) => infer Result ? Result : never
6124
- : never
6352
+ type StreamInvokeBuilder<
6353
+ States extends StateSchemas,
6354
+ Events extends ReadonlyArray<TaggedSchema>,
6355
+ Emits extends ReadonlyArray<TaggedSchema>,
6356
+ StateId extends StateIdentifier<States>,
6357
+ InputEvents extends ReadonlyArray<TaggedSchema>,
6358
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
6359
+ Source extends (...args: ReadonlyArray<any>) => Stream.Stream<any, any, any>
6360
+ > = InvokeBuilder<
6361
+ States,
6362
+ Events,
6363
+ Emits,
6364
+ StateId,
6365
+ InputEvents,
6366
+ ParentEvents,
6367
+ void,
6368
+ Stream.Error<ReturnType<Source>>,
6369
+ Stream.Services<ReturnType<Source>>,
6370
+ never,
6371
+ never,
6372
+ never,
6373
+ Stream.Success<ReturnType<Source>>,
6374
+ | "done"
6375
+ | RequiredInvokeChannel<Stream.Success<ReturnType<Source>>, "element">
6376
+ | RequiredInvokeChannel<Stream.Error<ReturnType<Source>>, "failure">,
6377
+ never
6378
+ >
6125
6379
 
6126
- export type LogicStateOf<Value> = Effect.Success<LogicInitialEffectOf<Value>>
6127
- export type LogicEventOf<Value> = Value extends { readonly initial: infer Initial } ?
6128
- Initial extends (scope: infer LogicScope, ...args: ReadonlyArray<any>) => any ?
6129
- LogicScope extends Logic.Scope<infer Event> ? Event : never
6130
- : never
6131
- : never
6132
- export type LogicErrorOf<Value> = Effect.Error<LogicRunEffectOf<Value>>
6133
- export type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>
6134
- export type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>
6135
- export type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>
6380
+ type LogicInvokeBuilder<
6381
+ States extends StateSchemas,
6382
+ Events extends ReadonlyArray<TaggedSchema>,
6383
+ Emits extends ReadonlyArray<TaggedSchema>,
6384
+ StateId extends StateIdentifier<States>,
6385
+ InputEvents extends ReadonlyArray<TaggedSchema>,
6386
+ ParentEvents extends ReadonlyArray<TaggedSchema>,
6387
+ ChildLogic
6388
+ > = InvokeBuilder<
6389
+ States,
6390
+ Events,
6391
+ Emits,
6392
+ StateId,
6393
+ InputEvents,
6394
+ ParentEvents,
6395
+ LogicOutputOf<ChildLogic>,
6396
+ LogicErrorOf<ChildLogic>,
6397
+ LogicServicesOf<ChildLogic>,
6398
+ LogicInitialErrorOf<ChildLogic>,
6399
+ never,
6400
+ never,
6401
+ never,
6402
+ | RequiredInvokeChannel<LogicOutputOf<ChildLogic>, "done">
6403
+ | RequiredInvokeChannel<LogicErrorOf<ChildLogic>, "failure">,
6404
+ InvokeTransition<
6405
+ States,
6406
+ Events,
6407
+ Emits,
6408
+ StateId,
6409
+ InvokeSnapshotContext<
6410
+ States,
6411
+ Events,
6412
+ Emits,
6413
+ StateId,
6414
+ LogicStateOf<ChildLogic>,
6415
+ LogicErrorOf<ChildLogic>,
6416
+ LogicOutputOf<ChildLogic>,
6417
+ InputEvents,
6418
+ ParentEvents
6419
+ >
6420
+ >
6421
+ >
6136
6422
 
6137
- type ContextualInvokeConfig<
6423
+ type ChildInvokeBuilder<
6138
6424
  States extends StateSchemas,
6139
6425
  Events extends ReadonlyArray<TaggedSchema>,
6140
6426
  Emits extends ReadonlyArray<TaggedSchema>,
6141
6427
  StateId extends StateIdentifier<States>,
6142
6428
  InputEvents extends ReadonlyArray<TaggedSchema>,
6143
6429
  ParentEvents extends ReadonlyArray<TaggedSchema>,
6144
- Raw
6145
- > = Raw extends InvokeTyped<any, any, any, any, any> ? unknown
6146
- : [Extract<keyof Raw, "onDone" | "onFailure" | "onElement" | "onSnapshot">] extends [never] ? unknown
6147
- : Raw extends { readonly effect: infer Source } ?
6148
- InvokeFactoryResult<Source> extends infer Fx extends Effect.Effect<any, any, any> ?
6149
- & InvokeDoneRequirement<
6150
- Effect.Success<Fx>,
6151
- InvokeTransition<
6152
- States,
6153
- Events,
6154
- Emits,
6155
- StateId,
6156
- InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<Fx>, InputEvents, ParentEvents>
6157
- >
6158
- >
6159
- & InvokeFailureRequirement<
6160
- Effect.Error<Fx>,
6161
- InvokeTransition<
6162
- States,
6163
- Events,
6164
- Emits,
6165
- StateId,
6166
- InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<Fx>, InputEvents, ParentEvents>
6167
- >
6168
- >
6169
- & { readonly onSnapshot?: never }
6170
- : never
6171
- : Raw extends { readonly stream: infer Source } ?
6172
- InvokeFactoryResult<Source> extends infer SourceStream extends Stream.Stream<any, any, any> ?
6173
- & InvokeElementRequirement<
6174
- Stream.Success<SourceStream>,
6175
- InvokeTransition<
6176
- States,
6177
- Events,
6178
- Emits,
6179
- StateId,
6180
- InvokeElementContext<
6181
- States,
6182
- Events,
6183
- Emits,
6184
- StateId,
6185
- Stream.Success<SourceStream>,
6186
- InputEvents,
6187
- ParentEvents
6188
- >
6189
- >
6190
- >
6191
- & {
6192
- readonly onDone: InvokeTransition<
6193
- States,
6194
- Events,
6195
- Emits,
6196
- StateId,
6197
- InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>
6198
- >
6199
- }
6200
- & InvokeFailureRequirement<
6201
- Stream.Error<SourceStream>,
6202
- InvokeTransition<
6203
- States,
6204
- Events,
6205
- Emits,
6206
- StateId,
6207
- InvokeFailureContext<
6208
- States,
6209
- Events,
6210
- Emits,
6211
- StateId,
6212
- Stream.Error<SourceStream>,
6213
- InputEvents,
6214
- ParentEvents
6215
- >
6216
- >
6217
- >
6218
- & { readonly onSnapshot?: never }
6219
- : never
6220
- : Raw extends { readonly after: unknown } ? {
6221
- readonly onDone: InvokeTransition<
6222
- States,
6223
- Events,
6224
- Emits,
6225
- StateId,
6226
- InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>
6227
- >
6228
- readonly onFailure?: never
6229
- readonly onSnapshot?: never
6230
- }
6231
- : Raw extends { readonly logic: infer Source; readonly address: infer Address } ?
6232
- InvokeResolvedSource<Source> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ?
6233
- & InvokeDoneRequirement<
6234
- InvokeOutput<Raw>,
6235
- InvokeTransition<
6236
- States,
6237
- Events,
6238
- Emits,
6239
- StateId,
6240
- InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>, InputEvents, ParentEvents>
6241
- >
6242
- >
6243
- & InvokeFailureRequirement<
6244
- InvokeRuntimeError<Raw>,
6245
- InvokeTransition<
6246
- States,
6247
- Events,
6248
- Emits,
6249
- StateId,
6250
- InvokeFailureContext<
6251
- States,
6252
- Events,
6253
- Emits,
6254
- StateId,
6255
- InvokeRuntimeError<Raw>,
6256
- InputEvents,
6257
- ParentEvents
6258
- >
6259
- >
6260
- >
6261
- & {
6262
- readonly address:
6263
- & ChildAddress<never>
6264
- & ChildAddress.Compatibility<
6265
- Address,
6266
- ChildLogic extends Logic<any, infer ChildEvent, any, any, any, any> ? ChildEvent : never
6267
- >
6268
- readonly onSnapshot?: InvokeTransition<
6269
- States,
6270
- Events,
6271
- Emits,
6272
- StateId,
6273
- InvokeSnapshotContext<
6274
- States,
6275
- Events,
6276
- Emits,
6277
- StateId,
6278
- ChildLogic extends Logic<infer ChildState, any, any, any, any, any> ? ChildState : never,
6279
- InvokeRuntimeError<Raw>,
6280
- InvokeOutput<Raw>,
6281
- InputEvents,
6282
- ParentEvents
6283
- >
6284
- >
6285
- }
6286
- : never
6287
- : Raw extends { readonly child: infer Child extends ChildMachine<string, infer ChildDefinition> } ?
6288
- ChildMachineLogic<Child> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ?
6289
- & InvokeDoneRequirement<
6290
- Output<ChildDefinition>,
6291
- InvokeTransition<
6292
- States,
6293
- Events,
6294
- Emits,
6295
- StateId,
6296
- InvokeDoneContext<
6297
- States,
6298
- Events,
6299
- Emits,
6300
- StateId,
6301
- Output<ChildDefinition>,
6302
- InputEvents,
6303
- ParentEvents
6304
- >
6305
- >
6306
- >
6307
- & InvokeFailureRequirement<
6308
- Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
6309
- InvokeTransition<
6310
- States,
6311
- Events,
6312
- Emits,
6313
- StateId,
6314
- InvokeFailureContext<
6315
- States,
6316
- Events,
6317
- Emits,
6318
- StateId,
6319
- Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
6320
- InputEvents,
6321
- ParentEvents
6322
- >
6323
- >
6324
- >
6325
- & (Input<ChildDefinition> extends typeof Schema.Void ? { readonly input?: never } : {
6326
- readonly input: InvokeSource<
6327
- Input<ChildDefinition>["Type"],
6328
- InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6329
- >
6330
- })
6331
- & {
6332
- readonly onSnapshot?: InvokeTransition<
6333
- States,
6334
- Events,
6335
- Emits,
6336
- StateId,
6337
- InvokeSnapshotContext<
6338
- States,
6339
- Events,
6340
- Emits,
6341
- StateId,
6342
- Snapshot<Machine.States<ChildDefinition>>,
6343
- Error<ChildDefinition>,
6344
- Output<ChildDefinition>,
6345
- InputEvents,
6346
- ParentEvents
6347
- >
6348
- >
6349
- }
6350
- : never
6351
- : never
6430
+ Child extends ChildMachine.Any,
6431
+ ChildDefinition extends Machine.Any = Child["machine"]
6432
+ > = InvokeBuilder<
6433
+ States,
6434
+ Events,
6435
+ Emits,
6436
+ StateId,
6437
+ InputEvents,
6438
+ ParentEvents,
6439
+ Output<ChildDefinition>,
6440
+ Error<ChildDefinition> | ActionError<Services<ChildDefinition>>,
6441
+ Services<ChildDefinition>,
6442
+ InitialError<ChildDefinition>,
6443
+ Emit<ChildDefinition>,
6444
+ EventOf<Machine.ParentEvents<ChildDefinition>>,
6445
+ never,
6446
+ | RequiredInvokeChannel<Output<ChildDefinition>, "done">
6447
+ | RequiredInvokeChannel<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, "failure">,
6448
+ InvokeTransition<
6449
+ States,
6450
+ Events,
6451
+ Emits,
6452
+ StateId,
6453
+ InvokeSnapshotContext<
6454
+ States,
6455
+ Events,
6456
+ Emits,
6457
+ StateId,
6458
+ Snapshot<Machine.States<ChildDefinition>>,
6459
+ Error<ChildDefinition>,
6460
+ Output<ChildDefinition>,
6461
+ InputEvents,
6462
+ ParentEvents
6463
+ >
6464
+ >
6465
+ >
6352
6466
 
6353
- type ContextualInvokeDefinition<
6467
+ /**
6468
+ * Selects state-owned work and begins its lifecycle-handler chain.
6469
+ *
6470
+ * Each source exposes exactly the lifecycle methods that it can produce. A
6471
+ * chain becomes returnable from `invoke` only after every reachable required
6472
+ * channel has been handled.
6473
+ *
6474
+ * **Example** (Invoking an Effect)
6475
+ *
6476
+ * ```ts
6477
+ * invoke: (from) =>
6478
+ * from.effect("load-user", () => loadUser).onDone((to) =>
6479
+ * to.full.Ready().resolve(({ output, target }) => target.from({ user: output }))
6480
+ * ).onFailure((to) =>
6481
+ * to.full.Failed().resolve(({ error, target }) => target.from({ error }))
6482
+ * )
6483
+ * ```
6484
+ *
6485
+ * @inlineType EffectInvokeBuilder
6486
+ * @inlineType StreamInvokeBuilder
6487
+ * @inlineType LogicInvokeBuilder
6488
+ * @inlineType ChildInvokeBuilder
6489
+ * @inlineType InvokeBuilder
6490
+ *
6491
+ * @category models
6492
+ * @since 0.18.0
6493
+ */
6494
+ export interface InvokeSelector<
6354
6495
  States extends StateSchemas,
6355
6496
  Events extends ReadonlyArray<TaggedSchema>,
6356
6497
  Emits extends ReadonlyArray<TaggedSchema>,
6357
6498
  StateId extends StateIdentifier<States>,
6358
- InputEvents extends ReadonlyArray<TaggedSchema>,
6359
- ParentEvents extends ReadonlyArray<TaggedSchema>,
6360
- Raw
6361
- > = Raw extends ReadonlyArray<any> ? {
6362
- readonly [Index in keyof Raw]: ContextualInvokeConfig<
6499
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6500
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6501
+ > {
6502
+ /**
6503
+ * Starts a fresh Effect each time the owning state is entered.
6504
+ *
6505
+ * @param id Parent-local lifecycle identifier.
6506
+ * @param source Lazy Effect factory evaluated on every entry.
6507
+ */
6508
+ readonly effect: <
6509
+ const Source extends (
6510
+ context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6511
+ ) => Effect.Effect<unknown, unknown, unknown>
6512
+ >(
6513
+ id: InvokeLifecycleId,
6514
+ source: Source
6515
+ ) => EffectInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>
6516
+
6517
+ /**
6518
+ * Starts a fresh, backpressured Stream each time the owning state is entered.
6519
+ *
6520
+ * @param id Parent-local lifecycle identifier.
6521
+ * @param source Lazy Stream factory evaluated on every entry.
6522
+ */
6523
+ readonly stream: <
6524
+ const Source extends (
6525
+ context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6526
+ ) => Stream.Stream<unknown, unknown, any>
6527
+ >(
6528
+ id: InvokeLifecycleId,
6529
+ source: Source
6530
+ ) => StreamInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>
6531
+
6532
+ /**
6533
+ * Starts a cancellable state-scoped timer.
6534
+ *
6535
+ * @param id Parent-local lifecycle identifier.
6536
+ * @param duration Duration input or context-dependent duration factory.
6537
+ */
6538
+ readonly timer: (
6539
+ id: InvokeLifecycleId,
6540
+ duration: InvokeSource<
6541
+ Duration.Input,
6542
+ InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6543
+ >
6544
+ ) => InvokeBuilder<
6545
+ States,
6546
+ Events,
6547
+ Emits,
6548
+ StateId,
6549
+ InputEvents,
6550
+ ParentEvents,
6551
+ void,
6552
+ never,
6553
+ never,
6554
+ never,
6555
+ never,
6556
+ never,
6557
+ never,
6558
+ "done",
6559
+ never
6560
+ >
6561
+
6562
+ /**
6563
+ * Starts reusable process logic at a typed parent-local address.
6564
+ *
6565
+ * @param id Parent-local lifecycle identifier.
6566
+ * @param options Address and reusable logic value or factory.
6567
+ */
6568
+ readonly logic: {
6569
+ <
6570
+ const Source extends (
6571
+ context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6572
+ ) => unknown,
6573
+ Address extends ChildAddress<never>
6574
+ >(
6575
+ id: InvokeLifecycleId,
6576
+ options: {
6577
+ /** Typed parent-local address used to send events to this logic. */
6578
+ readonly address:
6579
+ & Address
6580
+ & ChildAddress.Compatibility<Address, LogicEventOf<ReturnType<NoInfer<Source>>>>
6581
+ /** Context-dependent factory that returns reusable process logic. */
6582
+ readonly logic: Source
6583
+ },
6584
+ ..._validation: ReturnType<Source> extends { readonly initial: unknown; readonly run: unknown } ? [] : [
6585
+ "logic factory must return Machine.Logic"
6586
+ ]
6587
+ ): LogicInvokeBuilder<
6363
6588
  States,
6364
6589
  Events,
6365
6590
  Emits,
6366
6591
  StateId,
6367
6592
  InputEvents,
6368
6593
  ParentEvents,
6369
- Raw[Index]
6594
+ ReturnType<Source>
6595
+ >
6596
+ <const Source, Address extends ChildAddress<never>>(
6597
+ id: InvokeLifecycleId,
6598
+ options: {
6599
+ /** Typed parent-local address used to send events to this logic. */
6600
+ readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<NoInfer<Source>>>
6601
+ /** Reusable process logic started when the owning state enters. */
6602
+ readonly logic: Source
6603
+ },
6604
+ ..._validation: Source extends { readonly initial: unknown; readonly run: unknown } ? [] : [
6605
+ "logic must implement Machine.Logic"
6606
+ ]
6607
+ ): LogicInvokeBuilder<
6608
+ States,
6609
+ Events,
6610
+ Emits,
6611
+ StateId,
6612
+ InputEvents,
6613
+ ParentEvents,
6614
+ Source
6370
6615
  >
6371
6616
  }
6372
- : ContextualInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents, Raw>
6373
6617
 
6618
+ /**
6619
+ * Starts a complete child statechart represented by a reusable descriptor.
6620
+ *
6621
+ * @param child Reusable descriptor created with `Machine.child`.
6622
+ * @param options Input construction for a child with a non-void input schema.
6623
+ */
6624
+ readonly child: <const Child extends ChildMachine.Any>(
6625
+ child:
6626
+ & Child
6627
+ & (Child["machine"] extends EnsureExecutable<
6628
+ Machine.States<Child["machine"]>,
6629
+ Machine.UnhandledStates<Child["machine"]>,
6630
+ Machine.OutputStates<Child["machine"]>
6631
+ > ? unknown
6632
+ : never),
6633
+ ...options: InputSchema<Child["machine"]> extends typeof Schema.Void ? [options?: { readonly input?: never }]
6634
+ : [options: {
6635
+ /** Child input value or factory evaluated from the owning state context. */
6636
+ readonly input: InvokeSource<
6637
+ Input<Child["machine"]>,
6638
+ InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
6639
+ >
6640
+ }]
6641
+ ) => ChildInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Child>
6642
+ }
6643
+
6644
+ /**
6645
+ * Inline invocation declaration accepted by an active state handler.
6646
+ *
6647
+ * Return one completed source chain or an array of completed chains. Source
6648
+ * computations and child descriptors may be extracted, but the chain stays
6649
+ * local to preserve the owning state and machine protocols.
6650
+ *
6651
+ * @category models
6652
+ * @since 0.18.0
6653
+ */
6654
+ export type InvokeBuilderInput<
6655
+ States extends StateSchemas,
6656
+ Events extends ReadonlyArray<TaggedSchema>,
6657
+ Emits extends ReadonlyArray<TaggedSchema>,
6658
+ StateId extends StateIdentifier<States>,
6659
+ InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6660
+ ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6661
+ > = (
6662
+ from: InvokeSelector<States, Events, Emits, StateId, InputEvents, ParentEvents>
6663
+ ) =>
6664
+ | (InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
6665
+ readonly [InvokeBuilderTypeId]: true
6666
+ })
6667
+ | ReadonlyArray<
6668
+ InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
6669
+ readonly [InvokeBuilderTypeId]: true
6670
+ }
6671
+ >
6672
+
6673
+ /** Output construction available to final and output-producing parallel states. */
6374
6674
  type OutputHandlerConfig<
6375
6675
  States extends StateSchemas,
6376
6676
  Events extends ReadonlyArray<TaggedSchema>,
6377
6677
  StateId extends StateIdentifier<States>,
6378
6678
  Context
6379
6679
  > = NodeByIdentifier<States, StateId> extends { readonly output: Schema.Top } ? {
6680
+ /** Constructs the decoded output declared by the state's `output` schema. */
6380
6681
  readonly output: (context: Context) => OutputByIdentifier<States, StateId>
6381
6682
  }
6382
6683
  : {
@@ -6400,6 +6701,22 @@ export declare namespace Machine {
6400
6701
  /**
6401
6702
  * Configuration accepted for a non-final state.
6402
6703
  *
6704
+ * **Example** (State actions, events, and invocation)
6705
+ *
6706
+ * ```ts
6707
+ * machine.handle({
6708
+ * Loading: {
6709
+ * entry: (_, enqueue) => enqueue.emit({ _tag: "Started" }),
6710
+ * invoke: (from) =>
6711
+ * from.effect("load", () => load).onDone((to) => to.full.Ready()),
6712
+ * on: { Cancel: (to) => to.full.Idle() }
6713
+ * }
6714
+ * })
6715
+ * ```
6716
+ *
6717
+ * @inlineType ActiveOutputHandlerConfig
6718
+ * @inlineType OutputHandlerConfig
6719
+ *
6403
6720
  * @category models
6404
6721
  * @since 0.4.0
6405
6722
  */
@@ -6413,17 +6730,19 @@ export declare namespace Machine {
6413
6730
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6414
6731
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6415
6732
  > = {
6733
+ /** Runs synchronously when the state is entered and may enqueue commands. */
6416
6734
  readonly entry?: (
6417
6735
  context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
6418
6736
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
6419
6737
  ) => StateActionResult<any, any>
6738
+ /** Runs synchronously before the state is exited and may enqueue commands. */
6420
6739
  readonly exit?: (
6421
6740
  context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
6422
6741
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
6423
6742
  ) => StateActionResult<any, any>
6424
- readonly invoke?:
6425
- | InvokeDefinition<States, Events, Emits, StateId, InputEvents, ParentEvents>
6426
- | TypedInvokeDefinition
6743
+ /** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
6744
+ readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>
6745
+ /** Eventless transition evaluated after the state becomes stable. */
6427
6746
  readonly always?: TransitionConfig<
6428
6747
  States,
6429
6748
  Events,
@@ -6433,6 +6752,7 @@ export declare namespace Machine {
6433
6752
  false,
6434
6753
  TransitionAcceptance
6435
6754
  >
6755
+ /** Transition evaluated after this compound or parallel state completes. */
6436
6756
  readonly onDone?: TransitionConfig<
6437
6757
  States,
6438
6758
  Events,
@@ -6442,6 +6762,7 @@ export declare namespace Machine {
6442
6762
  false,
6443
6763
  TransitionAcceptance
6444
6764
  >
6765
+ /** Event handlers keyed by the `_tag` of the machine's public or internal events. */
6445
6766
  readonly on?: {
6446
6767
  readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<
6447
6768
  States,
@@ -6453,6 +6774,7 @@ export declare namespace Machine {
6453
6774
  TransitionAcceptance
6454
6775
  >
6455
6776
  }
6777
+ /** Supplies missing direct initial-child values required by implicit entry and shallow history. */
6456
6778
  readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>
6457
6779
  } & ActiveOutputHandlerConfig<States, Events, StateId>
6458
6780
 
@@ -6577,8 +6899,11 @@ export declare namespace Machine {
6577
6899
  Emits extends ReadonlyArray<TaggedSchema>,
6578
6900
  ParentId extends StateIdentifier<States>
6579
6901
  > {
6902
+ /** Lifecycle event that attempted to restore this history node. */
6580
6903
  readonly event: LifecycleEvent<Events>
6904
+ /** Complete target builder rooted at the history owner. */
6581
6905
  readonly target: HistoryDefaultTargetBuilder<States, ParentId>
6906
+ /** State path whose child configuration is restored by this history node. */
6582
6907
  readonly owner: ParentId
6583
6908
  }
6584
6909
 
@@ -6601,7 +6926,26 @@ export declare namespace Machine {
6601
6926
  | CompleteSnapshotContaining<States, ParentId>
6602
6927
  | StateConstruction<CompleteSnapshotContaining<States, ParentId>>
6603
6928
 
6604
- /** Default implementations keyed by direct history child. */
6929
+ /**
6930
+ * Fallback implementation for one direct history pseudo-state.
6931
+ *
6932
+ * @inline
6933
+ */
6934
+ interface HistoryDefaultEntry<
6935
+ States extends StateSchemas,
6936
+ Events extends ReadonlyArray<TaggedSchema>,
6937
+ Emits extends ReadonlyArray<TaggedSchema>,
6938
+ ParentId extends StateIdentifier<States>
6939
+ > {
6940
+ /** Builds the complete fallback configuration used before history is first captured. */
6941
+ readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>
6942
+ }
6943
+
6944
+ /**
6945
+ * Default implementations keyed by direct history child.
6946
+ *
6947
+ * @inlineType HistoryDefaultEntry
6948
+ */
6605
6949
  export type HistoryDefaultConfig<
6606
6950
  States extends StateSchemas,
6607
6951
  Events extends ReadonlyArray<TaggedSchema>,
@@ -6609,9 +6953,7 @@ export declare namespace Machine {
6609
6953
  ParentId extends StateIdentifier<States>,
6610
6954
  Children extends StateSchemas
6611
6955
  > = {
6612
- readonly [Key in HistoryStateKey<Children>]?: {
6613
- readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>
6614
- }
6956
+ readonly [Key in HistoryStateKey<Children>]?: HistoryDefaultEntry<States, Events, Emits, ParentId>
6615
6957
  }
6616
6958
 
6617
6959
  /** Required implementation for a choice pseudo-state. */
@@ -6623,6 +6965,7 @@ export declare namespace Machine {
6623
6965
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6624
6966
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6625
6967
  > {
6968
+ /** Required transition that resolves this transient choice to a concrete destination. */
6626
6969
  readonly choice: TransitionConfig<
6627
6970
  States,
6628
6971
  Events,
@@ -6643,6 +6986,8 @@ export declare namespace Machine {
6643
6986
  /**
6644
6987
  * Configuration accepted for a final state.
6645
6988
  *
6989
+ * @inlineType OutputHandlerConfig
6990
+ *
6646
6991
  * @category models
6647
6992
  * @since 0.4.0
6648
6993
  */
@@ -6654,6 +6999,7 @@ export declare namespace Machine {
6654
6999
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6655
7000
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6656
7001
  > = {
7002
+ /** Runs synchronously when the final state is entered and may enqueue commands. */
6657
7003
  readonly entry?: (
6658
7004
  context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
6659
7005
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
@@ -6727,55 +7073,6 @@ export declare namespace Machine {
6727
7073
  : Path extends keyof Config ? Config[Path]
6728
7074
  : never
6729
7075
 
6730
- type HandlerInvokeContextAtPath<
6731
- AllStates extends StateSchemas,
6732
- Events extends ReadonlyArray<TaggedSchema>,
6733
- InputEvents extends ReadonlyArray<TaggedSchema>,
6734
- Emits extends ReadonlyArray<TaggedSchema>,
6735
- ParentEvents extends ReadonlyArray<TaggedSchema>,
6736
- Config,
6737
- StateId extends StateNodeIdentifier<AllStates>,
6738
- NodeConfig = HandlerConfigAtPath<Config, StateId>
6739
- > = StateId extends StateIdentifier<AllStates> ?
6740
- NodeConfig extends { readonly invoke: infer Invoke } ? HandlerValidationAtPath<
6741
- StateId,
6742
- {
6743
- readonly invoke: ContextualInvokeDefinition<
6744
- AllStates,
6745
- Events,
6746
- Emits,
6747
- StateId,
6748
- InputEvents,
6749
- ParentEvents,
6750
- Invoke
6751
- >
6752
- }
6753
- >
6754
- : unknown
6755
- : unknown
6756
-
6757
- type HandlerInvokeContexts<
6758
- AllStates extends StateSchemas,
6759
- Events extends ReadonlyArray<TaggedSchema>,
6760
- InputEvents extends ReadonlyArray<TaggedSchema>,
6761
- Emits extends ReadonlyArray<TaggedSchema>,
6762
- ParentEvents extends ReadonlyArray<TaggedSchema>,
6763
- Config
6764
- > = Types.UnionToIntersection<
6765
- StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ?
6766
- StateId extends StateNodeIdentifier<AllStates> ? HandlerInvokeContextAtPath<
6767
- AllStates,
6768
- Events,
6769
- InputEvents,
6770
- Emits,
6771
- ParentEvents,
6772
- Config,
6773
- StateId
6774
- >
6775
- : never
6776
- : never
6777
- >
6778
-
6779
7076
  // Rebuild the public nested handler shape so branded validation errors stay
6780
7077
  // attached to the exact property that introduced them.
6781
7078
  type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
@@ -6785,6 +7082,7 @@ export declare namespace Machine {
6785
7082
  }
6786
7083
  : { readonly [Key in Path]?: Validation }
6787
7084
 
7085
+ /** Nested handler-tree structure shared by active and final state configs. */
6788
7086
  type HandlerNode<
6789
7087
  AllStates extends StateSchemas,
6790
7088
  Node,
@@ -6806,6 +7104,7 @@ export declare namespace Machine {
6806
7104
  readonly history?: never
6807
7105
  }
6808
7106
  : {
7107
+ /** Child-state handlers nested according to the declared state topology. */
6809
7108
  readonly states?: HandlerTree<
6810
7109
  AllStates,
6811
7110
  Children,
@@ -6817,6 +7116,7 @@ export declare namespace Machine {
6817
7116
  ParentEvents,
6818
7117
  Extract<StateId, StateIdentifier<AllStates>>
6819
7118
  >
7119
+ /** First-use defaults keyed by direct history pseudo-state. */
6820
7120
  readonly history?: HistoryDefaultConfig<
6821
7121
  AllStates,
6822
7122
  Events,
@@ -7375,7 +7675,6 @@ export declare namespace Machine {
7375
7675
  >(
7376
7676
  config:
7377
7677
  & Config
7378
- & HandlerInvokeContexts<States, Events, InputEvents, Emits, ParentEvents, NoInfer<Config>>
7379
7678
  & HandlerTreeValidation<
7380
7679
  States,
7381
7680
  Events,
@@ -7474,7 +7773,7 @@ export declare namespace Machine {
7474
7773
  context: StateActionContext<States, Events, Emits, StateId>,
7475
7774
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
7476
7775
  ) => StateActionResult<E, R>
7477
- readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>
7776
+ readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>
7478
7777
  readonly always?: TransitionConfig<
7479
7778
  States,
7480
7779
  Events,
@@ -7522,15 +7821,49 @@ export declare namespace Machine {
7522
7821
  >
7523
7822
  }
7524
7823
 
7824
+ type StateSource = Machine.DefinedStates<any> | Machine.Any
7825
+
7826
+ type StateSchemasOf<Source extends StateSource> = Source extends Machine.DefinedStates<infer States> ? States
7827
+ : Source extends Machine.Any ? Machine.States<Source>
7828
+ : never
7829
+
7525
7830
  /**
7526
- * Extracts the complete logical snapshot represented by a state definition.
7831
+ * Extracts the complete logical snapshot represented by a state definition or
7832
+ * machine.
7527
7833
  *
7528
7834
  * @category utility types
7529
7835
  * @since 0.15.0
7530
7836
  */
7531
- export type Snapshot<Defined extends Machine.DefinedStates<any>> = Defined extends Machine.DefinedStates<infer States>
7532
- ? Machine.Snapshot<States>
7533
- : never
7837
+ export type Snapshot<Source extends StateSource> = Machine.Snapshot<StateSchemasOf<Source>>
7838
+
7839
+ /**
7840
+ * Extracts the decoded value owned by a schema-backed state path.
7841
+ *
7842
+ * The source may be the object returned by {@link states} or a machine
7843
+ * definition. Control-only state paths are intentionally excluded.
7844
+ *
7845
+ * @category utility types
7846
+ * @since 0.18.0
7847
+ */
7848
+ export type Value<
7849
+ Source extends StateSource,
7850
+ Path extends Machine.ValuedStateIdentifier<StateSchemasOf<Source>>
7851
+ > = Machine.StateByIdentifier<StateSchemasOf<Source>, Path>
7852
+
7853
+ /**
7854
+ * Extracts the logical snapshot rooted at a state path.
7855
+ *
7856
+ * The source may be the object returned by {@link states} or a machine
7857
+ * definition. This is the type-level counterpart of
7858
+ * `DefinedStates.getSnapshot`.
7859
+ *
7860
+ * @category utility types
7861
+ * @since 0.18.0
7862
+ */
7863
+ export type SnapshotAt<
7864
+ Source extends StateSource,
7865
+ Path extends Machine.StateIdentifier<StateSchemasOf<Source>>
7866
+ > = Machine.SnapshotByIdentifier<StateSchemasOf<Source>, Path>
7534
7867
 
7535
7868
  /**
7536
7869
  * Returns `true` if a value is a `Machine`.
@@ -7667,20 +8000,28 @@ type MakeConfig<
7667
8000
  InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
7668
8001
  ParentDeclaration extends Parent.Any | undefined
7669
8002
  > = {
8003
+ /** Stable definition identifier used by inspection and visualization. */
7670
8004
  readonly id?: string
8005
+ /** State topology and value schemas, normally supplied by `Machine.states`. */
7671
8006
  readonly states: States & DefineStateTreeInput<NoInfer<States>>
8007
+ /** Public events accepted by independently running machine references. */
7672
8008
  readonly events:
7673
8009
  & Machine.EventProtocol<"public", InputEvents>
7674
8010
  & ValidateInputEventProtocol<NoInfer<InputEvents>>
8011
+ /** Machine-local events used by raised events and other internal deliveries. */
7675
8012
  readonly internalEvents?:
7676
8013
  & Machine.EventProtocol<"internal", InternalEvents>
7677
8014
  & ValidateInternalEventProtocol<
7678
8015
  NoInfer<InputEvents>,
7679
8016
  NoInfer<InternalEvents>
7680
8017
  >
8018
+ /** Ephemeral notifications that handlers may publish to observers. */
7681
8019
  readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>
8020
+ /** Required or optional owning-machine protocol for this definition. */
7682
8021
  readonly parent?: ParentDeclaration
8022
+ /** Schema used to decode input before initial-state construction. */
7683
8023
  readonly input?: Input
8024
+ /** Target-first declaration that constructs the initial active configuration. */
7684
8025
  readonly initial: unknown
7685
8026
  }
7686
8027
 
@@ -7706,7 +8047,9 @@ type MakeResult<
7706
8047
  Machine.ParentEventsOf<ParentDeclaration>
7707
8048
  >
7708
8049
 
8050
+ /** @inline */
7709
8051
  interface Make {
8052
+ /** @param config Complete schema-first machine definition. */
7710
8053
  <
7711
8054
  const States extends Machine.StateSchemas,
7712
8055
  const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
@@ -7725,6 +8068,7 @@ interface Make {
7725
8068
  & { readonly initial: Machine.InitialBuilderInput<States, Input["Type"]> },
7726
8069
  ..._validation: ValidateDefinedStates<NoInfer<States>>
7727
8070
  ): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>
8071
+ /** @param config Invalid state tree retained only to report its validation error at the call site. */
7728
8072
  <
7729
8073
  const States extends Machine.StateSchemas,
7730
8074
  const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
@@ -7802,6 +8146,7 @@ interface Make {
7802
8146
  * ```
7803
8147
  *
7804
8148
  * @see {@link states} for typed state-tree helpers.
8149
+ * @inlineType MakeConfig
7805
8150
  * @category constructors
7806
8151
  * @since 0.4.0
7807
8152
  */
@@ -7952,18 +8297,21 @@ export const emittedEvents: {
7952
8297
  *
7953
8298
  * **Details**
7954
8299
  *
7955
- * Each active state value and completed output is encoded with the schema
7956
- * declared for its state path. The result contains no process-local runtime
7957
- * state.
8300
+ * Each active state value and completed output is encoded with the canonical
8301
+ * JSON codec derived from the schema declared for its state path. Success
8302
+ * guarantees that every state, output, and history value is `Schema.Json`.
8303
+ * Non-JSON values, including cyclic process-local capabilities, fail with
8304
+ * {@link MachineSchemaEncodeError} at their declared boundary.
7958
8305
  *
7959
8306
  * **Gotchas**
7960
8307
  *
7961
8308
  * The encoded snapshot does not contain the machine definition, machine
7962
8309
  * version, running children, invoked process state, services, or subscriptions.
7963
8310
  * Store machine identity and migration metadata alongside the result when the
7964
- * snapshot crosses deployment versions. Schema encoding does not by itself
7965
- * guarantee JSON-compatible values; schemas used with JSON-backed storage must
7966
- * have JSON-compatible encoded representations.
8311
+ * snapshot crosses deployment versions. Opaque declarations without a JSON
8312
+ * codec can encode only when their current value is already JSON-compatible.
8313
+ * Define an explicit JSON codec or keep process-local capabilities outside the
8314
+ * logical snapshot.
7967
8315
  *
7968
8316
  * **Example**
7969
8317
  *
@@ -8111,199 +8459,6 @@ export const decodeSnapshot: <
8111
8459
  Machine.SnapshotDecodingServices<States>
8112
8460
  > = internal.decodeSnapshot as any
8113
8461
 
8114
- type EffectInvokeSource<
8115
- States extends Machine.StateSchemas,
8116
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8117
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8118
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8119
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8120
- StateId extends Machine.StateIdentifier<States>,
8121
- Source extends (
8122
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8123
- ) => Effect.Effect<unknown, unknown, unknown>
8124
- > = {
8125
- readonly id: InvokeLifecycleId
8126
- readonly effect: Source
8127
- readonly stream?: never
8128
- readonly after?: never
8129
- readonly logic?: never
8130
- readonly child?: never
8131
- readonly address?: never
8132
- readonly onElement?: never
8133
- readonly onSnapshot?: never
8134
- }
8135
-
8136
- type EffectDoneHandler<
8137
- States extends Machine.StateSchemas,
8138
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8139
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8140
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8141
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8142
- StateId extends Machine.StateIdentifier<States>,
8143
- Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
8144
- > = Machine.InvokeTransition<
8145
- States,
8146
- Events,
8147
- Emits,
8148
- StateId,
8149
- Machine.InvokeDoneContext<
8150
- States,
8151
- Events,
8152
- Emits,
8153
- StateId,
8154
- Effect.Success<ReturnType<NoInfer<Source>>>,
8155
- InputEvents,
8156
- ParentEvents
8157
- >
8158
- >
8159
-
8160
- type EffectFailureHandler<
8161
- States extends Machine.StateSchemas,
8162
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8163
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8164
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8165
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8166
- StateId extends Machine.StateIdentifier<States>,
8167
- Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
8168
- > = Machine.InvokeTransition<
8169
- States,
8170
- Events,
8171
- Emits,
8172
- StateId,
8173
- Machine.InvokeFailureContext<
8174
- States,
8175
- Events,
8176
- Emits,
8177
- StateId,
8178
- Effect.Error<ReturnType<NoInfer<Source>>>,
8179
- InputEvents,
8180
- ParentEvents
8181
- >
8182
- >
8183
-
8184
- type EffectInvokeResult<
8185
- States extends Machine.StateSchemas,
8186
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8187
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8188
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8189
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8190
- StateId extends Machine.StateIdentifier<States>,
8191
- Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>
8192
- > =
8193
- & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents>
8194
- & Machine.InvokeTyped<
8195
- Effect.Success<ReturnType<Source>>,
8196
- Effect.Error<ReturnType<Source>>,
8197
- Effect.Services<ReturnType<Source>>,
8198
- never
8199
- >
8200
-
8201
- type StreamInvokeSource<
8202
- States extends Machine.StateSchemas,
8203
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8204
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8205
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8206
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8207
- StateId extends Machine.StateIdentifier<States>,
8208
- Source extends (...args: ReadonlyArray<any>) => unknown
8209
- > = {
8210
- readonly id: InvokeLifecycleId
8211
- readonly stream:
8212
- & Source
8213
- & ((context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown)
8214
- readonly effect?: never
8215
- readonly after?: never
8216
- readonly logic?: never
8217
- readonly child?: never
8218
- readonly address?: never
8219
- readonly onSnapshot?: never
8220
- }
8221
-
8222
- type StreamSourceResult<Source extends (...args: ReadonlyArray<any>) => unknown> = ReturnType<Source> extends
8223
- infer Result extends Stream.Stream<any, any, any> ? Result : never
8224
-
8225
- type StreamElementHandler<
8226
- States extends Machine.StateSchemas,
8227
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8228
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8229
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8230
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8231
- StateId extends Machine.StateIdentifier<States>,
8232
- Source extends (...args: ReadonlyArray<any>) => unknown
8233
- > = Machine.InvokeTransition<
8234
- States,
8235
- Events,
8236
- Emits,
8237
- StateId,
8238
- Machine.InvokeElementContext<
8239
- States,
8240
- Events,
8241
- Emits,
8242
- StateId,
8243
- Stream.Success<StreamSourceResult<NoInfer<Source>>>,
8244
- InputEvents,
8245
- ParentEvents
8246
- >
8247
- >
8248
-
8249
- type StreamDoneHandler<
8250
- States extends Machine.StateSchemas,
8251
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8252
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8253
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8254
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8255
- StateId extends Machine.StateIdentifier<States>
8256
- > = Machine.InvokeTransition<
8257
- States,
8258
- Events,
8259
- Emits,
8260
- StateId,
8261
- Machine.InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>
8262
- >
8263
-
8264
- type StreamFailureHandler<
8265
- States extends Machine.StateSchemas,
8266
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8267
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8268
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8269
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8270
- StateId extends Machine.StateIdentifier<States>,
8271
- Source extends (...args: ReadonlyArray<any>) => unknown
8272
- > = Machine.InvokeTransition<
8273
- States,
8274
- Events,
8275
- Emits,
8276
- StateId,
8277
- Machine.InvokeFailureContext<
8278
- States,
8279
- Events,
8280
- Emits,
8281
- StateId,
8282
- Stream.Error<StreamSourceResult<NoInfer<Source>>>,
8283
- InputEvents,
8284
- ParentEvents
8285
- >
8286
- >
8287
-
8288
- type StreamInvokeResult<
8289
- States extends Machine.StateSchemas,
8290
- Events extends ReadonlyArray<Machine.TaggedSchema>,
8291
- Emits extends ReadonlyArray<Machine.TaggedSchema>,
8292
- InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8293
- ParentEvents extends ReadonlyArray<Machine.TaggedSchema>,
8294
- StateId extends Machine.StateIdentifier<States>,
8295
- Source extends (...args: ReadonlyArray<any>) => unknown
8296
- > =
8297
- & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents>
8298
- & Machine.InvokeTyped<
8299
- void,
8300
- Stream.Error<StreamSourceResult<Source>>,
8301
- Stream.Services<StreamSourceResult<Source>>,
8302
- never
8303
- >
8304
-
8305
- type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false
8306
-
8307
8462
  type TransitionBranchRecordError<Message extends string, Key extends PropertyKey = never> = {
8308
8463
  readonly "~effect/Machine/TransitionBranchRecordError": Message
8309
8464
  readonly key: Key
@@ -8319,368 +8474,6 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
8319
8474
  InvalidStaticTransitionBranchKey<Branches>
8320
8475
  >
8321
8476
 
8322
- /**
8323
- * Preserves inference for a state-owned invocation configuration.
8324
- *
8325
- * Use `effect` for one-shot work, `stream` for repeated values, `after` for a
8326
- * cancellable timer, `logic` for reusable process logic, or `child` for a
8327
- * complete child machine. Stream elements are handled by `onElement` before
8328
- * the next element is pulled. `onDone` is required whenever the source can
8329
- * complete, while `onFailure` is required only when the source has a typed
8330
- * failure channel.
8331
- *
8332
- * This constructor is an identity at runtime, but preserves lifecycle callback
8333
- * inference through published declarations. Effect and Stream factories run
8334
- * when their owning state is entered and infer the owner context, value,
8335
- * output, error, and service channels together without a return annotation.
8336
- * Durations may be
8337
- * supplied directly or derived from the owning state's entry context. Logic
8338
- * invocations require both a lifecycle `id` and a typed communication
8339
- * `address`. Child descriptors already own their identity, so `id` and
8340
- * `address` must not be repeated.
8341
- *
8342
- * Inside `handle(...)`, the owning definition contextually supplies its public
8343
- * input and declared parent protocols. Invocation sources and lifecycle handlers
8344
- * can therefore send through `self` and `parent` without naming the definition.
8345
- * The standard `Machine.invoke(...)` constructor preserves these contexts
8346
- * directly; no intermediate definition method is required.
8347
- *
8348
- * ```ts
8349
- * invoke: Machine.invoke({
8350
- * id: "load",
8351
- * effect: () =>
8352
- * Effect.tryPromise({
8353
- * try: () => fetch("/api/data").then((response) => response.json()),
8354
- * catch: (cause) => new LoadError({ cause })
8355
- * }),
8356
- * onDone: (to) =>
8357
- * to.full.Ready().resolve(({ output, target }) =>
8358
- * target.from({ data: output })),
8359
- * onFailure: (to) =>
8360
- * to.full.Failed().resolve(({ error, target }) =>
8361
- * target.from({ error }))
8362
- * })
8363
- * ```
8364
- *
8365
- * @category constructors
8366
- * @since 0.9.0
8367
- */
8368
- export const invoke: {
8369
- <
8370
- const States extends Machine.StateSchemas,
8371
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8372
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8373
- StateId extends Machine.StateIdentifier<States>,
8374
- const Source extends (
8375
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8376
- ) => Effect.Effect<unknown, unknown, unknown>,
8377
- const Config extends object,
8378
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8379
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8380
- >(
8381
- config:
8382
- & Config
8383
- & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8384
- & {
8385
- readonly onDone: EffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8386
- readonly onFailure: EffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8387
- },
8388
- ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
8389
- "onDone must be omitted when the Effect output is never"
8390
- ]
8391
- : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
8392
- "onFailure must be omitted when the Effect error is never"
8393
- ]
8394
- : []
8395
- ): NoInfer<Config> & EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8396
- <
8397
- const States extends Machine.StateSchemas,
8398
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8399
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8400
- StateId extends Machine.StateIdentifier<States>,
8401
- const Source extends (
8402
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8403
- ) => Effect.Effect<unknown, never, unknown>,
8404
- const Config extends object,
8405
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8406
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8407
- >(
8408
- config:
8409
- & Config
8410
- & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8411
- & {
8412
- readonly onDone: EffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8413
- readonly onFailure?: never
8414
- },
8415
- ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
8416
- "onDone must be omitted when the Effect output is never"
8417
- ]
8418
- : []
8419
- ): NoInfer<Config> & EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8420
- <
8421
- const States extends Machine.StateSchemas,
8422
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8423
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8424
- StateId extends Machine.StateIdentifier<States>,
8425
- const Source extends (
8426
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8427
- ) => Effect.Effect<never, unknown, unknown>,
8428
- const Config extends object,
8429
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8430
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8431
- >(
8432
- config:
8433
- & Config
8434
- & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8435
- & {
8436
- readonly onDone?: never
8437
- readonly onFailure: EffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8438
- },
8439
- ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
8440
- "onFailure must be omitted when the Effect error is never"
8441
- ]
8442
- : []
8443
- ): NoInfer<Config> & EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8444
- <
8445
- const States extends Machine.StateSchemas,
8446
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8447
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8448
- StateId extends Machine.StateIdentifier<States>,
8449
- const Source extends (
8450
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8451
- ) => Effect.Effect<never, never, unknown>,
8452
- const Config extends object,
8453
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8454
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8455
- >(
8456
- config:
8457
- & Config
8458
- & EffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8459
- & {
8460
- readonly onDone?: never
8461
- readonly onFailure?: never
8462
- }
8463
- ): NoInfer<Config> & EffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8464
- <
8465
- const States extends Machine.StateSchemas,
8466
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8467
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8468
- StateId extends Machine.StateIdentifier<States>,
8469
- const Source extends (
8470
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8471
- ) => Stream.Stream<unknown, unknown, any>,
8472
- const Config extends object,
8473
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8474
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8475
- >(
8476
- config:
8477
- & Config
8478
- & StreamInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8479
- & {
8480
- readonly onElement: StreamElementHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8481
- readonly onDone: StreamDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId>
8482
- readonly onFailure: StreamFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8483
- },
8484
- ..._validation: InvokeChannelIsNever<Stream.Success<ReturnType<Source>>> extends true ? [
8485
- "onElement must be omitted when the Stream element is never"
8486
- ]
8487
- : InvokeChannelIsNever<Stream.Error<ReturnType<Source>>> extends true ? [
8488
- "onFailure must be omitted when the Stream error is never"
8489
- ]
8490
- : []
8491
- ): NoInfer<Config> & StreamInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8492
- <
8493
- const States extends Machine.StateSchemas,
8494
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8495
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8496
- StateId extends Machine.StateIdentifier<States>,
8497
- const Source extends (
8498
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8499
- ) => Stream.Stream<never, unknown, any>,
8500
- const Config extends object,
8501
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8502
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8503
- >(
8504
- config:
8505
- & Config
8506
- & StreamInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8507
- & {
8508
- readonly onElement?: never
8509
- readonly onDone: StreamDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId>
8510
- readonly onFailure: StreamFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8511
- },
8512
- ..._validation: InvokeChannelIsNever<Stream.Error<ReturnType<Source>>> extends true ? [
8513
- "onFailure must be omitted when the Stream error is never"
8514
- ]
8515
- : []
8516
- ): NoInfer<Config> & StreamInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8517
- <
8518
- const States extends Machine.StateSchemas,
8519
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8520
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8521
- StateId extends Machine.StateIdentifier<States>,
8522
- const Source extends (
8523
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8524
- ) => Stream.Stream<never, never, any>,
8525
- const Config extends object,
8526
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8527
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8528
- >(
8529
- config:
8530
- & Config
8531
- & StreamInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8532
- & {
8533
- readonly onElement?: never
8534
- readonly onDone: StreamDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId>
8535
- readonly onFailure?: never
8536
- }
8537
- ): NoInfer<Config> & StreamInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8538
- <
8539
- const States extends Machine.StateSchemas,
8540
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8541
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8542
- StateId extends Machine.StateIdentifier<States>,
8543
- const Source extends (
8544
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8545
- ) => Stream.Stream<unknown, never, any>,
8546
- const Config extends object,
8547
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8548
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8549
- >(
8550
- config:
8551
- & Config
8552
- & StreamInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8553
- & {
8554
- readonly onElement: StreamElementHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8555
- readonly onDone: StreamDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId>
8556
- readonly onFailure?: never
8557
- }
8558
- ): NoInfer<Config> & StreamInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>
8559
- <
8560
- const States extends Machine.StateSchemas,
8561
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8562
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8563
- StateId extends Machine.StateIdentifier<States>,
8564
- const Config extends object,
8565
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8566
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8567
- >(
8568
- config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, InputEvents, ParentEvents>
8569
- ):
8570
- & NoInfer<Config>
8571
- & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents>
8572
- & Machine.InvokeTyped<void, never, never, never>
8573
- <
8574
- const States extends Machine.StateSchemas,
8575
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8576
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8577
- StateId extends Machine.StateIdentifier<States>,
8578
- const Source extends (
8579
- context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
8580
- ) => unknown,
8581
- Address extends ChildAddress<never>,
8582
- const Config extends object,
8583
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8584
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8585
- >(
8586
- config:
8587
- & Config
8588
- & { readonly logic: Source }
8589
- & Machine.LogicInvokeArgs<
8590
- States,
8591
- Events,
8592
- Emits,
8593
- StateId,
8594
- Machine.LogicStateOf<ReturnType<Source>>,
8595
- Machine.LogicEventOf<ReturnType<Source>>,
8596
- Machine.LogicErrorOf<ReturnType<Source>>,
8597
- Machine.LogicServicesOf<ReturnType<Source>>,
8598
- Machine.LogicOutputOf<ReturnType<Source>>,
8599
- Machine.LogicInitialErrorOf<ReturnType<Source>>,
8600
- Address,
8601
- Source,
8602
- InputEvents,
8603
- ParentEvents
8604
- >,
8605
- ..._validation: ReturnType<Source> extends { readonly initial: unknown; readonly run: unknown } ? [] : [
8606
- "logic factory must return Machine.Logic"
8607
- ]
8608
- ):
8609
- & NoInfer<Config>
8610
- & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents>
8611
- & Machine.InvokeTyped<
8612
- Machine.LogicOutputOf<ReturnType<Source>>,
8613
- Machine.LogicErrorOf<ReturnType<Source>>,
8614
- Machine.LogicServicesOf<ReturnType<Source>>,
8615
- Machine.LogicInitialErrorOf<ReturnType<Source>>
8616
- >
8617
- <
8618
- const States extends Machine.StateSchemas,
8619
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8620
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8621
- StateId extends Machine.StateIdentifier<States>,
8622
- const Source,
8623
- Address extends ChildAddress<never>,
8624
- const Config extends object,
8625
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8626
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8627
- >(
8628
- config:
8629
- & Config
8630
- & { readonly logic: Source }
8631
- & Machine.LogicInvokeArgs<
8632
- States,
8633
- Events,
8634
- Emits,
8635
- StateId,
8636
- Machine.LogicStateOf<Source>,
8637
- Machine.LogicEventOf<Source>,
8638
- Machine.LogicErrorOf<Source>,
8639
- Machine.LogicServicesOf<Source>,
8640
- Machine.LogicOutputOf<Source>,
8641
- Machine.LogicInitialErrorOf<Source>,
8642
- Address,
8643
- Source,
8644
- InputEvents,
8645
- ParentEvents
8646
- >,
8647
- ..._validation: Source extends { readonly initial: unknown; readonly run: unknown } ? [] : [
8648
- "logic must implement Machine.Logic"
8649
- ]
8650
- ):
8651
- & NoInfer<Config>
8652
- & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents>
8653
- & Machine.InvokeTyped<
8654
- Machine.LogicOutputOf<Source>,
8655
- Machine.LogicErrorOf<Source>,
8656
- Machine.LogicServicesOf<Source>,
8657
- Machine.LogicInitialErrorOf<Source>
8658
- >
8659
- <
8660
- const States extends Machine.StateSchemas,
8661
- const Events extends ReadonlyArray<Machine.TaggedSchema>,
8662
- const Emits extends ReadonlyArray<Machine.TaggedSchema>,
8663
- StateId extends Machine.StateIdentifier<States>,
8664
- const Child extends ChildMachine.Any,
8665
- const Config extends object,
8666
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8667
- const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
8668
- >(
8669
- config:
8670
- & Config
8671
- & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child, InputEvents, ParentEvents>
8672
- ):
8673
- & Config
8674
- & Machine.InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents>
8675
- & Machine.InvokeTyped<
8676
- Machine.Output<Child["machine"]>,
8677
- Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>,
8678
- Machine.Services<Child["machine"]>,
8679
- Machine.InitialError<Child["machine"]>,
8680
- Machine.Emit<Child["machine"]>,
8681
- Machine.EventOf<Machine.ParentEvents<Child["machine"]>>
8682
- >
8683
- } = ((config: unknown) => config) as any
8684
8477
  /**
8685
8478
  * Plans the initial state for a machine without executing machine commands.
8686
8479
  *
@@ -9128,7 +8921,7 @@ export const child: <const Id extends string, M extends Machine.Any>(id: Id, mac
9128
8921
  * Creates a typed parent-local address for lower-level child process logic.
9129
8922
  *
9130
8923
  * The default event protocol is `never`; provide an event type before using
9131
- * the address with `spawn`, `invoke`, or `sendTo`.
8924
+ * the address with `spawn`, a state-owned logic invocation, or `sendTo`.
9132
8925
  *
9133
8926
  * @category constructors
9134
8927
  * @since 0.4.0
@@ -9149,7 +8942,8 @@ export const childAddress: <Event = never>(id: string) => ChildAddress<Event> =
9149
8942
  * This Effect requires a managed process runtime. A named child id must be
9150
8943
  * unique for the current parent until that child stops.
9151
8944
  *
9152
- * @see {@link invoke} for children that start and stop with a state.
8945
+ * Use a state's `invoke: (from) => from.logic(...)` declaration for children
8946
+ * that start and stop with that state.
9153
8947
  * @see {@link sendTo} for sending events to named children.
9154
8948
  * @category runtime
9155
8949
  * @since 0.4.0