@typeonce/effect-machine 0.12.0 → 0.14.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 +130 -30
- package/dist/Machine.d.ts +722 -262
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +130 -62
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +1 -0
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +23 -0
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.js +2 -5
- package/dist/internal/machine/commandRuntime.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +5 -0
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +6 -2
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +1 -0
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +57 -24
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/initialization.d.ts +5 -0
- package/dist/internal/machine/initialization.d.ts.map +1 -0
- package/dist/internal/machine/initialization.js +61 -0
- package/dist/internal/machine/initialization.js.map +1 -0
- package/dist/internal/machine/inspectionRuntime.d.ts +25 -0
- package/dist/internal/machine/inspectionRuntime.d.ts.map +1 -0
- package/dist/internal/machine/inspectionRuntime.js +79 -0
- package/dist/internal/machine/inspectionRuntime.js.map +1 -0
- package/dist/internal/machine/invocation.d.ts +2 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +17 -10
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +4 -3
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +327 -32
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +28 -0
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +132 -51
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +4 -2
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +27 -3
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +440 -64
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/symbols.d.ts +2 -0
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js +2 -0
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +25 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +26 -10
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
- package/dist/internal/testing/machine/exploration.js +11 -2
- package/dist/internal/testing/machine/exploration.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +75 -69
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/transitionCoverage.d.ts +20 -0
- package/dist/internal/testing/machine/transitionCoverage.d.ts.map +1 -0
- package/dist/internal/testing/machine/transitionCoverage.js +80 -0
- package/dist/internal/testing/machine/transitionCoverage.js.map +1 -0
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +171 -33
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +97 -22
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +58 -16
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +4 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +4 -1
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +21 -3
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +21 -3
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +240 -65
- package/package.json +5 -5
- package/src/Machine.ts +1240 -495
- package/src/internal/machine/atom.ts +26 -0
- package/src/internal/machine/commandRuntime.ts +2 -9
- package/src/internal/machine/configuration.ts +28 -3
- package/src/internal/machine/executionPlan.ts +72 -24
- package/src/internal/machine/initialization.ts +73 -0
- package/src/internal/machine/inspectionRuntime.ts +102 -0
- package/src/internal/machine/invocation.ts +37 -12
- package/src/internal/machine/machine.ts +438 -39
- package/src/internal/machine/planner.ts +180 -55
- package/src/internal/machine/process.ts +4 -2
- package/src/internal/machine/runtime.ts +661 -89
- package/src/internal/machine/symbols.ts +3 -0
- package/src/internal/machine/topology.ts +65 -12
- package/src/internal/testing/machine/exploration.ts +10 -2
- package/src/internal/testing/machine/finiteModel.ts +114 -80
- package/src/internal/testing/machine/transitionCoverage.ts +116 -0
- package/src/internal/testing/machine/verification.ts +216 -58
- package/src/testing/MachineTest.ts +118 -28
- package/src/unstable/cluster/ClusterMachine.ts +4 -1
- package/src/unstable/reactivity/AtomMachine.ts +24 -3
package/dist/Machine.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import type * as Cause from "effect/Cause";
|
|
7
7
|
import type * as Duration from "effect/Duration";
|
|
8
8
|
import type * as Effect from "effect/Effect";
|
|
9
|
+
import type * as Exit from "effect/Exit";
|
|
9
10
|
import type * as Option from "effect/Option";
|
|
10
11
|
import type { Pipeable } from "effect/Pipeable";
|
|
11
12
|
import type * as Schema from "effect/Schema";
|
|
@@ -40,6 +41,7 @@ declare const MachineTypeId: unique symbol;
|
|
|
40
41
|
declare const EventConstructionTypeId: unique symbol;
|
|
41
42
|
declare const EmittedEventConstructionTypeId: unique symbol;
|
|
42
43
|
declare const EventProtocolTypeId: unique symbol;
|
|
44
|
+
declare const TransitionCaseTypeId: unique symbol;
|
|
43
45
|
declare const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId;
|
|
44
46
|
/**
|
|
45
47
|
* Type identifier used for the synthetic event passed to startup lifecycle
|
|
@@ -175,6 +177,8 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
175
177
|
readonly invoke: Invoker<States, Events, Emits, InputEvents, ParentEvents>;
|
|
176
178
|
/** @internal */
|
|
177
179
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
|
|
180
|
+
/** @internal */
|
|
181
|
+
readonly initialDefinition: Machine.InitialDefinition;
|
|
178
182
|
}
|
|
179
183
|
export {
|
|
180
184
|
/**
|
|
@@ -411,6 +415,7 @@ export declare namespace Runtime {
|
|
|
411
415
|
type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? Requirements : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : Requirements;
|
|
412
416
|
type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? never : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : never;
|
|
413
417
|
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
418
|
+
declare const TransitionTypeId: typeof internal.TransitionTypeId;
|
|
414
419
|
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
415
420
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
416
421
|
readonly path: Path;
|
|
@@ -534,13 +539,30 @@ type NodeBuilderMethod<Node, Arguments extends ReadonlyArray<unknown>, Result, F
|
|
|
534
539
|
readonly from: FromCallable<FromArguments, FromResult>;
|
|
535
540
|
};
|
|
536
541
|
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>;
|
|
542
|
+
type NodeMethodWithInitial<Node, Arguments extends ReadonlyArray<unknown>, Result, FromArguments extends ReadonlyArray<unknown>, Path extends string> = Machine.NodeSchema<Node> extends never ? {
|
|
543
|
+
readonly from: FromCallable<FromArguments, Machine.StateConstruction<Result>>;
|
|
544
|
+
readonly initial: InitialTargetFactory<Node, Path>;
|
|
545
|
+
} : ((...args: Arguments) => Result) & {
|
|
546
|
+
readonly from: FromCallable<FromArguments, Machine.StateConstruction<Result>>;
|
|
547
|
+
readonly initial: InitialTargetFactory<Node, Path>;
|
|
548
|
+
};
|
|
549
|
+
interface InitialTargetMethod<Node, Path extends string> {
|
|
550
|
+
/** Enters this state through its declared initial configuration. */
|
|
551
|
+
readonly initial: InitialTargetFactory<Node, Path>;
|
|
552
|
+
}
|
|
553
|
+
interface InitialTargetFactory<Node, Path extends string> {
|
|
554
|
+
(...args: WithNodeValue<Node, readonly []>): Machine.InitialTarget<Path>;
|
|
555
|
+
readonly from: FromCallable<WithNodeInput<Node, readonly []>, Machine.StateConstruction<Machine.InitialTarget<Path>>>;
|
|
556
|
+
}
|
|
537
557
|
type NodeConstructionSelectorFromCallable<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
|
|
538
558
|
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
539
559
|
} : ConstructionSelectorFromCallable<NodeMakeInput<Node>, Builder, Result>;
|
|
540
|
-
type NestedTargetMethod<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
|
|
560
|
+
type NestedTargetMethod<Node, Builder, Result, Path extends string> = Machine.NodeSchema<Node> extends never ? {
|
|
541
561
|
readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>;
|
|
562
|
+
readonly initial: InitialTargetFactory<Node, Path>;
|
|
542
563
|
} : (<Selected extends ConstructionResult<Result>>(value: NodeValue<Node>, state: (builder: Builder) => Selected) => Selected) & {
|
|
543
564
|
readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>;
|
|
565
|
+
readonly initial: InitialTargetFactory<Node, Path>;
|
|
544
566
|
};
|
|
545
567
|
type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input ? {
|
|
546
568
|
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
@@ -622,6 +644,14 @@ type FullSnapshotFromArguments<States extends Machine.StateSchemas, StateId exte
|
|
|
622
644
|
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>>
|
|
623
645
|
]> : WithNodeInput<Node, []> : never;
|
|
624
646
|
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>;
|
|
647
|
+
type InitialEntryStateKey<States extends Machine.StateSchemas> = {
|
|
648
|
+
readonly [Key in ActiveStateKey<States>]: States[Key] extends {
|
|
649
|
+
readonly states: Machine.StateSchemas;
|
|
650
|
+
} ? Key : never;
|
|
651
|
+
}[ActiveStateKey<States>];
|
|
652
|
+
type FullInitialTargetBuilder<States extends Machine.StateSchemas> = {
|
|
653
|
+
readonly [Key in InitialEntryStateKey<States>]: InitialTargetMethod<States[Key], Key>;
|
|
654
|
+
};
|
|
625
655
|
type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
626
656
|
readonly [Key in Remaining]: NodeBuilderMethod<States[Key], FullSnapshotArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
627
657
|
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
@@ -703,13 +733,13 @@ type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States
|
|
|
703
733
|
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 {
|
|
704
734
|
readonly type: "parallel";
|
|
705
735
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
706
|
-
} ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path
|
|
736
|
+
} ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>, Path> : NodeMethodWithInitial<Node, WithNodeValue<Node, [
|
|
707
737
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
708
738
|
]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
|
|
709
739
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
710
|
-
]
|
|
740
|
+
]>, Path> : Node extends {
|
|
711
741
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
712
|
-
} ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path
|
|
742
|
+
} ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>, Path> : NodeMethod<Node, WithNodeValue<Node, []>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, []>> : never;
|
|
713
743
|
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> ? {
|
|
714
744
|
/**
|
|
715
745
|
* Updates the value of the state containing the local group and moves to
|
|
@@ -737,13 +767,13 @@ type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, State
|
|
|
737
767
|
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 {
|
|
738
768
|
readonly type: "parallel";
|
|
739
769
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
740
|
-
} ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path
|
|
770
|
+
} ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>, Path> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethodWithInitial<Node, WithNodeValue<Node, [
|
|
741
771
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
742
772
|
]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
|
|
743
773
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
744
|
-
]
|
|
774
|
+
]>, Path> : Node extends {
|
|
745
775
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
746
|
-
} ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path
|
|
776
|
+
} ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>, Path> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethod<Node, WithNodeValue<Node, []>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, []>> : never;
|
|
747
777
|
type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.StateNodeIdentifier<States>> = {
|
|
748
778
|
readonly [Key in Root]: BranchTargetMethod<States, States, Key, "", Source>;
|
|
749
779
|
};
|
|
@@ -815,6 +845,164 @@ export type RuntimeSnapshot<State, Error = never, Output = never> = {
|
|
|
815
845
|
readonly status: "stopped";
|
|
816
846
|
readonly state: State;
|
|
817
847
|
};
|
|
848
|
+
/**
|
|
849
|
+
* Live, root-scoped records describing one prepared machine tree.
|
|
850
|
+
*
|
|
851
|
+
* Inspection records deliberately erase machine-specific values to `unknown`:
|
|
852
|
+
* one stream may contain unrelated root, child-machine, and `Logic` protocols.
|
|
853
|
+
* The record structure remains a closed discriminated union, while typed
|
|
854
|
+
* application observation continues through `changes` and `emissions`.
|
|
855
|
+
*
|
|
856
|
+
* @category models
|
|
857
|
+
* @since 0.13.0
|
|
858
|
+
*/
|
|
859
|
+
export declare namespace Inspection {
|
|
860
|
+
/** Read-only identity of a local machine endpoint. */
|
|
861
|
+
interface Endpoint {
|
|
862
|
+
readonly id: string;
|
|
863
|
+
readonly sessionId: string;
|
|
864
|
+
}
|
|
865
|
+
/** Read-only identity of a runtime represented in the inspection tree. */
|
|
866
|
+
interface Subject extends Endpoint {
|
|
867
|
+
readonly kind: "Machine" | "Logic";
|
|
868
|
+
}
|
|
869
|
+
/** Causal origin of an inspected runtime. */
|
|
870
|
+
type Origin = {
|
|
871
|
+
readonly _tag: "Root";
|
|
872
|
+
} | {
|
|
873
|
+
readonly _tag: "Invoke";
|
|
874
|
+
readonly ownerPath: string;
|
|
875
|
+
readonly invokeId: string;
|
|
876
|
+
} | {
|
|
877
|
+
readonly _tag: "Spawn";
|
|
878
|
+
readonly address: string | undefined;
|
|
879
|
+
};
|
|
880
|
+
/** Causal owner of a send or emission. */
|
|
881
|
+
type Causation = {
|
|
882
|
+
readonly _tag: "Initialization";
|
|
883
|
+
} | {
|
|
884
|
+
readonly _tag: "Macrostep";
|
|
885
|
+
readonly macrostepId: number;
|
|
886
|
+
} | {
|
|
887
|
+
readonly _tag: "Activity";
|
|
888
|
+
readonly activitySessionId: string;
|
|
889
|
+
};
|
|
890
|
+
/** Closed command projection safe for observation. */
|
|
891
|
+
type Command = {
|
|
892
|
+
readonly _tag: "SendTo";
|
|
893
|
+
readonly target: Endpoint | {
|
|
894
|
+
readonly id: string;
|
|
895
|
+
};
|
|
896
|
+
readonly event: unknown;
|
|
897
|
+
} | {
|
|
898
|
+
readonly _tag: "Stop";
|
|
899
|
+
readonly target: Endpoint | {
|
|
900
|
+
readonly id: string;
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
/** One statechart microstep in a committed macrostep. */
|
|
904
|
+
interface Microstep {
|
|
905
|
+
readonly event: unknown;
|
|
906
|
+
readonly transitions: ReadonlyArray<Machine.RetainedTransition>;
|
|
907
|
+
readonly raisedEvents: ReadonlyArray<unknown>;
|
|
908
|
+
readonly emittedEvents: ReadonlyArray<unknown>;
|
|
909
|
+
readonly commands: ReadonlyArray<Command>;
|
|
910
|
+
readonly exitPaths: ReadonlyArray<string>;
|
|
911
|
+
readonly entryPaths: ReadonlyArray<string>;
|
|
912
|
+
readonly changed: boolean;
|
|
913
|
+
}
|
|
914
|
+
/** Common ordering and identity fields for every record. */
|
|
915
|
+
interface Base {
|
|
916
|
+
/** Total publication order within this prepared root. */
|
|
917
|
+
readonly sequence: number;
|
|
918
|
+
/** Session id of the prepared root that owns this inspection stream. */
|
|
919
|
+
readonly rootSessionId: string;
|
|
920
|
+
/** Runtime instance described by this record. */
|
|
921
|
+
readonly subject: Subject;
|
|
922
|
+
}
|
|
923
|
+
/** Announces allocation of a root or owned process identity. */
|
|
924
|
+
interface Created extends Base {
|
|
925
|
+
readonly _tag: "Created";
|
|
926
|
+
readonly parent: Subject | undefined;
|
|
927
|
+
readonly origin: Origin;
|
|
928
|
+
/** Compiled statechart definition; absent for generic `Logic`. */
|
|
929
|
+
readonly definition: Machine.Any | undefined;
|
|
930
|
+
}
|
|
931
|
+
/** Announces successful initialization. */
|
|
932
|
+
interface Initialized extends Base {
|
|
933
|
+
readonly _tag: "Initialized";
|
|
934
|
+
readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown>;
|
|
935
|
+
readonly initialEntryPaths: ReadonlyArray<string>;
|
|
936
|
+
readonly microsteps: ReadonlyArray<Microstep>;
|
|
937
|
+
}
|
|
938
|
+
/** Announces failure before an initial runtime snapshot exists. */
|
|
939
|
+
interface StartFailed extends Base {
|
|
940
|
+
readonly _tag: "StartFailed";
|
|
941
|
+
readonly cause: Cause.Cause<unknown>;
|
|
942
|
+
}
|
|
943
|
+
/** Announces acceptance of an event by a local mailbox. */
|
|
944
|
+
interface EventSent extends Base {
|
|
945
|
+
readonly _tag: "EventSent";
|
|
946
|
+
readonly deliveryId: number;
|
|
947
|
+
readonly source: Subject | undefined;
|
|
948
|
+
readonly target: Endpoint;
|
|
949
|
+
readonly event: unknown;
|
|
950
|
+
readonly causedBy: Causation | undefined;
|
|
951
|
+
}
|
|
952
|
+
/** Announces complete processing of one statechart mailbox event. */
|
|
953
|
+
interface EventProcessed extends Base {
|
|
954
|
+
readonly _tag: "EventProcessed";
|
|
955
|
+
readonly macrostepId: number;
|
|
956
|
+
readonly deliveryId: number;
|
|
957
|
+
readonly source: Subject | undefined;
|
|
958
|
+
readonly event: unknown;
|
|
959
|
+
readonly before: RuntimeSnapshot<unknown, unknown, unknown>;
|
|
960
|
+
readonly after: RuntimeSnapshot<unknown, unknown, unknown>;
|
|
961
|
+
readonly handled: boolean;
|
|
962
|
+
readonly configurationChanged: boolean;
|
|
963
|
+
readonly microsteps: ReadonlyArray<Microstep>;
|
|
964
|
+
}
|
|
965
|
+
/** Announces a direct state update made by generic `Logic`. */
|
|
966
|
+
interface StateChanged extends Base {
|
|
967
|
+
readonly _tag: "StateChanged";
|
|
968
|
+
readonly before: unknown;
|
|
969
|
+
readonly after: unknown;
|
|
970
|
+
readonly causedByDeliveryId: number | undefined;
|
|
971
|
+
}
|
|
972
|
+
/** Announces actual publication on a machine's domain emission stream. */
|
|
973
|
+
interface Emitted extends Base {
|
|
974
|
+
readonly _tag: "Emitted";
|
|
975
|
+
readonly emission: unknown;
|
|
976
|
+
readonly causedBy: Causation | undefined;
|
|
977
|
+
}
|
|
978
|
+
/** Identity of one Effect or timer invocation run. */
|
|
979
|
+
interface Activity {
|
|
980
|
+
readonly id: string;
|
|
981
|
+
readonly sessionId: string;
|
|
982
|
+
readonly owner: Subject;
|
|
983
|
+
readonly ownerPath: string;
|
|
984
|
+
readonly kind: "Effect" | "Timer";
|
|
985
|
+
}
|
|
986
|
+
/** Announces an Effect or timer invocation starting. */
|
|
987
|
+
interface ActivityStarted extends Base {
|
|
988
|
+
readonly _tag: "ActivityStarted";
|
|
989
|
+
readonly activity: Activity;
|
|
990
|
+
}
|
|
991
|
+
/** Announces an Effect or timer invocation outcome. */
|
|
992
|
+
interface ActivityStopped extends Base {
|
|
993
|
+
readonly _tag: "ActivityStopped";
|
|
994
|
+
readonly activity: Activity;
|
|
995
|
+
/** Success or failure from the invoke; interruption means its owner stopped it. */
|
|
996
|
+
readonly exit: Exit.Exit<unknown, unknown>;
|
|
997
|
+
}
|
|
998
|
+
/** Announces a terminal local runtime snapshot. */
|
|
999
|
+
interface Terminated extends Base {
|
|
1000
|
+
readonly _tag: "Terminated";
|
|
1001
|
+
readonly snapshot: RuntimeSnapshot<unknown, unknown, unknown>;
|
|
1002
|
+
}
|
|
1003
|
+
/** Complete live inspection protocol. */
|
|
1004
|
+
type Event = Created | Initialized | StartFailed | EventSent | EventProcessed | StateChanged | Emitted | ActivityStarted | ActivityStopped | Terminated;
|
|
1005
|
+
}
|
|
818
1006
|
/**
|
|
819
1007
|
* Represents a classified terminal outcome derived from a runtime snapshot.
|
|
820
1008
|
*
|
|
@@ -878,6 +1066,13 @@ export interface Prepared<out State, in Event, out Error, out Output, out Emitte
|
|
|
878
1066
|
readonly changes: Stream.Stream<RuntimeSnapshot<State, Error, Output>, StartError>;
|
|
879
1067
|
/** Streams ephemeral notifications published after subscription. */
|
|
880
1068
|
readonly emissions: Stream.Stream<Emitted>;
|
|
1069
|
+
/**
|
|
1070
|
+
* Streams ordered operational records for this root and every locally owned
|
|
1071
|
+
* descendant. The stream is hot, non-replayed, never fails, and completes
|
|
1072
|
+
* after the prepared root terminates. Subscribe before evaluating `start` to
|
|
1073
|
+
* observe initialization.
|
|
1074
|
+
*/
|
|
1075
|
+
readonly inspection: Stream.Stream<Inspection.Event>;
|
|
881
1076
|
/** Initializes this machine once and returns its running reference. */
|
|
882
1077
|
readonly start: Effect.Effect<MachineRef<State, Event, Error, Output, Emitted>, StartError, StartRequirements>;
|
|
883
1078
|
}
|
|
@@ -1209,6 +1404,8 @@ export declare namespace Machine {
|
|
|
1209
1404
|
readonly invoke: any;
|
|
1210
1405
|
/** @internal */
|
|
1211
1406
|
readonly initial: any;
|
|
1407
|
+
/** @internal */
|
|
1408
|
+
readonly initialDefinition: InitialDefinition;
|
|
1212
1409
|
}
|
|
1213
1410
|
/**
|
|
1214
1411
|
* Extracts the state schema tree carried by a machine definition.
|
|
@@ -1593,12 +1790,12 @@ export declare namespace Machine {
|
|
|
1593
1790
|
*/
|
|
1594
1791
|
type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>;
|
|
1595
1792
|
/**
|
|
1596
|
-
* State definitions and snapshot
|
|
1793
|
+
* State definitions and snapshot access helpers returned by `defineStates`.
|
|
1597
1794
|
*
|
|
1598
1795
|
* **Details**
|
|
1599
1796
|
*
|
|
1600
1797
|
* The `states` property is the original state tree and can be passed directly
|
|
1601
|
-
* to `make`. The
|
|
1798
|
+
* to `make`. The remaining helpers match and read snapshots for the same
|
|
1602
1799
|
* state tree.
|
|
1603
1800
|
*
|
|
1604
1801
|
* @category models
|
|
@@ -1607,8 +1804,6 @@ export declare namespace Machine {
|
|
|
1607
1804
|
interface DefinedStates<States extends StateSchemas> {
|
|
1608
1805
|
/** Original state tree supplied to {@link defineStates}. */
|
|
1609
1806
|
readonly states: States;
|
|
1610
|
-
/** Type-safe builders for constructing valid initial snapshots. */
|
|
1611
|
-
readonly initial: InitialBuilder<States>;
|
|
1612
1807
|
/**
|
|
1613
1808
|
* Returns the decoded value for an active state path. The supplied
|
|
1614
1809
|
* snapshot may be a complete root snapshot or a snapshot previously
|
|
@@ -1775,28 +1970,40 @@ export declare namespace Machine {
|
|
|
1775
1970
|
readonly id: string;
|
|
1776
1971
|
readonly outcome: "done" | "failure" | "snapshot";
|
|
1777
1972
|
};
|
|
1778
|
-
/**
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
type
|
|
1786
|
-
readonly type: "
|
|
1973
|
+
/** Static topology selected by a transition branch. */
|
|
1974
|
+
interface TransitionTargetSelection<Path extends string | undefined = string | undefined, Kind extends Topology.TargetSelectionKind = Topology.TargetSelectionKind, Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> {
|
|
1975
|
+
readonly path: Path;
|
|
1976
|
+
readonly kind: Kind;
|
|
1977
|
+
readonly scope: Scope;
|
|
1978
|
+
}
|
|
1979
|
+
/** One statically captured branch of a transition definition. */
|
|
1980
|
+
type TransitionBranch<Path extends string = string> = {
|
|
1981
|
+
readonly type: "direct";
|
|
1982
|
+
readonly target: Path | undefined;
|
|
1983
|
+
readonly selection: TransitionTargetSelection<Path | undefined>;
|
|
1787
1984
|
} | {
|
|
1788
|
-
readonly type: "
|
|
1789
|
-
readonly
|
|
1985
|
+
readonly type: "case";
|
|
1986
|
+
readonly title: string;
|
|
1987
|
+
readonly target: Path | undefined;
|
|
1988
|
+
readonly selection: TransitionTargetSelection<Path | undefined>;
|
|
1989
|
+
} | {
|
|
1990
|
+
readonly type: "otherwise";
|
|
1991
|
+
readonly target: Path | undefined;
|
|
1992
|
+
readonly selection: TransitionTargetSelection<Path | undefined>;
|
|
1790
1993
|
};
|
|
1994
|
+
/** The statically selected root entry for machine startup. */
|
|
1995
|
+
interface InitialDefinition<Path extends string = string> {
|
|
1996
|
+
readonly target: Path;
|
|
1997
|
+
readonly selection: TransitionTargetSelection<Path, "state" | "initial", "initial">;
|
|
1998
|
+
}
|
|
1791
1999
|
/**
|
|
1792
2000
|
* Inspectable registration for a transition handler.
|
|
1793
2001
|
*
|
|
1794
2002
|
* **Details**
|
|
1795
2003
|
*
|
|
1796
|
-
*
|
|
1797
|
-
*
|
|
1798
|
-
*
|
|
1799
|
-
* reentry behavior are available without executing the handler.
|
|
2004
|
+
* Every branch exposes its selected target without executing its predicate
|
|
2005
|
+
* or resolver. A compound local or branch target covers its descendants;
|
|
2006
|
+
* `undefined` identifies an explicitly targetless branch.
|
|
1800
2007
|
*
|
|
1801
2008
|
* @category models
|
|
1802
2009
|
* @since 0.4.0
|
|
@@ -1805,7 +2012,7 @@ export declare namespace Machine {
|
|
|
1805
2012
|
readonly source: SourcePath;
|
|
1806
2013
|
readonly trigger: TransitionTrigger<EventTag>;
|
|
1807
2014
|
readonly reenter: boolean;
|
|
1808
|
-
readonly
|
|
2015
|
+
readonly branches: ReadonlyArray<TransitionBranch<TargetPath>>;
|
|
1809
2016
|
}
|
|
1810
2017
|
/**
|
|
1811
2018
|
* Serializable description of state-owned work.
|
|
@@ -1829,9 +2036,14 @@ export declare namespace Machine {
|
|
|
1829
2036
|
readonly source: SourcePath;
|
|
1830
2037
|
readonly trigger: TransitionTrigger<EventTag>;
|
|
1831
2038
|
readonly reenter: boolean;
|
|
1832
|
-
/**
|
|
2039
|
+
/** Zero-based index of the selected static branch. */
|
|
2040
|
+
readonly branchIndex: number;
|
|
2041
|
+
/** Path returned by the handler, including a choice or history pseudo-state. */
|
|
1833
2042
|
readonly target: TargetPath | undefined;
|
|
1834
|
-
/**
|
|
2043
|
+
/**
|
|
2044
|
+
* Concrete path used after resolving choice, initial, or history routing.
|
|
2045
|
+
* Choice microsteps retain each intermediate pseudo-state edge separately.
|
|
2046
|
+
*/
|
|
1835
2047
|
readonly resolvedTarget: TargetPath | undefined;
|
|
1836
2048
|
}
|
|
1837
2049
|
/**
|
|
@@ -2394,9 +2606,7 @@ export declare namespace Machine {
|
|
|
2394
2606
|
* Opaque result returned by an explicitly targetless transition.
|
|
2395
2607
|
*
|
|
2396
2608
|
* The transition remains handled and retains its queued commands, raised
|
|
2397
|
-
* events, and emitted events, but selects no concrete destination.
|
|
2398
|
-
* `targets` constrain only concrete destinations, so this result is always
|
|
2399
|
-
* permitted from ordinary transition handlers.
|
|
2609
|
+
* events, and emitted events, but selects no concrete destination.
|
|
2400
2610
|
*
|
|
2401
2611
|
* @category models
|
|
2402
2612
|
* @since 0.10.0
|
|
@@ -2419,6 +2629,22 @@ export declare namespace Machine {
|
|
|
2419
2629
|
readonly path: HistoryId;
|
|
2420
2630
|
readonly parent: Extract<ParentPath<HistoryId>, StateIdentifier<States>>;
|
|
2421
2631
|
}
|
|
2632
|
+
/**
|
|
2633
|
+
* Transition instruction that enters a compound or parallel state through
|
|
2634
|
+
* its declared initial configuration.
|
|
2635
|
+
*
|
|
2636
|
+
* @category models
|
|
2637
|
+
* @since 0.13.0
|
|
2638
|
+
*/
|
|
2639
|
+
interface InitialTarget<StateId extends string> {
|
|
2640
|
+
readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId;
|
|
2641
|
+
readonly [Topology.TargetSnapshotTypeId]?: never;
|
|
2642
|
+
readonly [Topology.InitialTargetTypeId]: typeof Topology.InitialTargetTypeId;
|
|
2643
|
+
readonly _tag: "InitialTarget";
|
|
2644
|
+
readonly path: StateId;
|
|
2645
|
+
readonly value: never;
|
|
2646
|
+
readonly values?: never;
|
|
2647
|
+
}
|
|
2422
2648
|
/** Branded transient target instruction used while constructing initial states. */
|
|
2423
2649
|
interface ChoiceTargetInstruction<ChoiceId extends string = string> {
|
|
2424
2650
|
readonly [Topology.ChoiceTargetTypeId]: typeof Topology.ChoiceTargetTypeId;
|
|
@@ -2443,7 +2669,7 @@ export declare namespace Machine {
|
|
|
2443
2669
|
* @category utility types
|
|
2444
2670
|
* @since 0.4.0
|
|
2445
2671
|
*/
|
|
2446
|
-
type FullTargetBuilder<States extends StateSchemas> = FullSnapshotBuilderWithPrefix<States>;
|
|
2672
|
+
type FullTargetBuilder<States extends StateSchemas> = [InitialEntryStateKey<States>] extends [never] ? FullSnapshotBuilderWithPrefix<States> : FullSnapshotBuilderWithPrefix<States> & FullInitialTargetBuilder<States>;
|
|
2447
2673
|
/**
|
|
2448
2674
|
* Builder for a complete fallback configuration containing a history owner.
|
|
2449
2675
|
*
|
|
@@ -2500,8 +2726,7 @@ export declare namespace Machine {
|
|
|
2500
2726
|
*
|
|
2501
2727
|
* The event or lifecycle outcome is handled and queued operations are
|
|
2502
2728
|
* retained, while the current state configuration remains the transition
|
|
2503
|
-
* result.
|
|
2504
|
-
* because those paths are an upper bound rather than an exhaustive result.
|
|
2729
|
+
* result.
|
|
2505
2730
|
*
|
|
2506
2731
|
* @since 0.10.0
|
|
2507
2732
|
*/
|
|
@@ -2537,6 +2762,66 @@ export declare namespace Machine {
|
|
|
2537
2762
|
/** Restores a declared shallow or deep history pseudo-state. */
|
|
2538
2763
|
readonly history: HistoryTargetBuilder<States>;
|
|
2539
2764
|
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Opaque exact destination selected while a machine definition is captured.
|
|
2767
|
+
* The selection contains topology only; state values are constructed later
|
|
2768
|
+
* by the selected branch's resolver.
|
|
2769
|
+
*
|
|
2770
|
+
* @category models
|
|
2771
|
+
* @since 0.14.0
|
|
2772
|
+
*/
|
|
2773
|
+
interface TargetSelection<out Result, out Path extends string | undefined = string | undefined, out Kind extends Topology.TargetSelectionKind = Topology.TargetSelectionKind> {
|
|
2774
|
+
readonly [Topology.TargetSelectionTypeId]: typeof Topology.TargetSelectionTypeId;
|
|
2775
|
+
readonly kind: Kind;
|
|
2776
|
+
readonly scope: Topology.TargetSelectionScope | undefined;
|
|
2777
|
+
readonly path: Path;
|
|
2778
|
+
readonly "~effect/Machine/TargetSelectionResult"?: Types.Covariant<Result>;
|
|
2779
|
+
}
|
|
2780
|
+
type SelectionMethod<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state"> = () => TargetSelection<Builder, Path, Kind>;
|
|
2781
|
+
type InitialSelectionMethod<Builder, Path extends string> = Builder extends {
|
|
2782
|
+
readonly initial: infer Initial;
|
|
2783
|
+
} ? {
|
|
2784
|
+
readonly initial: SelectionMethod<Initial, Path, "initial">;
|
|
2785
|
+
} : {};
|
|
2786
|
+
type SelectionTreeWithPrefix<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Scope extends "local" | "branch", Builder> = {
|
|
2787
|
+
readonly [Key in Extract<ActiveStateKey<States> | ChoiceStateKey<States>, keyof Builder>]: SelectionNode<AllStates, States[Key], JoinPath<Prefix, Key>, Scope, Builder[Key]>;
|
|
2788
|
+
};
|
|
2789
|
+
type SelectionNode<AllStates extends StateSchemas, Node, Path extends string, Scope extends "local" | "branch", Builder> = Node extends ChoiceStateNodeConfig ? SelectionMethod<Builder, Path, "choice"> : Node extends {
|
|
2790
|
+
readonly states: infer Children extends StateSchemas;
|
|
2791
|
+
} ? SelectionMethod<Builder, Path> & InitialSelectionMethod<Builder, Path> & SelectionTreeWithPrefix<AllStates, Children, Path, Scope, Builder> : SelectionMethod<Builder, Path>;
|
|
2792
|
+
type FullSelectionNode<AllStates extends StateSchemas, Node, Path extends StateIdentifier<AllStates>, Builder> = Node extends {
|
|
2793
|
+
readonly states: StateSchemas;
|
|
2794
|
+
} ? SelectionMethod<Builder, Path> & InitialSelectionMethod<Builder, Path> : SelectionMethod<Builder, Path>;
|
|
2795
|
+
type FullTargetSelector<States extends StateSchemas> = {
|
|
2796
|
+
readonly [Key in Extract<ActiveStateKey<States>, keyof FullTargetBuilder<States>>]: FullSelectionNode<States, States[Key], Extract<Key, StateIdentifier<States>>, FullTargetBuilder<States>[Key]>;
|
|
2797
|
+
};
|
|
2798
|
+
type BranchTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>, Root extends string = Source extends `${infer Head}.${string}` ? Head : Source> = Root extends ActiveStateKey<States> ? Root extends keyof BranchTargetBuilder<States, Source> ? {
|
|
2799
|
+
readonly [Key in Root]: SelectionNode<States, States[Key], Key, "branch", BranchTargetBuilder<States, Source>[Key]>;
|
|
2800
|
+
} : {} : {};
|
|
2801
|
+
type LocalTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = NearestCompoundScope<States, Source> extends infer Scope extends StateIdentifier<States> ? ChildrenOf<States, Scope> extends infer Children extends StateSchemas ? LocalTargetBuilder<States, Source> extends infer Builder ? SelectionTreeWithPrefix<States, Children, Scope, "local", Builder> & ("with" extends keyof Builder ? {
|
|
2802
|
+
readonly with: SelectionMethod<Builder["with"], Scope>;
|
|
2803
|
+
} : {}) : {} : {} : {};
|
|
2804
|
+
type HistorySelectionTree<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Builder> = {
|
|
2805
|
+
readonly [Key in Extract<HistoryContainingKey<States>, keyof Builder>]: States[Key] extends HistoryStateNodeConfig ? SelectionMethod<Builder[Key], JoinPath<Prefix, Key>, "history"> : States[Key] extends {
|
|
2806
|
+
readonly states: infer Children extends StateSchemas;
|
|
2807
|
+
} ? HistorySelectionTree<AllStates, Children, JoinPath<Prefix, Key>, Builder[Key]> : never;
|
|
2808
|
+
};
|
|
2809
|
+
/** Definition-time topology selector available to an ordinary transition. */
|
|
2810
|
+
interface TargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
|
|
2811
|
+
readonly none: SelectionMethod<TargetBuilder<States, Source>["none"], never, "none">;
|
|
2812
|
+
readonly local: LocalTargetSelector<States, Source>;
|
|
2813
|
+
readonly branch: BranchTargetSelector<States, Source>;
|
|
2814
|
+
readonly full: FullTargetSelector<States>;
|
|
2815
|
+
readonly history: HistorySelectionTree<States, States, "", HistoryTargetBuilder<States>>;
|
|
2816
|
+
}
|
|
2817
|
+
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
2818
|
+
type InitialSelector<States extends StateSchemas> = {
|
|
2819
|
+
readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends {
|
|
2820
|
+
readonly states: StateSchemas;
|
|
2821
|
+
} ? {
|
|
2822
|
+
readonly initial: SelectionMethod<InitialBuilder<States>[Key], Key, "initial">;
|
|
2823
|
+
} : SelectionMethod<InitialBuilder<States>[Key], Key>;
|
|
2824
|
+
};
|
|
2540
2825
|
/**
|
|
2541
2826
|
* Context passed to a state/event handler.
|
|
2542
2827
|
*
|
|
@@ -2727,7 +3012,7 @@ export declare namespace Machine {
|
|
|
2727
3012
|
* @category utility types
|
|
2728
3013
|
* @since 0.4.0
|
|
2729
3014
|
*/
|
|
2730
|
-
type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> | InitialSnapshot<States> | StateConstruction<Snapshot<States> | InitialSnapshot<States
|
|
3015
|
+
type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> | InitialSnapshot<States> | InitialTarget<StateIdentifier<States>> | StateConstruction<Snapshot<States> | InitialSnapshot<States> | InitialTarget<StateIdentifier<States>>>;
|
|
2731
3016
|
/** Initial snapshots may transiently terminate in a declared choice node. */
|
|
2732
3017
|
type InitialSnapshot<States extends StateSchemas> = {
|
|
2733
3018
|
readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">;
|
|
@@ -2784,9 +3069,9 @@ export declare namespace Machine {
|
|
|
2784
3069
|
*/
|
|
2785
3070
|
type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
2786
3071
|
/** Extracts the return value from an implicit initial child implementation. */
|
|
2787
|
-
type
|
|
2788
|
-
readonly
|
|
2789
|
-
} ? NonNullable<
|
|
3072
|
+
type StateInitializeReturn<Config> = Config extends {
|
|
3073
|
+
readonly initialize?: infer Initialize;
|
|
3074
|
+
} ? NonNullable<Initialize> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
2790
3075
|
/** Extracts the return values from a state's history defaults. */
|
|
2791
3076
|
type HistoryDefaultReturn<Config> = Config extends {
|
|
2792
3077
|
readonly history?: infer History;
|
|
@@ -2797,19 +3082,21 @@ export declare namespace Machine {
|
|
|
2797
3082
|
}[keyof NonNullable<History>] : never;
|
|
2798
3083
|
/** Extracts the return value from a choice resolver. */
|
|
2799
3084
|
type ChoiceReturn<Config> = Config extends {
|
|
2800
|
-
readonly choice:
|
|
2801
|
-
|
|
2802
|
-
};
|
|
2803
|
-
} ? Ret : never;
|
|
3085
|
+
readonly choice: infer Choice;
|
|
3086
|
+
} ? EventTransitionReturn<Choice> : never;
|
|
2804
3087
|
/**
|
|
2805
3088
|
* Extracts the return value from an event transition config.
|
|
2806
3089
|
*
|
|
2807
3090
|
* @category utility types
|
|
2808
3091
|
* @since 0.4.0
|
|
2809
3092
|
*/
|
|
2810
|
-
type EventTransitionReturn<Transition> =
|
|
2811
|
-
readonly
|
|
2812
|
-
} ? Ret : never
|
|
3093
|
+
type EventTransitionReturn<Transition> = (Transition extends {
|
|
3094
|
+
readonly resolve?: infer Resolve;
|
|
3095
|
+
} ? NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never : never) | (Transition extends {
|
|
3096
|
+
readonly cases: infer Cases extends ReadonlyArray<unknown>;
|
|
3097
|
+
} ? EventTransitionReturn<Cases[number]> : never) | (Transition extends {
|
|
3098
|
+
readonly otherwise: infer Otherwise;
|
|
3099
|
+
} ? EventTransitionReturn<Otherwise> : never);
|
|
2813
3100
|
/**
|
|
2814
3101
|
* Extracts the return value from a state's event handlers.
|
|
2815
3102
|
*
|
|
@@ -2837,10 +3124,11 @@ export declare namespace Machine {
|
|
|
2837
3124
|
* @since 0.4.0
|
|
2838
3125
|
*/
|
|
2839
3126
|
type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3127
|
+
type InvokeFactoryResult<Source> = Source extends (...args: any) => infer Resolved ? Resolved : never;
|
|
2840
3128
|
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialServices<M> | Services<M>>, internalRuntime.MachineRuntime>, Event<M>, Emit<M>>, Output<M>, InitialError<M> | Error<M> | ActionError<InitialServices<M> | Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError> : never;
|
|
2841
3129
|
type InvokeLogic<Invoke> = Invoke extends {
|
|
2842
3130
|
readonly effect: infer Source;
|
|
2843
|
-
} ?
|
|
3131
|
+
} ? InvokeFactoryResult<Source> extends infer Fx extends Effect.Effect<any, any, any> ? Logic<void, never, Effect.Error<Fx>, Effect.Services<Fx>, Effect.Success<Fx>> : never : Invoke extends {
|
|
2844
3132
|
readonly after: unknown;
|
|
2845
3133
|
} ? Logic<void, never, never, never, void> : Invoke extends {
|
|
2846
3134
|
readonly logic: infer Source;
|
|
@@ -2967,17 +3255,62 @@ export declare namespace Machine {
|
|
|
2967
3255
|
* @category utility types
|
|
2968
3256
|
* @since 0.4.0
|
|
2969
3257
|
*/
|
|
2970
|
-
type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<
|
|
2971
|
-
type
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
readonly
|
|
3258
|
+
type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config>;
|
|
3259
|
+
type TransitionWhenContext<Context> = Omit<Context, "target">;
|
|
3260
|
+
/** Type evidence retained by {@link transition} without affecting runtime data. */
|
|
3261
|
+
interface TransitionTyped<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean> {
|
|
3262
|
+
readonly [TransitionTypeId]: {
|
|
3263
|
+
readonly owner: Types.Covariant<readonly [States, Events, Emits, StateId, Context]>;
|
|
3264
|
+
};
|
|
3265
|
+
}
|
|
3266
|
+
/** Type evidence for a targetless transition reusable in every owning context. */
|
|
3267
|
+
interface TargetlessTransitionTyped {
|
|
3268
|
+
readonly [TransitionTypeId]: {
|
|
3269
|
+
readonly targetless: true;
|
|
3270
|
+
};
|
|
3271
|
+
}
|
|
3272
|
+
/** The only transition value accepted by machine handler APIs. */
|
|
3273
|
+
type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false> = (TransitionTyped<States, Events, Emits, StateId, Context, Reenter> | TargetlessTransitionTyped) & {
|
|
3274
|
+
readonly reenter?: [Reenter] extends [true] ? boolean : never;
|
|
3275
|
+
};
|
|
3276
|
+
type SelectionBuilder<Selection> = Selection extends TargetSelection<infer Builder, any, any> ? Builder : never;
|
|
3277
|
+
type SelectionKind<Selection> = Selection extends TargetSelection<any, any, infer Kind> ? Kind : never;
|
|
3278
|
+
type SelectionPath<Selection> = Selection extends TargetSelection<any, infer Path, any> ? Path : never;
|
|
3279
|
+
type TargetBuilderResult<Builder> = (Builder extends (...args: any) => infer Result ? Result : never) | (Builder extends {
|
|
3280
|
+
readonly from: (...args: any) => infer Result;
|
|
3281
|
+
} ? Result : never);
|
|
3282
|
+
type SelectedTargetResult<Selection> = SelectionBuilder<Selection> extends infer Builder ? TargetBuilderResult<Builder> : never;
|
|
3283
|
+
type TransitionResolveContext<Context, Selection, Match = never> = Omit<Context, "target"> & ([Match] extends [never] ? {} : {
|
|
3284
|
+
readonly match: Match;
|
|
3285
|
+
}) & (SelectionKind<Selection> extends "none" ? {} : {
|
|
3286
|
+
readonly target: SelectionBuilder<Selection>;
|
|
3287
|
+
});
|
|
3288
|
+
type TransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection, Match = never> = (context: TransitionResolveContext<Context, Selection, Match>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined;
|
|
3289
|
+
type TransitionDirectInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> = {
|
|
3290
|
+
readonly target: (to: TargetSelector<States, StateId>) => Selection;
|
|
3291
|
+
readonly resolve?: TransitionResolver<Events, Emits, Context, Selection>;
|
|
3292
|
+
readonly cases?: never;
|
|
3293
|
+
readonly otherwise?: never;
|
|
3294
|
+
readonly reenter?: Reenter;
|
|
2975
3295
|
};
|
|
3296
|
+
type TransitionCaseInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Selection extends TargetSelection<any, any, any>, Match> = {
|
|
3297
|
+
readonly title: string;
|
|
3298
|
+
readonly when: (context: TransitionWhenContext<Context>) => Option.Option<Match>;
|
|
3299
|
+
readonly target: (to: TargetSelector<States, StateId>) => Selection;
|
|
3300
|
+
readonly resolve?: TransitionResolver<Events, Emits, Context, Selection, NoInfer<Match>>;
|
|
3301
|
+
readonly cases?: never;
|
|
3302
|
+
readonly otherwise?: never;
|
|
3303
|
+
readonly reenter?: never;
|
|
3304
|
+
};
|
|
3305
|
+
type TransitionConditionalInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Cases extends readonly [TransitionCaseTyped, ...ReadonlyArray<TransitionCaseTyped>], OtherwiseSelection extends TargetSelection<any, any, any>> = {
|
|
3306
|
+
readonly target?: never;
|
|
3307
|
+
readonly resolve?: never;
|
|
3308
|
+
readonly cases: (branch: TransitionCaseConstructor<States, Events, Emits, StateId, Context>) => Cases;
|
|
3309
|
+
readonly otherwise: TransitionDirectInput<States, Events, Emits, StateId, Context, never, OtherwiseSelection>;
|
|
3310
|
+
readonly reenter?: Reenter;
|
|
3311
|
+
};
|
|
3312
|
+
type InvokeTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context> = TransitionConfig<States, Events, Emits, StateId, Context, true>;
|
|
2976
3313
|
type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
2977
|
-
interface AnyLogicSource {
|
|
2978
|
-
initial(...args: ReadonlyArray<any>): Effect.Effect<any, any, any>;
|
|
2979
|
-
run(...args: ReadonlyArray<any>): Effect.Effect<any, any, any>;
|
|
2980
|
-
}
|
|
2981
3314
|
/** Inline state-owned work that runs for the lifetime of its active state. */
|
|
2982
3315
|
interface InvokeOwned<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2983
3316
|
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId]>;
|
|
@@ -2995,7 +3328,7 @@ export declare namespace Machine {
|
|
|
2995
3328
|
}
|
|
2996
3329
|
type InvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = InvokeOwned<States, Events, Emits, StateId> & ({
|
|
2997
3330
|
readonly id: string;
|
|
2998
|
-
readonly effect:
|
|
3331
|
+
readonly effect: (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<any, any, any>;
|
|
2999
3332
|
readonly after?: never;
|
|
3000
3333
|
readonly logic?: never;
|
|
3001
3334
|
readonly child?: never;
|
|
@@ -3016,7 +3349,7 @@ export declare namespace Machine {
|
|
|
3016
3349
|
} | {
|
|
3017
3350
|
readonly id: string;
|
|
3018
3351
|
readonly address: string;
|
|
3019
|
-
readonly logic: InvokeSource<
|
|
3352
|
+
readonly logic: InvokeSource<Logic<any, any, any, any, any, any>, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3020
3353
|
readonly effect?: never;
|
|
3021
3354
|
readonly after?: never;
|
|
3022
3355
|
readonly child?: never;
|
|
@@ -3059,15 +3392,6 @@ export declare namespace Machine {
|
|
|
3059
3392
|
} : {
|
|
3060
3393
|
readonly onFailure?: never;
|
|
3061
3394
|
} : never;
|
|
3062
|
-
type EffectInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Fx extends Effect.Effect<any, any, any>, Source = Fx, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
3063
|
-
readonly id: InvokeLifecycleId;
|
|
3064
|
-
readonly effect: Source;
|
|
3065
|
-
readonly after?: never;
|
|
3066
|
-
readonly logic?: never;
|
|
3067
|
-
readonly child?: never;
|
|
3068
|
-
readonly address?: never;
|
|
3069
|
-
readonly onSnapshot?: never;
|
|
3070
|
-
} & InvokeDoneRequirement<Effect.Success<NoInfer<Fx>>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<NoInfer<Fx>>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<Effect.Error<NoInfer<Fx>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<NoInfer<Fx>>, InputEvents, ParentEvents>>>;
|
|
3071
3395
|
type TimerInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
3072
3396
|
readonly id: InvokeLifecycleId;
|
|
3073
3397
|
readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
@@ -3077,7 +3401,7 @@ export declare namespace Machine {
|
|
|
3077
3401
|
readonly address?: never;
|
|
3078
3402
|
readonly onFailure?: never;
|
|
3079
3403
|
readonly onSnapshot?: never;
|
|
3080
|
-
readonly onDone: InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>>;
|
|
3404
|
+
readonly onDone: InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>>;
|
|
3081
3405
|
};
|
|
3082
3406
|
type LogicInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, Source = Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
3083
3407
|
readonly id: InvokeLifecycleId;
|
|
@@ -3086,8 +3410,8 @@ export declare namespace Machine {
|
|
|
3086
3410
|
readonly effect?: never;
|
|
3087
3411
|
readonly after?: never;
|
|
3088
3412
|
readonly child?: never;
|
|
3089
|
-
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, ChildState
|
|
3090
|
-
} & InvokeDoneRequirement<ChildOutput
|
|
3413
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, NoInfer<ChildState>, NoInfer<ChildError>, NoInfer<ChildOutput>, InputEvents, ParentEvents>>;
|
|
3414
|
+
} & InvokeDoneRequirement<NoInfer<ChildOutput>, InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, NoInfer<ChildOutput>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<NoInfer<ChildError>, InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, NoInfer<ChildError>, InputEvents, ParentEvents>>>;
|
|
3091
3415
|
type ChildInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, ChildDefinition extends Machine.Any, Child extends ChildMachine<string, ChildDefinition>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
3092
3416
|
readonly child: Child & (ChildDefinition extends EnsureExecutable<Machine.States<ChildDefinition>, Machine.UnhandledStates<ChildDefinition>, Machine.OutputStates<ChildDefinition>> ? unknown : never);
|
|
3093
3417
|
readonly id?: never;
|
|
@@ -3095,42 +3419,50 @@ export declare namespace Machine {
|
|
|
3095
3419
|
readonly effect?: never;
|
|
3096
3420
|
readonly after?: never;
|
|
3097
3421
|
readonly logic?: never;
|
|
3098
|
-
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>;
|
|
3422
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>;
|
|
3099
3423
|
} & (Input<ChildDefinition> extends typeof Schema.Void ? {
|
|
3100
3424
|
readonly input?: never;
|
|
3101
3425
|
} : {
|
|
3102
3426
|
readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3103
|
-
}) & InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InputEvents, ParentEvents>>>;
|
|
3104
|
-
type
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
type
|
|
3108
|
-
|
|
3109
|
-
|
|
3427
|
+
}) & InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InputEvents, ParentEvents>>>;
|
|
3428
|
+
type LogicInitialEffectOf<Value> = Value extends {
|
|
3429
|
+
readonly initial: infer Initial;
|
|
3430
|
+
} ? Initial extends (...args: ReadonlyArray<any>) => infer Result ? Result : never : never;
|
|
3431
|
+
type LogicRunEffectOf<Value> = Value extends {
|
|
3432
|
+
readonly run: infer Run;
|
|
3433
|
+
} ? Run extends (...args: ReadonlyArray<any>) => infer Result ? Result : never : never;
|
|
3434
|
+
type LogicStateOf<Value> = Effect.Success<LogicInitialEffectOf<Value>>;
|
|
3435
|
+
type LogicEventOf<Value> = Value extends {
|
|
3436
|
+
readonly initial: infer Initial;
|
|
3437
|
+
} ? Initial extends (scope: infer LogicScope, ...args: ReadonlyArray<any>) => any ? LogicScope extends Logic.Scope<infer Event> ? Event : never : never : never;
|
|
3438
|
+
type LogicErrorOf<Value> = Effect.Error<LogicRunEffectOf<Value>>;
|
|
3439
|
+
type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>;
|
|
3440
|
+
type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>;
|
|
3441
|
+
type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>;
|
|
3110
3442
|
type ContextualInvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Raw> = Raw extends InvokeTyped<any, any, any, any, any> ? unknown : Raw extends {
|
|
3111
3443
|
readonly effect: infer Source;
|
|
3112
|
-
} ?
|
|
3444
|
+
} ? InvokeFactoryResult<Source> extends infer Fx extends Effect.Effect<any, any, any> ? InvokeDoneRequirement<Effect.Success<Fx>, InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<Fx>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<Effect.Error<Fx>, InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<Fx>, InputEvents, ParentEvents>>> & {
|
|
3113
3445
|
readonly onSnapshot?: never;
|
|
3114
3446
|
} : never : Raw extends {
|
|
3115
3447
|
readonly after: unknown;
|
|
3116
3448
|
} ? {
|
|
3117
|
-
readonly onDone: InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>>;
|
|
3449
|
+
readonly onDone: InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, void, InputEvents, ParentEvents>>;
|
|
3118
3450
|
readonly onFailure?: never;
|
|
3119
3451
|
readonly onSnapshot?: never;
|
|
3120
3452
|
} : Raw extends {
|
|
3121
3453
|
readonly logic: infer Source;
|
|
3122
3454
|
readonly address: infer Address;
|
|
3123
|
-
} ? InvokeResolvedSource<Source> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ? InvokeDoneRequirement<InvokeOutput<Raw>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<InvokeRuntimeError<Raw>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, InvokeRuntimeError<Raw>, InputEvents, ParentEvents>>> & {
|
|
3455
|
+
} ? InvokeResolvedSource<Source> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ? InvokeDoneRequirement<InvokeOutput<Raw>, InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<InvokeRuntimeError<Raw>, InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, InvokeRuntimeError<Raw>, InputEvents, ParentEvents>>> & {
|
|
3124
3456
|
readonly address: ChildAddress<never> & ChildAddress.Compatibility<Address, ChildLogic extends Logic<any, infer ChildEvent, any, any, any, any> ? ChildEvent : never>;
|
|
3125
|
-
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, ChildLogic extends Logic<infer ChildState, any, any, any, any, any> ? ChildState : never, InvokeRuntimeError<Raw>, InvokeOutput<Raw>, InputEvents, ParentEvents>>;
|
|
3457
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, ChildLogic extends Logic<infer ChildState, any, any, any, any, any> ? ChildState : never, InvokeRuntimeError<Raw>, InvokeOutput<Raw>, InputEvents, ParentEvents>>;
|
|
3126
3458
|
} : never : Raw extends {
|
|
3127
3459
|
readonly child: infer Child extends ChildMachine<string, infer ChildDefinition>;
|
|
3128
|
-
} ? ChildMachineLogic<Child> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ? InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InputEvents, ParentEvents>>> & (Input<ChildDefinition> extends typeof Schema.Void ? {
|
|
3460
|
+
} ? ChildMachineLogic<Child> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ? InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>, InputEvents, ParentEvents>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InputEvents, ParentEvents>>> & (Input<ChildDefinition> extends typeof Schema.Void ? {
|
|
3129
3461
|
readonly input?: never;
|
|
3130
3462
|
} : {
|
|
3131
3463
|
readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3132
3464
|
}) & {
|
|
3133
|
-
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>;
|
|
3465
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>;
|
|
3134
3466
|
} : never : never;
|
|
3135
3467
|
type ContextualInvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Raw> = Raw extends ReadonlyArray<any> ? {
|
|
3136
3468
|
readonly [Index in keyof Raw]: ContextualInvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents, Raw[Index]>;
|
|
@@ -3157,32 +3489,20 @@ export declare namespace Machine {
|
|
|
3157
3489
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
3158
3490
|
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
3159
3491
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId, InputEvents, ParentEvents> | TypedInvokeDefinition;
|
|
3160
|
-
readonly always?:
|
|
3161
|
-
|
|
3162
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3163
|
-
readonly transition: (context: AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
3164
|
-
};
|
|
3165
|
-
readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
3166
|
-
/** Statically declared upper bound of possible target paths. */
|
|
3167
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3168
|
-
readonly transition: (context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
3169
|
-
};
|
|
3492
|
+
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3493
|
+
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
3170
3494
|
readonly on?: {
|
|
3171
|
-
readonly [EventTag in TagOf<Events[number]>]?:
|
|
3172
|
-
readonly reenter?: boolean;
|
|
3173
|
-
/**
|
|
3174
|
-
* Upper bound of state or history paths this handler may target.
|
|
3175
|
-
* Returning `target.none()` is always permitted. Declaring a parent state also
|
|
3176
|
-
* permits concrete descendant targets below it.
|
|
3177
|
-
*/
|
|
3178
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3179
|
-
readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
3180
|
-
};
|
|
3495
|
+
readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, true>;
|
|
3181
3496
|
};
|
|
3182
|
-
readonly
|
|
3497
|
+
readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
3183
3498
|
} & ActiveOutputHandlerConfig<States, Events, StateId>;
|
|
3184
|
-
/**
|
|
3185
|
-
|
|
3499
|
+
/**
|
|
3500
|
+
* Values constructed for a state's schema-valued direct initial children.
|
|
3501
|
+
*
|
|
3502
|
+
* @category utility types
|
|
3503
|
+
* @since 0.13.0
|
|
3504
|
+
*/
|
|
3505
|
+
type StateInitializeValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
3186
3506
|
readonly type: "parallel";
|
|
3187
3507
|
readonly states: infer Children extends StateSchemas;
|
|
3188
3508
|
} ? {
|
|
@@ -3190,11 +3510,53 @@ export declare namespace Machine {
|
|
|
3190
3510
|
} : Node extends {
|
|
3191
3511
|
readonly states: infer Children extends StateSchemas;
|
|
3192
3512
|
readonly initial: infer Initial;
|
|
3193
|
-
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never :
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3513
|
+
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : {
|
|
3514
|
+
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
3515
|
+
} : never : never : never;
|
|
3516
|
+
type StateInitializeCompoundBuilder<Node, Initial extends PropertyKey> = Node extends {
|
|
3517
|
+
readonly states: infer Children extends StateSchemas;
|
|
3518
|
+
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : NodeBuilderMethod<Children[Initial], readonly [value: NodeValue<Children[Initial]>], SnapshotBuilderComplete<{
|
|
3519
|
+
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
3520
|
+
}>, readonly [input: NodeMakeInput<Children[Initial]>], SnapshotBuilderComplete<{
|
|
3521
|
+
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
3522
|
+
}, true>> : never : never;
|
|
3523
|
+
type StateInitializeParallelBuilder<Children extends StateSchemas, Remaining extends ActiveStateKey<Children> = {
|
|
3524
|
+
readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]> extends never ? never : Key;
|
|
3525
|
+
}[ActiveStateKey<Children>], Values = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Values, Constructed> & {
|
|
3526
|
+
readonly [Key in Remaining]: NodeBuilderMethod<Children[Key], readonly [value: NodeValue<Children[Key]>], StateInitializeParallelBuilder<Children, Exclude<Remaining, Key>, Values & {
|
|
3527
|
+
readonly [Region in Key]: NodeValue<Children[Key]>;
|
|
3528
|
+
}, Constructed>, readonly [input: NodeMakeInput<Children[Key]>], StateInitializeParallelBuilder<Children, Exclude<Remaining, Key>, Values & {
|
|
3529
|
+
readonly [Region in Key]: NodeValue<Children[Key]>;
|
|
3530
|
+
}, true>>;
|
|
3531
|
+
};
|
|
3532
|
+
/**
|
|
3533
|
+
* Builder bound to the direct initial child or regions owned by a state.
|
|
3534
|
+
*
|
|
3535
|
+
* @category utility types
|
|
3536
|
+
* @since 0.13.0
|
|
3537
|
+
*/
|
|
3538
|
+
type StateInitializeBuilder<States extends StateSchemas, StateId extends StateIdentifier<States>, Node = NodeByIdentifier<States, StateId>> = Node extends {
|
|
3539
|
+
readonly type: "parallel";
|
|
3540
|
+
readonly states: infer Children extends StateSchemas;
|
|
3541
|
+
} ? StateInitializeParallelBuilder<Children> : Node extends {
|
|
3542
|
+
readonly initial: infer Initial;
|
|
3543
|
+
} ? StateInitializeCompoundBuilder<Node, Initial & PropertyKey> : never;
|
|
3544
|
+
/**
|
|
3545
|
+
* Context passed to an implicit child-state initializer.
|
|
3546
|
+
*
|
|
3547
|
+
* @category models
|
|
3548
|
+
* @since 0.13.0
|
|
3549
|
+
*/
|
|
3550
|
+
type StateInitializeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
|
|
3551
|
+
readonly builder: StateInitializeBuilder<States, StateId>;
|
|
3552
|
+
};
|
|
3553
|
+
/**
|
|
3554
|
+
* Initial child value implementation for a compound or parallel state.
|
|
3555
|
+
*
|
|
3556
|
+
* @category models
|
|
3557
|
+
* @since 0.13.0
|
|
3558
|
+
*/
|
|
3559
|
+
type StateInitializeHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = (context: StateInitializeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>;
|
|
3198
3560
|
/** Context used only when a history node has no previously captured record. */
|
|
3199
3561
|
interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
3200
3562
|
readonly event: LifecycleEvent<Events>;
|
|
@@ -3217,11 +3579,7 @@ export declare namespace Machine {
|
|
|
3217
3579
|
};
|
|
3218
3580
|
/** Required implementation for a choice pseudo-state. */
|
|
3219
3581
|
interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3220
|
-
readonly choice:
|
|
3221
|
-
/** Statically inspectable upper bound of every possible target. */
|
|
3222
|
-
readonly targets: readonly [StateNodeIdentifier<States>, ...ReadonlyArray<StateNodeIdentifier<States>>];
|
|
3223
|
-
readonly transition: (context: ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => ChoiceResult<States, any, any>;
|
|
3224
|
-
};
|
|
3582
|
+
readonly choice: TransitionConfig<States, Events, Emits, ChoiceId, ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>>;
|
|
3225
3583
|
readonly entry?: never;
|
|
3226
3584
|
readonly exit?: never;
|
|
3227
3585
|
readonly invoke?: never;
|
|
@@ -3229,7 +3587,7 @@ export declare namespace Machine {
|
|
|
3229
3587
|
readonly on?: never;
|
|
3230
3588
|
readonly onDone?: never;
|
|
3231
3589
|
readonly output?: never;
|
|
3232
|
-
readonly
|
|
3590
|
+
readonly initialize?: never;
|
|
3233
3591
|
}
|
|
3234
3592
|
/**
|
|
3235
3593
|
* Configuration accepted for a final state.
|
|
@@ -3297,7 +3655,7 @@ export declare namespace Machine {
|
|
|
3297
3655
|
type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Prefix extends string> = {
|
|
3298
3656
|
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, InputEvents, ParentEvents, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
|
|
3299
3657
|
};
|
|
3300
|
-
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "
|
|
3658
|
+
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initialize" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
3301
3659
|
type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
|
|
3302
3660
|
readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
|
|
3303
3661
|
};
|
|
@@ -3335,27 +3693,26 @@ export declare namespace Machine {
|
|
|
3335
3693
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Handler config contains an event key that does not exist", StateId, Key>;
|
|
3336
3694
|
};
|
|
3337
3695
|
} : unknown;
|
|
3338
|
-
type
|
|
3696
|
+
type TransitionResultInitialTargetPath<Result> = IsAny<Result> extends true ? never : Result extends Effect.Effect<infer Success, any, any> ? TransitionResultInitialTargetPath<Success> : Result extends StateConstruction<infer Constructed> ? TransitionResultInitialTargetPath<Constructed> : Result extends {
|
|
3697
|
+
readonly [Topology.InitialTargetTypeId]: typeof Topology.InitialTargetTypeId;
|
|
3698
|
+
readonly _tag: "InitialTarget";
|
|
3699
|
+
} ? Result extends {
|
|
3339
3700
|
readonly path: infer Path extends string;
|
|
3340
|
-
} ? Path : never;
|
|
3341
|
-
type
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
type
|
|
3350
|
-
readonly
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
} : never
|
|
3354
|
-
type
|
|
3355
|
-
readonly [Key in Trigger]?: infer Value;
|
|
3356
|
-
} ? NonNullable<Value> : never, Undeclared extends string = UndeclaredTransitionTarget<Transition>> = Trigger extends keyof Config ? [Undeclared] extends [never] ? unknown : {
|
|
3357
|
-
readonly [Key in Trigger]: HandlerValidationError<"Transition returns a target not listed in targets", StateId, readonly [trigger: Trigger, target: Undeclared]>;
|
|
3358
|
-
} : unknown;
|
|
3701
|
+
} ? Path : never : never;
|
|
3702
|
+
type HandlerConfigInitialTargetPath<Config> = TransitionResultInitialTargetPath<EventHandlerReturn<Config> | AlwaysReturn<Config> | DoneReturn<Config> | ChoiceReturn<Config> | InvokeOutcomeReturn<InvokeReturn<Config>>>;
|
|
3703
|
+
type RequiredInitializersForTargetPath<AllStates extends StateSchemas, Path> = string extends Path ? never : Path extends StateIdentifier<AllStates> ? InitializerClosureForNode<AllStates, NodeByIdentifier<AllStates, Path>, Path> : never;
|
|
3704
|
+
type HandlerInitializeValidationAtPath<Config, Path extends string> = HandlerConfigAtPath<Config, Path> extends infer StateConfig ? [StateConfig] extends [never] ? HandlerValidationAtPath<Path, {
|
|
3705
|
+
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
3706
|
+
}> : "initialize" extends keyof StateConfig ? never : HandlerValidationAtPath<Path, {
|
|
3707
|
+
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
3708
|
+
}> : never;
|
|
3709
|
+
type HandlerInitialTargetValidationForPaths<AllStates extends StateSchemas, Config, Required> = Types.UnionToIntersection<Required extends string ? HandlerInitializeValidationAtPath<Config, Required> : unknown>;
|
|
3710
|
+
type HandlerTreeInitialTargetPath<Config> = string extends keyof Config ? never : Config extends object ? {
|
|
3711
|
+
readonly [Key in keyof Config]: HandlerConfigInitialTargetPath<HandlerConfigPart<Config[Key]>> | (Config[Key] extends {
|
|
3712
|
+
readonly states: infer Children;
|
|
3713
|
+
} ? HandlerTreeInitialTargetPath<Children> : never);
|
|
3714
|
+
}[keyof Config] : never;
|
|
3715
|
+
type HandlerInitialTargetValidation<AllStates extends StateSchemas, Config> = HandlerTreeInitialTargetPath<Config> extends infer TargetPath ? HandlerInitialTargetValidationForPaths<AllStates, Config, RequiredInitializersForTargetPath<AllStates, TargetPath>> : unknown;
|
|
3359
3716
|
type HandlerChildrenValidation<Node, Prefix extends string, Config> = "states" extends keyof Config ? Config extends {
|
|
3360
3717
|
readonly states?: infer ChildrenConfig;
|
|
3361
3718
|
} ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
@@ -3376,15 +3733,13 @@ export declare namespace Machine {
|
|
|
3376
3733
|
] extends [never] ? unknown : {
|
|
3377
3734
|
readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
3378
3735
|
} : unknown : unknown);
|
|
3379
|
-
type
|
|
3736
|
+
type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> ? "initialize" extends keyof Config ? unknown : {
|
|
3737
|
+
readonly initialize: HandlerValidationError<"State requires initialize for shallow history restoration", StateId>;
|
|
3738
|
+
} : unknown;
|
|
3739
|
+
type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerInvokeParentEventsValidation<InputEvents, StateId, Config> & HandlerChildrenValidation<Node, StateId, Config> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRequiredHistoryInitializeValidation<AllStates, StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : unknown;
|
|
3380
3740
|
type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
|
|
3381
3741
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
|
|
3382
3742
|
};
|
|
3383
|
-
type HandlerChoiceTargetValidation<StateId extends string, Config> = Config extends {
|
|
3384
|
-
readonly choice: infer Choice;
|
|
3385
|
-
} ? [UndeclaredTransitionTarget<Choice>] extends [never] ? unknown : {
|
|
3386
|
-
readonly choice: HandlerValidationError<"Choice resolver returns a target not listed in targets", StateId, UndeclaredTransitionTarget<Choice>>;
|
|
3387
|
-
} : unknown;
|
|
3388
3743
|
type HandlerInvokeParentEventsValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown : {
|
|
3389
3744
|
readonly invoke: HandlerValidationError<"Invoked child expects parent events not accepted by this machine", StateId, Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
3390
3745
|
};
|
|
@@ -3392,7 +3747,7 @@ export declare namespace Machine {
|
|
|
3392
3747
|
type HandlerNodeValidationAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : HandlerNodeValidation<AllStates, HandlerNodeByPath<AllStates, StateId>, Events, InputEvents, Emits, StateId, NodeConfig, AvailableOutputStates> extends infer Validation ? unknown extends Validation ? never : HandlerValidationAtPath<StateId, Validation> : never;
|
|
3393
3748
|
type HandlerTreeNodeValidations<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeValidationAtPath<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates, StateId> : never : never>;
|
|
3394
3749
|
type HandlerTreeValidation<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = HandlerUnknownStateKeyValidation<AllStates, "", Config> & HandlerTreeNodeValidations<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates>;
|
|
3395
|
-
type HandlerHasRequiredInitial<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = StateId extends RequiredHistoryInitializers<AllStates> ? "
|
|
3750
|
+
type HandlerHasRequiredInitial<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = StateId extends RequiredHistoryInitializers<AllStates> ? "initialize" extends keyof Config ? true : false : true;
|
|
3396
3751
|
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
3397
3752
|
readonly states: infer Children extends StateSchemas;
|
|
3398
3753
|
} ? [HistoryStateKey<Children>] extends [never] ? true : Config extends {
|
|
@@ -3408,7 +3763,7 @@ export declare namespace Machine {
|
|
|
3408
3763
|
Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
|
|
3409
3764
|
] extends [never] ? true : false : false : true;
|
|
3410
3765
|
type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates>] extends [never] ? StateId : HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
|
|
3411
|
-
type HandlerConfigError<Config> = Effect.Error<EventHandlerReturn<Config>> | Effect.Error<AlwaysReturn<Config>> | Effect.Error<DoneReturn<Config>> | Effect.Error<StateActionReturn<Config, "entry">> | Effect.Error<StateActionReturn<Config, "exit">> | Effect.Error<
|
|
3766
|
+
type HandlerConfigError<Config> = Effect.Error<EventHandlerReturn<Config>> | Effect.Error<AlwaysReturn<Config>> | Effect.Error<DoneReturn<Config>> | Effect.Error<StateActionReturn<Config, "entry">> | Effect.Error<StateActionReturn<Config, "exit">> | Effect.Error<HistoryDefaultReturn<Config>> | Effect.Error<ChoiceReturn<Config>> | InvokeError<Config>;
|
|
3412
3767
|
type HandlerNodeEvidence<AllStates extends StateSchemas, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : {
|
|
3413
3768
|
readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, HandlerNodeByPath<AllStates, StateId>, StateId, NodeConfig> : never;
|
|
3414
3769
|
readonly error: HandlerConfigError<HandlerConfigPart<NodeConfig>>;
|
|
@@ -3424,7 +3779,7 @@ export declare namespace Machine {
|
|
|
3424
3779
|
* @since 0.4.0
|
|
3425
3780
|
*/
|
|
3426
3781
|
interface Handler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> {
|
|
3427
|
-
<const Config extends HandlerTree<States, States, Events, Emits, E, R, InputEvents, ParentEvents, "">>(config: Config & HandlerInvokeContexts<States, Events, InputEvents, Emits, ParentEvents, NoInfer<Config>> & HandlerTreeValidation<States, Events, InputEvents, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, NoInfer<Config>>["outputState"], StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, ParentEvents, Config>;
|
|
3782
|
+
<const Config extends HandlerTree<States, States, Events, Emits, E, R, InputEvents, ParentEvents, "">>(config: Config & HandlerInvokeContexts<States, Events, InputEvents, Emits, ParentEvents, NoInfer<Config>> & HandlerTreeValidation<States, Events, InputEvents, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, NoInfer<Config>>["outputState"], StateIdentifier<States>>> & ([StateIdentifier<States>] extends [UnhandledStates] ? HandlerInitialTargetValidation<States, NoInfer<Config>> : unknown)): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, ParentEvents, Config>;
|
|
3428
3783
|
}
|
|
3429
3784
|
/**
|
|
3430
3785
|
* Any state config.
|
|
@@ -3439,12 +3794,7 @@ export declare namespace Machine {
|
|
|
3439
3794
|
* @category models
|
|
3440
3795
|
* @since 0.4.0
|
|
3441
3796
|
*/
|
|
3442
|
-
type EventHandlerMap<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey,
|
|
3443
|
-
readonly reenter?: boolean;
|
|
3444
|
-
/** Statically declared upper bound of possible target paths. */
|
|
3445
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3446
|
-
readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
3447
|
-
}>>;
|
|
3797
|
+
type EventHandlerMap<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, true>>>;
|
|
3448
3798
|
/**
|
|
3449
3799
|
* Runtime state config stored for a single state tag.
|
|
3450
3800
|
*
|
|
@@ -3455,14 +3805,8 @@ export declare namespace Machine {
|
|
|
3455
3805
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
|
|
3456
3806
|
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
|
|
3457
3807
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
|
|
3458
|
-
readonly always?:
|
|
3459
|
-
|
|
3460
|
-
readonly transition: (context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
3461
|
-
};
|
|
3462
|
-
readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
|
|
3463
|
-
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3464
|
-
readonly transition: (context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
3465
|
-
};
|
|
3808
|
+
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId>>;
|
|
3809
|
+
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId>>;
|
|
3466
3810
|
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
|
|
3467
3811
|
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
|
|
3468
3812
|
}
|
|
@@ -3494,15 +3838,15 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
3494
3838
|
* **When to use**
|
|
3495
3839
|
*
|
|
3496
3840
|
* Use when you want to pass a state tree to `make` and also get typed
|
|
3497
|
-
* snapshot
|
|
3841
|
+
* snapshot matching and access helpers.
|
|
3498
3842
|
*
|
|
3499
3843
|
* **Details**
|
|
3500
3844
|
*
|
|
3501
3845
|
* The returned `states` property is the same object passed to `defineStates`.
|
|
3502
|
-
*
|
|
3503
|
-
*
|
|
3504
|
-
*
|
|
3505
|
-
*
|
|
3846
|
+
* `Machine.make` derives its initial target selector from that tree and
|
|
3847
|
+
* enforces compound and parallel initial-state rules. Active nodes may omit
|
|
3848
|
+
* `schema` when they own no value and still participate fully in targeting,
|
|
3849
|
+
* matching, and snapshots.
|
|
3506
3850
|
*
|
|
3507
3851
|
* **Example** (Atomic initial snapshot)
|
|
3508
3852
|
*
|
|
@@ -3517,7 +3861,10 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
3517
3861
|
* Machine.make({
|
|
3518
3862
|
* states: States.states,
|
|
3519
3863
|
* events: Machine.events(),
|
|
3520
|
-
* initial:
|
|
3864
|
+
* initial: {
|
|
3865
|
+
* target: (to) => to.idle(),
|
|
3866
|
+
* resolve: ({ target }) => target.from()
|
|
3867
|
+
* }
|
|
3521
3868
|
* })
|
|
3522
3869
|
* ```
|
|
3523
3870
|
*
|
|
@@ -3525,6 +3872,15 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
3525
3872
|
* @since 0.4.0
|
|
3526
3873
|
*/
|
|
3527
3874
|
export declare const defineStates: DefineStates;
|
|
3875
|
+
type InitialDirectInput<States extends Machine.StateSchemas, Input, Selection extends Machine.TargetSelection<any, any, any>> = {
|
|
3876
|
+
readonly target: (to: Machine.InitialSelector<States>) => Selection;
|
|
3877
|
+
readonly resolve?: (context: {
|
|
3878
|
+
readonly input: Input;
|
|
3879
|
+
readonly target: Machine.SelectionBuilder<Selection>;
|
|
3880
|
+
}) => Machine.SelectedTargetResult<Selection>;
|
|
3881
|
+
readonly cases?: never;
|
|
3882
|
+
readonly otherwise?: never;
|
|
3883
|
+
};
|
|
3528
3884
|
type MakeConfig<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> = {
|
|
3529
3885
|
readonly id?: string;
|
|
3530
3886
|
readonly states: States & DefineStateTreeInput<NoInfer<States>>;
|
|
@@ -3533,11 +3889,13 @@ type MakeConfig<States extends Machine.StateSchemas, InputEvents extends Readonl
|
|
|
3533
3889
|
readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>;
|
|
3534
3890
|
readonly parentEvents?: Machine.EventProtocol<"public", ParentEvents>;
|
|
3535
3891
|
readonly input?: Input;
|
|
3536
|
-
readonly initial:
|
|
3892
|
+
readonly initial: unknown;
|
|
3537
3893
|
};
|
|
3538
3894
|
type MakeResult<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> = Machine<States, readonly [...InputEvents, ...InternalEvents], Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, Machine.FinalStateFromDefinition<States>, Machine.TerminalOutput<States>, Emits, never, InputEvents, ParentEvents>;
|
|
3539
3895
|
interface Make {
|
|
3540
|
-
<const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []
|
|
3896
|
+
<const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const InitialSelection extends Machine.TargetSelection<any, any, any> = Machine.TargetSelection<any, any, any>>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>, "initial"> & {
|
|
3897
|
+
readonly initial: InitialDirectInput<States, Input["Type"], InitialSelection>;
|
|
3898
|
+
}, ..._validation: ValidateDefinedStates<NoInfer<States>>): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>;
|
|
3541
3899
|
<const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>, "states"> & {
|
|
3542
3900
|
readonly states: InvalidDefinedStateTreeInput<States>;
|
|
3543
3901
|
}): never;
|
|
@@ -3581,18 +3939,24 @@ interface Make {
|
|
|
3581
3939
|
* const counter = Machine.make({
|
|
3582
3940
|
* states: States.states,
|
|
3583
3941
|
* events: Events,
|
|
3584
|
-
* initial:
|
|
3942
|
+
* initial: {
|
|
3943
|
+
* target: (to) => to.Count(),
|
|
3944
|
+
* resolve: ({ target }) => target(new Count({ value: 0 }))
|
|
3945
|
+
* }
|
|
3585
3946
|
* }).handle({
|
|
3586
3947
|
* Count: {
|
|
3587
3948
|
* on: {
|
|
3588
|
-
* Increment: ({
|
|
3589
|
-
*
|
|
3949
|
+
* Increment: Machine.transition({
|
|
3950
|
+
* target: (to) => to.full.Count(),
|
|
3951
|
+
* resolve: ({ event, state, target }) =>
|
|
3952
|
+
* target(new Count({ value: state.value + event.by }))
|
|
3953
|
+
* })
|
|
3590
3954
|
* }
|
|
3591
3955
|
* }
|
|
3592
3956
|
* })
|
|
3593
3957
|
* ```
|
|
3594
3958
|
*
|
|
3595
|
-
* @see {@link defineStates} for typed
|
|
3959
|
+
* @see {@link defineStates} for typed state-tree helpers.
|
|
3596
3960
|
* @category constructors
|
|
3597
3961
|
* @since 0.4.0
|
|
3598
3962
|
*/
|
|
@@ -3700,7 +4064,10 @@ export declare const emittedEvents: {
|
|
|
3700
4064
|
* const machine = Machine.make({
|
|
3701
4065
|
* states: States.states,
|
|
3702
4066
|
* events: Machine.events(),
|
|
3703
|
-
* initial:
|
|
4067
|
+
* initial: {
|
|
4068
|
+
* target: (to) => to.Idle(),
|
|
4069
|
+
* resolve: ({ target }) => target.from()
|
|
4070
|
+
* }
|
|
3704
4071
|
* }).handle({ Idle: {} })
|
|
3705
4072
|
*
|
|
3706
4073
|
* const encoded = Effect.gen(function*() {
|
|
@@ -3744,7 +4111,10 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
3744
4111
|
* const machine = Machine.make({
|
|
3745
4112
|
* states: States.states,
|
|
3746
4113
|
* events: Machine.events(),
|
|
3747
|
-
* initial:
|
|
4114
|
+
* initial: {
|
|
4115
|
+
* target: (to) => to.Idle(),
|
|
4116
|
+
* resolve: ({ target }) => target.from()
|
|
4117
|
+
* }
|
|
3748
4118
|
* }).handle({ Idle: {} })
|
|
3749
4119
|
*
|
|
3750
4120
|
* const roundTrip = Effect.gen(function*() {
|
|
@@ -3759,7 +4129,7 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
3759
4129
|
* @since 0.4.0
|
|
3760
4130
|
*/
|
|
3761
4131
|
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
3762
|
-
type
|
|
4132
|
+
type EffectInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<unknown, unknown, unknown>> = {
|
|
3763
4133
|
readonly id: InvokeLifecycleId;
|
|
3764
4134
|
readonly effect: Source;
|
|
3765
4135
|
readonly after?: never;
|
|
@@ -3768,11 +4138,11 @@ type DynamicEffectInvokeSource<States extends Machine.StateSchemas, Events exten
|
|
|
3768
4138
|
readonly address?: never;
|
|
3769
4139
|
readonly onSnapshot?: never;
|
|
3770
4140
|
};
|
|
3771
|
-
type
|
|
3772
|
-
type
|
|
3773
|
-
type
|
|
4141
|
+
type EffectDoneHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>, readonly [], readonly []>>;
|
|
4142
|
+
type EffectFailureHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>, readonly [], readonly []>>;
|
|
4143
|
+
type EffectInvokeResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeConfig<States, Events, Emits, StateId, readonly [], readonly []> & Machine.InvokeTyped<Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never>;
|
|
3774
4144
|
type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false;
|
|
3775
|
-
type
|
|
4145
|
+
type BoundEffectInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>> = {
|
|
3776
4146
|
readonly id: InvokeLifecycleId;
|
|
3777
4147
|
readonly effect: Source;
|
|
3778
4148
|
readonly after?: never;
|
|
@@ -3781,9 +4151,77 @@ type BoundDynamicEffectInvokeSource<States extends Machine.StateSchemas, Events
|
|
|
3781
4151
|
readonly address?: never;
|
|
3782
4152
|
readonly onSnapshot?: never;
|
|
3783
4153
|
};
|
|
3784
|
-
type
|
|
3785
|
-
type
|
|
3786
|
-
type
|
|
4154
|
+
type BoundEffectDoneHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>, InputEvents, ParentEvents>>;
|
|
4155
|
+
type BoundEffectFailureHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, StateId, Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>, InputEvents, ParentEvents>>;
|
|
4156
|
+
type BoundEffectInvokeResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never>;
|
|
4157
|
+
/** Type evidence retained for a case created by a conditional transition's local builder. */
|
|
4158
|
+
interface TransitionCaseTyped {
|
|
4159
|
+
readonly [TransitionCaseTypeId]: true;
|
|
4160
|
+
}
|
|
4161
|
+
/** Locally bound constructor that preserves each conditional transition case independently. */
|
|
4162
|
+
interface TransitionCaseConstructor<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateNodeIdentifier<States>, Context> {
|
|
4163
|
+
<const Selection extends Machine.TargetSelection<any, any, any>, const Match>(config: Machine.TransitionCaseInput<States, Events, Emits, StateId, Context, Selection, Match>): Machine.TransitionCaseInput<States, Events, Emits, StateId, Context, Selection, Match> & TransitionCaseTyped;
|
|
4164
|
+
}
|
|
4165
|
+
/**
|
|
4166
|
+
* Captures one exact transition topology while preserving handler inference.
|
|
4167
|
+
*
|
|
4168
|
+
* @category constructors
|
|
4169
|
+
* @since 0.14.0
|
|
4170
|
+
*/
|
|
4171
|
+
type ConditionalTransitionResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateNodeIdentifier<States>, Context, Reenter extends boolean, Cases extends readonly [
|
|
4172
|
+
TransitionCaseTyped,
|
|
4173
|
+
...ReadonlyArray<TransitionCaseTyped>
|
|
4174
|
+
], OtherwiseSelection extends Machine.TargetSelection<any, any, any>> = Omit<Machine.TransitionConditionalInput<States, Events, Emits, StateId, Context, Reenter, Cases, OtherwiseSelection>, "cases"> & {
|
|
4175
|
+
readonly cases: Cases;
|
|
4176
|
+
} & Machine.TransitionTyped<States, Events, Emits, StateId, Context, Reenter>;
|
|
4177
|
+
/**
|
|
4178
|
+
* Contextually types direct and conditional transition definitions.
|
|
4179
|
+
*
|
|
4180
|
+
* @category constructors
|
|
4181
|
+
* @since 0.14.0
|
|
4182
|
+
*/
|
|
4183
|
+
export interface TransitionConstructor {
|
|
4184
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateNodeIdentifier<States>, Context, const Selection extends Machine.TargetSelection<any, any, any>, Reenter extends boolean = never>(config: Machine.TransitionDirectInput<States, Events, Emits, StateId, Context, Reenter, Selection>): Machine.TransitionDirectInput<States, Events, Emits, StateId, Context, Reenter, Selection> & (Machine.SelectionKind<Selection> extends "none" ? Machine.TargetlessTransitionTyped : Machine.TransitionTyped<States, Events, Emits, StateId, Context, Reenter>);
|
|
4185
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateNodeIdentifier<States>, Context, const Cases extends readonly [
|
|
4186
|
+
TransitionCaseTyped,
|
|
4187
|
+
...ReadonlyArray<TransitionCaseTyped>
|
|
4188
|
+
], const OtherwiseSelection extends Machine.TargetSelection<any, any, any>, Reenter extends boolean = never>(config: Machine.TransitionConditionalInput<States, Events, Emits, StateId, Context, Reenter, Cases, OtherwiseSelection>): ConditionalTransitionResult<States, Events, Emits, StateId, Context, Reenter, Cases, OtherwiseSelection>;
|
|
4189
|
+
}
|
|
4190
|
+
/**
|
|
4191
|
+
* Defines a statically inspectable transition.
|
|
4192
|
+
*
|
|
4193
|
+
* It is required for every event, lifecycle, choice, and invocation transition
|
|
4194
|
+
* so the destination selected by `target` can contextually type the
|
|
4195
|
+
* corresponding resolver. Conditional transitions use the locally bound
|
|
4196
|
+
* `branch` constructor so every case independently infers its matched value and
|
|
4197
|
+
* selected destination, with no limit on the number of cases.
|
|
4198
|
+
*
|
|
4199
|
+
* ```ts
|
|
4200
|
+
* Machine.transition({
|
|
4201
|
+
* target: (to) => to.full.Ready(),
|
|
4202
|
+
* resolve: ({ target }) => target.from()
|
|
4203
|
+
* })
|
|
4204
|
+
*
|
|
4205
|
+
* Machine.transition({
|
|
4206
|
+
* cases: (branch) => [
|
|
4207
|
+
* branch({
|
|
4208
|
+
* title: "has cached data",
|
|
4209
|
+
* when: ({ event }) => event.cached,
|
|
4210
|
+
* target: (to) => to.full.Ready(),
|
|
4211
|
+
* resolve: ({ match, target }) => target.from({ data: match })
|
|
4212
|
+
* })
|
|
4213
|
+
* ],
|
|
4214
|
+
* otherwise: {
|
|
4215
|
+
* target: (to) => to.full.Loading(),
|
|
4216
|
+
* resolve: ({ target }) => target.from()
|
|
4217
|
+
* }
|
|
4218
|
+
* })
|
|
4219
|
+
* ```
|
|
4220
|
+
*
|
|
4221
|
+
* @category constructors
|
|
4222
|
+
* @since 0.14.0
|
|
4223
|
+
*/
|
|
4224
|
+
export declare const transition: TransitionConstructor;
|
|
3787
4225
|
/**
|
|
3788
4226
|
* Machine-bound invocation constructor that preserves the owning machine's
|
|
3789
4227
|
* public input and parent protocols in every invocation callback.
|
|
@@ -3792,34 +4230,47 @@ type BoundDynamicEffectInvokeResult<States extends Machine.StateSchemas, Events
|
|
|
3792
4230
|
* @since 0.11.0
|
|
3793
4231
|
*/
|
|
3794
4232
|
export interface Invoker<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> {
|
|
3795
|
-
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>>(config:
|
|
3796
|
-
readonly onDone:
|
|
3797
|
-
readonly onFailure:
|
|
4233
|
+
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>>(config: BoundEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4234
|
+
readonly onDone: BoundEffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4235
|
+
readonly onFailure: BoundEffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
3798
4236
|
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
3799
4237
|
"onDone must be omitted when the Effect output is never"
|
|
3800
4238
|
] : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
3801
4239
|
"onFailure must be omitted when the Effect error is never"
|
|
3802
|
-
] : []):
|
|
3803
|
-
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, never, unknown>>(config:
|
|
3804
|
-
readonly onDone:
|
|
4240
|
+
] : []): BoundEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4241
|
+
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, never, unknown>>(config: BoundEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
4242
|
+
readonly onDone: BoundEffectDoneHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
3805
4243
|
readonly onFailure?: never;
|
|
3806
4244
|
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
3807
4245
|
"onDone must be omitted when the Effect output is never"
|
|
3808
|
-
] : []):
|
|
3809
|
-
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<never, unknown, unknown>>(config:
|
|
4246
|
+
] : []): BoundEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4247
|
+
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<never, unknown, unknown>>(config: BoundEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
3810
4248
|
readonly onDone?: never;
|
|
3811
|
-
readonly onFailure:
|
|
4249
|
+
readonly onFailure: BoundEffectFailureHandler<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
3812
4250
|
}, ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
3813
4251
|
"onFailure must be omitted when the Effect error is never"
|
|
3814
|
-
] : []):
|
|
3815
|
-
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<never, never, unknown>>(config:
|
|
4252
|
+
] : []): BoundEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
4253
|
+
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<never, never, unknown>>(config: BoundEffectInvokeSource<States, Events, Emits, InputEvents, ParentEvents, StateId, Source> & {
|
|
3816
4254
|
readonly onDone?: never;
|
|
3817
4255
|
readonly onFailure?: never;
|
|
3818
|
-
}):
|
|
3819
|
-
<StateId extends Machine.StateIdentifier<States>, const Fx extends Effect.Effect<any, any, any>, const Config extends object>(config: Config & Machine.EffectInvokeArgs<States, Events, Emits, StateId, Fx, Fx, InputEvents, ParentEvents>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Effect.Success<Fx>, Effect.Error<Fx>, Effect.Services<Fx>, never>;
|
|
4256
|
+
}): BoundEffectInvokeResult<States, Events, Emits, InputEvents, ParentEvents, StateId, Source>;
|
|
3820
4257
|
<StateId extends Machine.StateIdentifier<States>, const Config extends object>(config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, InputEvents, ParentEvents>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>;
|
|
3821
|
-
<StateId extends Machine.StateIdentifier<States>,
|
|
3822
|
-
|
|
4258
|
+
<StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown, Address extends ChildAddress<never>>(config: {
|
|
4259
|
+
readonly logic: Source;
|
|
4260
|
+
} & Machine.LogicInvokeArgs<States, Events, Emits, StateId, Machine.LogicStateOf<ReturnType<Source>>, Machine.LogicEventOf<ReturnType<Source>>, Machine.LogicErrorOf<ReturnType<Source>>, Machine.LogicServicesOf<ReturnType<Source>>, Machine.LogicOutputOf<ReturnType<Source>>, Machine.LogicInitialErrorOf<ReturnType<Source>>, Address, Source, InputEvents, ParentEvents>, ..._validation: ReturnType<Source> extends {
|
|
4261
|
+
readonly initial: unknown;
|
|
4262
|
+
readonly run: unknown;
|
|
4263
|
+
} ? [] : [
|
|
4264
|
+
"logic factory must return Machine.Logic"
|
|
4265
|
+
]): Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<Machine.LogicOutputOf<ReturnType<Source>>, Machine.LogicErrorOf<ReturnType<Source>>, Machine.LogicServicesOf<ReturnType<Source>>, Machine.LogicInitialErrorOf<ReturnType<Source>>>;
|
|
4266
|
+
<StateId extends Machine.StateIdentifier<States>, const Source, Address extends ChildAddress<never>>(config: {
|
|
4267
|
+
readonly logic: Source;
|
|
4268
|
+
} & Machine.LogicInvokeArgs<States, Events, Emits, StateId, Machine.LogicStateOf<Source>, Machine.LogicEventOf<Source>, Machine.LogicErrorOf<Source>, Machine.LogicServicesOf<Source>, Machine.LogicOutputOf<Source>, Machine.LogicInitialErrorOf<Source>, Address, Source, InputEvents, ParentEvents>, ..._validation: Source extends {
|
|
4269
|
+
readonly initial: unknown;
|
|
4270
|
+
readonly run: unknown;
|
|
4271
|
+
} ? [] : [
|
|
4272
|
+
"logic must implement Machine.Logic"
|
|
4273
|
+
]): Machine.InvokeConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> & Machine.InvokeTyped<Machine.LogicOutputOf<Source>, Machine.LogicErrorOf<Source>, Machine.LogicServicesOf<Source>, Machine.LogicInitialErrorOf<Source>>;
|
|
3823
4274
|
<StateId extends Machine.StateIdentifier<States>, const Child extends ChildMachine.Any, const Config extends object>(config: Config & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child, InputEvents, ParentEvents>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Machine.Output<Child["machine"]>, Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>, Machine.Services<Child["machine"]>, Machine.InitialError<Child["machine"]>, Machine.Emit<Child["machine"]>, Machine.EventOf<Machine.ParentEvents<Child["machine"]>>>;
|
|
3824
4275
|
}
|
|
3825
4276
|
/**
|
|
@@ -3831,12 +4282,13 @@ export interface Invoker<States extends Machine.StateSchemas, Events extends Rea
|
|
|
3831
4282
|
* is required only when the source has a typed failure channel.
|
|
3832
4283
|
*
|
|
3833
4284
|
* This constructor is an identity at runtime, but preserves lifecycle callback
|
|
3834
|
-
* inference through published declarations.
|
|
3835
|
-
*
|
|
3836
|
-
*
|
|
3837
|
-
*
|
|
3838
|
-
* lifecycle `id` and a typed communication
|
|
3839
|
-
* own their identity, so `id` and
|
|
4285
|
+
* inference through published declarations. Effect factories run when their
|
|
4286
|
+
* owning state is entered and infer the owner context, output, error, and
|
|
4287
|
+
* service channels together without a return annotation. Durations may be
|
|
4288
|
+
* supplied directly or derived from the owning state's entry context. Logic
|
|
4289
|
+
* invocations require both a lifecycle `id` and a typed communication
|
|
4290
|
+
* `address`. Child descriptors already own their identity, so `id` and
|
|
4291
|
+
* `address` must not be repeated.
|
|
3840
4292
|
*
|
|
3841
4293
|
* Owner references are intentionally non-sendable here because this standalone
|
|
3842
4294
|
* constructor does not know the owning definition. When a callback sends to
|
|
@@ -3847,12 +4299,19 @@ export interface Invoker<States extends Machine.StateSchemas, Events extends Rea
|
|
|
3847
4299
|
* ```ts
|
|
3848
4300
|
* invoke: Machine.invoke({
|
|
3849
4301
|
* id: "load",
|
|
3850
|
-
* effect:
|
|
3851
|
-
*
|
|
3852
|
-
*
|
|
4302
|
+
* effect: () =>
|
|
4303
|
+
* Effect.tryPromise({
|
|
4304
|
+
* try: () => fetch("/api/data").then((response) => response.json()),
|
|
4305
|
+
* catch: (cause) => new LoadError({ cause })
|
|
4306
|
+
* }),
|
|
4307
|
+
* onDone: Machine.transition({
|
|
4308
|
+
* target: (to) => to.full.Ready(),
|
|
4309
|
+
* resolve: ({ output, target }) => target.from({ data: output })
|
|
3853
4310
|
* }),
|
|
3854
|
-
*
|
|
3855
|
-
*
|
|
4311
|
+
* onFailure: Machine.transition({
|
|
4312
|
+
* target: (to) => to.full.Failed(),
|
|
4313
|
+
* resolve: ({ error, target }) => target.from({ error })
|
|
4314
|
+
* })
|
|
3856
4315
|
* })
|
|
3857
4316
|
* ```
|
|
3858
4317
|
*
|
|
@@ -3860,31 +4319,30 @@ export interface Invoker<States extends Machine.StateSchemas, Events extends Rea
|
|
|
3860
4319
|
* @since 0.9.0
|
|
3861
4320
|
*/
|
|
3862
4321
|
export declare const invoke: {
|
|
3863
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<unknown, unknown, unknown>>(config:
|
|
3864
|
-
readonly onDone:
|
|
3865
|
-
readonly onFailure:
|
|
4322
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<unknown, unknown, unknown>>(config: EffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
4323
|
+
readonly onDone: EffectDoneHandler<States, Events, Emits, StateId, Source>;
|
|
4324
|
+
readonly onFailure: EffectFailureHandler<States, Events, Emits, StateId, Source>;
|
|
3866
4325
|
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
3867
4326
|
"onDone must be omitted when the Effect output is never"
|
|
3868
4327
|
] : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
3869
4328
|
"onFailure must be omitted when the Effect error is never"
|
|
3870
|
-
] : []):
|
|
3871
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<unknown, never, unknown>>(config:
|
|
3872
|
-
readonly onDone:
|
|
4329
|
+
] : []): EffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
4330
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<unknown, never, unknown>>(config: EffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
4331
|
+
readonly onDone: EffectDoneHandler<States, Events, Emits, StateId, Source>;
|
|
3873
4332
|
readonly onFailure?: never;
|
|
3874
4333
|
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
3875
4334
|
"onDone must be omitted when the Effect output is never"
|
|
3876
|
-
] : []):
|
|
3877
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<never, unknown, unknown>>(config:
|
|
4335
|
+
] : []): EffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
4336
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<never, unknown, unknown>>(config: EffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3878
4337
|
readonly onDone?: never;
|
|
3879
|
-
readonly onFailure:
|
|
4338
|
+
readonly onFailure: EffectFailureHandler<States, Events, Emits, StateId, Source>;
|
|
3880
4339
|
}, ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
3881
4340
|
"onFailure must be omitted when the Effect error is never"
|
|
3882
|
-
] : []):
|
|
3883
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<never, never, unknown>>(config:
|
|
4341
|
+
] : []): EffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
4342
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Effect.Effect<never, never, unknown>>(config: EffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3884
4343
|
readonly onDone?: never;
|
|
3885
4344
|
readonly onFailure?: never;
|
|
3886
|
-
}):
|
|
3887
|
-
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Fx extends Effect.Effect<any, any, any>, const Config extends object>(config: Config & Machine.EffectInvokeArgs<States, Events, Emits, StateId, Fx, Fx, readonly [], readonly []>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Effect.Success<Fx>, Effect.Error<Fx>, Effect.Services<Fx>, never>;
|
|
4345
|
+
}): EffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3888
4346
|
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Config extends object>(config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId, readonly [], readonly []>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>;
|
|
3889
4347
|
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>>(config: Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address, (context: Machine.InvokeContext<States, Events, Emits, StateId, readonly [], readonly []>) => Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, readonly [], readonly []>): Machine.InvokeConfig<States, Events, Emits, StateId, readonly [], readonly []> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
|
|
3890
4348
|
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, const Config extends object>(config: Config & Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address, Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, readonly [], readonly []>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
|
|
@@ -3919,7 +4377,10 @@ export declare const invoke: {
|
|
|
3919
4377
|
* const machine = Machine.make({
|
|
3920
4378
|
* states: States.states,
|
|
3921
4379
|
* events: Machine.events(),
|
|
3922
|
-
* initial:
|
|
4380
|
+
* initial: {
|
|
4381
|
+
* target: (to) => to.Idle(),
|
|
4382
|
+
* resolve: ({ target }) => target.from()
|
|
4383
|
+
* }
|
|
3923
4384
|
* }).handle({ Idle: {} })
|
|
3924
4385
|
*
|
|
3925
4386
|
* const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
|
|
@@ -3969,6 +4430,17 @@ export declare const planInitial: <const States extends Machine.StateSchemas, co
|
|
|
3969
4430
|
* @since 0.4.0
|
|
3970
4431
|
*/
|
|
3971
4432
|
export declare const stateNodes: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.StateNode<Machine.StateIdentifier<Machine.States<M>>, Machine.HistoryIdentifier<Machine.States<M>>, Machine.ChoiceIdentifier<Machine.States<M>>>>;
|
|
4433
|
+
/**
|
|
4434
|
+
* Returns the statically selected root entry used during machine startup.
|
|
4435
|
+
*
|
|
4436
|
+
* This function does not execute the initial resolver or require machine
|
|
4437
|
+
* input. `kind: "initial"` means that the selected root enters its declared
|
|
4438
|
+
* initial configuration.
|
|
4439
|
+
*
|
|
4440
|
+
* @category getters
|
|
4441
|
+
* @since 0.14.0
|
|
4442
|
+
*/
|
|
4443
|
+
export declare const initialDefinition: <M extends Machine.Any>(machine: M) => Machine.InitialDefinition<Machine.RootStateIdentifier<Machine.StateIdentifier<Machine.States<M>>>>;
|
|
3972
4444
|
/**
|
|
3973
4445
|
* Returns every registered transition handler in state definition order.
|
|
3974
4446
|
*
|
|
@@ -3976,9 +4448,9 @@ export declare const stateNodes: <M extends Machine.Any>(machine: M) => Readonly
|
|
|
3976
4448
|
*
|
|
3977
4449
|
* Event handlers retain their handler-key order within each source state and
|
|
3978
4450
|
* are followed by eventless and completion handlers. This function does not
|
|
3979
|
-
* execute
|
|
3980
|
-
*
|
|
3981
|
-
*
|
|
4451
|
+
* execute predicates or resolvers. Every direct, conditional, fallback, and
|
|
4452
|
+
* targetless branch exposes the destination selected by its required static
|
|
4453
|
+
* `target` declaration.
|
|
3982
4454
|
*
|
|
3983
4455
|
* @category getters
|
|
3984
4456
|
* @since 0.4.0
|
|
@@ -4047,8 +4519,21 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
4047
4519
|
* const machine = Machine.make({
|
|
4048
4520
|
* states: States.states,
|
|
4049
4521
|
* events: Machine.events(Toggle),
|
|
4050
|
-
* initial:
|
|
4051
|
-
*
|
|
4522
|
+
* initial: {
|
|
4523
|
+
* target: (to) => to.Off(),
|
|
4524
|
+
* resolve: ({ target }) => target.from()
|
|
4525
|
+
* }
|
|
4526
|
+
* }).handle({
|
|
4527
|
+
* Off: {
|
|
4528
|
+
* on: {
|
|
4529
|
+
* Toggle: Machine.transition({
|
|
4530
|
+
* target: (to) => to.full.On(),
|
|
4531
|
+
* resolve: ({ target }) => target.from()
|
|
4532
|
+
* })
|
|
4533
|
+
* }
|
|
4534
|
+
* },
|
|
4535
|
+
* On: {}
|
|
4536
|
+
* })
|
|
4052
4537
|
*
|
|
4053
4538
|
* const nextState = Effect.gen(function*() {
|
|
4054
4539
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -4115,37 +4600,6 @@ export declare const logic: <State, Event = never, Output = void, Error = never,
|
|
|
4115
4600
|
readonly initial: State | ((scope: Logic.Scope<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
|
|
4116
4601
|
readonly run: (context: Logic.Context<State, Event>) => Effect.Effect<Output, Error, Requirements>;
|
|
4117
4602
|
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError>;
|
|
4118
|
-
/**
|
|
4119
|
-
* Creates child process logic from an initial state and a transition function.
|
|
4120
|
-
*
|
|
4121
|
-
* **When to use**
|
|
4122
|
-
*
|
|
4123
|
-
* Use when a child process only needs sequential event-driven state updates and
|
|
4124
|
-
* does not need direct control over intermediate snapshots or child ownership.
|
|
4125
|
-
*
|
|
4126
|
-
* **Details**
|
|
4127
|
-
*
|
|
4128
|
-
* Each received event runs the transition Effect against the latest state. The
|
|
4129
|
-
* resulting state is published before the next queued event is processed.
|
|
4130
|
-
*
|
|
4131
|
-
* **Example**
|
|
4132
|
-
*
|
|
4133
|
-
* ```ts
|
|
4134
|
-
* import { Effect } from "effect"
|
|
4135
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
4136
|
-
*
|
|
4137
|
-
* const counter = Machine.transition(
|
|
4138
|
-
* 0,
|
|
4139
|
-
* (count, event: { readonly by: number }) => Effect.succeed(count + event.by)
|
|
4140
|
-
* )
|
|
4141
|
-
* ```
|
|
4142
|
-
*
|
|
4143
|
-
* Use an inline `invoke` with an `effect` source for one-shot work.
|
|
4144
|
-
* @see {@link logic} for direct process lifecycle control.
|
|
4145
|
-
* @category constructors
|
|
4146
|
-
* @since 0.4.0
|
|
4147
|
-
*/
|
|
4148
|
-
export declare const transition: <State, Event, Error = never, Requirements = never>(initial: State, transition: (state: State, event: Event) => Effect.Effect<State, Error, Requirements>) => Logic<State, Event, Error, Requirements, never>;
|
|
4149
4603
|
/**
|
|
4150
4604
|
* Creates a typed descriptor for a complete child machine.
|
|
4151
4605
|
*
|
|
@@ -4272,7 +4726,10 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
|
|
|
4272
4726
|
* const machine = Machine.make({
|
|
4273
4727
|
* states: States.states,
|
|
4274
4728
|
* events: Machine.events(),
|
|
4275
|
-
* initial:
|
|
4729
|
+
* initial: {
|
|
4730
|
+
* target: (to) => to.Idle(),
|
|
4731
|
+
* resolve: ({ target }) => target.from()
|
|
4732
|
+
* }
|
|
4276
4733
|
* }).handle({ Idle: {} })
|
|
4277
4734
|
*
|
|
4278
4735
|
* const state = Effect.gen(function*() {
|
|
@@ -4322,7 +4779,10 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
4322
4779
|
* const machine = Machine.make({
|
|
4323
4780
|
* states: States.states,
|
|
4324
4781
|
* events: Machine.events(),
|
|
4325
|
-
* initial:
|
|
4782
|
+
* initial: {
|
|
4783
|
+
* target: (to) => to.Idle(),
|
|
4784
|
+
* resolve: ({ target }) => target.from()
|
|
4785
|
+
* }
|
|
4326
4786
|
* }).handle({ Idle: {} })
|
|
4327
4787
|
*
|
|
4328
4788
|
* const resumed = Effect.gen(function*() {
|