@typeonce/effect-machine 0.35.0 → 0.36.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 (56) hide show
  1. package/README.md +8 -7
  2. package/dist/Machine.d.ts +113 -136
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js.map +1 -1
  5. package/dist/internal/machine/command.d.ts +0 -1
  6. package/dist/internal/machine/command.d.ts.map +1 -1
  7. package/dist/internal/machine/command.js +0 -14
  8. package/dist/internal/machine/command.js.map +1 -1
  9. package/dist/internal/machine/configuration.d.ts.map +1 -1
  10. package/dist/internal/machine/configuration.js +15 -2
  11. package/dist/internal/machine/configuration.js.map +1 -1
  12. package/dist/internal/machine/construction.d.ts +9 -0
  13. package/dist/internal/machine/construction.d.ts.map +1 -0
  14. package/dist/internal/machine/construction.js +132 -0
  15. package/dist/internal/machine/construction.js.map +1 -0
  16. package/dist/internal/machine/declaration.d.ts +1 -0
  17. package/dist/internal/machine/declaration.d.ts.map +1 -1
  18. package/dist/internal/machine/declaration.js +3 -8
  19. package/dist/internal/machine/declaration.js.map +1 -1
  20. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  21. package/dist/internal/machine/executionPlan.js +9 -7
  22. package/dist/internal/machine/executionPlan.js.map +1 -1
  23. package/dist/internal/machine/implementation.d.ts +2 -3
  24. package/dist/internal/machine/implementation.d.ts.map +1 -1
  25. package/dist/internal/machine/implementation.js.map +1 -1
  26. package/dist/internal/machine/machine.d.ts.map +1 -1
  27. package/dist/internal/machine/machine.js +68 -168
  28. package/dist/internal/machine/machine.js.map +1 -1
  29. package/dist/internal/machine/planner.d.ts.map +1 -1
  30. package/dist/internal/machine/planner.js +63 -17
  31. package/dist/internal/machine/planner.js.map +1 -1
  32. package/dist/internal/machine/topology.d.ts +6 -0
  33. package/dist/internal/machine/topology.d.ts.map +1 -1
  34. package/dist/internal/machine/topology.js.map +1 -1
  35. package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
  36. package/dist/internal/testing/machine/finiteModel.js +36 -76
  37. package/dist/internal/testing/machine/finiteModel.js.map +1 -1
  38. package/docs/agent-guide.md +37 -34
  39. package/docs/root-api.md +143 -190
  40. package/package.json +1 -1
  41. package/src/Machine.ts +176 -144
  42. package/src/internal/machine/command.ts +0 -16
  43. package/src/internal/machine/configuration.ts +13 -10
  44. package/src/internal/machine/construction.ts +147 -0
  45. package/src/internal/machine/declaration.ts +4 -7
  46. package/src/internal/machine/executionPlan.ts +9 -7
  47. package/src/internal/machine/implementation.ts +2 -3
  48. package/src/internal/machine/machine.ts +86 -223
  49. package/src/internal/machine/planner.ts +69 -18
  50. package/src/internal/machine/topology.ts +4 -0
  51. package/src/internal/testing/machine/finiteModel.ts +44 -122
  52. package/dist/internal/machine/targetBuilder.d.ts +0 -16
  53. package/dist/internal/machine/targetBuilder.d.ts.map +0 -1
  54. package/dist/internal/machine/targetBuilder.js +0 -333
  55. package/dist/internal/machine/targetBuilder.js.map +0 -1
  56. package/src/internal/machine/targetBuilder.ts +0 -525
package/README.md CHANGED
@@ -209,8 +209,8 @@ const machine = Machine.make({
209
209
  branches: "search",
210
210
  resolve: ({ event, select }) =>
211
211
  event.query.length > 0
212
- ? select.loading.from({ query: event.query })
213
- : select.idle.from()
212
+ ? select.loading({ data: { query: event.query } })
213
+ : select.idle()
214
214
  }
215
215
  }
216
216
  }
@@ -221,9 +221,9 @@ const machine = Machine.make({
221
221
  Each selector is bound to its declared destination. Its constructor rejects a
222
222
  payload belonging to another branch. A single-target group works the same way;
223
223
  there is no second path declaration in the resolver. For a compound target,
224
- `select.checkout.from(parentValues, child => child.Review.from(childValues))`
224
+ `select.checkout({ data: parentValues, states: { Review: { data: childValues } } })`
225
225
  constructs the explicitly selected subtree. Parallel constructors require every
226
- entered region. Every compound has an initial edge, including inactive branches. Final outputs,
226
+ entered region; source-local construction can retain active sibling regions. Every compound has an initial edge, including inactive branches. Final outputs,
227
227
  history defaults, and choices remain part of machine readiness checking.
228
228
 
229
229
  Use `guard: context => boolean` to decline before construction or commands.
@@ -239,9 +239,10 @@ All references come from the same root descriptor supplied to `make`:
239
239
  | Declaration | Meaning |
240
240
  | ----------------------------------------------------- | ------------------------------------------------------------------------- |
241
241
  | `{ target: targets.root.Checkout.Review, data: ... }` | Enter a declared destination with its value. |
242
- | `{ initial: targets.root.Checkout, data: ... }` | Enter the declared initial configuration of a compound or parallel state. |
242
+ | `{ target: targets.root.Checkout, data: ... }` | Enter the declared initial configuration of a compound or parallel state. |
243
243
  | `{ history: targets.root.Checkout.recent }` | Restore a declared history state. |
244
244
  | `{ update: targets.root.Checkout, data: ... }` | Replace a retained active owner's value. |
245
+ | `{ target: targets.root, input: ... }` | Reconstruct root and its initial children using fresh machine input. |
245
246
  | `{ update: targets.root, data: ... }` | Replace root data and retain active descendants. |
246
247
  | `{ none: true }` | Accept an event without changing the configuration. |
247
248
 
@@ -260,12 +261,12 @@ Save: {
260
261
 
261
262
  The complete replacement values are validated before either change is applied.
262
263
  Advanced construction declares both references in a branch and uses
263
- `select.saved.from(destinationValues).update.from(ownerValues)`.
264
+ `select.saved({ data: destinationValues, update: { data: ownerValues } })`.
264
265
  A retained owner must be active for that source and remain active through the
265
266
  transition. A sibling region's value cannot be updated through this operation.
266
267
 
267
268
  The runtime transition API does not replace arbitrary complete root
268
- configurations. Startup follows the initial declarations in `.handle`; history
269
+ configurations. Root targets accept fresh input and follow the initial declarations in `.handle`; history
269
270
  defaults retain complete subtree construction for restoration.
270
271
 
271
272
  ### Protocols and ownership
package/dist/Machine.d.ts CHANGED
@@ -180,8 +180,6 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
180
180
  /** @internal */
181
181
  readonly stateNodes: Machine.StateNodes;
182
182
  /** @internal */
183
- readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
184
- /** @internal */
185
183
  readonly handlers: Readonly<Record<string, unknown>>;
186
184
  /** @internal */
187
185
  readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
@@ -202,7 +200,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
202
200
  * @category models
203
201
  * @since 0.15.0
204
202
  */
205
- 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 Omit<Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents>, TypeId | "stateNodes" | "makeTargetBuilder" | "handlers" | "initial" | "initialDefinition"> {
203
+ 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 Omit<Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents>, TypeId | "stateNodes" | "handlers" | "initial" | "initialDefinition"> {
206
204
  /**
207
205
  * Adds typed state handlers and returns an independent machine
208
206
  * implementation. Event dispatch maps and transition descriptors are
@@ -242,7 +240,7 @@ export declare namespace Definition {
242
240
  * @category models
243
241
  * @since 0.15.0
244
242
  */
245
- interface Any extends Omit<Machine.Any, TypeId | "stateNodes" | "makeTargetBuilder" | "handlers" | "initial" | "initialDefinition"> {
243
+ interface Any extends Omit<Machine.Any, TypeId | "stateNodes" | "handlers" | "initial" | "initialDefinition"> {
246
244
  readonly handle: any;
247
245
  }
248
246
  }
@@ -752,55 +750,18 @@ type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends str
752
750
  readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
753
751
  }, true>>;
754
752
  };
755
- type HistorySnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
756
- readonly type: "parallel";
757
- readonly states: infer Children extends Machine.StateSchemas;
758
- } ? WithNodeValue<Node, [
759
- states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
760
- ]> : Node extends {
761
- readonly states: infer Children extends Machine.StateSchemas;
762
- } ? WithNodeValue<Node, [
763
- state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
764
- ]> : never : never;
765
- type HistorySnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotFromArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
766
- readonly type: "parallel";
767
- readonly states: infer Children extends Machine.StateSchemas;
768
- } ? WithNodeInput<Node, [
769
- states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
770
- ]> : Node extends {
771
- readonly states: infer Children extends Machine.StateSchemas;
772
- } ? WithNodeInput<Node, [
773
- state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
774
- ]> : never : never;
775
753
  type HistorySnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotResult<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
776
754
  readonly type: "parallel";
777
755
  readonly states: infer Children extends Machine.StateSchemas;
778
756
  } ? Machine.ParallelSnapshot<Path, NodeValue<Node>, HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
779
757
  readonly states: infer Children extends Machine.StateSchemas;
780
758
  } ? Machine.CompoundSnapshot<Path, NodeValue<Node>, HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
781
- type HistorySnapshotMethod<in out States extends Machine.StateSchemas, in out StateId extends ActiveStateKey<States>, in out Prefix extends string, in out Owner extends string> = {
782
- readonly [Key in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"]: Key extends "from" ? FromCallable<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, Machine.StateConstruction<HistorySnapshotResult<States, StateId, Prefix, Owner>>> : (...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>;
783
- };
784
759
  type HistorySnapshotWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string> = {
785
760
  readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
786
761
  }[ActiveStateKey<States>];
787
- type HistorySnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string = ""> = {
788
- readonly [Key in ActiveStateKey<States> as Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? Key : never]: HistorySnapshotMethod<States, Key, Prefix, Owner>;
789
- };
790
762
  type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends string, Owner extends string> = {
791
763
  readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
792
764
  };
793
- type HistoryParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Owner extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
794
- readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? NodeBuilderMethod<States[Key], HistorySnapshotArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
795
- readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
796
- }, Constructed>, HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
797
- readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
798
- }, true>> : NodeBuilderMethod<States[Key], FullSnapshotArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
799
- readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
800
- }, Constructed>, FullSnapshotFromArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
801
- readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
802
- }, true>>;
803
- };
804
765
  type ParentPath<Path extends string> = Machine.ImmediateParentStateIdentifier<Path>;
805
766
  type IsCompoundNode<Node> = Node extends {
806
767
  readonly type: "parallel";
@@ -1590,7 +1551,6 @@ export declare namespace Machine {
1590
1551
  /** @internal */
1591
1552
  readonly stateNodes: StateNodes;
1592
1553
  /** @internal */
1593
- readonly makeTargetBuilder: any;
1594
1554
  /** @internal */
1595
1555
  readonly handlers: any;
1596
1556
  /** @internal */
@@ -2974,11 +2934,7 @@ export declare namespace Machine {
2974
2934
  * @category utility types
2975
2935
  * @since 0.4.0
2976
2936
  */
2977
- type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotMethod<{
2978
- readonly "": Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig>;
2979
- }, "" & ActiveStateKey<{
2980
- readonly "": Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig>;
2981
- }>, "", Owner>;
2937
+ type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = (construction: HistoryConstruction<States[""], Owner>) => StateConstruction<CompleteSnapshotContaining<States, Owner>>;
2982
2938
  /**
2983
2939
  * Builder for source-local transition targets.
2984
2940
  *
@@ -3762,6 +3718,23 @@ export declare namespace Machine {
3762
3718
  } ? OutputHandlerConfig<States, Events, StateId, ParallelOutputContext<States, Events, StateId>> : {
3763
3719
  readonly output?: never;
3764
3720
  };
3721
+ type HistoryConstruction<Node, Owner extends string> = ConstructionData<Node> & (Node extends {
3722
+ readonly states: infer Children extends StateSchemas;
3723
+ } ? {
3724
+ readonly states: Node extends {
3725
+ readonly type: "parallel";
3726
+ } ? {
3727
+ readonly [K in (ActiveStateKey<Children> | ChoiceStateKey<Children>)]: HistoryConstruction<Children[K], Owner extends `${K}.${infer Rest}` ? Rest : "">;
3728
+ } : {
3729
+ readonly [K in (ActiveStateKey<Children> | ChoiceStateKey<Children>)]: Owner extends "" | K | `${K}.${string}` ? {
3730
+ readonly [P in K]: HistoryConstruction<Children[P], Owner extends `${K}.${infer Rest}` ? Rest : "">;
3731
+ } & {
3732
+ readonly [P in Exclude<(ActiveStateKey<Children> | ChoiceStateKey<Children>), K>]?: never;
3733
+ } : never;
3734
+ }[(ActiveStateKey<Children> | ChoiceStateKey<Children>)];
3735
+ } : {
3736
+ readonly states?: never;
3737
+ });
3765
3738
  /** Context used only when a history node has no previously captured record. */
3766
3739
  interface HistoryDefaultContext<in out States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, in out ParentId extends StateIdentifier<States>> {
3767
3740
  /** Lifecycle event that attempted to restore this history node. */
@@ -4010,7 +3983,7 @@ export declare namespace Machine {
4010
3983
  readonly title?: string;
4011
3984
  } & ({
4012
3985
  /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4013
- readonly target: ReferenceUnion<S, DestinationPath<S>>;
3986
+ readonly target: ReferenceUnion<S, DestinationPath<S>> | TargetReference<Root, "", "state">;
4014
3987
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4015
3988
  readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>;
4016
3989
  /** Enters a compound or parallel subtree through its declared initialization. */
@@ -4030,17 +4003,6 @@ export declare namespace Machine {
4030
4003
  readonly history?: never;
4031
4004
  /** Accepts the event without selecting a new destination. */
4032
4005
  readonly none?: never;
4033
- } | {
4034
- /** Enters a compound or parallel subtree through its declared initialization. */
4035
- readonly initial: ReferenceUnion<S, Exclude<ObjectCompoundPath<S>, "">>;
4036
- /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4037
- readonly target?: never;
4038
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4039
- readonly update?: never;
4040
- /** Restores the declared history reference, using its fallback on first entry. */
4041
- readonly history?: never;
4042
- /** Accepts the event without selecting a new destination. */
4043
- readonly none?: never;
4044
4006
  } | {
4045
4007
  /** Restores the declared history reference, using its fallback on first entry. */
4046
4008
  readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
@@ -4080,30 +4042,70 @@ export declare namespace Machine {
4080
4042
  /** Named groups of inspectable destinations used by transition resolvers. */
4081
4043
  readonly branches?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
4082
4044
  }
4045
+ type RegisteredInput<R> = R extends {
4046
+ readonly "~input": infer I extends Schema.Top;
4047
+ } ? I : typeof Schema.Void;
4083
4048
  type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {};
4084
- 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;
4085
- type BranchBuilderAt<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = AtBuilder<RootBuilder<BranchTargetBuilder<S, Src>>, P>;
4086
4049
  type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never;
4087
- type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D> = D extends {
4088
- /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4050
+ type ConstructionData<Node> = [NodeSchema<Node>] extends [never] ? {
4051
+ readonly data?: never;
4052
+ readonly decoded?: never;
4053
+ } : ({
4054
+ readonly decoded?: false;
4055
+ } & ({} extends NodeMakeInput<Node> ? {
4056
+ readonly data?: NodeMakeInput<Node>;
4057
+ } : {
4058
+ readonly data: NodeMakeInput<Node>;
4059
+ })) | {
4060
+ readonly decoded: true;
4061
+ readonly data: NodeValue<Node>;
4062
+ };
4063
+ type ConstructionChildren<Children extends StateSchemas, Parallel extends boolean, Source extends string = never> = Parallel extends true ? {
4064
+ readonly [K in ActiveStateKey<Children>]: ConstructionObject<Children[K], Source extends `${K}.${infer Rest}` ? Rest : Source extends K ? "" : never>;
4065
+ } : {
4066
+ readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: {
4067
+ readonly [P in K]: ConstructionObject<Children[P], Source extends `${P}.${infer Rest}` ? Rest : Source extends P ? "" : never>;
4068
+ } & {
4069
+ readonly [P in Exclude<ActiveStateKey<Children> | ChoiceStateKey<Children>, K>]?: never;
4070
+ };
4071
+ }[ActiveStateKey<Children> | ChoiceStateKey<Children>];
4072
+ /** Values for one state and, optionally, its explicitly selected descendants. */
4073
+ type ConstructionObject<Node, Source extends string = never> = {
4074
+ readonly input?: never;
4075
+ } & ConstructionData<Node> & (Node extends {
4076
+ readonly states: infer Children extends StateSchemas;
4077
+ } ? {
4078
+ readonly states?: ConstructionChildren<Children, Node extends {
4079
+ readonly type: "parallel";
4080
+ } ? [Source] extends [never] ? true : false : false, Source>;
4081
+ } : {
4082
+ readonly states?: never;
4083
+ });
4084
+ type ConstructionCall<A, Result> = {} extends A ? (construction?: A) => Result : (construction: A) => Result;
4085
+ type RootInput<R> = {
4086
+ readonly data?: never;
4087
+ readonly decoded?: never;
4088
+ readonly states?: never;
4089
+ readonly update?: never;
4090
+ } & (RegisteredInput<R> extends typeof Schema.Void ? {
4091
+ readonly input?: never;
4092
+ } : {
4093
+ /** Fresh machine input used by root construction and root initial callbacks. */ readonly input: RegisteredInput<R>["Type"];
4094
+ });
4095
+ type ObjectSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends StateNodeIdentifier<S>, R> = P extends "" ? ConstructionCall<RootInput<R>, InitialTarget<P>> : P extends ChoiceIdentifier<S> ? () => ChoiceTarget<S, P> : P extends StateIdentifier<S> ? ConstructionCall<ConstructionObject<NodeByIdentifier<S, P>, Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never> & {
4096
+ readonly update?: never;
4097
+ }, Target<S, P>> : never;
4098
+ type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D, R = {}> = D extends {
4089
4099
  readonly target: infer Ref;
4090
4100
  } ? RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ? D extends {
4091
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4092
4101
  readonly update: infer Update;
4093
- } ? 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 {
4094
- /** Enters a compound or parallel subtree through its declared initialization. */
4095
- readonly initial: infer Ref;
4096
- } ? RefPath<Ref> extends infer P extends string ? BranchBuilderAt<S, Src, P> extends {
4097
- /** Enters a compound or parallel subtree through its declared initialization. */
4098
- readonly initial: infer B;
4099
- } ? TargetSelection<B, P, "initial", "branch"> : never : never : D extends {
4100
- /** Restores the declared history reference, using its fallback on first entry. */
4102
+ } ? RefPath<Update> extends infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>> ? P extends StateIdentifier<S> ? TargetSelection<ConstructionCall<ConstructionObject<NodeByIdentifier<S, P>, Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never> & {
4103
+ readonly update: ConstructionData<NodeByIdentifier<S, Owner>>;
4104
+ }, CombinedTarget<Target<S, P>, S, Owner>>, P, "state", "branch"> : never : never : TargetSelection<ObjectSelection<S, Src, P, R>, P, P extends ChoiceIdentifier<S> ? "choice" : "state", "branch"> : never : D extends {
4101
4105
  readonly history: infer Ref;
4102
- } ? RefPath<Ref> extends infer P extends string ? TargetSelection<AtBuilder<RootBuilder<HistoryTargetBuilder<S>>, P>, P, "history", "full"> : never : D extends {
4103
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4106
+ } ? RefPath<Ref> extends infer P extends HistoryIdentifier<S> ? TargetSelection<() => HistoryTarget<S, P>, P, "history", "full"> : never : D extends {
4104
4107
  readonly update: infer Ref;
4105
- } ? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>> ? TargetSelection<StateUpdateBuilder<S, P>, P, "update", "branch"> : never : D extends {
4106
- /** Accepts the event without selecting a new destination. */
4108
+ } ? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>> ? TargetSelection<ConstructionCall<ConstructionData<NodeByIdentifier<S, P>>, StateUpdate<S, P>>, P, "update", "branch"> : never : D extends {
4107
4109
  readonly none: true;
4108
4110
  } ? TargetSelection<() => NoTarget, never, "none", "local"> : never;
4109
4111
  type BuilderArgs<B, K extends PropertyKey> = K extends keyof B ? B[K] extends (...args: infer A) => unknown ? A : never : never;
@@ -4114,14 +4116,6 @@ export declare namespace Machine {
4114
4116
  readonly [K in Exclude<"from" | "decoded", M>]?: never;
4115
4117
  } : never;
4116
4118
  }[Extract<keyof B, "from" | "decoded">];
4117
- type ObjectDefault<B> = B extends {
4118
- /** Constructs schema make input from the typed source context. */
4119
- readonly from: () => unknown;
4120
- } | (() => unknown) ? {
4121
- /** Constructs schema make input from the typed source context. */
4122
- readonly from?: never; /** Supplies an already decoded schema value from the typed source context. */
4123
- readonly decoded?: never;
4124
- } : never;
4125
4119
  type ObjectPolicy<C, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
4126
4120
  /** Set to true to exit and reenter the handler source. */
4127
4121
  readonly reenter?: Reenter extends true ? boolean : never;
@@ -4144,9 +4138,19 @@ export declare namespace Machine {
4144
4138
  type InlineDestinationConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends DestinationPath<S>, C> = P extends ChoiceIdentifier<S> ? {
4145
4139
  readonly from?: never;
4146
4140
  readonly decoded?: never;
4147
- } : P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
4148
- readonly states: StateSchemas;
4149
- } ? [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? ObjectConstruction<C, BranchBuilderAt<S, Src, P>> | ObjectDefault<BranchBuilderAt<S, Src, P>> : never : InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
4141
+ } : P extends StateIdentifier<S> ? InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
4142
+ type InlineRoot<S extends StateSchemas, C, R> = {
4143
+ readonly target: ReferenceAt<S, Extract<"", StateNodeIdentifier<S>>>;
4144
+ readonly update?: never;
4145
+ readonly branches?: never;
4146
+ readonly resolve?: never;
4147
+ readonly history?: never;
4148
+ readonly none?: never;
4149
+ } & (RegisteredInput<R> extends typeof Schema.Void ? {
4150
+ readonly input?: never;
4151
+ } : {
4152
+ /** Fresh machine input used to reconstruct root and its initial children. */ readonly input: DataValue<C, RegisteredInput<R>["Type"]>;
4153
+ });
4150
4154
  type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
4151
4155
  readonly [P in DestinationPath<S>]: {
4152
4156
  /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
@@ -4167,20 +4171,7 @@ export declare namespace Machine {
4167
4171
  readonly declinable?: never;
4168
4172
  } & InlineDestinationConstruction<S, Src, P, C>;
4169
4173
  }[DestinationPath<S>];
4170
- 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 {
4171
- readonly states: StateSchemas;
4172
- } ? {
4173
- readonly [M in Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">]: BuilderArgs<BranchBuilderAt<S, Src, P>, M> extends readonly [unknown?] ? {
4174
- readonly [K in M]: (context: C) => {
4175
- /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4176
- readonly target: BuilderArgs<BranchBuilderAt<S, Src, P>, M>[0];
4177
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4178
- readonly update: BuilderArgs<StateUpdateBuilder<S, Owner>, M>[0];
4179
- };
4180
- } & {
4181
- readonly [K in Exclude<"from" | "decoded", M>]?: never;
4182
- } : never;
4183
- }[Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">] : {
4174
+ type InlinePairConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string, Owner extends ValuedStateIdentifier<S>, C> = P extends StateIdentifier<S> ? {
4184
4175
  readonly from: (context: C) => {
4185
4176
  readonly target: [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? undefined : NodeMakeInput<NodeByIdentifier<S, P>>;
4186
4177
  readonly update: SchemaByIdentifier<S, Owner>["~type.make.in"];
@@ -4239,48 +4230,26 @@ export declare namespace Machine {
4239
4230
  readonly declinable?: never;
4240
4231
  } & ObjectConstruction<C, StateUpdateBuilder<S, P>>;
4241
4232
  }[Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>];
4242
- type InlineInitial<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = [
4243
- Exclude<ObjectCompoundPath<S>, "">
4244
- ] extends [never] ? never : {
4245
- readonly [P in Exclude<ObjectCompoundPath<S>, "">]: InitialTargetFactory<NodeByIdentifier<S, P>, P> extends infer B ? {
4246
- /** Enters a compound or parallel subtree through its declared initialization. */
4247
- readonly initial: ReferenceAt<S, P>;
4248
- /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4249
- readonly target?: never;
4250
- /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4251
- readonly update?: never;
4252
- /** Restores the declared history reference, using its fallback on first entry. */
4253
- readonly history?: never;
4254
- /** Accepts the event without selecting a new destination. */
4255
- readonly none?: never;
4256
- /** Named groups of inspectable destinations used by transition resolvers. */
4257
- readonly branches?: never;
4258
- /** Selects one declared branch and may enqueue synchronous commands. */
4259
- readonly resolve?: never;
4260
- /** Set to true when the resolver can explicitly return decline(). */
4261
- readonly declinable?: never;
4262
- } & (ObjectConstruction<C, B> | ObjectDefault<B>) : never;
4263
- }[Exclude<ObjectCompoundPath<S>, "">];
4264
- type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
4233
+ type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
4265
4234
  readonly [K in Extract<keyof Group, string>]: {
4266
4235
  /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
4267
- readonly target: SelectionOf<S, Src, Group[K]>;
4236
+ readonly target: SelectionOf<S, Src, Group[K], R>;
4268
4237
  };
4269
4238
  };
4270
4239
  type ObjectBranchResolver<Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, C, B extends Readonly<Record<string, TransitionBranchInput>>, Declinable extends boolean> = (context: C & {
4271
4240
  readonly select: BranchSelectors<B>;
4272
4241
  } & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => BranchSelectionResult<B> | (Declinable extends true ? Declined : never);
4273
- type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
4242
+ type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
4274
4243
  readonly [K in keyof Group]: Src extends ChoiceIdentifier<S> ? Group[K] extends {
4275
4244
  /** Accepts the event without selecting a new destination. */
4276
4245
  readonly none: true;
4277
4246
  } | {
4278
4247
  /** Replaces the complete value of a retained source or ancestor without replacing its active children. */
4279
4248
  readonly update: unknown;
4280
- } ? K : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never;
4249
+ } ? K : [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K : never : [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K : never;
4281
4250
  }[keyof Group];
4282
4251
  type ObjectBranches<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Acceptance extends TransitionAcceptance> = {
4283
- readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K]>] extends [never] ? unknown : never) & {
4252
+ readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K], R>] extends [never] ? unknown : never) & {
4284
4253
  /** Named groups of inspectable destinations used by transition resolvers. */
4285
4254
  readonly branches: K;
4286
4255
  /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
@@ -4301,7 +4270,7 @@ export declare namespace Machine {
4301
4270
  /** Set to true when the resolver can explicitly return decline(). */
4302
4271
  readonly declinable?: "declinable" extends Acceptance ? boolean : false;
4303
4272
  /** Selects one declared branch and may enqueue synchronous commands. */
4304
- readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K]>, true>;
4273
+ readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K], R>, true>;
4305
4274
  };
4306
4275
  }[Extract<keyof Registered<R, "branches">, string>];
4307
4276
  type DataValue<C, A> = A | ((context: C) => A);
@@ -4325,7 +4294,7 @@ export declare namespace Machine {
4325
4294
  * @category models
4326
4295
  * @since 0.34.0
4327
4296
  */
4328
- 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> & DeclarationData<(InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineInitial<S, Src, C> | {
4297
+ 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> & DeclarationData<(InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineRoot<S, C, R> | {
4329
4298
  /** Restores the declared history reference, using its fallback on first entry. */
4330
4299
  readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
4331
4300
  /** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
@@ -4520,11 +4489,11 @@ export declare namespace Machine {
4520
4489
  type RootConstruction<Node, Input> = [NodeSchema<Node>] extends [never] ? {
4521
4490
  readonly root?: never;
4522
4491
  } : {} extends NodeMakeInput<Node> ? {
4523
- /** Constructs root-owned data once from startup input. */ readonly root?: ShortConstruction<{
4492
+ /** Constructs root-owned data from startup or fresh root-target input. */ readonly root?: ShortConstruction<{
4524
4493
  readonly input: Input;
4525
4494
  }, Node>;
4526
4495
  } : {
4527
- /** Constructs root-owned data once from startup input. */ readonly root: ShortConstruction<{
4496
+ /** Constructs root-owned data from startup or fresh root-target input. */ readonly root: ShortConstruction<{
4528
4497
  readonly input: Input;
4529
4498
  }, Node>;
4530
4499
  };
@@ -4571,7 +4540,9 @@ export declare namespace Machine {
4571
4540
  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> & InitialHandler<S, Node, Src, StateActionContext<S, Ev, Em, Extract<Src, StateIdentifier<S>>, In, Pa> & {
4572
4541
  /** Root-owned data constructed before initial descendant values. */
4573
4542
  readonly root: StateByIdentifier<S, Extract<"", StateIdentifier<S>>>;
4574
- }> & (Src extends ChoiceIdentifier<S> ? {
4543
+ } & (Src extends "" ? {
4544
+ /** Fresh machine input used by root construction and root initial callbacks. */ readonly input: RegisteredInput<R>["Type"];
4545
+ } : {})> & (Src extends ChoiceIdentifier<S> ? {
4575
4546
  /** Required total transition for a transient choice state. */
4576
4547
  readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>;
4577
4548
  /** Event handlers keyed by the public or internal event tag. */
@@ -4631,8 +4602,12 @@ export declare namespace Machine {
4631
4602
  readonly states?: never; /** Restores the declared history reference, using its fallback on first entry. */
4632
4603
  readonly history?: never;
4633
4604
  }) : never);
4634
- type ValidateObjectTransition<T> = {
4635
- readonly [K in Exclude<keyof T, "target" | "update" | "initial" | "history" | "none" | "branches" | "data" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
4605
+ type ValidateObjectTransition<T> = ("input" extends keyof T ? T extends {
4606
+ readonly target: TargetReference<any, "", "state">;
4607
+ } ? unknown : {
4608
+ readonly input: never;
4609
+ } : unknown) & {
4610
+ readonly [K in Exclude<keyof T, "target" | "update" | "input" | "history" | "none" | "branches" | "data" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
4636
4611
  } & (T extends {
4637
4612
  /** Set to true when the resolver can explicitly return decline(). */
4638
4613
  readonly declinable: infer D;
@@ -4693,7 +4668,9 @@ export declare namespace Machine {
4693
4668
  * @since 0.34.0
4694
4669
  */
4695
4670
  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> {
4696
- <const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R> & RootConstruction<S[""], I["Type"]>> & RootConstruction<S[""], I["Type"]> & ValidateObjectConfig<NoInfer<C>, R> & RootHandlerValidation<S, Ev, In, Em, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
4671
+ <const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R & {
4672
+ readonly "~input": I;
4673
+ }> & RootConstruction<S[""], I["Type"]>> & RootConstruction<S[""], I["Type"]> & ValidateObjectConfig<NoInfer<C>, R> & RootHandlerValidation<S, Ev, In, Em, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
4697
4674
  readonly "": NormalizeObjectConfig<NoInfer<C>, R>;
4698
4675
  }>["outputState"], StateIdentifier<S>>>): HandleTreeResult<S, Ev, Em, I, StateIdentifier<S>, never, never, IE, IR, Final, Out, never, In, Pa, {
4699
4676
  readonly "": NormalizeObjectConfig<C, R>;