@typeonce/effect-machine 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +216 -636
  2. package/dist/Machine.d.ts +815 -583
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +20 -8
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/childRegistry.d.ts +1 -1
  7. package/dist/internal/machine/childRegistry.d.ts.map +1 -1
  8. package/dist/internal/machine/cluster.d.ts +2 -50
  9. package/dist/internal/machine/cluster.d.ts.map +1 -1
  10. package/dist/internal/machine/cluster.js +4 -27
  11. package/dist/internal/machine/cluster.js.map +1 -1
  12. package/dist/internal/machine/clusterProtocol.d.ts +35 -0
  13. package/dist/internal/machine/clusterProtocol.d.ts.map +1 -0
  14. package/dist/internal/machine/clusterProtocol.js +28 -0
  15. package/dist/internal/machine/clusterProtocol.js.map +1 -0
  16. package/dist/internal/machine/commandRuntime.d.ts +1 -1
  17. package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
  18. package/dist/internal/machine/configuration.d.ts +2 -1
  19. package/dist/internal/machine/configuration.d.ts.map +1 -1
  20. package/dist/internal/machine/configuration.js +38 -45
  21. package/dist/internal/machine/configuration.js.map +1 -1
  22. package/dist/internal/machine/declaration.d.ts +17 -0
  23. package/dist/internal/machine/declaration.d.ts.map +1 -0
  24. package/dist/internal/machine/declaration.js +120 -0
  25. package/dist/internal/machine/declaration.js.map +1 -0
  26. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  27. package/dist/internal/machine/executionPlan.js +5 -4
  28. package/dist/internal/machine/executionPlan.js.map +1 -1
  29. package/dist/internal/machine/implementation.d.ts +34 -0
  30. package/dist/internal/machine/implementation.d.ts.map +1 -0
  31. package/dist/internal/machine/implementation.js +3 -0
  32. package/dist/internal/machine/implementation.js.map +1 -0
  33. package/dist/internal/machine/invocation.d.ts +1 -1
  34. package/dist/internal/machine/invocation.d.ts.map +1 -1
  35. package/dist/internal/machine/invocation.js +1 -1
  36. package/dist/internal/machine/invocation.js.map +1 -1
  37. package/dist/internal/machine/invocationDefinition.d.ts +1 -1
  38. package/dist/internal/machine/invocationDefinition.d.ts.map +1 -1
  39. package/dist/internal/machine/machine.d.ts +13 -2
  40. package/dist/internal/machine/machine.d.ts.map +1 -1
  41. package/dist/internal/machine/machine.js +140 -278
  42. package/dist/internal/machine/machine.js.map +1 -1
  43. package/dist/internal/machine/planner.d.ts.map +1 -1
  44. package/dist/internal/machine/planner.js +12 -11
  45. package/dist/internal/machine/planner.js.map +1 -1
  46. package/dist/internal/machine/process.d.ts +8 -7
  47. package/dist/internal/machine/process.d.ts.map +1 -1
  48. package/dist/internal/machine/process.js +16 -12
  49. package/dist/internal/machine/process.js.map +1 -1
  50. package/dist/internal/machine/runtime.d.ts +2 -230
  51. package/dist/internal/machine/runtime.d.ts.map +1 -1
  52. package/dist/internal/machine/runtime.js +8 -1857
  53. package/dist/internal/machine/runtime.js.map +1 -1
  54. package/dist/internal/machine/runtimeCompiled.d.ts +5 -0
  55. package/dist/internal/machine/runtimeCompiled.d.ts.map +1 -0
  56. package/dist/internal/machine/runtimeCompiled.js +867 -0
  57. package/dist/internal/machine/runtimeCompiled.js.map +1 -0
  58. package/dist/internal/machine/runtimeGeneric.d.ts +3 -0
  59. package/dist/internal/machine/runtimeGeneric.d.ts.map +1 -0
  60. package/dist/internal/machine/runtimeGeneric.js +471 -0
  61. package/dist/internal/machine/runtimeGeneric.js.map +1 -0
  62. package/dist/internal/machine/runtimeProtocol.d.ts +312 -0
  63. package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -0
  64. package/dist/internal/machine/runtimeProtocol.js +561 -0
  65. package/dist/internal/machine/runtimeProtocol.js.map +1 -0
  66. package/dist/internal/machine/targetReference.d.ts +15 -0
  67. package/dist/internal/machine/targetReference.d.ts.map +1 -0
  68. package/dist/internal/machine/targetReference.js +31 -0
  69. package/dist/internal/machine/targetReference.js.map +1 -0
  70. package/dist/internal/machine/topology.d.ts.map +1 -1
  71. package/dist/internal/machine/topology.js +2 -1
  72. package/dist/internal/machine/topology.js.map +1 -1
  73. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  74. package/dist/internal/testing/machine/finiteModel.js +38 -40
  75. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  76. package/dist/internal/testing/machine/probe.js +1 -1
  77. package/dist/internal/testing/machine/probe.js.map +1 -1
  78. package/dist/unstable/cluster/ClusterMachine.d.ts +5 -5
  79. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
  80. package/dist/unstable/cluster/ClusterMachine.js +5 -17
  81. package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
  82. package/docs/agent-guide.md +66 -91
  83. package/docs/machine-review.md +19 -49
  84. package/docs/root-api.md +62 -62
  85. package/package.json +1 -1
  86. package/src/Machine.ts +1514 -2312
  87. package/src/internal/machine/childRegistry.ts +1 -1
  88. package/src/internal/machine/cluster.ts +7 -73
  89. package/src/internal/machine/clusterProtocol.ts +56 -0
  90. package/src/internal/machine/commandRuntime.ts +1 -1
  91. package/src/internal/machine/configuration.ts +53 -45
  92. package/src/internal/machine/declaration.ts +140 -0
  93. package/src/internal/machine/executionPlan.ts +6 -5
  94. package/src/internal/machine/implementation.ts +41 -0
  95. package/src/internal/machine/invocation.ts +3 -3
  96. package/src/internal/machine/invocationDefinition.ts +1 -1
  97. package/src/internal/machine/machine.ts +199 -409
  98. package/src/internal/machine/planner.ts +54 -35
  99. package/src/internal/machine/process.ts +40 -33
  100. package/src/internal/machine/runtime.ts +20 -3037
  101. package/src/internal/machine/runtimeCompiled.ts +1166 -0
  102. package/src/internal/machine/runtimeGeneric.ts +799 -0
  103. package/src/internal/machine/runtimeProtocol.ts +1213 -0
  104. package/src/internal/machine/targetReference.ts +40 -0
  105. package/src/internal/machine/topology.ts +2 -1
  106. package/src/internal/testing/machine/finiteModel.ts +42 -43
  107. package/src/internal/testing/machine/probe.ts +1 -1
  108. package/src/unstable/cluster/ClusterMachine.ts +9 -17
package/dist/Machine.d.ts CHANGED
@@ -19,7 +19,7 @@ import * as internal from "./internal/machine/machine.js";
19
19
  import { InitialEventTypeId } from "./internal/machine/machine.js";
20
20
  import type { EnsureExecutable } from "./internal/machine/readiness.js";
21
21
  import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js";
22
- import type * as internalRuntime from "./internal/machine/runtime.js";
22
+ import type * as internalRuntime from "./internal/machine/runtimeProtocol.js";
23
23
  import type * as StateDefinition from "./internal/machine/stateDefinition.js";
24
24
  import type * as Topology from "./internal/machine/topology.js";
25
25
  /**
@@ -91,9 +91,33 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
91
91
  *
92
92
  * **Gotchas**
93
93
  *
94
- * Declarative first-class guards are not part of the current API. Conditional
95
- * behavior can be expressed in typed handlers with ordinary TypeScript control
96
- * flow. Use `after` for cancellable state-scoped delayed events.
94
+ * Use `guard` to decline a transition before constructing its next state.
95
+ * Use `declinable: true` when a named branch resolver may return `decline()`.
96
+ * Register cancellable state-scoped delays in `make({ timers })`.
97
+ *
98
+ * **Example**
99
+ *
100
+ * ```ts
101
+ * import { Machine } from "@typeonce/effect-machine"
102
+ * import { Schema } from "effect"
103
+ *
104
+ * const events = Machine.events({ Add: { by: Schema.Number } })
105
+ * const Root = Machine.state({ fields: { count: Schema.Number } })
106
+ * const targets = Machine.targets(Root)
107
+ * export const counter = Machine.make({
108
+ * root: Root,
109
+ * events,
110
+ * initial: (root) => root.from(() => ({ count: 0 }))
111
+ * }).handle({
112
+ * on: {
113
+ * Add: {
114
+ * update: targets.root,
115
+ * guard: ({ event }) => event.by > 0,
116
+ * from: ({ root, event }) => ({ count: root.count + event.by })
117
+ * }
118
+ * }
119
+ * })
120
+ * ```
97
121
  *
98
122
  * @category models
99
123
  * @since 0.4.0
@@ -159,7 +183,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
159
183
  /** @internal */
160
184
  readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
161
185
  /** @internal */
162
- readonly handlers: Machine.StateConfigs<States, Events, Emits, UnhandledStates, Machine.TagOf<Events[number]>, E, R>;
186
+ readonly handlers: Readonly<Record<string, unknown>>;
163
187
  /** @internal */
164
188
  readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
165
189
  /** @internal */
@@ -179,7 +203,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
179
203
  * @category models
180
204
  * @since 0.15.0
181
205
  */
182
- export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []> extends Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents> {
206
+ export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], Registrations extends Machine.Registrations = {}> extends Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents> {
183
207
  /**
184
208
  * Adds typed state handlers and returns an independent machine
185
209
  * implementation. Event dispatch maps and transition descriptors are
@@ -189,12 +213,14 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
189
213
  * **Example**
190
214
  *
191
215
  * ```ts
216
+ * const targets = Machine.targets(States)
192
217
  * const counter = definition.handle({ states: {
193
218
  * Count: {
194
219
  * on: {
195
- * Increment: (to) =>
196
- * to.branch.Count().resolve(({ event, state, target }) =>
197
- * target.decoded(new Count({ value: state.value + event.by })))
220
+ * Increment: {
221
+ * update: targets.root.Count,
222
+ * decoded: ({ event, state }) => new Count({ value: state.value + event.by })
223
+ * }
198
224
  * }
199
225
  * }
200
226
  * } })
@@ -202,7 +228,7 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
202
228
  *
203
229
  * @since 0.4.0
204
230
  */
205
- readonly handle: Machine.Handler<States, Events, Emits, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, never, InputEvents, ParentEvents>;
231
+ readonly handle: Machine.Handler<States, Events, Emits, Input, InitialE, InitialR, FinalStates, Output, InputEvents, ParentEvents, Registrations>;
206
232
  }
207
233
  /**
208
234
  * Namespace containing type-level members associated with {@link Definition}.
@@ -490,9 +516,6 @@ export declare namespace Runtime {
490
516
  }
491
517
  type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? never : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : never;
492
518
  declare const InvokeTypeId: typeof internal.InvokeTypeId;
493
- declare const TransitionTypeId: typeof internal.TransitionTypeId;
494
- declare const TransitionBuilderTypeId: unique symbol;
495
- declare const InvokeBuilderTypeId: unique symbol;
496
519
  declare const InitialBuilderTypeId: unique symbol;
497
520
  type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
498
521
  readonly "~effect/Machine/DefinitionError": Message;
@@ -3052,7 +3075,7 @@ export declare namespace Machine {
3052
3075
  * do not directly control state re-entry. Exit and entry paths are derived
3053
3076
  * from the previous and next active paths. Shared active ancestors remain
3054
3077
  * entered even when a `full` target supplies their values again. Use an event
3055
- * transition with `.reenter()` when the source should explicitly exit and
3078
+ * transition with `reenter: true` when the source should explicitly exit and
3056
3079
  * enter again.
3057
3080
  *
3058
3081
  * @category models
@@ -3117,81 +3140,9 @@ export declare namespace Machine {
3117
3140
  }
3118
3141
  type SelectionValue<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state", Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> = TargetSelection<Builder, Path, Kind, Scope>;
3119
3142
  type SelectionMethod<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state", Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> = () => SelectionValue<Builder, Path, Kind, Scope>;
3120
- type InitialSelectionMethod<Builder, Path extends string, Scope extends Topology.TargetSelectionScope> = Builder extends {
3121
- readonly initial: infer Initial;
3122
- } ? {
3123
- readonly initial: SelectionValue<Initial, Path, "initial", Scope>;
3124
- } : {};
3125
- type SelectionTreeWithPrefix<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Scope extends "local" | "branch", Builder> = {
3126
- readonly [Key in Extract<ActiveStateKey<States> | ChoiceStateKey<States>, keyof Builder>]: SelectionNode<AllStates, States[Key], JoinPath<Prefix, Key>, Scope, Builder[Key]>;
3127
- };
3128
- type SelectionNode<AllStates extends StateSchemas, Node, Path extends string, Scope extends "local" | "branch", Builder> = Node extends ChoiceStateNodeConfig ? SelectionMethod<Builder, Path, "choice", Scope> : Node extends {
3129
- readonly states: infer Children extends StateSchemas;
3130
- } ? SelectionMethod<Builder, Path, "state", Scope> & InitialSelectionMethod<Builder, Path, Scope> & SelectionTreeWithPrefix<AllStates, Children, Path, Scope, Builder> : SelectionMethod<Builder, Path, "state", Scope>;
3131
- /** @internal */
3132
- type StateUpdateSelectionForNode<AllStates extends StateSchemas, Node, Path extends string, Scope extends "local" | "branch"> = Node extends {
3133
- readonly type: "final";
3134
- } ? {} : NodeSchema<Node> extends never ? {} : {
3135
- readonly update: SelectionValue<StateUpdateBuilder<AllStates, Extract<Path, ValuedStateIdentifier<AllStates>>>, Path, "update", Scope>;
3136
- };
3137
- /** @internal */
3138
- type BranchUpdateSelectionPath<AllStates extends StateSchemas, Node, Path extends string, Rest extends string, Scope extends "local" | "branch" = "branch"> = StateUpdateSelectionForNode<AllStates, Node, Path, Scope> & (Node extends {
3139
- readonly states: infer Children extends StateSchemas;
3140
- } ? Rest extends `${infer Head}.${infer Tail}` ? Head extends keyof Children ? {
3141
- readonly [Key in Head]: BranchUpdateSelectionPath<AllStates, Children[Head], JoinPath<Path, Head>, Tail, Scope>;
3142
- } : {} : Rest extends keyof Children ? {
3143
- readonly [Key in Rest]: StateUpdateSelectionForNode<AllStates, Children[Rest], JoinPath<Path, Rest>, Scope>;
3144
- } : {} : {});
3145
- type FullSelectionNode<AllStates extends StateSchemas, Node, Path extends StateIdentifier<AllStates>, Builder> = Node extends {
3146
- readonly states: StateSchemas;
3147
- } ? SelectionMethod<Builder, Path, "state", "full"> & InitialSelectionMethod<Builder, Path, "full"> : SelectionMethod<Builder, Path, "state", "full">;
3148
3143
  type RootBuilder<Builder> = Builder extends {
3149
3144
  readonly "": infer Root;
3150
3145
  } ? Root : never;
3151
- type FullTargetSelector<States extends StateSchemas> = SelectionValue<RootBuilder<FullTargetBuilder<States>>, "", "state", "full"> & InitialSelectionMethod<RootBuilder<FullTargetBuilder<States>>, "", "full">;
3152
- type BranchTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = States[""] extends {
3153
- readonly states: infer Children extends StateSchemas;
3154
- } ? SelectionTreeWithPrefix<States, Children, "", "branch", RootBuilder<BranchTargetBuilder<States, Source>>> & (Source extends ChoiceIdentifier<States> ? {} : Omit<BranchUpdateSelectionPath<States, States[""], "", Source>, "update">) : {};
3155
- type LocalTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = NearestCompoundScope<States, Source> extends infer Scope ? [Scope] extends [never] ? {} : Scope extends StateIdentifier<States> ? ChildrenOf<States, Scope> extends infer Children extends StateSchemas ? LocalTargetBuilder<States, Source> extends infer Builder ? SelectionTreeWithPrefix<States, Children, Scope, "local", Builder> & ("with" extends keyof Builder ? {
3156
- readonly with: SelectionValue<Builder["with"], Scope, "state", "local">;
3157
- } : {}) & (Source extends ChoiceIdentifier<States> ? {} : Scope extends ValuedStateIdentifier<States> ? {
3158
- readonly update: SelectionValue<StateUpdateBuilder<States, Scope>, Scope, "update", "local">;
3159
- } : {}) : {} : {} : {} : {};
3160
- type HistorySelectionTree<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Builder> = {
3161
- readonly [Key in Extract<HistoryContainingKey<States>, keyof Builder>]: States[Key] extends HistoryStateNodeConfig ? SelectionValue<Builder[Key], JoinPath<Prefix, Key>, "history", "full"> : States[Key] extends {
3162
- readonly states: infer Children extends StateSchemas;
3163
- } ? HistorySelectionTree<AllStates, Children, JoinPath<Prefix, Key>, Builder[Key]> : never;
3164
- };
3165
- /**
3166
- * Definition-time topology selector available to an ordinary transition.
3167
- *
3168
- * Topology-only instructions (`none`, declared `initial` and history
3169
- * selections, and `local.with`) are values.
3170
- *
3171
- * State and choice destinations remain callable selection methods so their
3172
- * target-specific resolver APIs retain exact inference.
3173
- */
3174
- interface TargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
3175
- /** Replaces this handler owner's value without reentry. */
3176
- /** Selects the current handler owner for a value update without reentry. */
3177
- readonly self: Source extends ValuedStateIdentifier<States> ? StateUpdateSelectionForNode<States, NodeByIdentifier<States, Source>, Source, "branch"> : {};
3178
- /** Addresses the root and its retained value from any active descendant. */
3179
- readonly root: "" extends ActiveStateKey<States> ? SelectionNode<States, States[""], "", "branch", (BranchTargetBuilder<States, Source> extends {
3180
- readonly "": infer Builder;
3181
- } ? Builder : never)> & StateUpdateSelectionForNode<States, States[""], "", "branch"> : never;
3182
- /** Handles the trigger without selecting a destination. */
3183
- readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none", "local">;
3184
- /** Selects a destination or updates the nearest active compound scope. */
3185
- readonly local: LocalTargetSelector<States, Source>;
3186
- /** Selects a destination or updates a valued active ancestor under the current root. */
3187
- readonly branch: BranchTargetSelector<States, Source>;
3188
- /** Selects a complete destination under any top-level state. */
3189
- readonly full: FullTargetSelector<States>;
3190
- /** Restores a shallow or deep history pseudo-state. */
3191
- readonly history: States[""] extends {
3192
- readonly states: infer Children extends StateSchemas;
3193
- } ? HistorySelectionTree<States, Children, "", RootBuilder<HistoryTargetBuilder<States>>> : {};
3194
- }
3195
3146
  /** Definition-time selector that can choose only a valid top-level initial entry. */
3196
3147
  type InitialTargetSelector<States extends StateSchemas> = {
3197
3148
  readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends {
@@ -3217,13 +3168,8 @@ export declare namespace Machine {
3217
3168
  readonly snapshot: Snapshot<States>;
3218
3169
  /** Event that selected this handler, narrowed by its `_tag`. */
3219
3170
  readonly event: EventByTag<Events, EventTag>;
3220
- /**
3221
- * Provides typed builders for choosing the next active state from this
3222
- * handler. Each builder documents which existing state values it keeps.
3223
- *
3224
- * @since 0.4.0
3225
- */
3226
- readonly target: TargetBuilder<States, StateId>;
3171
+ /** Value owned by the logical root. */
3172
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3227
3173
  };
3228
3174
  /**
3229
3175
  * Context passed to an entry or exit state handler.
@@ -3252,6 +3198,8 @@ export declare namespace Machine {
3252
3198
  readonly children: ChildOwner<EventOf<InputEvents>>;
3253
3199
  /** Value owned by the state that owns this invocation. */
3254
3200
  readonly state: StateByIdentifier<States, StateId>;
3201
+ /** Value owned by the logical root. */
3202
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3255
3203
  /** Value owned by the nearest schema-backed ancestor, when one exists. */
3256
3204
  readonly containingState: ParentStateValue<States, StateId>;
3257
3205
  /** Schema-backed ancestor values keyed by their complete state paths. */
@@ -3274,8 +3222,8 @@ export declare namespace Machine {
3274
3222
  readonly containingState: ParentStateValue<States, StateId>;
3275
3223
  /** Schema-backed ancestor values keyed by their complete state paths. */
3276
3224
  readonly ancestors: ParentStateValues<States, StateId>;
3277
- /** Builders for selecting the owning machine's next state. */
3278
- readonly target: TargetBuilder<States, StateId>;
3225
+ /** Value owned by the logical root. */
3226
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3279
3227
  /** Latest active lifecycle snapshot published by the invoked logic or child. */
3280
3228
  readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
3281
3229
  readonly status: "active";
@@ -3298,8 +3246,8 @@ export declare namespace Machine {
3298
3246
  readonly ancestors: ParentStateValues<States, StateId>;
3299
3247
  /** Complete owning-machine configuration captured for this transition. */
3300
3248
  readonly snapshot: Snapshot<States>;
3301
- /** Builders for selecting the owning machine's next state. */
3302
- readonly target: TargetBuilder<States, StateId>;
3249
+ /** Value owned by the logical root. */
3250
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3303
3251
  /** Successful output produced by the invocation. */
3304
3252
  readonly output: Output;
3305
3253
  };
@@ -3315,8 +3263,8 @@ export declare namespace Machine {
3315
3263
  readonly ancestors: ParentStateValues<States, StateId>;
3316
3264
  /** Complete owning-machine configuration captured for this transition. */
3317
3265
  readonly snapshot: Snapshot<States>;
3318
- /** Builders for selecting the owning machine's next state. */
3319
- readonly target: TargetBuilder<States, StateId>;
3266
+ /** Value owned by the logical root. */
3267
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3320
3268
  /** Next element emitted by the invoked Stream. */
3321
3269
  readonly element: Element;
3322
3270
  };
@@ -3332,8 +3280,8 @@ export declare namespace Machine {
3332
3280
  readonly ancestors: ParentStateValues<States, StateId>;
3333
3281
  /** Complete owning-machine configuration captured for this transition. */
3334
3282
  readonly snapshot: Snapshot<States>;
3335
- /** Builders for selecting the owning machine's next state. */
3336
- readonly target: TargetBuilder<States, StateId>;
3283
+ /** Value owned by the logical root. */
3284
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3337
3285
  /** Typed failure produced by the invocation. */
3338
3286
  readonly error: Error;
3339
3287
  };
@@ -3354,14 +3302,8 @@ export declare namespace Machine {
3354
3302
  readonly snapshot: Snapshot<States>;
3355
3303
  /** Lifecycle event retained while the eventless transition is evaluated. */
3356
3304
  readonly event: LifecycleEvent<Events>;
3357
- /**
3358
- * Provides typed builders for choosing the next active state from this
3359
- * eventless handler. Each builder documents which existing state values it
3360
- * keeps.
3361
- *
3362
- * @since 0.4.0
3363
- */
3364
- readonly target: TargetBuilder<States, StateId>;
3305
+ /** Value owned by the logical root. */
3306
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3365
3307
  };
3366
3308
  /**
3367
3309
  * Context passed to a state completion transition handler.
@@ -3382,14 +3324,8 @@ export declare namespace Machine {
3382
3324
  readonly event: LifecycleEvent<Events>;
3383
3325
  /** Output produced by the completed final child or parallel regions. */
3384
3326
  readonly output: CompletionOutputByIdentifier<States, StateId>;
3385
- /**
3386
- * Provides typed builders for choosing the next active state after this
3387
- * state completes. Each builder documents which existing state values it
3388
- * keeps.
3389
- *
3390
- * @since 0.4.0
3391
- */
3392
- readonly target: TargetBuilder<States, StateId>;
3327
+ /** Value owned by the logical root. */
3328
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3393
3329
  };
3394
3330
  /** Context passed to a transient choice resolver. There is no `state` value. */
3395
3331
  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> & {
@@ -3401,8 +3337,8 @@ export declare namespace Machine {
3401
3337
  };
3402
3338
  /** Lifecycle event that led to the transient choice. */
3403
3339
  readonly event: LifecycleEvent<Events>;
3404
- /** Builders for selecting the concrete destination of this choice. */
3405
- readonly target: TargetBuilder<States, ChoiceId>;
3340
+ /** Value owned by the logical root. */
3341
+ readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
3406
3342
  };
3407
3343
  /**
3408
3344
  * Context passed to a final state output function.
@@ -3475,7 +3411,7 @@ export declare namespace Machine {
3475
3411
  *
3476
3412
  * Handlers return snapshots for complete state replacement, target builder
3477
3413
  * results for path-safe partial transitions, state-value updates, or
3478
- * an explicit targetless result. In a machine definition, select `to.none`;
3414
+ * an explicit targetless result. In a machine definition, select `{ none: true }`;
3479
3415
  * its optional resolver returns `undefined`. Raw decoded state values are
3480
3416
  * not accepted as transition targets.
3481
3417
  *
@@ -3542,7 +3478,9 @@ export declare namespace Machine {
3542
3478
  * @category utility types
3543
3479
  * @since 0.4.0
3544
3480
  */
3545
- type EventTransitionReturn<Transition> = Transition extends (...args: any) => infer Authored ? Authored extends TransitionBuilderEvidence<infer Result, any> ? Result : never : Transition extends {
3481
+ type EventTransitionReturn<Transition> = Transition extends {
3482
+ readonly initial: TargetReference<any, infer P, any>;
3483
+ } ? InitialTarget<P> : Transition extends {
3546
3484
  readonly resolve?: infer Resolve;
3547
3485
  } ? NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never : never;
3548
3486
  /**
@@ -3571,7 +3509,7 @@ export declare namespace Machine {
3571
3509
  * @category utility types
3572
3510
  * @since 0.4.0
3573
3511
  */
3574
- type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source;
3512
+ type InvokeResolvedSource<Source> = Source extends LazyProgramValue ? Source : Source extends (...args: any) => infer Resolved ? Resolved : Source;
3575
3513
  type InvokeFactoryResult<Source> = Source extends (...args: any) => infer Resolved ? Resolved : never;
3576
3514
  type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialServices<M> | Services<M>>, internalRuntime.MachineRuntime>, Event<M>, EmittedEvent<M>>, Output<M>, InitialError<M> | Error<M> | ActionError<InitialServices<M> | Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError> : never;
3577
3515
  type InvokeLogic<Invoke> = Invoke extends {
@@ -3595,7 +3533,7 @@ export declare namespace Machine {
3595
3533
  readonly [InvokeTypeId]: {
3596
3534
  readonly initialError: Types.Covariant<infer InitialError>;
3597
3535
  };
3598
- } ? InitialError : InvokeLogic<Invoke> extends Logic<any, any, any, any, any, infer InitialError> ? InitialError : never;
3536
+ } ? InitialError : LogicInitialErrorOf<InvokeLogic<Invoke>>;
3599
3537
  /**
3600
3538
  * Extracts the runtime error from an invoked child process.
3601
3539
  *
@@ -3606,7 +3544,7 @@ export declare namespace Machine {
3606
3544
  readonly [InvokeTypeId]: {
3607
3545
  readonly error: Types.Covariant<infer Error>;
3608
3546
  };
3609
- } ? Error : InvokeLogic<Invoke> extends Logic<any, any, infer Error, any, any, any> ? Error : never;
3547
+ } ? Error : LogicErrorOf<InvokeLogic<Invoke>>;
3610
3548
  /**
3611
3549
  * Extracts the output from an invoked child process.
3612
3550
  *
@@ -3617,7 +3555,7 @@ export declare namespace Machine {
3617
3555
  readonly [InvokeTypeId]: {
3618
3556
  readonly output: Types.Covariant<infer Output>;
3619
3557
  };
3620
- } ? Output : InvokeLogic<Invoke> extends Logic<any, any, any, any, infer Output, any> ? Output : never;
3558
+ } ? Output : LogicOutputOf<InvokeLogic<Invoke>>;
3621
3559
  /**
3622
3560
  * Extracts the service requirements from an invoke source child process logic.
3623
3561
  *
@@ -3628,7 +3566,7 @@ export declare namespace Machine {
3628
3566
  readonly [InvokeTypeId]: {
3629
3567
  readonly requirements: Types.Covariant<infer Requirements>;
3630
3568
  };
3631
- } ? Requirements : InvokeLogic<Invoke> extends Logic<any, any, any, infer Requirements, any, any> ? Requirements : never;
3569
+ } ? Requirements : LogicServicesOf<InvokeLogic<Invoke>>;
3632
3570
  /**
3633
3571
  * Extracts events emitted directly by an invoked child.
3634
3572
  *
@@ -3714,30 +3652,20 @@ export declare namespace Machine {
3714
3652
  * @since 0.4.0
3715
3653
  */
3716
3654
  type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config>;
3717
- /** Type evidence retained by an authored transition without affecting runtime data. */
3718
- interface TransitionTyped<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance = "required"> {
3719
- readonly [TransitionTypeId]: {
3720
- readonly owner: Types.Covariant<readonly [States, Events, Emits, StateId, Context]>;
3721
- readonly acceptance: Types.Covariant<Acceptance>;
3722
- };
3723
- }
3724
3655
  /** The only transition value accepted by machine handler APIs. */
3725
- type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = TransitionBuilderInput<States, Events, Emits, StateId, Context, Reenter, Acceptance>;
3656
+ type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = Transition<States, StateId, Context, Events, Emits, {}, Reenter, Acceptance>;
3726
3657
  type SelectionBuilder<Selection> = Selection extends TargetSelection<infer Builder, any, any, any> ? Builder : never;
3727
3658
  type SelectionKind<Selection> = Selection extends TargetSelection<any, any, infer Kind, any> ? Kind : never;
3728
3659
  type SelectionPath<Selection> = Selection extends TargetSelection<any, infer Path, any, any> ? Path : never;
3729
- type SelectionScope<Selection> = Selection extends TargetSelection<any, any, any, infer Scope> ? Scope : never;
3730
3660
  type TargetBuilderResult<Builder> = (Builder extends (...args: any) => infer Result ? Result : never) | (Builder extends {
3731
3661
  readonly decoded: (...args: any) => infer Result;
3732
3662
  } ? Result : never) | (Builder extends {
3733
3663
  readonly from: (...args: any) => infer Result;
3734
3664
  } ? Result : never);
3735
3665
  type SelectedTargetResult<Selection> = SelectionBuilder<Selection> extends infer Builder ? TargetBuilderResult<Builder> : never;
3736
- type RetainedUpdateOwner<States extends StateSchemas, Source extends StateNodeIdentifier<States>, Selection> = Extract<ParentStateIdentifier<Source>, ParentStateIdentifier<Extract<SelectionPath<Selection>, string>> & ValuedStateIdentifier<States>>;
3737
- type RetainedOwnerSelector<Owner extends string> = () => TargetSelection<any, Owner, "state", "branch">;
3738
3666
  /**
3739
3667
  * Destination construction returned when a transition declares one retained
3740
- * valued owner with `.updating(...)`.
3668
+ * valued owner with a `{ target, update }` declaration.
3741
3669
  *
3742
3670
  * @category models
3743
3671
  * @since 0.22.0
@@ -3762,31 +3690,11 @@ export declare namespace Machine {
3762
3690
  type TransitionResolveContext<Context, Selection> = Omit<Context, "target"> & (SelectionKind<Selection> extends "none" ? {} : {
3763
3691
  readonly target: SelectionBuilder<Selection>;
3764
3692
  });
3765
- type StateUpdateResolveContext<States extends StateSchemas, Context, Owner extends ValuedStateIdentifier<States>> = Omit<Context, "target"> & {
3766
- /** Decoded owner value from the pre-transition snapshot. */
3767
- readonly current: StateByIdentifier<States, Owner>;
3768
- /** Constructs the complete replacement for the selected owner. */
3769
- readonly owner: StateUpdateBuilder<States, Owner>;
3770
- };
3771
- type UpdatingTransitionResolveContext<States extends StateSchemas, Context, Selection, Owner extends ValuedStateIdentifier<States>> = Omit<Context, "target"> & {
3772
- /** Decoded owner value from the pre-transition snapshot. */
3773
- readonly current: StateByIdentifier<States, Owner>;
3774
- /** Constructs the selected topology and requires `.update(...)`. */
3775
- readonly target: UpdatingTargetBuilder<SelectionBuilder<Selection>, States, Owner>;
3776
- /** Constructs the complete replacement for the retained owner. */
3777
- readonly owner: StateUpdateBuilder<States, Owner>;
3778
- };
3779
3693
  /** Context capability available only to explicitly declinable resolvers. */
3780
3694
  interface DeclineCapability {
3781
3695
  /** Declines this candidate and continues hierarchical transition selection. */
3782
3696
  readonly decline: () => Declined;
3783
3697
  }
3784
- type TransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined;
3785
- type DeclinableTransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined;
3786
- /** @internal */
3787
- type StateUpdateResolver<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Owner extends ValuedStateIdentifier<States>> = (context: StateUpdateResolveContext<States, Context, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateUpdate<States, Owner>;
3788
- /** @internal */
3789
- type DeclinableStateUpdateResolver<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Owner extends ValuedStateIdentifier<States>> = (context: StateUpdateResolveContext<States, Context, Owner> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateUpdate<States, Owner> | Declined;
3790
3698
  /** One named destination declared by a branching transition. */
3791
3699
  interface TransitionBranchInput<Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>> {
3792
3700
  /** Exact topology destination available to the branching resolver. */
@@ -3801,13 +3709,23 @@ export declare namespace Machine {
3801
3709
  readonly result: Types.Covariant<Result>;
3802
3710
  };
3803
3711
  }
3712
+ type CompletedBranchResult<R> = R extends {
3713
+ readonly update: unknown;
3714
+ } ? R extends UpdatingStateConstruction<infer Target, infer S, infer Owner> ? CombinedTarget<UnwrapConstruction<Target>, S, Owner> : R : R;
3715
+ type SelectedConstruction<K extends string, R> = R extends {
3716
+ readonly update: unknown;
3717
+ } ? R extends UpdatingStateConstruction<infer Target, infer S, infer Owner> ? {
3718
+ readonly update: SelectedBranchBuilder<StateUpdateBuilder<S, Owner>, K> extends infer B ? {
3719
+ readonly [M in keyof B]: StateUpdateBuilder<S, Owner>[Extract<M, keyof StateUpdateBuilder<S, Owner>>] extends (...args: infer A) => unknown ? (...args: A) => SelectedBranch<K, CombinedTarget<UnwrapConstruction<Target>, S, Owner>> : never;
3720
+ } : never;
3721
+ } : SelectedBranch<K, R> : SelectedBranch<K, R>;
3804
3722
  type SelectedBranchCallable<Callable, Key extends string> = Callable extends {
3805
3723
  (...args: infer Arguments1): infer Result1;
3806
3724
  (...args: infer Arguments2): infer Result2;
3807
3725
  } ? {
3808
- (...args: Arguments1): SelectedBranch<Key, Result1>;
3809
- (...args: Arguments2): SelectedBranch<Key, Result2>;
3810
- } : Callable extends (...args: infer Arguments) => infer Result ? (...args: Arguments) => SelectedBranch<Key, Result> : {};
3726
+ (...args: Arguments1): SelectedConstruction<Key, Result1>;
3727
+ (...args: Arguments2): SelectedConstruction<Key, Result2>;
3728
+ } : Callable extends (...args: infer Arguments) => infer Result ? (...args: Arguments) => SelectedConstruction<Key, Result> : {};
3811
3729
  type SelectedBranchBuilderProperties<Builder, Key extends string> = {
3812
3730
  readonly [Property in keyof Builder]: Builder[Property] extends (...args: any) => any ? SelectedBranchCallable<Builder[Property], Key> : Builder[Property];
3813
3731
  };
@@ -3817,131 +3735,14 @@ export declare namespace Machine {
3817
3735
  readonly [Key in Extract<keyof Branches, string>]: SelectedBranchBuilder<SelectionBuilder<Branches[Key]["target"]>, Key>;
3818
3736
  };
3819
3737
  type BranchSelectionResult<Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
3820
- readonly [Key in Extract<keyof Branches, string>]: SelectedBranch<Key, SelectedTargetResult<Branches[Key]["target"]>>;
3738
+ readonly [Key in Extract<keyof Branches, string>]: SelectedBranch<Key, CompletedBranchResult<SelectedTargetResult<Branches[Key]["target"]>>>;
3821
3739
  }[Extract<keyof Branches, string>];
3822
3740
  type TransitionBranchesResolveContext<Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = Omit<Context, "target"> & {
3823
3741
  readonly select: BranchSelectors<Branches>;
3824
3742
  };
3825
- type TransitionBranchesResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = (context: TransitionBranchesResolveContext<Context, Branches>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => BranchSelectionResult<Branches>;
3826
- type DeclinableTransitionBranchesResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = (context: TransitionBranchesResolveContext<Context, Branches> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => BranchSelectionResult<Branches> | Declined;
3827
- /** @internal Type evidence retained by a transition authored through its bound selector. */
3828
- interface TransitionBuilderEvidence<out Result, out Acceptance extends TransitionAcceptance> {
3829
- readonly [TransitionBuilderTypeId]: {
3830
- readonly result: Types.Covariant<Result>;
3831
- readonly acceptance: Types.Covariant<Acceptance>;
3832
- };
3833
- }
3834
- type TransitionRequiredOptions = {
3835
- /** Keeps the transition required. The resolver cannot return `decline()`. */
3836
- readonly declinable?: false;
3837
- readonly reenter?: never;
3838
- };
3839
- type TransitionDeclinableOptions = {
3840
- /** Adds `decline()` to the resolver context and permits declining this candidate. */
3841
- readonly declinable: true;
3842
- readonly reenter?: never;
3843
- };
3844
- 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>;
3845
- interface TransitionResolveRequired<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>> {
3846
- (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
3847
- }
3848
- 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>> {
3849
- (resolve: DeclinableTransitionResolver<Events, Emits, Context, Selection>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined, "declinable">;
3850
- }
3851
3743
  type ConstructionCallbacks<Context, Builder, Result> = {
3852
3744
  readonly [Method in Extract<keyof Builder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown ? Args extends readonly [unknown?] ? Method : never : never]: Builder[Method] extends (...args: infer Args) => unknown ? (value: (context: Context) => Args[0]) => Result : never;
3853
3745
  };
3854
- type GuardedTransition<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>> = ConstructionCallbacks<Omit<Context, "target">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">> & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable"> : {}) & {
3855
- readonly resolve: (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
3856
- };
3857
- /**
3858
- * A selected transition target with target-specific resolver operations.
3859
- *
3860
- * **Example** (Constructing state while reentering)
3861
- *
3862
- * ```ts
3863
- * Reset: (to) =>
3864
- * to.branch.Ready().reenter().from(({ event }) => ({ count: event.count }))
3865
- * ```
3866
- *
3867
- * @inlineType TransitionRequiredOptions
3868
- * @inlineType TransitionDeclinableOptions
3869
- */
3870
- 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 & ("declinable" extends Acceptance ? {
3871
- /** Declines this candidate before construction when the predicate is false. */
3872
- readonly guard: (predicate: (context: Omit<Context, "target">) => boolean) => GuardedTransition<States, Events, Emits, StateId, Context, Reenter, Selection>;
3873
- } : {}) & ConstructionCallbacks<Omit<Context, "target">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required"> : {}) & {
3874
- /** Evaluates state construction after this transition is selected. */
3875
- readonly resolve: TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? TransitionResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
3876
- } & ([Reenter] extends [true] ? {
3877
- /** Forces source exit and entry, preserving subsequent construction and guards. */
3878
- readonly reenter: () => Omit<TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>, typeof Topology.TargetSelectionTypeId>;
3879
- } : {}) & (SelectionKind<Selection> extends "state" ? SelectionScope<Selection> extends "local" | "branch" ? RetainedUpdateOwner<States, StateId, Selection> extends infer Owner extends ValuedStateIdentifier<States> ? [
3880
- Owner
3881
- ] extends [never] ? {} : {
3882
- /** Declares one valued owner retained by the selected topology. */
3883
- readonly updating: <SelectedOwner extends Owner>(owner: RetainedOwnerSelector<SelectedOwner>) => UpdatingTransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection, SelectedOwner>;
3884
- } : {} : {} : {});
3885
- type UpdatingConstructionCallbacks<Context, Builder, OwnerBuilder, Result> = {
3886
- readonly [Method in Extract<keyof Builder & keyof OwnerBuilder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown ? Args extends readonly [unknown?] ? Method : never : never]: Builder[Method] extends (...args: infer Args) => unknown ? OwnerBuilder[Method] extends (value: infer Update) => unknown ? (construct: (context: Context) => {
3887
- readonly target: Args[0];
3888
- readonly update: Update;
3889
- }) => Result : never : never;
3890
- };
3891
- type UpdatingCallbacks<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>, Acceptance extends TransitionAcceptance> = UpdatingConstructionCallbacks<Omit<UpdatingTransitionResolveContext<States, Context, Selection, Owner>, "owner" | "target">, SelectionBuilder<Selection>, StateUpdateBuilder<States, Owner>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | (Acceptance extends "declinable" ? Declined : never), Acceptance>>;
3892
- type GuardedUpdatingTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>> = UpdatingCallbacks<States, Events, Emits, StateId, Context, Reenter, Selection, Owner, "declinable"> & {
3893
- readonly resolve: (resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable">;
3894
- };
3895
- /**
3896
- * A topology selection that requires one retained owner replacement.
3897
- *
3898
- * `.from` constructs both values from schema inputs; `.decoded` accepts both
3899
- * decoded values. Both callbacks return `{ target, update }` and read the same
3900
- * pre-transition snapshot. Use `.resolve` for explicit child construction,
3901
- * mixed construction methods, or queued commands.
3902
- *
3903
- * **Example** (Guarding an atomic destination and owner update)
3904
- *
3905
- * ```ts
3906
- * Save: (to) => to.local.Saving().updating(to.root)
3907
- * .guard(({ current }) => current.draft.length > 0)
3908
- * .from(({ current }) => ({
3909
- * target: { text: current.draft },
3910
- * update: { ...current, attempts: current.attempts + 1 }
3911
- * }))
3912
- * ```
3913
- */
3914
- type UpdatingTransitionTarget<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, "state">, Owner extends ValuedStateIdentifier<States>> = Selection & UpdatingCallbacks<States, Events, Emits, StateId, Context, Reenter, Selection, Owner, "required"> & ([Reenter] extends [true] ? {
3915
- readonly reenter: () => Omit<UpdatingTransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection, Owner>, typeof Topology.TargetSelectionTypeId>;
3916
- } : {}) & ("declinable" extends Acceptance ? {
3917
- /** Declines before either value is constructed or any commands are enqueued. */
3918
- readonly guard: (predicate: (context: Omit<UpdatingTransitionResolveContext<States, Context, Selection, Owner>, "owner" | "target">) => boolean) => GuardedUpdatingTransition<States, Events, Emits, StateId, Context, Reenter, Selection, Owner>;
3919
- } : {}) & {
3920
- /** @internal */
3921
- readonly "~effect/Machine/UpdatingTransitionTarget": Owner;
3922
- readonly resolve: ((resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, "required">) & ("declinable" extends Acceptance ? (resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, options: TransitionDeclinableOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable"> : {});
3923
- };
3924
- /** @internal */
3925
- interface StateUpdateTransitionRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> {
3926
- (resolve: StateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">;
3927
- }
3928
- /** @internal */
3929
- interface StateUpdateTransitionDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> {
3930
- (resolve: DeclinableStateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
3931
- }
3932
- type GuardedStateUpdateTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> = ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">> & {
3933
- readonly resolve: (resolve: StateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
3934
- };
3935
- /** @internal */
3936
- type StateUpdateTransition<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, "update">> = Selection & ([Reenter] extends [true] ? {
3937
- /** Reenters the source while updating its retained valued ancestor. */
3938
- readonly reenter: () => Omit<StateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>, typeof Topology.TargetSelectionTypeId>;
3939
- } : {}) & ("declinable" extends Acceptance ? {
3940
- /** Declines before replacing the selected owner value. */
3941
- readonly guard: (predicate: (context: Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">) => boolean) => GuardedStateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Selection>;
3942
- } : {}) & ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & {
3943
- readonly resolve: StateUpdateTransitionRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? StateUpdateTransitionDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
3944
- };
3945
3746
  /** @internal Type evidence retained by a machine initial-entry declaration. */
3946
3747
  interface InitialBuilderEvidence<out Selection> {
3947
3748
  readonly [InitialBuilderTypeId]: Types.Covariant<Selection>;
@@ -3989,51 +3790,12 @@ export declare namespace Machine {
3989
3790
  readonly "": Root;
3990
3791
  }>>) => InitialBuilderEvidence<RootConfigurationSelection<Root>>;
3991
3792
  }) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
3992
- type TransitionSelectorNode<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Node> = Node extends TargetSelection<any, any, "update"> ? StateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node> : Node extends (...args: infer Args) => infer Selection ? Selection extends TargetSelection<any, any, any> ? ((...args: Args) => TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>) & {
3993
- readonly [Key in keyof Node]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node[Key]>;
3994
- } : never : Node extends TargetSelection<any, any, any> ? TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node> : {
3995
- readonly [Key in keyof Node]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node[Key]>;
3996
- };
3997
- interface TransitionBranchesResolveRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Branches extends Readonly<Record<string, TransitionBranchInput>>> {
3998
- (resolve: TransitionBranchesResolver<Events, Emits, Context, Branches>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches>, "required">;
3999
- }
4000
- interface TransitionBranchesResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Branches extends Readonly<Record<string, TransitionBranchInput>>> {
4001
- (resolve: DeclinableTransitionBranchesResolver<Events, Emits, Context, Branches>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches> | Declined, "declinable">;
4002
- }
4003
- type TransitionSelectorTargets<in out States extends StateSchemas, in out Events extends ReadonlyArray<TaggedSchema>, in out Emits extends ReadonlyArray<TaggedSchema>, in out StateId extends StateNodeIdentifier<States>, in out Context, in out Reenter extends boolean, in out Acceptance extends TransitionAcceptance> = {
4004
- readonly [Key in keyof TargetSelector<States, StateId>]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Key extends "self" ? false : Reenter, Acceptance, TargetSelector<States, StateId>[Key]>;
4005
- };
4006
- type TransitionBranchesTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
4007
- /** Resolves exactly one declared branch after this transition is selected. */
4008
- readonly resolve: TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches> & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Branches> : {});
4009
- } & ([Reenter] extends [true] ? {
4010
- readonly reenter: () => TransitionBranchesTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Branches>;
4011
- } : {});
4012
- /** Selector supplied to inline transition declarations. */
4013
- interface TransitionSelector<in out States extends StateSchemas, in out Events extends ReadonlyArray<TaggedSchema>, in out Emits extends ReadonlyArray<TaggedSchema>, in out StateId extends StateNodeIdentifier<States>, in out Context, in out Reenter extends boolean, in out Acceptance extends TransitionAcceptance> extends TransitionSelectorTargets<States, Events, Emits, StateId, Context, Reenter, Acceptance> {
4014
- /** Declares a closed set of named destinations for one resolver. */
4015
- readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>) => TransitionBranchesTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Branches>;
4016
- }
4017
- /** Inline transition declaration accepted by state and invocation handlers. */
4018
- type TransitionBuilderInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance> = (to: TransitionSelector<States, Events, Emits, StateId, Context, Reenter, Acceptance>) => TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<any, Acceptance>;
4019
3793
  type InvokeTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context> = TransitionConfig<States, Events, Emits, StateId, Context, true, TransitionAcceptance>;
4020
3794
  type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
4021
3795
  /** Inline state-owned work that runs for the lifetime of its active state. */
4022
3796
  interface InvokeOwned<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 []> {
4023
3797
  readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId, InputEvents, ParentEvents]>;
4024
3798
  }
4025
- /** Type evidence retained by a completed state-owned invocation. */
4026
- interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never, Outcomes = never> {
4027
- readonly [InvokeTypeId]: {
4028
- readonly output: Types.Covariant<Output>;
4029
- readonly error: Types.Covariant<Error>;
4030
- readonly requirements: Types.Covariant<Requirements>;
4031
- readonly initialError: Types.Covariant<InitialError>;
4032
- readonly emits: Types.Covariant<Emits>;
4033
- readonly parentEvents: Types.Covariant<ParentEvent>;
4034
- readonly outcomes: Types.Covariant<Outcomes>;
4035
- };
4036
- }
4037
3799
  type StoredInvokeConfig<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 []> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & ({
4038
3800
  readonly id: string;
4039
3801
  readonly effect: (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<any, any, any>;
@@ -4111,137 +3873,6 @@ export declare namespace Machine {
4111
3873
  type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>;
4112
3874
  type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>;
4113
3875
  type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>;
4114
- type RequiredInvokeChannel<Value, Channel extends string> = IsAny<Value> extends true ? Channel : [Value] extends [never] ? never : Channel;
4115
- 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> & {
4116
- readonly [InvokeBuilderTypeId]: true;
4117
- };
4118
- /** Lifecycle handlers exposed according to the selected invocation source. */
4119
- 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 ? {
4120
- /** Handles successful completion and exposes the invocation output. */
4121
- 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>;
4122
- } : {}) & ("failure" extends Pending ? {
4123
- /** Handles typed failure and exposes the invocation error. */
4124
- 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>;
4125
- } : {}) & ("element" extends Pending ? {
4126
- /** Handles each backpressured element emitted by an invoked Stream. */
4127
- 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>;
4128
- } : {}) & ([SnapshotHandler] extends [never] ? {} : {
4129
- /** Handles each active snapshot published by invoked logic or a child machine. */
4130
- 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>;
4131
- });
4132
- 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>;
4133
- type StreamInvokeBuilder<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>) => Stream.Stream<any, any, any>> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, void, Stream.Error<ReturnType<Source>>, Stream.Services<ReturnType<Source>>, never, never, never, Stream.Success<ReturnType<Source>>, "done" | RequiredInvokeChannel<Stream.Success<ReturnType<Source>>, "element"> | RequiredInvokeChannel<Stream.Error<ReturnType<Source>>, "failure">, never>;
4134
- type LogicInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, ChildLogic> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, LogicOutputOf<ChildLogic>, LogicErrorOf<ChildLogic>, LogicServicesOf<ChildLogic>, LogicInitialErrorOf<ChildLogic>, never, never, never, RequiredInvokeChannel<LogicOutputOf<ChildLogic>, "done"> | RequiredInvokeChannel<LogicErrorOf<ChildLogic>, "failure">, InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, LogicStateOf<ChildLogic>, LogicErrorOf<ChildLogic>, LogicOutputOf<ChildLogic>, InputEvents, ParentEvents>>>;
4135
- type ChildInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Child extends ChildMachine.Any, ChildDefinition extends Machine.Any = Child["machine"]> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output<ChildDefinition>, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, Services<ChildDefinition>, InitialError<ChildDefinition>, EmittedEvent<ChildDefinition>, EventOf<Machine.ParentEvents<ChildDefinition>>, never, RequiredInvokeChannel<Output<ChildDefinition>, "done"> | RequiredInvokeChannel<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, "failure">, InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>>;
4136
- /**
4137
- * Selects state-owned work and begins its lifecycle-handler chain.
4138
- *
4139
- * Each source exposes exactly the lifecycle methods that it can produce. A
4140
- * chain becomes returnable from `invoke` only after every reachable required
4141
- * channel has been handled.
4142
- *
4143
- * **Example** (Invoking an Effect)
4144
- *
4145
- * ```ts
4146
- * invoke: (from) =>
4147
- * from.effect("load-user", () => loadUser).onDone((to) =>
4148
- * to.branch.Ready().resolve(({ output, target }) => target.from({ user: output }))
4149
- * ).onFailure((to) =>
4150
- * to.branch.Failed().resolve(({ error, target }) => target.from({ error }))
4151
- * )
4152
- * ```
4153
- *
4154
- * @inlineType EffectInvokeBuilder
4155
- * @inlineType StreamInvokeBuilder
4156
- * @inlineType LogicInvokeBuilder
4157
- * @inlineType ChildInvokeBuilder
4158
- * @inlineType InvokeBuilder
4159
- *
4160
- * @category models
4161
- * @since 0.18.0
4162
- */
4163
- 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 []> {
4164
- /**
4165
- * Starts a fresh Effect each time the owning state is entered.
4166
- *
4167
- * @param id Parent-local lifecycle identifier.
4168
- * @param source Lazy Effect factory evaluated on every entry.
4169
- */
4170
- 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>;
4171
- /**
4172
- * Starts a fresh, backpressured Stream each time the owning state is entered.
4173
- *
4174
- * @param id Parent-local lifecycle identifier.
4175
- * @param source Lazy Stream factory evaluated on every entry.
4176
- */
4177
- 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>;
4178
- /**
4179
- * Starts a cancellable state-scoped timer.
4180
- *
4181
- * @param id Parent-local lifecycle identifier.
4182
- * @param duration Duration input or context-dependent duration factory.
4183
- */
4184
- 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>;
4185
- /**
4186
- * Starts reusable process logic at a typed parent-local address.
4187
- *
4188
- * @param id Parent-local lifecycle identifier.
4189
- * @param options Address and reusable logic value or factory.
4190
- */
4191
- readonly logic: {
4192
- <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
4193
- /** Typed parent-local address used to send events to this logic. */
4194
- readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<ReturnType<NoInfer<Source>>>>;
4195
- /** Context-dependent factory that returns reusable process logic. */
4196
- readonly logic: Source;
4197
- }, ..._validation: ReturnType<Source> extends {
4198
- readonly initial: unknown;
4199
- readonly run: unknown;
4200
- } ? [] : [
4201
- "logic factory must return Machine.Logic"
4202
- ]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, ReturnType<Source>>;
4203
- <const Source, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
4204
- /** Typed parent-local address used to send events to this logic. */
4205
- readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<NoInfer<Source>>>;
4206
- /** Reusable process logic started when the owning state enters. */
4207
- readonly logic: Source;
4208
- }, ..._validation: Source extends {
4209
- readonly initial: unknown;
4210
- readonly run: unknown;
4211
- } ? [] : [
4212
- "logic must implement Machine.Logic"
4213
- ]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
4214
- };
4215
- /**
4216
- * Starts a complete child statechart represented by a reusable descriptor.
4217
- *
4218
- * @param child Reusable descriptor created with `Machine.child`.
4219
- * @param options Input construction for a child with a non-void input schema.
4220
- */
4221
- 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?: {
4222
- readonly input?: never;
4223
- }] : [
4224
- options: {
4225
- /** Child input value or factory evaluated from the owning state context. */
4226
- readonly input: InvokeSource<Input<Child["machine"]>, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
4227
- }
4228
- ]) => ChildInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Child>;
4229
- }
4230
- /**
4231
- * Inline invocation declaration accepted by an active state handler.
4232
- *
4233
- * Return one completed source chain or an array of completed chains. Source
4234
- * computations and child descriptors may be extracted, but the chain stays
4235
- * local to preserve the owning state and machine protocols.
4236
- *
4237
- * @category models
4238
- * @since 0.18.0
4239
- */
4240
- type InvokeBuilderInput<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 []> = (from: InvokeSelector<States, Events, Emits, StateId, InputEvents, ParentEvents>) => (InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
4241
- readonly [InvokeBuilderTypeId]: true;
4242
- }) | ReadonlyArray<InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
4243
- readonly [InvokeBuilderTypeId]: true;
4244
- }>;
4245
3876
  /** Output construction available to final and output-producing parallel states. */
4246
3877
  type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
4247
3878
  readonly output: Schema.Top;
@@ -4256,46 +3887,6 @@ export declare namespace Machine {
4256
3887
  } ? OutputHandlerConfig<States, Events, StateId, ParallelOutputContext<States, Events, StateId>> : {
4257
3888
  readonly output?: never;
4258
3889
  };
4259
- /**
4260
- * Configuration accepted for a non-final state.
4261
- *
4262
- * **Example** (State actions, events, and invocation)
4263
- *
4264
- * ```ts
4265
- * machine.handle({ states: {
4266
- * Loading: {
4267
- * entry: (_, enqueue) => enqueue.emit({ _tag: "Started" }),
4268
- * invoke: (from) =>
4269
- * from.effect("load", () => load).onDone((to) => to.branch.Ready()),
4270
- * on: { Cancel: (to) => to.branch.Idle() }
4271
- * }
4272
- * } })
4273
- * ```
4274
- *
4275
- * @inlineType ActiveOutputHandlerConfig
4276
- * @inlineType OutputHandlerConfig
4277
- *
4278
- * @category models
4279
- * @since 0.4.0
4280
- */
4281
- 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 []> = {
4282
- /** Runs synchronously when the state is entered and may enqueue commands. */
4283
- readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
4284
- /** Runs synchronously before the state is exited and may enqueue commands. */
4285
- readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
4286
- /** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
4287
- readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>;
4288
- /** Eventless transition evaluated after the state becomes stable. */
4289
- readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
4290
- /** Transition evaluated after this compound or parallel state completes. */
4291
- readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
4292
- /** Event handlers keyed by the `_tag` of the machine's public or internal events. */
4293
- readonly on?: {
4294
- readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, true, TransitionAcceptance>;
4295
- };
4296
- /** Supplies missing direct initial-child values required by implicit entry and shallow history. */
4297
- readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>;
4298
- } & ActiveOutputHandlerConfig<States, Events, StateId>;
4299
3890
  /**
4300
3891
  * Values constructed for a state's schema-valued direct initial children.
4301
3892
  *
@@ -4404,36 +3995,9 @@ export declare namespace Machine {
4404
3995
  readonly output?: never;
4405
3996
  readonly initialize?: never;
4406
3997
  }
4407
- /**
4408
- * Configuration accepted for a final state.
4409
- *
4410
- * @inlineType OutputHandlerConfig
4411
- *
4412
- * @category models
4413
- * @since 0.4.0
4414
- */
4415
- 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 []> = {
4416
- /** Runs synchronously when the final state is entered and may enqueue commands. */
4417
- readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
4418
- readonly exit?: never;
4419
- readonly always?: never;
4420
- readonly onDone?: never;
4421
- readonly on?: never;
4422
- } & OutputHandlerConfig<States, Events, StateId, FinalOutputContext<States, Events, StateId>>;
4423
- /**
4424
- * Configuration accepted by `handle` for a state tag.
4425
- *
4426
- * @category models
4427
- * @since 0.4.0
4428
- */
4429
- type HandlerConfig<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 []> = NodeByIdentifier<States, StateId> extends {
4430
- readonly type: "final";
4431
- } ? FinalStateConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> : ActiveStateConfig<States, Events, Emits, StateId, E, R, InputEvents, ParentEvents>;
4432
- type HandlerNodeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path, InputEvents, ParentEvents> : Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R, InputEvents, ParentEvents> : never;
4433
3998
  type HandlerChildren<Node> = Node extends {
4434
3999
  readonly states: infer Children extends StateSchemas;
4435
4000
  } ? Children : never;
4436
- type HandlerNodeId<States extends StateSchemas, Path extends string> = Extract<Path, StateNodeIdentifier<States>>;
4437
4001
  type HandlerConfigPart<Config> = {
4438
4002
  readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key];
4439
4003
  };
@@ -4453,25 +4017,6 @@ export declare namespace Machine {
4453
4017
  } : {
4454
4018
  readonly [Key in Path]?: Validation;
4455
4019
  };
4456
- /** Nested handler-tree structure shared by active and final state configs. */
4457
- 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> ? {
4458
- readonly states?: never;
4459
- readonly history?: never;
4460
- } : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
4461
- readonly states?: never;
4462
- readonly history?: never;
4463
- } : {
4464
- /** Child-state handlers nested according to the declared state topology. */
4465
- readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, InputEvents, ParentEvents, Extract<StateId, StateIdentifier<AllStates>>>;
4466
- /** First-use defaults keyed by direct history pseudo-state. */
4467
- readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
4468
- } : {
4469
- readonly states?: never;
4470
- readonly history?: never;
4471
- });
4472
- type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Prefix extends string> = {
4473
- readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, InputEvents, ParentEvents, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
4474
- };
4475
4020
  type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initialize" | "invoke" | "on" | "onDone" | "output" | "states";
4476
4021
  type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
4477
4022
  readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
@@ -4518,18 +4063,11 @@ export declare namespace Machine {
4518
4063
  } ? Path : never : never;
4519
4064
  type HandlerConfigInitialTargetPath<Config> = TransitionResultInitialTargetPath<EventHandlerReturn<Config> | AlwaysReturn<Config> | DoneReturn<Config> | ChoiceReturn<Config> | InvokeOutcomeReturn<InvokeReturn<Config>>>;
4520
4065
  type RequiredInitializersForTargetPath<AllStates extends StateSchemas, Path> = string extends Path ? never : Path extends StateIdentifier<AllStates> ? InitializerClosureForNode<AllStates, NodeByIdentifier<AllStates, Path>, Path> : never;
4521
- type HandlerInitializeValidationAtPath<Config, Path extends string> = HandlerConfigAtPath<Config, Path> extends infer StateConfig ? [StateConfig] extends [never] ? HandlerValidationAtPath<Path, {
4522
- readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
4523
- }> : "initialize" extends keyof StateConfig ? never : HandlerValidationAtPath<Path, {
4524
- readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
4525
- }> : never;
4526
- type HandlerInitialTargetValidationForPaths<AllStates extends StateSchemas, Config, Required> = Types.UnionToIntersection<Required extends string ? HandlerInitializeValidationAtPath<Config, Required> : unknown>;
4527
4066
  type HandlerTreeInitialTargetPath<Config> = string extends keyof Config ? never : Config extends object ? {
4528
4067
  readonly [Key in keyof Config]: HandlerConfigInitialTargetPath<HandlerConfigPart<Config[Key]>> | (Config[Key] extends {
4529
4068
  readonly states: infer Children;
4530
4069
  } ? HandlerTreeInitialTargetPath<Children> : never);
4531
4070
  }[keyof Config] : never;
4532
- type HandlerInitialTargetValidation<AllStates extends StateSchemas, Config> = HandlerTreeInitialTargetPath<Config> extends infer TargetPath ? HandlerInitialTargetValidationForPaths<AllStates, Config, RequiredInitializersForTargetPath<AllStates, TargetPath>> : unknown;
4533
4071
  type HandlerChildrenValidation<Node, Prefix extends string, Config> = "states" extends keyof Config ? Config extends {
4534
4072
  readonly states?: infer ChildrenConfig;
4535
4073
  } ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
@@ -4561,15 +4099,6 @@ export declare namespace Machine {
4561
4099
  readonly invoke: HandlerValidationError<"Invoked child expects parent events not accepted by this machine", StateId, Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>>;
4562
4100
  };
4563
4101
  type HandlerRuntimeValidation<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, Incompatible = keyof Config extends never ? never : IncompatibleRuntime<ConfigServices<HandlerConfigPart<Config>>, EventOf<Events>, EmittedEventOf<Emits>>> = [Incompatible] extends [never] ? unknown : HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>;
4564
- type HandlerNodeValidationAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : HandlerNodeValidation<AllStates, HandlerNodeByPath<AllStates, StateId>, Events, InputEvents, Emits, StateId, NodeConfig, AvailableOutputStates> extends infer Validation ? unknown extends Validation ? never : "" extends keyof AllStates ? StateId extends "" ? {
4565
- readonly ""?: Validation;
4566
- } : {
4567
- readonly ""?: {
4568
- readonly states: HandlerValidationAtPath<StateId, Validation>;
4569
- };
4570
- } : HandlerValidationAtPath<StateId, Validation> : never;
4571
- type HandlerTreeNodeValidations<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeValidationAtPath<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates, StateId> : never : never>;
4572
- type HandlerTreeValidation<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = HandlerUnknownStateKeyValidation<AllStates, "", Config> & HandlerTreeNodeValidations<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates>;
4573
4102
  type RootInitialTargetValidation<States extends StateSchemas, Config> = RequiredInitializersForTargetPath<States, HandlerTreeInitialTargetPath<{
4574
4103
  readonly "": Config;
4575
4104
  }>> extends infer Required ? Types.UnionToIntersection<Required extends string ? HandlerConfigAtPath<{
@@ -4616,17 +4145,626 @@ export declare namespace Machine {
4616
4145
  };
4617
4146
  type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId> : never : never;
4618
4147
  type HandleTreeResult<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<AllStates>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<AllStates>, Output, OutputStates extends StateIdentifier<AllStates>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Config> = Machine<AllStates, Events, Input, Exclude<UnhandledStates, HandlerTreeEvidence<AllStates, Config>["stateId"]>, E | HandlerTreeEvidence<AllStates, Config>["error"], ExcludeCompatibleRuntime<R | HandlerTreeEvidence<AllStates, Config>["services"], EventOf<Events>, EmittedEventOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>, InputEvents, ParentEvents>;
4148
+ type ObjectCompoundPath<S extends StateSchemas> = {
4149
+ readonly [P in StateIdentifier<S>]: NodeByIdentifier<S, P> extends {
4150
+ /** Child handlers nested according to the declared root topology. */
4151
+ readonly states: StateSchemas;
4152
+ } ? P : never;
4153
+ }[StateIdentifier<S>];
4154
+ type LazyProgramValue = Effect.Effect<unknown, unknown, unknown> | Stream.Stream<unknown, unknown, unknown>;
4155
+ /** Registered lazy programs and their optional explicit input adapters. */
4156
+ type Program<Value> = Value | ((...args: never[]) => Value);
4157
+ type EffectSources = Readonly<Record<string, Program<Effect.Effect<unknown, unknown, unknown>>>>;
4158
+ type StreamSources = Readonly<Record<string, Program<Stream.Stream<unknown, unknown, unknown>>>>;
4159
+ type TimerSources = Readonly<Record<string, Program<Duration.Input>>>;
4160
+ type LogicSources = Readonly<Record<string, unknown>>;
4161
+ type ValidateLogicSources<Sources> = {
4162
+ readonly [K in keyof Sources]: InvokeResolvedSource<Sources[K]> extends {
4163
+ /** Enters a compound or parallel subtree through its declared initialization. */
4164
+ readonly initial: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
4165
+ readonly run: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
4166
+ } ? unknown : never;
4167
+ };
4168
+ type ChildSources = Readonly<Record<string, ChildMachine.Any>>;
4169
+ type ValidatePrograms<Sources> = {
4170
+ readonly [K in keyof Sources]: Sources[K] extends LazyProgramValue ? unknown : Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never : unknown;
4171
+ };
4172
+ type ReferenceRoot<S extends StateSchemas> = "~effect/Machine/ExplicitInitial" extends keyof S[""] ? Extract<Omit<S[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig> : Extract<S[""], StateNodeConfig>;
4173
+ type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = TargetReference<ReferenceRoot<S>, P, P extends HistoryIdentifier<S> ? "history" : P extends ChoiceIdentifier<S> ? "choice" : "state">;
4174
+ type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = {
4175
+ readonly [P in Paths]: ReferenceAt<S, P>;
4176
+ }[Paths];
4177
+ type DestinationPath<S extends StateSchemas> = Exclude<StateNodeIdentifier<S>, "">;
4178
+ type RootSchemas<Root extends StateNodeConfig> = {
4179
+ readonly "": Root;
4180
+ };
4181
+ /** A topology declaration; its state values are constructed by a resolver. */
4182
+ type BranchDeclaration<Root extends StateNodeConfig, S extends StateSchemas = RootSchemas<Root>> = {
4183
+ /** Optional presentation label for this named branch. */
4184
+ readonly title?: string;
4185
+ } & ({
4186
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4187
+ readonly target: ReferenceUnion<S, DestinationPath<S>>;
4188
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4189
+ readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>;
4190
+ /** Enters a compound or parallel subtree through its declared initialization. */
4191
+ readonly initial?: never;
4192
+ /** Restores the declared history reference, using its fallback on first entry. */
4193
+ readonly history?: never;
4194
+ /** Accepts the event without selecting a new destination. */
4195
+ readonly none?: never;
4196
+ } | {
4197
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4198
+ readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>;
4199
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4200
+ readonly target?: never;
4201
+ /** Enters a compound or parallel subtree through its declared initialization. */
4202
+ readonly initial?: never;
4203
+ /** Restores the declared history reference, using its fallback on first entry. */
4204
+ readonly history?: never;
4205
+ /** Accepts the event without selecting a new destination. */
4206
+ readonly none?: never;
4207
+ } | {
4208
+ /** Enters a compound or parallel subtree through its declared initialization. */
4209
+ readonly initial: ReferenceUnion<S, Exclude<ObjectCompoundPath<S>, "">>;
4210
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4211
+ readonly target?: never;
4212
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4213
+ readonly update?: never;
4214
+ /** Restores the declared history reference, using its fallback on first entry. */
4215
+ readonly history?: never;
4216
+ /** Accepts the event without selecting a new destination. */
4217
+ readonly none?: never;
4218
+ } | {
4219
+ /** Restores the declared history reference, using its fallback on first entry. */
4220
+ readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
4221
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4222
+ readonly target?: never;
4223
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4224
+ readonly update?: never;
4225
+ /** Enters a compound or parallel subtree through its declared initialization. */
4226
+ readonly initial?: never;
4227
+ /** Accepts the event without selecting a new destination. */
4228
+ readonly none?: never;
4229
+ } | {
4230
+ /** Accepts the event without selecting a new destination. */
4231
+ readonly none: true;
4232
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4233
+ readonly target?: never;
4234
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4235
+ readonly update?: never;
4236
+ /** Enters a compound or parallel subtree through its declared initialization. */
4237
+ readonly initial?: never;
4238
+ /** Restores the declared history reference, using its fallback on first entry. */
4239
+ readonly history?: never;
4240
+ });
4241
+ type BranchDefinitions<Root extends StateNodeConfig> = Readonly<Record<string, Readonly<Record<string, BranchDeclaration<Root>>>>>;
4242
+ /** Source programs and named topology declarations captured by a machine definition. */
4243
+ interface Registrations {
4244
+ /** Lazy Effects or functions with one required input, invoked by registered name. */
4245
+ readonly effects?: EffectSources;
4246
+ /** Lazy Streams or functions with one required input, invoked by registered name. */
4247
+ readonly streams?: StreamSources;
4248
+ /** Cancellable delays, supplied as durations or functions of one required input. */
4249
+ readonly timers?: TimerSources;
4250
+ /** Logic values or functions of one required input; their Effect channels remain inferred. */
4251
+ readonly logic?: LogicSources;
4252
+ /** Child machine descriptors registered for state-owned invocation. */
4253
+ readonly children?: ChildSources;
4254
+ /** Named groups of inspectable destinations used by transition resolvers. */
4255
+ readonly branches?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
4256
+ }
4257
+ type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {};
4258
+ type AtBuilder<T, P extends string> = P extends "" ? T : P extends `${infer H}.${infer Rest}` ? H extends keyof T ? AtBuilder<T[H], Rest> : never : P extends keyof T ? T[P] : never;
4259
+ type BranchBuilderAt<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = AtBuilder<RootBuilder<BranchTargetBuilder<S, Src>>, P>;
4260
+ type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never;
4261
+ type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D> = D extends {
4262
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4263
+ readonly target: infer Ref;
4264
+ } ? RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ? D extends {
4265
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4266
+ readonly update: infer Update;
4267
+ } ? RefPath<Update> extends infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>> ? TargetSelection<UpdatingTargetBuilder<BranchBuilderAt<S, Src, P>, S, Owner>, P, "state", "branch"> : never : TargetSelection<BranchBuilderAt<S, Src, P>, P, P extends ChoiceIdentifier<S> ? "choice" : "state", "branch"> : never : D extends {
4268
+ /** Enters a compound or parallel subtree through its declared initialization. */
4269
+ readonly initial: infer Ref;
4270
+ } ? RefPath<Ref> extends infer P extends string ? BranchBuilderAt<S, Src, P> extends {
4271
+ /** Enters a compound or parallel subtree through its declared initialization. */
4272
+ readonly initial: infer B;
4273
+ } ? TargetSelection<B, P, "initial", "branch"> : never : never : D extends {
4274
+ /** Restores the declared history reference, using its fallback on first entry. */
4275
+ readonly history: infer Ref;
4276
+ } ? RefPath<Ref> extends infer P extends string ? TargetSelection<AtBuilder<RootBuilder<HistoryTargetBuilder<S>>, P>, P, "history", "full"> : never : D extends {
4277
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4278
+ readonly update: infer Ref;
4279
+ } ? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>> ? TargetSelection<StateUpdateBuilder<S, P>, P, "update", "branch"> : never : D extends {
4280
+ /** Accepts the event without selecting a new destination. */
4281
+ readonly none: true;
4282
+ } ? TargetSelection<() => NoTarget, never, "none", "local"> : never;
4283
+ type BuilderArgs<B, K extends PropertyKey> = K extends keyof B ? B[K] extends (...args: infer A) => unknown ? A : never : never;
4284
+ type ObjectConstruction<C, B> = {
4285
+ readonly [M in Extract<keyof B, "from" | "decoded">]: BuilderArgs<B, M> extends readonly [unknown?] ? {
4286
+ readonly [K in M]: (context: C) => BuilderArgs<B, M>[0];
4287
+ } & {
4288
+ readonly [K in Exclude<"from" | "decoded", M>]?: never;
4289
+ } : never;
4290
+ }[Extract<keyof B, "from" | "decoded">];
4291
+ type ObjectDefault<B> = B extends {
4292
+ /** Constructs schema make input from the typed source context. */
4293
+ readonly from: () => unknown;
4294
+ } | (() => unknown) ? {
4295
+ /** Constructs schema make input from the typed source context. */
4296
+ readonly from?: never; /** Supplies an already decoded schema value from the typed source context. */
4297
+ readonly decoded?: never;
4298
+ } : never;
4299
+ type ObjectPolicy<C, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
4300
+ /** Set to true to exit and reenter the handler source. */
4301
+ readonly reenter?: Reenter extends true ? boolean : never;
4302
+ /** Declines the transition before construction when the predicate returns false. */
4303
+ readonly guard?: "declinable" extends Acceptance ? ((context: C) => boolean) | undefined : never;
4304
+ };
4305
+ type InlineNodeConstruction<C, Node> = [NodeSchema<Node>] extends [never] ? {
4306
+ readonly from?: (context: C) => undefined;
4307
+ readonly decoded?: never;
4308
+ } : {
4309
+ readonly from: (context: C) => NodeMakeInput<Node>;
4310
+ readonly decoded?: never;
4311
+ } | {
4312
+ readonly decoded: (context: C) => NodeValue<Node>;
4313
+ readonly from?: never;
4314
+ } | ({} extends NodeMakeInput<Node> ? {
4315
+ readonly from?: never;
4316
+ readonly decoded?: never;
4317
+ } : never);
4318
+ type InlineDestinationConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends DestinationPath<S>, C> = P extends ChoiceIdentifier<S> ? {
4319
+ readonly from?: never;
4320
+ readonly decoded?: never;
4321
+ } : P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
4322
+ readonly states: StateSchemas;
4323
+ } ? [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? ObjectConstruction<C, BranchBuilderAt<S, Src, P>> | ObjectDefault<BranchBuilderAt<S, Src, P>> : never : InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
4324
+ type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
4325
+ readonly [P in DestinationPath<S>]: {
4326
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4327
+ readonly target: ReferenceAt<S, P>;
4328
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4329
+ readonly update?: never;
4330
+ /** Enters a compound or parallel subtree through its declared initialization. */
4331
+ readonly initial?: never;
4332
+ /** Restores the declared history reference, using its fallback on first entry. */
4333
+ readonly history?: never;
4334
+ /** Accepts the event without selecting a new destination. */
4335
+ readonly none?: never;
4336
+ /** Named groups of inspectable destinations used by transition resolvers. */
4337
+ readonly branches?: never;
4338
+ /** Selects one declared branch and may enqueue synchronous commands. */
4339
+ readonly resolve?: never;
4340
+ /** Set to true when the resolver can explicitly return decline(). */
4341
+ readonly declinable?: never;
4342
+ } & InlineDestinationConstruction<S, Src, P, C>;
4343
+ }[DestinationPath<S>];
4344
+ type InlinePairConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string, Owner extends ValuedStateIdentifier<S>, C> = P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
4345
+ readonly states: StateSchemas;
4346
+ } ? {
4347
+ readonly [M in Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">]: BuilderArgs<BranchBuilderAt<S, Src, P>, M> extends readonly [unknown?] ? {
4348
+ readonly [K in M]: (context: C) => {
4349
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4350
+ readonly target: BuilderArgs<BranchBuilderAt<S, Src, P>, M>[0];
4351
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4352
+ readonly update: BuilderArgs<StateUpdateBuilder<S, Owner>, M>[0];
4353
+ };
4354
+ } & {
4355
+ readonly [K in Exclude<"from" | "decoded", M>]?: never;
4356
+ } : never;
4357
+ }[Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">] : {
4358
+ readonly from: (context: C) => {
4359
+ readonly target: [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? undefined : NodeMakeInput<NodeByIdentifier<S, P>>;
4360
+ readonly update: SchemaByIdentifier<S, Owner>["~type.make.in"];
4361
+ };
4362
+ readonly decoded?: never;
4363
+ } | ([NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? never : {
4364
+ readonly decoded: (context: C) => {
4365
+ readonly target: NodeValue<NodeByIdentifier<S, P>>;
4366
+ readonly update: StateByIdentifier<S, Owner>;
4367
+ };
4368
+ readonly from?: never;
4369
+ }) : never;
4370
+ type InlineCombined<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = Src extends ChoiceIdentifier<S> ? never : [
4371
+ Extract<ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>
4372
+ ] extends [never] ? never : {
4373
+ readonly [P in DestinationPath<S>]: {
4374
+ readonly [Owner in Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>]: {
4375
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4376
+ readonly target: ReferenceAt<S, P>;
4377
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4378
+ readonly update: ReferenceAt<S, Owner>;
4379
+ /** Enters a compound or parallel subtree through its declared initialization. */
4380
+ readonly initial?: never;
4381
+ /** Restores the declared history reference, using its fallback on first entry. */
4382
+ readonly history?: never;
4383
+ /** Accepts the event without selecting a new destination. */
4384
+ readonly none?: never;
4385
+ /** Named groups of inspectable destinations used by transition resolvers. */
4386
+ readonly branches?: never;
4387
+ /** Selects one declared branch and may enqueue synchronous commands. */
4388
+ readonly resolve?: never;
4389
+ /** Set to true when the resolver can explicitly return decline(). */
4390
+ readonly declinable?: never;
4391
+ } & InlinePairConstruction<S, Src, P, Owner, C>;
4392
+ }[Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>];
4393
+ }[DestinationPath<S>];
4394
+ type InlineUpdate<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = Src extends ChoiceIdentifier<S> ? never : {
4395
+ readonly [P in Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>]: {
4396
+ /** Set to true to exit and reenter the handler source. */
4397
+ readonly reenter?: P extends Src ? never : boolean;
4398
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4399
+ readonly update: ReferenceAt<S, P>;
4400
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4401
+ readonly target?: never;
4402
+ /** Enters a compound or parallel subtree through its declared initialization. */
4403
+ readonly initial?: never;
4404
+ /** Restores the declared history reference, using its fallback on first entry. */
4405
+ readonly history?: never;
4406
+ /** Accepts the event without selecting a new destination. */
4407
+ readonly none?: never;
4408
+ /** Named groups of inspectable destinations used by transition resolvers. */
4409
+ readonly branches?: never;
4410
+ /** Selects one declared branch and may enqueue synchronous commands. */
4411
+ readonly resolve?: never;
4412
+ /** Set to true when the resolver can explicitly return decline(). */
4413
+ readonly declinable?: never;
4414
+ } & ObjectConstruction<C, StateUpdateBuilder<S, P>>;
4415
+ }[Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>];
4416
+ type InlineInitial<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = [
4417
+ Exclude<ObjectCompoundPath<S>, "">
4418
+ ] extends [never] ? never : {
4419
+ readonly [P in Exclude<ObjectCompoundPath<S>, "">]: InitialTargetFactory<NodeByIdentifier<S, P>, P> extends infer B ? {
4420
+ /** Enters a compound or parallel subtree through its declared initialization. */
4421
+ readonly initial: ReferenceAt<S, P>;
4422
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4423
+ readonly target?: never;
4424
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4425
+ readonly update?: never;
4426
+ /** Restores the declared history reference, using its fallback on first entry. */
4427
+ readonly history?: never;
4428
+ /** Accepts the event without selecting a new destination. */
4429
+ readonly none?: never;
4430
+ /** Named groups of inspectable destinations used by transition resolvers. */
4431
+ readonly branches?: never;
4432
+ /** Selects one declared branch and may enqueue synchronous commands. */
4433
+ readonly resolve?: never;
4434
+ /** Set to true when the resolver can explicitly return decline(). */
4435
+ readonly declinable?: never;
4436
+ } & (ObjectConstruction<C, B> | ObjectDefault<B>) : never;
4437
+ }[Exclude<ObjectCompoundPath<S>, "">];
4438
+ type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
4439
+ readonly [K in Extract<keyof Group, string>]: {
4440
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4441
+ readonly target: SelectionOf<S, Src, Group[K]>;
4442
+ };
4443
+ };
4444
+ type ObjectBranchResolver<Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, C, B extends Readonly<Record<string, TransitionBranchInput>>, Declinable extends boolean> = (context: C & {
4445
+ readonly select: BranchSelectors<B>;
4446
+ } & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => BranchSelectionResult<B> | (Declinable extends true ? Declined : never);
4447
+ type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
4448
+ readonly [K in keyof Group]: Src extends ChoiceIdentifier<S> ? Group[K] extends {
4449
+ /** Accepts the event without selecting a new destination. */
4450
+ readonly none: true;
4451
+ } | {
4452
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4453
+ readonly update: unknown;
4454
+ } ? K : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never;
4455
+ }[keyof Group];
4456
+ type ObjectBranches<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Acceptance extends TransitionAcceptance> = {
4457
+ readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K]>] extends [never] ? unknown : never) & {
4458
+ /** Named groups of inspectable destinations used by transition resolvers. */
4459
+ readonly branches: K;
4460
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4461
+ readonly target?: never;
4462
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4463
+ readonly update?: never;
4464
+ /** Enters a compound or parallel subtree through its declared initialization. */
4465
+ readonly initial?: never;
4466
+ /** Restores the declared history reference, using its fallback on first entry. */
4467
+ readonly history?: never;
4468
+ /** Accepts the event without selecting a new destination. */
4469
+ readonly none?: never;
4470
+ /** Constructs schema make input from the typed source context. */
4471
+ readonly from?: never;
4472
+ /** Supplies an already decoded schema value from the typed source context. */
4473
+ readonly decoded?: never;
4474
+ } & {
4475
+ /** Set to true when the resolver can explicitly return decline(). */
4476
+ readonly declinable?: "declinable" extends Acceptance ? boolean : false;
4477
+ /** Selects one declared branch and may enqueue synchronous commands. */
4478
+ readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K]>, true>;
4479
+ };
4480
+ }[Extract<keyof Registered<R, "branches">, string>];
4619
4481
  /**
4620
- * Adds state handlers from a root state object.
4482
+ * A transition with an inspectable destination and source-specific construction.
4483
+ *
4484
+ * @category models
4485
+ * @since 0.34.0
4486
+ */
4487
+ type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> & (InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineInitial<S, Src, C> | {
4488
+ /** Restores the declared history reference, using its fallback on first entry. */
4489
+ readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
4490
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4491
+ readonly target?: never;
4492
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4493
+ readonly update?: never;
4494
+ /** Enters a compound or parallel subtree through its declared initialization. */
4495
+ readonly initial?: never;
4496
+ /** Accepts the event without selecting a new destination. */
4497
+ readonly none?: never;
4498
+ /** Named groups of inspectable destinations used by transition resolvers. */
4499
+ readonly branches?: never;
4500
+ /** Selects one declared branch and may enqueue synchronous commands. */
4501
+ readonly resolve?: never;
4502
+ /** Constructs schema make input from the typed source context. */
4503
+ readonly from?: never;
4504
+ /** Supplies an already decoded schema value from the typed source context. */
4505
+ readonly decoded?: never;
4506
+ /** Set to true when the resolver can explicitly return decline(). */
4507
+ readonly declinable?: never;
4508
+ } | (Src extends ChoiceIdentifier<S> ? never : {
4509
+ /** Accepts the event without selecting a new destination. */
4510
+ readonly none: true;
4511
+ /** Selects the declared descendant destination. Supply required values with from or decoded. */
4512
+ readonly target?: never;
4513
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4514
+ readonly update?: never;
4515
+ /** Enters a compound or parallel subtree through its declared initialization. */
4516
+ readonly initial?: never;
4517
+ /** Restores the declared history reference, using its fallback on first entry. */
4518
+ readonly history?: never;
4519
+ /** Named groups of inspectable destinations used by transition resolvers. */
4520
+ readonly branches?: never;
4521
+ /** Constructs schema make input from the typed source context. */
4522
+ readonly from?: never;
4523
+ /** Supplies an already decoded schema value from the typed source context. */
4524
+ readonly decoded?: never;
4525
+ /** Set to true when the resolver can explicitly return decline(). */
4526
+ readonly declinable?: "declinable" extends Acceptance ? boolean : false;
4527
+ /** Selects one declared branch and may enqueue synchronous commands. */
4528
+ readonly resolve?: (context: C & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => undefined | Declined;
4529
+ }) | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>);
4530
+ type SourceValue<R, K extends PropertyKey> = {
4531
+ readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Registered<R, Kind>[K] : never;
4532
+ }["effects" | "streams" | "timers" | "logic" | "children"];
4533
+ type SourceKind<R, K extends PropertyKey> = {
4534
+ readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Kind : never;
4535
+ }["effects" | "streams" | "timers" | "logic" | "children"];
4536
+ type SourceKeys<R> = {
4537
+ readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: keyof Registered<R, Kind>;
4538
+ }["effects" | "streams" | "timers" | "logic" | "children"];
4539
+ type SourceInput<F, C> = F extends LazyProgramValue ? {
4540
+ readonly input?: never;
4541
+ } : F extends (...args: never[]) => unknown ? Parameters<F>["length"] extends 1 ? {
4542
+ /** Maps the owning state context to the registered source input. */
4543
+ readonly input: (context: C) => Parameters<F>[0];
4544
+ } : never : {
4545
+ /** Maps the owning state context to the registered source input. */
4546
+ readonly input?: never;
4547
+ };
4548
+ type ResolvedInvoke<R, K extends PropertyKey> = SourceKind<R, K> extends "effects" ? {
4549
+ readonly effect: () => InvokeResolvedSource<SourceValue<R, K>>;
4550
+ } : SourceKind<R, K> extends "streams" ? {
4551
+ readonly stream: () => InvokeResolvedSource<SourceValue<R, K>>;
4552
+ } : SourceKind<R, K> extends "timers" ? {
4553
+ readonly after: Duration.Input;
4554
+ } : SourceKind<R, K> extends "logic" ? {
4555
+ /** Logic values or functions of one required input; their Effect channels remain inferred. */
4556
+ readonly logic: InvokeResolvedSource<SourceValue<R, K>>;
4557
+ } : SourceKind<R, K> extends "children" ? {
4558
+ readonly child: SourceValue<R, K>;
4559
+ } & (SourceValue<R, K> extends ChildMachine<string, infer M> ? {
4560
+ readonly [InvokeTypeId]: {
4561
+ readonly error: Types.Covariant<Error<M> | ActionError<Services<M>>>;
4562
+ readonly initialError: Types.Covariant<InitialError<M>>;
4563
+ readonly requirements: Types.Covariant<Services<M>>;
4564
+ };
4565
+ } : never) : never;
4566
+ type RegisteredInvocationInput<R, K extends PropertyKey, C> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? InputSchema<M> extends typeof Schema.Void ? {
4567
+ /** Maps the owning state context to the registered source input. */
4568
+ readonly input?: never;
4569
+ } : {
4570
+ /** Maps the owning state context to the registered source input. */
4571
+ readonly input: (context: C) => Input<M>;
4572
+ } : never : SourceInput<SourceValue<R, K>, C>;
4573
+ type ObjectOutcome<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R, V, Channel extends "onDone" | "onFailure" | "onElement" | "onSnapshot"> = [V] extends [never] ? {} : Channel extends "onDone" ? {
4574
+ /** Handles successful invocation or state completion with its exact output type. */
4575
+ readonly onDone: Transition<S, Src, InvokeDoneContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
4576
+ } : Channel extends "onFailure" ? {
4577
+ /** Handles the typed failure of the invoked source; required exactly when that channel is reachable. */
4578
+ readonly onFailure: Transition<S, Src, InvokeFailureContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
4579
+ } : Channel extends "onElement" ? {
4580
+ /** Handles each Stream element; required when the element type is reachable. */
4581
+ readonly onElement: Transition<S, Src, InvokeElementContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
4582
+ } : {
4583
+ /** Optionally handles active snapshots of invoked logic or a child machine. */
4584
+ readonly onSnapshot: Transition<S, Src, InvokeSnapshotContext<S, Ev, Em, Src, V, never, never, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
4585
+ };
4586
+ type RegisteredInvokeError<R, K extends PropertyKey> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? Error<M> | ActionError<Services<M>> : never : InvokeRuntimeError<ResolvedInvoke<R, K>>;
4587
+ /**
4588
+ * A registered source invocation with its required input and reachable outcomes.
4589
+ *
4590
+ * @category models
4591
+ * @since 0.34.0
4592
+ */
4593
+ type Invocation<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = {
4594
+ readonly [K in Extract<SourceKeys<R>, string>]: Types.Simplify<{
4595
+ /** Name of the source registered in make. */
4596
+ readonly src: K;
4597
+ } & (SourceKind<R, K> extends "children" ? {
4598
+ /** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
4599
+ readonly id?: never; /** Typed runtime address required for invoked logic; child descriptors carry their own address. */
4600
+ readonly address?: never;
4601
+ } : SourceKind<R, K> extends "logic" ? {
4602
+ /** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
4603
+ readonly id: InvokeLifecycleId;
4604
+ /** Typed runtime address required for invoked logic; child descriptors carry their own address. */
4605
+ readonly address: ChildAddress<LogicEventOf<InvokeResolvedSource<SourceValue<R, K>>>>;
4606
+ } : {
4607
+ /** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
4608
+ readonly id?: InvokeLifecycleId; /** Typed runtime address required for invoked logic; child descriptors carry their own address. */
4609
+ readonly address?: never;
4610
+ }) & (SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? M extends EnsureExecutable<States<M>, UnhandledStates<M>, OutputStates<M>> ? unknown : never : never : unknown) & RegisteredInvocationInput<R, K, InvokeContext<S, Ev, Em, Src, In, Pa>> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, InvokeOutput<ResolvedInvoke<R, K>>, "onDone"> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, RegisteredInvokeError<R, K>, "onFailure"> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, SourceKind<R, K> extends "streams" ? Stream.Success<Extract<InvokeResolvedSource<SourceValue<R, K>>, Stream.Stream<any, any, any>>> : never, "onElement"> & (SourceKind<R, K> extends "logic" | "children" ? Partial<ObjectOutcome<S, Ev, Em, Src, In, Pa, R, LogicStateOf<InvokeLogic<ResolvedInvoke<R, K>>>, "onSnapshot">> : {})>;
4611
+ }[Extract<SourceKeys<R>, string>];
4612
+ type ObjectLifecycle<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>> = Src extends StateIdentifier<S> ? {
4613
+ /** Runs synchronously on entry and may enqueue commands. */
4614
+ readonly entry?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
4615
+ } & (Node extends {
4616
+ readonly type: "final";
4617
+ } ? {
4618
+ /** Runs synchronously on exit and may enqueue commands. */
4619
+ readonly exit?: never; /** Constructs required values for the declared initial child or parallel regions. */
4620
+ readonly initialize?: never;
4621
+ } & OutputHandlerConfig<S, Ev, Src, FinalOutputContext<S, Ev, Src>> : {
4622
+ /** Runs synchronously on exit and may enqueue commands. */
4623
+ readonly exit?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
4624
+ /** Constructs required values for the declared initial child or parallel regions. */
4625
+ readonly initialize?: StateInitializeHandler<S, Ev, Em, Src, In, Pa>;
4626
+ } & ActiveOutputHandlerConfig<S, Ev, Src>) : {
4627
+ /** Runs synchronously on entry and may enqueue commands. */
4628
+ readonly entry?: never; /** Runs synchronously on exit and may enqueue commands. */
4629
+ readonly exit?: never; /** Constructs required values for the declared initial child or parallel regions. */
4630
+ readonly initialize?: never; /** Constructs the decoded output declared by the state schema. */
4631
+ readonly output?: never;
4632
+ };
4633
+ /**
4634
+ * Handlers for a node of the declared root tree.
4635
+ *
4636
+ * @category models
4637
+ * @since 0.34.0
4638
+ */
4639
+ type StateHandler<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa> & (Src extends ChoiceIdentifier<S> ? {
4640
+ /** Required total transition for a transient choice state. */
4641
+ readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>;
4642
+ /** Event handlers keyed by the public or internal event tag. */
4643
+ readonly on?: never;
4644
+ /** Eventless transition evaluated during stabilization. */
4645
+ readonly always?: never;
4646
+ /** Handles successful invocation or state completion with its exact output type. */
4647
+ readonly onDone?: never;
4648
+ /** One registered invocation or an array with distinct lifecycle identities. */
4649
+ readonly invoke?: never;
4650
+ /** Child handlers nested according to the declared root topology. */
4651
+ readonly states?: never;
4652
+ /** Restores the declared history reference, using its fallback on first entry. */
4653
+ readonly history?: never;
4654
+ } : Src extends StateIdentifier<S> ? Node extends {
4655
+ readonly type: "final";
4656
+ } ? {
4657
+ /** Event handlers keyed by the public or internal event tag. */
4658
+ readonly on?: never;
4659
+ /** Eventless transition evaluated during stabilization. */
4660
+ readonly always?: never;
4661
+ /** Handles successful invocation or state completion with its exact output type. */
4662
+ readonly onDone?: never;
4663
+ /** Required total transition for a transient choice state. */
4664
+ readonly choice?: never;
4665
+ /** One registered invocation or an array with distinct lifecycle identities. */
4666
+ readonly invoke?: never;
4667
+ /** Child handlers nested according to the declared root topology. */
4668
+ readonly states?: never;
4669
+ /** Restores the declared history reference, using its fallback on first entry. */
4670
+ readonly history?: never;
4671
+ } : {
4672
+ /** Event handlers keyed by the public or internal event tag. */
4673
+ readonly on?: {
4674
+ readonly [Tag in TagOf<Ev[number]>]?: Transition<S, Src, HandlerContext<S, Ev, Em, Src, Tag, never, never, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
4675
+ };
4676
+ /** Eventless transition evaluated during stabilization. */
4677
+ readonly always?: Transition<S, Src, AlwaysContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, TransitionAcceptance>;
4678
+ /** Handles successful invocation or state completion with its exact output type. */
4679
+ readonly onDone?: Transition<S, Src, DoneContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, TransitionAcceptance>;
4680
+ /** Required total transition for a transient choice state. */
4681
+ readonly choice?: never;
4682
+ /** One registered invocation or an array with distinct lifecycle identities. */
4683
+ readonly invoke?: Invocation<S, Ev, Em, Src, In, Pa, R> | (ReadonlyArray<Invocation<S, Ev, Em, Src, In, Pa, R>> & {
4684
+ /** Name of the source registered in make. */
4685
+ readonly src?: never;
4686
+ });
4687
+ } & (Node extends {
4688
+ /** Child handlers nested according to the declared root topology. */
4689
+ readonly states: infer Children extends StateSchemas;
4690
+ } ? {
4691
+ /** Child handlers nested according to the declared root topology. */
4692
+ readonly states?: {
4693
+ readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]?: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>;
4694
+ };
4695
+ /** Restores the declared history reference, using its fallback on first entry. */
4696
+ readonly history?: HistoryDefaultConfig<S, Ev, Em, Src, Children>;
4697
+ } : {
4698
+ /** Child handlers nested according to the declared root topology. */
4699
+ readonly states?: never; /** Restores the declared history reference, using its fallback on first entry. */
4700
+ readonly history?: never;
4701
+ }) : never);
4702
+ type ValidateObjectTransition<T> = {
4703
+ readonly [K in Exclude<keyof T, "target" | "update" | "initial" | "history" | "none" | "branches" | "from" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
4704
+ } & (T extends {
4705
+ /** Set to true when the resolver can explicitly return decline(). */
4706
+ readonly declinable: infer D;
4707
+ } ? boolean extends D ? {
4708
+ /** Set to true when the resolver can explicitly return decline(). */
4709
+ readonly declinable: never;
4710
+ } : unknown : unknown) & (T extends {
4711
+ /** Set to true when the resolver can explicitly return decline(). */
4712
+ readonly declinable: true;
4713
+ } ? unknown : T extends {
4714
+ /** Selects one declared branch and may enqueue synchronous commands. */
4715
+ readonly resolve: (...args: any[]) => infer Result;
4716
+ } ? [Extract<Result, Declined>] extends [never] ? unknown : {
4717
+ /** Selects one declared branch and may enqueue synchronous commands. */
4718
+ readonly resolve: never;
4719
+ } : unknown);
4720
+ type AllowedInvokeChannels<R, K extends PropertyKey> = ([InvokeOutput<ResolvedInvoke<R, K>>] extends [never] ? never : "onDone") | ([RegisteredInvokeError<R, K>] extends [never] ? never : "onFailure") | (SourceKind<R, K> extends "streams" ? [Stream.Success<Extract<InvokeResolvedSource<SourceValue<R, K>>, Stream.Stream<any, any, any>>>] extends [never] ? never : "onElement" : never) | (SourceKind<R, K> extends "logic" | "children" ? "onSnapshot" : never);
4721
+ type ValidateObjectInvoke<I, R> = I extends ReadonlyArray<unknown> ? {
4722
+ readonly [K in keyof I]: ValidateObjectInvoke<I[K], R>;
4723
+ } : I extends {
4724
+ /** Name of the source registered in make. */
4725
+ readonly src: infer Src extends PropertyKey;
4726
+ } ? {
4727
+ readonly [K in keyof I]: K extends AllowedInvokeChannels<R, Src> ? ValidateObjectTransition<I[K]> : K extends "src" | "id" | "address" | "input" ? unknown : never;
4728
+ } : never;
4729
+ type ObjectDeclarations<C> = Extract<keyof C, "on" | "always" | "onDone" | "choice" | "invoke"> | (C extends {
4730
+ readonly states: infer Children;
4731
+ } ? {
4732
+ readonly [K in keyof Children]: ObjectDeclarations<Children[K]>;
4733
+ }[keyof Children] : never);
4734
+ type ValidateObjectConfig<C, R> = [ObjectDeclarations<C>] extends [never] ? unknown : {
4735
+ readonly [K in keyof C]: K extends "states" ? {
4736
+ readonly [P in keyof C[K]]: ValidateObjectConfig<C[K][P], R>;
4737
+ } : K extends "on" ? {
4738
+ readonly [P in keyof C[K]]: ValidateObjectTransition<C[K][P]>;
4739
+ } : K extends "always" | "onDone" | "choice" ? ValidateObjectTransition<C[K]> : K extends "invoke" ? ValidateObjectInvoke<C[K], R> : unknown;
4740
+ };
4741
+ type NormalizeObjectInvoke<I, R> = I extends ReadonlyArray<unknown> ? {
4742
+ readonly [K in keyof I]: NormalizeObjectInvoke<I[K], R>;
4743
+ } : I extends {
4744
+ /** Name of the source registered in make. */
4745
+ readonly src: infer K extends PropertyKey;
4746
+ } ? Omit<I, "src"> & ResolvedInvoke<R, K> : I;
4747
+ type NormalizeObjectConfig<C, R> = [SourceKeys<R>] extends [never] ? C : {
4748
+ readonly [K in keyof C]: K extends "states" ? {
4749
+ readonly [P in keyof C[K]]: NormalizeObjectConfig<C[K][P], R>;
4750
+ } : K extends "invoke" ? NormalizeObjectInvoke<C[K], R> : C[K];
4751
+ };
4752
+ type HandlerShape<C, H> = {
4753
+ readonly [K in keyof C]: K extends keyof H ? K extends "states" ? {
4754
+ readonly [P in keyof C[K]]: P extends keyof NonNullable<H[K]> ? HandlerShape<C[K][P], NonNullable<NonNullable<H[K]>[P]>> : never;
4755
+ } : H[K] : never;
4756
+ } & Omit<H, keyof C>;
4757
+ /**
4758
+ * Adds object handlers while checking topology, protocols, invocation outcomes, and readiness.
4621
4759
  *
4622
4760
  * @category combinators
4623
- * @since 0.4.0
4761
+ * @since 0.34.0
4624
4762
  */
4625
- interface Handler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> {
4626
- <const Config>(config: Config & (Config extends (...args: never[]) => unknown ? never : unknown) & HandlerNode<States, States[""], Events, Emits, E, R, InputEvents, ParentEvents, Extract<"", StateNodeIdentifier<States>>> & RootHandlerValidation<States, Events, InputEvents, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, {
4627
- readonly "": NoInfer<Config>;
4628
- }>["outputState"], StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, ParentEvents, {
4629
- readonly "": Config;
4763
+ interface Handler<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, I extends Schema.Top, IE, IR, Final extends StateIdentifier<S>, Out, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> {
4764
+ <const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & ([Ev[number] | keyof Registered<R, "branches"> | SourceKeys<R>] extends [never] ? StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R> : HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R>>) & ValidateObjectConfig<NoInfer<C>, R> & RootHandlerValidation<S, Ev, In, Em, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
4765
+ readonly "": NormalizeObjectConfig<NoInfer<C>, R>;
4766
+ }>["outputState"], StateIdentifier<S>>>): HandleTreeResult<S, Ev, Em, I, StateIdentifier<S>, never, never, IE, IR, Final, Out, never, In, Pa, {
4767
+ readonly "": NormalizeObjectConfig<C, R>;
4630
4768
  }>;
4631
4769
  }
4632
4770
  /**
@@ -4650,12 +4788,19 @@ export declare namespace Machine {
4650
4788
  * @since 0.4.0
4651
4789
  */
4652
4790
  interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
4791
+ /** Runs synchronously on entry and may enqueue commands. */
4653
4792
  readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
4793
+ /** Runs synchronously on exit and may enqueue commands. */
4654
4794
  readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
4795
+ /** One registered invocation or an array with distinct lifecycle identities. */
4655
4796
  readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>;
4797
+ /** Eventless transition evaluated during stabilization. */
4656
4798
  readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
4799
+ /** Handles successful invocation or state completion with its exact output type. */
4657
4800
  readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
4801
+ /** Constructs the decoded output declared by the state schema. */
4658
4802
  readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
4803
+ /** Event handlers keyed by the public or internal event tag. */
4659
4804
  readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
4660
4805
  }
4661
4806
  /**
@@ -4691,6 +4836,7 @@ export declare namespace Snapshot {
4691
4836
  } ? State | (State extends {
4692
4837
  readonly state: infer Child;
4693
4838
  } ? Node<Child> : State extends {
4839
+ /** Child handlers nested according to the declared root topology. */
4694
4840
  readonly states: infer Regions;
4695
4841
  } ? Node<Regions[keyof Regions]> : never) : never;
4696
4842
  /** Every valid absolute path in a logical snapshot type. */
@@ -4773,7 +4919,71 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
4773
4919
  * @since 0.15.0
4774
4920
  */
4775
4921
  export declare const state: StateConstructor;
4776
- type MakeConfig<Root extends Machine.StateNodeConfig, 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> = {
4922
+ /**
4923
+ * An opaque reference to one node in a declared state tree.
4924
+ *
4925
+ * @category models
4926
+ * @since 0.34.0
4927
+ */
4928
+ export interface TargetReference<Root extends Machine.StateNodeConfig, Path extends string, Kind extends "state" | "choice" | "history"> {
4929
+ readonly [internal.TargetReferenceTypeId]: {
4930
+ readonly root: {
4931
+ readonly node: Root;
4932
+ };
4933
+ readonly path: Path;
4934
+ readonly kind: Kind;
4935
+ };
4936
+ }
4937
+ type TargetReferenceTree<Root extends Machine.StateNodeConfig, Node, Path extends string> = TargetReference<Root, Path, Node extends {
4938
+ readonly type: "history";
4939
+ } ? "history" : Node extends {
4940
+ readonly type: "choice";
4941
+ } ? "choice" : "state"> & (Node extends {
4942
+ /** Child handlers nested according to the declared root topology. */
4943
+ readonly states: infer Children;
4944
+ } ? {
4945
+ readonly [Key in Extract<keyof Children, string>]: TargetReferenceTree<Root, Children[Key], Machine.JoinPath<Path, Key>>;
4946
+ } : {});
4947
+ /**
4948
+ * References for every path in a declared root tree.
4949
+ *
4950
+ * @category models
4951
+ * @since 0.34.0
4952
+ */
4953
+ export interface Targets<Root extends Machine.StateNodeConfig> {
4954
+ /** Root data owner and the starting point for descendant state references. */
4955
+ readonly root: TargetReferenceTree<Root, Root, "">;
4956
+ }
4957
+ /**
4958
+ * Derives immutable state references from a root descriptor.
4959
+ *
4960
+ * References follow the declared tree: `targets.root.Checkout.Review`.
4961
+ * Creating references does not construct state values or start machine work.
4962
+ *
4963
+ * @category constructors
4964
+ * @since 0.34.0
4965
+ */
4966
+ export declare const targets: <const Root extends Machine.StateNodeConfig>(root: State<Root>) => Targets<Root>;
4967
+ type UniqueSourceNames<F, S, T, L, C> = [
4968
+ Extract<keyof F, keyof S | keyof T | keyof L | keyof C> | Extract<keyof S, keyof T | keyof L | keyof C> | Extract<keyof T, keyof L | keyof C> | Extract<keyof L, keyof C>
4969
+ ] extends [never] ? unknown : {
4970
+ readonly "~effect/Machine/DuplicateSourceName": never;
4971
+ };
4972
+ type MakeConfig<Root extends Machine.StateNodeConfig, 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, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources, Branches extends Machine.BranchDefinitions<Root>> = {
4973
+ /** Lazy Effects or functions with one required input, invoked by registered name. */
4974
+ readonly effects?: Effects & Machine.ValidatePrograms<Effects>;
4975
+ /** Lazy Streams or functions with one required input, invoked by registered name. */
4976
+ readonly streams?: Streams & Machine.ValidatePrograms<Streams>;
4977
+ /** Cancellable delays, supplied as durations or functions of one required input. */
4978
+ readonly timers?: Timers & Machine.ValidatePrograms<Timers>;
4979
+ /** Logic values or functions of one required input; their Effect channels remain inferred. */
4980
+ readonly logic?: Logics & Machine.ValidatePrograms<Logics> & Machine.ValidateLogicSources<NoInfer<Logics>>;
4981
+ /** Child machine descriptors registered for state-owned invocation. */
4982
+ readonly children?: Children;
4983
+ /** Named groups of inspectable destinations used by transition resolvers. */
4984
+ readonly branches?: Branches & {
4985
+ readonly [K in keyof Branches]: ValidateTransitionBranchRecord<NoInfer<Branches[K]>>;
4986
+ };
4777
4987
  /** Stable definition identifier used by inspection and visualization. */
4778
4988
  readonly id?: string;
4779
4989
  /** State topology and value schemas, captured by a `Machine.state` descriptor. */
@@ -4792,37 +5002,53 @@ type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends Readon
4792
5002
  /** Schema used to decode input before initial-state construction. */
4793
5003
  readonly input?: Input;
4794
5004
  };
4795
- type MakeResult<Root extends Machine.StateNodeConfig, 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<{
5005
+ type MakeResult<Root extends Machine.StateNodeConfig, 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, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources, Branches extends Readonly<Record<string, Readonly<Record<string, unknown>>>>> = Definition<{
4796
5006
  readonly "": Root;
4797
5007
  }, readonly [...InputEvents, ...InternalEvents], Input, InitialE, InitialR, Machine.FinalStateFromDefinition<{
4798
5008
  readonly "": Root;
4799
5009
  }>, Machine.TerminalOutput<{
4800
5010
  readonly "": Root;
4801
- }>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration>>;
5011
+ }>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration>, {
5012
+ /** Lazy Effects or functions with one required input, invoked by registered name. */
5013
+ readonly effects: Effects;
5014
+ /** Lazy Streams or functions with one required input, invoked by registered name. */
5015
+ readonly streams: Streams;
5016
+ /** Cancellable delays, supplied as durations or functions of one required input. */
5017
+ readonly timers: Timers;
5018
+ /** Logic values or functions of one required input; their Effect channels remain inferred. */
5019
+ readonly logic: Logics;
5020
+ /** Child machine descriptors registered for state-owned invocation. */
5021
+ readonly children: Children;
5022
+ /** Named groups of inspectable destinations used by transition resolvers. */
5023
+ readonly branches: Branches;
5024
+ }>;
4802
5025
  type RootInitialization<Root extends Machine.StateNodeConfig, Input> = {
4803
5026
  readonly initialConfiguration?: never;
4804
5027
  } & (Machine.NodeSchema<Root> extends never ? {
5028
+ /** Enters a compound or parallel subtree through its declared initialization. */
4805
5029
  readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
4806
5030
  } : {} extends NodeMakeInput<Root> ? {
5031
+ /** Enters a compound or parallel subtree through its declared initialization. */
4807
5032
  readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
4808
5033
  } : {
5034
+ /** Enters a compound or parallel subtree through its declared initialization. */
4809
5035
  readonly initial: Machine.RootInitialBuilderInput<Root, Input>;
4810
5036
  });
4811
5037
  /** @inline */
4812
5038
  interface Make {
4813
5039
  /** @param config Complete starting configuration, including root and descendant values. */
4814
- <const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration> & {
5040
+ <const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>> & {
4815
5041
  /** Mutually exclusive with a complete initial configuration. */
4816
5042
  readonly initial?: never;
4817
5043
  /** Constructs the complete initial root configuration, overriding child defaults. */
4818
5044
  readonly initialConfiguration: Machine.RootConfigurationBuilderInput<NoInfer<Root>, Input["Type"]>;
4819
5045
  }): MakeResult<Root & {
4820
5046
  readonly "~effect/Machine/ExplicitInitial": true;
4821
- }, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
5047
+ }, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
4822
5048
  /** @param config Complete schema-first machine definition. */
4823
- <const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration> & Exclude<RootInitialization<NoInfer<Root>, Input["Type"]>, {
5049
+ <const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>> & Exclude<RootInitialization<NoInfer<Root>, Input["Type"]>, {
4824
5050
  readonly initialConfiguration: unknown;
4825
- }>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
5051
+ }>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
4826
5052
  }
4827
5053
  /**
4828
5054
  * Creates a schema-first machine definition.
@@ -4865,6 +5091,7 @@ interface Make {
4865
5091
  *
4866
5092
  * const States = Machine.state({ initial: "Count", states: { Count } })
4867
5093
  * const Events = Machine.eventsFromSchemas(Increment)
5094
+ * const targets = Machine.targets(States)
4868
5095
  *
4869
5096
  * const counter = Machine.make({
4870
5097
  * root: States,
@@ -4873,9 +5100,10 @@ interface Make {
4873
5100
  * }).handle({ states: {
4874
5101
  * Count: {
4875
5102
  * on: {
4876
- * Increment: (to) =>
4877
- * to.branch.Count().resolve(({ event, state, target }) =>
4878
- * target.decoded(new Count({ value: state.value + event.by })))
5103
+ * Increment: {
5104
+ * update: targets.root.Count,
5105
+ * decoded: ({ event, state }) => new Count({ value: state.value + event.by })
5106
+ * }
4879
5107
  * }
4880
5108
  * }
4881
5109
  * } })
@@ -5130,17 +5358,16 @@ type TransitionBranchRecordError<Message extends string, Key extends PropertyKey
5130
5358
  readonly "~effect/Machine/TransitionBranchRecordError": Message;
5131
5359
  readonly key: Key;
5132
5360
  };
5133
- type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol>;
5134
- type InvalidUpdatingTransitionBranchKey<Branches> = {
5135
- readonly [Key in keyof Branches]: Branches[Key] extends {
5136
- readonly target: {
5137
- readonly "~effect/Machine/UpdatingTransitionTarget": string;
5138
- };
5139
- } ? Key : never;
5140
- }[keyof Branches];
5141
- type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never] ? TransitionBranchRecordError<"Branch records must contain at least one branch"> : [InvalidStaticTransitionBranchKey<Branches>] extends [never] ? [
5142
- InvalidUpdatingTransitionBranchKey<Branches>
5143
- ] extends [never] ? unknown : TransitionBranchRecordError<"Updating targets require a direct resolver", InvalidUpdatingTransitionBranchKey<Branches>> : TransitionBranchRecordError<"Branch keys must be non-empty, non-index strings", InvalidStaticTransitionBranchKey<Branches>>;
5361
+ type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol | `${number}` | "NaN" | "Infinity" | "-Infinity">;
5362
+ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never] ? TransitionBranchRecordError<"Branch records must contain at least one branch"> : [InvalidStaticTransitionBranchKey<Branches>] extends [never] ? {
5363
+ readonly [K in keyof Branches]: {
5364
+ readonly [Extra in Exclude<keyof Branches[K], "target" | "update" | "initial" | "history" | "none" | "title">]: never;
5365
+ } & (Branches[K] extends {
5366
+ readonly title: "";
5367
+ } ? {
5368
+ readonly title: never;
5369
+ } : unknown);
5370
+ } : TransitionBranchRecordError<"Branch keys must be non-empty, non-numeric strings", InvalidStaticTransitionBranchKey<Branches>>;
5144
5371
  /**
5145
5372
  * Plans the initial state for a machine without executing machine commands.
5146
5373
  *
@@ -5200,9 +5427,11 @@ export declare const planInitial: <const States extends Machine.StateSchemas, co
5200
5427
  }>;
5201
5428
  } & ({
5202
5429
  readonly done: true;
5430
+ /** Constructs the decoded output declared by the state schema. */
5203
5431
  readonly output: Output;
5204
5432
  } | {
5205
5433
  readonly done: false;
5434
+ /** Constructs the decoded output declared by the state schema. */
5206
5435
  readonly output: undefined;
5207
5436
  }), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, never>;
5208
5437
  /**
@@ -5337,7 +5566,7 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
5337
5566
  * events: Machine.eventsFromSchemas(),
5338
5567
  * internalEvents,
5339
5568
  * initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.from()))
5340
- * }).handle({ states: { Idle: { on: { Loaded: (to) => to.none } } } })
5569
+ * }).handle({ states: { Idle: { on: { Loaded: { none: true } } } } })
5341
5570
  *
5342
5571
  * export const canLoad = Effect.gen(function*() {
5343
5572
  * const initial = yield* Machine.planInitial(machine)
@@ -5379,6 +5608,7 @@ export declare const can: {
5379
5608
  * class On extends Schema.TaggedClass<On>("On")("On", {}) {}
5380
5609
  * class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
5381
5610
  * const States = Machine.state({ initial: "Off", states: { Off, On } })
5611
+ * const targets = Machine.targets(States)
5382
5612
  * const machine = Machine.make({
5383
5613
  * root: States,
5384
5614
  * events: Machine.eventsFromSchemas(Toggle),
@@ -5386,8 +5616,7 @@ export declare const can: {
5386
5616
  * }).handle({ states: {
5387
5617
  * Off: {
5388
5618
  * on: {
5389
- * Toggle: (to) =>
5390
- * to.branch.On().resolve(({ target }) => target.from())
5619
+ * Toggle: { target: targets.root.On }
5391
5620
  * }
5392
5621
  * },
5393
5622
  * On: {}
@@ -5422,9 +5651,11 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
5422
5651
  }>;
5423
5652
  } & ({
5424
5653
  readonly done: true;
5654
+ /** Constructs the decoded output declared by the state schema. */
5425
5655
  readonly output: Output;
5426
5656
  } | {
5427
5657
  readonly done: false;
5658
+ /** Constructs the decoded output declared by the state schema. */
5428
5659
  readonly output: undefined;
5429
5660
  }), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
5430
5661
  /**
@@ -5456,6 +5687,7 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
5456
5687
  * @since 0.4.0
5457
5688
  */
5458
5689
  export declare const logic: <State, Event = never, Output = void, Error = never, Requirements = never, InitialError = never, InitialRequirements = never>(options: {
5690
+ /** Enters a compound or parallel subtree through its declared initialization. */
5459
5691
  readonly initial: State | ((scope: Logic.Scope<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
5460
5692
  readonly run: (context: Logic.Context<State, Event>) => Effect.Effect<Output, Error, Requirements>;
5461
5693
  }) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError>;
@@ -5503,7 +5735,7 @@ export declare const childAddress: <Event = never>(id: string) => ChildAddress<E
5503
5735
  * This Effect requires a managed process runtime. A named child id must be
5504
5736
  * unique for the current parent until that child stops.
5505
5737
  *
5506
- * Use a state's `invoke: (from) => from.logic(...)` declaration for children
5738
+ * Register logic in `make({ logic })` and use `invoke: { src, id, address, ...outcomes }` for children
5507
5739
  * that start and stop with that state.
5508
5740
  * @see {@link sendTo} for sending events to named children.
5509
5741
  * @category runtime