@typeonce/effect-machine 0.7.0 → 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.
- package/README.md +21 -0
- package/dist/Machine.d.ts +159 -140
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +3 -1
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +8 -2
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +103 -20
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +6 -0
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.js +1 -1
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +22 -16
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +10 -0
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +45 -35
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/serialization.d.ts.map +1 -1
- package/dist/internal/machine/serialization.js +53 -21
- package/dist/internal/machine/serialization.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +4 -4
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +18 -11
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +5 -5
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +16 -13
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +10 -3
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +8 -2
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +56 -28
- package/package.json +2 -2
- package/src/Machine.ts +371 -296
- package/src/internal/machine/atom.ts +10 -3
- package/src/internal/machine/configuration.ts +102 -23
- package/src/internal/machine/executionPlan.ts +6 -0
- package/src/internal/machine/invocation.ts +1 -1
- package/src/internal/machine/machine.ts +85 -57
- package/src/internal/machine/planner.ts +49 -38
- package/src/internal/machine/serialization.ts +56 -31
- package/src/internal/machine/stateDefinition.ts +22 -11
- package/src/internal/machine/topology.ts +21 -18
- package/src/internal/testing/machine/verification.ts +13 -3
- package/src/unstable/reactivity/AtomMachine.ts +9 -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 :
|
|
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 :
|
|
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,
|
|
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,
|
|
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]:
|
|
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
|
|
541
|
-
|
|
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
|
-
] :
|
|
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
|
-
] :
|
|
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]:
|
|
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
|
|
581
|
-
|
|
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,
|
|
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,
|
|
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}` ?
|
|
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 & {
|
|
627
619
|
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
628
|
-
}, Constructed
|
|
629
|
-
readonly
|
|
630
|
-
|
|
631
|
-
}, true>>;
|
|
632
|
-
} : ((...args: FullSnapshotArguments<States, Key, Prefix>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
620
|
+
}, Constructed>, HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
621
|
+
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
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
|
|
636
|
-
|
|
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}` ?
|
|
668
|
-
|
|
669
|
-
|
|
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
|
-
]
|
|
659
|
+
]>> : Node extends {
|
|
673
660
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
674
|
-
} ?
|
|
675
|
-
|
|
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}` ?
|
|
707
|
-
|
|
708
|
-
|
|
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
|
-
]
|
|
693
|
+
]>> : Node extends {
|
|
712
694
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
713
|
-
} ?
|
|
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
|
-
*
|
|
1284
|
-
* affect state identity, targeting, or
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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?:
|
|
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?:
|
|
1378
|
+
readonly annotations?: SchemaLessStateAnnotations;
|
|
1366
1379
|
}
|
|
1367
1380
|
/**
|
|
1368
1381
|
* Configuration accepted for an object state node.
|
|
@@ -1431,8 +1444,8 @@ export declare namespace Machine {
|
|
|
1431
1444
|
* @since 0.4.0
|
|
1432
1445
|
*/
|
|
1433
1446
|
readonly get: {
|
|
1434
|
-
<Path extends
|
|
1435
|
-
<const From extends StateIdentifier<States>, const Path extends
|
|
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>>;
|
|
1436
1449
|
};
|
|
1437
1450
|
/**
|
|
1438
1451
|
* Returns the decoded value for an active state path together with all of
|
|
@@ -1444,7 +1457,7 @@ export declare namespace Machine {
|
|
|
1444
1457
|
*
|
|
1445
1458
|
* @since 0.4.0
|
|
1446
1459
|
*/
|
|
1447
|
-
readonly getWithParents: <Path extends
|
|
1460
|
+
readonly getWithParents: <Path extends ValuedStateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<StateWithParents<States, Path>>;
|
|
1448
1461
|
/**
|
|
1449
1462
|
* Returns the snapshot for an active state path. The supplied snapshot may
|
|
1450
1463
|
* be a complete root snapshot or a snapshot previously extracted from this
|
|
@@ -1481,14 +1494,14 @@ export declare namespace Machine {
|
|
|
1481
1494
|
interface StateNodeBase<Path extends string = string> {
|
|
1482
1495
|
readonly path: Path;
|
|
1483
1496
|
readonly key: string;
|
|
1484
|
-
/** Resolved
|
|
1497
|
+
/** Resolved schema annotations, or descriptive schema-less-state annotations. */
|
|
1485
1498
|
readonly annotations: Readonly<StateNodeAnnotations> | undefined;
|
|
1486
1499
|
readonly order: number;
|
|
1487
1500
|
}
|
|
1488
1501
|
/** Runtime metadata for a compiled atomic state. */
|
|
1489
1502
|
interface AtomicStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1490
1503
|
readonly type: "atomic";
|
|
1491
|
-
readonly schema: TaggedSchema;
|
|
1504
|
+
readonly schema: TaggedSchema | undefined;
|
|
1492
1505
|
readonly output: undefined;
|
|
1493
1506
|
readonly history: undefined;
|
|
1494
1507
|
readonly parent: ActivePath | undefined;
|
|
@@ -1498,7 +1511,7 @@ export declare namespace Machine {
|
|
|
1498
1511
|
/** Runtime metadata for a compiled compound state. */
|
|
1499
1512
|
interface CompoundStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath, ChoicePath extends string = ActivePath> extends StateNodeBase<OwnPath> {
|
|
1500
1513
|
readonly type: "compound";
|
|
1501
|
-
readonly schema: TaggedSchema;
|
|
1514
|
+
readonly schema: TaggedSchema | undefined;
|
|
1502
1515
|
readonly output: undefined;
|
|
1503
1516
|
readonly history: undefined;
|
|
1504
1517
|
readonly parent: ActivePath | undefined;
|
|
@@ -1509,7 +1522,7 @@ export declare namespace Machine {
|
|
|
1509
1522
|
/** Runtime metadata for a compiled parallel state. */
|
|
1510
1523
|
interface ParallelStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1511
1524
|
readonly type: "parallel";
|
|
1512
|
-
readonly schema: TaggedSchema;
|
|
1525
|
+
readonly schema: TaggedSchema | undefined;
|
|
1513
1526
|
readonly output: Schema.Top | undefined;
|
|
1514
1527
|
readonly history: undefined;
|
|
1515
1528
|
readonly parent: ActivePath | undefined;
|
|
@@ -1520,7 +1533,7 @@ export declare namespace Machine {
|
|
|
1520
1533
|
/** Runtime metadata for a compiled final state. */
|
|
1521
1534
|
interface FinalStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1522
1535
|
readonly type: "final";
|
|
1523
|
-
readonly schema: TaggedSchema;
|
|
1536
|
+
readonly schema: TaggedSchema | undefined;
|
|
1524
1537
|
readonly output: Schema.Top | undefined;
|
|
1525
1538
|
readonly history: undefined;
|
|
1526
1539
|
readonly parent: ActivePath | undefined;
|
|
@@ -1680,6 +1693,10 @@ export declare namespace Machine {
|
|
|
1680
1693
|
* @since 0.4.0
|
|
1681
1694
|
*/
|
|
1682
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>>;
|
|
1683
1700
|
/**
|
|
1684
1701
|
* Extracts the state path values represented by a state definition under a
|
|
1685
1702
|
* parent path prefix.
|
|
@@ -1807,7 +1824,7 @@ export declare namespace Machine {
|
|
|
1807
1824
|
* @category utility types
|
|
1808
1825
|
* @since 0.4.0
|
|
1809
1826
|
*/
|
|
1810
|
-
type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> =
|
|
1827
|
+
type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends ValuedStateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : undefined;
|
|
1811
1828
|
/**
|
|
1812
1829
|
* Extracts every parent state path from a state identifier.
|
|
1813
1830
|
*
|
|
@@ -1829,7 +1846,7 @@ export declare namespace Machine {
|
|
|
1829
1846
|
* @since 0.4.0
|
|
1830
1847
|
*/
|
|
1831
1848
|
type ParentStateValues<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
1832
|
-
readonly [Parent in Extract<ParentStateIdentifier<StateId>,
|
|
1849
|
+
readonly [Parent in Extract<ParentStateIdentifier<StateId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
1833
1850
|
} : never;
|
|
1834
1851
|
/**
|
|
1835
1852
|
* Extracts the nearest parent value, or `undefined` for a root state.
|
|
@@ -1837,7 +1854,7 @@ export declare namespace Machine {
|
|
|
1837
1854
|
* @category utility types
|
|
1838
1855
|
* @since 0.4.0
|
|
1839
1856
|
*/
|
|
1840
|
-
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
|
|
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;
|
|
1841
1858
|
/**
|
|
1842
1859
|
* Represents a decoded state value together with all of its parent values.
|
|
1843
1860
|
*
|
|
@@ -1954,7 +1971,7 @@ export declare namespace Machine {
|
|
|
1954
1971
|
*/
|
|
1955
1972
|
interface EncodedSnapshotState {
|
|
1956
1973
|
readonly path: string;
|
|
1957
|
-
readonly value
|
|
1974
|
+
readonly value?: unknown;
|
|
1958
1975
|
}
|
|
1959
1976
|
/**
|
|
1960
1977
|
* Encoded output for one completed state path in a normalized machine
|
|
@@ -2103,9 +2120,9 @@ export declare namespace Machine {
|
|
|
2103
2120
|
type SnapshotByIdentifierWithPath<States extends StateSchemas, StateId extends ActiveStateKey<States>, Path extends string> = States[StateId] extends {
|
|
2104
2121
|
readonly type: "parallel";
|
|
2105
2122
|
readonly states: infer Children;
|
|
2106
|
-
} ? Children extends StateSchemas ? ParallelSnapshot<Path,
|
|
2123
|
+
} ? Children extends StateSchemas ? ParallelSnapshot<Path, NodeValue<States[StateId]>, SnapshotRegionsWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeValue<States[StateId]>> : States[StateId] extends {
|
|
2107
2124
|
readonly states: infer Children;
|
|
2108
|
-
} ? Children extends StateSchemas ? CompoundSnapshot<Path,
|
|
2125
|
+
} ? Children extends StateSchemas ? CompoundSnapshot<Path, NodeValue<States[StateId]>, SnapshotWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeValue<States[StateId]>> : AtomicSnapshot<Path, NodeValue<States[StateId]>>;
|
|
2109
2126
|
/**
|
|
2110
2127
|
* Extracts a complete root snapshot whose selected configuration contains a
|
|
2111
2128
|
* particular active state.
|
|
@@ -2190,7 +2207,7 @@ export declare namespace Machine {
|
|
|
2190
2207
|
readonly path: StateId;
|
|
2191
2208
|
readonly value: StateByIdentifier<States, StateId>;
|
|
2192
2209
|
readonly values?: Partial<{
|
|
2193
|
-
readonly [AncestorStateId in
|
|
2210
|
+
readonly [AncestorStateId in ValuedStateIdentifier<States>]: StateByIdentifier<States, AncestorStateId>;
|
|
2194
2211
|
}>;
|
|
2195
2212
|
}
|
|
2196
2213
|
/**
|
|
@@ -2431,7 +2448,7 @@ export declare namespace Machine {
|
|
|
2431
2448
|
interface ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
|
|
2432
2449
|
readonly parent: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
|
|
2433
2450
|
readonly parents: {
|
|
2434
|
-
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>,
|
|
2451
|
+
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
2435
2452
|
};
|
|
2436
2453
|
readonly event: LifecycleEvent<Events>;
|
|
2437
2454
|
readonly target: TargetBuilder<States, ChoiceId>;
|
|
@@ -2819,11 +2836,11 @@ export declare namespace Machine {
|
|
|
2819
2836
|
readonly type: "parallel";
|
|
2820
2837
|
readonly states: infer Children extends StateSchemas;
|
|
2821
2838
|
} ? {
|
|
2822
|
-
readonly [Key in ActiveStateKey<Children>
|
|
2839
|
+
readonly [Key in ActiveStateKey<Children> as NodeSchema<Children[Key]> extends never ? never : Key]: NodeValue<Children[Key]>;
|
|
2823
2840
|
} : Node extends {
|
|
2824
2841
|
readonly states: infer Children extends StateSchemas;
|
|
2825
2842
|
readonly initial: infer Initial;
|
|
2826
|
-
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]>[
|
|
2843
|
+
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : NodeValue<Children[Initial]> : never : never : never;
|
|
2827
2844
|
/** Context passed to an implicit child-state initializer. */
|
|
2828
2845
|
type StateInitialContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = StateActionContext<States, Events, Emits, StateId>;
|
|
2829
2846
|
/** Initial child value implementation for a compound or parallel state. */
|
|
@@ -3133,7 +3150,9 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
3133
3150
|
*
|
|
3134
3151
|
* The returned `states` property is the same object passed to `defineStates`.
|
|
3135
3152
|
* The returned `initial` builder creates snapshots without user-authored path
|
|
3136
|
-
* 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.
|
|
3137
3156
|
*
|
|
3138
3157
|
* **Example** (Atomic initial snapshot)
|
|
3139
3158
|
*
|