@typeonce/effect-machine 0.6.1 → 0.8.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 +25 -3
  2. package/dist/Machine.d.ts +181 -144
  3. package/dist/Machine.d.ts.map +1 -1
  4. package/dist/Machine.js +3 -1
  5. package/dist/Machine.js.map +1 -1
  6. package/dist/internal/machine/atom.d.ts +13 -2
  7. package/dist/internal/machine/atom.d.ts.map +1 -1
  8. package/dist/internal/machine/atom.js +6 -3
  9. package/dist/internal/machine/atom.js.map +1 -1
  10. package/dist/internal/machine/configuration.d.ts.map +1 -1
  11. package/dist/internal/machine/configuration.js +103 -20
  12. package/dist/internal/machine/configuration.js.map +1 -1
  13. package/dist/internal/machine/executionPlan.d.ts.map +1 -1
  14. package/dist/internal/machine/executionPlan.js +6 -0
  15. package/dist/internal/machine/executionPlan.js.map +1 -1
  16. package/dist/internal/machine/invocation.js +1 -1
  17. package/dist/internal/machine/invocation.js.map +1 -1
  18. package/dist/internal/machine/machine.d.ts.map +1 -1
  19. package/dist/internal/machine/machine.js +23 -17
  20. package/dist/internal/machine/machine.js.map +1 -1
  21. package/dist/internal/machine/planner.d.ts +10 -0
  22. package/dist/internal/machine/planner.d.ts.map +1 -1
  23. package/dist/internal/machine/planner.js +45 -35
  24. package/dist/internal/machine/planner.js.map +1 -1
  25. package/dist/internal/machine/serialization.d.ts.map +1 -1
  26. package/dist/internal/machine/serialization.js +53 -21
  27. package/dist/internal/machine/serialization.js.map +1 -1
  28. package/dist/internal/machine/stateDefinition.d.ts +4 -4
  29. package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
  30. package/dist/internal/machine/stateDefinition.js +18 -11
  31. package/dist/internal/machine/stateDefinition.js.map +1 -1
  32. package/dist/internal/machine/topology.d.ts +5 -5
  33. package/dist/internal/machine/topology.d.ts.map +1 -1
  34. package/dist/internal/machine/topology.js +16 -13
  35. package/dist/internal/machine/topology.js.map +1 -1
  36. package/dist/internal/testing/machine/verification.d.ts.map +1 -1
  37. package/dist/internal/testing/machine/verification.js +10 -3
  38. package/dist/internal/testing/machine/verification.js.map +1 -1
  39. package/dist/unstable/reactivity/AtomMachine.d.ts +34 -2
  40. package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
  41. package/dist/unstable/reactivity/AtomMachine.js +23 -0
  42. package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
  43. package/docs/agent-guide.md +70 -28
  44. package/package.json +2 -2
  45. package/src/Machine.ts +420 -309
  46. package/src/internal/machine/atom.ts +61 -6
  47. package/src/internal/machine/configuration.ts +102 -23
  48. package/src/internal/machine/executionPlan.ts +6 -0
  49. package/src/internal/machine/invocation.ts +1 -1
  50. package/src/internal/machine/machine.ts +93 -62
  51. package/src/internal/machine/planner.ts +49 -38
  52. package/src/internal/machine/serialization.ts +56 -31
  53. package/src/internal/machine/stateDefinition.ts +22 -11
  54. package/src/internal/machine/topology.ts +21 -18
  55. package/src/internal/testing/machine/verification.ts +13 -3
  56. package/src/unstable/reactivity/AtomMachine.ts +56 -2
package/dist/Machine.d.ts CHANGED
@@ -383,48 +383,38 @@ type UnknownPseudoAnnotationProperty<Node> = Node extends {
383
383
  type ValidatePseudoStateAnnotations<Node, Path extends PropertyKey> = [UnknownPseudoAnnotationProperty<Node>] extends [
384
384
  never
385
385
  ] ? unknown : StateDefinitionError<"Pseudo-state annotations contain unknown properties", Path, Extract<UnknownPseudoAnnotationProperty<Node>, PropertyKey>>;
386
- type ValidateStateNode<Node, AllowHistory extends boolean, Path extends PropertyKey> = Node extends Machine.TaggedSchema ? unknown : Node extends Machine.HistoryStateNodeConfig ? ValidateExactStateNodeProperties<Node, "history", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateHistoryStateNode<Node> : StateDefinitionError<"History states must be declared below an active parent state", Path>) : Node extends Machine.ChoiceStateNodeConfig ? ValidateExactStateNodeProperties<Node, "choice", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateChoiceStateNode<Node> : StateDefinitionError<"Choice states must be declared below an active parent state", Path>) : Node extends {
387
- readonly schema: Machine.TaggedSchema;
388
- } ? ValidateStateNodeConfig<Node, Path> : StateDefinitionError<"State nodes must be tagged schemas or state node configs", Path>;
386
+ type ValidateStateNode<Node, AllowHistory extends boolean, Path extends PropertyKey> = Node extends Machine.TaggedSchema ? unknown : Node extends Machine.HistoryStateNodeConfig ? ValidateExactStateNodeProperties<Node, "history", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateHistoryStateNode<Node> : StateDefinitionError<"History states must be declared below an active parent state", Path>) : Node extends Machine.ChoiceStateNodeConfig ? ValidateExactStateNodeProperties<Node, "choice", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateChoiceStateNode<Node> : StateDefinitionError<"Choice states must be declared below an active parent state", Path>) : Node extends Machine.StateNodeConfig ? ValidateStateNodeConfig<Node, Path> : StateDefinitionError<"State nodes must be tagged schemas or state node configs", Path>;
389
387
  type ValidateHistoryStateNode<Node extends Machine.HistoryStateNodeConfig> = [
390
388
  Extract<keyof Node, "schema" | "states" | "initial" | "output" | "choice">
391
389
  ] extends [never] ? unknown : StateDefinitionError<"History states cannot declare schemas, children, initial states, or output">;
392
390
  type ValidateChoiceStateNode<Node extends Machine.ChoiceStateNodeConfig> = [
393
391
  Extract<keyof Node, "schema" | "states" | "initial" | "output" | "history">
394
392
  ] extends [never] ? unknown : StateDefinitionError<"Choice states cannot declare schemas, children, initial states, output, or history">;
395
- type ValidateStateNodeConfig<Node extends {
396
- readonly schema: Machine.TaggedSchema;
397
- }, Path extends PropertyKey> = Node extends {
393
+ type ValidateStateNodeConfig<Node extends Machine.StateNodeConfig, Path extends PropertyKey> = Node extends {
398
394
  readonly type: "parallel";
399
395
  } ? ValidateExactStateNodeProperties<Node, "parallel", Path> & ValidateStateNodeWithChildren<Node, Node extends {
400
396
  readonly states: infer Children;
401
- } ? Children : never, Path> : Node extends {
397
+ } ? Children : never, Path> & ValidatePseudoStateAnnotations<Node, Path> : Node extends {
402
398
  readonly type: "final";
403
- } ? ValidateExactStateNodeProperties<Node, "final", Path> & ValidateStateNodeWithoutChildren<Node> : Node extends {
399
+ } ? ValidateExactStateNodeProperties<Node, "final", Path> & ValidateStateNodeWithoutChildren<Node> & ValidatePseudoStateAnnotations<Node, Path> : Node extends {
404
400
  readonly states: infer Children;
405
- } ? ValidateExactStateNodeProperties<Node, "compound", Path> & ValidateStateNodeWithChildren<Node, Children, Path> : ValidateExactStateNodeProperties<Node, "atomic", Path> & ValidateStateNodeWithoutChildren<Node>;
401
+ } ? ValidateExactStateNodeProperties<Node, "compound", Path> & ValidateStateNodeWithChildren<Node, Children, Path> & ValidatePseudoStateAnnotations<Node, Path> : ValidateExactStateNodeProperties<Node, "atomic", Path> & ValidateStateNodeWithoutChildren<Node> & ValidatePseudoStateAnnotations<Node, Path>;
406
402
  type ValidateOutputSchema<Node> = "output" extends keyof Node ? Node extends {
407
403
  readonly output: Schema.Top;
408
404
  } ? unknown : StateDefinitionError<"State output must be a schema"> : unknown;
409
- type ValidateStateNodeWithChildren<Node extends {
410
- readonly schema: Machine.TaggedSchema;
411
- }, Children, Path extends PropertyKey> = Children extends Machine.StateSchemas ? Node extends {
405
+ type ValidateStateNodeWithChildren<Node extends Machine.StateNodeConfig, Children, Path extends PropertyKey> = Children extends Machine.StateSchemas ? Node extends {
412
406
  readonly type: "final";
413
407
  } ? StateDefinitionError<"Final states cannot declare child states"> : Node extends {
414
408
  readonly type: "parallel";
415
409
  } ? "initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
416
410
  readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
417
411
  } & ValidateOutputSchema<Node> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : ValidateCompoundStateNode<Node, Children, Path> : StateDefinitionError<"Child states must be a state tree">;
418
- type ValidateCompoundStateNode<Node extends {
419
- readonly schema: Machine.TaggedSchema;
420
- }, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
412
+ type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
421
413
  readonly initial: infer Initial;
422
414
  } ? Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? {
423
415
  readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
424
416
  } : StateDefinitionError<"Compound initial must be one of its direct child keys"> : StateDefinitionError<"Compound states must declare an initial child">;
425
- type ValidateStateNodeWithoutChildren<Node extends {
426
- readonly schema: Machine.TaggedSchema;
427
- }> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
417
+ type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
428
418
  readonly type: infer Type;
429
419
  } ? Type extends "final" ? ValidateOutputSchema<Node> : Type extends "active" | undefined ? "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown : StateDefinitionError<"State node type must be active, final, or parallel"> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown;
430
420
  type DefineStateTreeInput<States extends Machine.StateSchemas> = {
@@ -483,6 +473,24 @@ type FromMethod<Arguments extends ReadonlyArray<unknown>, Result> = {
483
473
  };
484
474
  type ConstructionResult<Result> = Result | Machine.StateConstruction<Result>;
485
475
  type UnwrapConstruction<Result> = Result extends Machine.StateConstruction<infer Value> ? Value : Result;
476
+ type NodeValue<Node> = [Machine.NodeSchema<Node>] extends [never] ? undefined : Machine.NodeSchema<Node>["Type"];
477
+ type NodeMakeInput<Node> = [Machine.NodeSchema<Node>] extends [never] ? never : Machine.NodeSchema<Node>["~type.make.in"];
478
+ type WithNodeValue<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest : readonly [value: NodeValue<Node>, ...Rest];
479
+ type WithNodeInput<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest : readonly [input: NodeMakeInput<Node>, ...Rest];
480
+ type NodeBuilderMethod<Node, Arguments extends ReadonlyArray<unknown>, Result, FromArguments extends ReadonlyArray<unknown>, FromResult> = Machine.NodeSchema<Node> extends never ? {
481
+ readonly from: FromCallable<FromArguments, FromResult>;
482
+ } : ((...args: Arguments) => Result) & {
483
+ readonly from: FromCallable<FromArguments, FromResult>;
484
+ };
485
+ type NodeMethod<Node, Arguments extends ReadonlyArray<unknown>, Result, FromArguments extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? FromMethod<FromArguments, Result> : ((...args: Arguments) => Result) & FromMethod<FromArguments, Result>;
486
+ type NodeConstructionSelectorFromCallable<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
487
+ <Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
488
+ } : ConstructionSelectorFromCallable<NodeMakeInput<Node>, Builder, Result>;
489
+ type NestedTargetMethod<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
490
+ readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>;
491
+ } : (<Selected extends ConstructionResult<Result>>(value: NodeValue<Node>, state: (builder: Builder) => Selected) => Selected) & {
492
+ readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>;
493
+ };
486
494
  type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input ? {
487
495
  <Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
488
496
  <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
@@ -492,127 +500,111 @@ type InitialSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefi
492
500
  } & {
493
501
  readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
494
502
  };
495
- type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = ((...args: InitialSnapshotArguments<States, StateId, Prefix>) => InitialSnapshotResult<States, StateId, Prefix>) & FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>>;
503
+ type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>> : ((...args: InitialSnapshotArguments<States, StateId, Prefix>) => InitialSnapshotResult<States, StateId, Prefix>) & FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>>;
496
504
  type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
497
505
  readonly type: "parallel";
498
506
  readonly states: infer Children extends Machine.StateSchemas;
499
- } ? [
500
- value: Machine.NodeSchema<Node>["Type"],
507
+ } ? WithNodeValue<Node, [
501
508
  states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>>
502
- ] : Node extends {
509
+ ]> : Node extends {
503
510
  readonly states: infer Children extends Machine.StateSchemas;
504
511
  } ? Node extends {
505
512
  readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
506
- } ? [
507
- value: Machine.NodeSchema<Node>["Type"],
513
+ } ? WithNodeValue<Node, [
508
514
  state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSelectableResult<Children, Initial, Path>
509
- ] : never : [value: Machine.NodeSchema<Node>["Type"]] : never;
515
+ ]> : never : WithNodeValue<Node, []> : never;
510
516
  type InitialSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
511
517
  readonly type: "parallel";
512
518
  readonly states: infer Children extends Machine.StateSchemas;
513
- } ? [
514
- input: Machine.NodeSchema<Node>["~type.make.in"],
519
+ } ? WithNodeInput<Node, [
515
520
  states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
516
- ] : Node extends {
521
+ ]> : Node extends {
517
522
  readonly states: infer Children extends Machine.StateSchemas;
518
523
  } ? Node extends {
519
524
  readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
520
- } ? [
521
- input: Machine.NodeSchema<Node>["~type.make.in"],
525
+ } ? WithNodeInput<Node, [
522
526
  state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
523
- ] : never : [input: Machine.NodeSchema<Node>["~type.make.in"]] : never;
527
+ ]> : never : WithNodeInput<Node, []> : never;
524
528
  type InitialSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
525
529
  readonly type: "parallel";
526
530
  readonly states: infer Children extends Machine.StateSchemas;
527
- } ? Machine.ParallelSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
531
+ } ? Machine.ParallelSnapshot<Path, NodeValue<Node>, InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
528
532
  readonly states: infer Children extends Machine.StateSchemas;
529
533
  } ? Node extends {
530
534
  readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
531
- } ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, Machine.NodeSchema<Node>["Type"]> : never;
535
+ } ? Machine.CompoundSnapshot<Path, NodeValue<Node>, InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, NodeValue<Node>> : never;
532
536
  type InitialSelectableResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States> | ChoiceStateKey<States>, Prefix extends string> = StateId extends ChoiceStateKey<States> ? Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, StateId>> : StateId extends ActiveStateKey<States> ? InitialSnapshotResult<States, StateId, Prefix> : never;
533
537
  type InitialSnapshotRegionsWithPrefix<States extends Machine.StateSchemas, Prefix extends string> = {
534
538
  readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>;
535
539
  };
536
540
  type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
537
- readonly [Key in Remaining]: ((...args: InitialSnapshotArguments<States, Key, Prefix>) => InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
541
+ readonly [Key in Remaining]: NodeBuilderMethod<States[Key], InitialSnapshotArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
538
542
  readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
539
- }, Constructed>) & {
540
- readonly from: FromCallable<InitialSnapshotFromArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
541
- readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
542
- }, true>>;
543
- };
543
+ }, Constructed>, InitialSnapshotFromArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
544
+ readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
545
+ }, true>>;
544
546
  };
545
547
  type FullSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
546
548
  readonly [Key in ActiveStateKey<States>]: FullSnapshotMethod<States, Key, Prefix>;
547
549
  } & {
548
550
  readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
549
551
  };
550
- type FullSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = ((...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>) & FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>>;
552
+ type FullSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>> : ((...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>) & FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>>;
551
553
  type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
552
554
  readonly type: "parallel";
553
555
  readonly states: infer Children extends Machine.StateSchemas;
554
- } ? [
555
- value: Machine.NodeSchema<Node>["Type"],
556
+ } ? WithNodeValue<Node, [
556
557
  states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
557
- ] : Node extends {
558
+ ]> : Node extends {
558
559
  readonly states: infer Children extends Machine.StateSchemas;
559
- } ? [
560
- value: Machine.NodeSchema<Node>["Type"],
560
+ } ? WithNodeValue<Node, [
561
561
  state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
562
- ] : [value: Machine.NodeSchema<Node>["Type"]] : never;
562
+ ]> : WithNodeValue<Node, []> : never;
563
563
  type FullSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
564
564
  readonly type: "parallel";
565
565
  readonly states: infer Children extends Machine.StateSchemas;
566
- } ? [
567
- input: Machine.NodeSchema<Node>["~type.make.in"],
566
+ } ? WithNodeInput<Node, [
568
567
  states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
569
- ] : Node extends {
568
+ ]> : Node extends {
570
569
  readonly states: infer Children extends Machine.StateSchemas;
571
- } ? [
572
- input: Machine.NodeSchema<Node>["~type.make.in"],
570
+ } ? WithNodeInput<Node, [
573
571
  state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>>
574
- ] : [input: Machine.NodeSchema<Node>["~type.make.in"]] : never;
572
+ ]> : WithNodeInput<Node, []> : never;
575
573
  type FullSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Machine.SnapshotByIdentifierWithPath<States, StateId, Path>;
576
574
  type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
577
- readonly [Key in Remaining]: ((...args: FullSnapshotArguments<States, Key, Prefix>) => FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
575
+ readonly [Key in Remaining]: NodeBuilderMethod<States[Key], FullSnapshotArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
578
576
  readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
579
- }, Constructed>) & {
580
- readonly from: FromCallable<FullSnapshotFromArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
581
- readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
582
- }, true>>;
583
- };
577
+ }, Constructed>, FullSnapshotFromArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
578
+ readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
579
+ }, true>>;
584
580
  };
585
581
  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 {
586
582
  readonly type: "parallel";
587
583
  readonly states: infer Children extends Machine.StateSchemas;
588
- } ? [
589
- value: Machine.NodeSchema<Node>["Type"],
584
+ } ? WithNodeValue<Node, [
590
585
  states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
591
- ] : Node extends {
586
+ ]> : Node extends {
592
587
  readonly states: infer Children extends Machine.StateSchemas;
593
- } ? [
594
- value: Machine.NodeSchema<Node>["Type"],
588
+ } ? WithNodeValue<Node, [
595
589
  state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
596
- ] : never : never;
590
+ ]> : never : never;
597
591
  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 {
598
592
  readonly type: "parallel";
599
593
  readonly states: infer Children extends Machine.StateSchemas;
600
- } ? [
601
- input: Machine.NodeSchema<Node>["~type.make.in"],
594
+ } ? WithNodeInput<Node, [
602
595
  states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
603
- ] : Node extends {
596
+ ]> : Node extends {
604
597
  readonly states: infer Children extends Machine.StateSchemas;
605
- } ? [
606
- input: Machine.NodeSchema<Node>["~type.make.in"],
598
+ } ? WithNodeInput<Node, [
607
599
  state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
608
- ] : never : never;
600
+ ]> : never : never;
609
601
  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 {
610
602
  readonly type: "parallel";
611
603
  readonly states: infer Children extends Machine.StateSchemas;
612
- } ? Machine.ParallelSnapshot<Path, Machine.NodeSchema<Node>["Type"], HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
604
+ } ? Machine.ParallelSnapshot<Path, NodeValue<Node>, HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
613
605
  readonly states: infer Children extends Machine.StateSchemas;
614
- } ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
615
- type HistorySnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string> = ((...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>) & FromMethod<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, HistorySnapshotResult<States, StateId, Prefix, Owner>>;
606
+ } ? Machine.CompoundSnapshot<Path, NodeValue<Node>, HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
607
+ type HistorySnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, HistorySnapshotResult<States, StateId, Prefix, Owner>> : ((...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>) & FromMethod<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, HistorySnapshotResult<States, StateId, Prefix, Owner>>;
616
608
  type HistorySnapshotWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string> = {
617
609
  readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
618
610
  }[ActiveStateKey<States>];
@@ -623,19 +615,15 @@ type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends
623
615
  readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
624
616
  };
625
617
  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> & {
626
- readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? ((...args: HistorySnapshotArguments<States, Key, Prefix, Owner>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
618
+ readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? NodeBuilderMethod<States[Key], HistorySnapshotArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
619
+ readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
620
+ }, Constructed>, HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
627
621
  readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
628
- }, Constructed>) & {
629
- readonly from: FromCallable<HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
630
- readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
631
- }, true>>;
632
- } : ((...args: FullSnapshotArguments<States, Key, Prefix>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
622
+ }, true>> : NodeBuilderMethod<States[Key], FullSnapshotArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
633
623
  readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
634
- }, Constructed>) & {
635
- readonly from: FromCallable<FullSnapshotFromArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
636
- readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
637
- }, true>>;
638
- };
624
+ }, Constructed>, FullSnapshotFromArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
625
+ readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
626
+ }, true>>;
639
627
  };
640
628
  type ParentPath<Path extends string> = Path extends `${infer Parent}.${infer Child}` ? Child extends `${string}.${string}` ? `${Parent}.${ParentPath<Child>}` : Parent : never;
641
629
  type IsCompoundNode<Node> = Node extends {
@@ -664,19 +652,14 @@ type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States
664
652
  type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
665
653
  readonly type: "parallel";
666
654
  readonly states: infer Children extends Machine.StateSchemas;
667
- } ? Source extends Path | `${Path}.${string}` ? (<Result extends ConstructionResult<LocalTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
668
- readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>>;
669
- } : ((value: Machine.NodeSchema<Node>["Type"], states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
670
- input: Machine.NodeSchema<Node>["~type.make.in"],
655
+ } ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>> : NodeMethod<Node, WithNodeValue<Node, [
656
+ states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
657
+ ]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
671
658
  states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
672
- ], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : Node extends {
659
+ ]>> : Node extends {
673
660
  readonly states: infer Children extends Machine.StateSchemas;
674
- } ? (<Result extends ConstructionResult<LocalTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
675
- readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>>;
676
- } : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
677
- input: Machine.NodeSchema<Node>["~type.make.in"]
678
- ], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
679
- type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope extends Machine.StateIdentifier<States>, Source extends Machine.StateNodeIdentifier<States>> = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ? LocalTargetBuilderWithPrefix<States, Children, Scope, Source> & {
661
+ } ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>> : NodeMethod<Node, WithNodeValue<Node, []>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, []>> : never;
662
+ type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope extends Machine.StateIdentifier<States>, Source extends Machine.StateNodeIdentifier<States>> = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ? LocalTargetBuilderWithPrefix<States, Children, Scope, Source> & (Scope extends Machine.ValuedStateIdentifier<States> ? {
680
663
  /**
681
664
  * Updates the value of the state containing the local group and moves to
682
665
  * one of the states inside it. Values in other active branches are kept.
@@ -686,7 +669,7 @@ type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope exten
686
669
  readonly with: (<Result extends ConstructionResult<LocalTargetResultWithPrefix<States, Children, Scope>>>(value: Machine.StateByIdentifier<States, Scope>, state: (builder: LocalTargetBuilderWithPrefix<States, Children, Scope, Source>) => Result) => Result) & {
687
670
  readonly from: ConstructionSelectorFromCallable<Machine.SchemaByIdentifier<States, Scope>["~type.make.in"], LocalTargetBuilderWithPrefix<States, Children, Scope, Source>, LocalTargetResultWithPrefix<States, Children, Scope>>;
688
671
  };
689
- } : {};
672
+ } : {}) : {};
690
673
  type BranchTargetResult<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends {
691
674
  readonly states: infer Children extends Machine.StateSchemas;
692
675
  } ? States[StateId] extends {
@@ -703,18 +686,13 @@ type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, State
703
686
  type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
704
687
  readonly type: "parallel";
705
688
  readonly states: infer Children extends Machine.StateSchemas;
706
- } ? Source extends Path | `${Path}.${string}` ? (<Result extends ConstructionResult<BranchTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
707
- readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>>;
708
- } & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : ((value: Machine.NodeSchema<Node>["Type"], states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
709
- input: Machine.NodeSchema<Node>["~type.make.in"],
689
+ } ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethod<Node, WithNodeValue<Node, [
690
+ states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
691
+ ]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
710
692
  states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
711
- ], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : Node extends {
693
+ ]>> : Node extends {
712
694
  readonly states: infer Children extends Machine.StateSchemas;
713
- } ? (<Result extends ConstructionResult<BranchTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
714
- readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>>;
715
- } & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
716
- input: Machine.NodeSchema<Node>["~type.make.in"]
717
- ], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
695
+ } ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethod<Node, WithNodeValue<Node, []>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, []>> : never;
718
696
  type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.StateNodeIdentifier<States>> = {
719
697
  readonly [Key in Root]: BranchTargetMethod<States, States, Key, "", Source>;
720
698
  };
@@ -735,13 +713,16 @@ type HasDirectShallowHistory<States extends Machine.StateSchemas> = {
735
713
  readonly history: "deep";
736
714
  } ? never : Key;
737
715
  }[HistoryStateKey<States>] extends never ? false : true;
716
+ type HasValuedActiveChild<States extends Machine.StateSchemas> = {
717
+ readonly [Key in ActiveStateKey<States>]: Machine.NodeSchema<States[Key]> extends never ? never : Key;
718
+ }[ActiveStateKey<States>] extends never ? false : true;
738
719
  type InitializerClosureForNode<AllStates extends Machine.StateSchemas, Node, Path extends string> = Node extends {
739
720
  readonly type: "parallel";
740
721
  readonly states: infer Children extends Machine.StateSchemas;
741
- } ? Extract<Path, Machine.StateIdentifier<AllStates>> | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
722
+ } ? (HasValuedActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never) | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
742
723
  readonly states: infer Children extends Machine.StateSchemas;
743
724
  readonly initial: infer Initial;
744
- } ? Extract<Path, Machine.StateIdentifier<AllStates>> | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<AllStates, Children[Initial], Machine.JoinPath<Path, Initial>> : never) : never;
725
+ } ? (Initial extends ActiveStateKey<Children> ? Machine.NodeSchema<Children[Initial]> extends never ? never : Extract<Path, Machine.StateIdentifier<AllStates>> : never) | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<AllStates, Children[Initial], Machine.JoinPath<Path, Initial>> : never) : never;
745
726
  type InitializerClosuresForChildren<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
746
727
  readonly [Key in ActiveStateKey<States>]: InitializerClosureForNode<AllStates, States[Key], Machine.JoinPath<Prefix, Key>>;
747
728
  }[ActiveStateKey<States>];
@@ -1280,8 +1261,9 @@ export declare namespace Machine {
1280
1261
  * Descriptive annotations exposed for compiled state nodes.
1281
1262
  *
1282
1263
  * Schema-backed states resolve their complete Effect Schema annotation map.
1283
- * Pseudo-states accept only the descriptive fields below. Annotations never
1284
- * affect state identity, targeting, or runtime behavior.
1264
+ * Schema-less active states and pseudo-states accept only the descriptive
1265
+ * fields below. Annotations never affect state identity, targeting, or
1266
+ * runtime behavior.
1285
1267
  *
1286
1268
  * @category models
1287
1269
  * @since 0.4.0
@@ -1291,10 +1273,13 @@ export declare namespace Machine {
1291
1273
  readonly description?: string | undefined;
1292
1274
  readonly documentation?: string | undefined;
1293
1275
  }
1294
- /** Descriptive annotations accepted by schema-less pseudo-states. */
1295
- type PseudoStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
1276
+ /** Descriptive annotations accepted by schema-less active and pseudo-states. */
1277
+ type SchemaLessStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
1278
+ /** @deprecated Use {@link SchemaLessStateAnnotations}. */
1279
+ type PseudoStateAnnotations = SchemaLessStateAnnotations;
1296
1280
  /**
1297
- * Configuration accepted for an atomic object state node.
1281
+ * Configuration accepted for an atomic object state node. Omit `schema` when
1282
+ * the state owns no value; a schema-less final may still declare `output`.
1298
1283
  *
1299
1284
  * @category models
1300
1285
  * @since 0.4.0
@@ -1303,35 +1288,63 @@ export declare namespace Machine {
1303
1288
  readonly schema: TaggedSchema;
1304
1289
  readonly type?: "active";
1305
1290
  readonly output?: never;
1291
+ readonly annotations?: never;
1306
1292
  } | {
1307
1293
  readonly schema: TaggedSchema;
1308
1294
  readonly type: "final";
1309
1295
  readonly output?: Schema.Top;
1296
+ readonly annotations?: never;
1297
+ } | {
1298
+ readonly schema?: never;
1299
+ readonly type?: "active";
1300
+ readonly output?: never;
1301
+ readonly annotations?: SchemaLessStateAnnotations;
1302
+ } | {
1303
+ readonly schema?: never;
1304
+ readonly type: "final";
1305
+ readonly output?: Schema.Top;
1306
+ readonly annotations?: SchemaLessStateAnnotations;
1310
1307
  };
1311
1308
  /**
1312
- * Configuration accepted for a compound object state node.
1309
+ * Configuration accepted for a compound object state node. Omit `schema`
1310
+ * when the compound state exists only to own control topology.
1313
1311
  *
1314
1312
  * @category models
1315
1313
  * @since 0.4.0
1316
1314
  */
1317
- interface CompoundStateNodeConfig {
1315
+ type CompoundStateNodeConfig = {
1318
1316
  readonly schema: TaggedSchema;
1319
1317
  readonly type?: "active";
1320
1318
  readonly initial: string;
1321
1319
  readonly states: StateTree;
1322
- }
1320
+ readonly annotations?: never;
1321
+ } | {
1322
+ readonly schema?: never;
1323
+ readonly type?: "active";
1324
+ readonly initial: string;
1325
+ readonly states: StateTree;
1326
+ readonly annotations?: SchemaLessStateAnnotations;
1327
+ };
1323
1328
  /**
1324
- * Configuration accepted for a parallel object state node.
1329
+ * Configuration accepted for a parallel object state node. Omit `schema`
1330
+ * when the parallel state exists only to own its regions.
1325
1331
  *
1326
1332
  * @category models
1327
1333
  * @since 0.4.0
1328
1334
  */
1329
- interface ParallelStateNodeConfig {
1335
+ type ParallelStateNodeConfig = {
1330
1336
  readonly schema: TaggedSchema;
1331
1337
  readonly type: "parallel";
1332
1338
  readonly output?: Schema.Top;
1333
1339
  readonly states: StateTree;
1334
- }
1340
+ readonly annotations?: never;
1341
+ } | {
1342
+ readonly schema?: never;
1343
+ readonly type: "parallel";
1344
+ readonly output?: Schema.Top;
1345
+ readonly states: StateTree;
1346
+ readonly annotations?: SchemaLessStateAnnotations;
1347
+ };
1335
1348
  /**
1336
1349
  * Pseudo-state that restores the last active configuration of its parent.
1337
1350
  *
@@ -1348,7 +1361,7 @@ export declare namespace Machine {
1348
1361
  readonly type: "history";
1349
1362
  /** Defaults to shallow history. */
1350
1363
  readonly history?: "shallow" | "deep";
1351
- readonly annotations?: PseudoStateAnnotations;
1364
+ readonly annotations?: SchemaLessStateAnnotations;
1352
1365
  }
1353
1366
  /**
1354
1367
  * Transient decision pseudo-state resolved immediately when targeted.
@@ -1362,7 +1375,7 @@ export declare namespace Machine {
1362
1375
  */
1363
1376
  interface ChoiceStateNodeConfig {
1364
1377
  readonly type: "choice";
1365
- readonly annotations?: PseudoStateAnnotations;
1378
+ readonly annotations?: SchemaLessStateAnnotations;
1366
1379
  }
1367
1380
  /**
1368
1381
  * Configuration accepted for an object state node.
@@ -1423,11 +1436,17 @@ export declare namespace Machine {
1423
1436
  /** Type-safe builders for constructing valid initial snapshots. */
1424
1437
  readonly initial: InitialBuilder<States>;
1425
1438
  /**
1426
- * Returns the decoded value for an active state path.
1439
+ * Returns the decoded value for an active state path. The supplied
1440
+ * snapshot may be a complete root snapshot or a snapshot previously
1441
+ * extracted from this definition. Extracted snapshots accept only their
1442
+ * own absolute path and descendant paths.
1427
1443
  *
1428
1444
  * @since 0.4.0
1429
1445
  */
1430
- readonly get: <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<StateByIdentifier<States, Path>>;
1446
+ readonly get: {
1447
+ <Path extends ValuedStateIdentifier<States>>(snapshot: Snapshot<States>, path: Path): Option.Option<StateByIdentifier<States, Path>>;
1448
+ <const From extends StateIdentifier<States>, const Path extends ValuedStateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | `${NoInfer<From>}.${string}` ? unknown : never)): Option.Option<StateByIdentifier<States, Path>>;
1449
+ };
1431
1450
  /**
1432
1451
  * Returns the decoded value for an active state path together with all of
1433
1452
  * its active parent values.
@@ -1438,19 +1457,31 @@ export declare namespace Machine {
1438
1457
  *
1439
1458
  * @since 0.4.0
1440
1459
  */
1441
- readonly getWithParents: <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<StateWithParents<States, Path>>;
1460
+ readonly getWithParents: <Path extends ValuedStateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<StateWithParents<States, Path>>;
1442
1461
  /**
1443
- * Returns the snapshot for an active state path.
1462
+ * Returns the snapshot for an active state path. The supplied snapshot may
1463
+ * be a complete root snapshot or a snapshot previously extracted from this
1464
+ * definition. Extracted snapshots accept only their own absolute path and
1465
+ * descendant paths.
1444
1466
  *
1445
1467
  * @since 0.4.0
1446
1468
  */
1447
- readonly getSnapshot: <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<SnapshotByIdentifier<States, Path>>;
1469
+ readonly getSnapshot: {
1470
+ <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path): Option.Option<SnapshotByIdentifier<States, Path>>;
1471
+ <const From extends StateIdentifier<States>, const Path extends StateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | `${NoInfer<From>}.${string}` ? unknown : never)): Option.Option<SnapshotByIdentifier<States, Path>>;
1472
+ };
1448
1473
  /**
1449
- * Returns whether a state path is active in the snapshot.
1474
+ * Returns whether a state path is active in the snapshot. The supplied
1475
+ * snapshot may be a complete root snapshot or a snapshot previously
1476
+ * extracted from this definition. Extracted snapshots accept only their
1477
+ * own absolute path and descendant paths.
1450
1478
  *
1451
1479
  * @since 0.4.0
1452
1480
  */
1453
- readonly matches: <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => boolean;
1481
+ readonly matches: {
1482
+ <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path): boolean;
1483
+ <const From extends StateIdentifier<States>, const Path extends StateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | `${NoInfer<From>}.${string}` ? unknown : never)): boolean;
1484
+ };
1454
1485
  }
1455
1486
  /**
1456
1487
  * Validates the nested shape of state schema definitions.
@@ -1463,14 +1494,14 @@ export declare namespace Machine {
1463
1494
  interface StateNodeBase<Path extends string = string> {
1464
1495
  readonly path: Path;
1465
1496
  readonly key: string;
1466
- /** Resolved Effect Schema annotations, or descriptive pseudo-state annotations. */
1497
+ /** Resolved schema annotations, or descriptive schema-less-state annotations. */
1467
1498
  readonly annotations: Readonly<StateNodeAnnotations> | undefined;
1468
1499
  readonly order: number;
1469
1500
  }
1470
1501
  /** Runtime metadata for a compiled atomic state. */
1471
1502
  interface AtomicStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
1472
1503
  readonly type: "atomic";
1473
- readonly schema: TaggedSchema;
1504
+ readonly schema: TaggedSchema | undefined;
1474
1505
  readonly output: undefined;
1475
1506
  readonly history: undefined;
1476
1507
  readonly parent: ActivePath | undefined;
@@ -1480,7 +1511,7 @@ export declare namespace Machine {
1480
1511
  /** Runtime metadata for a compiled compound state. */
1481
1512
  interface CompoundStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath, ChoicePath extends string = ActivePath> extends StateNodeBase<OwnPath> {
1482
1513
  readonly type: "compound";
1483
- readonly schema: TaggedSchema;
1514
+ readonly schema: TaggedSchema | undefined;
1484
1515
  readonly output: undefined;
1485
1516
  readonly history: undefined;
1486
1517
  readonly parent: ActivePath | undefined;
@@ -1491,7 +1522,7 @@ export declare namespace Machine {
1491
1522
  /** Runtime metadata for a compiled parallel state. */
1492
1523
  interface ParallelStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
1493
1524
  readonly type: "parallel";
1494
- readonly schema: TaggedSchema;
1525
+ readonly schema: TaggedSchema | undefined;
1495
1526
  readonly output: Schema.Top | undefined;
1496
1527
  readonly history: undefined;
1497
1528
  readonly parent: ActivePath | undefined;
@@ -1502,7 +1533,7 @@ export declare namespace Machine {
1502
1533
  /** Runtime metadata for a compiled final state. */
1503
1534
  interface FinalStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
1504
1535
  readonly type: "final";
1505
- readonly schema: TaggedSchema;
1536
+ readonly schema: TaggedSchema | undefined;
1506
1537
  readonly output: Schema.Top | undefined;
1507
1538
  readonly history: undefined;
1508
1539
  readonly parent: ActivePath | undefined;
@@ -1662,6 +1693,10 @@ export declare namespace Machine {
1662
1693
  * @since 0.4.0
1663
1694
  */
1664
1695
  type StateIdentifier<States extends StateSchemas> = StateIdentifierWithPrefix<States>;
1696
+ /** Extracts active state paths whose definitions declare a state value schema. */
1697
+ type ValuedStateIdentifier<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? NodeSchema<NodeByIdentifier<States, StateId>> extends never ? never : StateId : never : never;
1698
+ /** Extracts active state paths whose definitions intentionally omit a state value schema. */
1699
+ type StructuralStateIdentifier<States extends StateSchemas> = Exclude<StateIdentifier<States>, ValuedStateIdentifier<States>>;
1665
1700
  /**
1666
1701
  * Extracts the state path values represented by a state definition under a
1667
1702
  * parent path prefix.
@@ -1789,7 +1824,7 @@ export declare namespace Machine {
1789
1824
  * @category utility types
1790
1825
  * @since 0.4.0
1791
1826
  */
1792
- type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = Extract<StateOf<States>, SchemaByIdentifier<States, StateId>["Type"]>;
1827
+ type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends ValuedStateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : undefined;
1793
1828
  /**
1794
1829
  * Extracts every parent state path from a state identifier.
1795
1830
  *
@@ -1811,7 +1846,7 @@ export declare namespace Machine {
1811
1846
  * @since 0.4.0
1812
1847
  */
1813
1848
  type ParentStateValues<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
1814
- readonly [Parent in Extract<ParentStateIdentifier<StateId>, StateIdentifier<States>>]: StateByIdentifier<States, Parent>;
1849
+ readonly [Parent in Extract<ParentStateIdentifier<StateId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
1815
1850
  } : never;
1816
1851
  /**
1817
1852
  * Extracts the nearest parent value, or `undefined` for a root state.
@@ -1819,7 +1854,7 @@ export declare namespace Machine {
1819
1854
  * @category utility types
1820
1855
  * @since 0.4.0
1821
1856
  */
1822
- type ParentStateValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? Extract<ImmediateParentStateIdentifier<StateId>, StateIdentifier<States>> extends infer Parent ? [Parent] extends [never] ? undefined : Parent extends StateIdentifier<States> ? StateByIdentifier<States, Parent> : undefined : undefined : never;
1857
+ type ParentStateValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? Extract<ImmediateParentStateIdentifier<StateId>, StateIdentifier<States>> extends infer Parent ? [Parent] extends [never] ? undefined : Parent extends ValuedStateIdentifier<States> ? StateByIdentifier<States, Parent> : undefined : undefined : never;
1823
1858
  /**
1824
1859
  * Represents a decoded state value together with all of its parent values.
1825
1860
  *
@@ -1936,7 +1971,7 @@ export declare namespace Machine {
1936
1971
  */
1937
1972
  interface EncodedSnapshotState {
1938
1973
  readonly path: string;
1939
- readonly value: unknown;
1974
+ readonly value?: unknown;
1940
1975
  }
1941
1976
  /**
1942
1977
  * Encoded output for one completed state path in a normalized machine
@@ -2085,9 +2120,9 @@ export declare namespace Machine {
2085
2120
  type SnapshotByIdentifierWithPath<States extends StateSchemas, StateId extends ActiveStateKey<States>, Path extends string> = States[StateId] extends {
2086
2121
  readonly type: "parallel";
2087
2122
  readonly states: infer Children;
2088
- } ? Children extends StateSchemas ? ParallelSnapshot<Path, NodeSchema<States[StateId]>["Type"], SnapshotRegionsWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]> : States[StateId] extends {
2123
+ } ? Children extends StateSchemas ? ParallelSnapshot<Path, NodeValue<States[StateId]>, SnapshotRegionsWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeValue<States[StateId]>> : States[StateId] extends {
2089
2124
  readonly states: infer Children;
2090
- } ? Children extends StateSchemas ? CompoundSnapshot<Path, NodeSchema<States[StateId]>["Type"], SnapshotWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]>;
2125
+ } ? Children extends StateSchemas ? CompoundSnapshot<Path, NodeValue<States[StateId]>, SnapshotWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeValue<States[StateId]>> : AtomicSnapshot<Path, NodeValue<States[StateId]>>;
2091
2126
  /**
2092
2127
  * Extracts a complete root snapshot whose selected configuration contains a
2093
2128
  * particular active state.
@@ -2172,7 +2207,7 @@ export declare namespace Machine {
2172
2207
  readonly path: StateId;
2173
2208
  readonly value: StateByIdentifier<States, StateId>;
2174
2209
  readonly values?: Partial<{
2175
- readonly [AncestorStateId in StateIdentifier<States>]: StateByIdentifier<States, AncestorStateId>;
2210
+ readonly [AncestorStateId in ValuedStateIdentifier<States>]: StateByIdentifier<States, AncestorStateId>;
2176
2211
  }>;
2177
2212
  }
2178
2213
  /**
@@ -2413,7 +2448,7 @@ export declare namespace Machine {
2413
2448
  interface ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
2414
2449
  readonly parent: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
2415
2450
  readonly parents: {
2416
- readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, StateIdentifier<States>>]: StateByIdentifier<States, Parent>;
2451
+ readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
2417
2452
  };
2418
2453
  readonly event: LifecycleEvent<Events>;
2419
2454
  readonly target: TargetBuilder<States, ChoiceId>;
@@ -2801,11 +2836,11 @@ export declare namespace Machine {
2801
2836
  readonly type: "parallel";
2802
2837
  readonly states: infer Children extends StateSchemas;
2803
2838
  } ? {
2804
- readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]>["Type"];
2839
+ readonly [Key in ActiveStateKey<Children> as NodeSchema<Children[Key]> extends never ? never : Key]: NodeValue<Children[Key]>;
2805
2840
  } : Node extends {
2806
2841
  readonly states: infer Children extends StateSchemas;
2807
2842
  readonly initial: infer Initial;
2808
- } ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]>["Type"] : never : never : never;
2843
+ } ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : NodeValue<Children[Initial]> : never : never : never;
2809
2844
  /** Context passed to an implicit child-state initializer. */
2810
2845
  type StateInitialContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = StateActionContext<States, Events, Emits, StateId>;
2811
2846
  /** Initial child value implementation for a compound or parallel state. */
@@ -3115,7 +3150,9 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
3115
3150
  *
3116
3151
  * The returned `states` property is the same object passed to `defineStates`.
3117
3152
  * The returned `initial` builder creates snapshots without user-authored path
3118
- * strings and enforces compound and parallel initial-state rules.
3153
+ * strings and enforces compound and parallel initial-state rules. Active nodes
3154
+ * may omit `schema` when they own no value; those builders expose `.from(...)`
3155
+ * and still participate fully in targeting, matching, and snapshots.
3119
3156
  *
3120
3157
  * **Example** (Atomic initial snapshot)
3121
3158
  *