@typeonce/effect-machine 0.34.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -29
- package/dist/Machine.d.ts +309 -361
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +126 -87
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +0 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +0 -19
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +12 -20
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/initialDeclaration.d.ts +14 -0
- package/dist/internal/machine/initialDeclaration.d.ts.map +1 -0
- package/dist/internal/machine/initialDeclaration.js +137 -0
- package/dist/internal/machine/initialDeclaration.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +0 -2
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +39 -120
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +8 -0
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +25 -67
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +1 -1
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +1 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +1 -13
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/targetReference.d.ts.map +1 -1
- package/dist/internal/machine/targetReference.js +14 -4
- package/dist/internal/machine/targetReference.js.map +1 -1
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +3 -2
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +15 -6
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +7 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +105 -73
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +105 -73
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +13 -8
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +13 -8
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +41 -24
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +41 -24
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/package.json +1 -1
- package/src/Machine.ts +471 -744
- package/src/internal/machine/configuration.ts +0 -20
- package/src/internal/machine/executionPlan.ts +11 -18
- package/src/internal/machine/initialDeclaration.ts +157 -0
- package/src/internal/machine/machine.ts +38 -179
- package/src/internal/machine/planner.ts +30 -83
- package/src/internal/machine/protocol.ts +3 -3
- package/src/internal/machine/stateDefinition.ts +1 -15
- package/src/internal/machine/targetReference.ts +19 -4
- package/src/internal/machine/topology.ts +3 -2
- package/src/internal/testing/machine/finiteModel.ts +16 -10
- package/src/internal/testing/machine/verification.ts +7 -1
- package/src/testing/MachineTest.ts +105 -73
- package/src/unstable/cluster/ClusterMachine.ts +13 -8
- package/src/unstable/reactivity/AtomMachine.ts +41 -24
package/dist/Machine.d.ts
CHANGED
|
@@ -100,20 +100,19 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
100
100
|
* ```ts
|
|
101
101
|
* import { Machine } from "@typeonce/effect-machine"
|
|
102
102
|
* import { Schema } from "effect"
|
|
103
|
-
*
|
|
104
103
|
* const events = Machine.events({ Add: { by: Schema.Number } })
|
|
105
104
|
* const Root = Machine.state({ fields: { count: Schema.Number } })
|
|
106
105
|
* const targets = Machine.targets(Root)
|
|
107
106
|
* export const counter = Machine.make({
|
|
108
107
|
* root: Root,
|
|
109
|
-
* events
|
|
110
|
-
* initial: (root) => root.from(() => ({ count: 0 }))
|
|
108
|
+
* events
|
|
111
109
|
* }).handle({
|
|
110
|
+
* root: () => ({ count: 0 }),
|
|
112
111
|
* on: {
|
|
113
112
|
* Add: {
|
|
114
113
|
* update: targets.root,
|
|
115
114
|
* guard: ({ event }) => event.by > 0,
|
|
116
|
-
*
|
|
115
|
+
* data: ({ root, event }) => ({ count: root.count + event.by })
|
|
117
116
|
* }
|
|
118
117
|
* }
|
|
119
118
|
* })
|
|
@@ -203,7 +202,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
203
202
|
* @category models
|
|
204
203
|
* @since 0.15.0
|
|
205
204
|
*/
|
|
206
|
-
export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], Registrations extends Machine.Registrations = {}> extends Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents> {
|
|
205
|
+
export interface Definition<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], Registrations extends Machine.Registrations = {}> extends Omit<Machine<States, Events, Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, FinalStates, Output, Emits, never, InputEvents, ParentEvents>, TypeId | "stateNodes" | "makeTargetBuilder" | "handlers" | "initial" | "initialDefinition"> {
|
|
207
206
|
/**
|
|
208
207
|
* Adds typed state handlers and returns an independent machine
|
|
209
208
|
* implementation. Event dispatch maps and transition descriptors are
|
|
@@ -243,7 +242,7 @@ export declare namespace Definition {
|
|
|
243
242
|
* @category models
|
|
244
243
|
* @since 0.15.0
|
|
245
244
|
*/
|
|
246
|
-
interface Any extends Machine.Any {
|
|
245
|
+
interface Any extends Omit<Machine.Any, TypeId | "stateNodes" | "makeTargetBuilder" | "handlers" | "initial" | "initialDefinition"> {
|
|
247
246
|
readonly handle: any;
|
|
248
247
|
}
|
|
249
248
|
}
|
|
@@ -516,7 +515,6 @@ export declare namespace Runtime {
|
|
|
516
515
|
}
|
|
517
516
|
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;
|
|
518
517
|
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
519
|
-
declare const InitialBuilderTypeId: unique symbol;
|
|
520
518
|
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
521
519
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
522
520
|
readonly path: Path;
|
|
@@ -569,11 +567,9 @@ type ValidateStateNodeWithChildren<Node extends Machine.StateNodeConfig, Childre
|
|
|
569
567
|
} ? ValidateInitialSelectorChild<Children, Path> & ("initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
|
|
570
568
|
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
571
569
|
} & ValidateOutputSchema<Node>) : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : ValidateCompoundStateNode<Node, Children, Path> : StateDefinitionError<"Child states must be a state tree">;
|
|
572
|
-
type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> =
|
|
573
|
-
readonly initial: infer Initial;
|
|
574
|
-
} ? Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? ValidateInitialSelectorChild<Children, Path> & ValidateWithSelectorChild<Node, Children, Path> & {
|
|
570
|
+
type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> = "initial" extends keyof Node ? StateDefinitionError<"Declare initial edges in handle", Path> : ValidateInitialSelectorChild<Children, Path> & ValidateWithSelectorChild<Node, Children, Path> & {
|
|
575
571
|
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
576
|
-
}
|
|
572
|
+
};
|
|
577
573
|
type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
|
|
578
574
|
readonly type: infer Type;
|
|
579
575
|
} ? Type extends "final" ? ValidateOutputSchema<Node> : Type extends "active" | undefined ? "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown : StateDefinitionError<"State node type must be active, final, or parallel"> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : unknown;
|
|
@@ -712,55 +708,6 @@ type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input
|
|
|
712
708
|
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
713
709
|
<Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
714
710
|
} : <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected) => Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
715
|
-
type InitialSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
|
|
716
|
-
readonly [Key in ActiveStateKey<States>]: InitialSnapshotMethod<States, Key, Prefix>;
|
|
717
|
-
} & {
|
|
718
|
-
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
719
|
-
};
|
|
720
|
-
type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>> : DecodedMethod<InitialSnapshotArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>> & FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>>;
|
|
721
|
-
type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
722
|
-
readonly type: "parallel";
|
|
723
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
724
|
-
} ? WithNodeValue<Node, [
|
|
725
|
-
states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>>
|
|
726
|
-
]> : Node extends {
|
|
727
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
728
|
-
} ? Node extends {
|
|
729
|
-
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
730
|
-
} ? WithNodeValue<Node, [
|
|
731
|
-
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSelectableResult<Children, Initial, Path>
|
|
732
|
-
]> : never : WithNodeValue<Node, []> : never;
|
|
733
|
-
type InitialSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
734
|
-
readonly type: "parallel";
|
|
735
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
736
|
-
} ? WithNodeInput<Node, [
|
|
737
|
-
states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
738
|
-
]> : Node extends {
|
|
739
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
740
|
-
} ? Node extends {
|
|
741
|
-
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
742
|
-
} ? WithNodeInput<Node, [
|
|
743
|
-
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
|
|
744
|
-
]> : never : WithNodeInput<Node, []> : never;
|
|
745
|
-
type InitialSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
746
|
-
readonly type: "parallel";
|
|
747
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
748
|
-
} ? Machine.ParallelSnapshot<Path, NodeValue<Node>, InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
|
|
749
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
750
|
-
} ? Node extends {
|
|
751
|
-
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
752
|
-
} ? Machine.CompoundSnapshot<Path, NodeValue<Node>, InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, NodeValue<Node>> : never;
|
|
753
|
-
type InitialSelectableResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States> | ChoiceStateKey<States>, Prefix extends string> = StateId extends ChoiceStateKey<States> ? Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, StateId>> : StateId extends ActiveStateKey<States> ? InitialSnapshotResult<States, StateId, Prefix> : never;
|
|
754
|
-
type InitialSnapshotRegionsWithPrefix<States extends Machine.StateSchemas, Prefix extends string> = {
|
|
755
|
-
readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>;
|
|
756
|
-
};
|
|
757
|
-
type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
758
|
-
readonly [Key in Remaining]: NodeBuilderMethod<States[Key], InitialSnapshotArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
759
|
-
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
760
|
-
}, Constructed>, InitialSnapshotFromArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
761
|
-
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
762
|
-
}, true>>;
|
|
763
|
-
};
|
|
764
711
|
type FullSnapshotBuilderWithPrefix<in out States extends Machine.StateSchemas, in out Prefix extends string = ""> = {
|
|
765
712
|
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]: Key extends ActiveStateKey<States> ? FullSnapshotMethod<States, Key, Prefix> : () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
766
713
|
};
|
|
@@ -954,8 +901,7 @@ type InitializerClosureForNode<AllStates extends Machine.StateSchemas, Node, Pat
|
|
|
954
901
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
955
902
|
} ? (HasRequiredActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never) | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
|
|
956
903
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
957
|
-
|
|
958
|
-
} ? (Initial extends ActiveStateKey<Children> ? RequiresInitialValue<Children[Initial]> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never : never) | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<AllStates, Children[Initial], Machine.JoinPath<Path, Initial>> : never) : never : never;
|
|
904
|
+
} ? Extract<Path, Machine.StateIdentifier<AllStates>> | InitializerClosuresForChildren<AllStates, Children, Path> : never : never;
|
|
959
905
|
type InitializerClosuresForChildren<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
960
906
|
readonly [Key in ActiveStateKey<States>]: InitializerClosureForNode<AllStates, States[Key], Machine.JoinPath<Prefix, Key>>;
|
|
961
907
|
}[ActiveStateKey<States>];
|
|
@@ -1953,7 +1899,6 @@ export declare namespace Machine {
|
|
|
1953
1899
|
/** Compound states are ordinary active states. */
|
|
1954
1900
|
readonly type?: "active";
|
|
1955
1901
|
/** Direct child selected when the compound state is entered initially. */
|
|
1956
|
-
readonly initial: string;
|
|
1957
1902
|
/** Nested state nodes owned by this compound state. */
|
|
1958
1903
|
readonly states: StateTree;
|
|
1959
1904
|
/** Schema-backed states take their annotations from the schema. */
|
|
@@ -1961,7 +1906,6 @@ export declare namespace Machine {
|
|
|
1961
1906
|
} | {
|
|
1962
1907
|
readonly schema?: never;
|
|
1963
1908
|
readonly type?: "active";
|
|
1964
|
-
readonly initial: string;
|
|
1965
1909
|
readonly states: StateTree;
|
|
1966
1910
|
/** Descriptive metadata for a schema-less state. */
|
|
1967
1911
|
readonly annotations?: SchemaLessStateAnnotations;
|
|
@@ -2073,7 +2017,6 @@ export declare namespace Machine {
|
|
|
2073
2017
|
* @category utility types
|
|
2074
2018
|
* @since 0.4.0
|
|
2075
2019
|
*/
|
|
2076
|
-
type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>;
|
|
2077
2020
|
/**
|
|
2078
2021
|
* Typed snapshot access shared by state descriptors.
|
|
2079
2022
|
*
|
|
@@ -2458,12 +2401,10 @@ export declare namespace Machine {
|
|
|
2458
2401
|
type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = IsAny<States> extends true ? unknown : ([HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
2459
2402
|
readonly "~effect/Machine/MissingHistoryImplementation": MissingHistoryImplementations<States, UnhandledStates>;
|
|
2460
2403
|
}) & EnsureChoiceImplementations<States, UnhandledStates>;
|
|
2461
|
-
/** Owners
|
|
2462
|
-
type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never : "" extends keyof States ? States[""]
|
|
2463
|
-
readonly "~effect/Machine/ExplicitInitial": true;
|
|
2464
|
-
} ? never : InitializerClosureForNode<States, States[""], ""> : never;
|
|
2404
|
+
/** Owners that require a handler-owned initial edge or region data. */
|
|
2405
|
+
type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never : "" extends keyof States ? InitializerClosureForNode<States, States[""], ""> : never;
|
|
2465
2406
|
/** Proof that initialization can construct every required default value. */
|
|
2466
|
-
type EnsureInitialImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown : {
|
|
2407
|
+
type EnsureInitialImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [UnhandledStates] extends [never] ? unknown : [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown : {
|
|
2467
2408
|
readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>;
|
|
2468
2409
|
};
|
|
2469
2410
|
/**
|
|
@@ -3143,14 +3084,6 @@ export declare namespace Machine {
|
|
|
3143
3084
|
type RootBuilder<Builder> = Builder extends {
|
|
3144
3085
|
readonly "": infer Root;
|
|
3145
3086
|
} ? Root : never;
|
|
3146
|
-
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
3147
|
-
type InitialTargetSelector<States extends StateSchemas> = {
|
|
3148
|
-
readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends {
|
|
3149
|
-
readonly states: StateSchemas;
|
|
3150
|
-
} ? {
|
|
3151
|
-
readonly initial: SelectionValue<InitialBuilder<States>[Key], Key, "initial", "initial">;
|
|
3152
|
-
} : SelectionMethod<InitialBuilder<States>[Key], Key, "state", "initial">;
|
|
3153
|
-
};
|
|
3154
3087
|
/**
|
|
3155
3088
|
* Context passed to a state/event handler.
|
|
3156
3089
|
*
|
|
@@ -3399,11 +3332,7 @@ export declare namespace Machine {
|
|
|
3399
3332
|
* @category utility types
|
|
3400
3333
|
* @since 0.4.0
|
|
3401
3334
|
*/
|
|
3402
|
-
type InitialResult<States extends StateSchemas, E, R> =
|
|
3403
|
-
/** Initial snapshots may transiently terminate in a declared choice node. */
|
|
3404
|
-
type InitialSnapshot<States extends StateSchemas> = {
|
|
3405
|
-
readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">;
|
|
3406
|
-
}[ActiveStateKey<States>];
|
|
3335
|
+
type InitialResult<States extends StateSchemas, E, R> = InitialTarget<StateIdentifier<States>>;
|
|
3407
3336
|
/**
|
|
3408
3337
|
* Return value accepted from transition handlers.
|
|
3409
3338
|
*
|
|
@@ -3456,10 +3385,6 @@ export declare namespace Machine {
|
|
|
3456
3385
|
* @since 0.4.0
|
|
3457
3386
|
*/
|
|
3458
3387
|
type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3459
|
-
/** Extracts the return value from an implicit initial child implementation. */
|
|
3460
|
-
type StateInitializeReturn<Config> = Config extends {
|
|
3461
|
-
readonly initialize?: infer Initialize;
|
|
3462
|
-
} ? NonNullable<Initialize> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3463
3388
|
/** Extracts the return values from a state's history defaults. */
|
|
3464
3389
|
type HistoryDefaultReturn<Config> = Config extends {
|
|
3465
3390
|
readonly history?: infer History;
|
|
@@ -3651,7 +3576,7 @@ export declare namespace Machine {
|
|
|
3651
3576
|
* @category utility types
|
|
3652
3577
|
* @since 0.4.0
|
|
3653
3578
|
*/
|
|
3654
|
-
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
|
|
3579
|
+
type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : 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> : never;
|
|
3655
3580
|
/** The only transition value accepted by machine handler APIs. */
|
|
3656
3581
|
type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = Transition<States, StateId, Context, Events, Emits, {}, Reenter, Acceptance>;
|
|
3657
3582
|
type SelectionBuilder<Selection> = Selection extends TargetSelection<infer Builder, any, any, any> ? Builder : never;
|
|
@@ -3740,56 +3665,6 @@ export declare namespace Machine {
|
|
|
3740
3665
|
type TransitionBranchesResolveContext<Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = Omit<Context, "target"> & {
|
|
3741
3666
|
readonly select: BranchSelectors<Branches>;
|
|
3742
3667
|
};
|
|
3743
|
-
type ConstructionCallbacks<Context, Builder, Result> = {
|
|
3744
|
-
readonly [Method in Extract<keyof Builder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown ? Args extends readonly [unknown?] ? Method : never : never]: Builder[Method] extends (...args: infer Args) => unknown ? (value: (context: Context) => Args[0]) => Result : never;
|
|
3745
|
-
};
|
|
3746
|
-
/** @internal Type evidence retained by a machine initial-entry declaration. */
|
|
3747
|
-
interface InitialBuilderEvidence<out Selection> {
|
|
3748
|
-
readonly [InitialBuilderTypeId]: Types.Covariant<Selection>;
|
|
3749
|
-
}
|
|
3750
|
-
/** Decoded input shared by initial construction callbacks. */
|
|
3751
|
-
interface InitialContext<Input> {
|
|
3752
|
-
/** Decoded value supplied when the machine is started. */
|
|
3753
|
-
readonly input: Input;
|
|
3754
|
-
}
|
|
3755
|
-
/** A selected machine initial entry with its exact resolver target. */
|
|
3756
|
-
type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> = Selection & ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<Selection>, InitialBuilderEvidence<Selection>> & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {}) & {
|
|
3757
|
-
/** Lazily constructs the selected initial state from decoded machine input. */
|
|
3758
|
-
readonly resolve: (resolve: (context: {
|
|
3759
|
-
/** Decoded value supplied when the machine is started. */
|
|
3760
|
-
readonly input: Input;
|
|
3761
|
-
/** Builder specialized to the selected initial destination. */
|
|
3762
|
-
readonly target: SelectionBuilder<Selection>;
|
|
3763
|
-
}) => SelectedTargetResult<Selection>) => InitialBuilderEvidence<Selection>;
|
|
3764
|
-
};
|
|
3765
|
-
type InitialSelectorNode<Input, Node> = Node extends (...args: infer Args) => infer Selection ? Selection extends TargetSelection<any, any, any> ? ((...args: Args) => InitialTransitionTarget<Input, Selection>) & {
|
|
3766
|
-
readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>;
|
|
3767
|
-
} : never : Node extends TargetSelection<any, any, any> ? InitialTransitionTarget<Input, Node> : {
|
|
3768
|
-
readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>;
|
|
3769
|
-
};
|
|
3770
|
-
/** Definition-time selector for a machine's top-level initial entry. */
|
|
3771
|
-
type InitialSelector<States extends StateSchemas, Input = void> = InitialSelectorNode<Input, InitialTargetSelector<States>>;
|
|
3772
|
-
/** Target-first initial-entry declaration accepted by {@link make}. */
|
|
3773
|
-
type InitialBuilderInput<States extends StateSchemas, Input> = (to: InitialSelector<States, Input>) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3774
|
-
/** Initializes the root and its declared default descendants. */
|
|
3775
|
-
type RootInitialBuilderInput<Root extends StateNodeConfig, Input> = (root: InitialTransitionTarget<Input, SelectionValue<InitialTargetFactory<Root, "">, "", "initial", "initial">>) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3776
|
-
interface RootConfigurationSelection<in out Root extends StateNodeConfig> extends TargetSelection<FullSnapshotMethod<{
|
|
3777
|
-
readonly "": Root;
|
|
3778
|
-
}, "" & ActiveStateKey<{
|
|
3779
|
-
readonly "": Root;
|
|
3780
|
-
}>, "">, "", "state", "initial"> {
|
|
3781
|
-
}
|
|
3782
|
-
/** Explicitly constructs a complete starting configuration. */
|
|
3783
|
-
type RootConfigurationBuilderInput<Root extends StateNodeConfig, Input> = (root: ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<RootConfigurationSelection<Root>>, InitialBuilderEvidence<RootConfigurationSelection<Root>>> & {
|
|
3784
|
-
readonly resolve: (resolve: (context: {
|
|
3785
|
-
/** Decoded startup input. */
|
|
3786
|
-
readonly input: Input;
|
|
3787
|
-
/** Builder for the complete root configuration. */
|
|
3788
|
-
readonly target: SelectionBuilder<RootConfigurationSelection<Root>>;
|
|
3789
|
-
}) => ConstructionResult<Snapshot<{
|
|
3790
|
-
readonly "": Root;
|
|
3791
|
-
}>>) => InitialBuilderEvidence<RootConfigurationSelection<Root>>;
|
|
3792
|
-
}) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3793
3668
|
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, TransitionAcceptance>;
|
|
3794
3669
|
type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
3795
3670
|
/** Inline state-owned work that runs for the lifetime of its active state. */
|
|
@@ -3887,67 +3762,6 @@ export declare namespace Machine {
|
|
|
3887
3762
|
} ? OutputHandlerConfig<States, Events, StateId, ParallelOutputContext<States, Events, StateId>> : {
|
|
3888
3763
|
readonly output?: never;
|
|
3889
3764
|
};
|
|
3890
|
-
/**
|
|
3891
|
-
* Values constructed for a state's schema-valued direct initial children.
|
|
3892
|
-
*
|
|
3893
|
-
* @category utility types
|
|
3894
|
-
* @since 0.13.0
|
|
3895
|
-
*/
|
|
3896
|
-
type StateInitializeValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
3897
|
-
readonly type: "parallel";
|
|
3898
|
-
readonly states: infer Children extends StateSchemas;
|
|
3899
|
-
} ? {
|
|
3900
|
-
readonly [Key in ActiveStateKey<Children> as NodeSchema<Children[Key]> extends never ? never : Key]: NodeValue<Children[Key]>;
|
|
3901
|
-
} : Node extends {
|
|
3902
|
-
readonly states: infer Children extends StateSchemas;
|
|
3903
|
-
readonly initial: infer Initial;
|
|
3904
|
-
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : {
|
|
3905
|
-
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
3906
|
-
} : never : never : never;
|
|
3907
|
-
type StateInitializeCompoundBuilder<Node, Initial extends PropertyKey> = Node extends {
|
|
3908
|
-
readonly states: infer Children extends StateSchemas;
|
|
3909
|
-
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : NodeBuilderMethod<Children[Initial], readonly [value: NodeValue<Children[Initial]>], SnapshotBuilderComplete<{
|
|
3910
|
-
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
3911
|
-
}>, readonly [input: NodeMakeInput<Children[Initial]>], SnapshotBuilderComplete<{
|
|
3912
|
-
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
3913
|
-
}, true>> : never : never;
|
|
3914
|
-
type StateInitializeParallelBuilder<Children extends StateSchemas, Remaining extends ActiveStateKey<Children> = {
|
|
3915
|
-
readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]> extends never ? never : Key;
|
|
3916
|
-
}[ActiveStateKey<Children>], Values = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Values, Constructed> & {
|
|
3917
|
-
readonly [Key in Remaining]: NodeBuilderMethod<Children[Key], readonly [value: NodeValue<Children[Key]>], StateInitializeParallelBuilder<Children, Exclude<Remaining, Key>, Values & {
|
|
3918
|
-
readonly [Region in Key]: NodeValue<Children[Key]>;
|
|
3919
|
-
}, Constructed>, readonly [input: NodeMakeInput<Children[Key]>], StateInitializeParallelBuilder<Children, Exclude<Remaining, Key>, Values & {
|
|
3920
|
-
readonly [Region in Key]: NodeValue<Children[Key]>;
|
|
3921
|
-
}, true>>;
|
|
3922
|
-
};
|
|
3923
|
-
/**
|
|
3924
|
-
* Builder bound to the direct initial child or regions owned by a state.
|
|
3925
|
-
*
|
|
3926
|
-
* @category utility types
|
|
3927
|
-
* @since 0.13.0
|
|
3928
|
-
*/
|
|
3929
|
-
type StateInitializeBuilder<States extends StateSchemas, StateId extends StateIdentifier<States>, Node = NodeByIdentifier<States, StateId>> = Node extends {
|
|
3930
|
-
readonly type: "parallel";
|
|
3931
|
-
readonly states: infer Children extends StateSchemas;
|
|
3932
|
-
} ? StateInitializeParallelBuilder<Children> : Node extends {
|
|
3933
|
-
readonly initial: infer Initial;
|
|
3934
|
-
} ? StateInitializeCompoundBuilder<Node, Initial & PropertyKey> : never;
|
|
3935
|
-
/**
|
|
3936
|
-
* Context passed to an implicit child-state initializer.
|
|
3937
|
-
*
|
|
3938
|
-
* @category models
|
|
3939
|
-
* @since 0.13.0
|
|
3940
|
-
*/
|
|
3941
|
-
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> & {
|
|
3942
|
-
readonly builder: StateInitializeBuilder<States, StateId>;
|
|
3943
|
-
};
|
|
3944
|
-
/**
|
|
3945
|
-
* Initial child value implementation for a compound or parallel state.
|
|
3946
|
-
*
|
|
3947
|
-
* @category models
|
|
3948
|
-
* @since 0.13.0
|
|
3949
|
-
*/
|
|
3950
|
-
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>, EmittedEventOf<Emits>>) => SnapshotBuilderComplete<StateInitializeValue<States, StateId>, boolean>;
|
|
3951
3765
|
/** Context used only when a history node has no previously captured record. */
|
|
3952
3766
|
interface HistoryDefaultContext<in out States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, in out ParentId extends StateIdentifier<States>> {
|
|
3953
3767
|
/** Lifecycle event that attempted to restore this history node. */
|
|
@@ -3993,13 +3807,12 @@ export declare namespace Machine {
|
|
|
3993
3807
|
readonly on?: never;
|
|
3994
3808
|
readonly onDone?: never;
|
|
3995
3809
|
readonly output?: never;
|
|
3996
|
-
readonly initialize?: never;
|
|
3997
3810
|
}
|
|
3998
3811
|
type HandlerChildren<Node> = Node extends {
|
|
3999
3812
|
readonly states: infer Children extends StateSchemas;
|
|
4000
3813
|
} ? Children : never;
|
|
4001
3814
|
type HandlerConfigPart<Config> = {
|
|
4002
|
-
readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key];
|
|
3815
|
+
readonly [Key in keyof Config as Key extends "states" | "initial" | "root" ? never : Key]: Config[Key];
|
|
4003
3816
|
};
|
|
4004
3817
|
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
|
|
4005
3818
|
readonly states?: infer Children;
|
|
@@ -4017,7 +3830,7 @@ export declare namespace Machine {
|
|
|
4017
3830
|
} : {
|
|
4018
3831
|
readonly [Key in Path]?: Validation;
|
|
4019
3832
|
};
|
|
4020
|
-
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "
|
|
3833
|
+
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initial" | "root" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
4021
3834
|
type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
|
|
4022
3835
|
readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
|
|
4023
3836
|
};
|
|
@@ -4088,10 +3901,10 @@ export declare namespace Machine {
|
|
|
4088
3901
|
] extends [never] ? unknown : {
|
|
4089
3902
|
readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
4090
3903
|
} : unknown : unknown);
|
|
4091
|
-
type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "
|
|
4092
|
-
readonly
|
|
3904
|
+
type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "initial" extends keyof Config ? unknown : {
|
|
3905
|
+
readonly initial: HandlerValidationError<"State requires an initial declaration for shallow history restoration", StateId>;
|
|
4093
3906
|
} : unknown;
|
|
4094
|
-
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;
|
|
3907
|
+
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> & ValidateConstructionDeclarations<Node, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : unknown;
|
|
4095
3908
|
type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
|
|
4096
3909
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
|
|
4097
3910
|
};
|
|
@@ -4105,7 +3918,7 @@ export declare namespace Machine {
|
|
|
4105
3918
|
readonly "": Config;
|
|
4106
3919
|
}, Required> extends infer NodeConfig ? [
|
|
4107
3920
|
NodeConfig
|
|
4108
|
-
] extends [never] ? RootInitializeError<Required> : "
|
|
3921
|
+
] extends [never] ? RootInitializeError<Required> : "initial" extends keyof NodeConfig ? never : RootInitializeError<Required> : never : unknown> : unknown;
|
|
4109
3922
|
type RootInitializeError<Path extends string> = Path extends "" ? {
|
|
4110
3923
|
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4111
3924
|
} : {
|
|
@@ -4113,14 +3926,21 @@ export declare namespace Machine {
|
|
|
4113
3926
|
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4114
3927
|
}>;
|
|
4115
3928
|
};
|
|
4116
|
-
type
|
|
4117
|
-
readonly
|
|
4118
|
-
}
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
readonly states:
|
|
4122
|
-
|
|
4123
|
-
|
|
3929
|
+
type HandlerTreeValidation<States extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, Config, OutputStates extends StateIdentifier<States>> = HandlerNodeValidation<States, Node, Events, InputEvents, Emits, Path, Config, OutputStates> & (Config extends {
|
|
3930
|
+
readonly states: infer Handlers;
|
|
3931
|
+
} ? Node extends {
|
|
3932
|
+
readonly states: infer Children extends StateSchemas;
|
|
3933
|
+
} ? {
|
|
3934
|
+
readonly states: {
|
|
3935
|
+
readonly [K in keyof Handlers]: K extends keyof Children ? HandlerTreeValidation<States, Children[K], Events, InputEvents, Emits, Extract<JoinPath<Path, Extract<K, string>>, StateNodeIdentifier<States>>, Handlers[K], OutputStates> : unknown;
|
|
3936
|
+
};
|
|
3937
|
+
} : unknown : unknown);
|
|
3938
|
+
type RootHandlerValidation<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, OutputStates extends StateIdentifier<States>> = HandlerTreeValidation<States, States[""], Events, InputEvents, Emits, Extract<"", StateNodeIdentifier<States>>, Config, OutputStates>;
|
|
3939
|
+
type HandlerHasRequiredInitial<Node, Config> = Node extends {
|
|
3940
|
+
readonly states: infer Children extends StateSchemas;
|
|
3941
|
+
} ? Node extends {
|
|
3942
|
+
readonly type: "parallel";
|
|
3943
|
+
} ? HasRequiredActiveChild<Children> extends true ? "initial" extends keyof Config ? true : false : true : "initial" extends keyof Config ? true : false : true;
|
|
4124
3944
|
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
4125
3945
|
readonly states: infer Children extends StateSchemas;
|
|
4126
3946
|
} ? [HistoryStateKey<Children>] extends [never] ? true : Config extends {
|
|
@@ -4135,15 +3955,21 @@ export declare namespace Machine {
|
|
|
4135
3955
|
} ? [
|
|
4136
3956
|
Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
|
|
4137
3957
|
] extends [never] ? true : false : false : true;
|
|
4138
|
-
type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> =
|
|
4139
|
-
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
|
|
4140
|
-
type HandlerNodeEvidence<AllStates extends StateSchemas,
|
|
4141
|
-
readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates,
|
|
3958
|
+
type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = HandlerHasRequiredInitial<Node, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
|
|
3959
|
+
type HandlerConfigError<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : 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> : never;
|
|
3960
|
+
type HandlerNodeEvidence<AllStates extends StateSchemas, Node, StateId extends StateNodeIdentifier<AllStates>, NodeConfig> = [NodeConfig] extends [never] ? never : {
|
|
3961
|
+
readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, Node, StateId, NodeConfig> : never;
|
|
4142
3962
|
readonly error: HandlerConfigError<HandlerConfigPart<NodeConfig>>;
|
|
4143
3963
|
readonly services: ConfigServices<HandlerConfigPart<NodeConfig>>;
|
|
4144
3964
|
readonly outputState: StateId extends StateIdentifier<AllStates> ? HandlerOutputStates<AllStates, StateId, HandlerConfigPart<NodeConfig>> : never;
|
|
4145
3965
|
};
|
|
4146
|
-
type HandlerTreeEvidence<AllStates extends StateSchemas, Config
|
|
3966
|
+
type HandlerTreeEvidence<AllStates extends StateSchemas, Config, Nodes extends StateSchemas = AllStates, Prefix extends string = ""> = {
|
|
3967
|
+
readonly [K in Extract<keyof Config & keyof Nodes, string>]: HandlerNodeEvidence<AllStates, Nodes[K], Extract<JoinPath<Prefix, K>, StateNodeIdentifier<AllStates>>, Config[K]> | (Nodes[K] extends {
|
|
3968
|
+
readonly states: infer Children extends StateSchemas;
|
|
3969
|
+
} ? Config[K] extends {
|
|
3970
|
+
readonly states: infer Handlers;
|
|
3971
|
+
} ? HandlerTreeEvidence<AllStates, Handlers, Children, JoinPath<Prefix, K>> : never : never);
|
|
3972
|
+
}[Extract<keyof Config & keyof Nodes, string>];
|
|
4147
3973
|
type HandleTreeResult<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<AllStates>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<AllStates>, Output, OutputStates extends StateIdentifier<AllStates>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Config> = Machine<AllStates, Events, Input, Exclude<UnhandledStates, HandlerTreeEvidence<AllStates, Config>["stateId"]>, E | HandlerTreeEvidence<AllStates, Config>["error"], ExcludeCompatibleRuntime<R | HandlerTreeEvidence<AllStates, Config>["services"], EventOf<Events>, EmittedEventOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>, InputEvents, ParentEvents>;
|
|
4148
3974
|
type ObjectCompoundPath<S extends StateSchemas> = {
|
|
4149
3975
|
readonly [P in StateIdentifier<S>]: NodeByIdentifier<S, P> extends {
|
|
@@ -4169,7 +3995,7 @@ export declare namespace Machine {
|
|
|
4169
3995
|
type ValidatePrograms<Sources> = {
|
|
4170
3996
|
readonly [K in keyof Sources]: Sources[K] extends LazyProgramValue ? unknown : Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never : unknown;
|
|
4171
3997
|
};
|
|
4172
|
-
type ReferenceRoot<S extends StateSchemas> =
|
|
3998
|
+
type ReferenceRoot<S extends StateSchemas> = Extract<S[""], StateNodeConfig>;
|
|
4173
3999
|
type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = TargetReference<ReferenceRoot<S>, P, P extends HistoryIdentifier<S> ? "history" : P extends ChoiceIdentifier<S> ? "choice" : "state">;
|
|
4174
4000
|
type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = {
|
|
4175
4001
|
readonly [P in Paths]: ReferenceAt<S, P>;
|
|
@@ -4183,7 +4009,7 @@ export declare namespace Machine {
|
|
|
4183
4009
|
/** Optional presentation label for this named branch. */
|
|
4184
4010
|
readonly title?: string;
|
|
4185
4011
|
} & ({
|
|
4186
|
-
/** Selects
|
|
4012
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4187
4013
|
readonly target: ReferenceUnion<S, DestinationPath<S>>;
|
|
4188
4014
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4189
4015
|
readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>;
|
|
@@ -4196,7 +4022,7 @@ export declare namespace Machine {
|
|
|
4196
4022
|
} | {
|
|
4197
4023
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4198
4024
|
readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>;
|
|
4199
|
-
/** Selects
|
|
4025
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4200
4026
|
readonly target?: never;
|
|
4201
4027
|
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4202
4028
|
readonly initial?: never;
|
|
@@ -4207,7 +4033,7 @@ export declare namespace Machine {
|
|
|
4207
4033
|
} | {
|
|
4208
4034
|
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4209
4035
|
readonly initial: ReferenceUnion<S, Exclude<ObjectCompoundPath<S>, "">>;
|
|
4210
|
-
/** Selects
|
|
4036
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4211
4037
|
readonly target?: never;
|
|
4212
4038
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4213
4039
|
readonly update?: never;
|
|
@@ -4218,7 +4044,7 @@ export declare namespace Machine {
|
|
|
4218
4044
|
} | {
|
|
4219
4045
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4220
4046
|
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
4221
|
-
/** Selects
|
|
4047
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4222
4048
|
readonly target?: never;
|
|
4223
4049
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4224
4050
|
readonly update?: never;
|
|
@@ -4229,7 +4055,7 @@ export declare namespace Machine {
|
|
|
4229
4055
|
} | {
|
|
4230
4056
|
/** Accepts the event without selecting a new destination. */
|
|
4231
4057
|
readonly none: true;
|
|
4232
|
-
/** Selects
|
|
4058
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4233
4059
|
readonly target?: never;
|
|
4234
4060
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4235
4061
|
readonly update?: never;
|
|
@@ -4259,7 +4085,7 @@ export declare namespace Machine {
|
|
|
4259
4085
|
type BranchBuilderAt<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = AtBuilder<RootBuilder<BranchTargetBuilder<S, Src>>, P>;
|
|
4260
4086
|
type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never;
|
|
4261
4087
|
type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D> = D extends {
|
|
4262
|
-
/** Selects
|
|
4088
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4263
4089
|
readonly target: infer Ref;
|
|
4264
4090
|
} ? RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ? D extends {
|
|
4265
4091
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
@@ -4323,7 +4149,7 @@ export declare namespace Machine {
|
|
|
4323
4149
|
} ? [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? ObjectConstruction<C, BranchBuilderAt<S, Src, P>> | ObjectDefault<BranchBuilderAt<S, Src, P>> : never : InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
|
|
4324
4150
|
type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
|
|
4325
4151
|
readonly [P in DestinationPath<S>]: {
|
|
4326
|
-
/** Selects
|
|
4152
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4327
4153
|
readonly target: ReferenceAt<S, P>;
|
|
4328
4154
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4329
4155
|
readonly update?: never;
|
|
@@ -4346,7 +4172,7 @@ export declare namespace Machine {
|
|
|
4346
4172
|
} ? {
|
|
4347
4173
|
readonly [M in Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">]: BuilderArgs<BranchBuilderAt<S, Src, P>, M> extends readonly [unknown?] ? {
|
|
4348
4174
|
readonly [K in M]: (context: C) => {
|
|
4349
|
-
/** Selects
|
|
4175
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4350
4176
|
readonly target: BuilderArgs<BranchBuilderAt<S, Src, P>, M>[0];
|
|
4351
4177
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4352
4178
|
readonly update: BuilderArgs<StateUpdateBuilder<S, Owner>, M>[0];
|
|
@@ -4372,7 +4198,7 @@ export declare namespace Machine {
|
|
|
4372
4198
|
] extends [never] ? never : {
|
|
4373
4199
|
readonly [P in DestinationPath<S>]: {
|
|
4374
4200
|
readonly [Owner in Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>]: {
|
|
4375
|
-
/** Selects
|
|
4201
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4376
4202
|
readonly target: ReferenceAt<S, P>;
|
|
4377
4203
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4378
4204
|
readonly update: ReferenceAt<S, Owner>;
|
|
@@ -4397,7 +4223,7 @@ export declare namespace Machine {
|
|
|
4397
4223
|
readonly reenter?: P extends Src ? never : boolean;
|
|
4398
4224
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4399
4225
|
readonly update: ReferenceAt<S, P>;
|
|
4400
|
-
/** Selects
|
|
4226
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4401
4227
|
readonly target?: never;
|
|
4402
4228
|
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4403
4229
|
readonly initial?: never;
|
|
@@ -4419,7 +4245,7 @@ export declare namespace Machine {
|
|
|
4419
4245
|
readonly [P in Exclude<ObjectCompoundPath<S>, "">]: InitialTargetFactory<NodeByIdentifier<S, P>, P> extends infer B ? {
|
|
4420
4246
|
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4421
4247
|
readonly initial: ReferenceAt<S, P>;
|
|
4422
|
-
/** Selects
|
|
4248
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4423
4249
|
readonly target?: never;
|
|
4424
4250
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4425
4251
|
readonly update?: never;
|
|
@@ -4437,7 +4263,7 @@ export declare namespace Machine {
|
|
|
4437
4263
|
}[Exclude<ObjectCompoundPath<S>, "">];
|
|
4438
4264
|
type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
|
|
4439
4265
|
readonly [K in Extract<keyof Group, string>]: {
|
|
4440
|
-
/** Selects
|
|
4266
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4441
4267
|
readonly target: SelectionOf<S, Src, Group[K]>;
|
|
4442
4268
|
};
|
|
4443
4269
|
};
|
|
@@ -4457,7 +4283,7 @@ export declare namespace Machine {
|
|
|
4457
4283
|
readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K]>] extends [never] ? unknown : never) & {
|
|
4458
4284
|
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4459
4285
|
readonly branches: K;
|
|
4460
|
-
/** Selects
|
|
4286
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4461
4287
|
readonly target?: never;
|
|
4462
4288
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4463
4289
|
readonly update?: never;
|
|
@@ -4478,16 +4304,31 @@ export declare namespace Machine {
|
|
|
4478
4304
|
readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K]>, true>;
|
|
4479
4305
|
};
|
|
4480
4306
|
}[Extract<keyof Registered<R, "branches">, string>];
|
|
4307
|
+
type DataValue<C, A> = A | ((context: C) => A);
|
|
4308
|
+
type DeclarationData<T> = T extends {
|
|
4309
|
+
readonly from: (context: infer C) => infer A;
|
|
4310
|
+
} ? Omit<T, "from" | "decoded"> & {
|
|
4311
|
+
readonly data: DataValue<C, A>;
|
|
4312
|
+
readonly decoded?: false;
|
|
4313
|
+
} : T extends {
|
|
4314
|
+
readonly decoded: (context: infer C) => infer A;
|
|
4315
|
+
} ? Omit<T, "from" | "decoded"> & {
|
|
4316
|
+
readonly data: DataValue<C, A>;
|
|
4317
|
+
readonly decoded: true;
|
|
4318
|
+
} : T extends unknown ? Omit<T, "from" | "decoded"> & {
|
|
4319
|
+
readonly data?: never;
|
|
4320
|
+
readonly decoded?: never;
|
|
4321
|
+
} : never;
|
|
4481
4322
|
/**
|
|
4482
4323
|
* A transition with an inspectable destination and source-specific construction.
|
|
4483
4324
|
*
|
|
4484
4325
|
* @category models
|
|
4485
4326
|
* @since 0.34.0
|
|
4486
4327
|
*/
|
|
4487
|
-
type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> & (InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineInitial<S, Src, C> | {
|
|
4328
|
+
type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> & DeclarationData<(InlineDestination<S, Src, C> | InlineUpdate<S, Src, C> | InlineCombined<S, Src, C> | InlineInitial<S, Src, C> | {
|
|
4488
4329
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4489
4330
|
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
4490
|
-
/** Selects
|
|
4331
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4491
4332
|
readonly target?: never;
|
|
4492
4333
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4493
4334
|
readonly update?: never;
|
|
@@ -4508,7 +4349,7 @@ export declare namespace Machine {
|
|
|
4508
4349
|
} | (Src extends ChoiceIdentifier<S> ? never : {
|
|
4509
4350
|
/** Accepts the event without selecting a new destination. */
|
|
4510
4351
|
readonly none: true;
|
|
4511
|
-
/** Selects
|
|
4352
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4512
4353
|
readonly target?: never;
|
|
4513
4354
|
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4514
4355
|
readonly update?: never;
|
|
@@ -4526,7 +4367,7 @@ export declare namespace Machine {
|
|
|
4526
4367
|
readonly declinable?: "declinable" extends Acceptance ? boolean : false;
|
|
4527
4368
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4528
4369
|
readonly resolve?: (context: C & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => undefined | Declined;
|
|
4529
|
-
}) | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>)
|
|
4370
|
+
}) | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>)>;
|
|
4530
4371
|
type SourceValue<R, K extends PropertyKey> = {
|
|
4531
4372
|
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Registered<R, Kind>[K] : never;
|
|
4532
4373
|
}["effects" | "streams" | "timers" | "logic" | "children"];
|
|
@@ -4609,6 +4450,101 @@ export declare namespace Machine {
|
|
|
4609
4450
|
readonly address?: never;
|
|
4610
4451
|
}) & (SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? M extends EnsureExecutable<States<M>, UnhandledStates<M>, OutputStates<M>> ? unknown : never : never : unknown) & RegisteredInvocationInput<R, K, InvokeContext<S, Ev, Em, Src, In, Pa>> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, InvokeOutput<ResolvedInvoke<R, K>>, "onDone"> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, RegisteredInvokeError<R, K>, "onFailure"> & ObjectOutcome<S, Ev, Em, Src, In, Pa, R, SourceKind<R, K> extends "streams" ? Stream.Success<Extract<InvokeResolvedSource<SourceValue<R, K>>, Stream.Stream<any, any, any>>> : never, "onElement"> & (SourceKind<R, K> extends "logic" | "children" ? Partial<ObjectOutcome<S, Ev, Em, Src, In, Pa, R, LogicStateOf<InvokeLogic<ResolvedInvoke<R, K>>>, "onSnapshot">> : {})>;
|
|
4611
4452
|
}[Extract<SourceKeys<R>, string>];
|
|
4453
|
+
type OrdinaryData<A> = A extends unknown ? A & ({
|
|
4454
|
+
readonly decoded?: false | undefined;
|
|
4455
|
+
} | {
|
|
4456
|
+
readonly data?: never;
|
|
4457
|
+
}) : never;
|
|
4458
|
+
type ShortConstruction<C, Node> = [NodeSchema<Node>] extends [never] ? never : OrdinaryData<NodeMakeInput<Node>> | ((context: C) => NodeMakeInput<Node>) | {
|
|
4459
|
+
readonly decoded: true;
|
|
4460
|
+
readonly data: DataValue<C, NodeValue<Node>>;
|
|
4461
|
+
};
|
|
4462
|
+
type InitialData<C, Node> = [NodeSchema<Node>] extends [never] ? {
|
|
4463
|
+
readonly data?: never;
|
|
4464
|
+
readonly decoded?: never;
|
|
4465
|
+
} : ({
|
|
4466
|
+
readonly decoded?: false;
|
|
4467
|
+
} & ({} extends NodeMakeInput<Node> ? {
|
|
4468
|
+
readonly data?: DataValue<C, NodeMakeInput<Node>>;
|
|
4469
|
+
} : {
|
|
4470
|
+
readonly data: DataValue<C, NodeMakeInput<Node>>;
|
|
4471
|
+
})) | {
|
|
4472
|
+
readonly decoded: true;
|
|
4473
|
+
readonly data: DataValue<C, NodeValue<Node>>;
|
|
4474
|
+
};
|
|
4475
|
+
type InitialEdge<S extends StateSchemas, Node, Src extends StateNodeIdentifier<S>, C> = Node extends {
|
|
4476
|
+
readonly states: infer Children extends StateSchemas;
|
|
4477
|
+
} ? {
|
|
4478
|
+
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: {
|
|
4479
|
+
readonly target: TargetReference<ReferenceRoot<S>, JoinPath<Src, K>, Children[K] extends ChoiceStateNodeConfig ? "choice" : "state">;
|
|
4480
|
+
} & InitialData<C, Children[K]>;
|
|
4481
|
+
}[ActiveStateKey<Children> | ChoiceStateKey<Children>] : never;
|
|
4482
|
+
type InitialRegions<C, Children extends StateSchemas> = {
|
|
4483
|
+
readonly [K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? K : never]?: never;
|
|
4484
|
+
} & {
|
|
4485
|
+
readonly [K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? never : {} extends NodeMakeInput<Children[K]> ? never : K]: ShortConstruction<C, Children[K]>;
|
|
4486
|
+
} & {
|
|
4487
|
+
readonly [K in ActiveStateKey<Children> as [NodeSchema<Children[K]>] extends [never] ? never : {} extends NodeMakeInput<Children[K]> ? K : never]?: ShortConstruction<C, Children[K]>;
|
|
4488
|
+
};
|
|
4489
|
+
type RequiresInitialHandler<Node> = Node extends {
|
|
4490
|
+
readonly states: StateSchemas;
|
|
4491
|
+
} ? true : false;
|
|
4492
|
+
type ChildHandlerMap<S extends StateSchemas, Children extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = {
|
|
4493
|
+
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children> as RequiresInitialHandler<Children[K]> extends true ? K : never]: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>;
|
|
4494
|
+
} & {
|
|
4495
|
+
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children> as RequiresInitialHandler<Children[K]> extends true ? never : K]?: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>;
|
|
4496
|
+
};
|
|
4497
|
+
type ChildHandlers<S extends StateSchemas, Children extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = [
|
|
4498
|
+
{
|
|
4499
|
+
[K in ActiveStateKey<Children> | ChoiceStateKey<Children>]: RequiresInitialHandler<Children[K]> extends true ? K : never;
|
|
4500
|
+
}[ActiveStateKey<Children> | ChoiceStateKey<Children>]
|
|
4501
|
+
] extends [never] ? {
|
|
4502
|
+
readonly states?: ChildHandlerMap<S, Children, Ev, Em, Src, In, Pa, R>;
|
|
4503
|
+
} : {
|
|
4504
|
+
readonly states: ChildHandlerMap<S, Children, Ev, Em, Src, In, Pa, R>;
|
|
4505
|
+
};
|
|
4506
|
+
type InitialHandler<S extends StateSchemas, Node, Src extends StateNodeIdentifier<S>, C> = Node extends {
|
|
4507
|
+
readonly type: "parallel";
|
|
4508
|
+
readonly states: infer Children extends StateSchemas;
|
|
4509
|
+
} ? {} extends InitialRegions<C, Children> ? {
|
|
4510
|
+
readonly initial?: InitialRegions<C, Children>;
|
|
4511
|
+
} : {
|
|
4512
|
+
readonly initial: InitialRegions<C, Children>;
|
|
4513
|
+
} : Node extends {
|
|
4514
|
+
readonly states: StateSchemas;
|
|
4515
|
+
} ? {
|
|
4516
|
+
readonly initial: InitialEdge<S, Node, Src, C>;
|
|
4517
|
+
} : {
|
|
4518
|
+
readonly initial?: never;
|
|
4519
|
+
};
|
|
4520
|
+
type RootConstruction<Node, Input> = [NodeSchema<Node>] extends [never] ? {
|
|
4521
|
+
readonly root?: never;
|
|
4522
|
+
} : {} extends NodeMakeInput<Node> ? {
|
|
4523
|
+
/** Constructs root-owned data once from startup input. */ readonly root?: ShortConstruction<{
|
|
4524
|
+
readonly input: Input;
|
|
4525
|
+
}, Node>;
|
|
4526
|
+
} : {
|
|
4527
|
+
/** Constructs root-owned data once from startup input. */ readonly root: ShortConstruction<{
|
|
4528
|
+
readonly input: Input;
|
|
4529
|
+
}, Node>;
|
|
4530
|
+
};
|
|
4531
|
+
type ExactConstruction<C> = C extends {
|
|
4532
|
+
readonly decoded: true;
|
|
4533
|
+
readonly data: unknown;
|
|
4534
|
+
} ? {
|
|
4535
|
+
readonly [K in Exclude<keyof C, "decoded" | "data">]: never;
|
|
4536
|
+
} : unknown;
|
|
4537
|
+
type ValidateInitialDeclaration<Node, C> = Node extends {
|
|
4538
|
+
readonly type: "parallel";
|
|
4539
|
+
readonly states: infer Children extends StateSchemas;
|
|
4540
|
+
} ? {
|
|
4541
|
+
readonly [K in keyof C]: K extends ActiveStateKey<Children> ? ExactConstruction<C[K]> : never;
|
|
4542
|
+
} : {
|
|
4543
|
+
readonly [K in Exclude<keyof C, "target" | "data" | "decoded">]: never;
|
|
4544
|
+
};
|
|
4545
|
+
type ValidateConstructionDeclarations<Node, C> = {
|
|
4546
|
+
readonly [K in Extract<keyof C, "root" | "initial">]: K extends "root" ? ExactConstruction<C[K]> : K extends "initial" ? ValidateInitialDeclaration<Node, C[K]> : unknown;
|
|
4547
|
+
};
|
|
4612
4548
|
type ObjectLifecycle<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>> = Src extends StateIdentifier<S> ? {
|
|
4613
4549
|
/** Runs synchronously on entry and may enqueue commands. */
|
|
4614
4550
|
readonly entry?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
|
|
@@ -4616,18 +4552,14 @@ export declare namespace Machine {
|
|
|
4616
4552
|
readonly type: "final";
|
|
4617
4553
|
} ? {
|
|
4618
4554
|
/** Runs synchronously on exit and may enqueue commands. */
|
|
4619
|
-
readonly exit?: never;
|
|
4620
|
-
readonly initialize?: never;
|
|
4555
|
+
readonly exit?: never;
|
|
4621
4556
|
} & OutputHandlerConfig<S, Ev, Src, FinalOutputContext<S, Ev, Src>> : {
|
|
4622
4557
|
/** Runs synchronously on exit and may enqueue commands. */
|
|
4623
4558
|
readonly exit?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
|
|
4624
|
-
/** Constructs required values for the declared initial child or parallel regions. */
|
|
4625
|
-
readonly initialize?: StateInitializeHandler<S, Ev, Em, Src, In, Pa>;
|
|
4626
4559
|
} & ActiveOutputHandlerConfig<S, Ev, Src>) : {
|
|
4627
4560
|
/** Runs synchronously on entry and may enqueue commands. */
|
|
4628
4561
|
readonly entry?: never; /** Runs synchronously on exit and may enqueue commands. */
|
|
4629
|
-
readonly exit?: never; /** Constructs
|
|
4630
|
-
readonly initialize?: never; /** Constructs the decoded output declared by the state schema. */
|
|
4562
|
+
readonly exit?: never; /** Constructs the decoded output declared by the state schema. */
|
|
4631
4563
|
readonly output?: never;
|
|
4632
4564
|
};
|
|
4633
4565
|
/**
|
|
@@ -4636,7 +4568,10 @@ export declare namespace Machine {
|
|
|
4636
4568
|
* @category models
|
|
4637
4569
|
* @since 0.34.0
|
|
4638
4570
|
*/
|
|
4639
|
-
type StateHandler<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa> &
|
|
4571
|
+
type StateHandler<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa> & InitialHandler<S, Node, Src, StateActionContext<S, Ev, Em, Extract<Src, StateIdentifier<S>>, In, Pa> & {
|
|
4572
|
+
/** Root-owned data constructed before initial descendant values. */
|
|
4573
|
+
readonly root: StateByIdentifier<S, Extract<"", StateIdentifier<S>>>;
|
|
4574
|
+
}> & (Src extends ChoiceIdentifier<S> ? {
|
|
4640
4575
|
/** Required total transition for a transient choice state. */
|
|
4641
4576
|
readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>;
|
|
4642
4577
|
/** Event handlers keyed by the public or internal event tag. */
|
|
@@ -4689,18 +4624,15 @@ export declare namespace Machine {
|
|
|
4689
4624
|
readonly states: infer Children extends StateSchemas;
|
|
4690
4625
|
} ? {
|
|
4691
4626
|
/** Child handlers nested according to the declared root topology. */
|
|
4692
|
-
readonly states?: {
|
|
4693
|
-
readonly [K in ActiveStateKey<Children> | ChoiceStateKey<Children>]?: StateHandler<S, Children[K], Ev, Em, Extract<JoinPath<Src, K>, StateNodeIdentifier<S>>, In, Pa, R>;
|
|
4694
|
-
};
|
|
4695
4627
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4696
4628
|
readonly history?: HistoryDefaultConfig<S, Ev, Em, Src, Children>;
|
|
4697
|
-
} : {
|
|
4629
|
+
} & ChildHandlers<S, Children, Ev, Em, Src, In, Pa, R> : {
|
|
4698
4630
|
/** Child handlers nested according to the declared root topology. */
|
|
4699
4631
|
readonly states?: never; /** Restores the declared history reference, using its fallback on first entry. */
|
|
4700
4632
|
readonly history?: never;
|
|
4701
4633
|
}) : never);
|
|
4702
4634
|
type ValidateObjectTransition<T> = {
|
|
4703
|
-
readonly [K in Exclude<keyof T, "target" | "update" | "initial" | "history" | "none" | "branches" | "
|
|
4635
|
+
readonly [K in Exclude<keyof T, "target" | "update" | "initial" | "history" | "none" | "branches" | "data" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
|
|
4704
4636
|
} & (T extends {
|
|
4705
4637
|
/** Set to true when the resolver can explicitly return decline(). */
|
|
4706
4638
|
readonly declinable: infer D;
|
|
@@ -4761,7 +4693,7 @@ export declare namespace Machine {
|
|
|
4761
4693
|
* @since 0.34.0
|
|
4762
4694
|
*/
|
|
4763
4695
|
interface Handler<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, I extends Schema.Top, IE, IR, Final extends StateIdentifier<S>, Out, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> {
|
|
4764
|
-
<const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) &
|
|
4696
|
+
<const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R> & RootConstruction<S[""], I["Type"]>> & RootConstruction<S[""], I["Type"]> & ValidateObjectConfig<NoInfer<C>, R> & RootHandlerValidation<S, Ev, In, Em, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
|
|
4765
4697
|
readonly "": NormalizeObjectConfig<NoInfer<C>, R>;
|
|
4766
4698
|
}>["outputState"], StateIdentifier<S>>>): HandleTreeResult<S, Ev, Em, I, StateIdentifier<S>, never, never, IE, IR, Final, Out, never, In, Pa, {
|
|
4767
4699
|
readonly "": NormalizeObjectConfig<C, R>;
|
|
@@ -4884,24 +4816,23 @@ export declare const isMachine: (u: unknown) => u is Machine.Any;
|
|
|
4884
4816
|
*/
|
|
4885
4817
|
export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, 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>, state: Machine.Snapshot<States>) => state is Machine.SnapshotContainingFinal<States, FinalStates>;
|
|
4886
4818
|
/**
|
|
4887
|
-
* Defines
|
|
4819
|
+
* Defines root or nested state schemas while preserving the exact child topology.
|
|
4888
4820
|
*
|
|
4889
|
-
*
|
|
4890
|
-
*
|
|
4891
|
-
*
|
|
4821
|
+
* Pass the root descriptor to {@link make} and {@link targets}. Nested states
|
|
4822
|
+
* can be declared inline or reused by mounting a descriptor in multiple places.
|
|
4823
|
+
* Initial edges and value constructors belong in the handler tree.
|
|
4892
4824
|
*
|
|
4893
4825
|
* **Example** (Repeated compound state)
|
|
4894
4826
|
*
|
|
4895
4827
|
* ```ts
|
|
4896
|
-
* import { Schema } from "effect"
|
|
4897
4828
|
* import { Machine } from "@typeonce/effect-machine"
|
|
4829
|
+
* import { Schema } from "effect"
|
|
4898
4830
|
*
|
|
4899
4831
|
* const TradingState = Schema.TaggedUnion({
|
|
4900
4832
|
* InSession: {},
|
|
4901
4833
|
* Applying: {}
|
|
4902
4834
|
* })
|
|
4903
4835
|
* const TradingSlot = Machine.state({
|
|
4904
|
-
* initial: "Idle",
|
|
4905
4836
|
* states: {
|
|
4906
4837
|
* Idle: {},
|
|
4907
4838
|
* InSession: TradingState.cases.InSession,
|
|
@@ -4909,10 +4840,12 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
4909
4840
|
* }
|
|
4910
4841
|
* })
|
|
4911
4842
|
*
|
|
4912
|
-
* const States = Machine.state({
|
|
4913
|
-
*
|
|
4914
|
-
*
|
|
4915
|
-
*
|
|
4843
|
+
* const States = Machine.state({
|
|
4844
|
+
* states: {
|
|
4845
|
+
* slot1: TradingSlot,
|
|
4846
|
+
* slot2: TradingSlot
|
|
4847
|
+
* }
|
|
4848
|
+
* })
|
|
4916
4849
|
* ```
|
|
4917
4850
|
*
|
|
4918
4851
|
* @category constructors
|
|
@@ -5022,33 +4955,10 @@ type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends Readon
|
|
|
5022
4955
|
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
5023
4956
|
readonly branches: Branches;
|
|
5024
4957
|
}>;
|
|
5025
|
-
type RootInitialization<Root extends Machine.StateNodeConfig, Input> = {
|
|
5026
|
-
readonly initialConfiguration?: never;
|
|
5027
|
-
} & (Machine.NodeSchema<Root> extends never ? {
|
|
5028
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
5029
|
-
readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
|
|
5030
|
-
} : {} extends NodeMakeInput<Root> ? {
|
|
5031
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
5032
|
-
readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
|
|
5033
|
-
} : {
|
|
5034
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
5035
|
-
readonly initial: Machine.RootInitialBuilderInput<Root, Input>;
|
|
5036
|
-
});
|
|
5037
4958
|
/** @inline */
|
|
5038
4959
|
interface Make {
|
|
5039
|
-
/** @param config Complete starting configuration, including root and descendant values. */
|
|
5040
|
-
<const Root extends Machine.StateNodeConfig, 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 ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>> & {
|
|
5041
|
-
/** Mutually exclusive with a complete initial configuration. */
|
|
5042
|
-
readonly initial?: never;
|
|
5043
|
-
/** Constructs the complete initial root configuration, overriding child defaults. */
|
|
5044
|
-
readonly initialConfiguration: Machine.RootConfigurationBuilderInput<NoInfer<Root>, Input["Type"]>;
|
|
5045
|
-
}): MakeResult<Root & {
|
|
5046
|
-
readonly "~effect/Machine/ExplicitInitial": true;
|
|
5047
|
-
}, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
|
|
5048
4960
|
/** @param config Complete schema-first machine definition. */
|
|
5049
|
-
<const Root extends Machine.StateNodeConfig, 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 ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>
|
|
5050
|
-
readonly initialConfiguration: unknown;
|
|
5051
|
-
}>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
|
|
4961
|
+
<const Root extends Machine.StateNodeConfig, 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 ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}, const Branches extends Machine.BranchDefinitions<NoInfer<Root>> = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children, Branches>;
|
|
5052
4962
|
}
|
|
5053
4963
|
/**
|
|
5054
4964
|
* Creates a schema-first machine definition.
|
|
@@ -5078,35 +4988,40 @@ interface Make {
|
|
|
5078
4988
|
* **Example** (Typed counter machine)
|
|
5079
4989
|
*
|
|
5080
4990
|
* ```ts
|
|
5081
|
-
* import { Schema } from "effect"
|
|
5082
4991
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5083
|
-
*
|
|
4992
|
+
* import { Schema } from "effect"
|
|
5084
4993
|
* class Count extends Schema.TaggedClass<Count>("Count")("Count", {
|
|
5085
4994
|
* value: Schema.Number
|
|
5086
|
-
* }) {
|
|
5087
|
-
*
|
|
4995
|
+
* }) {
|
|
4996
|
+
* }
|
|
5088
4997
|
* class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
|
|
5089
4998
|
* by: Schema.Number
|
|
5090
|
-
* }) {
|
|
5091
|
-
*
|
|
5092
|
-
* const States = Machine.state({
|
|
4999
|
+
* }) {
|
|
5000
|
+
* }
|
|
5001
|
+
* const States = Machine.state({ states: { Count } })
|
|
5093
5002
|
* const Events = Machine.eventsFromSchemas(Increment)
|
|
5094
5003
|
* const targets = Machine.targets(States)
|
|
5095
|
-
*
|
|
5096
5004
|
* const counter = Machine.make({
|
|
5097
5005
|
* root: States,
|
|
5098
|
-
* events: Events
|
|
5099
|
-
*
|
|
5100
|
-
*
|
|
5101
|
-
*
|
|
5102
|
-
*
|
|
5103
|
-
*
|
|
5104
|
-
*
|
|
5105
|
-
*
|
|
5006
|
+
* events: Events
|
|
5007
|
+
* }).handle({
|
|
5008
|
+
* initial: {
|
|
5009
|
+
* target: Machine.targets(States).root.Count,
|
|
5010
|
+
* decoded: true,
|
|
5011
|
+
* data: new Count({ value: 0 })
|
|
5012
|
+
* },
|
|
5013
|
+
* states: {
|
|
5014
|
+
* Count: {
|
|
5015
|
+
* on: {
|
|
5016
|
+
* Increment: {
|
|
5017
|
+
* update: targets.root.Count,
|
|
5018
|
+
* decoded: true,
|
|
5019
|
+
* data: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
5020
|
+
* }
|
|
5106
5021
|
* }
|
|
5107
5022
|
* }
|
|
5108
5023
|
* }
|
|
5109
|
-
* }
|
|
5024
|
+
* })
|
|
5110
5025
|
* ```
|
|
5111
5026
|
*
|
|
5112
5027
|
* @see {@link state} for typed state-tree helpers.
|
|
@@ -5287,17 +5202,22 @@ export declare const emittedEventsFromSchemas: {
|
|
|
5287
5202
|
* **Example**
|
|
5288
5203
|
*
|
|
5289
5204
|
* ```ts
|
|
5290
|
-
* import { Effect, Schema } from "effect"
|
|
5291
5205
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5292
|
-
*
|
|
5293
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5294
|
-
*
|
|
5206
|
+
* import { Effect, Schema } from "effect"
|
|
5207
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5208
|
+
* }
|
|
5209
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5295
5210
|
* const machine = Machine.make({
|
|
5296
5211
|
* root: States,
|
|
5297
|
-
* events: Machine.eventsFromSchemas()
|
|
5298
|
-
*
|
|
5299
|
-
*
|
|
5300
|
-
*
|
|
5212
|
+
* events: Machine.eventsFromSchemas()
|
|
5213
|
+
* }).handle({
|
|
5214
|
+
* initial: {
|
|
5215
|
+
* target: Machine.targets(States).root.Idle
|
|
5216
|
+
* },
|
|
5217
|
+
* states: {
|
|
5218
|
+
* Idle: {}
|
|
5219
|
+
* }
|
|
5220
|
+
* })
|
|
5301
5221
|
* const encoded = Effect.gen(function*() {
|
|
5302
5222
|
* const initial = yield* Machine.planInitial(machine)
|
|
5303
5223
|
* return yield* Machine.encodeSnapshot(machine, initial.state)
|
|
@@ -5331,17 +5251,22 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
5331
5251
|
* **Example**
|
|
5332
5252
|
*
|
|
5333
5253
|
* ```ts
|
|
5334
|
-
* import { Effect, Schema } from "effect"
|
|
5335
5254
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5336
|
-
*
|
|
5337
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5338
|
-
*
|
|
5255
|
+
* import { Effect, Schema } from "effect"
|
|
5256
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5257
|
+
* }
|
|
5258
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5339
5259
|
* const machine = Machine.make({
|
|
5340
5260
|
* root: States,
|
|
5341
|
-
* events: Machine.eventsFromSchemas()
|
|
5342
|
-
*
|
|
5343
|
-
*
|
|
5344
|
-
*
|
|
5261
|
+
* events: Machine.eventsFromSchemas()
|
|
5262
|
+
* }).handle({
|
|
5263
|
+
* initial: {
|
|
5264
|
+
* target: Machine.targets(States).root.Idle
|
|
5265
|
+
* },
|
|
5266
|
+
* states: {
|
|
5267
|
+
* Idle: {}
|
|
5268
|
+
* }
|
|
5269
|
+
* })
|
|
5345
5270
|
* const roundTrip = Effect.gen(function*() {
|
|
5346
5271
|
* const initial = yield* Machine.planInitial(machine)
|
|
5347
5272
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
@@ -5389,17 +5314,22 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
5389
5314
|
* **Example**
|
|
5390
5315
|
*
|
|
5391
5316
|
* ```ts
|
|
5392
|
-
* import { Effect, Schema } from "effect"
|
|
5393
5317
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5394
|
-
*
|
|
5395
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5396
|
-
*
|
|
5318
|
+
* import { Effect, Schema } from "effect"
|
|
5319
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5320
|
+
* }
|
|
5321
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5397
5322
|
* const machine = Machine.make({
|
|
5398
5323
|
* root: States,
|
|
5399
|
-
* events: Machine.eventsFromSchemas()
|
|
5400
|
-
*
|
|
5401
|
-
*
|
|
5402
|
-
*
|
|
5324
|
+
* events: Machine.eventsFromSchemas()
|
|
5325
|
+
* }).handle({
|
|
5326
|
+
* initial: {
|
|
5327
|
+
* target: Machine.targets(States).root.Idle
|
|
5328
|
+
* },
|
|
5329
|
+
* states: {
|
|
5330
|
+
* Idle: {}
|
|
5331
|
+
* }
|
|
5332
|
+
* })
|
|
5403
5333
|
* const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
|
|
5404
5334
|
* ```
|
|
5405
5335
|
*
|
|
@@ -5561,12 +5491,15 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5561
5491
|
* import { Effect, Schema } from "effect"
|
|
5562
5492
|
*
|
|
5563
5493
|
* const internalEvents = Machine.internalEventsFromSchemas(Schema.TaggedStruct("Loaded", {}))
|
|
5494
|
+
* const Root = Machine.state({ states: { Idle: {} } })
|
|
5564
5495
|
* const machine = Machine.make({
|
|
5565
|
-
* root:
|
|
5496
|
+
* root: Root,
|
|
5566
5497
|
* events: Machine.eventsFromSchemas(),
|
|
5567
|
-
* internalEvents
|
|
5568
|
-
*
|
|
5569
|
-
*
|
|
5498
|
+
* internalEvents
|
|
5499
|
+
* }).handle({
|
|
5500
|
+
* initial: { target: Machine.targets(Root).root.Idle },
|
|
5501
|
+
* states: { Idle: { on: { Loaded: { none: true } } } }
|
|
5502
|
+
* })
|
|
5570
5503
|
*
|
|
5571
5504
|
* export const canLoad = Effect.gen(function*() {
|
|
5572
5505
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -5601,27 +5534,32 @@ export declare const can: {
|
|
|
5601
5534
|
* **Example**
|
|
5602
5535
|
*
|
|
5603
5536
|
* ```ts
|
|
5604
|
-
* import { Effect, Schema } from "effect"
|
|
5605
5537
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5606
|
-
*
|
|
5607
|
-
* class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {
|
|
5608
|
-
*
|
|
5609
|
-
* class
|
|
5610
|
-
*
|
|
5538
|
+
* import { Effect, Schema } from "effect"
|
|
5539
|
+
* class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {
|
|
5540
|
+
* }
|
|
5541
|
+
* class On extends Schema.TaggedClass<On>("On")("On", {}) {
|
|
5542
|
+
* }
|
|
5543
|
+
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {
|
|
5544
|
+
* }
|
|
5545
|
+
* const States = Machine.state({ states: { Off, On } })
|
|
5611
5546
|
* const targets = Machine.targets(States)
|
|
5612
5547
|
* const machine = Machine.make({
|
|
5613
5548
|
* root: States,
|
|
5614
|
-
* events: Machine.eventsFromSchemas(Toggle)
|
|
5615
|
-
*
|
|
5616
|
-
*
|
|
5617
|
-
*
|
|
5618
|
-
* on: {
|
|
5619
|
-
* Toggle: { target: targets.root.On }
|
|
5620
|
-
* }
|
|
5549
|
+
* events: Machine.eventsFromSchemas(Toggle)
|
|
5550
|
+
* }).handle({
|
|
5551
|
+
* initial: {
|
|
5552
|
+
* target: Machine.targets(States).root.Off
|
|
5621
5553
|
* },
|
|
5622
|
-
*
|
|
5623
|
-
*
|
|
5624
|
-
*
|
|
5554
|
+
* states: {
|
|
5555
|
+
* Off: {
|
|
5556
|
+
* on: {
|
|
5557
|
+
* Toggle: { target: targets.root.On }
|
|
5558
|
+
* }
|
|
5559
|
+
* },
|
|
5560
|
+
* On: {}
|
|
5561
|
+
* }
|
|
5562
|
+
* })
|
|
5625
5563
|
* const nextState = Effect.gen(function*() {
|
|
5626
5564
|
* const initial = yield* Machine.planInitial(machine)
|
|
5627
5565
|
* return (yield* Machine.plan(machine, initial.state, new Toggle({}))).next
|
|
@@ -5820,17 +5758,22 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
|
|
|
5820
5758
|
* **Example**
|
|
5821
5759
|
*
|
|
5822
5760
|
* ```ts
|
|
5823
|
-
* import { Effect, Schema } from "effect"
|
|
5824
5761
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5825
|
-
*
|
|
5826
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5827
|
-
*
|
|
5762
|
+
* import { Effect, Schema } from "effect"
|
|
5763
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5764
|
+
* }
|
|
5765
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5828
5766
|
* const machine = Machine.make({
|
|
5829
5767
|
* root: States,
|
|
5830
|
-
* events: Machine.eventsFromSchemas()
|
|
5831
|
-
*
|
|
5832
|
-
*
|
|
5833
|
-
*
|
|
5768
|
+
* events: Machine.eventsFromSchemas()
|
|
5769
|
+
* }).handle({
|
|
5770
|
+
* initial: {
|
|
5771
|
+
* target: Machine.targets(States).root.Idle
|
|
5772
|
+
* },
|
|
5773
|
+
* states: {
|
|
5774
|
+
* Idle: {}
|
|
5775
|
+
* }
|
|
5776
|
+
* })
|
|
5834
5777
|
* const state = Effect.gen(function*() {
|
|
5835
5778
|
* const ref = yield* Machine.start(machine)
|
|
5836
5779
|
* return yield* ref.state
|
|
@@ -5870,17 +5813,22 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
5870
5813
|
* **Example**
|
|
5871
5814
|
*
|
|
5872
5815
|
* ```ts
|
|
5873
|
-
* import { Effect, Schema } from "effect"
|
|
5874
5816
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5875
|
-
*
|
|
5876
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5877
|
-
*
|
|
5817
|
+
* import { Effect, Schema } from "effect"
|
|
5818
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5819
|
+
* }
|
|
5820
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5878
5821
|
* const machine = Machine.make({
|
|
5879
5822
|
* root: States,
|
|
5880
|
-
* events: Machine.eventsFromSchemas()
|
|
5881
|
-
*
|
|
5882
|
-
*
|
|
5883
|
-
*
|
|
5823
|
+
* events: Machine.eventsFromSchemas()
|
|
5824
|
+
* }).handle({
|
|
5825
|
+
* initial: {
|
|
5826
|
+
* target: Machine.targets(States).root.Idle
|
|
5827
|
+
* },
|
|
5828
|
+
* states: {
|
|
5829
|
+
* Idle: {}
|
|
5830
|
+
* }
|
|
5831
|
+
* })
|
|
5884
5832
|
* const resumed = Effect.gen(function*() {
|
|
5885
5833
|
* const initial = yield* Machine.planInitial(machine)
|
|
5886
5834
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|