@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/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
@@ -1878,6 +1894,9 @@ export type RuntimeSnapshot<State, Error = never, Output = never> =
1878
1894
  * one stream may contain unrelated root, child-machine, and `Logic` protocols.
1879
1895
  * The record structure remains a closed discriminated union, while typed
1880
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.
1881
1900
  *
1882
1901
  * @category models
1883
1902
  * @since 0.13.0
@@ -2912,8 +2931,11 @@ export declare namespace Machine {
2912
2931
  * @since 0.4.0
2913
2932
  */
2914
2933
  export interface StateNodeAnnotations extends Schema.Annotations.Annotations {
2934
+ /** Human-readable label used by visualization and documentation tooling. */
2915
2935
  readonly title?: string | undefined
2936
+ /** Short explanation of the state node's domain meaning. */
2916
2937
  readonly description?: string | undefined
2938
+ /** Longer documentation text associated with the state node. */
2917
2939
  readonly documentation?: string | undefined
2918
2940
  }
2919
2941
 
@@ -2927,22 +2949,29 @@ export declare namespace Machine {
2927
2949
  export type PseudoStateAnnotations = SchemaLessStateAnnotations
2928
2950
 
2929
2951
  /**
2930
- * Configuration accepted for an atomic object state node. Omit `schema` when
2931
- * 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`.
2932
2956
  *
2933
2957
  * @category models
2934
2958
  * @since 0.4.0
2935
2959
  */
2936
2960
  export type AtomicStateNodeConfig =
2937
2961
  | {
2962
+ /** Tagged schema that owns the state's decoded value. */
2938
2963
  readonly schema: TaggedSchema
2964
+ /** Declares an ordinary active state. Omitted values default to `"active"`. */
2939
2965
  readonly type?: "active"
2966
+ /** Atomic active states cannot declare terminal output. */
2940
2967
  readonly output?: never
2968
+ /** Schema-backed states take their annotations from the schema. */
2941
2969
  readonly annotations?: never
2942
2970
  }
2943
2971
  | {
2944
2972
  readonly schema: TaggedSchema
2945
2973
  readonly type: "final"
2974
+ /** Optional schema describing the terminal value produced by this final state. */
2946
2975
  readonly output?: Schema.Top
2947
2976
  readonly annotations?: never
2948
2977
  }
@@ -2950,12 +2979,15 @@ export declare namespace Machine {
2950
2979
  readonly schema?: never
2951
2980
  readonly type?: "active"
2952
2981
  readonly output?: never
2982
+ /** Descriptive metadata for a schema-less state. */
2953
2983
  readonly annotations?: SchemaLessStateAnnotations
2954
2984
  }
2955
2985
  | {
2956
2986
  readonly schema?: never
2957
2987
  readonly type: "final"
2988
+ /** Optional schema describing the terminal value produced by this final state. */
2958
2989
  readonly output?: Schema.Top
2990
+ /** Descriptive metadata for a schema-less state. */
2959
2991
  readonly annotations?: SchemaLessStateAnnotations
2960
2992
  }
2961
2993
 
@@ -2968,10 +3000,15 @@ export declare namespace Machine {
2968
3000
  */
2969
3001
  export type CompoundStateNodeConfig =
2970
3002
  | {
3003
+ /** Tagged schema that owns the compound state's decoded value. */
2971
3004
  readonly schema: TaggedSchema
3005
+ /** Compound states are ordinary active states. */
2972
3006
  readonly type?: "active"
3007
+ /** Direct child selected when the compound state is entered initially. */
2973
3008
  readonly initial: string
3009
+ /** Nested state nodes owned by this compound state. */
2974
3010
  readonly states: StateTree
3011
+ /** Schema-backed states take their annotations from the schema. */
2975
3012
  readonly annotations?: never
2976
3013
  }
2977
3014
  | {
@@ -2979,6 +3016,7 @@ export declare namespace Machine {
2979
3016
  readonly type?: "active"
2980
3017
  readonly initial: string
2981
3018
  readonly states: StateTree
3019
+ /** Descriptive metadata for a schema-less state. */
2982
3020
  readonly annotations?: SchemaLessStateAnnotations
2983
3021
  }
2984
3022
 
@@ -2991,10 +3029,15 @@ export declare namespace Machine {
2991
3029
  */
2992
3030
  export type ParallelStateNodeConfig =
2993
3031
  | {
3032
+ /** Tagged schema that owns the parallel state's decoded value. */
2994
3033
  readonly schema: TaggedSchema
3034
+ /** Selects parallel-region semantics for the node. */
2995
3035
  readonly type: "parallel"
3036
+ /** Optional schema describing the value produced after every region completes. */
2996
3037
  readonly output?: Schema.Top
3038
+ /** Child regions that are entered and remain active simultaneously. */
2997
3039
  readonly states: StateTree
3040
+ /** Schema-backed states take their annotations from the schema. */
2998
3041
  readonly annotations?: never
2999
3042
  }
3000
3043
  | {
@@ -3002,6 +3045,7 @@ export declare namespace Machine {
3002
3045
  readonly type: "parallel"
3003
3046
  readonly output?: Schema.Top
3004
3047
  readonly states: StateTree
3048
+ /** Descriptive metadata for a schema-less state. */
3005
3049
  readonly annotations?: SchemaLessStateAnnotations
3006
3050
  }
3007
3051
 
@@ -3018,9 +3062,16 @@ export declare namespace Machine {
3018
3062
  * @since 0.4.0
3019
3063
  */
3020
3064
  export interface HistoryStateNodeConfig {
3065
+ /** Selects history pseudo-state semantics. */
3021
3066
  readonly type: "history"
3022
- /** 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
+ */
3023
3073
  readonly history?: "shallow" | "deep"
3074
+ /** Descriptive metadata used by visualization and documentation tooling. */
3024
3075
  readonly annotations?: SchemaLessStateAnnotations
3025
3076
  }
3026
3077
 
@@ -3035,7 +3086,9 @@ export declare namespace Machine {
3035
3086
  * @since 0.4.0
3036
3087
  */
3037
3088
  export interface ChoiceStateNodeConfig {
3089
+ /** Selects transient choice pseudo-state semantics. */
3038
3090
  readonly type: "choice"
3091
+ /** Descriptive metadata used by visualization and documentation tooling. */
3039
3092
  readonly annotations?: SchemaLessStateAnnotations
3040
3093
  }
3041
3094
 
@@ -3963,26 +4016,28 @@ export declare namespace Machine {
3963
4016
  */
3964
4017
  export interface EncodedSnapshotState {
3965
4018
  readonly path: string
3966
- readonly value?: unknown
4019
+ readonly value?: Schema.Json
3967
4020
  }
3968
4021
 
3969
4022
  /**
3970
4023
  * Encoded output for one completed state path in a normalized machine
3971
- * 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`.
3972
4027
  *
3973
4028
  * @category models
3974
4029
  * @since 0.4.0
3975
4030
  */
3976
4031
  export interface EncodedSnapshotCompletion {
3977
4032
  readonly path: string
3978
- readonly output?: unknown
4033
+ readonly output?: Schema.Json
3979
4034
  }
3980
4035
 
3981
4036
  /** Encoded values and paths retained by one history pseudo-state. */
3982
4037
  export interface EncodedSnapshotHistoryEntry {
3983
4038
  readonly mode: "shallow" | "deep"
3984
4039
  readonly active: ReadonlyArray<string>
3985
- readonly values: Readonly<Record<string, unknown>>
4040
+ readonly values: Readonly<Record<string, Schema.Json>>
3986
4041
  }
3987
4042
 
3988
4043
  /**
@@ -3990,9 +4045,10 @@ export declare namespace Machine {
3990
4045
  *
3991
4046
  * **Details**
3992
4047
  *
3993
- * Active state and completion values use the encoded representations of
3994
- * their declared schemas. Runtime process state such as children, fibers,
3995
- * 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.
3996
4052
  *
3997
4053
  * @category models
3998
4054
  * @since 0.4.0
@@ -4636,18 +4692,26 @@ export declare namespace Machine {
4636
4692
 
4637
4693
  /**
4638
4694
  * Definition-time topology selector available to an ordinary transition.
4695
+ *
4639
4696
  * Topology-only instructions (`none`, declared `initial` and history
4640
- * selections, and `local.with`) are values. State and choice destinations
4641
- * 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.
4642
4701
  */
4643
4702
  export interface TargetSelector<
4644
4703
  States extends StateSchemas,
4645
4704
  Source extends StateNodeIdentifier<States>
4646
4705
  > {
4706
+ /** Handles the trigger without selecting a destination. */
4647
4707
  readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none">
4708
+ /** Selects a destination inside the nearest active compound scope. */
4648
4709
  readonly local: LocalTargetSelector<States, Source>
4710
+ /** Selects a destination elsewhere under the currently active root. */
4649
4711
  readonly branch: BranchTargetSelector<States, Source>
4712
+ /** Selects a complete destination under any top-level state. */
4650
4713
  readonly full: FullTargetSelector<States>
4714
+ /** Restores a shallow or deep history pseudo-state. */
4651
4715
  readonly history: HistorySelectionTree<States, States, "", HistoryTargetBuilder<States>>
4652
4716
  }
4653
4717
 
@@ -4677,11 +4741,15 @@ export declare namespace Machine {
4677
4741
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4678
4742
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4679
4743
  > = MachineReferences<InputEvents, ParentEvents> & {
4744
+ /** Value owned by the state whose handler is running. */
4680
4745
  readonly state: StateByIdentifier<States, StateId>
4746
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4681
4747
  readonly containingState: ParentStateValue<States, StateId>
4748
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4682
4749
  readonly ancestors: ParentStateValues<States, StateId>
4683
4750
  /** Complete logical configuration captured at the start of this microstep. */
4684
4751
  readonly snapshot: Snapshot<States>
4752
+ /** Event that selected this handler, narrowed by its `_tag`. */
4685
4753
  readonly event: EventByTag<Events, EventTag>
4686
4754
 
4687
4755
  /**
@@ -4707,9 +4775,13 @@ export declare namespace Machine {
4707
4775
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4708
4776
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4709
4777
  > = MachineReferences<InputEvents, ParentEvents> & {
4778
+ /** Value owned by the state entering or exiting. */
4710
4779
  readonly state: StateByIdentifier<States, StateId>
4780
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4711
4781
  readonly containingState: ParentStateValue<States, StateId>
4782
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4712
4783
  readonly ancestors: ParentStateValues<States, StateId>
4784
+ /** Event or initial-entry marker responsible for the lifecycle action. */
4713
4785
  readonly event: LifecycleEvent<Events>
4714
4786
  }
4715
4787
 
@@ -4727,9 +4799,13 @@ export declare namespace Machine {
4727
4799
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4728
4800
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4729
4801
  > = MachineReferences<InputEvents, ParentEvents> & {
4802
+ /** Value owned by the state that owns this invocation. */
4730
4803
  readonly state: StateByIdentifier<States, StateId>
4804
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4731
4805
  readonly containingState: ParentStateValue<States, StateId>
4806
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4732
4807
  readonly ancestors: ParentStateValues<States, StateId>
4808
+ /** Event or initial-entry marker responsible for starting the invocation. */
4733
4809
  readonly event: LifecycleEvent<Events>
4734
4810
  }
4735
4811
 
@@ -4750,11 +4826,17 @@ export declare namespace Machine {
4750
4826
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4751
4827
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4752
4828
  > = MachineReferences<InputEvents, ParentEvents> & {
4829
+ /** Parent-local invocation identifier. */
4753
4830
  readonly id: string
4831
+ /** Current value of the state that owns the invocation. */
4754
4832
  readonly state: StateByIdentifier<States, StateId>
4833
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4755
4834
  readonly containingState: ParentStateValue<States, StateId>
4835
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4756
4836
  readonly ancestors: ParentStateValues<States, StateId>
4837
+ /** Builders for selecting the owning machine's next state. */
4757
4838
  readonly target: TargetBuilder<States, StateId>
4839
+ /** Latest active lifecycle snapshot published by the invoked logic or child. */
4758
4840
  readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, { readonly status: "active" }>
4759
4841
  }
4760
4842
 
@@ -4773,12 +4855,19 @@ export declare namespace Machine {
4773
4855
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4774
4856
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4775
4857
  > = MachineReferences<InputEvents, ParentEvents> & {
4858
+ /** Parent-local invocation identifier. */
4776
4859
  readonly id: string
4860
+ /** Current value of the state that owns the invocation. */
4777
4861
  readonly state: StateByIdentifier<States, StateId>
4862
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4778
4863
  readonly containingState: ParentStateValue<States, StateId>
4864
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4779
4865
  readonly ancestors: ParentStateValues<States, StateId>
4866
+ /** Complete owning-machine configuration captured for this transition. */
4780
4867
  readonly snapshot: Snapshot<States>
4868
+ /** Builders for selecting the owning machine's next state. */
4781
4869
  readonly target: TargetBuilder<States, StateId>
4870
+ /** Successful output produced by the invocation. */
4782
4871
  readonly output: Output
4783
4872
  }
4784
4873
 
@@ -4792,12 +4881,19 @@ export declare namespace Machine {
4792
4881
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4793
4882
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4794
4883
  > = MachineReferences<InputEvents, ParentEvents> & {
4884
+ /** Parent-local invocation identifier. */
4795
4885
  readonly id: string
4886
+ /** Current value of the state that owns the Stream invocation. */
4796
4887
  readonly state: StateByIdentifier<States, StateId>
4888
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4797
4889
  readonly containingState: ParentStateValue<States, StateId>
4890
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4798
4891
  readonly ancestors: ParentStateValues<States, StateId>
4892
+ /** Complete owning-machine configuration captured for this transition. */
4799
4893
  readonly snapshot: Snapshot<States>
4894
+ /** Builders for selecting the owning machine's next state. */
4800
4895
  readonly target: TargetBuilder<States, StateId>
4896
+ /** Next element emitted by the invoked Stream. */
4801
4897
  readonly element: Element
4802
4898
  }
4803
4899
 
@@ -4811,12 +4907,19 @@ export declare namespace Machine {
4811
4907
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4812
4908
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4813
4909
  > = MachineReferences<InputEvents, ParentEvents> & {
4910
+ /** Parent-local invocation identifier. */
4814
4911
  readonly id: string
4912
+ /** Current value of the state that owns the invocation. */
4815
4913
  readonly state: StateByIdentifier<States, StateId>
4914
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4816
4915
  readonly containingState: ParentStateValue<States, StateId>
4916
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4817
4917
  readonly ancestors: ParentStateValues<States, StateId>
4918
+ /** Complete owning-machine configuration captured for this transition. */
4818
4919
  readonly snapshot: Snapshot<States>
4920
+ /** Builders for selecting the owning machine's next state. */
4819
4921
  readonly target: TargetBuilder<States, StateId>
4922
+ /** Typed failure produced by the invocation. */
4820
4923
  readonly error: Error
4821
4924
  }
4822
4925
 
@@ -4834,11 +4937,15 @@ export declare namespace Machine {
4834
4937
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4835
4938
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4836
4939
  > = MachineReferences<InputEvents, ParentEvents> & {
4940
+ /** Current value of the state evaluating the eventless transition. */
4837
4941
  readonly state: StateByIdentifier<States, StateId>
4942
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4838
4943
  readonly containingState: ParentStateValue<States, StateId>
4944
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4839
4945
  readonly ancestors: ParentStateValues<States, StateId>
4840
4946
  /** Complete logical configuration captured at the start of this microstep. */
4841
4947
  readonly snapshot: Snapshot<States>
4948
+ /** Lifecycle event retained while the eventless transition is evaluated. */
4842
4949
  readonly event: LifecycleEvent<Events>
4843
4950
 
4844
4951
  /**
@@ -4865,12 +4972,17 @@ export declare namespace Machine {
4865
4972
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4866
4973
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4867
4974
  > = MachineReferences<InputEvents, ParentEvents> & {
4975
+ /** Current value of the state whose child configuration completed. */
4868
4976
  readonly state: StateByIdentifier<States, StateId>
4977
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4869
4978
  readonly containingState: ParentStateValue<States, StateId>
4979
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4870
4980
  readonly ancestors: ParentStateValues<States, StateId>
4871
4981
  /** Complete logical configuration captured at the start of this microstep. */
4872
4982
  readonly snapshot: Snapshot<States>
4983
+ /** Lifecycle event retained while state completion is processed. */
4873
4984
  readonly event: LifecycleEvent<Events>
4985
+ /** Output produced by the completed final child or parallel regions. */
4874
4986
  readonly output: CompletionOutputByIdentifier<States, StateId>
4875
4987
 
4876
4988
  /**
@@ -4892,17 +5004,21 @@ export declare namespace Machine {
4892
5004
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
4893
5005
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
4894
5006
  > = MachineReferences<InputEvents, ParentEvents> & {
5007
+ /** Value owned by the choice node's immediate schema-backed parent. */
4895
5008
  readonly containingState: StateByIdentifier<
4896
5009
  States,
4897
5010
  Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>
4898
5011
  >
5012
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4899
5013
  readonly ancestors: {
4900
5014
  readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<
4901
5015
  States,
4902
5016
  Parent
4903
5017
  >
4904
5018
  }
5019
+ /** Lifecycle event that led to the transient choice. */
4905
5020
  readonly event: LifecycleEvent<Events>
5021
+ /** Builders for selecting the concrete destination of this choice. */
4906
5022
  readonly target: TargetBuilder<States, ChoiceId>
4907
5023
  }
4908
5024
 
@@ -4917,9 +5033,13 @@ export declare namespace Machine {
4917
5033
  Events extends ReadonlyArray<TaggedSchema>,
4918
5034
  StateId extends StateIdentifier<States>
4919
5035
  > {
5036
+ /** Decoded value owned by the final state. */
4920
5037
  readonly state: StateByIdentifier<States, StateId>
5038
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4921
5039
  readonly containingState: ParentStateValue<States, StateId>
5040
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4922
5041
  readonly ancestors: ParentStateValues<States, StateId>
5042
+ /** Lifecycle event responsible for entering the final state. */
4923
5043
  readonly event: LifecycleEvent<Events>
4924
5044
  }
4925
5045
 
@@ -4952,10 +5072,15 @@ export declare namespace Machine {
4952
5072
  Events extends ReadonlyArray<TaggedSchema>,
4953
5073
  StateId extends StateIdentifier<States>
4954
5074
  > {
5075
+ /** Decoded value owned by the completed parallel state. */
4955
5076
  readonly state: StateByIdentifier<States, StateId>
5077
+ /** Value owned by the nearest schema-backed ancestor, when one exists. */
4956
5078
  readonly containingState: ParentStateValue<States, StateId>
5079
+ /** Schema-backed ancestor values keyed by their complete state paths. */
4957
5080
  readonly ancestors: ParentStateValues<States, StateId>
5081
+ /** Lifecycle event retained while parallel completion is processed. */
4958
5082
  readonly event: LifecycleEvent<Events>
5083
+ /** Completion output from every direct parallel region. */
4959
5084
  readonly outputs: ParallelOutputRegions<States, StateId>
4960
5085
  }
4961
5086
 
@@ -5360,6 +5485,7 @@ export declare namespace Machine {
5360
5485
 
5361
5486
  /** Context capability available only to explicitly declinable resolvers. */
5362
5487
  export interface DeclineCapability {
5488
+ /** Declines this candidate and continues hierarchical transition selection. */
5363
5489
  readonly decline: () => Declined
5364
5490
  }
5365
5491
 
@@ -5389,7 +5515,9 @@ export declare namespace Machine {
5389
5515
  export interface TransitionBranchInput<
5390
5516
  Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>
5391
5517
  > {
5518
+ /** Exact topology destination available to the branching resolver. */
5392
5519
  readonly target: Selection
5520
+ /** Optional human-readable branch label used by visualization tooling. */
5393
5521
  readonly title?: string
5394
5522
  }
5395
5523
 
@@ -5469,16 +5597,25 @@ export declare namespace Machine {
5469
5597
  }
5470
5598
  }
5471
5599
 
5472
- 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
+ }
5473
5604
  : { readonly reenter?: never }
5474
5605
 
5475
5606
  type TransitionRequiredOptions<Reenter extends boolean> =
5476
5607
  & TransitionReenterOption<Reenter>
5477
- & { readonly declinable?: false }
5608
+ & {
5609
+ /** Keeps the transition required. The resolver cannot return `decline()`. */
5610
+ readonly declinable?: false
5611
+ }
5478
5612
 
5479
5613
  type TransitionDeclinableOptions<Reenter extends boolean> =
5480
5614
  & TransitionReenterOption<Reenter>
5481
- & { readonly declinable: true }
5615
+ & {
5616
+ /** Adds `decline()` to the resolver context and permits declining this candidate. */
5617
+ readonly declinable: true
5618
+ }
5482
5619
 
5483
5620
  type BuiltTransition<
5484
5621
  States extends StateSchemas,
@@ -5542,7 +5679,23 @@ export declare namespace Machine {
5542
5679
  >
5543
5680
  }
5544
5681
 
5545
- /** 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
+ */
5546
5699
  export type TransitionTarget<
5547
5700
  States extends StateSchemas,
5548
5701
  Events extends ReadonlyArray<TaggedSchema>,
@@ -5566,6 +5719,10 @@ export declare namespace Machine {
5566
5719
  >
5567
5720
  : {})
5568
5721
  & {
5722
+ /**
5723
+ * Evaluates state construction and queued commands only after this
5724
+ * transition has been selected.
5725
+ */
5569
5726
  readonly resolve:
5570
5727
  & TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection>
5571
5728
  & ("declinable" extends Acceptance ? TransitionResolveDeclinable<
@@ -5580,6 +5737,7 @@ export declare namespace Machine {
5580
5737
  : {})
5581
5738
  }
5582
5739
  & ([Reenter] extends [true] ? SelectionSupportsDefaultConstruction<Selection> extends true ? {
5740
+ /** Reenters the source using the selected target's default construction. */
5583
5741
  readonly reenter: () => BuiltTransition<
5584
5742
  States,
5585
5743
  Events,
@@ -5604,9 +5762,12 @@ export declare namespace Machine {
5604
5762
  & Selection
5605
5763
  & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {})
5606
5764
  & {
5765
+ /** Lazily constructs the selected initial state from decoded machine input. */
5607
5766
  readonly resolve: (
5608
5767
  resolve: (context: {
5768
+ /** Decoded value supplied when the machine is started. */
5609
5769
  readonly input: Input
5770
+ /** Builder specialized to the selected initial destination. */
5610
5771
  readonly target: SelectionBuilder<Selection>
5611
5772
  }) => SelectedTargetResult<Selection>
5612
5773
  ) => InitialBuilderEvidence<Selection>
@@ -5760,9 +5921,11 @@ export declare namespace Machine {
5760
5921
  TargetSelector<States, StateId>
5761
5922
  >
5762
5923
  & {
5924
+ /** Declares a closed set of named destinations for one resolver. */
5763
5925
  readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(
5764
5926
  branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>
5765
5927
  ) => {
5928
+ /** Resolves exactly one declared branch after this transition is selected. */
5766
5929
  readonly resolve:
5767
5930
  & TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches>
5768
5931
  & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<
@@ -5982,6 +6145,7 @@ export declare namespace Machine {
5982
6145
  & InvokeTyped<Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes>
5983
6146
  & { readonly [InvokeBuilderTypeId]: true }
5984
6147
 
6148
+ /** Lifecycle handlers exposed according to the selected invocation source. */
5985
6149
  type InvokeBuilder<
5986
6150
  States extends StateSchemas,
5987
6151
  Events extends ReadonlyArray<TaggedSchema>,
@@ -6017,6 +6181,7 @@ export declare namespace Machine {
6017
6181
  >
6018
6182
  : {})
6019
6183
  & ("done" extends Pending ? {
6184
+ /** Handles successful completion and exposes the invocation output. */
6020
6185
  readonly onDone: <
6021
6186
  const Handler extends InvokeTransition<
6022
6187
  States,
@@ -6056,6 +6221,7 @@ export declare namespace Machine {
6056
6221
  }
6057
6222
  : {})
6058
6223
  & ("failure" extends Pending ? {
6224
+ /** Handles typed failure and exposes the invocation error. */
6059
6225
  readonly onFailure: <
6060
6226
  const Handler extends InvokeTransition<
6061
6227
  States,
@@ -6095,6 +6261,7 @@ export declare namespace Machine {
6095
6261
  }
6096
6262
  : {})
6097
6263
  & ("element" extends Pending ? {
6264
+ /** Handles each backpressured element emitted by an invoked Stream. */
6098
6265
  readonly onElement: <
6099
6266
  const Handler extends InvokeTransition<
6100
6267
  States,
@@ -6134,6 +6301,7 @@ export declare namespace Machine {
6134
6301
  }
6135
6302
  : {})
6136
6303
  & ([SnapshotHandler] extends [never] ? {} : {
6304
+ /** Handles each active snapshot published by invoked logic or a child machine. */
6137
6305
  readonly onSnapshot: <const Handler extends SnapshotHandler>(handler: Handler & SnapshotHandler) => InvokeBuilder<
6138
6306
  States,
6139
6307
  Events,
@@ -6303,6 +6471,23 @@ export declare namespace Machine {
6303
6471
  * chain becomes returnable from `invoke` only after every reachable required
6304
6472
  * channel has been handled.
6305
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
+ *
6306
6491
  * @category models
6307
6492
  * @since 0.18.0
6308
6493
  */
@@ -6314,7 +6499,12 @@ export declare namespace Machine {
6314
6499
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6315
6500
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6316
6501
  > {
6317
- /** Starts a fresh Effect each time the owning state is entered. */
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
+ */
6318
6508
  readonly effect: <
6319
6509
  const Source extends (
6320
6510
  context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
@@ -6324,7 +6514,12 @@ export declare namespace Machine {
6324
6514
  source: Source
6325
6515
  ) => EffectInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>
6326
6516
 
6327
- /** Starts a fresh, backpressured Stream each time the owning state is entered. */
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
+ */
6328
6523
  readonly stream: <
6329
6524
  const Source extends (
6330
6525
  context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
@@ -6334,7 +6529,12 @@ export declare namespace Machine {
6334
6529
  source: Source
6335
6530
  ) => StreamInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>
6336
6531
 
6337
- /** Starts a cancellable state-scoped timer. */
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
+ */
6338
6538
  readonly timer: (
6339
6539
  id: InvokeLifecycleId,
6340
6540
  duration: InvokeSource<
@@ -6359,7 +6559,12 @@ export declare namespace Machine {
6359
6559
  never
6360
6560
  >
6361
6561
 
6362
- /** Starts reusable process logic at a typed parent-local address. */
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
+ */
6363
6568
  readonly logic: {
6364
6569
  <
6365
6570
  const Source extends (
@@ -6369,9 +6574,11 @@ export declare namespace Machine {
6369
6574
  >(
6370
6575
  id: InvokeLifecycleId,
6371
6576
  options: {
6577
+ /** Typed parent-local address used to send events to this logic. */
6372
6578
  readonly address:
6373
6579
  & Address
6374
6580
  & ChildAddress.Compatibility<Address, LogicEventOf<ReturnType<NoInfer<Source>>>>
6581
+ /** Context-dependent factory that returns reusable process logic. */
6375
6582
  readonly logic: Source
6376
6583
  },
6377
6584
  ..._validation: ReturnType<Source> extends { readonly initial: unknown; readonly run: unknown } ? [] : [
@@ -6389,7 +6596,9 @@ export declare namespace Machine {
6389
6596
  <const Source, Address extends ChildAddress<never>>(
6390
6597
  id: InvokeLifecycleId,
6391
6598
  options: {
6599
+ /** Typed parent-local address used to send events to this logic. */
6392
6600
  readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<NoInfer<Source>>>
6601
+ /** Reusable process logic started when the owning state enters. */
6393
6602
  readonly logic: Source
6394
6603
  },
6395
6604
  ..._validation: Source extends { readonly initial: unknown; readonly run: unknown } ? [] : [
@@ -6406,7 +6615,12 @@ export declare namespace Machine {
6406
6615
  >
6407
6616
  }
6408
6617
 
6409
- /** Starts a complete child statechart represented by a reusable descriptor. */
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
+ */
6410
6624
  readonly child: <const Child extends ChildMachine.Any>(
6411
6625
  child:
6412
6626
  & Child
@@ -6418,6 +6632,7 @@ export declare namespace Machine {
6418
6632
  : never),
6419
6633
  ...options: InputSchema<Child["machine"]> extends typeof Schema.Void ? [options?: { readonly input?: never }]
6420
6634
  : [options: {
6635
+ /** Child input value or factory evaluated from the owning state context. */
6421
6636
  readonly input: InvokeSource<
6422
6637
  Input<Child["machine"]>,
6423
6638
  InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>
@@ -6455,12 +6670,14 @@ export declare namespace Machine {
6455
6670
  }
6456
6671
  >
6457
6672
 
6673
+ /** Output construction available to final and output-producing parallel states. */
6458
6674
  type OutputHandlerConfig<
6459
6675
  States extends StateSchemas,
6460
6676
  Events extends ReadonlyArray<TaggedSchema>,
6461
6677
  StateId extends StateIdentifier<States>,
6462
6678
  Context
6463
6679
  > = NodeByIdentifier<States, StateId> extends { readonly output: Schema.Top } ? {
6680
+ /** Constructs the decoded output declared by the state's `output` schema. */
6464
6681
  readonly output: (context: Context) => OutputByIdentifier<States, StateId>
6465
6682
  }
6466
6683
  : {
@@ -6484,6 +6701,22 @@ export declare namespace Machine {
6484
6701
  /**
6485
6702
  * Configuration accepted for a non-final state.
6486
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
+ *
6487
6720
  * @category models
6488
6721
  * @since 0.4.0
6489
6722
  */
@@ -6497,15 +6730,19 @@ export declare namespace Machine {
6497
6730
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6498
6731
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6499
6732
  > = {
6733
+ /** Runs synchronously when the state is entered and may enqueue commands. */
6500
6734
  readonly entry?: (
6501
6735
  context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
6502
6736
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
6503
6737
  ) => StateActionResult<any, any>
6738
+ /** Runs synchronously before the state is exited and may enqueue commands. */
6504
6739
  readonly exit?: (
6505
6740
  context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
6506
6741
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
6507
6742
  ) => StateActionResult<any, any>
6743
+ /** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
6508
6744
  readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>
6745
+ /** Eventless transition evaluated after the state becomes stable. */
6509
6746
  readonly always?: TransitionConfig<
6510
6747
  States,
6511
6748
  Events,
@@ -6515,6 +6752,7 @@ export declare namespace Machine {
6515
6752
  false,
6516
6753
  TransitionAcceptance
6517
6754
  >
6755
+ /** Transition evaluated after this compound or parallel state completes. */
6518
6756
  readonly onDone?: TransitionConfig<
6519
6757
  States,
6520
6758
  Events,
@@ -6524,6 +6762,7 @@ export declare namespace Machine {
6524
6762
  false,
6525
6763
  TransitionAcceptance
6526
6764
  >
6765
+ /** Event handlers keyed by the `_tag` of the machine's public or internal events. */
6527
6766
  readonly on?: {
6528
6767
  readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<
6529
6768
  States,
@@ -6535,6 +6774,7 @@ export declare namespace Machine {
6535
6774
  TransitionAcceptance
6536
6775
  >
6537
6776
  }
6777
+ /** Supplies missing direct initial-child values required by implicit entry and shallow history. */
6538
6778
  readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>
6539
6779
  } & ActiveOutputHandlerConfig<States, Events, StateId>
6540
6780
 
@@ -6659,8 +6899,11 @@ export declare namespace Machine {
6659
6899
  Emits extends ReadonlyArray<TaggedSchema>,
6660
6900
  ParentId extends StateIdentifier<States>
6661
6901
  > {
6902
+ /** Lifecycle event that attempted to restore this history node. */
6662
6903
  readonly event: LifecycleEvent<Events>
6904
+ /** Complete target builder rooted at the history owner. */
6663
6905
  readonly target: HistoryDefaultTargetBuilder<States, ParentId>
6906
+ /** State path whose child configuration is restored by this history node. */
6664
6907
  readonly owner: ParentId
6665
6908
  }
6666
6909
 
@@ -6683,7 +6926,26 @@ export declare namespace Machine {
6683
6926
  | CompleteSnapshotContaining<States, ParentId>
6684
6927
  | StateConstruction<CompleteSnapshotContaining<States, ParentId>>
6685
6928
 
6686
- /** 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
+ */
6687
6949
  export type HistoryDefaultConfig<
6688
6950
  States extends StateSchemas,
6689
6951
  Events extends ReadonlyArray<TaggedSchema>,
@@ -6691,9 +6953,7 @@ export declare namespace Machine {
6691
6953
  ParentId extends StateIdentifier<States>,
6692
6954
  Children extends StateSchemas
6693
6955
  > = {
6694
- readonly [Key in HistoryStateKey<Children>]?: {
6695
- readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>
6696
- }
6956
+ readonly [Key in HistoryStateKey<Children>]?: HistoryDefaultEntry<States, Events, Emits, ParentId>
6697
6957
  }
6698
6958
 
6699
6959
  /** Required implementation for a choice pseudo-state. */
@@ -6705,6 +6965,7 @@ export declare namespace Machine {
6705
6965
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6706
6966
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6707
6967
  > {
6968
+ /** Required transition that resolves this transient choice to a concrete destination. */
6708
6969
  readonly choice: TransitionConfig<
6709
6970
  States,
6710
6971
  Events,
@@ -6725,6 +6986,8 @@ export declare namespace Machine {
6725
6986
  /**
6726
6987
  * Configuration accepted for a final state.
6727
6988
  *
6989
+ * @inlineType OutputHandlerConfig
6990
+ *
6728
6991
  * @category models
6729
6992
  * @since 0.4.0
6730
6993
  */
@@ -6736,6 +6999,7 @@ export declare namespace Machine {
6736
6999
  InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6737
7000
  ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6738
7001
  > = {
7002
+ /** Runs synchronously when the final state is entered and may enqueue commands. */
6739
7003
  readonly entry?: (
6740
7004
  context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
6741
7005
  enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>
@@ -6818,6 +7082,7 @@ export declare namespace Machine {
6818
7082
  }
6819
7083
  : { readonly [Key in Path]?: Validation }
6820
7084
 
7085
+ /** Nested handler-tree structure shared by active and final state configs. */
6821
7086
  type HandlerNode<
6822
7087
  AllStates extends StateSchemas,
6823
7088
  Node,
@@ -6839,6 +7104,7 @@ export declare namespace Machine {
6839
7104
  readonly history?: never
6840
7105
  }
6841
7106
  : {
7107
+ /** Child-state handlers nested according to the declared state topology. */
6842
7108
  readonly states?: HandlerTree<
6843
7109
  AllStates,
6844
7110
  Children,
@@ -6850,6 +7116,7 @@ export declare namespace Machine {
6850
7116
  ParentEvents,
6851
7117
  Extract<StateId, StateIdentifier<AllStates>>
6852
7118
  >
7119
+ /** First-use defaults keyed by direct history pseudo-state. */
6853
7120
  readonly history?: HistoryDefaultConfig<
6854
7121
  AllStates,
6855
7122
  Events,
@@ -7733,20 +8000,28 @@ type MakeConfig<
7733
8000
  InternalEvents extends ReadonlyArray<Machine.TaggedSchema>,
7734
8001
  ParentDeclaration extends Parent.Any | undefined
7735
8002
  > = {
8003
+ /** Stable definition identifier used by inspection and visualization. */
7736
8004
  readonly id?: string
8005
+ /** State topology and value schemas, normally supplied by `Machine.states`. */
7737
8006
  readonly states: States & DefineStateTreeInput<NoInfer<States>>
8007
+ /** Public events accepted by independently running machine references. */
7738
8008
  readonly events:
7739
8009
  & Machine.EventProtocol<"public", InputEvents>
7740
8010
  & ValidateInputEventProtocol<NoInfer<InputEvents>>
8011
+ /** Machine-local events used by raised events and other internal deliveries. */
7741
8012
  readonly internalEvents?:
7742
8013
  & Machine.EventProtocol<"internal", InternalEvents>
7743
8014
  & ValidateInternalEventProtocol<
7744
8015
  NoInfer<InputEvents>,
7745
8016
  NoInfer<InternalEvents>
7746
8017
  >
8018
+ /** Ephemeral notifications that handlers may publish to observers. */
7747
8019
  readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>
8020
+ /** Required or optional owning-machine protocol for this definition. */
7748
8021
  readonly parent?: ParentDeclaration
8022
+ /** Schema used to decode input before initial-state construction. */
7749
8023
  readonly input?: Input
8024
+ /** Target-first declaration that constructs the initial active configuration. */
7750
8025
  readonly initial: unknown
7751
8026
  }
7752
8027
 
@@ -7772,7 +8047,9 @@ type MakeResult<
7772
8047
  Machine.ParentEventsOf<ParentDeclaration>
7773
8048
  >
7774
8049
 
8050
+ /** @inline */
7775
8051
  interface Make {
8052
+ /** @param config Complete schema-first machine definition. */
7776
8053
  <
7777
8054
  const States extends Machine.StateSchemas,
7778
8055
  const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
@@ -7791,6 +8068,7 @@ interface Make {
7791
8068
  & { readonly initial: Machine.InitialBuilderInput<States, Input["Type"]> },
7792
8069
  ..._validation: ValidateDefinedStates<NoInfer<States>>
7793
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. */
7794
8072
  <
7795
8073
  const States extends Machine.StateSchemas,
7796
8074
  const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
@@ -7868,6 +8146,7 @@ interface Make {
7868
8146
  * ```
7869
8147
  *
7870
8148
  * @see {@link states} for typed state-tree helpers.
8149
+ * @inlineType MakeConfig
7871
8150
  * @category constructors
7872
8151
  * @since 0.4.0
7873
8152
  */
@@ -8018,18 +8297,21 @@ export const emittedEvents: {
8018
8297
  *
8019
8298
  * **Details**
8020
8299
  *
8021
- * Each active state value and completed output is encoded with the schema
8022
- * declared for its state path. The result contains no process-local runtime
8023
- * 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.
8024
8305
  *
8025
8306
  * **Gotchas**
8026
8307
  *
8027
8308
  * The encoded snapshot does not contain the machine definition, machine
8028
8309
  * version, running children, invoked process state, services, or subscriptions.
8029
8310
  * Store machine identity and migration metadata alongside the result when the
8030
- * snapshot crosses deployment versions. Schema encoding does not by itself
8031
- * guarantee JSON-compatible values; schemas used with JSON-backed storage must
8032
- * 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.
8033
8315
  *
8034
8316
  * **Example**
8035
8317
  *