@typeonce/effect-machine 0.34.0 → 0.35.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 (71) hide show
  1. package/README.md +93 -29
  2. package/dist/Machine.d.ts +309 -361
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +126 -87
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/configuration.d.ts +0 -1
  7. package/dist/internal/machine/configuration.d.ts.map +1 -1
  8. package/dist/internal/machine/configuration.js +0 -19
  9. package/dist/internal/machine/configuration.js.map +1 -1
  10. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  11. package/dist/internal/machine/executionPlan.js +12 -20
  12. package/dist/internal/machine/executionPlan.js.map +1 -1
  13. package/dist/internal/machine/initialDeclaration.d.ts +14 -0
  14. package/dist/internal/machine/initialDeclaration.d.ts.map +1 -0
  15. package/dist/internal/machine/initialDeclaration.js +137 -0
  16. package/dist/internal/machine/initialDeclaration.js.map +1 -0
  17. package/dist/internal/machine/machine.d.ts +0 -2
  18. package/dist/internal/machine/machine.d.ts.map +1 -1
  19. package/dist/internal/machine/machine.js +39 -120
  20. package/dist/internal/machine/machine.js.map +1 -1
  21. package/dist/internal/machine/planner.d.ts +8 -0
  22. package/dist/internal/machine/planner.d.ts.map +1 -1
  23. package/dist/internal/machine/planner.js +25 -67
  24. package/dist/internal/machine/planner.js.map +1 -1
  25. package/dist/internal/machine/protocol.d.ts +1 -1
  26. package/dist/internal/machine/protocol.d.ts.map +1 -1
  27. package/dist/internal/machine/protocol.js.map +1 -1
  28. package/dist/internal/machine/stateDefinition.d.ts +1 -1
  29. package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
  30. package/dist/internal/machine/stateDefinition.js +1 -13
  31. package/dist/internal/machine/stateDefinition.js.map +1 -1
  32. package/dist/internal/machine/targetReference.d.ts.map +1 -1
  33. package/dist/internal/machine/targetReference.js +14 -4
  34. package/dist/internal/machine/targetReference.js.map +1 -1
  35. package/dist/internal/machine/topology.d.ts.map +1 -1
  36. package/dist/internal/machine/topology.js +3 -2
  37. package/dist/internal/machine/topology.js.map +1 -1
  38. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  39. package/dist/internal/testing/machine/finiteModel.js +15 -6
  40. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  41. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  42. package/dist/internal/testing/machine/verification.js +7 -1
  43. package/dist/internal/testing/machine/verification.js.map +1 -1
  44. package/dist/testing/MachineTest.d.ts +105 -73
  45. package/dist/testing/MachineTest.d.ts.map +1 -1
  46. package/dist/testing/MachineTest.js +105 -73
  47. package/dist/testing/MachineTest.js.map +1 -1
  48. package/dist/unstable/cluster/ClusterMachine.d.ts +13 -8
  49. package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
  50. package/dist/unstable/cluster/ClusterMachine.js +13 -8
  51. package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
  52. package/dist/unstable/reactivity/AtomMachine.d.ts +41 -24
  53. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  54. package/dist/unstable/reactivity/AtomMachine.js +41 -24
  55. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/Machine.ts +471 -744
  58. package/src/internal/machine/configuration.ts +0 -20
  59. package/src/internal/machine/executionPlan.ts +11 -18
  60. package/src/internal/machine/initialDeclaration.ts +157 -0
  61. package/src/internal/machine/machine.ts +38 -179
  62. package/src/internal/machine/planner.ts +30 -83
  63. package/src/internal/machine/protocol.ts +3 -3
  64. package/src/internal/machine/stateDefinition.ts +1 -15
  65. package/src/internal/machine/targetReference.ts +19 -4
  66. package/src/internal/machine/topology.ts +3 -2
  67. package/src/internal/testing/machine/finiteModel.ts +16 -10
  68. package/src/internal/testing/machine/verification.ts +7 -1
  69. package/src/testing/MachineTest.ts +105 -73
  70. package/src/unstable/cluster/ClusterMachine.ts +13 -8
  71. package/src/unstable/reactivity/AtomMachine.ts +41 -24
package/src/Machine.ts CHANGED
@@ -120,20 +120,19 @@ type IsAny<A> = 0 extends (1 & A) ? true : false
120
120
  * ```ts
121
121
  * import { Machine } from "@typeonce/effect-machine"
122
122
  * import { Schema } from "effect"
123
- *
124
123
  * const events = Machine.events({ Add: { by: Schema.Number } })
125
124
  * const Root = Machine.state({ fields: { count: Schema.Number } })
126
125
  * const targets = Machine.targets(Root)
127
126
  * export const counter = Machine.make({
128
127
  * root: Root,
129
- * events,
130
- * initial: (root) => root.from(() => ({ count: 0 }))
128
+ * events
131
129
  * }).handle({
130
+ * root: () => ({ count: 0 }),
132
131
  * on: {
133
132
  * Add: {
134
133
  * update: targets.root,
135
134
  * guard: ({ event }) => event.by > 0,
136
- * from: ({ root, event }) => ({ count: root.count + event.by })
135
+ * data: ({ root, event }) => ({ count: root.count + event.by })
137
136
  * }
138
137
  * }
139
138
  * })
@@ -284,21 +283,24 @@ export interface Definition<
284
283
  ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
285
284
  Registrations extends Machine.Registrations = {}
286
285
  > extends
287
- Machine<
288
- States,
289
- Events,
290
- Input,
291
- Machine.StateIdentifier<States>,
292
- never,
293
- never,
294
- InitialE,
295
- InitialR,
296
- FinalStates,
297
- Output,
298
- Emits,
299
- never,
300
- InputEvents,
301
- ParentEvents
286
+ Omit<
287
+ Machine<
288
+ States,
289
+ Events,
290
+ Input,
291
+ Machine.StateIdentifier<States>,
292
+ never,
293
+ never,
294
+ InitialE,
295
+ InitialR,
296
+ FinalStates,
297
+ Output,
298
+ Emits,
299
+ never,
300
+ InputEvents,
301
+ ParentEvents
302
+ >,
303
+ TypeId | "stateNodes" | "makeTargetBuilder" | "handlers" | "initial" | "initialDefinition"
302
304
  >
303
305
  {
304
306
  /**
@@ -353,7 +355,10 @@ export declare namespace Definition {
353
355
  * @category models
354
356
  * @since 0.15.0
355
357
  */
356
- export interface Any extends Machine.Any {
358
+ export interface Any
359
+ extends
360
+ Omit<Machine.Any, TypeId | "stateNodes" | "makeTargetBuilder" | "handlers" | "initial" | "initialDefinition">
361
+ {
357
362
  readonly handle: any
358
363
  }
359
364
  }
@@ -668,7 +673,6 @@ type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Run
668
673
  : never
669
674
 
670
675
  const InvokeTypeId: typeof internal.InvokeTypeId = internal.InvokeTypeId
671
- declare const InitialBuilderTypeId: unique symbol
672
676
 
673
677
  type StateDefinitionError<
674
678
  Message extends string,
@@ -835,19 +839,10 @@ type ValidateCompoundStateNode<
835
839
  Node extends Machine.StateNodeConfig,
836
840
  Children extends Machine.StateSchemas,
837
841
  Path extends PropertyKey
838
- > = Node extends { readonly initial: infer Initial } ?
839
- Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ?
840
- & ValidateInitialSelectorChild<Children, Path>
841
- & ValidateWithSelectorChild<Node, Children, Path>
842
- & {
843
- readonly states: ValidateStateTree<Children, true, Extract<Path, string>>
844
- }
845
- : StateDefinitionError<
846
- "Compound initial must be one of its direct child keys",
847
- Path,
848
- Extract<Initial, PropertyKey>
849
- >
850
- : StateDefinitionError<"Compound states must declare an initial child", Path>
842
+ > = "initial" extends keyof Node ? StateDefinitionError<"Declare initial edges in handle", Path>
843
+ : ValidateInitialSelectorChild<Children, Path> & ValidateWithSelectorChild<Node, Children, Path> & {
844
+ readonly states: ValidateStateTree<Children, true, Extract<Path, string>>
845
+ }
851
846
 
852
847
  type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ?
853
848
  StateDefinitionError<"Atomic states cannot declare an initial child">
@@ -1125,149 +1120,6 @@ type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input
1125
1120
  state: (builder: Builder) => Selected
1126
1121
  ) => Machine.StateConstruction<UnwrapConstruction<Selected>>
1127
1122
 
1128
- type InitialSnapshotBuilderWithPrefix<
1129
- States extends Machine.StateSchemas,
1130
- Prefix extends string = ""
1131
- > =
1132
- & {
1133
- readonly [Key in ActiveStateKey<States>]: InitialSnapshotMethod<States, Key, Prefix>
1134
- }
1135
- & {
1136
- readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>
1137
- }
1138
-
1139
- type InitialSnapshotMethod<
1140
- States extends Machine.StateSchemas,
1141
- StateId extends ActiveStateKey<States>,
1142
- Prefix extends string
1143
- > = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<
1144
- InitialSnapshotFromArguments<States, StateId, Prefix>,
1145
- InitialSnapshotResult<States, StateId, Prefix>
1146
- >
1147
- :
1148
- & DecodedMethod<
1149
- InitialSnapshotArguments<States, StateId, Prefix>,
1150
- InitialSnapshotResult<States, StateId, Prefix>
1151
- >
1152
- & FromMethod<
1153
- InitialSnapshotFromArguments<States, StateId, Prefix>,
1154
- InitialSnapshotResult<States, StateId, Prefix>
1155
- >
1156
-
1157
- type InitialSnapshotArguments<
1158
- States extends Machine.StateSchemas,
1159
- StateId extends ActiveStateKey<States>,
1160
- Prefix extends string,
1161
- Path extends string = Machine.JoinPath<Prefix, StateId>
1162
- > = States[StateId] extends infer Node ?
1163
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1164
- WithNodeValue<Node, [
1165
- states: (
1166
- builder: InitialParallelBuilder<Children, Path>
1167
- ) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>>
1168
- ]>
1169
- : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
1170
- Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
1171
- WithNodeValue<Node, [
1172
- state: (
1173
- builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>
1174
- ) => InitialSelectableResult<Children, Initial, Path>
1175
- ]>
1176
- : never
1177
- : WithNodeValue<Node, []>
1178
- : never
1179
-
1180
- type InitialSnapshotFromArguments<
1181
- States extends Machine.StateSchemas,
1182
- StateId extends ActiveStateKey<States>,
1183
- Prefix extends string,
1184
- Path extends string = Machine.JoinPath<Prefix, StateId>
1185
- > = States[StateId] extends infer Node ?
1186
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1187
- WithNodeInput<Node, [
1188
- states: (
1189
- builder: InitialParallelBuilder<Children, Path>
1190
- ) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
1191
- ]>
1192
- : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
1193
- Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
1194
- WithNodeInput<Node, [
1195
- state: (
1196
- builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>
1197
- ) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
1198
- ]>
1199
- : never
1200
- : WithNodeInput<Node, []>
1201
- : never
1202
-
1203
- type InitialSnapshotResult<
1204
- States extends Machine.StateSchemas,
1205
- StateId extends ActiveStateKey<States>,
1206
- Prefix extends string,
1207
- Path extends string = Machine.JoinPath<Prefix, StateId>
1208
- > = States[StateId] extends infer Node ?
1209
- Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1210
- Machine.ParallelSnapshot<
1211
- Path,
1212
- NodeValue<Node>,
1213
- InitialSnapshotRegionsWithPrefix<Children, Path>
1214
- >
1215
- : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
1216
- Node extends { readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> } ?
1217
- Machine.CompoundSnapshot<
1218
- Path,
1219
- NodeValue<Node>,
1220
- InitialSelectableResult<Children, Initial, Path>
1221
- >
1222
- : never
1223
- : Machine.AtomicSnapshot<Path, NodeValue<Node>>
1224
- : never
1225
-
1226
- type InitialSelectableResult<
1227
- States extends Machine.StateSchemas,
1228
- StateId extends ActiveStateKey<States> | ChoiceStateKey<States>,
1229
- Prefix extends string
1230
- > = StateId extends ChoiceStateKey<States> ? Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, StateId>>
1231
- : StateId extends ActiveStateKey<States> ? InitialSnapshotResult<States, StateId, Prefix>
1232
- : never
1233
-
1234
- type InitialSnapshotRegionsWithPrefix<
1235
- States extends Machine.StateSchemas,
1236
- Prefix extends string
1237
- > = {
1238
- readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>
1239
- }
1240
-
1241
- type InitialParallelBuilder<
1242
- States extends Machine.StateSchemas,
1243
- Prefix extends string,
1244
- Remaining extends ActiveStateKey<States> = ActiveStateKey<States>,
1245
- Regions = {},
1246
- Constructed extends boolean = false
1247
- > =
1248
- & SnapshotBuilderComplete<Regions, Constructed>
1249
- & {
1250
- readonly [Key in Remaining]: NodeBuilderMethod<
1251
- States[Key],
1252
- InitialSnapshotArguments<States, Key, Prefix>,
1253
- InitialParallelBuilder<
1254
- States,
1255
- Prefix,
1256
- Exclude<Remaining, Key>,
1257
- Regions & { readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix> },
1258
- Constructed
1259
- >,
1260
- InitialSnapshotFromArguments<States, Key, Prefix>,
1261
- InitialParallelBuilder<
1262
- States,
1263
- Prefix,
1264
- Exclude<Remaining, Key>,
1265
- Regions & { readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix> },
1266
- true
1267
- >
1268
- >
1269
- }
1270
-
1271
1123
  type FullSnapshotBuilderWithPrefix<
1272
1124
  in out States extends Machine.StateSchemas,
1273
1125
  in out Prefix extends string = ""
@@ -1843,16 +1695,9 @@ type InitializerClosureForNode<
1843
1695
  Node extends { readonly type: "parallel"; readonly states: infer Children extends Machine.StateSchemas } ?
1844
1696
  | (HasRequiredActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never)
1845
1697
  | InitializerClosuresForChildren<AllStates, Children, Path>
1846
- : Node extends { readonly states: infer Children extends Machine.StateSchemas; readonly initial: infer Initial } ?
1847
- | (Initial extends ActiveStateKey<Children> ?
1848
- RequiresInitialValue<Children[Initial]> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never
1849
- : never)
1850
- | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<
1851
- AllStates,
1852
- Children[Initial],
1853
- Machine.JoinPath<Path, Initial>
1854
- >
1855
- : never)
1698
+ : Node extends { readonly states: infer Children extends Machine.StateSchemas } ?
1699
+ | Extract<Path, Machine.StateIdentifier<AllStates>>
1700
+ | InitializerClosuresForChildren<AllStates, Children, Path>
1856
1701
  : never
1857
1702
  : never
1858
1703
 
@@ -3170,7 +3015,6 @@ export declare namespace Machine {
3170
3015
  /** Compound states are ordinary active states. */
3171
3016
  readonly type?: "active"
3172
3017
  /** Direct child selected when the compound state is entered initially. */
3173
- readonly initial: string
3174
3018
  /** Nested state nodes owned by this compound state. */
3175
3019
  readonly states: StateTree
3176
3020
  /** Schema-backed states take their annotations from the schema. */
@@ -3179,7 +3023,6 @@ export declare namespace Machine {
3179
3023
  | {
3180
3024
  readonly schema?: never
3181
3025
  readonly type?: "active"
3182
- readonly initial: string
3183
3026
  readonly states: StateTree
3184
3027
  /** Descriptive metadata for a schema-less state. */
3185
3028
  readonly annotations?: SchemaLessStateAnnotations
@@ -3305,7 +3148,6 @@ export declare namespace Machine {
3305
3148
  * @category utility types
3306
3149
  * @since 0.4.0
3307
3150
  */
3308
- type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>
3309
3151
 
3310
3152
  /**
3311
3153
  * Typed snapshot access shared by state descriptors.
@@ -3876,19 +3718,20 @@ export declare namespace Machine {
3876
3718
  })
3877
3719
  & EnsureChoiceImplementations<States, UnhandledStates>
3878
3720
 
3879
- /** Owners whose declared default descendants require supplied values. */
3721
+ /** Owners that require a handler-owned initial edge or region data. */
3880
3722
  export type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never :
3881
- "" extends keyof States ? States[""] extends { readonly "~effect/Machine/ExplicitInitial": true } ? never
3882
- : InitializerClosureForNode<States, States[""], ""> :
3723
+ "" extends keyof States ? InitializerClosureForNode<States, States[""], ""> :
3883
3724
  never
3884
3725
 
3885
3726
  /** Proof that initialization can construct every required default value. */
3886
3727
  export type EnsureInitialImplementations<
3887
3728
  States extends StateSchemas,
3888
3729
  UnhandledStates extends StateIdentifier<States>
3889
- > = [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown : {
3890
- readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>
3891
- }
3730
+ > = [UnhandledStates] extends [never] ? unknown
3731
+ : [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown :
3732
+ {
3733
+ readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>
3734
+ }
3892
3735
 
3893
3736
  /**
3894
3737
  * Extracts a state-tree node by state path.
@@ -4843,15 +4686,6 @@ export declare namespace Machine {
4843
4686
 
4844
4687
  type RootBuilder<Builder> = Builder extends { readonly "": infer Root } ? Root : never
4845
4688
 
4846
- /** Definition-time selector that can choose only a valid top-level initial entry. */
4847
- type InitialTargetSelector<States extends StateSchemas> = {
4848
- readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends
4849
- { readonly states: StateSchemas } ? {
4850
- readonly initial: SelectionValue<InitialBuilder<States>[Key], Key, "initial", "initial">
4851
- }
4852
- : SelectionMethod<InitialBuilder<States>[Key], Key, "state", "initial">
4853
- }
4854
-
4855
4689
  /**
4856
4690
  * Context passed to a state/event handler.
4857
4691
  *
@@ -5213,16 +5047,7 @@ export declare namespace Machine {
5213
5047
  * @category utility types
5214
5048
  * @since 0.4.0
5215
5049
  */
5216
- export type InitialResult<States extends StateSchemas, E, R> =
5217
- | Snapshot<States>
5218
- | InitialSnapshot<States>
5219
- | InitialTarget<StateIdentifier<States>>
5220
- | StateConstruction<Snapshot<States> | InitialSnapshot<States> | InitialTarget<StateIdentifier<States>>>
5221
-
5222
- /** Initial snapshots may transiently terminate in a declared choice node. */
5223
- export type InitialSnapshot<States extends StateSchemas> = {
5224
- readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">
5225
- }[ActiveStateKey<States>]
5050
+ export type InitialResult<States extends StateSchemas, E, R> = InitialTarget<StateIdentifier<States>>
5226
5051
 
5227
5052
  /**
5228
5053
  * Return value accepted from transition handlers.
@@ -5308,10 +5133,6 @@ export declare namespace Machine {
5308
5133
  export type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config
5309
5134
  ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never
5310
5135
  : never
5311
- /** Extracts the return value from an implicit initial child implementation. */
5312
- export type StateInitializeReturn<Config> = Config extends { readonly initialize?: infer Initialize }
5313
- ? NonNullable<Initialize> extends (...args: any) => infer Ret ? Ret : never
5314
- : never
5315
5136
  /** Extracts the return values from a state's history defaults. */
5316
5137
  export type HistoryDefaultReturn<Config> = Config extends { readonly history?: infer History } ? {
5317
5138
  readonly [Key in keyof NonNullable<History>]: NonNullable<History>[Key] extends {
@@ -5543,7 +5364,7 @@ export declare namespace Machine {
5543
5364
  * @category utility types
5544
5365
  * @since 0.4.0
5545
5366
  */
5546
- export type ConfigServices<Config> =
5367
+ export type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never :
5547
5368
  | Effect.Services<EventHandlerReturn<Config>>
5548
5369
  | Effect.Services<AlwaysReturn<Config>>
5549
5370
  | Effect.Services<DoneReturn<Config>>
@@ -5552,6 +5373,7 @@ export declare namespace Machine {
5552
5373
  | Effect.Services<HistoryDefaultReturn<Config>>
5553
5374
  | Effect.Services<ChoiceReturn<Config>>
5554
5375
  | InvokeRequirements<Config>
5376
+ : never
5555
5377
 
5556
5378
  /** The only transition value accepted by machine handler APIs. */
5557
5379
  type TransitionConfig<
@@ -5713,104 +5535,6 @@ export declare namespace Machine {
5713
5535
  Branches extends Readonly<Record<string, TransitionBranchInput>>
5714
5536
  > = Omit<Context, "target"> & { readonly select: BranchSelectors<Branches> }
5715
5537
 
5716
- type ConstructionCallbacks<Context, Builder, Result> = {
5717
- readonly [
5718
- Method in Extract<keyof Builder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown
5719
- ? Args extends readonly [unknown?] ? Method : never :
5720
- never
5721
- ]: Builder[Method] extends (...args: infer Args) => unknown ? (
5722
- value: (context: Context) => Args[0]
5723
- ) => Result :
5724
- never
5725
- }
5726
-
5727
- /** @internal Type evidence retained by a machine initial-entry declaration. */
5728
- export interface InitialBuilderEvidence<out Selection> {
5729
- readonly [InitialBuilderTypeId]: Types.Covariant<Selection>
5730
- }
5731
-
5732
- /** Decoded input shared by initial construction callbacks. */
5733
- export interface InitialContext<Input> {
5734
- /** Decoded value supplied when the machine is started. */
5735
- readonly input: Input
5736
- }
5737
-
5738
- /** A selected machine initial entry with its exact resolver target. */
5739
- export type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> =
5740
- & Selection
5741
- & ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<Selection>, InitialBuilderEvidence<Selection>>
5742
- & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {})
5743
- & {
5744
- /** Lazily constructs the selected initial state from decoded machine input. */
5745
- readonly resolve: (
5746
- resolve: (context: {
5747
- /** Decoded value supplied when the machine is started. */
5748
- readonly input: Input
5749
- /** Builder specialized to the selected initial destination. */
5750
- readonly target: SelectionBuilder<Selection>
5751
- }) => SelectedTargetResult<Selection>
5752
- ) => InitialBuilderEvidence<Selection>
5753
- }
5754
-
5755
- type InitialSelectorNode<Input, Node> = Node extends (...args: infer Args) => infer Selection ?
5756
- Selection extends TargetSelection<any, any, any> ?
5757
- & ((...args: Args) => InitialTransitionTarget<Input, Selection>)
5758
- & {
5759
- readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>
5760
- }
5761
- : never
5762
- : Node extends TargetSelection<any, any, any> ? InitialTransitionTarget<Input, Node>
5763
- : {
5764
- readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>
5765
- }
5766
-
5767
- /** Definition-time selector for a machine's top-level initial entry. */
5768
- export type InitialSelector<States extends StateSchemas, Input = void> = InitialSelectorNode<
5769
- Input,
5770
- InitialTargetSelector<States>
5771
- >
5772
-
5773
- /** Target-first initial-entry declaration accepted by {@link make}. */
5774
- export type InitialBuilderInput<States extends StateSchemas, Input> = (
5775
- to: InitialSelector<States, Input>
5776
- ) => InitialBuilderEvidence<TargetSelection<any, any, any>>
5777
-
5778
- /** Initializes the root and its declared default descendants. */
5779
- export type RootInitialBuilderInput<Root extends StateNodeConfig, Input> = (
5780
- root: InitialTransitionTarget<Input, SelectionValue<InitialTargetFactory<Root, "">, "", "initial", "initial">>
5781
- ) => InitialBuilderEvidence<TargetSelection<any, any, any>>
5782
-
5783
- interface RootConfigurationSelection<in out Root extends StateNodeConfig> extends
5784
- TargetSelection<
5785
- FullSnapshotMethod<{ readonly "": Root }, "" & ActiveStateKey<{ readonly "": Root }>, "">,
5786
- "",
5787
- "state",
5788
- "initial"
5789
- >
5790
- {}
5791
-
5792
- /** Explicitly constructs a complete starting configuration. */
5793
- export type RootConfigurationBuilderInput<Root extends StateNodeConfig, Input> = (
5794
- root:
5795
- & ConstructionCallbacks<
5796
- InitialContext<Input>,
5797
- SelectionBuilder<RootConfigurationSelection<Root>>,
5798
- InitialBuilderEvidence<RootConfigurationSelection<Root>>
5799
- >
5800
- & {
5801
- readonly resolve: (
5802
- resolve: (
5803
- context: {
5804
- /** Decoded startup input. */
5805
- readonly input: Input
5806
- /** Builder for the complete root configuration. */
5807
- readonly target: SelectionBuilder<RootConfigurationSelection<Root>>
5808
- }
5809
- ) => ConstructionResult<Snapshot<{ readonly "": Root }>>
5810
- ) => InitialBuilderEvidence<RootConfigurationSelection<Root>>
5811
- }
5812
- ) => InitialBuilderEvidence<TargetSelection<any, any, any>>
5813
-
5814
5538
  export type InvokeTransition<
5815
5539
  States extends StateSchemas,
5816
5540
  Events extends ReadonlyArray<TaggedSchema>,
@@ -5984,120 +5708,6 @@ export declare namespace Machine {
5984
5708
  readonly output?: never
5985
5709
  }
5986
5710
 
5987
- /**
5988
- * Values constructed for a state's schema-valued direct initial children.
5989
- *
5990
- * @category utility types
5991
- * @since 0.13.0
5992
- */
5993
- export type StateInitializeValue<
5994
- States extends StateSchemas,
5995
- StateId extends StateIdentifier<States>
5996
- > = NodeByIdentifier<States, StateId> extends infer Node ?
5997
- Node extends { readonly type: "parallel"; readonly states: infer Children extends StateSchemas } ? {
5998
- readonly [Key in ActiveStateKey<Children> as NodeSchema<Children[Key]> extends never ? never : Key]: NodeValue<
5999
- Children[Key]
6000
- >
6001
- }
6002
- : Node extends { readonly states: infer Children extends StateSchemas; readonly initial: infer Initial } ?
6003
- Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never
6004
- : { readonly [Key in Initial]: NodeValue<Children[Initial]> }
6005
- : never
6006
- : never
6007
- : never
6008
-
6009
- type StateInitializeCompoundBuilder<Node, Initial extends PropertyKey> = Node extends {
6010
- readonly states: infer Children extends StateSchemas
6011
- } ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never
6012
- : NodeBuilderMethod<
6013
- Children[Initial],
6014
- readonly [value: NodeValue<Children[Initial]>],
6015
- SnapshotBuilderComplete<{ readonly [Key in Initial]: NodeValue<Children[Initial]> }>,
6016
- readonly [input: NodeMakeInput<Children[Initial]>],
6017
- SnapshotBuilderComplete<{ readonly [Key in Initial]: NodeValue<Children[Initial]> }, true>
6018
- >
6019
- : never
6020
- : never
6021
-
6022
- type StateInitializeParallelBuilder<
6023
- Children extends StateSchemas,
6024
- Remaining extends ActiveStateKey<Children> = {
6025
- readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]> extends never ? never : Key
6026
- }[ActiveStateKey<Children>],
6027
- Values = {},
6028
- Constructed extends boolean = false
6029
- > =
6030
- & SnapshotBuilderComplete<Values, Constructed>
6031
- & {
6032
- readonly [Key in Remaining]: NodeBuilderMethod<
6033
- Children[Key],
6034
- readonly [value: NodeValue<Children[Key]>],
6035
- StateInitializeParallelBuilder<
6036
- Children,
6037
- Exclude<Remaining, Key>,
6038
- Values & { readonly [Region in Key]: NodeValue<Children[Key]> },
6039
- Constructed
6040
- >,
6041
- readonly [input: NodeMakeInput<Children[Key]>],
6042
- StateInitializeParallelBuilder<
6043
- Children,
6044
- Exclude<Remaining, Key>,
6045
- Values & { readonly [Region in Key]: NodeValue<Children[Key]> },
6046
- true
6047
- >
6048
- >
6049
- }
6050
-
6051
- /**
6052
- * Builder bound to the direct initial child or regions owned by a state.
6053
- *
6054
- * @category utility types
6055
- * @since 0.13.0
6056
- */
6057
- export type StateInitializeBuilder<
6058
- States extends StateSchemas,
6059
- StateId extends StateIdentifier<States>,
6060
- Node = NodeByIdentifier<States, StateId>
6061
- > = Node extends { readonly type: "parallel"; readonly states: infer Children extends StateSchemas } ?
6062
- StateInitializeParallelBuilder<Children>
6063
- : Node extends { readonly initial: infer Initial } ? StateInitializeCompoundBuilder<Node, Initial & PropertyKey>
6064
- : never
6065
-
6066
- /**
6067
- * Context passed to an implicit child-state initializer.
6068
- *
6069
- * @category models
6070
- * @since 0.13.0
6071
- */
6072
- export type StateInitializeContext<
6073
- States extends StateSchemas,
6074
- Events extends ReadonlyArray<TaggedSchema>,
6075
- Emits extends ReadonlyArray<TaggedSchema>,
6076
- StateId extends StateIdentifier<States>,
6077
- InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6078
- ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6079
- > = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
6080
- readonly builder: StateInitializeBuilder<States, StateId>
6081
- }
6082
-
6083
- /**
6084
- * Initial child value implementation for a compound or parallel state.
6085
- *
6086
- * @category models
6087
- * @since 0.13.0
6088
- */
6089
- export type StateInitializeHandler<
6090
- States extends StateSchemas,
6091
- Events extends ReadonlyArray<TaggedSchema>,
6092
- Emits extends ReadonlyArray<TaggedSchema>,
6093
- StateId extends StateIdentifier<States>,
6094
- InputEvents extends ReadonlyArray<TaggedSchema> = Events,
6095
- ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []
6096
- > = (
6097
- context: StateInitializeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>,
6098
- enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>
6099
- ) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>
6100
-
6101
5711
  /** Context used only when a history node has no previously captured record. */
6102
5712
  export interface HistoryDefaultContext<
6103
5713
  in out States extends StateSchemas,
@@ -6186,13 +5796,12 @@ export declare namespace Machine {
6186
5796
  readonly on?: never
6187
5797
  readonly onDone?: never
6188
5798
  readonly output?: never
6189
- readonly initialize?: never
6190
5799
  }
6191
5800
 
6192
5801
  type HandlerChildren<Node> = Node extends { readonly states: infer Children extends StateSchemas } ? Children : never
6193
5802
 
6194
5803
  type HandlerConfigPart<Config> = {
6195
- readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key]
5804
+ readonly [Key in keyof Config as Key extends "states" | "initial" | "root" ? never : Key]: Config[Key]
6196
5805
  }
6197
5806
 
6198
5807
  type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ?
@@ -6239,7 +5848,8 @@ export declare namespace Machine {
6239
5848
  | "entry"
6240
5849
  | "exit"
6241
5850
  | "history"
6242
- | "initialize"
5851
+ | "initial"
5852
+ | "root"
6243
5853
  | "invoke"
6244
5854
  | "on"
6245
5855
  | "onDone"
@@ -6443,9 +6053,9 @@ export declare namespace Machine {
6443
6053
  Config
6444
6054
  > = [HistoryIdentifier<AllStates>] extends [never] ? unknown
6445
6055
  : StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ?
6446
- "initialize" extends keyof Config ? unknown : {
6447
- readonly initialize: HandlerValidationError<
6448
- "State requires initialize for shallow history restoration",
6056
+ "initial" extends keyof Config ? unknown : {
6057
+ readonly initial: HandlerValidationError<
6058
+ "State requires an initial declaration for shallow history restoration",
6449
6059
  StateId
6450
6060
  >
6451
6061
  }
@@ -6470,6 +6080,7 @@ export declare namespace Machine {
6470
6080
  & HandlerChildrenValidation<Node, StateId, Config>
6471
6081
  & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config>
6472
6082
  & HandlerRequiredHistoryInitializeValidation<AllStates, StateId, Config>
6083
+ & ValidateConstructionDeclarations<Node, Config>
6473
6084
  & HandlerRuntimeValidation<Events, Emits, StateId, Config>
6474
6085
  : unknown
6475
6086
 
@@ -6518,7 +6129,7 @@ export declare namespace Machine {
6518
6129
  Required extends string ?
6519
6130
  HandlerConfigAtPath<{ readonly "": Config }, Required> extends infer NodeConfig ?
6520
6131
  [NodeConfig] extends [never] ? RootInitializeError<Required>
6521
- : "initialize" extends keyof NodeConfig ? never
6132
+ : "initial" extends keyof NodeConfig ? never
6522
6133
  : RootInitializeError<Required>
6523
6134
  : never :
6524
6135
  unknown
@@ -6540,53 +6151,71 @@ export declare namespace Machine {
6540
6151
  }>
6541
6152
  }
6542
6153
 
6543
- type RootHandlerValidation<
6154
+ type HandlerTreeValidation<
6544
6155
  States extends StateSchemas,
6156
+ Node,
6545
6157
  Events extends ReadonlyArray<TaggedSchema>,
6546
6158
  InputEvents extends ReadonlyArray<TaggedSchema>,
6547
6159
  Emits extends ReadonlyArray<TaggedSchema>,
6160
+ Path extends StateNodeIdentifier<States>,
6548
6161
  Config,
6549
6162
  OutputStates extends StateIdentifier<States>
6550
6163
  > =
6551
6164
  & HandlerNodeValidation<
6552
6165
  States,
6553
- States[""],
6166
+ Node,
6554
6167
  Events,
6555
6168
  InputEvents,
6556
6169
  Emits,
6557
- Extract<"", StateNodeIdentifier<States>>,
6170
+ Path,
6558
6171
  Config,
6559
6172
  OutputStates
6560
6173
  >
6561
- & RootInitialTargetValidation<States, Config>
6562
- & Types.UnionToIntersection<
6563
- Exclude<StateNodeIdentifier<States>, ""> extends infer Path ?
6564
- Path extends StateNodeIdentifier<States> ?
6565
- HandlerConfigAtPath<{ readonly "": Config }, Path> extends infer NodeConfig ?
6566
- [NodeConfig] extends [never] ? never :
6567
- HandlerNodeValidation<
6568
- States,
6569
- HandlerNodeByPath<States, Path>,
6570
- Events,
6571
- InputEvents,
6572
- Emits,
6573
- Path,
6574
- NodeConfig,
6575
- OutputStates
6576
- > extends infer Validation ? unknown extends Validation ? never
6577
- : { readonly states: HandlerValidationAtPath<Path, Validation> }
6578
- : never :
6579
- never :
6580
- never :
6581
- never
6582
- >
6174
+ & (Config extends { readonly states: infer Handlers }
6175
+ ? Node extends { readonly states: infer Children extends StateSchemas } ? {
6176
+ readonly states: {
6177
+ readonly [K in keyof Handlers]: K extends keyof Children ? HandlerTreeValidation<
6178
+ States,
6179
+ Children[K],
6180
+ Events,
6181
+ InputEvents,
6182
+ Emits,
6183
+ Extract<JoinPath<Path, Extract<K, string>>, StateNodeIdentifier<States>>,
6184
+ Handlers[K],
6185
+ OutputStates
6186
+ > :
6187
+ unknown
6188
+ }
6189
+ } :
6190
+ unknown
6191
+ : unknown)
6583
6192
 
6584
- type HandlerHasRequiredInitial<
6585
- AllStates extends StateSchemas,
6586
- StateId extends StateIdentifier<AllStates>,
6587
- Config
6588
- > = StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates>
6589
- ? "initialize" extends keyof Config ? true : false
6193
+ type RootHandlerValidation<
6194
+ States extends StateSchemas,
6195
+ Events extends ReadonlyArray<TaggedSchema>,
6196
+ InputEvents extends ReadonlyArray<TaggedSchema>,
6197
+ Emits extends ReadonlyArray<TaggedSchema>,
6198
+ Config,
6199
+ OutputStates extends StateIdentifier<States>
6200
+ > = HandlerTreeValidation<
6201
+ States,
6202
+ States[""],
6203
+ Events,
6204
+ InputEvents,
6205
+ Emits,
6206
+ Extract<"", StateNodeIdentifier<States>>,
6207
+ Config,
6208
+ OutputStates
6209
+ >
6210
+
6211
+ type HandlerHasRequiredInitial<
6212
+ Node,
6213
+ Config
6214
+ > = Node extends { readonly states: infer Children extends StateSchemas }
6215
+ ? Node extends { readonly type: "parallel" }
6216
+ ? HasRequiredActiveChild<Children> extends true ? "initial" extends keyof Config ? true : false : true
6217
+ : "initial" extends keyof Config ? true
6218
+ : false
6590
6219
  : true
6591
6220
 
6592
6221
  type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
@@ -6614,15 +6243,13 @@ export declare namespace Machine {
6614
6243
  Node,
6615
6244
  StateId extends StateIdentifier<AllStates>,
6616
6245
  Config
6617
- > = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates> | RequiredInitializers<AllStates>] extends [never] ?
6618
- StateId
6619
- : HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ?
6620
- HandlerHasRequiredHistoryDefaults<Node, Config> extends true ?
6621
- HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never
6622
- : never
6246
+ > = HandlerHasRequiredInitial<Node, Config> extends true ?
6247
+ HandlerHasRequiredHistoryDefaults<Node, Config> extends true ?
6248
+ HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never
6249
+ : never
6623
6250
  : never
6624
6251
 
6625
- type HandlerConfigError<Config> =
6252
+ type HandlerConfigError<Config> = Config extends unknown ? [keyof Config] extends [never] ? never :
6626
6253
  | Effect.Error<EventHandlerReturn<Config>>
6627
6254
  | Effect.Error<AlwaysReturn<Config>>
6628
6255
  | Effect.Error<DoneReturn<Config>>
@@ -6631,16 +6258,17 @@ export declare namespace Machine {
6631
6258
  | Effect.Error<HistoryDefaultReturn<Config>>
6632
6259
  | Effect.Error<ChoiceReturn<Config>>
6633
6260
  | InvokeError<Config>
6261
+ : never
6634
6262
 
6635
6263
  type HandlerNodeEvidence<
6636
6264
  AllStates extends StateSchemas,
6637
- Config,
6265
+ Node,
6638
6266
  StateId extends StateNodeIdentifier<AllStates>,
6639
- NodeConfig = HandlerConfigAtPath<Config, StateId>
6267
+ NodeConfig
6640
6268
  > = [NodeConfig] extends [never] ? never : {
6641
6269
  readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<
6642
6270
  AllStates,
6643
- HandlerNodeByPath<AllStates, StateId>,
6271
+ Node,
6644
6272
  StateId,
6645
6273
  NodeConfig
6646
6274
  >
@@ -6657,11 +6285,25 @@ export declare namespace Machine {
6657
6285
 
6658
6286
  // Compute every accumulated channel from one normalized node union instead
6659
6287
  // of repeating recursive walks for states, errors, services, and outputs.
6660
- type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends
6661
- infer StateId extends StateNodeIdentifier<AllStates> ?
6662
- StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId>
6663
- : never
6664
- : never
6288
+ type HandlerTreeEvidence<
6289
+ AllStates extends StateSchemas,
6290
+ Config,
6291
+ Nodes extends StateSchemas = AllStates,
6292
+ Prefix extends string = ""
6293
+ > = {
6294
+ readonly [K in Extract<keyof Config & keyof Nodes, string>]:
6295
+ | HandlerNodeEvidence<
6296
+ AllStates,
6297
+ Nodes[K],
6298
+ Extract<JoinPath<Prefix, K>, StateNodeIdentifier<AllStates>>,
6299
+ Config[K]
6300
+ >
6301
+ | (Nodes[K] extends { readonly states: infer Children extends StateSchemas }
6302
+ ? Config[K] extends { readonly states: infer Handlers }
6303
+ ? HandlerTreeEvidence<AllStates, Handlers, Children, JoinPath<Prefix, K>>
6304
+ : never
6305
+ : never)
6306
+ }[Extract<keyof Config & keyof Nodes, string>]
6665
6307
 
6666
6308
  type HandleTreeResult<
6667
6309
  AllStates extends StateSchemas,
@@ -6730,9 +6372,7 @@ export declare namespace Machine {
6730
6372
  Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never
6731
6373
  : unknown
6732
6374
  }
6733
- type ReferenceRoot<S extends StateSchemas> = "~effect/Machine/ExplicitInitial" extends keyof S[""]
6734
- ? Extract<Omit<S[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig>
6735
- : Extract<S[""], StateNodeConfig>
6375
+ type ReferenceRoot<S extends StateSchemas> = Extract<S[""], StateNodeConfig>
6736
6376
  type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = TargetReference<
6737
6377
  ReferenceRoot<S>,
6738
6378
  P,
@@ -6752,7 +6392,7 @@ export declare namespace Machine {
6752
6392
  }
6753
6393
  & (
6754
6394
  | {
6755
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6395
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6756
6396
  readonly target: ReferenceUnion<S, DestinationPath<S>>
6757
6397
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6758
6398
  readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>
@@ -6766,7 +6406,7 @@ export declare namespace Machine {
6766
6406
  | {
6767
6407
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6768
6408
  readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>
6769
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6409
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6770
6410
  readonly target?: never
6771
6411
  /** Enters a compound or parallel subtree through its declared initialization. */
6772
6412
  readonly initial?: never
@@ -6778,7 +6418,7 @@ export declare namespace Machine {
6778
6418
  | {
6779
6419
  /** Enters a compound or parallel subtree through its declared initialization. */
6780
6420
  readonly initial: ReferenceUnion<S, Exclude<ObjectCompoundPath<S>, "">>
6781
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6421
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6782
6422
  readonly target?: never
6783
6423
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6784
6424
  readonly update?: never
@@ -6790,7 +6430,7 @@ export declare namespace Machine {
6790
6430
  | {
6791
6431
  /** Restores the declared history reference, using its fallback on first entry. */
6792
6432
  readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
6793
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6433
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6794
6434
  readonly target?: never
6795
6435
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6796
6436
  readonly update?: never
@@ -6802,7 +6442,7 @@ export declare namespace Machine {
6802
6442
  | {
6803
6443
  /** Accepts the event without selecting a new destination. */
6804
6444
  readonly none: true
6805
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6445
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6806
6446
  readonly target?: never
6807
6447
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6808
6448
  readonly update?: never
@@ -6841,7 +6481,7 @@ export declare namespace Machine {
6841
6481
  >
6842
6482
  type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never
6843
6483
  type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D> = D extends {
6844
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6484
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6845
6485
  readonly target: infer Ref
6846
6486
  } ? RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ? D extends {
6847
6487
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
@@ -6930,7 +6570,7 @@ export declare namespace Machine {
6930
6570
  type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
6931
6571
  readonly [P in DestinationPath<S>]:
6932
6572
  & {
6933
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6573
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6934
6574
  readonly target: ReferenceAt<S, P>
6935
6575
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6936
6576
  readonly update?: never
@@ -6963,7 +6603,7 @@ export declare namespace Machine {
6963
6603
  readonly [K in M]: (
6964
6604
  context: C
6965
6605
  ) => {
6966
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6606
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6967
6607
  readonly target: BuilderArgs<BranchBuilderAt<S, Src, P>, M>[0]
6968
6608
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6969
6609
  readonly update: BuilderArgs<StateUpdateBuilder<S, Owner>, M>[0]
@@ -6998,7 +6638,7 @@ export declare namespace Machine {
6998
6638
  readonly [P in DestinationPath<S>]: {
6999
6639
  readonly [Owner in Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>]:
7000
6640
  & {
7001
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6641
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
7002
6642
  readonly target: ReferenceAt<S, P>
7003
6643
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
7004
6644
  readonly update: ReferenceAt<S, Owner>
@@ -7027,7 +6667,7 @@ export declare namespace Machine {
7027
6667
  readonly reenter?: P extends Src ? never : boolean
7028
6668
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
7029
6669
  readonly update: ReferenceAt<S, P>
7030
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6670
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
7031
6671
  readonly target?: never
7032
6672
  /** Enters a compound or parallel subtree through its declared initialization. */
7033
6673
  readonly initial?: never
@@ -7051,7 +6691,7 @@ export declare namespace Machine {
7051
6691
  & {
7052
6692
  /** Enters a compound or parallel subtree through its declared initialization. */
7053
6693
  readonly initial: ReferenceAt<S, P>
7054
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6694
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
7055
6695
  readonly target?: never
7056
6696
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
7057
6697
  readonly update?: never
@@ -7071,7 +6711,7 @@ export declare namespace Machine {
7071
6711
  }[Exclude<ObjectCompoundPath<S>, "">]
7072
6712
  type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
7073
6713
  readonly [K in Extract<keyof Group, string>]: {
7074
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6714
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
7075
6715
  readonly target: SelectionOf<S, Src, Group[K]>
7076
6716
  }
7077
6717
  }
@@ -7112,7 +6752,7 @@ export declare namespace Machine {
7112
6752
  & {
7113
6753
  /** Named groups of inspectable destinations used by transition resolvers. */
7114
6754
  readonly branches: K
7115
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
6755
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
7116
6756
  readonly target?: never
7117
6757
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
7118
6758
  readonly update?: never
@@ -7134,6 +6774,13 @@ export declare namespace Machine {
7134
6774
  readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K]>, true>
7135
6775
  }
7136
6776
  }[Extract<keyof Registered<R, "branches">, string>]
6777
+ type DataValue<C, A> = A | ((context: C) => A)
6778
+ type DeclarationData<T> = T extends { readonly from: (context: infer C) => infer A }
6779
+ ? Omit<T, "from" | "decoded"> & { readonly data: DataValue<C, A>; readonly decoded?: false }
6780
+ : T extends { readonly decoded: (context: infer C) => infer A }
6781
+ ? Omit<T, "from" | "decoded"> & { readonly data: DataValue<C, A>; readonly decoded: true }
6782
+ : T extends unknown ? Omit<T, "from" | "decoded"> & { readonly data?: never; readonly decoded?: never }
6783
+ : never
7137
6784
  /**
7138
6785
  * A transition with an inspectable destination and source-specific construction.
7139
6786
  *
@@ -7151,60 +6798,62 @@ export declare namespace Machine {
7151
6798
  Acceptance extends TransitionAcceptance = "required"
7152
6799
  > =
7153
6800
  & ObjectPolicy<C, Reenter, Acceptance>
7154
- & (
7155
- | InlineDestination<S, Src, C>
7156
- | InlineUpdate<S, Src, C>
7157
- | InlineCombined<S, Src, C>
7158
- | InlineInitial<S, Src, C>
7159
- | {
7160
- /** Restores the declared history reference, using its fallback on first entry. */
7161
- readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
7162
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
7163
- readonly target?: never
7164
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
7165
- readonly update?: never
7166
- /** Enters a compound or parallel subtree through its declared initialization. */
7167
- readonly initial?: never
7168
- /** Accepts the event without selecting a new destination. */
7169
- readonly none?: never
7170
- /** Named groups of inspectable destinations used by transition resolvers. */
7171
- readonly branches?: never
7172
- /** Selects one declared branch and may enqueue synchronous commands. */
7173
- readonly resolve?: never
7174
- /** Constructs schema make input from the typed source context. */
7175
- readonly from?: never
7176
- /** Supplies an already decoded schema value from the typed source context. */
7177
- readonly decoded?: never
7178
- /** Set to true when the resolver can explicitly return decline(). */
7179
- readonly declinable?: never
7180
- }
7181
- | (Src extends ChoiceIdentifier<S> ? never : {
7182
- /** Accepts the event without selecting a new destination. */
7183
- readonly none: true
7184
- /** Selects the declared descendant destination. Supply required values with from or decoded. */
7185
- readonly target?: never
7186
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
7187
- readonly update?: never
7188
- /** Enters a compound or parallel subtree through its declared initialization. */
7189
- readonly initial?: never
7190
- /** Restores the declared history reference, using its fallback on first entry. */
7191
- readonly history?: never
7192
- /** Named groups of inspectable destinations used by transition resolvers. */
7193
- readonly branches?: never
7194
- /** Constructs schema make input from the typed source context. */
7195
- readonly from?: never
7196
- /** Supplies an already decoded schema value from the typed source context. */
7197
- readonly decoded?: never
7198
- /** Set to true when the resolver can explicitly return decline(). */
7199
- readonly declinable?: "declinable" extends Acceptance ? boolean : false
7200
- /** Selects one declared branch and may enqueue synchronous commands. */
7201
- readonly resolve?: (
7202
- context: C & DeclineCapability,
7203
- enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>
7204
- ) => undefined | Declined
7205
- })
7206
- | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>
7207
- )
6801
+ & DeclarationData<
6802
+ (
6803
+ | InlineDestination<S, Src, C>
6804
+ | InlineUpdate<S, Src, C>
6805
+ | InlineCombined<S, Src, C>
6806
+ | InlineInitial<S, Src, C>
6807
+ | {
6808
+ /** Restores the declared history reference, using its fallback on first entry. */
6809
+ readonly history: ReferenceUnion<S, HistoryIdentifier<S>>
6810
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6811
+ readonly target?: never
6812
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6813
+ readonly update?: never
6814
+ /** Enters a compound or parallel subtree through its declared initialization. */
6815
+ readonly initial?: never
6816
+ /** Accepts the event without selecting a new destination. */
6817
+ readonly none?: never
6818
+ /** Named groups of inspectable destinations used by transition resolvers. */
6819
+ readonly branches?: never
6820
+ /** Selects one declared branch and may enqueue synchronous commands. */
6821
+ readonly resolve?: never
6822
+ /** Constructs schema make input from the typed source context. */
6823
+ readonly from?: never
6824
+ /** Supplies an already decoded schema value from the typed source context. */
6825
+ readonly decoded?: never
6826
+ /** Set to true when the resolver can explicitly return decline(). */
6827
+ readonly declinable?: never
6828
+ }
6829
+ | (Src extends ChoiceIdentifier<S> ? never : {
6830
+ /** Accepts the event without selecting a new destination. */
6831
+ readonly none: true
6832
+ /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
6833
+ readonly target?: never
6834
+ /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
6835
+ readonly update?: never
6836
+ /** Enters a compound or parallel subtree through its declared initialization. */
6837
+ readonly initial?: never
6838
+ /** Restores the declared history reference, using its fallback on first entry. */
6839
+ readonly history?: never
6840
+ /** Named groups of inspectable destinations used by transition resolvers. */
6841
+ readonly branches?: never
6842
+ /** Constructs schema make input from the typed source context. */
6843
+ readonly from?: never
6844
+ /** Supplies an already decoded schema value from the typed source context. */
6845
+ readonly decoded?: never
6846
+ /** Set to true when the resolver can explicitly return decline(). */
6847
+ readonly declinable?: "declinable" extends Acceptance ? boolean : false
6848
+ /** Selects one declared branch and may enqueue synchronous commands. */
6849
+ readonly resolve?: (
6850
+ context: C & DeclineCapability,
6851
+ enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>
6852
+ ) => undefined | Declined
6853
+ })
6854
+ | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>
6855
+ )
6856
+ >
7208
6857
  type SourceValue<R, K extends PropertyKey> = {
7209
6858
  readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind>
7210
6859
  ? Registered<R, Kind>[K]
@@ -7388,6 +7037,128 @@ export declare namespace Machine {
7388
7037
  : {})
7389
7038
  >
7390
7039
  }[Extract<SourceKeys<R>, string>]
7040
+ type OrdinaryData<A> = A extends unknown ?
7041
+ & A
7042
+ & (
7043
+ | { readonly decoded?: false | undefined }
7044
+ | { readonly data?: never }
7045
+ ) :
7046
+ never
7047
+ type ShortConstruction<C, Node> = [NodeSchema<Node>] extends [never] ? never
7048
+ : OrdinaryData<NodeMakeInput<Node>> | ((context: C) => NodeMakeInput<Node>) | {
7049
+ readonly decoded: true
7050
+ readonly data: DataValue<C, NodeValue<Node>>
7051
+ }
7052
+ type InitialData<C, Node> = [NodeSchema<Node>] extends [never] ? { readonly data?: never; readonly decoded?: never }
7053
+ :
7054
+ | (
7055
+ & { readonly decoded?: false }
7056
+ & ({} extends NodeMakeInput<Node> ? { readonly data?: DataValue<C, NodeMakeInput<Node>> }
7057
+ : { readonly data: DataValue<C, NodeMakeInput<Node>> })
7058
+ )
7059
+ | { readonly decoded: true; readonly data: DataValue<C, NodeValue<Node>> }
7060
+ type InitialEdge<S extends StateSchemas, Node, Src extends StateNodeIdentifier<S>, C> = Node extends
7061
+ { readonly states: infer Children extends StateSchemas } ? {
7062
+ readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]:
7063
+ & {
7064
+ readonly target: TargetReference<
7065
+ ReferenceRoot<S>,
7066
+ JoinPath<Src, K>,
7067
+ Children[K] extends ChoiceStateNodeConfig ? "choice" : "state"
7068
+ >
7069
+ }
7070
+ & InitialData<C, Children[K]>
7071
+ }[ActiveStateKey<Children> | ChoiceStateKey<Children>]
7072
+ : never
7073
+ type InitialRegions<C, Children extends StateSchemas> =
7074
+ & { readonly [K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? K : never]?: never }
7075
+ & {
7076
+ readonly [
7077
+ K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? never
7078
+ : {} extends NodeMakeInput<Children[K]> ? never
7079
+ : K
7080
+ ]: ShortConstruction<C, Children[K]>
7081
+ }
7082
+ & {
7083
+ readonly [
7084
+ K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? never
7085
+ : {} extends NodeMakeInput<Children[K]> ? K
7086
+ : never
7087
+ ]?: ShortConstruction<C, Children[K]>
7088
+ }
7089
+ type RequiresInitialHandler<Node> = Node extends { readonly states: StateSchemas } ? true : false
7090
+ type ChildHandlerMap<
7091
+ S extends StateSchemas,
7092
+ Children extends StateSchemas,
7093
+ Ev extends ReadonlyArray<TaggedSchema>,
7094
+ Em extends ReadonlyArray<TaggedSchema>,
7095
+ Src extends StateNodeIdentifier<S>,
7096
+ In extends ReadonlyArray<TaggedSchema>,
7097
+ Pa extends ReadonlyArray<TaggedSchema>,
7098
+ R
7099
+ > =
7100
+ & {
7101
+ readonly [
7102
+ K in ActiveStateKey<Children> | ChoiceStateKey<Children> as RequiresInitialHandler<Children[K]> extends true ? K
7103
+ : never
7104
+ ]: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>
7105
+ }
7106
+ & {
7107
+ readonly [
7108
+ K in ActiveStateKey<Children> | ChoiceStateKey<Children> as RequiresInitialHandler<Children[K]> extends true
7109
+ ? never
7110
+ : K
7111
+ ]?: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>
7112
+ }
7113
+ type ChildHandlers<
7114
+ S extends StateSchemas,
7115
+ Children extends StateSchemas,
7116
+ Ev extends ReadonlyArray<TaggedSchema>,
7117
+ Em extends ReadonlyArray<TaggedSchema>,
7118
+ Src extends StateNodeIdentifier<S>,
7119
+ In extends ReadonlyArray<TaggedSchema>,
7120
+ Pa extends ReadonlyArray<TaggedSchema>,
7121
+ R
7122
+ > = [
7123
+ {
7124
+ [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: RequiresInitialHandler<Children[K]> extends true ? K
7125
+ : never
7126
+ }[ActiveStateKey<Children> | ChoiceStateKey<Children>]
7127
+ ] extends [never] ? { readonly states?: ChildHandlerMap<S, Children, Ev, Em, Src, In, Pa, R> }
7128
+ : { readonly states: ChildHandlerMap<S, Children, Ev, Em, Src, In, Pa, R> }
7129
+ type InitialHandler<S extends StateSchemas, Node, Src extends StateNodeIdentifier<S>, C> = Node extends
7130
+ { readonly type: "parallel"; readonly states: infer Children extends StateSchemas }
7131
+ ? {} extends InitialRegions<C, Children> ? { readonly initial?: InitialRegions<C, Children> }
7132
+ : { readonly initial: InitialRegions<C, Children> }
7133
+ : Node extends { readonly states: StateSchemas } ? { readonly initial: InitialEdge<S, Node, Src, C> }
7134
+ : { readonly initial?: never }
7135
+ type RootConstruction<Node, Input> = [NodeSchema<Node>] extends [never] ?
7136
+ { /** Root-owned data is available only when the root declares a schema. */ readonly root?: never }
7137
+ : {} extends NodeMakeInput<Node> ? {
7138
+ /** Constructs root-owned data once from startup input. */ readonly root?: ShortConstruction<
7139
+ { readonly input: Input },
7140
+ Node
7141
+ >
7142
+ }
7143
+ : {
7144
+ /** Constructs root-owned data once from startup input. */ readonly root: ShortConstruction<
7145
+ { readonly input: Input },
7146
+ Node
7147
+ >
7148
+ }
7149
+ type ExactConstruction<C> = C extends { readonly decoded: true; readonly data: unknown }
7150
+ ? { readonly [K in Exclude<keyof C, "decoded" | "data">]: never }
7151
+ : unknown
7152
+ type ValidateInitialDeclaration<Node, C> = Node extends {
7153
+ readonly type: "parallel"
7154
+ readonly states: infer Children extends StateSchemas
7155
+ } ? { readonly [K in keyof C]: K extends ActiveStateKey<Children> ? ExactConstruction<C[K]> : never }
7156
+ : { readonly [K in Exclude<keyof C, "target" | "data" | "decoded">]: never }
7157
+ type ValidateConstructionDeclarations<Node, C> = {
7158
+ readonly [K in Extract<keyof C, "root" | "initial">]: K extends "root" ? ExactConstruction<C[K]>
7159
+ : K extends "initial" ? ValidateInitialDeclaration<Node, C[K]>
7160
+ : unknown
7161
+ }
7391
7162
  type ObjectLifecycle<
7392
7163
  S extends StateSchemas,
7393
7164
  Node,
@@ -7407,8 +7178,7 @@ export declare namespace Machine {
7407
7178
  & (Node extends { readonly type: "final" } ?
7408
7179
  & {
7409
7180
  /** Runs synchronously on exit and may enqueue commands. */
7410
- readonly exit?: never /** Constructs required values for the declared initial child or parallel regions. */
7411
- readonly initialize?: never
7181
+ readonly exit?: never
7412
7182
  }
7413
7183
  & OutputHandlerConfig<S, Ev, Src, FinalOutputContext<S, Ev, Src>>
7414
7184
  : {
@@ -7417,14 +7187,11 @@ export declare namespace Machine {
7417
7187
  context: StateActionContext<S, Ev, Em, Src, In, Pa>,
7418
7188
  enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>
7419
7189
  ) => StateActionResult<any, any>
7420
- /** Constructs required values for the declared initial child or parallel regions. */
7421
- readonly initialize?: StateInitializeHandler<S, Ev, Em, Src, In, Pa>
7422
7190
  } & ActiveOutputHandlerConfig<S, Ev, Src>)
7423
7191
  : {
7424
7192
  /** Runs synchronously on entry and may enqueue commands. */
7425
7193
  readonly entry?: never /** Runs synchronously on exit and may enqueue commands. */
7426
- readonly exit?: never /** Constructs required values for the declared initial child or parallel regions. */
7427
- readonly initialize?: never /** Constructs the decoded output declared by the state schema. */
7194
+ readonly exit?: never /** Constructs the decoded output declared by the state schema. */
7428
7195
  readonly output?: never
7429
7196
  }
7430
7197
  /**
@@ -7444,6 +7211,15 @@ export declare namespace Machine {
7444
7211
  R
7445
7212
  > =
7446
7213
  & ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa>
7214
+ & InitialHandler<
7215
+ S,
7216
+ Node,
7217
+ Src,
7218
+ StateActionContext<S, Ev, Em, Extract<Src, StateIdentifier<S>>, In, Pa> & {
7219
+ /** Root-owned data constructed before initial descendant values. */
7220
+ readonly root: StateByIdentifier<S, Extract<"", StateIdentifier<S>>>
7221
+ }
7222
+ >
7447
7223
  & (Src extends ChoiceIdentifier<S> ? {
7448
7224
  /** Required total transition for a transient choice state. */
7449
7225
  readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>
@@ -7528,21 +7304,9 @@ export declare namespace Machine {
7528
7304
  readonly states: infer Children extends StateSchemas
7529
7305
  } ? {
7530
7306
  /** Child handlers nested according to the declared root topology. */
7531
- readonly states?: {
7532
- readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]?: StateHandler<
7533
- S,
7534
- Children[K],
7535
- Ev,
7536
- Em,
7537
- Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>,
7538
- In,
7539
- Pa,
7540
- R
7541
- >
7542
- }
7543
7307
  /** Restores the declared history reference, using its fallback on first entry. */
7544
7308
  readonly history?: HistoryDefaultConfig<S, Ev, Em, Src, Children>
7545
- } :
7309
+ } & ChildHandlers<S, Children, Ev, Em, Src, In, Pa, R> :
7546
7310
  {
7547
7311
  /** Child handlers nested according to the declared root topology. */
7548
7312
  readonly states?: never /** Restores the declared history reference, using its fallback on first entry. */
@@ -7560,7 +7324,7 @@ export declare namespace Machine {
7560
7324
  | "history"
7561
7325
  | "none"
7562
7326
  | "branches"
7563
- | "from"
7327
+ | "data"
7564
7328
  | "decoded"
7565
7329
  | "resolve"
7566
7330
  | "guard"
@@ -7670,9 +7434,12 @@ export declare namespace Machine {
7670
7434
  config:
7671
7435
  & C
7672
7436
  & (C extends (...args: never[]) => unknown ? never : unknown)
7673
- & ([Ev[number] | keyof Registered<R, "branches"> | SourceKeys<R>] extends [never]
7674
- ? StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R>
7675
- : HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R>>)
7437
+ & HandlerShape<
7438
+ C,
7439
+ & StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R>
7440
+ & RootConstruction<S[""], I["Type"]>
7441
+ >
7442
+ & RootConstruction<S[""], I["Type"]>
7676
7443
  & ValidateObjectConfig<NoInfer<C>, R>
7677
7444
  & RootHandlerValidation<
7678
7445
  S,
@@ -7941,24 +7708,23 @@ export const isFinal: <
7941
7708
  ) => state is Machine.SnapshotContainingFinal<States, FinalStates> = internal.isFinal as any
7942
7709
 
7943
7710
  /**
7944
- * Defines one reusable active state while preserving its exact child topology.
7711
+ * Defines root or nested state schemas while preserving the exact child topology.
7945
7712
  *
7946
- * Prefer declaring state nodes inline in {@link states}. Use this constructor
7947
- * only when the same state definition is mounted more than once.
7948
- * Tagged schemas are already reusable and do not need this constructor.
7713
+ * Pass the root descriptor to {@link make} and {@link targets}. Nested states
7714
+ * can be declared inline or reused by mounting a descriptor in multiple places.
7715
+ * Initial edges and value constructors belong in the handler tree.
7949
7716
  *
7950
7717
  * **Example** (Repeated compound state)
7951
7718
  *
7952
7719
  * ```ts
7953
- * import { Schema } from "effect"
7954
7720
  * import { Machine } from "@typeonce/effect-machine"
7721
+ * import { Schema } from "effect"
7955
7722
  *
7956
7723
  * const TradingState = Schema.TaggedUnion({
7957
7724
  * InSession: {},
7958
7725
  * Applying: {}
7959
7726
  * })
7960
7727
  * const TradingSlot = Machine.state({
7961
- * initial: "Idle",
7962
7728
  * states: {
7963
7729
  * Idle: {},
7964
7730
  * InSession: TradingState.cases.InSession,
@@ -7966,10 +7732,12 @@ export const isFinal: <
7966
7732
  * }
7967
7733
  * })
7968
7734
  *
7969
- * const States = Machine.state({ initial: "slot1", states: {
7970
- * slot1: TradingSlot,
7971
- * slot2: TradingSlot
7972
- * } })
7735
+ * const States = Machine.state({
7736
+ * states: {
7737
+ * slot1: TradingSlot,
7738
+ * slot2: TradingSlot
7739
+ * }
7740
+ * })
7973
7741
  * ```
7974
7742
  *
7975
7743
  * @category constructors
@@ -8142,83 +7910,8 @@ type MakeResult<
8142
7910
  }
8143
7911
  >
8144
7912
 
8145
- type RootInitialization<Root extends Machine.StateNodeConfig, Input> =
8146
- & { readonly initialConfiguration?: never }
8147
- & (Machine.NodeSchema<Root> extends never ? {
8148
- /** Enters a compound or parallel subtree through its declared initialization. */
8149
- readonly initial?: Machine.RootInitialBuilderInput<Root, Input>
8150
- }
8151
- : {} extends NodeMakeInput<Root> ? {
8152
- /** Enters a compound or parallel subtree through its declared initialization. */
8153
- readonly initial?: Machine.RootInitialBuilderInput<Root, Input>
8154
- }
8155
- : {
8156
- /** Enters a compound or parallel subtree through its declared initialization. */
8157
- readonly initial: Machine.RootInitialBuilderInput<Root, Input>
8158
- })
8159
-
8160
7913
  /** @inline */
8161
7914
  interface Make {
8162
- /** @param config Complete starting configuration, including root and descendant values. */
8163
- <
8164
- const Root extends Machine.StateNodeConfig,
8165
- const InputEvents extends ReadonlyArray<Machine.TaggedSchema>,
8166
- const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8167
- const Input extends Schema.Top = typeof Schema.Void,
8168
- InitialE = never,
8169
- InitialR = never,
8170
- const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [],
8171
- const ParentDeclaration extends Parent.Any | undefined = undefined,
8172
- const Effects extends Machine.EffectSources = {},
8173
- const Streams extends Machine.StreamSources = {},
8174
- const Timers extends Machine.TimerSources = {},
8175
- const Logics extends Machine.LogicSources = {},
8176
- const Children extends Machine.ChildSources = {},
8177
- const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}
8178
- >(
8179
- config:
8180
- & MakeConfig<
8181
- Root,
8182
- InputEvents,
8183
- Emits,
8184
- Input,
8185
- InitialE,
8186
- InitialR,
8187
- InternalEvents,
8188
- ParentDeclaration,
8189
- Effects,
8190
- Streams,
8191
- Timers,
8192
- Logics,
8193
- Children,
8194
- Branches
8195
- >
8196
- & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>
8197
- & {
8198
- /** Mutually exclusive with a complete initial configuration. */
8199
- readonly initial?: never
8200
- /** Constructs the complete initial root configuration, overriding child defaults. */
8201
- readonly initialConfiguration: Machine.RootConfigurationBuilderInput<
8202
- NoInfer<Root>,
8203
- Input["Type"]
8204
- >
8205
- }
8206
- ): MakeResult<
8207
- Root & { readonly "~effect/Machine/ExplicitInitial": true },
8208
- InputEvents,
8209
- Emits,
8210
- Input,
8211
- InitialE,
8212
- InitialR,
8213
- InternalEvents,
8214
- ParentDeclaration,
8215
- Effects,
8216
- Streams,
8217
- Timers,
8218
- Logics,
8219
- Children,
8220
- Branches
8221
- >
8222
7915
  /** @param config Complete schema-first machine definition. */
8223
7916
  <
8224
7917
  const Root extends Machine.StateNodeConfig,
@@ -8254,10 +7947,6 @@ interface Make {
8254
7947
  Branches
8255
7948
  >
8256
7949
  & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>
8257
- & Exclude<
8258
- RootInitialization<NoInfer<Root>, Input["Type"]>,
8259
- { readonly initialConfiguration: unknown }
8260
- >
8261
7950
  ): MakeResult<
8262
7951
  Root,
8263
7952
  InputEvents,
@@ -8304,35 +7993,40 @@ interface Make {
8304
7993
  * **Example** (Typed counter machine)
8305
7994
  *
8306
7995
  * ```ts
8307
- * import { Schema } from "effect"
8308
7996
  * import { Machine } from "@typeonce/effect-machine"
8309
- *
7997
+ * import { Schema } from "effect"
8310
7998
  * class Count extends Schema.TaggedClass<Count>("Count")("Count", {
8311
7999
  * value: Schema.Number
8312
- * }) {}
8313
- *
8000
+ * }) {
8001
+ * }
8314
8002
  * class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
8315
8003
  * by: Schema.Number
8316
- * }) {}
8317
- *
8318
- * const States = Machine.state({ initial: "Count", states: { Count } })
8004
+ * }) {
8005
+ * }
8006
+ * const States = Machine.state({ states: { Count } })
8319
8007
  * const Events = Machine.eventsFromSchemas(Increment)
8320
8008
  * const targets = Machine.targets(States)
8321
- *
8322
8009
  * const counter = Machine.make({
8323
8010
  * root: States,
8324
- * events: Events,
8325
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Count.decoded(new Count({ value: 0 }))))
8326
- * }).handle({ states: {
8327
- * Count: {
8328
- * on: {
8329
- * Increment: {
8330
- * update: targets.root.Count,
8331
- * decoded: ({ event, state }) => new Count({ value: state.value + event.by })
8011
+ * events: Events
8012
+ * }).handle({
8013
+ * initial: {
8014
+ * target: Machine.targets(States).root.Count,
8015
+ * decoded: true,
8016
+ * data: new Count({ value: 0 })
8017
+ * },
8018
+ * states: {
8019
+ * Count: {
8020
+ * on: {
8021
+ * Increment: {
8022
+ * update: targets.root.Count,
8023
+ * decoded: true,
8024
+ * data: ({ event, state }) => new Count({ value: state.value + event.by })
8025
+ * }
8332
8026
  * }
8333
8027
  * }
8334
8028
  * }
8335
- * } })
8029
+ * })
8336
8030
  * ```
8337
8031
  *
8338
8032
  * @see {@link state} for typed state-tree helpers.
@@ -8553,17 +8247,22 @@ export const emittedEventsFromSchemas: {
8553
8247
  * **Example**
8554
8248
  *
8555
8249
  * ```ts
8556
- * import { Effect, Schema } from "effect"
8557
8250
  * import { Machine } from "@typeonce/effect-machine"
8558
- *
8559
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
8560
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
8251
+ * import { Effect, Schema } from "effect"
8252
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
8253
+ * }
8254
+ * const States = Machine.state({ states: { Idle } })
8561
8255
  * const machine = Machine.make({
8562
8256
  * root: States,
8563
- * events: Machine.eventsFromSchemas(),
8564
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
8565
- * }).handle({ states: { Idle: {} } })
8566
- *
8257
+ * events: Machine.eventsFromSchemas()
8258
+ * }).handle({
8259
+ * initial: {
8260
+ * target: Machine.targets(States).root.Idle
8261
+ * },
8262
+ * states: {
8263
+ * Idle: {}
8264
+ * }
8265
+ * })
8567
8266
  * const encoded = Effect.gen(function*() {
8568
8267
  * const initial = yield* Machine.planInitial(machine)
8569
8268
  * return yield* Machine.encodeSnapshot(machine, initial.state)
@@ -8635,17 +8334,22 @@ export const encodeSnapshot: <
8635
8334
  * **Example**
8636
8335
  *
8637
8336
  * ```ts
8638
- * import { Effect, Schema } from "effect"
8639
8337
  * import { Machine } from "@typeonce/effect-machine"
8640
- *
8641
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
8642
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
8338
+ * import { Effect, Schema } from "effect"
8339
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
8340
+ * }
8341
+ * const States = Machine.state({ states: { Idle } })
8643
8342
  * const machine = Machine.make({
8644
8343
  * root: States,
8645
- * events: Machine.eventsFromSchemas(),
8646
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
8647
- * }).handle({ states: { Idle: {} } })
8648
- *
8344
+ * events: Machine.eventsFromSchemas()
8345
+ * }).handle({
8346
+ * initial: {
8347
+ * target: Machine.targets(States).root.Idle
8348
+ * },
8349
+ * states: {
8350
+ * Idle: {}
8351
+ * }
8352
+ * })
8649
8353
  * const roundTrip = Effect.gen(function*() {
8650
8354
  * const initial = yield* Machine.planInitial(machine)
8651
8355
  * const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
@@ -8743,17 +8447,22 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
8743
8447
  * **Example**
8744
8448
  *
8745
8449
  * ```ts
8746
- * import { Effect, Schema } from "effect"
8747
8450
  * import { Machine } from "@typeonce/effect-machine"
8748
- *
8749
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
8750
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
8451
+ * import { Effect, Schema } from "effect"
8452
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
8453
+ * }
8454
+ * const States = Machine.state({ states: { Idle } })
8751
8455
  * const machine = Machine.make({
8752
8456
  * root: States,
8753
- * events: Machine.eventsFromSchemas(),
8754
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
8755
- * }).handle({ states: { Idle: {} } })
8756
- *
8457
+ * events: Machine.eventsFromSchemas()
8458
+ * }).handle({
8459
+ * initial: {
8460
+ * target: Machine.targets(States).root.Idle
8461
+ * },
8462
+ * states: {
8463
+ * Idle: {}
8464
+ * }
8465
+ * })
8757
8466
  * const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
8758
8467
  * ```
8759
8468
  *
@@ -9032,12 +8741,15 @@ export const enabled: <
9032
8741
  * import { Effect, Schema } from "effect"
9033
8742
  *
9034
8743
  * const internalEvents = Machine.internalEventsFromSchemas(Schema.TaggedStruct("Loaded", {}))
8744
+ * const Root = Machine.state({ states: { Idle: {} } })
9035
8745
  * const machine = Machine.make({
9036
- * root: Machine.state({ initial: "Idle", states: { Idle: {} } }),
8746
+ * root: Root,
9037
8747
  * events: Machine.eventsFromSchemas(),
9038
- * internalEvents,
9039
- * initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.from()))
9040
- * }).handle({ states: { Idle: { on: { Loaded: { none: true } } } } })
8748
+ * internalEvents
8749
+ * }).handle({
8750
+ * initial: { target: Machine.targets(Root).root.Idle },
8751
+ * states: { Idle: { on: { Loaded: { none: true } } } }
8752
+ * })
9041
8753
  *
9042
8754
  * export const canLoad = Effect.gen(function*() {
9043
8755
  * const initial = yield* Machine.planInitial(machine)
@@ -9148,27 +8860,32 @@ export const can: {
9148
8860
  * **Example**
9149
8861
  *
9150
8862
  * ```ts
9151
- * import { Effect, Schema } from "effect"
9152
8863
  * import { Machine } from "@typeonce/effect-machine"
9153
- *
9154
- * class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {}
9155
- * class On extends Schema.TaggedClass<On>("On")("On", {}) {}
9156
- * class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
9157
- * const States = Machine.state({ initial: "Off", states: { Off, On } })
8864
+ * import { Effect, Schema } from "effect"
8865
+ * class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {
8866
+ * }
8867
+ * class On extends Schema.TaggedClass<On>("On")("On", {}) {
8868
+ * }
8869
+ * class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {
8870
+ * }
8871
+ * const States = Machine.state({ states: { Off, On } })
9158
8872
  * const targets = Machine.targets(States)
9159
8873
  * const machine = Machine.make({
9160
8874
  * root: States,
9161
- * events: Machine.eventsFromSchemas(Toggle),
9162
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Off.from()))
9163
- * }).handle({ states: {
9164
- * Off: {
9165
- * on: {
9166
- * Toggle: { target: targets.root.On }
9167
- * }
8875
+ * events: Machine.eventsFromSchemas(Toggle)
8876
+ * }).handle({
8877
+ * initial: {
8878
+ * target: Machine.targets(States).root.Off
9168
8879
  * },
9169
- * On: {}
9170
- * } })
9171
- *
8880
+ * states: {
8881
+ * Off: {
8882
+ * on: {
8883
+ * Toggle: { target: targets.root.On }
8884
+ * }
8885
+ * },
8886
+ * On: {}
8887
+ * }
8888
+ * })
9172
8889
  * const nextState = Effect.gen(function*() {
9173
8890
  * const initial = yield* Machine.planInitial(machine)
9174
8891
  * return (yield* Machine.plan(machine, initial.state, new Toggle({}))).next
@@ -9546,17 +9263,22 @@ export const prepare: <
9546
9263
  * **Example**
9547
9264
  *
9548
9265
  * ```ts
9549
- * import { Effect, Schema } from "effect"
9550
9266
  * import { Machine } from "@typeonce/effect-machine"
9551
- *
9552
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
9553
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
9267
+ * import { Effect, Schema } from "effect"
9268
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
9269
+ * }
9270
+ * const States = Machine.state({ states: { Idle } })
9554
9271
  * const machine = Machine.make({
9555
9272
  * root: States,
9556
- * events: Machine.eventsFromSchemas(),
9557
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
9558
- * }).handle({ states: { Idle: {} } })
9559
- *
9273
+ * events: Machine.eventsFromSchemas()
9274
+ * }).handle({
9275
+ * initial: {
9276
+ * target: Machine.targets(States).root.Idle
9277
+ * },
9278
+ * states: {
9279
+ * Idle: {}
9280
+ * }
9281
+ * })
9560
9282
  * const state = Effect.gen(function*() {
9561
9283
  * const ref = yield* Machine.start(machine)
9562
9284
  * return yield* ref.state
@@ -9657,17 +9379,22 @@ export const start: <
9657
9379
  * **Example**
9658
9380
  *
9659
9381
  * ```ts
9660
- * import { Effect, Schema } from "effect"
9661
9382
  * import { Machine } from "@typeonce/effect-machine"
9662
- *
9663
- * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
9664
- * const States = Machine.state({ initial: "Idle", states: { Idle } })
9383
+ * import { Effect, Schema } from "effect"
9384
+ * class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
9385
+ * }
9386
+ * const States = Machine.state({ states: { Idle } })
9665
9387
  * const machine = Machine.make({
9666
9388
  * root: States,
9667
- * events: Machine.eventsFromSchemas(),
9668
- * initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
9669
- * }).handle({ states: { Idle: {} } })
9670
- *
9389
+ * events: Machine.eventsFromSchemas()
9390
+ * }).handle({
9391
+ * initial: {
9392
+ * target: Machine.targets(States).root.Idle
9393
+ * },
9394
+ * states: {
9395
+ * Idle: {}
9396
+ * }
9397
+ * })
9671
9398
  * const resumed = Effect.gen(function*() {
9672
9399
  * const initial = yield* Machine.planInitial(machine)
9673
9400
  * const encoded = yield* Machine.encodeSnapshot(machine, initial.state)