@typeonce/effect-machine 0.18.0 → 0.19.1

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 (33) hide show
  1. package/README.md +54 -16
  2. package/dist/Machine.d.ts +300 -30
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +10 -6
  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/serialization.d.ts.map +1 -1
  11. package/dist/internal/machine/serialization.js +75 -18
  12. package/dist/internal/machine/serialization.js.map +1 -1
  13. package/dist/internal/testing/machine/verification.d.ts +1 -1
  14. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  15. package/dist/internal/testing/machine/verification.js +9 -6
  16. package/dist/internal/testing/machine/verification.js.map +1 -1
  17. package/dist/testing/MachineTest.d.ts +9 -6
  18. package/dist/testing/MachineTest.d.ts.map +1 -1
  19. package/dist/testing/MachineTest.js +5 -3
  20. package/dist/testing/MachineTest.js.map +1 -1
  21. package/dist/unstable/cluster/ClusterMachine.d.ts +22 -2
  22. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
  23. package/dist/unstable/cluster/ClusterMachine.js +4 -0
  24. package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
  25. package/docs/agent-guide.md +278 -1389
  26. package/docs/effect-atom-react.md +202 -0
  27. package/package.json +4 -4
  28. package/src/Machine.ts +315 -33
  29. package/src/internal/machine/cluster.ts +4 -1
  30. package/src/internal/machine/serialization.ts +100 -25
  31. package/src/internal/testing/machine/verification.ts +15 -10
  32. package/src/testing/MachineTest.ts +9 -6
  33. package/src/unstable/cluster/ClusterMachine.ts +51 -1
package/dist/Machine.d.ts CHANGED
@@ -183,6 +183,20 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
183
183
  * captured by value, so later mutation of the supplied objects cannot alter
184
184
  * the resulting machine.
185
185
  *
186
+ * **Example**
187
+ *
188
+ * ```ts
189
+ * const counter = definition.handle({
190
+ * Count: {
191
+ * on: {
192
+ * Increment: (to) =>
193
+ * to.full.Count().resolve(({ event, state, target }) =>
194
+ * target(new Count({ value: state.value + event.by })))
195
+ * }
196
+ * }
197
+ * })
198
+ * ```
199
+ *
186
200
  * @since 0.4.0
187
201
  */
188
202
  readonly handle: Machine.Handler<States, Events, Emits, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, never, InputEvents, ParentEvents>;
@@ -384,8 +398,10 @@ export type MachineReferences<InputEvents extends ReadonlyArray<Machine.TaggedSc
384
398
  } : {});
385
399
  /**
386
400
  * Synchronous commands available while a machine transition is being
387
- * selected. Enqueuing only records statechart and machine operations; it never
388
- * executes an Effect.
401
+ * selected.
402
+ *
403
+ * Enqueuing records statechart and machine operations for the selected
404
+ * transition. It never executes an Effect while the transition is evaluated.
389
405
  *
390
406
  * @category models
391
407
  * @since 0.4.0
@@ -925,6 +941,9 @@ export type RuntimeSnapshot<State, Error = never, Output = never> = {
925
941
  * one stream may contain unrelated root, child-machine, and `Logic` protocols.
926
942
  * The record structure remains a closed discriminated union, while typed
927
943
  * application observation continues through `changes` and `emissions`.
944
+ * Records retain decoded local events and snapshots and are not themselves a
945
+ * stable JSON export format. Telemetry exporters must project process-local
946
+ * values into an explicit portable representation.
928
947
  *
929
948
  * @category models
930
949
  * @since 0.13.0
@@ -1735,8 +1754,11 @@ export declare namespace Machine {
1735
1754
  * @since 0.4.0
1736
1755
  */
1737
1756
  interface StateNodeAnnotations extends Schema.Annotations.Annotations {
1757
+ /** Human-readable label used by visualization and documentation tooling. */
1738
1758
  readonly title?: string | undefined;
1759
+ /** Short explanation of the state node's domain meaning. */
1739
1760
  readonly description?: string | undefined;
1761
+ /** Longer documentation text associated with the state node. */
1740
1762
  readonly documentation?: string | undefined;
1741
1763
  }
1742
1764
  /** Descriptive annotations accepted by schema-less active and pseudo-states. */
@@ -1744,31 +1766,41 @@ export declare namespace Machine {
1744
1766
  /** @deprecated Use {@link SchemaLessStateAnnotations}. */
1745
1767
  type PseudoStateAnnotations = SchemaLessStateAnnotations;
1746
1768
  /**
1747
- * Configuration accepted for an atomic object state node. Omit `schema` when
1748
- * the state owns no value; a schema-less final may still declare `output`.
1769
+ * Configuration accepted for an atomic object state node.
1770
+ *
1771
+ * Omit `schema` when the state owns no value. A schema-less final may still
1772
+ * declare `output`.
1749
1773
  *
1750
1774
  * @category models
1751
1775
  * @since 0.4.0
1752
1776
  */
1753
1777
  type AtomicStateNodeConfig = {
1778
+ /** Tagged schema that owns the state's decoded value. */
1754
1779
  readonly schema: TaggedSchema;
1780
+ /** Declares an ordinary active state. Omitted values default to `"active"`. */
1755
1781
  readonly type?: "active";
1782
+ /** Atomic active states cannot declare terminal output. */
1756
1783
  readonly output?: never;
1784
+ /** Schema-backed states take their annotations from the schema. */
1757
1785
  readonly annotations?: never;
1758
1786
  } | {
1759
1787
  readonly schema: TaggedSchema;
1760
1788
  readonly type: "final";
1789
+ /** Optional schema describing the terminal value produced by this final state. */
1761
1790
  readonly output?: Schema.Top;
1762
1791
  readonly annotations?: never;
1763
1792
  } | {
1764
1793
  readonly schema?: never;
1765
1794
  readonly type?: "active";
1766
1795
  readonly output?: never;
1796
+ /** Descriptive metadata for a schema-less state. */
1767
1797
  readonly annotations?: SchemaLessStateAnnotations;
1768
1798
  } | {
1769
1799
  readonly schema?: never;
1770
1800
  readonly type: "final";
1801
+ /** Optional schema describing the terminal value produced by this final state. */
1771
1802
  readonly output?: Schema.Top;
1803
+ /** Descriptive metadata for a schema-less state. */
1772
1804
  readonly annotations?: SchemaLessStateAnnotations;
1773
1805
  };
1774
1806
  /**
@@ -1779,16 +1811,22 @@ export declare namespace Machine {
1779
1811
  * @since 0.4.0
1780
1812
  */
1781
1813
  type CompoundStateNodeConfig = {
1814
+ /** Tagged schema that owns the compound state's decoded value. */
1782
1815
  readonly schema: TaggedSchema;
1816
+ /** Compound states are ordinary active states. */
1783
1817
  readonly type?: "active";
1818
+ /** Direct child selected when the compound state is entered initially. */
1784
1819
  readonly initial: string;
1820
+ /** Nested state nodes owned by this compound state. */
1785
1821
  readonly states: StateTree;
1822
+ /** Schema-backed states take their annotations from the schema. */
1786
1823
  readonly annotations?: never;
1787
1824
  } | {
1788
1825
  readonly schema?: never;
1789
1826
  readonly type?: "active";
1790
1827
  readonly initial: string;
1791
1828
  readonly states: StateTree;
1829
+ /** Descriptive metadata for a schema-less state. */
1792
1830
  readonly annotations?: SchemaLessStateAnnotations;
1793
1831
  };
1794
1832
  /**
@@ -1799,16 +1837,22 @@ export declare namespace Machine {
1799
1837
  * @since 0.4.0
1800
1838
  */
1801
1839
  type ParallelStateNodeConfig = {
1840
+ /** Tagged schema that owns the parallel state's decoded value. */
1802
1841
  readonly schema: TaggedSchema;
1842
+ /** Selects parallel-region semantics for the node. */
1803
1843
  readonly type: "parallel";
1844
+ /** Optional schema describing the value produced after every region completes. */
1804
1845
  readonly output?: Schema.Top;
1846
+ /** Child regions that are entered and remain active simultaneously. */
1805
1847
  readonly states: StateTree;
1848
+ /** Schema-backed states take their annotations from the schema. */
1806
1849
  readonly annotations?: never;
1807
1850
  } | {
1808
1851
  readonly schema?: never;
1809
1852
  readonly type: "parallel";
1810
1853
  readonly output?: Schema.Top;
1811
1854
  readonly states: StateTree;
1855
+ /** Descriptive metadata for a schema-less state. */
1812
1856
  readonly annotations?: SchemaLessStateAnnotations;
1813
1857
  };
1814
1858
  /**
@@ -1824,9 +1868,16 @@ export declare namespace Machine {
1824
1868
  * @since 0.4.0
1825
1869
  */
1826
1870
  interface HistoryStateNodeConfig {
1871
+ /** Selects history pseudo-state semantics. */
1827
1872
  readonly type: "history";
1828
- /** Defaults to shallow history. */
1873
+ /**
1874
+ * Restores only the direct child for shallow history or the complete
1875
+ * descendant configuration for deep history.
1876
+ *
1877
+ * @defaultValue `"shallow"`
1878
+ */
1829
1879
  readonly history?: "shallow" | "deep";
1880
+ /** Descriptive metadata used by visualization and documentation tooling. */
1830
1881
  readonly annotations?: SchemaLessStateAnnotations;
1831
1882
  }
1832
1883
  /**
@@ -1840,7 +1891,9 @@ export declare namespace Machine {
1840
1891
  * @since 0.4.0
1841
1892
  */
1842
1893
  interface ChoiceStateNodeConfig {
1894
+ /** Selects transient choice pseudo-state semantics. */
1843
1895
  readonly type: "choice";
1896
+ /** Descriptive metadata used by visualization and documentation tooling. */
1844
1897
  readonly annotations?: SchemaLessStateAnnotations;
1845
1898
  }
1846
1899
  /**
@@ -2467,33 +2520,36 @@ export declare namespace Machine {
2467
2520
  */
2468
2521
  interface EncodedSnapshotState {
2469
2522
  readonly path: string;
2470
- readonly value?: unknown;
2523
+ readonly value?: Schema.Json;
2471
2524
  }
2472
2525
  /**
2473
2526
  * Encoded output for one completed state path in a normalized machine
2474
- * snapshot. An omitted output represents `undefined`.
2527
+ * snapshot. An omitted output means the final state declares no output
2528
+ * schema; a declared `Schema.Void` or `Schema.Undefined` output encodes as
2529
+ * canonical JSON `null`.
2475
2530
  *
2476
2531
  * @category models
2477
2532
  * @since 0.4.0
2478
2533
  */
2479
2534
  interface EncodedSnapshotCompletion {
2480
2535
  readonly path: string;
2481
- readonly output?: unknown;
2536
+ readonly output?: Schema.Json;
2482
2537
  }
2483
2538
  /** Encoded values and paths retained by one history pseudo-state. */
2484
2539
  interface EncodedSnapshotHistoryEntry {
2485
2540
  readonly mode: "shallow" | "deep";
2486
2541
  readonly active: ReadonlyArray<string>;
2487
- readonly values: Readonly<Record<string, unknown>>;
2542
+ readonly values: Readonly<Record<string, Schema.Json>>;
2488
2543
  }
2489
2544
  /**
2490
2545
  * Normalized data representation of a machine snapshot.
2491
2546
  *
2492
2547
  * **Details**
2493
2548
  *
2494
- * Active state and completion values use the encoded representations of
2495
- * their declared schemas. Runtime process state such as children, fibers,
2496
- * scopes, queues, and subscriptions is not included.
2549
+ * Active state and completion values use the canonical JSON representations
2550
+ * derived from their declared schemas. A successfully encoded snapshot is
2551
+ * safe to pass to JSON-backed persistence and transport. Runtime process state
2552
+ * such as children, fibers, scopes, queues, and subscriptions is not included.
2497
2553
  *
2498
2554
  * @category models
2499
2555
  * @since 0.4.0
@@ -2929,15 +2985,23 @@ export declare namespace Machine {
2929
2985
  };
2930
2986
  /**
2931
2987
  * Definition-time topology selector available to an ordinary transition.
2988
+ *
2932
2989
  * Topology-only instructions (`none`, declared `initial` and history
2933
- * selections, and `local.with`) are values. State and choice destinations
2934
- * remain callable selection methods.
2990
+ * selections, and `local.with`) are values.
2991
+ *
2992
+ * State and choice destinations remain callable selection methods so their
2993
+ * target-specific resolver APIs retain exact inference.
2935
2994
  */
2936
2995
  interface TargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
2996
+ /** Handles the trigger without selecting a destination. */
2937
2997
  readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none">;
2998
+ /** Selects a destination inside the nearest active compound scope. */
2938
2999
  readonly local: LocalTargetSelector<States, Source>;
3000
+ /** Selects a destination elsewhere under the currently active root. */
2939
3001
  readonly branch: BranchTargetSelector<States, Source>;
3002
+ /** Selects a complete destination under any top-level state. */
2940
3003
  readonly full: FullTargetSelector<States>;
3004
+ /** Restores a shallow or deep history pseudo-state. */
2941
3005
  readonly history: HistorySelectionTree<States, States, "", HistoryTargetBuilder<States>>;
2942
3006
  }
2943
3007
  /** Definition-time selector that can choose only a valid top-level initial entry. */
@@ -2955,11 +3019,15 @@ export declare namespace Machine {
2955
3019
  * @since 0.4.0
2956
3020
  */
2957
3021
  type HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3022
+ /** Value owned by the state whose handler is running. */
2958
3023
  readonly state: StateByIdentifier<States, StateId>;
3024
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
2959
3025
  readonly containingState: ParentStateValue<States, StateId>;
3026
+ /** Schema-backed ancestor values keyed by their complete state paths. */
2960
3027
  readonly ancestors: ParentStateValues<States, StateId>;
2961
3028
  /** Complete logical configuration captured at the start of this microstep. */
2962
3029
  readonly snapshot: Snapshot<States>;
3030
+ /** Event that selected this handler, narrowed by its `_tag`. */
2963
3031
  readonly event: EventByTag<Events, EventTag>;
2964
3032
  /**
2965
3033
  * Provides typed builders for choosing the next active state from this
@@ -2976,9 +3044,13 @@ export declare namespace Machine {
2976
3044
  * @since 0.4.0
2977
3045
  */
2978
3046
  type StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3047
+ /** Value owned by the state entering or exiting. */
2979
3048
  readonly state: StateByIdentifier<States, StateId>;
3049
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
2980
3050
  readonly containingState: ParentStateValue<States, StateId>;
3051
+ /** Schema-backed ancestor values keyed by their complete state paths. */
2981
3052
  readonly ancestors: ParentStateValues<States, StateId>;
3053
+ /** Event or initial-entry marker responsible for the lifecycle action. */
2982
3054
  readonly event: LifecycleEvent<Events>;
2983
3055
  };
2984
3056
  /**
@@ -2988,9 +3060,13 @@ export declare namespace Machine {
2988
3060
  * @since 0.4.0
2989
3061
  */
2990
3062
  type InvokeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3063
+ /** Value owned by the state that owns this invocation. */
2991
3064
  readonly state: StateByIdentifier<States, StateId>;
3065
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
2992
3066
  readonly containingState: ParentStateValue<States, StateId>;
3067
+ /** Schema-backed ancestor values keyed by their complete state paths. */
2993
3068
  readonly ancestors: ParentStateValues<States, StateId>;
3069
+ /** Event or initial-entry marker responsible for starting the invocation. */
2994
3070
  readonly event: LifecycleEvent<Events>;
2995
3071
  };
2996
3072
  /**
@@ -3000,11 +3076,17 @@ export declare namespace Machine {
3000
3076
  * @since 0.4.0
3001
3077
  */
3002
3078
  type InvokeSnapshotContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, State, Error, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3079
+ /** Parent-local invocation identifier. */
3003
3080
  readonly id: string;
3081
+ /** Current value of the state that owns the invocation. */
3004
3082
  readonly state: StateByIdentifier<States, StateId>;
3083
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
3005
3084
  readonly containingState: ParentStateValue<States, StateId>;
3085
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3006
3086
  readonly ancestors: ParentStateValues<States, StateId>;
3087
+ /** Builders for selecting the owning machine's next state. */
3007
3088
  readonly target: TargetBuilder<States, StateId>;
3089
+ /** Latest active lifecycle snapshot published by the invoked logic or child. */
3008
3090
  readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
3009
3091
  readonly status: "active";
3010
3092
  }>;
@@ -3016,32 +3098,53 @@ export declare namespace Machine {
3016
3098
  * @since 0.4.0
3017
3099
  */
3018
3100
  type InvokeDoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3101
+ /** Parent-local invocation identifier. */
3019
3102
  readonly id: string;
3103
+ /** Current value of the state that owns the invocation. */
3020
3104
  readonly state: StateByIdentifier<States, StateId>;
3105
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
3021
3106
  readonly containingState: ParentStateValue<States, StateId>;
3107
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3022
3108
  readonly ancestors: ParentStateValues<States, StateId>;
3109
+ /** Complete owning-machine configuration captured for this transition. */
3023
3110
  readonly snapshot: Snapshot<States>;
3111
+ /** Builders for selecting the owning machine's next state. */
3024
3112
  readonly target: TargetBuilder<States, StateId>;
3113
+ /** Successful output produced by the invocation. */
3025
3114
  readonly output: Output;
3026
3115
  };
3027
3116
  /** Context passed to a Stream invocation's element transition. */
3028
3117
  type InvokeElementContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Element, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3118
+ /** Parent-local invocation identifier. */
3029
3119
  readonly id: string;
3120
+ /** Current value of the state that owns the Stream invocation. */
3030
3121
  readonly state: StateByIdentifier<States, StateId>;
3122
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
3031
3123
  readonly containingState: ParentStateValue<States, StateId>;
3124
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3032
3125
  readonly ancestors: ParentStateValues<States, StateId>;
3126
+ /** Complete owning-machine configuration captured for this transition. */
3033
3127
  readonly snapshot: Snapshot<States>;
3128
+ /** Builders for selecting the owning machine's next state. */
3034
3129
  readonly target: TargetBuilder<States, StateId>;
3130
+ /** Next element emitted by the invoked Stream. */
3035
3131
  readonly element: Element;
3036
3132
  };
3037
3133
  /** Context passed to an invocation typed-failure transition. */
3038
3134
  type InvokeFailureContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Error, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3135
+ /** Parent-local invocation identifier. */
3039
3136
  readonly id: string;
3137
+ /** Current value of the state that owns the invocation. */
3040
3138
  readonly state: StateByIdentifier<States, StateId>;
3139
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
3041
3140
  readonly containingState: ParentStateValue<States, StateId>;
3141
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3042
3142
  readonly ancestors: ParentStateValues<States, StateId>;
3143
+ /** Complete owning-machine configuration captured for this transition. */
3043
3144
  readonly snapshot: Snapshot<States>;
3145
+ /** Builders for selecting the owning machine's next state. */
3044
3146
  readonly target: TargetBuilder<States, StateId>;
3147
+ /** Typed failure produced by the invocation. */
3045
3148
  readonly error: Error;
3046
3149
  };
3047
3150
  /**
@@ -3051,11 +3154,15 @@ export declare namespace Machine {
3051
3154
  * @since 0.4.0
3052
3155
  */
3053
3156
  type AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3157
+ /** Current value of the state evaluating the eventless transition. */
3054
3158
  readonly state: StateByIdentifier<States, StateId>;
3159
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
3055
3160
  readonly containingState: ParentStateValue<States, StateId>;
3161
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3056
3162
  readonly ancestors: ParentStateValues<States, StateId>;
3057
3163
  /** Complete logical configuration captured at the start of this microstep. */
3058
3164
  readonly snapshot: Snapshot<States>;
3165
+ /** Lifecycle event retained while the eventless transition is evaluated. */
3059
3166
  readonly event: LifecycleEvent<Events>;
3060
3167
  /**
3061
3168
  * Provides typed builders for choosing the next active state from this
@@ -3073,12 +3180,17 @@ export declare namespace Machine {
3073
3180
  * @since 0.4.0
3074
3181
  */
3075
3182
  type DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3183
+ /** Current value of the state whose child configuration completed. */
3076
3184
  readonly state: StateByIdentifier<States, StateId>;
3185
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
3077
3186
  readonly containingState: ParentStateValue<States, StateId>;
3187
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3078
3188
  readonly ancestors: ParentStateValues<States, StateId>;
3079
3189
  /** Complete logical configuration captured at the start of this microstep. */
3080
3190
  readonly snapshot: Snapshot<States>;
3191
+ /** Lifecycle event retained while state completion is processed. */
3081
3192
  readonly event: LifecycleEvent<Events>;
3193
+ /** Output produced by the completed final child or parallel regions. */
3082
3194
  readonly output: CompletionOutputByIdentifier<States, StateId>;
3083
3195
  /**
3084
3196
  * Provides typed builders for choosing the next active state after this
@@ -3091,11 +3203,15 @@ export declare namespace Machine {
3091
3203
  };
3092
3204
  /** Context passed to a transient choice resolver. There is no `state` value. */
3093
3205
  type ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
3206
+ /** Value owned by the choice node's immediate schema-backed parent. */
3094
3207
  readonly containingState: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
3208
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3095
3209
  readonly ancestors: {
3096
3210
  readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
3097
3211
  };
3212
+ /** Lifecycle event that led to the transient choice. */
3098
3213
  readonly event: LifecycleEvent<Events>;
3214
+ /** Builders for selecting the concrete destination of this choice. */
3099
3215
  readonly target: TargetBuilder<States, ChoiceId>;
3100
3216
  };
3101
3217
  /**
@@ -3105,9 +3221,13 @@ export declare namespace Machine {
3105
3221
  * @since 0.4.0
3106
3222
  */
3107
3223
  interface FinalOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
3224
+ /** Decoded value owned by the final state. */
3108
3225
  readonly state: StateByIdentifier<States, StateId>;
3226
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
3109
3227
  readonly containingState: ParentStateValue<States, StateId>;
3228
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3110
3229
  readonly ancestors: ParentStateValues<States, StateId>;
3230
+ /** Lifecycle event responsible for entering the final state. */
3111
3231
  readonly event: LifecycleEvent<Events>;
3112
3232
  }
3113
3233
  /**
@@ -3129,10 +3249,15 @@ export declare namespace Machine {
3129
3249
  * @since 0.4.0
3130
3250
  */
3131
3251
  interface ParallelOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
3252
+ /** Decoded value owned by the completed parallel state. */
3132
3253
  readonly state: StateByIdentifier<States, StateId>;
3254
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
3133
3255
  readonly containingState: ParentStateValue<States, StateId>;
3256
+ /** Schema-backed ancestor values keyed by their complete state paths. */
3134
3257
  readonly ancestors: ParentStateValues<States, StateId>;
3258
+ /** Lifecycle event retained while parallel completion is processed. */
3135
3259
  readonly event: LifecycleEvent<Events>;
3260
+ /** Completion output from every direct parallel region. */
3136
3261
  readonly outputs: ParallelOutputRegions<States, StateId>;
3137
3262
  }
3138
3263
  /**
@@ -3422,13 +3547,16 @@ export declare namespace Machine {
3422
3547
  });
3423
3548
  /** Context capability available only to explicitly declinable resolvers. */
3424
3549
  interface DeclineCapability {
3550
+ /** Declines this candidate and continues hierarchical transition selection. */
3425
3551
  readonly decline: () => Declined;
3426
3552
  }
3427
3553
  type TransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined;
3428
3554
  type DeclinableTransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined;
3429
3555
  /** One named destination declared by a branching transition. */
3430
3556
  interface TransitionBranchInput<Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>> {
3557
+ /** Exact topology destination available to the branching resolver. */
3431
3558
  readonly target: Selection;
3559
+ /** Optional human-readable branch label used by visualization tooling. */
3432
3560
  readonly title?: string;
3433
3561
  }
3434
3562
  /** Opaque evidence that a branching resolver selected one declared branch. */
@@ -3469,14 +3597,17 @@ export declare namespace Machine {
3469
3597
  };
3470
3598
  }
3471
3599
  type TransitionReenterOption<Reenter extends boolean> = [Reenter] extends [true] ? {
3600
+ /** Forces the source state to exit and enter even when active paths remain unchanged. */
3472
3601
  readonly reenter?: boolean;
3473
3602
  } : {
3474
3603
  readonly reenter?: never;
3475
3604
  };
3476
3605
  type TransitionRequiredOptions<Reenter extends boolean> = TransitionReenterOption<Reenter> & {
3606
+ /** Keeps the transition required. The resolver cannot return `decline()`. */
3477
3607
  readonly declinable?: false;
3478
3608
  };
3479
3609
  type TransitionDeclinableOptions<Reenter extends boolean> = TransitionReenterOption<Reenter> & {
3610
+ /** Adds `decline()` to the resolver context and permits declining this candidate. */
3480
3611
  readonly declinable: true;
3481
3612
  };
3482
3613
  type BuiltTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Result, Acceptance extends TransitionAcceptance> = TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<Result, Acceptance>;
@@ -3486,10 +3617,31 @@ export declare namespace Machine {
3486
3617
  interface TransitionResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> {
3487
3618
  (resolve: DeclinableTransitionResolver<Events, Emits, Context, Selection>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined, "declinable">;
3488
3619
  }
3489
- /** A selected transition target with target-specific resolver operations. */
3620
+ /**
3621
+ * A selected transition target with target-specific resolver operations.
3622
+ *
3623
+ * **Example** (Updating state while reentering)
3624
+ *
3625
+ * ```ts
3626
+ * Reset: (to) =>
3627
+ * to.full.Ready().resolve(
3628
+ * ({ target }) => target.from(),
3629
+ * { reenter: true }
3630
+ * )
3631
+ * ```
3632
+ *
3633
+ * @inlineType TransitionRequiredOptions
3634
+ * @inlineType TransitionDeclinableOptions
3635
+ * @inlineType TransitionReenterOption
3636
+ */
3490
3637
  type TransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, any>> = Selection & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required"> : {}) & {
3638
+ /**
3639
+ * Evaluates state construction and queued commands only after this
3640
+ * transition has been selected.
3641
+ */
3491
3642
  readonly resolve: TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? TransitionResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
3492
3643
  } & ([Reenter] extends [true] ? SelectionSupportsDefaultConstruction<Selection> extends true ? {
3644
+ /** Reenters the source using the selected target's default construction. */
3493
3645
  readonly reenter: () => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
3494
3646
  } : {} : {});
3495
3647
  /** @internal Type evidence retained by a machine initial-entry declaration. */
@@ -3498,8 +3650,11 @@ export declare namespace Machine {
3498
3650
  }
3499
3651
  /** A selected machine initial entry with its exact resolver target. */
3500
3652
  type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> = Selection & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {}) & {
3653
+ /** Lazily constructs the selected initial state from decoded machine input. */
3501
3654
  readonly resolve: (resolve: (context: {
3655
+ /** Decoded value supplied when the machine is started. */
3502
3656
  readonly input: Input;
3657
+ /** Builder specialized to the selected initial destination. */
3503
3658
  readonly target: SelectionBuilder<Selection>;
3504
3659
  }) => SelectedTargetResult<Selection>) => InitialBuilderEvidence<Selection>;
3505
3660
  };
@@ -3525,7 +3680,9 @@ export declare namespace Machine {
3525
3680
  }
3526
3681
  /** Selector supplied to inline transition declarations. */
3527
3682
  type TransitionSelector<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance> = TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, TargetSelector<States, StateId>> & {
3683
+ /** Declares a closed set of named destinations for one resolver. */
3528
3684
  readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>) => {
3685
+ /** Resolves exactly one declared branch after this transition is selected. */
3529
3686
  readonly resolve: TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches> & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Branches> : {});
3530
3687
  };
3531
3688
  };
@@ -3630,13 +3787,18 @@ export declare namespace Machine {
3630
3787
  type InvokeBuilderResult<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & InvokeTyped<Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> & {
3631
3788
  readonly [InvokeBuilderTypeId]: true;
3632
3789
  };
3790
+ /** Lifecycle handlers exposed according to the selected invocation source. */
3633
3791
  type InvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Pending extends string, SnapshotHandler, Outcomes = never> = ([Pending] extends [never] ? InvokeBuilderResult<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> : {}) & ("done" extends Pending ? {
3792
+ /** Handles successful completion and exposes the invocation output. */
3634
3793
  readonly onDone: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "done">, SnapshotHandler, Outcomes | Handler>;
3635
3794
  } : {}) & ("failure" extends Pending ? {
3795
+ /** Handles typed failure and exposes the invocation error. */
3636
3796
  readonly onFailure: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "failure">, SnapshotHandler, Outcomes | Handler>;
3637
3797
  } : {}) & ("element" extends Pending ? {
3798
+ /** Handles each backpressured element emitted by an invoked Stream. */
3638
3799
  readonly onElement: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "element">, SnapshotHandler, Outcomes | Handler>;
3639
3800
  } : {}) & ([SnapshotHandler] extends [never] ? {} : {
3801
+ /** Handles each active snapshot published by invoked logic or a child machine. */
3640
3802
  readonly onSnapshot: <const Handler extends SnapshotHandler>(handler: Handler & SnapshotHandler) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Pending, never, Outcomes | Handler>;
3641
3803
  });
3642
3804
  type EffectInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Source extends (...args: ReadonlyArray<any>) => Effect.Effect<any, any, any>> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never, never, never, never, RequiredInvokeChannel<Effect.Success<ReturnType<Source>>, "done"> | RequiredInvokeChannel<Effect.Error<ReturnType<Source>>, "failure">, never>;
@@ -3650,20 +3812,59 @@ export declare namespace Machine {
3650
3812
  * chain becomes returnable from `invoke` only after every reachable required
3651
3813
  * channel has been handled.
3652
3814
  *
3815
+ * **Example** (Invoking an Effect)
3816
+ *
3817
+ * ```ts
3818
+ * invoke: (from) =>
3819
+ * from.effect("load-user", () => loadUser).onDone((to) =>
3820
+ * to.full.Ready().resolve(({ output, target }) => target.from({ user: output }))
3821
+ * ).onFailure((to) =>
3822
+ * to.full.Failed().resolve(({ error, target }) => target.from({ error }))
3823
+ * )
3824
+ * ```
3825
+ *
3826
+ * @inlineType EffectInvokeBuilder
3827
+ * @inlineType StreamInvokeBuilder
3828
+ * @inlineType LogicInvokeBuilder
3829
+ * @inlineType ChildInvokeBuilder
3830
+ * @inlineType InvokeBuilder
3831
+ *
3653
3832
  * @category models
3654
3833
  * @since 0.18.0
3655
3834
  */
3656
3835
  interface InvokeSelector<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
3657
- /** Starts a fresh Effect each time the owning state is entered. */
3836
+ /**
3837
+ * Starts a fresh Effect each time the owning state is entered.
3838
+ *
3839
+ * @param id Parent-local lifecycle identifier.
3840
+ * @param source Lazy Effect factory evaluated on every entry.
3841
+ */
3658
3842
  readonly effect: <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>>(id: InvokeLifecycleId, source: Source) => EffectInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
3659
- /** Starts a fresh, backpressured Stream each time the owning state is entered. */
3843
+ /**
3844
+ * Starts a fresh, backpressured Stream each time the owning state is entered.
3845
+ *
3846
+ * @param id Parent-local lifecycle identifier.
3847
+ * @param source Lazy Stream factory evaluated on every entry.
3848
+ */
3660
3849
  readonly stream: <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<unknown, unknown, any>>(id: InvokeLifecycleId, source: Source) => StreamInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
3661
- /** Starts a cancellable state-scoped timer. */
3850
+ /**
3851
+ * Starts a cancellable state-scoped timer.
3852
+ *
3853
+ * @param id Parent-local lifecycle identifier.
3854
+ * @param duration Duration input or context-dependent duration factory.
3855
+ */
3662
3856
  readonly timer: (id: InvokeLifecycleId, duration: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, void, never, never, never, never, never, never, "done", never>;
3663
- /** Starts reusable process logic at a typed parent-local address. */
3857
+ /**
3858
+ * Starts reusable process logic at a typed parent-local address.
3859
+ *
3860
+ * @param id Parent-local lifecycle identifier.
3861
+ * @param options Address and reusable logic value or factory.
3862
+ */
3664
3863
  readonly logic: {
3665
3864
  <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
3865
+ /** Typed parent-local address used to send events to this logic. */
3666
3866
  readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<ReturnType<NoInfer<Source>>>>;
3867
+ /** Context-dependent factory that returns reusable process logic. */
3667
3868
  readonly logic: Source;
3668
3869
  }, ..._validation: ReturnType<Source> extends {
3669
3870
  readonly initial: unknown;
@@ -3672,7 +3873,9 @@ export declare namespace Machine {
3672
3873
  "logic factory must return Machine.Logic"
3673
3874
  ]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, ReturnType<Source>>;
3674
3875
  <const Source, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
3876
+ /** Typed parent-local address used to send events to this logic. */
3675
3877
  readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<NoInfer<Source>>>;
3878
+ /** Reusable process logic started when the owning state enters. */
3676
3879
  readonly logic: Source;
3677
3880
  }, ..._validation: Source extends {
3678
3881
  readonly initial: unknown;
@@ -3681,11 +3884,17 @@ export declare namespace Machine {
3681
3884
  "logic must implement Machine.Logic"
3682
3885
  ]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
3683
3886
  };
3684
- /** Starts a complete child statechart represented by a reusable descriptor. */
3887
+ /**
3888
+ * Starts a complete child statechart represented by a reusable descriptor.
3889
+ *
3890
+ * @param child Reusable descriptor created with `Machine.child`.
3891
+ * @param options Input construction for a child with a non-void input schema.
3892
+ */
3685
3893
  readonly child: <const Child extends ChildMachine.Any>(child: Child & (Child["machine"] extends EnsureExecutable<Machine.States<Child["machine"]>, Machine.UnhandledStates<Child["machine"]>, Machine.OutputStates<Child["machine"]>> ? unknown : never), ...options: InputSchema<Child["machine"]> extends typeof Schema.Void ? [options?: {
3686
3894
  readonly input?: never;
3687
3895
  }] : [
3688
3896
  options: {
3897
+ /** Child input value or factory evaluated from the owning state context. */
3689
3898
  readonly input: InvokeSource<Input<Child["machine"]>, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
3690
3899
  }
3691
3900
  ]) => ChildInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Child>;
@@ -3705,9 +3914,11 @@ export declare namespace Machine {
3705
3914
  }) | ReadonlyArray<InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
3706
3915
  readonly [InvokeBuilderTypeId]: true;
3707
3916
  }>;
3917
+ /** Output construction available to final and output-producing parallel states. */
3708
3918
  type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
3709
3919
  readonly output: Schema.Top;
3710
3920
  } ? {
3921
+ /** Constructs the decoded output declared by the state's `output` schema. */
3711
3922
  readonly output: (context: Context) => OutputByIdentifier<States, StateId>;
3712
3923
  } : {
3713
3924
  readonly output?: never;
@@ -3720,18 +3931,41 @@ export declare namespace Machine {
3720
3931
  /**
3721
3932
  * Configuration accepted for a non-final state.
3722
3933
  *
3934
+ * **Example** (State actions, events, and invocation)
3935
+ *
3936
+ * ```ts
3937
+ * machine.handle({
3938
+ * Loading: {
3939
+ * entry: (_, enqueue) => enqueue.emit({ _tag: "Started" }),
3940
+ * invoke: (from) =>
3941
+ * from.effect("load", () => load).onDone((to) => to.full.Ready()),
3942
+ * on: { Cancel: (to) => to.full.Idle() }
3943
+ * }
3944
+ * })
3945
+ * ```
3946
+ *
3947
+ * @inlineType ActiveOutputHandlerConfig
3948
+ * @inlineType OutputHandlerConfig
3949
+ *
3723
3950
  * @category models
3724
3951
  * @since 0.4.0
3725
3952
  */
3726
3953
  type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
3954
+ /** Runs synchronously when the state is entered and may enqueue commands. */
3727
3955
  readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
3956
+ /** Runs synchronously before the state is exited and may enqueue commands. */
3728
3957
  readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
3958
+ /** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
3729
3959
  readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>;
3960
+ /** Eventless transition evaluated after the state becomes stable. */
3730
3961
  readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
3962
+ /** Transition evaluated after this compound or parallel state completes. */
3731
3963
  readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
3964
+ /** Event handlers keyed by the `_tag` of the machine's public or internal events. */
3732
3965
  readonly on?: {
3733
3966
  readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, true, TransitionAcceptance>;
3734
3967
  };
3968
+ /** Supplies missing direct initial-child values required by implicit entry and shallow history. */
3735
3969
  readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>;
3736
3970
  } & ActiveOutputHandlerConfig<States, Events, StateId>;
3737
3971
  /**
@@ -3797,8 +4031,11 @@ export declare namespace Machine {
3797
4031
  type StateInitializeHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = (context: StateInitializeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>;
3798
4032
  /** Context used only when a history node has no previously captured record. */
3799
4033
  interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
4034
+ /** Lifecycle event that attempted to restore this history node. */
3800
4035
  readonly event: LifecycleEvent<Events>;
4036
+ /** Complete target builder rooted at the history owner. */
3801
4037
  readonly target: HistoryDefaultTargetBuilder<States, ParentId>;
4038
+ /** State path whose child configuration is restored by this history node. */
3802
4039
  readonly owner: ParentId;
3803
4040
  }
3804
4041
  /**
@@ -3809,14 +4046,26 @@ export declare namespace Machine {
3809
4046
  * and provides every inactive ancestor and required parallel region.
3810
4047
  */
3811
4048
  type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => CompleteSnapshotContaining<States, ParentId> | StateConstruction<CompleteSnapshotContaining<States, ParentId>>;
3812
- /** Default implementations keyed by direct history child. */
4049
+ /**
4050
+ * Fallback implementation for one direct history pseudo-state.
4051
+ *
4052
+ * @inline
4053
+ */
4054
+ interface HistoryDefaultEntry<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
4055
+ /** Builds the complete fallback configuration used before history is first captured. */
4056
+ readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>;
4057
+ }
4058
+ /**
4059
+ * Default implementations keyed by direct history child.
4060
+ *
4061
+ * @inlineType HistoryDefaultEntry
4062
+ */
3813
4063
  type HistoryDefaultConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>, Children extends StateSchemas> = {
3814
- readonly [Key in HistoryStateKey<Children>]?: {
3815
- readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>;
3816
- };
4064
+ readonly [Key in HistoryStateKey<Children>]?: HistoryDefaultEntry<States, Events, Emits, ParentId>;
3817
4065
  };
3818
4066
  /** Required implementation for a choice pseudo-state. */
3819
4067
  interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
4068
+ /** Required transition that resolves this transient choice to a concrete destination. */
3820
4069
  readonly choice: TransitionConfig<States, Events, Emits, ChoiceId, ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>>;
3821
4070
  readonly entry?: never;
3822
4071
  readonly exit?: never;
@@ -3830,10 +4079,13 @@ export declare namespace Machine {
3830
4079
  /**
3831
4080
  * Configuration accepted for a final state.
3832
4081
  *
4082
+ * @inlineType OutputHandlerConfig
4083
+ *
3833
4084
  * @category models
3834
4085
  * @since 0.4.0
3835
4086
  */
3836
4087
  type FinalStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
4088
+ /** Runs synchronously when the final state is entered and may enqueue commands. */
3837
4089
  readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
3838
4090
  readonly exit?: never;
3839
4091
  readonly always?: never;
@@ -3871,6 +4123,7 @@ export declare namespace Machine {
3871
4123
  } : {
3872
4124
  readonly [Key in Path]?: Validation;
3873
4125
  };
4126
+ /** Nested handler-tree structure shared by active and final state configs. */
3874
4127
  type HandlerNode<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>> = HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R, InputEvents, ParentEvents> & (StateId extends ChoiceIdentifier<AllStates> ? {
3875
4128
  readonly states?: never;
3876
4129
  readonly history?: never;
@@ -3878,7 +4131,9 @@ export declare namespace Machine {
3878
4131
  readonly states?: never;
3879
4132
  readonly history?: never;
3880
4133
  } : {
4134
+ /** Child-state handlers nested according to the declared state topology. */
3881
4135
  readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, InputEvents, ParentEvents, Extract<StateId, StateIdentifier<AllStates>>>;
4136
+ /** First-use defaults keyed by direct history pseudo-state. */
3882
4137
  readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
3883
4138
  } : {
3884
4139
  readonly states?: never;
@@ -4170,20 +4425,31 @@ export declare const state: StateConstructor;
4170
4425
  */
4171
4426
  export declare const states: StatesConstructor;
4172
4427
  type MakeConfig<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined> = {
4428
+ /** Stable definition identifier used by inspection and visualization. */
4173
4429
  readonly id?: string;
4430
+ /** State topology and value schemas, normally supplied by `Machine.states`. */
4174
4431
  readonly states: States & DefineStateTreeInput<NoInfer<States>>;
4432
+ /** Public events accepted by independently running machine references. */
4175
4433
  readonly events: Machine.EventProtocol<"public", InputEvents> & ValidateInputEventProtocol<NoInfer<InputEvents>>;
4434
+ /** Machine-local events used by raised events and other internal deliveries. */
4176
4435
  readonly internalEvents?: Machine.EventProtocol<"internal", InternalEvents> & ValidateInternalEventProtocol<NoInfer<InputEvents>, NoInfer<InternalEvents>>;
4436
+ /** Ephemeral notifications that handlers may publish to observers. */
4177
4437
  readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>;
4438
+ /** Required or optional owning-machine protocol for this definition. */
4178
4439
  readonly parent?: ParentDeclaration;
4440
+ /** Schema used to decode input before initial-state construction. */
4179
4441
  readonly input?: Input;
4442
+ /** Target-first declaration that constructs the initial active configuration. */
4180
4443
  readonly initial: unknown;
4181
4444
  };
4182
4445
  type MakeResult<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined> = Definition<States, readonly [...InputEvents, ...InternalEvents], Input, InitialE, InitialR, Machine.FinalStateFromDefinition<States>, Machine.TerminalOutput<States>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration>>;
4446
+ /** @inline */
4183
4447
  interface Make {
4448
+ /** @param config Complete schema-first machine definition. */
4184
4449
  <const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>, "initial"> & {
4185
4450
  readonly initial: Machine.InitialBuilderInput<States, Input["Type"]>;
4186
4451
  }, ..._validation: ValidateDefinedStates<NoInfer<States>>): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
4452
+ /** @param config Invalid state tree retained only to report its validation error at the call site. */
4187
4453
  <const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>, "states"> & {
4188
4454
  readonly states: InvalidDefinedStateTreeInput<States>;
4189
4455
  }): never;
@@ -4246,6 +4512,7 @@ interface Make {
4246
4512
  * ```
4247
4513
  *
4248
4514
  * @see {@link states} for typed state-tree helpers.
4515
+ * @inlineType MakeConfig
4249
4516
  * @category constructors
4250
4517
  * @since 0.4.0
4251
4518
  */
@@ -4371,18 +4638,21 @@ export declare const emittedEvents: {
4371
4638
  *
4372
4639
  * **Details**
4373
4640
  *
4374
- * Each active state value and completed output is encoded with the schema
4375
- * declared for its state path. The result contains no process-local runtime
4376
- * state.
4641
+ * Each active state value and completed output is encoded with the canonical
4642
+ * JSON codec derived from the schema declared for its state path. Success
4643
+ * guarantees that every state, output, and history value is `Schema.Json`.
4644
+ * Non-JSON values, including cyclic process-local capabilities, fail with
4645
+ * {@link MachineSchemaEncodeError} at their declared boundary.
4377
4646
  *
4378
4647
  * **Gotchas**
4379
4648
  *
4380
4649
  * The encoded snapshot does not contain the machine definition, machine
4381
4650
  * version, running children, invoked process state, services, or subscriptions.
4382
4651
  * Store machine identity and migration metadata alongside the result when the
4383
- * snapshot crosses deployment versions. Schema encoding does not by itself
4384
- * guarantee JSON-compatible values; schemas used with JSON-backed storage must
4385
- * have JSON-compatible encoded representations.
4652
+ * snapshot crosses deployment versions. Opaque declarations without a JSON
4653
+ * codec can encode only when their current value is already JSON-compatible.
4654
+ * Define an explicit JSON codec or keep process-local capabilities outside the
4655
+ * logical snapshot.
4386
4656
  *
4387
4657
  * **Example**
4388
4658
  *