@typeonce/effect-machine 0.33.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 +272 -628
- package/dist/Machine.d.ts +1076 -896
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +141 -90
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/childRegistry.d.ts +1 -1
- package/dist/internal/machine/childRegistry.d.ts.map +1 -1
- package/dist/internal/machine/cluster.d.ts +2 -50
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js +4 -27
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/clusterProtocol.d.ts +35 -0
- package/dist/internal/machine/clusterProtocol.d.ts.map +1 -0
- package/dist/internal/machine/clusterProtocol.js +28 -0
- package/dist/internal/machine/clusterProtocol.js.map +1 -0
- package/dist/internal/machine/commandRuntime.d.ts +1 -1
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/configuration.d.ts +2 -2
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +38 -64
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/declaration.d.ts +17 -0
- package/dist/internal/machine/declaration.d.ts.map +1 -0
- package/dist/internal/machine/declaration.js +120 -0
- package/dist/internal/machine/declaration.js.map +1 -0
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +15 -22
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +34 -0
- package/dist/internal/machine/implementation.d.ts.map +1 -0
- package/dist/internal/machine/implementation.js +3 -0
- package/dist/internal/machine/implementation.js.map +1 -0
- 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/invocation.d.ts +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +1 -1
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationDefinition.d.ts +1 -1
- package/dist/internal/machine/invocationDefinition.d.ts.map +1 -1
- package/dist/internal/machine/machine.d.ts +13 -4
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +169 -388
- 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 +37 -78
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +8 -7
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +16 -12
- package/dist/internal/machine/process.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/runtime.d.ts +2 -230
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +8 -1857
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/runtimeCompiled.d.ts +5 -0
- package/dist/internal/machine/runtimeCompiled.d.ts.map +1 -0
- package/dist/internal/machine/runtimeCompiled.js +867 -0
- package/dist/internal/machine/runtimeCompiled.js.map +1 -0
- package/dist/internal/machine/runtimeGeneric.d.ts +3 -0
- package/dist/internal/machine/runtimeGeneric.d.ts.map +1 -0
- package/dist/internal/machine/runtimeGeneric.js +471 -0
- package/dist/internal/machine/runtimeGeneric.js.map +1 -0
- package/dist/internal/machine/runtimeProtocol.d.ts +312 -0
- package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -0
- package/dist/internal/machine/runtimeProtocol.js +561 -0
- package/dist/internal/machine/runtimeProtocol.js.map +1 -0
- 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 +15 -0
- package/dist/internal/machine/targetReference.d.ts.map +1 -0
- package/dist/internal/machine/targetReference.js +41 -0
- package/dist/internal/machine/targetReference.js.map +1 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +5 -3
- 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 +53 -46
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/probe.js +1 -1
- package/dist/internal/testing/machine/probe.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 +18 -13
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +18 -25
- 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/docs/agent-guide.md +66 -91
- package/docs/machine-review.md +19 -49
- package/docs/root-api.md +62 -62
- package/package.json +1 -1
- package/src/Machine.ts +1836 -2907
- package/src/internal/machine/childRegistry.ts +1 -1
- package/src/internal/machine/cluster.ts +7 -73
- package/src/internal/machine/clusterProtocol.ts +56 -0
- package/src/internal/machine/commandRuntime.ts +1 -1
- package/src/internal/machine/configuration.ts +53 -65
- package/src/internal/machine/declaration.ts +140 -0
- package/src/internal/machine/executionPlan.ts +16 -22
- package/src/internal/machine/implementation.ts +41 -0
- package/src/internal/machine/initialDeclaration.ts +157 -0
- package/src/internal/machine/invocation.ts +3 -3
- package/src/internal/machine/invocationDefinition.ts +1 -1
- package/src/internal/machine/machine.ts +225 -576
- package/src/internal/machine/planner.ts +84 -118
- package/src/internal/machine/process.ts +40 -33
- package/src/internal/machine/protocol.ts +3 -3
- package/src/internal/machine/runtime.ts +20 -3037
- package/src/internal/machine/runtimeCompiled.ts +1166 -0
- package/src/internal/machine/runtimeGeneric.ts +799 -0
- package/src/internal/machine/runtimeProtocol.ts +1213 -0
- package/src/internal/machine/stateDefinition.ts +1 -15
- package/src/internal/machine/targetReference.ts +55 -0
- package/src/internal/machine/topology.ts +5 -3
- package/src/internal/testing/machine/finiteModel.ts +58 -53
- package/src/internal/testing/machine/probe.ts +1 -1
- package/src/internal/testing/machine/verification.ts +7 -1
- package/src/testing/MachineTest.ts +105 -73
- package/src/unstable/cluster/ClusterMachine.ts +22 -25
- package/src/unstable/reactivity/AtomMachine.ts +41 -24
package/dist/Machine.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import * as internal from "./internal/machine/machine.js";
|
|
|
19
19
|
import { InitialEventTypeId } from "./internal/machine/machine.js";
|
|
20
20
|
import type { EnsureExecutable } from "./internal/machine/readiness.js";
|
|
21
21
|
import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js";
|
|
22
|
-
import type * as internalRuntime from "./internal/machine/
|
|
22
|
+
import type * as internalRuntime from "./internal/machine/runtimeProtocol.js";
|
|
23
23
|
import type * as StateDefinition from "./internal/machine/stateDefinition.js";
|
|
24
24
|
import type * as Topology from "./internal/machine/topology.js";
|
|
25
25
|
/**
|
|
@@ -91,9 +91,32 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
91
91
|
*
|
|
92
92
|
* **Gotchas**
|
|
93
93
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
94
|
+
* Use `guard` to decline a transition before constructing its next state.
|
|
95
|
+
* Use `declinable: true` when a named branch resolver may return `decline()`.
|
|
96
|
+
* Register cancellable state-scoped delays in `make({ timers })`.
|
|
97
|
+
*
|
|
98
|
+
* **Example**
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
102
|
+
* import { Schema } from "effect"
|
|
103
|
+
* const events = Machine.events({ Add: { by: Schema.Number } })
|
|
104
|
+
* const Root = Machine.state({ fields: { count: Schema.Number } })
|
|
105
|
+
* const targets = Machine.targets(Root)
|
|
106
|
+
* export const counter = Machine.make({
|
|
107
|
+
* root: Root,
|
|
108
|
+
* events
|
|
109
|
+
* }).handle({
|
|
110
|
+
* root: () => ({ count: 0 }),
|
|
111
|
+
* on: {
|
|
112
|
+
* Add: {
|
|
113
|
+
* update: targets.root,
|
|
114
|
+
* guard: ({ event }) => event.by > 0,
|
|
115
|
+
* data: ({ root, event }) => ({ count: root.count + event.by })
|
|
116
|
+
* }
|
|
117
|
+
* }
|
|
118
|
+
* })
|
|
119
|
+
* ```
|
|
97
120
|
*
|
|
98
121
|
* @category models
|
|
99
122
|
* @since 0.4.0
|
|
@@ -159,7 +182,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
159
182
|
/** @internal */
|
|
160
183
|
readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
|
|
161
184
|
/** @internal */
|
|
162
|
-
readonly handlers:
|
|
185
|
+
readonly handlers: Readonly<Record<string, unknown>>;
|
|
163
186
|
/** @internal */
|
|
164
187
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
|
|
165
188
|
/** @internal */
|
|
@@ -179,7 +202,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
179
202
|
* @category models
|
|
180
203
|
* @since 0.15.0
|
|
181
204
|
*/
|
|
182
|
-
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 []> 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"> {
|
|
183
206
|
/**
|
|
184
207
|
* Adds typed state handlers and returns an independent machine
|
|
185
208
|
* implementation. Event dispatch maps and transition descriptors are
|
|
@@ -189,12 +212,14 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
|
|
|
189
212
|
* **Example**
|
|
190
213
|
*
|
|
191
214
|
* ```ts
|
|
215
|
+
* const targets = Machine.targets(States)
|
|
192
216
|
* const counter = definition.handle({ states: {
|
|
193
217
|
* Count: {
|
|
194
218
|
* on: {
|
|
195
|
-
* Increment:
|
|
196
|
-
*
|
|
197
|
-
*
|
|
219
|
+
* Increment: {
|
|
220
|
+
* update: targets.root.Count,
|
|
221
|
+
* decoded: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
222
|
+
* }
|
|
198
223
|
* }
|
|
199
224
|
* }
|
|
200
225
|
* } })
|
|
@@ -202,7 +227,7 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
|
|
|
202
227
|
*
|
|
203
228
|
* @since 0.4.0
|
|
204
229
|
*/
|
|
205
|
-
readonly handle: Machine.Handler<States, Events, Emits, Input,
|
|
230
|
+
readonly handle: Machine.Handler<States, Events, Emits, Input, InitialE, InitialR, FinalStates, Output, InputEvents, ParentEvents, Registrations>;
|
|
206
231
|
}
|
|
207
232
|
/**
|
|
208
233
|
* Namespace containing type-level members associated with {@link Definition}.
|
|
@@ -217,7 +242,7 @@ export declare namespace Definition {
|
|
|
217
242
|
* @category models
|
|
218
243
|
* @since 0.15.0
|
|
219
244
|
*/
|
|
220
|
-
interface Any extends Machine.Any {
|
|
245
|
+
interface Any extends Omit<Machine.Any, TypeId | "stateNodes" | "makeTargetBuilder" | "handlers" | "initial" | "initialDefinition"> {
|
|
221
246
|
readonly handle: any;
|
|
222
247
|
}
|
|
223
248
|
}
|
|
@@ -490,10 +515,6 @@ export declare namespace Runtime {
|
|
|
490
515
|
}
|
|
491
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;
|
|
492
517
|
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
493
|
-
declare const TransitionTypeId: typeof internal.TransitionTypeId;
|
|
494
|
-
declare const TransitionBuilderTypeId: unique symbol;
|
|
495
|
-
declare const InvokeBuilderTypeId: unique symbol;
|
|
496
|
-
declare const InitialBuilderTypeId: unique symbol;
|
|
497
518
|
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
498
519
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
499
520
|
readonly path: Path;
|
|
@@ -546,11 +567,9 @@ type ValidateStateNodeWithChildren<Node extends Machine.StateNodeConfig, Childre
|
|
|
546
567
|
} ? ValidateInitialSelectorChild<Children, Path> & ("initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
|
|
547
568
|
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
548
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">;
|
|
549
|
-
type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> =
|
|
550
|
-
readonly initial: infer Initial;
|
|
551
|
-
} ? 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> & {
|
|
552
571
|
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
553
|
-
}
|
|
572
|
+
};
|
|
554
573
|
type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
|
|
555
574
|
readonly type: infer Type;
|
|
556
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;
|
|
@@ -689,55 +708,6 @@ type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input
|
|
|
689
708
|
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
690
709
|
<Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
691
710
|
} : <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected) => Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
692
|
-
type InitialSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
|
|
693
|
-
readonly [Key in ActiveStateKey<States>]: InitialSnapshotMethod<States, Key, Prefix>;
|
|
694
|
-
} & {
|
|
695
|
-
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
696
|
-
};
|
|
697
|
-
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>>;
|
|
698
|
-
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 {
|
|
699
|
-
readonly type: "parallel";
|
|
700
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
701
|
-
} ? WithNodeValue<Node, [
|
|
702
|
-
states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>>
|
|
703
|
-
]> : Node extends {
|
|
704
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
705
|
-
} ? Node extends {
|
|
706
|
-
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
707
|
-
} ? WithNodeValue<Node, [
|
|
708
|
-
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSelectableResult<Children, Initial, Path>
|
|
709
|
-
]> : never : WithNodeValue<Node, []> : never;
|
|
710
|
-
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 {
|
|
711
|
-
readonly type: "parallel";
|
|
712
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
713
|
-
} ? WithNodeInput<Node, [
|
|
714
|
-
states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
715
|
-
]> : Node extends {
|
|
716
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
717
|
-
} ? Node extends {
|
|
718
|
-
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
719
|
-
} ? WithNodeInput<Node, [
|
|
720
|
-
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
|
|
721
|
-
]> : never : WithNodeInput<Node, []> : never;
|
|
722
|
-
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 {
|
|
723
|
-
readonly type: "parallel";
|
|
724
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
725
|
-
} ? Machine.ParallelSnapshot<Path, NodeValue<Node>, InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
|
|
726
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
727
|
-
} ? Node extends {
|
|
728
|
-
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
729
|
-
} ? Machine.CompoundSnapshot<Path, NodeValue<Node>, InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, NodeValue<Node>> : never;
|
|
730
|
-
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;
|
|
731
|
-
type InitialSnapshotRegionsWithPrefix<States extends Machine.StateSchemas, Prefix extends string> = {
|
|
732
|
-
readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>;
|
|
733
|
-
};
|
|
734
|
-
type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
735
|
-
readonly [Key in Remaining]: NodeBuilderMethod<States[Key], InitialSnapshotArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
736
|
-
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
737
|
-
}, Constructed>, InitialSnapshotFromArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
738
|
-
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
739
|
-
}, true>>;
|
|
740
|
-
};
|
|
741
711
|
type FullSnapshotBuilderWithPrefix<in out States extends Machine.StateSchemas, in out Prefix extends string = ""> = {
|
|
742
712
|
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]: Key extends ActiveStateKey<States> ? FullSnapshotMethod<States, Key, Prefix> : () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
743
713
|
};
|
|
@@ -931,8 +901,7 @@ type InitializerClosureForNode<AllStates extends Machine.StateSchemas, Node, Pat
|
|
|
931
901
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
932
902
|
} ? (HasRequiredActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never) | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
|
|
933
903
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
934
|
-
|
|
935
|
-
} ? (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;
|
|
936
905
|
type InitializerClosuresForChildren<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
937
906
|
readonly [Key in ActiveStateKey<States>]: InitializerClosureForNode<AllStates, States[Key], Machine.JoinPath<Prefix, Key>>;
|
|
938
907
|
}[ActiveStateKey<States>];
|
|
@@ -1930,7 +1899,6 @@ export declare namespace Machine {
|
|
|
1930
1899
|
/** Compound states are ordinary active states. */
|
|
1931
1900
|
readonly type?: "active";
|
|
1932
1901
|
/** Direct child selected when the compound state is entered initially. */
|
|
1933
|
-
readonly initial: string;
|
|
1934
1902
|
/** Nested state nodes owned by this compound state. */
|
|
1935
1903
|
readonly states: StateTree;
|
|
1936
1904
|
/** Schema-backed states take their annotations from the schema. */
|
|
@@ -1938,7 +1906,6 @@ export declare namespace Machine {
|
|
|
1938
1906
|
} | {
|
|
1939
1907
|
readonly schema?: never;
|
|
1940
1908
|
readonly type?: "active";
|
|
1941
|
-
readonly initial: string;
|
|
1942
1909
|
readonly states: StateTree;
|
|
1943
1910
|
/** Descriptive metadata for a schema-less state. */
|
|
1944
1911
|
readonly annotations?: SchemaLessStateAnnotations;
|
|
@@ -2050,7 +2017,6 @@ export declare namespace Machine {
|
|
|
2050
2017
|
* @category utility types
|
|
2051
2018
|
* @since 0.4.0
|
|
2052
2019
|
*/
|
|
2053
|
-
type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>;
|
|
2054
2020
|
/**
|
|
2055
2021
|
* Typed snapshot access shared by state descriptors.
|
|
2056
2022
|
*
|
|
@@ -2435,12 +2401,10 @@ export declare namespace Machine {
|
|
|
2435
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 : {
|
|
2436
2402
|
readonly "~effect/Machine/MissingHistoryImplementation": MissingHistoryImplementations<States, UnhandledStates>;
|
|
2437
2403
|
}) & EnsureChoiceImplementations<States, UnhandledStates>;
|
|
2438
|
-
/** Owners
|
|
2439
|
-
type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never : "" extends keyof States ? States[""]
|
|
2440
|
-
readonly "~effect/Machine/ExplicitInitial": true;
|
|
2441
|
-
} ? 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;
|
|
2442
2406
|
/** Proof that initialization can construct every required default value. */
|
|
2443
|
-
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 : {
|
|
2444
2408
|
readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>;
|
|
2445
2409
|
};
|
|
2446
2410
|
/**
|
|
@@ -3052,7 +3016,7 @@ export declare namespace Machine {
|
|
|
3052
3016
|
* do not directly control state re-entry. Exit and entry paths are derived
|
|
3053
3017
|
* from the previous and next active paths. Shared active ancestors remain
|
|
3054
3018
|
* entered even when a `full` target supplies their values again. Use an event
|
|
3055
|
-
* transition with
|
|
3019
|
+
* transition with `reenter: true` when the source should explicitly exit and
|
|
3056
3020
|
* enter again.
|
|
3057
3021
|
*
|
|
3058
3022
|
* @category models
|
|
@@ -3117,89 +3081,9 @@ export declare namespace Machine {
|
|
|
3117
3081
|
}
|
|
3118
3082
|
type SelectionValue<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state", Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> = TargetSelection<Builder, Path, Kind, Scope>;
|
|
3119
3083
|
type SelectionMethod<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state", Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> = () => SelectionValue<Builder, Path, Kind, Scope>;
|
|
3120
|
-
type InitialSelectionMethod<Builder, Path extends string, Scope extends Topology.TargetSelectionScope> = Builder extends {
|
|
3121
|
-
readonly initial: infer Initial;
|
|
3122
|
-
} ? {
|
|
3123
|
-
readonly initial: SelectionValue<Initial, Path, "initial", Scope>;
|
|
3124
|
-
} : {};
|
|
3125
|
-
type SelectionTreeWithPrefix<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Scope extends "local" | "branch", Builder> = {
|
|
3126
|
-
readonly [Key in Extract<ActiveStateKey<States> | ChoiceStateKey<States>, keyof Builder>]: SelectionNode<AllStates, States[Key], JoinPath<Prefix, Key>, Scope, Builder[Key]>;
|
|
3127
|
-
};
|
|
3128
|
-
type SelectionNode<AllStates extends StateSchemas, Node, Path extends string, Scope extends "local" | "branch", Builder> = Node extends ChoiceStateNodeConfig ? SelectionMethod<Builder, Path, "choice", Scope> : Node extends {
|
|
3129
|
-
readonly states: infer Children extends StateSchemas;
|
|
3130
|
-
} ? SelectionMethod<Builder, Path, "state", Scope> & InitialSelectionMethod<Builder, Path, Scope> & SelectionTreeWithPrefix<AllStates, Children, Path, Scope, Builder> : SelectionMethod<Builder, Path, "state", Scope>;
|
|
3131
|
-
/** @internal */
|
|
3132
|
-
type StateUpdateSelectionForNode<AllStates extends StateSchemas, Node, Path extends string, Scope extends "local" | "branch"> = Node extends {
|
|
3133
|
-
readonly type: "final";
|
|
3134
|
-
} ? {} : NodeSchema<Node> extends never ? {} : {
|
|
3135
|
-
readonly update: SelectionValue<StateUpdateBuilder<AllStates, Extract<Path, ValuedStateIdentifier<AllStates>>>, Path, "update", Scope>;
|
|
3136
|
-
};
|
|
3137
|
-
/** @internal */
|
|
3138
|
-
type BranchUpdateSelectionPath<AllStates extends StateSchemas, Node, Path extends string, Rest extends string, Scope extends "local" | "branch" = "branch"> = StateUpdateSelectionForNode<AllStates, Node, Path, Scope> & (Node extends {
|
|
3139
|
-
readonly states: infer Children extends StateSchemas;
|
|
3140
|
-
} ? Rest extends `${infer Head}.${infer Tail}` ? Head extends keyof Children ? {
|
|
3141
|
-
readonly [Key in Head]: BranchUpdateSelectionPath<AllStates, Children[Head], JoinPath<Path, Head>, Tail, Scope>;
|
|
3142
|
-
} : {} : Rest extends keyof Children ? {
|
|
3143
|
-
readonly [Key in Rest]: StateUpdateSelectionForNode<AllStates, Children[Rest], JoinPath<Path, Rest>, Scope>;
|
|
3144
|
-
} : {} : {});
|
|
3145
|
-
type FullSelectionNode<AllStates extends StateSchemas, Node, Path extends StateIdentifier<AllStates>, Builder> = Node extends {
|
|
3146
|
-
readonly states: StateSchemas;
|
|
3147
|
-
} ? SelectionMethod<Builder, Path, "state", "full"> & InitialSelectionMethod<Builder, Path, "full"> : SelectionMethod<Builder, Path, "state", "full">;
|
|
3148
3084
|
type RootBuilder<Builder> = Builder extends {
|
|
3149
3085
|
readonly "": infer Root;
|
|
3150
3086
|
} ? Root : never;
|
|
3151
|
-
type FullTargetSelector<States extends StateSchemas> = SelectionValue<RootBuilder<FullTargetBuilder<States>>, "", "state", "full"> & InitialSelectionMethod<RootBuilder<FullTargetBuilder<States>>, "", "full">;
|
|
3152
|
-
type BranchTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = States[""] extends {
|
|
3153
|
-
readonly states: infer Children extends StateSchemas;
|
|
3154
|
-
} ? SelectionTreeWithPrefix<States, Children, "", "branch", RootBuilder<BranchTargetBuilder<States, Source>>> & (Source extends ChoiceIdentifier<States> ? {} : Omit<BranchUpdateSelectionPath<States, States[""], "", Source>, "update">) : {};
|
|
3155
|
-
type LocalTargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = NearestCompoundScope<States, Source> extends infer Scope ? [Scope] extends [never] ? {} : Scope extends StateIdentifier<States> ? ChildrenOf<States, Scope> extends infer Children extends StateSchemas ? LocalTargetBuilder<States, Source> extends infer Builder ? SelectionTreeWithPrefix<States, Children, Scope, "local", Builder> & ("with" extends keyof Builder ? {
|
|
3156
|
-
readonly with: SelectionValue<Builder["with"], Scope, "state", "local">;
|
|
3157
|
-
} : {}) & (Source extends ChoiceIdentifier<States> ? {} : Scope extends ValuedStateIdentifier<States> ? {
|
|
3158
|
-
readonly update: SelectionValue<StateUpdateBuilder<States, Scope>, Scope, "update", "local">;
|
|
3159
|
-
} : {}) : {} : {} : {} : {};
|
|
3160
|
-
type HistorySelectionTree<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Builder> = {
|
|
3161
|
-
readonly [Key in Extract<HistoryContainingKey<States>, keyof Builder>]: States[Key] extends HistoryStateNodeConfig ? SelectionValue<Builder[Key], JoinPath<Prefix, Key>, "history", "full"> : States[Key] extends {
|
|
3162
|
-
readonly states: infer Children extends StateSchemas;
|
|
3163
|
-
} ? HistorySelectionTree<AllStates, Children, JoinPath<Prefix, Key>, Builder[Key]> : never;
|
|
3164
|
-
};
|
|
3165
|
-
/**
|
|
3166
|
-
* Definition-time topology selector available to an ordinary transition.
|
|
3167
|
-
*
|
|
3168
|
-
* Topology-only instructions (`none`, declared `initial` and history
|
|
3169
|
-
* selections, and `local.with`) are values.
|
|
3170
|
-
*
|
|
3171
|
-
* State and choice destinations remain callable selection methods so their
|
|
3172
|
-
* target-specific resolver APIs retain exact inference.
|
|
3173
|
-
*/
|
|
3174
|
-
interface TargetSelector<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
|
|
3175
|
-
/** Replaces this handler owner's value without reentry. */
|
|
3176
|
-
/** Selects the current handler owner for a value update without reentry. */
|
|
3177
|
-
readonly self: Source extends ValuedStateIdentifier<States> ? StateUpdateSelectionForNode<States, NodeByIdentifier<States, Source>, Source, "branch"> : {};
|
|
3178
|
-
/** Addresses the root and its retained value from any active descendant. */
|
|
3179
|
-
readonly root: "" extends ActiveStateKey<States> ? SelectionNode<States, States[""], "", "branch", (BranchTargetBuilder<States, Source> extends {
|
|
3180
|
-
readonly "": infer Builder;
|
|
3181
|
-
} ? Builder : never)> & StateUpdateSelectionForNode<States, States[""], "", "branch"> : never;
|
|
3182
|
-
/** Handles the trigger without selecting a destination. */
|
|
3183
|
-
readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none", "local">;
|
|
3184
|
-
/** Selects a destination or updates the nearest active compound scope. */
|
|
3185
|
-
readonly local: LocalTargetSelector<States, Source>;
|
|
3186
|
-
/** Selects a destination or updates a valued active ancestor under the current root. */
|
|
3187
|
-
readonly branch: BranchTargetSelector<States, Source>;
|
|
3188
|
-
/** Selects a complete destination under any top-level state. */
|
|
3189
|
-
readonly full: FullTargetSelector<States>;
|
|
3190
|
-
/** Restores a shallow or deep history pseudo-state. */
|
|
3191
|
-
readonly history: States[""] extends {
|
|
3192
|
-
readonly states: infer Children extends StateSchemas;
|
|
3193
|
-
} ? HistorySelectionTree<States, Children, "", RootBuilder<HistoryTargetBuilder<States>>> : {};
|
|
3194
|
-
}
|
|
3195
|
-
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
3196
|
-
type InitialTargetSelector<States extends StateSchemas> = {
|
|
3197
|
-
readonly [Key in Extract<ActiveStateKey<States>, keyof InitialBuilder<States>>]: States[Key] extends {
|
|
3198
|
-
readonly states: StateSchemas;
|
|
3199
|
-
} ? {
|
|
3200
|
-
readonly initial: SelectionValue<InitialBuilder<States>[Key], Key, "initial", "initial">;
|
|
3201
|
-
} : SelectionMethod<InitialBuilder<States>[Key], Key, "state", "initial">;
|
|
3202
|
-
};
|
|
3203
3087
|
/**
|
|
3204
3088
|
* Context passed to a state/event handler.
|
|
3205
3089
|
*
|
|
@@ -3217,13 +3101,8 @@ export declare namespace Machine {
|
|
|
3217
3101
|
readonly snapshot: Snapshot<States>;
|
|
3218
3102
|
/** Event that selected this handler, narrowed by its `_tag`. */
|
|
3219
3103
|
readonly event: EventByTag<Events, EventTag>;
|
|
3220
|
-
/**
|
|
3221
|
-
|
|
3222
|
-
* handler. Each builder documents which existing state values it keeps.
|
|
3223
|
-
*
|
|
3224
|
-
* @since 0.4.0
|
|
3225
|
-
*/
|
|
3226
|
-
readonly target: TargetBuilder<States, StateId>;
|
|
3104
|
+
/** Value owned by the logical root. */
|
|
3105
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3227
3106
|
};
|
|
3228
3107
|
/**
|
|
3229
3108
|
* Context passed to an entry or exit state handler.
|
|
@@ -3252,6 +3131,8 @@ export declare namespace Machine {
|
|
|
3252
3131
|
readonly children: ChildOwner<EventOf<InputEvents>>;
|
|
3253
3132
|
/** Value owned by the state that owns this invocation. */
|
|
3254
3133
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3134
|
+
/** Value owned by the logical root. */
|
|
3135
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3255
3136
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
3256
3137
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3257
3138
|
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
@@ -3274,8 +3155,8 @@ export declare namespace Machine {
|
|
|
3274
3155
|
readonly containingState: ParentStateValue<States, StateId>;
|
|
3275
3156
|
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
3276
3157
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3277
|
-
/**
|
|
3278
|
-
readonly
|
|
3158
|
+
/** Value owned by the logical root. */
|
|
3159
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3279
3160
|
/** Latest active lifecycle snapshot published by the invoked logic or child. */
|
|
3280
3161
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
3281
3162
|
readonly status: "active";
|
|
@@ -3298,8 +3179,8 @@ export declare namespace Machine {
|
|
|
3298
3179
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3299
3180
|
/** Complete owning-machine configuration captured for this transition. */
|
|
3300
3181
|
readonly snapshot: Snapshot<States>;
|
|
3301
|
-
/**
|
|
3302
|
-
readonly
|
|
3182
|
+
/** Value owned by the logical root. */
|
|
3183
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3303
3184
|
/** Successful output produced by the invocation. */
|
|
3304
3185
|
readonly output: Output;
|
|
3305
3186
|
};
|
|
@@ -3315,8 +3196,8 @@ export declare namespace Machine {
|
|
|
3315
3196
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3316
3197
|
/** Complete owning-machine configuration captured for this transition. */
|
|
3317
3198
|
readonly snapshot: Snapshot<States>;
|
|
3318
|
-
/**
|
|
3319
|
-
readonly
|
|
3199
|
+
/** Value owned by the logical root. */
|
|
3200
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3320
3201
|
/** Next element emitted by the invoked Stream. */
|
|
3321
3202
|
readonly element: Element;
|
|
3322
3203
|
};
|
|
@@ -3332,8 +3213,8 @@ export declare namespace Machine {
|
|
|
3332
3213
|
readonly ancestors: ParentStateValues<States, StateId>;
|
|
3333
3214
|
/** Complete owning-machine configuration captured for this transition. */
|
|
3334
3215
|
readonly snapshot: Snapshot<States>;
|
|
3335
|
-
/**
|
|
3336
|
-
readonly
|
|
3216
|
+
/** Value owned by the logical root. */
|
|
3217
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3337
3218
|
/** Typed failure produced by the invocation. */
|
|
3338
3219
|
readonly error: Error;
|
|
3339
3220
|
};
|
|
@@ -3354,14 +3235,8 @@ export declare namespace Machine {
|
|
|
3354
3235
|
readonly snapshot: Snapshot<States>;
|
|
3355
3236
|
/** Lifecycle event retained while the eventless transition is evaluated. */
|
|
3356
3237
|
readonly event: LifecycleEvent<Events>;
|
|
3357
|
-
/**
|
|
3358
|
-
|
|
3359
|
-
* eventless handler. Each builder documents which existing state values it
|
|
3360
|
-
* keeps.
|
|
3361
|
-
*
|
|
3362
|
-
* @since 0.4.0
|
|
3363
|
-
*/
|
|
3364
|
-
readonly target: TargetBuilder<States, StateId>;
|
|
3238
|
+
/** Value owned by the logical root. */
|
|
3239
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3365
3240
|
};
|
|
3366
3241
|
/**
|
|
3367
3242
|
* Context passed to a state completion transition handler.
|
|
@@ -3382,14 +3257,8 @@ export declare namespace Machine {
|
|
|
3382
3257
|
readonly event: LifecycleEvent<Events>;
|
|
3383
3258
|
/** Output produced by the completed final child or parallel regions. */
|
|
3384
3259
|
readonly output: CompletionOutputByIdentifier<States, StateId>;
|
|
3385
|
-
/**
|
|
3386
|
-
|
|
3387
|
-
* state completes. Each builder documents which existing state values it
|
|
3388
|
-
* keeps.
|
|
3389
|
-
*
|
|
3390
|
-
* @since 0.4.0
|
|
3391
|
-
*/
|
|
3392
|
-
readonly target: TargetBuilder<States, StateId>;
|
|
3260
|
+
/** Value owned by the logical root. */
|
|
3261
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3393
3262
|
};
|
|
3394
3263
|
/** Context passed to a transient choice resolver. There is no `state` value. */
|
|
3395
3264
|
type ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
@@ -3401,8 +3270,8 @@ export declare namespace Machine {
|
|
|
3401
3270
|
};
|
|
3402
3271
|
/** Lifecycle event that led to the transient choice. */
|
|
3403
3272
|
readonly event: LifecycleEvent<Events>;
|
|
3404
|
-
/**
|
|
3405
|
-
readonly
|
|
3273
|
+
/** Value owned by the logical root. */
|
|
3274
|
+
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3406
3275
|
};
|
|
3407
3276
|
/**
|
|
3408
3277
|
* Context passed to a final state output function.
|
|
@@ -3463,11 +3332,7 @@ export declare namespace Machine {
|
|
|
3463
3332
|
* @category utility types
|
|
3464
3333
|
* @since 0.4.0
|
|
3465
3334
|
*/
|
|
3466
|
-
type InitialResult<States extends StateSchemas, E, R> =
|
|
3467
|
-
/** Initial snapshots may transiently terminate in a declared choice node. */
|
|
3468
|
-
type InitialSnapshot<States extends StateSchemas> = {
|
|
3469
|
-
readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">;
|
|
3470
|
-
}[ActiveStateKey<States>];
|
|
3335
|
+
type InitialResult<States extends StateSchemas, E, R> = InitialTarget<StateIdentifier<States>>;
|
|
3471
3336
|
/**
|
|
3472
3337
|
* Return value accepted from transition handlers.
|
|
3473
3338
|
*
|
|
@@ -3475,7 +3340,7 @@ export declare namespace Machine {
|
|
|
3475
3340
|
*
|
|
3476
3341
|
* Handlers return snapshots for complete state replacement, target builder
|
|
3477
3342
|
* results for path-safe partial transitions, state-value updates, or
|
|
3478
|
-
* an explicit targetless result. In a machine definition, select `
|
|
3343
|
+
* an explicit targetless result. In a machine definition, select `{ none: true }`;
|
|
3479
3344
|
* its optional resolver returns `undefined`. Raw decoded state values are
|
|
3480
3345
|
* not accepted as transition targets.
|
|
3481
3346
|
*
|
|
@@ -3520,10 +3385,6 @@ export declare namespace Machine {
|
|
|
3520
3385
|
* @since 0.4.0
|
|
3521
3386
|
*/
|
|
3522
3387
|
type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3523
|
-
/** Extracts the return value from an implicit initial child implementation. */
|
|
3524
|
-
type StateInitializeReturn<Config> = Config extends {
|
|
3525
|
-
readonly initialize?: infer Initialize;
|
|
3526
|
-
} ? NonNullable<Initialize> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3527
3388
|
/** Extracts the return values from a state's history defaults. */
|
|
3528
3389
|
type HistoryDefaultReturn<Config> = Config extends {
|
|
3529
3390
|
readonly history?: infer History;
|
|
@@ -3542,7 +3403,9 @@ export declare namespace Machine {
|
|
|
3542
3403
|
* @category utility types
|
|
3543
3404
|
* @since 0.4.0
|
|
3544
3405
|
*/
|
|
3545
|
-
type EventTransitionReturn<Transition> = Transition extends
|
|
3406
|
+
type EventTransitionReturn<Transition> = Transition extends {
|
|
3407
|
+
readonly initial: TargetReference<any, infer P, any>;
|
|
3408
|
+
} ? InitialTarget<P> : Transition extends {
|
|
3546
3409
|
readonly resolve?: infer Resolve;
|
|
3547
3410
|
} ? NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3548
3411
|
/**
|
|
@@ -3571,7 +3434,7 @@ export declare namespace Machine {
|
|
|
3571
3434
|
* @category utility types
|
|
3572
3435
|
* @since 0.4.0
|
|
3573
3436
|
*/
|
|
3574
|
-
type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3437
|
+
type InvokeResolvedSource<Source> = Source extends LazyProgramValue ? Source : Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3575
3438
|
type InvokeFactoryResult<Source> = Source extends (...args: any) => infer Resolved ? Resolved : never;
|
|
3576
3439
|
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialServices<M> | Services<M>>, internalRuntime.MachineRuntime>, Event<M>, EmittedEvent<M>>, Output<M>, InitialError<M> | Error<M> | ActionError<InitialServices<M> | Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError> : never;
|
|
3577
3440
|
type InvokeLogic<Invoke> = Invoke extends {
|
|
@@ -3595,7 +3458,7 @@ export declare namespace Machine {
|
|
|
3595
3458
|
readonly [InvokeTypeId]: {
|
|
3596
3459
|
readonly initialError: Types.Covariant<infer InitialError>;
|
|
3597
3460
|
};
|
|
3598
|
-
} ? InitialError : InvokeLogic<Invoke
|
|
3461
|
+
} ? InitialError : LogicInitialErrorOf<InvokeLogic<Invoke>>;
|
|
3599
3462
|
/**
|
|
3600
3463
|
* Extracts the runtime error from an invoked child process.
|
|
3601
3464
|
*
|
|
@@ -3606,7 +3469,7 @@ export declare namespace Machine {
|
|
|
3606
3469
|
readonly [InvokeTypeId]: {
|
|
3607
3470
|
readonly error: Types.Covariant<infer Error>;
|
|
3608
3471
|
};
|
|
3609
|
-
} ? Error : InvokeLogic<Invoke
|
|
3472
|
+
} ? Error : LogicErrorOf<InvokeLogic<Invoke>>;
|
|
3610
3473
|
/**
|
|
3611
3474
|
* Extracts the output from an invoked child process.
|
|
3612
3475
|
*
|
|
@@ -3617,7 +3480,7 @@ export declare namespace Machine {
|
|
|
3617
3480
|
readonly [InvokeTypeId]: {
|
|
3618
3481
|
readonly output: Types.Covariant<infer Output>;
|
|
3619
3482
|
};
|
|
3620
|
-
} ? Output : InvokeLogic<Invoke
|
|
3483
|
+
} ? Output : LogicOutputOf<InvokeLogic<Invoke>>;
|
|
3621
3484
|
/**
|
|
3622
3485
|
* Extracts the service requirements from an invoke source child process logic.
|
|
3623
3486
|
*
|
|
@@ -3628,7 +3491,7 @@ export declare namespace Machine {
|
|
|
3628
3491
|
readonly [InvokeTypeId]: {
|
|
3629
3492
|
readonly requirements: Types.Covariant<infer Requirements>;
|
|
3630
3493
|
};
|
|
3631
|
-
} ? Requirements : InvokeLogic<Invoke
|
|
3494
|
+
} ? Requirements : LogicServicesOf<InvokeLogic<Invoke>>;
|
|
3632
3495
|
/**
|
|
3633
3496
|
* Extracts events emitted directly by an invoked child.
|
|
3634
3497
|
*
|
|
@@ -3713,31 +3576,21 @@ export declare namespace Machine {
|
|
|
3713
3576
|
* @category utility types
|
|
3714
3577
|
* @since 0.4.0
|
|
3715
3578
|
*/
|
|
3716
|
-
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
|
|
3717
|
-
/** Type evidence retained by an authored transition without affecting runtime data. */
|
|
3718
|
-
interface TransitionTyped<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance = "required"> {
|
|
3719
|
-
readonly [TransitionTypeId]: {
|
|
3720
|
-
readonly owner: Types.Covariant<readonly [States, Events, Emits, StateId, Context]>;
|
|
3721
|
-
readonly acceptance: Types.Covariant<Acceptance>;
|
|
3722
|
-
};
|
|
3723
|
-
}
|
|
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;
|
|
3724
3580
|
/** The only transition value accepted by machine handler APIs. */
|
|
3725
|
-
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"> =
|
|
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>;
|
|
3726
3582
|
type SelectionBuilder<Selection> = Selection extends TargetSelection<infer Builder, any, any, any> ? Builder : never;
|
|
3727
3583
|
type SelectionKind<Selection> = Selection extends TargetSelection<any, any, infer Kind, any> ? Kind : never;
|
|
3728
3584
|
type SelectionPath<Selection> = Selection extends TargetSelection<any, infer Path, any, any> ? Path : never;
|
|
3729
|
-
type SelectionScope<Selection> = Selection extends TargetSelection<any, any, any, infer Scope> ? Scope : never;
|
|
3730
3585
|
type TargetBuilderResult<Builder> = (Builder extends (...args: any) => infer Result ? Result : never) | (Builder extends {
|
|
3731
3586
|
readonly decoded: (...args: any) => infer Result;
|
|
3732
3587
|
} ? Result : never) | (Builder extends {
|
|
3733
3588
|
readonly from: (...args: any) => infer Result;
|
|
3734
3589
|
} ? Result : never);
|
|
3735
3590
|
type SelectedTargetResult<Selection> = SelectionBuilder<Selection> extends infer Builder ? TargetBuilderResult<Builder> : never;
|
|
3736
|
-
type RetainedUpdateOwner<States extends StateSchemas, Source extends StateNodeIdentifier<States>, Selection> = Extract<ParentStateIdentifier<Source>, ParentStateIdentifier<Extract<SelectionPath<Selection>, string>> & ValuedStateIdentifier<States>>;
|
|
3737
|
-
type RetainedOwnerSelector<Owner extends string> = () => TargetSelection<any, Owner, "state", "branch">;
|
|
3738
3591
|
/**
|
|
3739
3592
|
* Destination construction returned when a transition declares one retained
|
|
3740
|
-
* valued owner with
|
|
3593
|
+
* valued owner with a `{ target, update }` declaration.
|
|
3741
3594
|
*
|
|
3742
3595
|
* @category models
|
|
3743
3596
|
* @since 0.22.0
|
|
@@ -3762,31 +3615,11 @@ export declare namespace Machine {
|
|
|
3762
3615
|
type TransitionResolveContext<Context, Selection> = Omit<Context, "target"> & (SelectionKind<Selection> extends "none" ? {} : {
|
|
3763
3616
|
readonly target: SelectionBuilder<Selection>;
|
|
3764
3617
|
});
|
|
3765
|
-
type StateUpdateResolveContext<States extends StateSchemas, Context, Owner extends ValuedStateIdentifier<States>> = Omit<Context, "target"> & {
|
|
3766
|
-
/** Decoded owner value from the pre-transition snapshot. */
|
|
3767
|
-
readonly current: StateByIdentifier<States, Owner>;
|
|
3768
|
-
/** Constructs the complete replacement for the selected owner. */
|
|
3769
|
-
readonly owner: StateUpdateBuilder<States, Owner>;
|
|
3770
|
-
};
|
|
3771
|
-
type UpdatingTransitionResolveContext<States extends StateSchemas, Context, Selection, Owner extends ValuedStateIdentifier<States>> = Omit<Context, "target"> & {
|
|
3772
|
-
/** Decoded owner value from the pre-transition snapshot. */
|
|
3773
|
-
readonly current: StateByIdentifier<States, Owner>;
|
|
3774
|
-
/** Constructs the selected topology and requires `.update(...)`. */
|
|
3775
|
-
readonly target: UpdatingTargetBuilder<SelectionBuilder<Selection>, States, Owner>;
|
|
3776
|
-
/** Constructs the complete replacement for the retained owner. */
|
|
3777
|
-
readonly owner: StateUpdateBuilder<States, Owner>;
|
|
3778
|
-
};
|
|
3779
3618
|
/** Context capability available only to explicitly declinable resolvers. */
|
|
3780
3619
|
interface DeclineCapability {
|
|
3781
3620
|
/** Declines this candidate and continues hierarchical transition selection. */
|
|
3782
3621
|
readonly decline: () => Declined;
|
|
3783
3622
|
}
|
|
3784
|
-
type TransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined;
|
|
3785
|
-
type DeclinableTransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined;
|
|
3786
|
-
/** @internal */
|
|
3787
|
-
type StateUpdateResolver<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Owner extends ValuedStateIdentifier<States>> = (context: StateUpdateResolveContext<States, Context, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateUpdate<States, Owner>;
|
|
3788
|
-
/** @internal */
|
|
3789
|
-
type DeclinableStateUpdateResolver<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Owner extends ValuedStateIdentifier<States>> = (context: StateUpdateResolveContext<States, Context, Owner> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateUpdate<States, Owner> | Declined;
|
|
3790
3623
|
/** One named destination declared by a branching transition. */
|
|
3791
3624
|
interface TransitionBranchInput<Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>> {
|
|
3792
3625
|
/** Exact topology destination available to the branching resolver. */
|
|
@@ -3801,13 +3634,23 @@ export declare namespace Machine {
|
|
|
3801
3634
|
readonly result: Types.Covariant<Result>;
|
|
3802
3635
|
};
|
|
3803
3636
|
}
|
|
3637
|
+
type CompletedBranchResult<R> = R extends {
|
|
3638
|
+
readonly update: unknown;
|
|
3639
|
+
} ? R extends UpdatingStateConstruction<infer Target, infer S, infer Owner> ? CombinedTarget<UnwrapConstruction<Target>, S, Owner> : R : R;
|
|
3640
|
+
type SelectedConstruction<K extends string, R> = R extends {
|
|
3641
|
+
readonly update: unknown;
|
|
3642
|
+
} ? R extends UpdatingStateConstruction<infer Target, infer S, infer Owner> ? {
|
|
3643
|
+
readonly update: SelectedBranchBuilder<StateUpdateBuilder<S, Owner>, K> extends infer B ? {
|
|
3644
|
+
readonly [M in keyof B]: StateUpdateBuilder<S, Owner>[Extract<M, keyof StateUpdateBuilder<S, Owner>>] extends (...args: infer A) => unknown ? (...args: A) => SelectedBranch<K, CombinedTarget<UnwrapConstruction<Target>, S, Owner>> : never;
|
|
3645
|
+
} : never;
|
|
3646
|
+
} : SelectedBranch<K, R> : SelectedBranch<K, R>;
|
|
3804
3647
|
type SelectedBranchCallable<Callable, Key extends string> = Callable extends {
|
|
3805
3648
|
(...args: infer Arguments1): infer Result1;
|
|
3806
3649
|
(...args: infer Arguments2): infer Result2;
|
|
3807
3650
|
} ? {
|
|
3808
|
-
(...args: Arguments1):
|
|
3809
|
-
(...args: Arguments2):
|
|
3810
|
-
} : Callable extends (...args: infer Arguments) => infer Result ? (...args: Arguments) =>
|
|
3651
|
+
(...args: Arguments1): SelectedConstruction<Key, Result1>;
|
|
3652
|
+
(...args: Arguments2): SelectedConstruction<Key, Result2>;
|
|
3653
|
+
} : Callable extends (...args: infer Arguments) => infer Result ? (...args: Arguments) => SelectedConstruction<Key, Result> : {};
|
|
3811
3654
|
type SelectedBranchBuilderProperties<Builder, Key extends string> = {
|
|
3812
3655
|
readonly [Property in keyof Builder]: Builder[Property] extends (...args: any) => any ? SelectedBranchCallable<Builder[Property], Key> : Builder[Property];
|
|
3813
3656
|
};
|
|
@@ -3817,223 +3660,17 @@ export declare namespace Machine {
|
|
|
3817
3660
|
readonly [Key in Extract<keyof Branches, string>]: SelectedBranchBuilder<SelectionBuilder<Branches[Key]["target"]>, Key>;
|
|
3818
3661
|
};
|
|
3819
3662
|
type BranchSelectionResult<Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
|
|
3820
|
-
readonly [Key in Extract<keyof Branches, string>]: SelectedBranch<Key, SelectedTargetResult<Branches[Key]["target"]
|
|
3663
|
+
readonly [Key in Extract<keyof Branches, string>]: SelectedBranch<Key, CompletedBranchResult<SelectedTargetResult<Branches[Key]["target"]>>>;
|
|
3821
3664
|
}[Extract<keyof Branches, string>];
|
|
3822
3665
|
type TransitionBranchesResolveContext<Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = Omit<Context, "target"> & {
|
|
3823
3666
|
readonly select: BranchSelectors<Branches>;
|
|
3824
3667
|
};
|
|
3825
|
-
type TransitionBranchesResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = (context: TransitionBranchesResolveContext<Context, Branches>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => BranchSelectionResult<Branches>;
|
|
3826
|
-
type DeclinableTransitionBranchesResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = (context: TransitionBranchesResolveContext<Context, Branches> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => BranchSelectionResult<Branches> | Declined;
|
|
3827
|
-
/** @internal Type evidence retained by a transition authored through its bound selector. */
|
|
3828
|
-
interface TransitionBuilderEvidence<out Result, out Acceptance extends TransitionAcceptance> {
|
|
3829
|
-
readonly [TransitionBuilderTypeId]: {
|
|
3830
|
-
readonly result: Types.Covariant<Result>;
|
|
3831
|
-
readonly acceptance: Types.Covariant<Acceptance>;
|
|
3832
|
-
};
|
|
3833
|
-
}
|
|
3834
|
-
type TransitionRequiredOptions = {
|
|
3835
|
-
/** Keeps the transition required. The resolver cannot return `decline()`. */
|
|
3836
|
-
readonly declinable?: false;
|
|
3837
|
-
readonly reenter?: never;
|
|
3838
|
-
};
|
|
3839
|
-
type TransitionDeclinableOptions = {
|
|
3840
|
-
/** Adds `decline()` to the resolver context and permits declining this candidate. */
|
|
3841
|
-
readonly declinable: true;
|
|
3842
|
-
readonly reenter?: never;
|
|
3843
|
-
};
|
|
3844
|
-
type BuiltTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Result, Acceptance extends TransitionAcceptance> = TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<Result, Acceptance>;
|
|
3845
|
-
interface TransitionResolveRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> {
|
|
3846
|
-
(resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required">;
|
|
3847
|
-
}
|
|
3848
|
-
interface TransitionResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> {
|
|
3849
|
-
(resolve: DeclinableTransitionResolver<Events, Emits, Context, Selection>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined, "declinable">;
|
|
3850
|
-
}
|
|
3851
|
-
type ConstructionCallbacks<Context, Builder, Result> = {
|
|
3852
|
-
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;
|
|
3853
|
-
};
|
|
3854
|
-
type GuardedTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, any>> = ConstructionCallbacks<Omit<Context, "target">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">> & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable"> : {}) & {
|
|
3855
|
-
readonly resolve: (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
|
|
3856
|
-
};
|
|
3857
|
-
/**
|
|
3858
|
-
* A selected transition target with target-specific resolver operations.
|
|
3859
|
-
*
|
|
3860
|
-
* **Example** (Constructing state while reentering)
|
|
3861
|
-
*
|
|
3862
|
-
* ```ts
|
|
3863
|
-
* Reset: (to) =>
|
|
3864
|
-
* to.branch.Ready().reenter().from(({ event }) => ({ count: event.count }))
|
|
3865
|
-
* ```
|
|
3866
|
-
*
|
|
3867
|
-
* @inlineType TransitionRequiredOptions
|
|
3868
|
-
* @inlineType TransitionDeclinableOptions
|
|
3869
|
-
*/
|
|
3870
|
-
type TransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, any>> = Selection & ("declinable" extends Acceptance ? {
|
|
3871
|
-
/** Declines this candidate before construction when the predicate is false. */
|
|
3872
|
-
readonly guard: (predicate: (context: Omit<Context, "target">) => boolean) => GuardedTransition<States, Events, Emits, StateId, Context, Reenter, Selection>;
|
|
3873
|
-
} : {}) & ConstructionCallbacks<Omit<Context, "target">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & (SelectionSupportsDefaultConstruction<Selection> extends true ? BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined, "required"> : {}) & {
|
|
3874
|
-
/** Evaluates state construction after this transition is selected. */
|
|
3875
|
-
readonly resolve: TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? TransitionResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
|
|
3876
|
-
} & ([Reenter] extends [true] ? {
|
|
3877
|
-
/** Forces source exit and entry, preserving subsequent construction and guards. */
|
|
3878
|
-
readonly reenter: () => Omit<TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>, typeof Topology.TargetSelectionTypeId>;
|
|
3879
|
-
} : {}) & (SelectionKind<Selection> extends "state" ? SelectionScope<Selection> extends "local" | "branch" ? RetainedUpdateOwner<States, StateId, Selection> extends infer Owner extends ValuedStateIdentifier<States> ? [
|
|
3880
|
-
Owner
|
|
3881
|
-
] extends [never] ? {} : {
|
|
3882
|
-
/** Declares one valued owner retained by the selected topology. */
|
|
3883
|
-
readonly updating: <SelectedOwner extends Owner>(owner: RetainedOwnerSelector<SelectedOwner>) => UpdatingTransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection, SelectedOwner>;
|
|
3884
|
-
} : {} : {} : {});
|
|
3885
|
-
type UpdatingConstructionCallbacks<Context, Builder, OwnerBuilder, Result> = {
|
|
3886
|
-
readonly [Method in Extract<keyof Builder & keyof OwnerBuilder, "from" | "decoded"> as Builder[Method] extends (...args: infer Args) => unknown ? Args extends readonly [unknown?] ? Method : never : never]: Builder[Method] extends (...args: infer Args) => unknown ? OwnerBuilder[Method] extends (value: infer Update) => unknown ? (construct: (context: Context) => {
|
|
3887
|
-
readonly target: Args[0];
|
|
3888
|
-
readonly update: Update;
|
|
3889
|
-
}) => Result : never : never;
|
|
3890
|
-
};
|
|
3891
|
-
type UpdatingCallbacks<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>, Acceptance extends TransitionAcceptance> = UpdatingConstructionCallbacks<Omit<UpdatingTransitionResolveContext<States, Context, Selection, Owner>, "owner" | "target">, SelectionBuilder<Selection>, StateUpdateBuilder<States, Owner>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | (Acceptance extends "declinable" ? Declined : never), Acceptance>>;
|
|
3892
|
-
type GuardedUpdatingTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>> = UpdatingCallbacks<States, Events, Emits, StateId, Context, Reenter, Selection, Owner, "declinable"> & {
|
|
3893
|
-
readonly resolve: (resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable">;
|
|
3894
|
-
};
|
|
3895
|
-
/**
|
|
3896
|
-
* A topology selection that requires one retained owner replacement.
|
|
3897
|
-
*
|
|
3898
|
-
* `.from` constructs both values from schema inputs; `.decoded` accepts both
|
|
3899
|
-
* decoded values. Both callbacks return `{ target, update }` and read the same
|
|
3900
|
-
* pre-transition snapshot. Use `.resolve` for explicit child construction,
|
|
3901
|
-
* mixed construction methods, or queued commands.
|
|
3902
|
-
*
|
|
3903
|
-
* **Example** (Guarding an atomic destination and owner update)
|
|
3904
|
-
*
|
|
3905
|
-
* ```ts
|
|
3906
|
-
* Save: (to) => to.local.Saving().updating(to.root)
|
|
3907
|
-
* .guard(({ current }) => current.draft.length > 0)
|
|
3908
|
-
* .from(({ current }) => ({
|
|
3909
|
-
* target: { text: current.draft },
|
|
3910
|
-
* update: { ...current, attempts: current.attempts + 1 }
|
|
3911
|
-
* }))
|
|
3912
|
-
* ```
|
|
3913
|
-
*/
|
|
3914
|
-
type UpdatingTransitionTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, "state">, Owner extends ValuedStateIdentifier<States>> = Selection & UpdatingCallbacks<States, Events, Emits, StateId, Context, Reenter, Selection, Owner, "required"> & ([Reenter] extends [true] ? {
|
|
3915
|
-
readonly reenter: () => Omit<UpdatingTransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection, Owner>, typeof Topology.TargetSelectionTypeId>;
|
|
3916
|
-
} : {}) & ("declinable" extends Acceptance ? {
|
|
3917
|
-
/** Declines before either value is constructed or any commands are enqueued. */
|
|
3918
|
-
readonly guard: (predicate: (context: Omit<UpdatingTransitionResolveContext<States, Context, Selection, Owner>, "owner" | "target">) => boolean) => GuardedUpdatingTransition<States, Events, Emits, StateId, Context, Reenter, Selection, Owner>;
|
|
3919
|
-
} : {}) & {
|
|
3920
|
-
/** @internal */
|
|
3921
|
-
readonly "~effect/Machine/UpdatingTransitionTarget": Owner;
|
|
3922
|
-
readonly resolve: ((resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, "required">) & ("declinable" extends Acceptance ? (resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner> & DeclineCapability, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, options: TransitionDeclinableOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable"> : {});
|
|
3923
|
-
};
|
|
3924
|
-
/** @internal */
|
|
3925
|
-
interface StateUpdateTransitionRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> {
|
|
3926
|
-
(resolve: StateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">;
|
|
3927
|
-
}
|
|
3928
|
-
/** @internal */
|
|
3929
|
-
interface StateUpdateTransitionDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> {
|
|
3930
|
-
(resolve: DeclinableStateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
|
|
3931
|
-
}
|
|
3932
|
-
type GuardedStateUpdateTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Selection extends TargetSelection<any, any, "update">> = ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">> & {
|
|
3933
|
-
readonly resolve: (resolve: StateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options?: TransitionRequiredOptions) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
|
|
3934
|
-
};
|
|
3935
|
-
/** @internal */
|
|
3936
|
-
type StateUpdateTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Selection extends TargetSelection<any, any, "update">> = Selection & ([Reenter] extends [true] ? {
|
|
3937
|
-
/** Reenters the source while updating its retained valued ancestor. */
|
|
3938
|
-
readonly reenter: () => Omit<StateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>, typeof Topology.TargetSelectionTypeId>;
|
|
3939
|
-
} : {}) & ("declinable" extends Acceptance ? {
|
|
3940
|
-
/** Declines before replacing the selected owner value. */
|
|
3941
|
-
readonly guard: (predicate: (context: Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">) => boolean) => GuardedStateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Selection>;
|
|
3942
|
-
} : {}) & ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & {
|
|
3943
|
-
readonly resolve: StateUpdateTransitionRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? StateUpdateTransitionDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
|
|
3944
|
-
};
|
|
3945
|
-
/** @internal Type evidence retained by a machine initial-entry declaration. */
|
|
3946
|
-
interface InitialBuilderEvidence<out Selection> {
|
|
3947
|
-
readonly [InitialBuilderTypeId]: Types.Covariant<Selection>;
|
|
3948
|
-
}
|
|
3949
|
-
/** Decoded input shared by initial construction callbacks. */
|
|
3950
|
-
interface InitialContext<Input> {
|
|
3951
|
-
/** Decoded value supplied when the machine is started. */
|
|
3952
|
-
readonly input: Input;
|
|
3953
|
-
}
|
|
3954
|
-
/** A selected machine initial entry with its exact resolver target. */
|
|
3955
|
-
type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> = Selection & ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<Selection>, InitialBuilderEvidence<Selection>> & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {}) & {
|
|
3956
|
-
/** Lazily constructs the selected initial state from decoded machine input. */
|
|
3957
|
-
readonly resolve: (resolve: (context: {
|
|
3958
|
-
/** Decoded value supplied when the machine is started. */
|
|
3959
|
-
readonly input: Input;
|
|
3960
|
-
/** Builder specialized to the selected initial destination. */
|
|
3961
|
-
readonly target: SelectionBuilder<Selection>;
|
|
3962
|
-
}) => SelectedTargetResult<Selection>) => InitialBuilderEvidence<Selection>;
|
|
3963
|
-
};
|
|
3964
|
-
type InitialSelectorNode<Input, Node> = Node extends (...args: infer Args) => infer Selection ? Selection extends TargetSelection<any, any, any> ? ((...args: Args) => InitialTransitionTarget<Input, Selection>) & {
|
|
3965
|
-
readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>;
|
|
3966
|
-
} : never : Node extends TargetSelection<any, any, any> ? InitialTransitionTarget<Input, Node> : {
|
|
3967
|
-
readonly [Key in keyof Node]: InitialSelectorNode<Input, Node[Key]>;
|
|
3968
|
-
};
|
|
3969
|
-
/** Definition-time selector for a machine's top-level initial entry. */
|
|
3970
|
-
type InitialSelector<States extends StateSchemas, Input = void> = InitialSelectorNode<Input, InitialTargetSelector<States>>;
|
|
3971
|
-
/** Target-first initial-entry declaration accepted by {@link make}. */
|
|
3972
|
-
type InitialBuilderInput<States extends StateSchemas, Input> = (to: InitialSelector<States, Input>) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3973
|
-
/** Initializes the root and its declared default descendants. */
|
|
3974
|
-
type RootInitialBuilderInput<Root extends StateNodeConfig, Input> = (root: InitialTransitionTarget<Input, SelectionValue<InitialTargetFactory<Root, "">, "", "initial", "initial">>) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3975
|
-
interface RootConfigurationSelection<in out Root extends StateNodeConfig> extends TargetSelection<FullSnapshotMethod<{
|
|
3976
|
-
readonly "": Root;
|
|
3977
|
-
}, "" & ActiveStateKey<{
|
|
3978
|
-
readonly "": Root;
|
|
3979
|
-
}>, "">, "", "state", "initial"> {
|
|
3980
|
-
}
|
|
3981
|
-
/** Explicitly constructs a complete starting configuration. */
|
|
3982
|
-
type RootConfigurationBuilderInput<Root extends StateNodeConfig, Input> = (root: ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<RootConfigurationSelection<Root>>, InitialBuilderEvidence<RootConfigurationSelection<Root>>> & {
|
|
3983
|
-
readonly resolve: (resolve: (context: {
|
|
3984
|
-
/** Decoded startup input. */
|
|
3985
|
-
readonly input: Input;
|
|
3986
|
-
/** Builder for the complete root configuration. */
|
|
3987
|
-
readonly target: SelectionBuilder<RootConfigurationSelection<Root>>;
|
|
3988
|
-
}) => ConstructionResult<Snapshot<{
|
|
3989
|
-
readonly "": Root;
|
|
3990
|
-
}>>) => InitialBuilderEvidence<RootConfigurationSelection<Root>>;
|
|
3991
|
-
}) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3992
|
-
type TransitionSelectorNode<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Node> = Node extends TargetSelection<any, any, "update"> ? StateUpdateTransition<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node> : Node extends (...args: infer Args) => infer Selection ? Selection extends TargetSelection<any, any, any> ? ((...args: Args) => TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Selection>) & {
|
|
3993
|
-
readonly [Key in keyof Node]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node[Key]>;
|
|
3994
|
-
} : never : Node extends TargetSelection<any, any, any> ? TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node> : {
|
|
3995
|
-
readonly [Key in keyof Node]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node[Key]>;
|
|
3996
|
-
};
|
|
3997
|
-
interface TransitionBranchesResolveRequired<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Branches extends Readonly<Record<string, TransitionBranchInput>>> {
|
|
3998
|
-
(resolve: TransitionBranchesResolver<Events, Emits, Context, Branches>, options?: TransitionRequiredOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches>, "required">;
|
|
3999
|
-
}
|
|
4000
|
-
interface TransitionBranchesResolveDeclinable<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Branches extends Readonly<Record<string, TransitionBranchInput>>> {
|
|
4001
|
-
(resolve: DeclinableTransitionBranchesResolver<Events, Emits, Context, Branches>, options: TransitionDeclinableOptions): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches> | Declined, "declinable">;
|
|
4002
|
-
}
|
|
4003
|
-
type TransitionSelectorTargets<in out States extends StateSchemas, in out Events extends ReadonlyArray<TaggedSchema>, in out Emits extends ReadonlyArray<TaggedSchema>, in out StateId extends StateNodeIdentifier<States>, in out Context, in out Reenter extends boolean, in out Acceptance extends TransitionAcceptance> = {
|
|
4004
|
-
readonly [Key in keyof TargetSelector<States, StateId>]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Key extends "self" ? false : Reenter, Acceptance, TargetSelector<States, StateId>[Key]>;
|
|
4005
|
-
};
|
|
4006
|
-
type TransitionBranchesTarget<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance, Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
|
|
4007
|
-
/** Resolves exactly one declared branch after this transition is selected. */
|
|
4008
|
-
readonly resolve: TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches> & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Branches> : {});
|
|
4009
|
-
} & ([Reenter] extends [true] ? {
|
|
4010
|
-
readonly reenter: () => TransitionBranchesTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Branches>;
|
|
4011
|
-
} : {});
|
|
4012
|
-
/** Selector supplied to inline transition declarations. */
|
|
4013
|
-
interface TransitionSelector<in out States extends StateSchemas, in out Events extends ReadonlyArray<TaggedSchema>, in out Emits extends ReadonlyArray<TaggedSchema>, in out StateId extends StateNodeIdentifier<States>, in out Context, in out Reenter extends boolean, in out Acceptance extends TransitionAcceptance> extends TransitionSelectorTargets<States, Events, Emits, StateId, Context, Reenter, Acceptance> {
|
|
4014
|
-
/** Declares a closed set of named destinations for one resolver. */
|
|
4015
|
-
readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>) => TransitionBranchesTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Branches>;
|
|
4016
|
-
}
|
|
4017
|
-
/** Inline transition declaration accepted by state and invocation handlers. */
|
|
4018
|
-
type TransitionBuilderInput<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean, Acceptance extends TransitionAcceptance> = (to: TransitionSelector<States, Events, Emits, StateId, Context, Reenter, Acceptance>) => TransitionTyped<States, Events, Emits, StateId, Context, Reenter, Acceptance> & TransitionBuilderEvidence<any, Acceptance>;
|
|
4019
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>;
|
|
4020
3669
|
type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
4021
3670
|
/** Inline state-owned work that runs for the lifetime of its active state. */
|
|
4022
3671
|
interface InvokeOwned<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 []> {
|
|
4023
3672
|
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId, InputEvents, ParentEvents]>;
|
|
4024
3673
|
}
|
|
4025
|
-
/** Type evidence retained by a completed state-owned invocation. */
|
|
4026
|
-
interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never, Outcomes = never> {
|
|
4027
|
-
readonly [InvokeTypeId]: {
|
|
4028
|
-
readonly output: Types.Covariant<Output>;
|
|
4029
|
-
readonly error: Types.Covariant<Error>;
|
|
4030
|
-
readonly requirements: Types.Covariant<Requirements>;
|
|
4031
|
-
readonly initialError: Types.Covariant<InitialError>;
|
|
4032
|
-
readonly emits: Types.Covariant<Emits>;
|
|
4033
|
-
readonly parentEvents: Types.Covariant<ParentEvent>;
|
|
4034
|
-
readonly outcomes: Types.Covariant<Outcomes>;
|
|
4035
|
-
};
|
|
4036
|
-
}
|
|
4037
3674
|
type StoredInvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & ({
|
|
4038
3675
|
readonly id: string;
|
|
4039
3676
|
readonly effect: (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<any, any, any>;
|
|
@@ -4111,137 +3748,6 @@ export declare namespace Machine {
|
|
|
4111
3748
|
type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>;
|
|
4112
3749
|
type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>;
|
|
4113
3750
|
type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>;
|
|
4114
|
-
type RequiredInvokeChannel<Value, Channel extends string> = IsAny<Value> extends true ? Channel : [Value] extends [never] ? never : Channel;
|
|
4115
|
-
type InvokeBuilderResult<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & InvokeTyped<Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> & {
|
|
4116
|
-
readonly [InvokeBuilderTypeId]: true;
|
|
4117
|
-
};
|
|
4118
|
-
/** Lifecycle handlers exposed according to the selected invocation source. */
|
|
4119
|
-
type InvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Pending extends string, SnapshotHandler, Outcomes = never> = ([Pending] extends [never] ? InvokeBuilderResult<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Outcomes> : {}) & ("done" extends Pending ? {
|
|
4120
|
-
/** Handles successful completion and exposes the invocation output. */
|
|
4121
|
-
readonly onDone: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeDoneContext<States, Events, Emits, StateId, Output, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "done">, SnapshotHandler, Outcomes | Handler>;
|
|
4122
|
-
} : {}) & ("failure" extends Pending ? {
|
|
4123
|
-
/** Handles typed failure and exposes the invocation error. */
|
|
4124
|
-
readonly onFailure: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeFailureContext<States, Events, Emits, StateId, Error, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "failure">, SnapshotHandler, Outcomes | Handler>;
|
|
4125
|
-
} : {}) & ("element" extends Pending ? {
|
|
4126
|
-
/** Handles each backpressured element emitted by an invoked Stream. */
|
|
4127
|
-
readonly onElement: <const Handler extends InvokeTransition<States, Events, Emits, StateId, InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>>>(handler: Handler & InvokeTransition<States, Events, Emits, StateId, InvokeElementContext<States, Events, Emits, StateId, Element, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Exclude<Pending, "element">, SnapshotHandler, Outcomes | Handler>;
|
|
4128
|
-
} : {}) & ([SnapshotHandler] extends [never] ? {} : {
|
|
4129
|
-
/** Handles each active snapshot published by invoked logic or a child machine. */
|
|
4130
|
-
readonly onSnapshot: <const Handler extends SnapshotHandler>(handler: Handler & SnapshotHandler) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output, Error, Requirements, InitialError, ChildEmits, ChildParentEvent, Element, Pending, never, Outcomes | Handler>;
|
|
4131
|
-
});
|
|
4132
|
-
type EffectInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Source extends (...args: ReadonlyArray<any>) => Effect.Effect<any, any, any>> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never, never, never, never, RequiredInvokeChannel<Effect.Success<ReturnType<Source>>, "done"> | RequiredInvokeChannel<Effect.Error<ReturnType<Source>>, "failure">, never>;
|
|
4133
|
-
type StreamInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Source extends (...args: ReadonlyArray<any>) => Stream.Stream<any, any, any>> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, void, Stream.Error<ReturnType<Source>>, Stream.Services<ReturnType<Source>>, never, never, never, Stream.Success<ReturnType<Source>>, "done" | RequiredInvokeChannel<Stream.Success<ReturnType<Source>>, "element"> | RequiredInvokeChannel<Stream.Error<ReturnType<Source>>, "failure">, never>;
|
|
4134
|
-
type LogicInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, ChildLogic> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, LogicOutputOf<ChildLogic>, LogicErrorOf<ChildLogic>, LogicServicesOf<ChildLogic>, LogicInitialErrorOf<ChildLogic>, never, never, never, RequiredInvokeChannel<LogicOutputOf<ChildLogic>, "done"> | RequiredInvokeChannel<LogicErrorOf<ChildLogic>, "failure">, InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, LogicStateOf<ChildLogic>, LogicErrorOf<ChildLogic>, LogicOutputOf<ChildLogic>, InputEvents, ParentEvents>>>;
|
|
4135
|
-
type ChildInvokeBuilder<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Child extends ChildMachine.Any, ChildDefinition extends Machine.Any = Child["machine"]> = InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Output<ChildDefinition>, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, Services<ChildDefinition>, InitialError<ChildDefinition>, EmittedEvent<ChildDefinition>, EventOf<Machine.ParentEvents<ChildDefinition>>, never, RequiredInvokeChannel<Output<ChildDefinition>, "done"> | RequiredInvokeChannel<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, "failure">, InvokeTransition<States, Events, Emits, StateId, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>, InputEvents, ParentEvents>>>;
|
|
4136
|
-
/**
|
|
4137
|
-
* Selects state-owned work and begins its lifecycle-handler chain.
|
|
4138
|
-
*
|
|
4139
|
-
* Each source exposes exactly the lifecycle methods that it can produce. A
|
|
4140
|
-
* chain becomes returnable from `invoke` only after every reachable required
|
|
4141
|
-
* channel has been handled.
|
|
4142
|
-
*
|
|
4143
|
-
* **Example** (Invoking an Effect)
|
|
4144
|
-
*
|
|
4145
|
-
* ```ts
|
|
4146
|
-
* invoke: (from) =>
|
|
4147
|
-
* from.effect("load-user", () => loadUser).onDone((to) =>
|
|
4148
|
-
* to.branch.Ready().resolve(({ output, target }) => target.from({ user: output }))
|
|
4149
|
-
* ).onFailure((to) =>
|
|
4150
|
-
* to.branch.Failed().resolve(({ error, target }) => target.from({ error }))
|
|
4151
|
-
* )
|
|
4152
|
-
* ```
|
|
4153
|
-
*
|
|
4154
|
-
* @inlineType EffectInvokeBuilder
|
|
4155
|
-
* @inlineType StreamInvokeBuilder
|
|
4156
|
-
* @inlineType LogicInvokeBuilder
|
|
4157
|
-
* @inlineType ChildInvokeBuilder
|
|
4158
|
-
* @inlineType InvokeBuilder
|
|
4159
|
-
*
|
|
4160
|
-
* @category models
|
|
4161
|
-
* @since 0.18.0
|
|
4162
|
-
*/
|
|
4163
|
-
interface InvokeSelector<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 []> {
|
|
4164
|
-
/**
|
|
4165
|
-
* Starts a fresh Effect each time the owning state is entered.
|
|
4166
|
-
*
|
|
4167
|
-
* @param id Parent-local lifecycle identifier.
|
|
4168
|
-
* @param source Lazy Effect factory evaluated on every entry.
|
|
4169
|
-
*/
|
|
4170
|
-
readonly effect: <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Effect.Effect<unknown, unknown, unknown>>(id: InvokeLifecycleId, source: Source) => EffectInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
4171
|
-
/**
|
|
4172
|
-
* Starts a fresh, backpressured Stream each time the owning state is entered.
|
|
4173
|
-
*
|
|
4174
|
-
* @param id Parent-local lifecycle identifier.
|
|
4175
|
-
* @param source Lazy Stream factory evaluated on every entry.
|
|
4176
|
-
*/
|
|
4177
|
-
readonly stream: <const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => Stream.Stream<unknown, unknown, any>>(id: InvokeLifecycleId, source: Source) => StreamInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
4178
|
-
/**
|
|
4179
|
-
* Starts a cancellable state-scoped timer.
|
|
4180
|
-
*
|
|
4181
|
-
* @param id Parent-local lifecycle identifier.
|
|
4182
|
-
* @param duration Duration input or context-dependent duration factory.
|
|
4183
|
-
*/
|
|
4184
|
-
readonly timer: (id: InvokeLifecycleId, duration: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>) => InvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, void, never, never, never, never, never, never, "done", never>;
|
|
4185
|
-
/**
|
|
4186
|
-
* Starts reusable process logic at a typed parent-local address.
|
|
4187
|
-
*
|
|
4188
|
-
* @param id Parent-local lifecycle identifier.
|
|
4189
|
-
* @param options Address and reusable logic value or factory.
|
|
4190
|
-
*/
|
|
4191
|
-
readonly logic: {
|
|
4192
|
-
<const Source extends (context: InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>) => unknown, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
|
|
4193
|
-
/** Typed parent-local address used to send events to this logic. */
|
|
4194
|
-
readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<ReturnType<NoInfer<Source>>>>;
|
|
4195
|
-
/** Context-dependent factory that returns reusable process logic. */
|
|
4196
|
-
readonly logic: Source;
|
|
4197
|
-
}, ..._validation: ReturnType<Source> extends {
|
|
4198
|
-
readonly initial: unknown;
|
|
4199
|
-
readonly run: unknown;
|
|
4200
|
-
} ? [] : [
|
|
4201
|
-
"logic factory must return Machine.Logic"
|
|
4202
|
-
]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, ReturnType<Source>>;
|
|
4203
|
-
<const Source, Address extends ChildAddress<never>>(id: InvokeLifecycleId, options: {
|
|
4204
|
-
/** Typed parent-local address used to send events to this logic. */
|
|
4205
|
-
readonly address: Address & ChildAddress.Compatibility<Address, LogicEventOf<NoInfer<Source>>>;
|
|
4206
|
-
/** Reusable process logic started when the owning state enters. */
|
|
4207
|
-
readonly logic: Source;
|
|
4208
|
-
}, ..._validation: Source extends {
|
|
4209
|
-
readonly initial: unknown;
|
|
4210
|
-
readonly run: unknown;
|
|
4211
|
-
} ? [] : [
|
|
4212
|
-
"logic must implement Machine.Logic"
|
|
4213
|
-
]): LogicInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Source>;
|
|
4214
|
-
};
|
|
4215
|
-
/**
|
|
4216
|
-
* Starts a complete child statechart represented by a reusable descriptor.
|
|
4217
|
-
*
|
|
4218
|
-
* @param child Reusable descriptor created with `Machine.child`.
|
|
4219
|
-
* @param options Input construction for a child with a non-void input schema.
|
|
4220
|
-
*/
|
|
4221
|
-
readonly child: <const Child extends ChildMachine.Any>(child: Child & (Child["machine"] extends EnsureExecutable<Machine.States<Child["machine"]>, Machine.UnhandledStates<Child["machine"]>, Machine.OutputStates<Child["machine"]>> ? unknown : never), ...options: InputSchema<Child["machine"]> extends typeof Schema.Void ? [options?: {
|
|
4222
|
-
readonly input?: never;
|
|
4223
|
-
}] : [
|
|
4224
|
-
options: {
|
|
4225
|
-
/** Child input value or factory evaluated from the owning state context. */
|
|
4226
|
-
readonly input: InvokeSource<Input<Child["machine"]>, InvokeContext<States, Events, Emits, StateId, InputEvents, ParentEvents>>;
|
|
4227
|
-
}
|
|
4228
|
-
]) => ChildInvokeBuilder<States, Events, Emits, StateId, InputEvents, ParentEvents, Child>;
|
|
4229
|
-
}
|
|
4230
|
-
/**
|
|
4231
|
-
* Inline invocation declaration accepted by an active state handler.
|
|
4232
|
-
*
|
|
4233
|
-
* Return one completed source chain or an array of completed chains. Source
|
|
4234
|
-
* computations and child descriptors may be extracted, but the chain stays
|
|
4235
|
-
* local to preserve the owning state and machine protocols.
|
|
4236
|
-
*
|
|
4237
|
-
* @category models
|
|
4238
|
-
* @since 0.18.0
|
|
4239
|
-
*/
|
|
4240
|
-
type InvokeBuilderInput<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 []> = (from: InvokeSelector<States, Events, Emits, StateId, InputEvents, ParentEvents>) => (InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
|
|
4241
|
-
readonly [InvokeBuilderTypeId]: true;
|
|
4242
|
-
}) | ReadonlyArray<InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & {
|
|
4243
|
-
readonly [InvokeBuilderTypeId]: true;
|
|
4244
|
-
}>;
|
|
4245
3751
|
/** Output construction available to final and output-producing parallel states. */
|
|
4246
3752
|
type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
4247
3753
|
readonly output: Schema.Top;
|
|
@@ -4256,107 +3762,6 @@ export declare namespace Machine {
|
|
|
4256
3762
|
} ? OutputHandlerConfig<States, Events, StateId, ParallelOutputContext<States, Events, StateId>> : {
|
|
4257
3763
|
readonly output?: never;
|
|
4258
3764
|
};
|
|
4259
|
-
/**
|
|
4260
|
-
* Configuration accepted for a non-final state.
|
|
4261
|
-
*
|
|
4262
|
-
* **Example** (State actions, events, and invocation)
|
|
4263
|
-
*
|
|
4264
|
-
* ```ts
|
|
4265
|
-
* machine.handle({ states: {
|
|
4266
|
-
* Loading: {
|
|
4267
|
-
* entry: (_, enqueue) => enqueue.emit({ _tag: "Started" }),
|
|
4268
|
-
* invoke: (from) =>
|
|
4269
|
-
* from.effect("load", () => load).onDone((to) => to.branch.Ready()),
|
|
4270
|
-
* on: { Cancel: (to) => to.branch.Idle() }
|
|
4271
|
-
* }
|
|
4272
|
-
* } })
|
|
4273
|
-
* ```
|
|
4274
|
-
*
|
|
4275
|
-
* @inlineType ActiveOutputHandlerConfig
|
|
4276
|
-
* @inlineType OutputHandlerConfig
|
|
4277
|
-
*
|
|
4278
|
-
* @category models
|
|
4279
|
-
* @since 0.4.0
|
|
4280
|
-
*/
|
|
4281
|
-
type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = {
|
|
4282
|
-
/** Runs synchronously when the state is entered and may enqueue commands. */
|
|
4283
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4284
|
-
/** Runs synchronously before the state is exited and may enqueue commands. */
|
|
4285
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4286
|
-
/** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
|
|
4287
|
-
readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
4288
|
-
/** Eventless transition evaluated after the state becomes stable. */
|
|
4289
|
-
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
|
|
4290
|
-
/** Transition evaluated after this compound or parallel state completes. */
|
|
4291
|
-
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, false, TransitionAcceptance>;
|
|
4292
|
-
/** Event handlers keyed by the `_tag` of the machine's public or internal events. */
|
|
4293
|
-
readonly on?: {
|
|
4294
|
-
readonly [EventTag in TagOf<Events[number]>]?: TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, true, TransitionAcceptance>;
|
|
4295
|
-
};
|
|
4296
|
-
/** Supplies missing direct initial-child values required by implicit entry and shallow history. */
|
|
4297
|
-
readonly initialize?: StateInitializeHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
4298
|
-
} & ActiveOutputHandlerConfig<States, Events, StateId>;
|
|
4299
|
-
/**
|
|
4300
|
-
* Values constructed for a state's schema-valued direct initial children.
|
|
4301
|
-
*
|
|
4302
|
-
* @category utility types
|
|
4303
|
-
* @since 0.13.0
|
|
4304
|
-
*/
|
|
4305
|
-
type StateInitializeValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
4306
|
-
readonly type: "parallel";
|
|
4307
|
-
readonly states: infer Children extends StateSchemas;
|
|
4308
|
-
} ? {
|
|
4309
|
-
readonly [Key in ActiveStateKey<Children> as NodeSchema<Children[Key]> extends never ? never : Key]: NodeValue<Children[Key]>;
|
|
4310
|
-
} : Node extends {
|
|
4311
|
-
readonly states: infer Children extends StateSchemas;
|
|
4312
|
-
readonly initial: infer Initial;
|
|
4313
|
-
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : {
|
|
4314
|
-
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
4315
|
-
} : never : never : never;
|
|
4316
|
-
type StateInitializeCompoundBuilder<Node, Initial extends PropertyKey> = Node extends {
|
|
4317
|
-
readonly states: infer Children extends StateSchemas;
|
|
4318
|
-
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : NodeBuilderMethod<Children[Initial], readonly [value: NodeValue<Children[Initial]>], SnapshotBuilderComplete<{
|
|
4319
|
-
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
4320
|
-
}>, readonly [input: NodeMakeInput<Children[Initial]>], SnapshotBuilderComplete<{
|
|
4321
|
-
readonly [Key in Initial]: NodeValue<Children[Initial]>;
|
|
4322
|
-
}, true>> : never : never;
|
|
4323
|
-
type StateInitializeParallelBuilder<Children extends StateSchemas, Remaining extends ActiveStateKey<Children> = {
|
|
4324
|
-
readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]> extends never ? never : Key;
|
|
4325
|
-
}[ActiveStateKey<Children>], Values = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Values, Constructed> & {
|
|
4326
|
-
readonly [Key in Remaining]: NodeBuilderMethod<Children[Key], readonly [value: NodeValue<Children[Key]>], StateInitializeParallelBuilder<Children, Exclude<Remaining, Key>, Values & {
|
|
4327
|
-
readonly [Region in Key]: NodeValue<Children[Key]>;
|
|
4328
|
-
}, Constructed>, readonly [input: NodeMakeInput<Children[Key]>], StateInitializeParallelBuilder<Children, Exclude<Remaining, Key>, Values & {
|
|
4329
|
-
readonly [Region in Key]: NodeValue<Children[Key]>;
|
|
4330
|
-
}, true>>;
|
|
4331
|
-
};
|
|
4332
|
-
/**
|
|
4333
|
-
* Builder bound to the direct initial child or regions owned by a state.
|
|
4334
|
-
*
|
|
4335
|
-
* @category utility types
|
|
4336
|
-
* @since 0.13.0
|
|
4337
|
-
*/
|
|
4338
|
-
type StateInitializeBuilder<States extends StateSchemas, StateId extends StateIdentifier<States>, Node = NodeByIdentifier<States, StateId>> = Node extends {
|
|
4339
|
-
readonly type: "parallel";
|
|
4340
|
-
readonly states: infer Children extends StateSchemas;
|
|
4341
|
-
} ? StateInitializeParallelBuilder<Children> : Node extends {
|
|
4342
|
-
readonly initial: infer Initial;
|
|
4343
|
-
} ? StateInitializeCompoundBuilder<Node, Initial & PropertyKey> : never;
|
|
4344
|
-
/**
|
|
4345
|
-
* Context passed to an implicit child-state initializer.
|
|
4346
|
-
*
|
|
4347
|
-
* @category models
|
|
4348
|
-
* @since 0.13.0
|
|
4349
|
-
*/
|
|
4350
|
-
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> & {
|
|
4351
|
-
readonly builder: StateInitializeBuilder<States, StateId>;
|
|
4352
|
-
};
|
|
4353
|
-
/**
|
|
4354
|
-
* Initial child value implementation for a compound or parallel state.
|
|
4355
|
-
*
|
|
4356
|
-
* @category models
|
|
4357
|
-
* @since 0.13.0
|
|
4358
|
-
*/
|
|
4359
|
-
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>;
|
|
4360
3765
|
/** Context used only when a history node has no previously captured record. */
|
|
4361
3766
|
interface HistoryDefaultContext<in out States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, in out ParentId extends StateIdentifier<States>> {
|
|
4362
3767
|
/** Lifecycle event that attempted to restore this history node. */
|
|
@@ -4402,40 +3807,12 @@ export declare namespace Machine {
|
|
|
4402
3807
|
readonly on?: never;
|
|
4403
3808
|
readonly onDone?: never;
|
|
4404
3809
|
readonly output?: never;
|
|
4405
|
-
readonly initialize?: never;
|
|
4406
3810
|
}
|
|
4407
|
-
/**
|
|
4408
|
-
* Configuration accepted for a final state.
|
|
4409
|
-
*
|
|
4410
|
-
* @inlineType OutputHandlerConfig
|
|
4411
|
-
*
|
|
4412
|
-
* @category models
|
|
4413
|
-
* @since 0.4.0
|
|
4414
|
-
*/
|
|
4415
|
-
type FinalStateConfig<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 []> = {
|
|
4416
|
-
/** Runs synchronously when the final state is entered and may enqueue commands. */
|
|
4417
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4418
|
-
readonly exit?: never;
|
|
4419
|
-
readonly always?: never;
|
|
4420
|
-
readonly onDone?: never;
|
|
4421
|
-
readonly on?: never;
|
|
4422
|
-
} & OutputHandlerConfig<States, Events, StateId, FinalOutputContext<States, Events, StateId>>;
|
|
4423
|
-
/**
|
|
4424
|
-
* Configuration accepted by `handle` for a state tag.
|
|
4425
|
-
*
|
|
4426
|
-
* @category models
|
|
4427
|
-
* @since 0.4.0
|
|
4428
|
-
*/
|
|
4429
|
-
type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = NodeByIdentifier<States, StateId> extends {
|
|
4430
|
-
readonly type: "final";
|
|
4431
|
-
} ? FinalStateConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> : ActiveStateConfig<States, Events, Emits, StateId, E, R, InputEvents, ParentEvents>;
|
|
4432
|
-
type HandlerNodeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path, InputEvents, ParentEvents> : Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R, InputEvents, ParentEvents> : never;
|
|
4433
3811
|
type HandlerChildren<Node> = Node extends {
|
|
4434
3812
|
readonly states: infer Children extends StateSchemas;
|
|
4435
3813
|
} ? Children : never;
|
|
4436
|
-
type HandlerNodeId<States extends StateSchemas, Path extends string> = Extract<Path, StateNodeIdentifier<States>>;
|
|
4437
3814
|
type HandlerConfigPart<Config> = {
|
|
4438
|
-
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];
|
|
4439
3816
|
};
|
|
4440
3817
|
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
|
|
4441
3818
|
readonly states?: infer Children;
|
|
@@ -4453,26 +3830,7 @@ export declare namespace Machine {
|
|
|
4453
3830
|
} : {
|
|
4454
3831
|
readonly [Key in Path]?: Validation;
|
|
4455
3832
|
};
|
|
4456
|
-
|
|
4457
|
-
type HandlerNode<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>> = HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R, InputEvents, ParentEvents> & (StateId extends ChoiceIdentifier<AllStates> ? {
|
|
4458
|
-
readonly states?: never;
|
|
4459
|
-
readonly history?: never;
|
|
4460
|
-
} : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
4461
|
-
readonly states?: never;
|
|
4462
|
-
readonly history?: never;
|
|
4463
|
-
} : {
|
|
4464
|
-
/** Child-state handlers nested according to the declared state topology. */
|
|
4465
|
-
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, InputEvents, ParentEvents, Extract<StateId, StateIdentifier<AllStates>>>;
|
|
4466
|
-
/** First-use defaults keyed by direct history pseudo-state. */
|
|
4467
|
-
readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
|
|
4468
|
-
} : {
|
|
4469
|
-
readonly states?: never;
|
|
4470
|
-
readonly history?: never;
|
|
4471
|
-
});
|
|
4472
|
-
type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Prefix extends string> = {
|
|
4473
|
-
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, InputEvents, ParentEvents, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
|
|
4474
|
-
};
|
|
4475
|
-
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initialize" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
3833
|
+
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initial" | "root" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
4476
3834
|
type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
|
|
4477
3835
|
readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
|
|
4478
3836
|
};
|
|
@@ -4518,18 +3876,11 @@ export declare namespace Machine {
|
|
|
4518
3876
|
} ? Path : never : never;
|
|
4519
3877
|
type HandlerConfigInitialTargetPath<Config> = TransitionResultInitialTargetPath<EventHandlerReturn<Config> | AlwaysReturn<Config> | DoneReturn<Config> | ChoiceReturn<Config> | InvokeOutcomeReturn<InvokeReturn<Config>>>;
|
|
4520
3878
|
type RequiredInitializersForTargetPath<AllStates extends StateSchemas, Path> = string extends Path ? never : Path extends StateIdentifier<AllStates> ? InitializerClosureForNode<AllStates, NodeByIdentifier<AllStates, Path>, Path> : never;
|
|
4521
|
-
type HandlerInitializeValidationAtPath<Config, Path extends string> = HandlerConfigAtPath<Config, Path> extends infer StateConfig ? [StateConfig] extends [never] ? HandlerValidationAtPath<Path, {
|
|
4522
|
-
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4523
|
-
}> : "initialize" extends keyof StateConfig ? never : HandlerValidationAtPath<Path, {
|
|
4524
|
-
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4525
|
-
}> : never;
|
|
4526
|
-
type HandlerInitialTargetValidationForPaths<AllStates extends StateSchemas, Config, Required> = Types.UnionToIntersection<Required extends string ? HandlerInitializeValidationAtPath<Config, Required> : unknown>;
|
|
4527
3879
|
type HandlerTreeInitialTargetPath<Config> = string extends keyof Config ? never : Config extends object ? {
|
|
4528
3880
|
readonly [Key in keyof Config]: HandlerConfigInitialTargetPath<HandlerConfigPart<Config[Key]>> | (Config[Key] extends {
|
|
4529
3881
|
readonly states: infer Children;
|
|
4530
3882
|
} ? HandlerTreeInitialTargetPath<Children> : never);
|
|
4531
3883
|
}[keyof Config] : never;
|
|
4532
|
-
type HandlerInitialTargetValidation<AllStates extends StateSchemas, Config> = HandlerTreeInitialTargetPath<Config> extends infer TargetPath ? HandlerInitialTargetValidationForPaths<AllStates, Config, RequiredInitializersForTargetPath<AllStates, TargetPath>> : unknown;
|
|
4533
3884
|
type HandlerChildrenValidation<Node, Prefix extends string, Config> = "states" extends keyof Config ? Config extends {
|
|
4534
3885
|
readonly states?: infer ChildrenConfig;
|
|
4535
3886
|
} ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
@@ -4550,10 +3901,10 @@ export declare namespace Machine {
|
|
|
4550
3901
|
] extends [never] ? unknown : {
|
|
4551
3902
|
readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
4552
3903
|
} : unknown : unknown);
|
|
4553
|
-
type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "
|
|
4554
|
-
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>;
|
|
4555
3906
|
} : unknown;
|
|
4556
|
-
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;
|
|
4557
3908
|
type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
|
|
4558
3909
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
|
|
4559
3910
|
};
|
|
@@ -4561,22 +3912,13 @@ export declare namespace Machine {
|
|
|
4561
3912
|
readonly invoke: HandlerValidationError<"Invoked child expects parent events not accepted by this machine", StateId, Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
4562
3913
|
};
|
|
4563
3914
|
type HandlerRuntimeValidation<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, Incompatible = keyof Config extends never ? never : IncompatibleRuntime<ConfigServices<HandlerConfigPart<Config>>, EventOf<Events>, EmittedEventOf<Emits>>> = [Incompatible] extends [never] ? unknown : HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>;
|
|
4564
|
-
type HandlerNodeValidationAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : HandlerNodeValidation<AllStates, HandlerNodeByPath<AllStates, StateId>, Events, InputEvents, Emits, StateId, NodeConfig, AvailableOutputStates> extends infer Validation ? unknown extends Validation ? never : "" extends keyof AllStates ? StateId extends "" ? {
|
|
4565
|
-
readonly ""?: Validation;
|
|
4566
|
-
} : {
|
|
4567
|
-
readonly ""?: {
|
|
4568
|
-
readonly states: HandlerValidationAtPath<StateId, Validation>;
|
|
4569
|
-
};
|
|
4570
|
-
} : HandlerValidationAtPath<StateId, Validation> : never;
|
|
4571
|
-
type HandlerTreeNodeValidations<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeValidationAtPath<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates, StateId> : never : never>;
|
|
4572
|
-
type HandlerTreeValidation<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = HandlerUnknownStateKeyValidation<AllStates, "", Config> & HandlerTreeNodeValidations<AllStates, Events, InputEvents, Emits, Config, AvailableOutputStates>;
|
|
4573
3915
|
type RootInitialTargetValidation<States extends StateSchemas, Config> = RequiredInitializersForTargetPath<States, HandlerTreeInitialTargetPath<{
|
|
4574
3916
|
readonly "": Config;
|
|
4575
3917
|
}>> extends infer Required ? Types.UnionToIntersection<Required extends string ? HandlerConfigAtPath<{
|
|
4576
3918
|
readonly "": Config;
|
|
4577
3919
|
}, Required> extends infer NodeConfig ? [
|
|
4578
3920
|
NodeConfig
|
|
4579
|
-
] extends [never] ? RootInitializeError<Required> : "
|
|
3921
|
+
] extends [never] ? RootInitializeError<Required> : "initial" extends keyof NodeConfig ? never : RootInitializeError<Required> : never : unknown> : unknown;
|
|
4580
3922
|
type RootInitializeError<Path extends string> = Path extends "" ? {
|
|
4581
3923
|
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4582
3924
|
} : {
|
|
@@ -4584,14 +3926,21 @@ export declare namespace Machine {
|
|
|
4584
3926
|
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4585
3927
|
}>;
|
|
4586
3928
|
};
|
|
4587
|
-
type
|
|
4588
|
-
readonly
|
|
4589
|
-
}
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
readonly states:
|
|
4593
|
-
|
|
4594
|
-
|
|
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;
|
|
4595
3944
|
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
4596
3945
|
readonly states: infer Children extends StateSchemas;
|
|
4597
3946
|
} ? [HistoryStateKey<Children>] extends [never] ? true : Config extends {
|
|
@@ -4606,27 +3955,748 @@ export declare namespace Machine {
|
|
|
4606
3955
|
} ? [
|
|
4607
3956
|
Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
|
|
4608
3957
|
] extends [never] ? true : false : false : true;
|
|
4609
|
-
type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> =
|
|
4610
|
-
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
|
|
4611
|
-
type HandlerNodeEvidence<AllStates extends StateSchemas,
|
|
4612
|
-
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;
|
|
4613
3962
|
readonly error: HandlerConfigError<HandlerConfigPart<NodeConfig>>;
|
|
4614
3963
|
readonly services: ConfigServices<HandlerConfigPart<NodeConfig>>;
|
|
4615
3964
|
readonly outputState: StateId extends StateIdentifier<AllStates> ? HandlerOutputStates<AllStates, StateId, HandlerConfigPart<NodeConfig>> : never;
|
|
4616
3965
|
};
|
|
4617
|
-
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>];
|
|
4618
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>;
|
|
3974
|
+
type ObjectCompoundPath<S extends StateSchemas> = {
|
|
3975
|
+
readonly [P in StateIdentifier<S>]: NodeByIdentifier<S, P> extends {
|
|
3976
|
+
/** Child handlers nested according to the declared root topology. */
|
|
3977
|
+
readonly states: StateSchemas;
|
|
3978
|
+
} ? P : never;
|
|
3979
|
+
}[StateIdentifier<S>];
|
|
3980
|
+
type LazyProgramValue = Effect.Effect<unknown, unknown, unknown> | Stream.Stream<unknown, unknown, unknown>;
|
|
3981
|
+
/** Registered lazy programs and their optional explicit input adapters. */
|
|
3982
|
+
type Program<Value> = Value | ((...args: never[]) => Value);
|
|
3983
|
+
type EffectSources = Readonly<Record<string, Program<Effect.Effect<unknown, unknown, unknown>>>>;
|
|
3984
|
+
type StreamSources = Readonly<Record<string, Program<Stream.Stream<unknown, unknown, unknown>>>>;
|
|
3985
|
+
type TimerSources = Readonly<Record<string, Program<Duration.Input>>>;
|
|
3986
|
+
type LogicSources = Readonly<Record<string, unknown>>;
|
|
3987
|
+
type ValidateLogicSources<Sources> = {
|
|
3988
|
+
readonly [K in keyof Sources]: InvokeResolvedSource<Sources[K]> extends {
|
|
3989
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
3990
|
+
readonly initial: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
|
|
3991
|
+
readonly run: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
|
|
3992
|
+
} ? unknown : never;
|
|
3993
|
+
};
|
|
3994
|
+
type ChildSources = Readonly<Record<string, ChildMachine.Any>>;
|
|
3995
|
+
type ValidatePrograms<Sources> = {
|
|
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;
|
|
3997
|
+
};
|
|
3998
|
+
type ReferenceRoot<S extends StateSchemas> = Extract<S[""], StateNodeConfig>;
|
|
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">;
|
|
4000
|
+
type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = {
|
|
4001
|
+
readonly [P in Paths]: ReferenceAt<S, P>;
|
|
4002
|
+
}[Paths];
|
|
4003
|
+
type DestinationPath<S extends StateSchemas> = Exclude<StateNodeIdentifier<S>, "">;
|
|
4004
|
+
type RootSchemas<Root extends StateNodeConfig> = {
|
|
4005
|
+
readonly "": Root;
|
|
4006
|
+
};
|
|
4007
|
+
/** A topology declaration; its state values are constructed by a resolver. */
|
|
4008
|
+
type BranchDeclaration<Root extends StateNodeConfig, S extends StateSchemas = RootSchemas<Root>> = {
|
|
4009
|
+
/** Optional presentation label for this named branch. */
|
|
4010
|
+
readonly title?: string;
|
|
4011
|
+
} & ({
|
|
4012
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4013
|
+
readonly target: ReferenceUnion<S, DestinationPath<S>>;
|
|
4014
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4015
|
+
readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>;
|
|
4016
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4017
|
+
readonly initial?: never;
|
|
4018
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4019
|
+
readonly history?: never;
|
|
4020
|
+
/** Accepts the event without selecting a new destination. */
|
|
4021
|
+
readonly none?: never;
|
|
4022
|
+
} | {
|
|
4023
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4024
|
+
readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>;
|
|
4025
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4026
|
+
readonly target?: never;
|
|
4027
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4028
|
+
readonly initial?: never;
|
|
4029
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4030
|
+
readonly history?: never;
|
|
4031
|
+
/** Accepts the event without selecting a new destination. */
|
|
4032
|
+
readonly none?: never;
|
|
4033
|
+
} | {
|
|
4034
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4035
|
+
readonly initial: ReferenceUnion<S, Exclude<ObjectCompoundPath<S>, "">>;
|
|
4036
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4037
|
+
readonly target?: never;
|
|
4038
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4039
|
+
readonly update?: never;
|
|
4040
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4041
|
+
readonly history?: never;
|
|
4042
|
+
/** Accepts the event without selecting a new destination. */
|
|
4043
|
+
readonly none?: never;
|
|
4044
|
+
} | {
|
|
4045
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4046
|
+
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
4047
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4048
|
+
readonly target?: never;
|
|
4049
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4050
|
+
readonly update?: never;
|
|
4051
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4052
|
+
readonly initial?: never;
|
|
4053
|
+
/** Accepts the event without selecting a new destination. */
|
|
4054
|
+
readonly none?: never;
|
|
4055
|
+
} | {
|
|
4056
|
+
/** Accepts the event without selecting a new destination. */
|
|
4057
|
+
readonly none: true;
|
|
4058
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4059
|
+
readonly target?: never;
|
|
4060
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4061
|
+
readonly update?: never;
|
|
4062
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4063
|
+
readonly initial?: never;
|
|
4064
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4065
|
+
readonly history?: never;
|
|
4066
|
+
});
|
|
4067
|
+
type BranchDefinitions<Root extends StateNodeConfig> = Readonly<Record<string, Readonly<Record<string, BranchDeclaration<Root>>>>>;
|
|
4068
|
+
/** Source programs and named topology declarations captured by a machine definition. */
|
|
4069
|
+
interface Registrations {
|
|
4070
|
+
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
4071
|
+
readonly effects?: EffectSources;
|
|
4072
|
+
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
4073
|
+
readonly streams?: StreamSources;
|
|
4074
|
+
/** Cancellable delays, supplied as durations or functions of one required input. */
|
|
4075
|
+
readonly timers?: TimerSources;
|
|
4076
|
+
/** Logic values or functions of one required input; their Effect channels remain inferred. */
|
|
4077
|
+
readonly logic?: LogicSources;
|
|
4078
|
+
/** Child machine descriptors registered for state-owned invocation. */
|
|
4079
|
+
readonly children?: ChildSources;
|
|
4080
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4081
|
+
readonly branches?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
4082
|
+
}
|
|
4083
|
+
type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {};
|
|
4084
|
+
type AtBuilder<T, P extends string> = P extends "" ? T : P extends `${infer H}.${infer Rest}` ? H extends keyof T ? AtBuilder<T[H], Rest> : never : P extends keyof T ? T[P] : never;
|
|
4085
|
+
type BranchBuilderAt<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = AtBuilder<RootBuilder<BranchTargetBuilder<S, Src>>, P>;
|
|
4086
|
+
type RefPath<R> = R extends TargetReference<any, infer P, any> ? P : never;
|
|
4087
|
+
type SelectionOf<S extends StateSchemas, Src extends StateNodeIdentifier<S>, D> = D extends {
|
|
4088
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4089
|
+
readonly target: infer Ref;
|
|
4090
|
+
} ? RefPath<Ref> extends infer P extends StateNodeIdentifier<S> ? D extends {
|
|
4091
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4092
|
+
readonly update: infer Update;
|
|
4093
|
+
} ? RefPath<Update> extends infer Owner extends Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>> ? TargetSelection<UpdatingTargetBuilder<BranchBuilderAt<S, Src, P>, S, Owner>, P, "state", "branch"> : never : TargetSelection<BranchBuilderAt<S, Src, P>, P, P extends ChoiceIdentifier<S> ? "choice" : "state", "branch"> : never : D extends {
|
|
4094
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4095
|
+
readonly initial: infer Ref;
|
|
4096
|
+
} ? RefPath<Ref> extends infer P extends string ? BranchBuilderAt<S, Src, P> extends {
|
|
4097
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4098
|
+
readonly initial: infer B;
|
|
4099
|
+
} ? TargetSelection<B, P, "initial", "branch"> : never : never : D extends {
|
|
4100
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4101
|
+
readonly history: infer Ref;
|
|
4102
|
+
} ? RefPath<Ref> extends infer P extends string ? TargetSelection<AtBuilder<RootBuilder<HistoryTargetBuilder<S>>, P>, P, "history", "full"> : never : D extends {
|
|
4103
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4104
|
+
readonly update: infer Ref;
|
|
4105
|
+
} ? RefPath<Ref> extends infer P extends Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>> ? TargetSelection<StateUpdateBuilder<S, P>, P, "update", "branch"> : never : D extends {
|
|
4106
|
+
/** Accepts the event without selecting a new destination. */
|
|
4107
|
+
readonly none: true;
|
|
4108
|
+
} ? TargetSelection<() => NoTarget, never, "none", "local"> : never;
|
|
4109
|
+
type BuilderArgs<B, K extends PropertyKey> = K extends keyof B ? B[K] extends (...args: infer A) => unknown ? A : never : never;
|
|
4110
|
+
type ObjectConstruction<C, B> = {
|
|
4111
|
+
readonly [M in Extract<keyof B, "from" | "decoded">]: BuilderArgs<B, M> extends readonly [unknown?] ? {
|
|
4112
|
+
readonly [K in M]: (context: C) => BuilderArgs<B, M>[0];
|
|
4113
|
+
} & {
|
|
4114
|
+
readonly [K in Exclude<"from" | "decoded", M>]?: never;
|
|
4115
|
+
} : never;
|
|
4116
|
+
}[Extract<keyof B, "from" | "decoded">];
|
|
4117
|
+
type ObjectDefault<B> = B extends {
|
|
4118
|
+
/** Constructs schema make input from the typed source context. */
|
|
4119
|
+
readonly from: () => unknown;
|
|
4120
|
+
} | (() => unknown) ? {
|
|
4121
|
+
/** Constructs schema make input from the typed source context. */
|
|
4122
|
+
readonly from?: never; /** Supplies an already decoded schema value from the typed source context. */
|
|
4123
|
+
readonly decoded?: never;
|
|
4124
|
+
} : never;
|
|
4125
|
+
type ObjectPolicy<C, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
|
|
4126
|
+
/** Set to true to exit and reenter the handler source. */
|
|
4127
|
+
readonly reenter?: Reenter extends true ? boolean : never;
|
|
4128
|
+
/** Declines the transition before construction when the predicate returns false. */
|
|
4129
|
+
readonly guard?: "declinable" extends Acceptance ? ((context: C) => boolean) | undefined : never;
|
|
4130
|
+
};
|
|
4131
|
+
type InlineNodeConstruction<C, Node> = [NodeSchema<Node>] extends [never] ? {
|
|
4132
|
+
readonly from?: (context: C) => undefined;
|
|
4133
|
+
readonly decoded?: never;
|
|
4134
|
+
} : {
|
|
4135
|
+
readonly from: (context: C) => NodeMakeInput<Node>;
|
|
4136
|
+
readonly decoded?: never;
|
|
4137
|
+
} | {
|
|
4138
|
+
readonly decoded: (context: C) => NodeValue<Node>;
|
|
4139
|
+
readonly from?: never;
|
|
4140
|
+
} | ({} extends NodeMakeInput<Node> ? {
|
|
4141
|
+
readonly from?: never;
|
|
4142
|
+
readonly decoded?: never;
|
|
4143
|
+
} : never);
|
|
4144
|
+
type InlineDestinationConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends DestinationPath<S>, C> = P extends ChoiceIdentifier<S> ? {
|
|
4145
|
+
readonly from?: never;
|
|
4146
|
+
readonly decoded?: never;
|
|
4147
|
+
} : P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
|
|
4148
|
+
readonly states: StateSchemas;
|
|
4149
|
+
} ? [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? ObjectConstruction<C, BranchBuilderAt<S, Src, P>> | ObjectDefault<BranchBuilderAt<S, Src, P>> : never : InlineNodeConstruction<C, NodeByIdentifier<S, P>> : never;
|
|
4150
|
+
type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
|
|
4151
|
+
readonly [P in DestinationPath<S>]: {
|
|
4152
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4153
|
+
readonly target: ReferenceAt<S, P>;
|
|
4154
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4155
|
+
readonly update?: never;
|
|
4156
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4157
|
+
readonly initial?: never;
|
|
4158
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4159
|
+
readonly history?: never;
|
|
4160
|
+
/** Accepts the event without selecting a new destination. */
|
|
4161
|
+
readonly none?: never;
|
|
4162
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4163
|
+
readonly branches?: never;
|
|
4164
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4165
|
+
readonly resolve?: never;
|
|
4166
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4167
|
+
readonly declinable?: never;
|
|
4168
|
+
} & InlineDestinationConstruction<S, Src, P, C>;
|
|
4169
|
+
}[DestinationPath<S>];
|
|
4170
|
+
type InlinePairConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string, Owner extends ValuedStateIdentifier<S>, C> = P extends StateIdentifier<S> ? NodeByIdentifier<S, P> extends {
|
|
4171
|
+
readonly states: StateSchemas;
|
|
4172
|
+
} ? {
|
|
4173
|
+
readonly [M in Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">]: BuilderArgs<BranchBuilderAt<S, Src, P>, M> extends readonly [unknown?] ? {
|
|
4174
|
+
readonly [K in M]: (context: C) => {
|
|
4175
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4176
|
+
readonly target: BuilderArgs<BranchBuilderAt<S, Src, P>, M>[0];
|
|
4177
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4178
|
+
readonly update: BuilderArgs<StateUpdateBuilder<S, Owner>, M>[0];
|
|
4179
|
+
};
|
|
4180
|
+
} & {
|
|
4181
|
+
readonly [K in Exclude<"from" | "decoded", M>]?: never;
|
|
4182
|
+
} : never;
|
|
4183
|
+
}[Extract<keyof BranchBuilderAt<S, Src, P> & keyof StateUpdateBuilder<S, Owner>, "from" | "decoded">] : {
|
|
4184
|
+
readonly from: (context: C) => {
|
|
4185
|
+
readonly target: [NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? undefined : NodeMakeInput<NodeByIdentifier<S, P>>;
|
|
4186
|
+
readonly update: SchemaByIdentifier<S, Owner>["~type.make.in"];
|
|
4187
|
+
};
|
|
4188
|
+
readonly decoded?: never;
|
|
4189
|
+
} | ([NodeSchema<NodeByIdentifier<S, P>>] extends [never] ? never : {
|
|
4190
|
+
readonly decoded: (context: C) => {
|
|
4191
|
+
readonly target: NodeValue<NodeByIdentifier<S, P>>;
|
|
4192
|
+
readonly update: StateByIdentifier<S, Owner>;
|
|
4193
|
+
};
|
|
4194
|
+
readonly from?: never;
|
|
4195
|
+
}) : never;
|
|
4196
|
+
type InlineCombined<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = Src extends ChoiceIdentifier<S> ? never : [
|
|
4197
|
+
Extract<ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>
|
|
4198
|
+
] extends [never] ? never : {
|
|
4199
|
+
readonly [P in DestinationPath<S>]: {
|
|
4200
|
+
readonly [Owner in Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>]: {
|
|
4201
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4202
|
+
readonly target: ReferenceAt<S, P>;
|
|
4203
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4204
|
+
readonly update: ReferenceAt<S, Owner>;
|
|
4205
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4206
|
+
readonly initial?: never;
|
|
4207
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4208
|
+
readonly history?: never;
|
|
4209
|
+
/** Accepts the event without selecting a new destination. */
|
|
4210
|
+
readonly none?: never;
|
|
4211
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4212
|
+
readonly branches?: never;
|
|
4213
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4214
|
+
readonly resolve?: never;
|
|
4215
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4216
|
+
readonly declinable?: never;
|
|
4217
|
+
} & InlinePairConstruction<S, Src, P, Owner, C>;
|
|
4218
|
+
}[Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>];
|
|
4219
|
+
}[DestinationPath<S>];
|
|
4220
|
+
type InlineUpdate<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = Src extends ChoiceIdentifier<S> ? never : {
|
|
4221
|
+
readonly [P in Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>]: {
|
|
4222
|
+
/** Set to true to exit and reenter the handler source. */
|
|
4223
|
+
readonly reenter?: P extends Src ? never : boolean;
|
|
4224
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4225
|
+
readonly update: ReferenceAt<S, P>;
|
|
4226
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4227
|
+
readonly target?: never;
|
|
4228
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4229
|
+
readonly initial?: never;
|
|
4230
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4231
|
+
readonly history?: never;
|
|
4232
|
+
/** Accepts the event without selecting a new destination. */
|
|
4233
|
+
readonly none?: never;
|
|
4234
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4235
|
+
readonly branches?: never;
|
|
4236
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4237
|
+
readonly resolve?: never;
|
|
4238
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4239
|
+
readonly declinable?: never;
|
|
4240
|
+
} & ObjectConstruction<C, StateUpdateBuilder<S, P>>;
|
|
4241
|
+
}[Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>];
|
|
4242
|
+
type InlineInitial<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = [
|
|
4243
|
+
Exclude<ObjectCompoundPath<S>, "">
|
|
4244
|
+
] extends [never] ? never : {
|
|
4245
|
+
readonly [P in Exclude<ObjectCompoundPath<S>, "">]: InitialTargetFactory<NodeByIdentifier<S, P>, P> extends infer B ? {
|
|
4246
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4247
|
+
readonly initial: ReferenceAt<S, P>;
|
|
4248
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4249
|
+
readonly target?: never;
|
|
4250
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4251
|
+
readonly update?: never;
|
|
4252
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4253
|
+
readonly history?: never;
|
|
4254
|
+
/** Accepts the event without selecting a new destination. */
|
|
4255
|
+
readonly none?: never;
|
|
4256
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4257
|
+
readonly branches?: never;
|
|
4258
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4259
|
+
readonly resolve?: never;
|
|
4260
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4261
|
+
readonly declinable?: never;
|
|
4262
|
+
} & (ObjectConstruction<C, B> | ObjectDefault<B>) : never;
|
|
4263
|
+
}[Exclude<ObjectCompoundPath<S>, "">];
|
|
4264
|
+
type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
|
|
4265
|
+
readonly [K in Extract<keyof Group, string>]: {
|
|
4266
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4267
|
+
readonly target: SelectionOf<S, Src, Group[K]>;
|
|
4268
|
+
};
|
|
4269
|
+
};
|
|
4270
|
+
type ObjectBranchResolver<Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, C, B extends Readonly<Record<string, TransitionBranchInput>>, Declinable extends boolean> = (context: C & {
|
|
4271
|
+
readonly select: BranchSelectors<B>;
|
|
4272
|
+
} & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => BranchSelectionResult<B> | (Declinable extends true ? Declined : never);
|
|
4273
|
+
type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group> = {
|
|
4274
|
+
readonly [K in keyof Group]: Src extends ChoiceIdentifier<S> ? Group[K] extends {
|
|
4275
|
+
/** Accepts the event without selecting a new destination. */
|
|
4276
|
+
readonly none: true;
|
|
4277
|
+
} | {
|
|
4278
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4279
|
+
readonly update: unknown;
|
|
4280
|
+
} ? K : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never : [SelectionBuilder<SelectionOf<S, Src, Group[K]>>] extends [never] ? K : never;
|
|
4281
|
+
}[keyof Group];
|
|
4282
|
+
type ObjectBranches<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Acceptance extends TransitionAcceptance> = {
|
|
4283
|
+
readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K]>] extends [never] ? unknown : never) & {
|
|
4284
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4285
|
+
readonly branches: K;
|
|
4286
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4287
|
+
readonly target?: never;
|
|
4288
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4289
|
+
readonly update?: never;
|
|
4290
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4291
|
+
readonly initial?: never;
|
|
4292
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4293
|
+
readonly history?: never;
|
|
4294
|
+
/** Accepts the event without selecting a new destination. */
|
|
4295
|
+
readonly none?: never;
|
|
4296
|
+
/** Constructs schema make input from the typed source context. */
|
|
4297
|
+
readonly from?: never;
|
|
4298
|
+
/** Supplies an already decoded schema value from the typed source context. */
|
|
4299
|
+
readonly decoded?: never;
|
|
4300
|
+
} & {
|
|
4301
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4302
|
+
readonly declinable?: "declinable" extends Acceptance ? boolean : false;
|
|
4303
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4304
|
+
readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K]>, true>;
|
|
4305
|
+
};
|
|
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;
|
|
4619
4322
|
/**
|
|
4620
|
-
*
|
|
4323
|
+
* A transition with an inspectable destination and source-specific construction.
|
|
4324
|
+
*
|
|
4325
|
+
* @category models
|
|
4326
|
+
* @since 0.34.0
|
|
4327
|
+
*/
|
|
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> | {
|
|
4329
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4330
|
+
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
4331
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4332
|
+
readonly target?: never;
|
|
4333
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4334
|
+
readonly update?: never;
|
|
4335
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4336
|
+
readonly initial?: never;
|
|
4337
|
+
/** Accepts the event without selecting a new destination. */
|
|
4338
|
+
readonly none?: never;
|
|
4339
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4340
|
+
readonly branches?: never;
|
|
4341
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4342
|
+
readonly resolve?: never;
|
|
4343
|
+
/** Constructs schema make input from the typed source context. */
|
|
4344
|
+
readonly from?: never;
|
|
4345
|
+
/** Supplies an already decoded schema value from the typed source context. */
|
|
4346
|
+
readonly decoded?: never;
|
|
4347
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4348
|
+
readonly declinable?: never;
|
|
4349
|
+
} | (Src extends ChoiceIdentifier<S> ? never : {
|
|
4350
|
+
/** Accepts the event without selecting a new destination. */
|
|
4351
|
+
readonly none: true;
|
|
4352
|
+
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4353
|
+
readonly target?: never;
|
|
4354
|
+
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4355
|
+
readonly update?: never;
|
|
4356
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4357
|
+
readonly initial?: never;
|
|
4358
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4359
|
+
readonly history?: never;
|
|
4360
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4361
|
+
readonly branches?: never;
|
|
4362
|
+
/** Constructs schema make input from the typed source context. */
|
|
4363
|
+
readonly from?: never;
|
|
4364
|
+
/** Supplies an already decoded schema value from the typed source context. */
|
|
4365
|
+
readonly decoded?: never;
|
|
4366
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4367
|
+
readonly declinable?: "declinable" extends Acceptance ? boolean : false;
|
|
4368
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4369
|
+
readonly resolve?: (context: C & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => undefined | Declined;
|
|
4370
|
+
}) | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance>)>;
|
|
4371
|
+
type SourceValue<R, K extends PropertyKey> = {
|
|
4372
|
+
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Registered<R, Kind>[K] : never;
|
|
4373
|
+
}["effects" | "streams" | "timers" | "logic" | "children"];
|
|
4374
|
+
type SourceKind<R, K extends PropertyKey> = {
|
|
4375
|
+
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Kind : never;
|
|
4376
|
+
}["effects" | "streams" | "timers" | "logic" | "children"];
|
|
4377
|
+
type SourceKeys<R> = {
|
|
4378
|
+
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: keyof Registered<R, Kind>;
|
|
4379
|
+
}["effects" | "streams" | "timers" | "logic" | "children"];
|
|
4380
|
+
type SourceInput<F, C> = F extends LazyProgramValue ? {
|
|
4381
|
+
readonly input?: never;
|
|
4382
|
+
} : F extends (...args: never[]) => unknown ? Parameters<F>["length"] extends 1 ? {
|
|
4383
|
+
/** Maps the owning state context to the registered source input. */
|
|
4384
|
+
readonly input: (context: C) => Parameters<F>[0];
|
|
4385
|
+
} : never : {
|
|
4386
|
+
/** Maps the owning state context to the registered source input. */
|
|
4387
|
+
readonly input?: never;
|
|
4388
|
+
};
|
|
4389
|
+
type ResolvedInvoke<R, K extends PropertyKey> = SourceKind<R, K> extends "effects" ? {
|
|
4390
|
+
readonly effect: () => InvokeResolvedSource<SourceValue<R, K>>;
|
|
4391
|
+
} : SourceKind<R, K> extends "streams" ? {
|
|
4392
|
+
readonly stream: () => InvokeResolvedSource<SourceValue<R, K>>;
|
|
4393
|
+
} : SourceKind<R, K> extends "timers" ? {
|
|
4394
|
+
readonly after: Duration.Input;
|
|
4395
|
+
} : SourceKind<R, K> extends "logic" ? {
|
|
4396
|
+
/** Logic values or functions of one required input; their Effect channels remain inferred. */
|
|
4397
|
+
readonly logic: InvokeResolvedSource<SourceValue<R, K>>;
|
|
4398
|
+
} : SourceKind<R, K> extends "children" ? {
|
|
4399
|
+
readonly child: SourceValue<R, K>;
|
|
4400
|
+
} & (SourceValue<R, K> extends ChildMachine<string, infer M> ? {
|
|
4401
|
+
readonly [InvokeTypeId]: {
|
|
4402
|
+
readonly error: Types.Covariant<Error<M> | ActionError<Services<M>>>;
|
|
4403
|
+
readonly initialError: Types.Covariant<InitialError<M>>;
|
|
4404
|
+
readonly requirements: Types.Covariant<Services<M>>;
|
|
4405
|
+
};
|
|
4406
|
+
} : never) : never;
|
|
4407
|
+
type RegisteredInvocationInput<R, K extends PropertyKey, C> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? InputSchema<M> extends typeof Schema.Void ? {
|
|
4408
|
+
/** Maps the owning state context to the registered source input. */
|
|
4409
|
+
readonly input?: never;
|
|
4410
|
+
} : {
|
|
4411
|
+
/** Maps the owning state context to the registered source input. */
|
|
4412
|
+
readonly input: (context: C) => Input<M>;
|
|
4413
|
+
} : never : SourceInput<SourceValue<R, K>, C>;
|
|
4414
|
+
type ObjectOutcome<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R, V, Channel extends "onDone" | "onFailure" | "onElement" | "onSnapshot"> = [V] extends [never] ? {} : Channel extends "onDone" ? {
|
|
4415
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4416
|
+
readonly onDone: Transition<S, Src, InvokeDoneContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4417
|
+
} : Channel extends "onFailure" ? {
|
|
4418
|
+
/** Handles the typed failure of the invoked source; required exactly when that channel is reachable. */
|
|
4419
|
+
readonly onFailure: Transition<S, Src, InvokeFailureContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4420
|
+
} : Channel extends "onElement" ? {
|
|
4421
|
+
/** Handles each Stream element; required when the element type is reachable. */
|
|
4422
|
+
readonly onElement: Transition<S, Src, InvokeElementContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4423
|
+
} : {
|
|
4424
|
+
/** Optionally handles active snapshots of invoked logic or a child machine. */
|
|
4425
|
+
readonly onSnapshot: Transition<S, Src, InvokeSnapshotContext<S, Ev, Em, Src, V, never, never, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4426
|
+
};
|
|
4427
|
+
type RegisteredInvokeError<R, K extends PropertyKey> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? Error<M> | ActionError<Services<M>> : never : InvokeRuntimeError<ResolvedInvoke<R, K>>;
|
|
4428
|
+
/**
|
|
4429
|
+
* A registered source invocation with its required input and reachable outcomes.
|
|
4430
|
+
*
|
|
4431
|
+
* @category models
|
|
4432
|
+
* @since 0.34.0
|
|
4433
|
+
*/
|
|
4434
|
+
type Invocation<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = {
|
|
4435
|
+
readonly [K in Extract<SourceKeys<R>, string>]: Types.Simplify<{
|
|
4436
|
+
/** Name of the source registered in make. */
|
|
4437
|
+
readonly src: K;
|
|
4438
|
+
} & (SourceKind<R, K> extends "children" ? {
|
|
4439
|
+
/** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
|
|
4440
|
+
readonly id?: never; /** Typed runtime address required for invoked logic; child descriptors carry their own address. */
|
|
4441
|
+
readonly address?: never;
|
|
4442
|
+
} : SourceKind<R, K> extends "logic" ? {
|
|
4443
|
+
/** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
|
|
4444
|
+
readonly id: InvokeLifecycleId;
|
|
4445
|
+
/** Typed runtime address required for invoked logic; child descriptors carry their own address. */
|
|
4446
|
+
readonly address: ChildAddress<LogicEventOf<InvokeResolvedSource<SourceValue<R, K>>>>;
|
|
4447
|
+
} : {
|
|
4448
|
+
/** Lifecycle identifier; Effects, Streams, and timers default to their registered source name. */
|
|
4449
|
+
readonly id?: InvokeLifecycleId; /** Typed runtime address required for invoked logic; child descriptors carry their own address. */
|
|
4450
|
+
readonly address?: never;
|
|
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">> : {})>;
|
|
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
|
+
};
|
|
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> ? {
|
|
4549
|
+
/** Runs synchronously on entry and may enqueue commands. */
|
|
4550
|
+
readonly entry?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
|
|
4551
|
+
} & (Node extends {
|
|
4552
|
+
readonly type: "final";
|
|
4553
|
+
} ? {
|
|
4554
|
+
/** Runs synchronously on exit and may enqueue commands. */
|
|
4555
|
+
readonly exit?: never;
|
|
4556
|
+
} & OutputHandlerConfig<S, Ev, Src, FinalOutputContext<S, Ev, Src>> : {
|
|
4557
|
+
/** Runs synchronously on exit and may enqueue commands. */
|
|
4558
|
+
readonly exit?: (context: StateActionContext<S, Ev, Em, Src, In, Pa>, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => StateActionResult<any, any>;
|
|
4559
|
+
} & ActiveOutputHandlerConfig<S, Ev, Src>) : {
|
|
4560
|
+
/** Runs synchronously on entry and may enqueue commands. */
|
|
4561
|
+
readonly entry?: never; /** Runs synchronously on exit and may enqueue commands. */
|
|
4562
|
+
readonly exit?: never; /** Constructs the decoded output declared by the state schema. */
|
|
4563
|
+
readonly output?: never;
|
|
4564
|
+
};
|
|
4565
|
+
/**
|
|
4566
|
+
* Handlers for a node of the declared root tree.
|
|
4567
|
+
*
|
|
4568
|
+
* @category models
|
|
4569
|
+
* @since 0.34.0
|
|
4570
|
+
*/
|
|
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> ? {
|
|
4575
|
+
/** Required total transition for a transient choice state. */
|
|
4576
|
+
readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>;
|
|
4577
|
+
/** Event handlers keyed by the public or internal event tag. */
|
|
4578
|
+
readonly on?: never;
|
|
4579
|
+
/** Eventless transition evaluated during stabilization. */
|
|
4580
|
+
readonly always?: never;
|
|
4581
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4582
|
+
readonly onDone?: never;
|
|
4583
|
+
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4584
|
+
readonly invoke?: never;
|
|
4585
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4586
|
+
readonly states?: never;
|
|
4587
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4588
|
+
readonly history?: never;
|
|
4589
|
+
} : Src extends StateIdentifier<S> ? Node extends {
|
|
4590
|
+
readonly type: "final";
|
|
4591
|
+
} ? {
|
|
4592
|
+
/** Event handlers keyed by the public or internal event tag. */
|
|
4593
|
+
readonly on?: never;
|
|
4594
|
+
/** Eventless transition evaluated during stabilization. */
|
|
4595
|
+
readonly always?: never;
|
|
4596
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4597
|
+
readonly onDone?: never;
|
|
4598
|
+
/** Required total transition for a transient choice state. */
|
|
4599
|
+
readonly choice?: never;
|
|
4600
|
+
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4601
|
+
readonly invoke?: never;
|
|
4602
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4603
|
+
readonly states?: never;
|
|
4604
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4605
|
+
readonly history?: never;
|
|
4606
|
+
} : {
|
|
4607
|
+
/** Event handlers keyed by the public or internal event tag. */
|
|
4608
|
+
readonly on?: {
|
|
4609
|
+
readonly [Tag in TagOf<Ev[number]>]?: Transition<S, Src, HandlerContext<S, Ev, Em, Src, Tag, never, never, In, Pa>, Ev, Em, R, true, TransitionAcceptance>;
|
|
4610
|
+
};
|
|
4611
|
+
/** Eventless transition evaluated during stabilization. */
|
|
4612
|
+
readonly always?: Transition<S, Src, AlwaysContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, TransitionAcceptance>;
|
|
4613
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4614
|
+
readonly onDone?: Transition<S, Src, DoneContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, TransitionAcceptance>;
|
|
4615
|
+
/** Required total transition for a transient choice state. */
|
|
4616
|
+
readonly choice?: never;
|
|
4617
|
+
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4618
|
+
readonly invoke?: Invocation<S, Ev, Em, Src, In, Pa, R> | (ReadonlyArray<Invocation<S, Ev, Em, Src, In, Pa, R>> & {
|
|
4619
|
+
/** Name of the source registered in make. */
|
|
4620
|
+
readonly src?: never;
|
|
4621
|
+
});
|
|
4622
|
+
} & (Node extends {
|
|
4623
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4624
|
+
readonly states: infer Children extends StateSchemas;
|
|
4625
|
+
} ? {
|
|
4626
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4627
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4628
|
+
readonly history?: HistoryDefaultConfig<S, Ev, Em, Src, Children>;
|
|
4629
|
+
} & ChildHandlers<S, Children, Ev, Em, Src, In, Pa, R> : {
|
|
4630
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4631
|
+
readonly states?: never; /** Restores the declared history reference, using its fallback on first entry. */
|
|
4632
|
+
readonly history?: never;
|
|
4633
|
+
}) : never);
|
|
4634
|
+
type ValidateObjectTransition<T> = {
|
|
4635
|
+
readonly [K in Exclude<keyof T, "target" | "update" | "initial" | "history" | "none" | "branches" | "data" | "decoded" | "resolve" | "guard" | "reenter" | "declinable">]: never;
|
|
4636
|
+
} & (T extends {
|
|
4637
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4638
|
+
readonly declinable: infer D;
|
|
4639
|
+
} ? boolean extends D ? {
|
|
4640
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4641
|
+
readonly declinable: never;
|
|
4642
|
+
} : unknown : unknown) & (T extends {
|
|
4643
|
+
/** Set to true when the resolver can explicitly return decline(). */
|
|
4644
|
+
readonly declinable: true;
|
|
4645
|
+
} ? unknown : T extends {
|
|
4646
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4647
|
+
readonly resolve: (...args: any[]) => infer Result;
|
|
4648
|
+
} ? [Extract<Result, Declined>] extends [never] ? unknown : {
|
|
4649
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4650
|
+
readonly resolve: never;
|
|
4651
|
+
} : unknown);
|
|
4652
|
+
type AllowedInvokeChannels<R, K extends PropertyKey> = ([InvokeOutput<ResolvedInvoke<R, K>>] extends [never] ? never : "onDone") | ([RegisteredInvokeError<R, K>] extends [never] ? never : "onFailure") | (SourceKind<R, K> extends "streams" ? [Stream.Success<Extract<InvokeResolvedSource<SourceValue<R, K>>, Stream.Stream<any, any, any>>>] extends [never] ? never : "onElement" : never) | (SourceKind<R, K> extends "logic" | "children" ? "onSnapshot" : never);
|
|
4653
|
+
type ValidateObjectInvoke<I, R> = I extends ReadonlyArray<unknown> ? {
|
|
4654
|
+
readonly [K in keyof I]: ValidateObjectInvoke<I[K], R>;
|
|
4655
|
+
} : I extends {
|
|
4656
|
+
/** Name of the source registered in make. */
|
|
4657
|
+
readonly src: infer Src extends PropertyKey;
|
|
4658
|
+
} ? {
|
|
4659
|
+
readonly [K in keyof I]: K extends AllowedInvokeChannels<R, Src> ? ValidateObjectTransition<I[K]> : K extends "src" | "id" | "address" | "input" ? unknown : never;
|
|
4660
|
+
} : never;
|
|
4661
|
+
type ObjectDeclarations<C> = Extract<keyof C, "on" | "always" | "onDone" | "choice" | "invoke"> | (C extends {
|
|
4662
|
+
readonly states: infer Children;
|
|
4663
|
+
} ? {
|
|
4664
|
+
readonly [K in keyof Children]: ObjectDeclarations<Children[K]>;
|
|
4665
|
+
}[keyof Children] : never);
|
|
4666
|
+
type ValidateObjectConfig<C, R> = [ObjectDeclarations<C>] extends [never] ? unknown : {
|
|
4667
|
+
readonly [K in keyof C]: K extends "states" ? {
|
|
4668
|
+
readonly [P in keyof C[K]]: ValidateObjectConfig<C[K][P], R>;
|
|
4669
|
+
} : K extends "on" ? {
|
|
4670
|
+
readonly [P in keyof C[K]]: ValidateObjectTransition<C[K][P]>;
|
|
4671
|
+
} : K extends "always" | "onDone" | "choice" ? ValidateObjectTransition<C[K]> : K extends "invoke" ? ValidateObjectInvoke<C[K], R> : unknown;
|
|
4672
|
+
};
|
|
4673
|
+
type NormalizeObjectInvoke<I, R> = I extends ReadonlyArray<unknown> ? {
|
|
4674
|
+
readonly [K in keyof I]: NormalizeObjectInvoke<I[K], R>;
|
|
4675
|
+
} : I extends {
|
|
4676
|
+
/** Name of the source registered in make. */
|
|
4677
|
+
readonly src: infer K extends PropertyKey;
|
|
4678
|
+
} ? Omit<I, "src"> & ResolvedInvoke<R, K> : I;
|
|
4679
|
+
type NormalizeObjectConfig<C, R> = [SourceKeys<R>] extends [never] ? C : {
|
|
4680
|
+
readonly [K in keyof C]: K extends "states" ? {
|
|
4681
|
+
readonly [P in keyof C[K]]: NormalizeObjectConfig<C[K][P], R>;
|
|
4682
|
+
} : K extends "invoke" ? NormalizeObjectInvoke<C[K], R> : C[K];
|
|
4683
|
+
};
|
|
4684
|
+
type HandlerShape<C, H> = {
|
|
4685
|
+
readonly [K in keyof C]: K extends keyof H ? K extends "states" ? {
|
|
4686
|
+
readonly [P in keyof C[K]]: P extends keyof NonNullable<H[K]> ? HandlerShape<C[K][P], NonNullable<NonNullable<H[K]>[P]>> : never;
|
|
4687
|
+
} : H[K] : never;
|
|
4688
|
+
} & Omit<H, keyof C>;
|
|
4689
|
+
/**
|
|
4690
|
+
* Adds object handlers while checking topology, protocols, invocation outcomes, and readiness.
|
|
4621
4691
|
*
|
|
4622
4692
|
* @category combinators
|
|
4623
|
-
* @since 0.
|
|
4693
|
+
* @since 0.34.0
|
|
4624
4694
|
*/
|
|
4625
|
-
interface Handler<
|
|
4626
|
-
<const
|
|
4627
|
-
readonly "": NoInfer<
|
|
4628
|
-
}>["outputState"], StateIdentifier<
|
|
4629
|
-
readonly "":
|
|
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> {
|
|
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, {
|
|
4697
|
+
readonly "": NormalizeObjectConfig<NoInfer<C>, R>;
|
|
4698
|
+
}>["outputState"], StateIdentifier<S>>>): HandleTreeResult<S, Ev, Em, I, StateIdentifier<S>, never, never, IE, IR, Final, Out, never, In, Pa, {
|
|
4699
|
+
readonly "": NormalizeObjectConfig<C, R>;
|
|
4630
4700
|
}>;
|
|
4631
4701
|
}
|
|
4632
4702
|
/**
|
|
@@ -4650,12 +4720,19 @@ export declare namespace Machine {
|
|
|
4650
4720
|
* @since 0.4.0
|
|
4651
4721
|
*/
|
|
4652
4722
|
interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
4723
|
+
/** Runs synchronously on entry and may enqueue commands. */
|
|
4653
4724
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4725
|
+
/** Runs synchronously on exit and may enqueue commands. */
|
|
4654
4726
|
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4727
|
+
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4655
4728
|
readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>;
|
|
4729
|
+
/** Eventless transition evaluated during stabilization. */
|
|
4656
4730
|
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4731
|
+
/** Handles successful invocation or state completion with its exact output type. */
|
|
4657
4732
|
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4733
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
4658
4734
|
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
|
|
4735
|
+
/** Event handlers keyed by the public or internal event tag. */
|
|
4659
4736
|
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
|
|
4660
4737
|
}
|
|
4661
4738
|
/**
|
|
@@ -4691,6 +4768,7 @@ export declare namespace Snapshot {
|
|
|
4691
4768
|
} ? State | (State extends {
|
|
4692
4769
|
readonly state: infer Child;
|
|
4693
4770
|
} ? Node<Child> : State extends {
|
|
4771
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4694
4772
|
readonly states: infer Regions;
|
|
4695
4773
|
} ? Node<Regions[keyof Regions]> : never) : never;
|
|
4696
4774
|
/** Every valid absolute path in a logical snapshot type. */
|
|
@@ -4738,24 +4816,23 @@ export declare const isMachine: (u: unknown) => u is Machine.Any;
|
|
|
4738
4816
|
*/
|
|
4739
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>;
|
|
4740
4818
|
/**
|
|
4741
|
-
* Defines
|
|
4819
|
+
* Defines root or nested state schemas while preserving the exact child topology.
|
|
4742
4820
|
*
|
|
4743
|
-
*
|
|
4744
|
-
*
|
|
4745
|
-
*
|
|
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.
|
|
4746
4824
|
*
|
|
4747
4825
|
* **Example** (Repeated compound state)
|
|
4748
4826
|
*
|
|
4749
4827
|
* ```ts
|
|
4750
|
-
* import { Schema } from "effect"
|
|
4751
4828
|
* import { Machine } from "@typeonce/effect-machine"
|
|
4829
|
+
* import { Schema } from "effect"
|
|
4752
4830
|
*
|
|
4753
4831
|
* const TradingState = Schema.TaggedUnion({
|
|
4754
4832
|
* InSession: {},
|
|
4755
4833
|
* Applying: {}
|
|
4756
4834
|
* })
|
|
4757
4835
|
* const TradingSlot = Machine.state({
|
|
4758
|
-
* initial: "Idle",
|
|
4759
4836
|
* states: {
|
|
4760
4837
|
* Idle: {},
|
|
4761
4838
|
* InSession: TradingState.cases.InSession,
|
|
@@ -4763,17 +4840,83 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
4763
4840
|
* }
|
|
4764
4841
|
* })
|
|
4765
4842
|
*
|
|
4766
|
-
* const States = Machine.state({
|
|
4767
|
-
*
|
|
4768
|
-
*
|
|
4769
|
-
*
|
|
4843
|
+
* const States = Machine.state({
|
|
4844
|
+
* states: {
|
|
4845
|
+
* slot1: TradingSlot,
|
|
4846
|
+
* slot2: TradingSlot
|
|
4847
|
+
* }
|
|
4848
|
+
* })
|
|
4770
4849
|
* ```
|
|
4771
4850
|
*
|
|
4772
4851
|
* @category constructors
|
|
4773
4852
|
* @since 0.15.0
|
|
4774
4853
|
*/
|
|
4775
4854
|
export declare const state: StateConstructor;
|
|
4776
|
-
|
|
4855
|
+
/**
|
|
4856
|
+
* An opaque reference to one node in a declared state tree.
|
|
4857
|
+
*
|
|
4858
|
+
* @category models
|
|
4859
|
+
* @since 0.34.0
|
|
4860
|
+
*/
|
|
4861
|
+
export interface TargetReference<Root extends Machine.StateNodeConfig, Path extends string, Kind extends "state" | "choice" | "history"> {
|
|
4862
|
+
readonly [internal.TargetReferenceTypeId]: {
|
|
4863
|
+
readonly root: {
|
|
4864
|
+
readonly node: Root;
|
|
4865
|
+
};
|
|
4866
|
+
readonly path: Path;
|
|
4867
|
+
readonly kind: Kind;
|
|
4868
|
+
};
|
|
4869
|
+
}
|
|
4870
|
+
type TargetReferenceTree<Root extends Machine.StateNodeConfig, Node, Path extends string> = TargetReference<Root, Path, Node extends {
|
|
4871
|
+
readonly type: "history";
|
|
4872
|
+
} ? "history" : Node extends {
|
|
4873
|
+
readonly type: "choice";
|
|
4874
|
+
} ? "choice" : "state"> & (Node extends {
|
|
4875
|
+
/** Child handlers nested according to the declared root topology. */
|
|
4876
|
+
readonly states: infer Children;
|
|
4877
|
+
} ? {
|
|
4878
|
+
readonly [Key in Extract<keyof Children, string>]: TargetReferenceTree<Root, Children[Key], Machine.JoinPath<Path, Key>>;
|
|
4879
|
+
} : {});
|
|
4880
|
+
/**
|
|
4881
|
+
* References for every path in a declared root tree.
|
|
4882
|
+
*
|
|
4883
|
+
* @category models
|
|
4884
|
+
* @since 0.34.0
|
|
4885
|
+
*/
|
|
4886
|
+
export interface Targets<Root extends Machine.StateNodeConfig> {
|
|
4887
|
+
/** Root data owner and the starting point for descendant state references. */
|
|
4888
|
+
readonly root: TargetReferenceTree<Root, Root, "">;
|
|
4889
|
+
}
|
|
4890
|
+
/**
|
|
4891
|
+
* Derives immutable state references from a root descriptor.
|
|
4892
|
+
*
|
|
4893
|
+
* References follow the declared tree: `targets.root.Checkout.Review`.
|
|
4894
|
+
* Creating references does not construct state values or start machine work.
|
|
4895
|
+
*
|
|
4896
|
+
* @category constructors
|
|
4897
|
+
* @since 0.34.0
|
|
4898
|
+
*/
|
|
4899
|
+
export declare const targets: <const Root extends Machine.StateNodeConfig>(root: State<Root>) => Targets<Root>;
|
|
4900
|
+
type UniqueSourceNames<F, S, T, L, C> = [
|
|
4901
|
+
Extract<keyof F, keyof S | keyof T | keyof L | keyof C> | Extract<keyof S, keyof T | keyof L | keyof C> | Extract<keyof T, keyof L | keyof C> | Extract<keyof L, keyof C>
|
|
4902
|
+
] extends [never] ? unknown : {
|
|
4903
|
+
readonly "~effect/Machine/DuplicateSourceName": never;
|
|
4904
|
+
};
|
|
4905
|
+
type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources, Branches extends Machine.BranchDefinitions<Root>> = {
|
|
4906
|
+
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
4907
|
+
readonly effects?: Effects & Machine.ValidatePrograms<Effects>;
|
|
4908
|
+
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
4909
|
+
readonly streams?: Streams & Machine.ValidatePrograms<Streams>;
|
|
4910
|
+
/** Cancellable delays, supplied as durations or functions of one required input. */
|
|
4911
|
+
readonly timers?: Timers & Machine.ValidatePrograms<Timers>;
|
|
4912
|
+
/** Logic values or functions of one required input; their Effect channels remain inferred. */
|
|
4913
|
+
readonly logic?: Logics & Machine.ValidatePrograms<Logics> & Machine.ValidateLogicSources<NoInfer<Logics>>;
|
|
4914
|
+
/** Child machine descriptors registered for state-owned invocation. */
|
|
4915
|
+
readonly children?: Children;
|
|
4916
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4917
|
+
readonly branches?: Branches & {
|
|
4918
|
+
readonly [K in keyof Branches]: ValidateTransitionBranchRecord<NoInfer<Branches[K]>>;
|
|
4919
|
+
};
|
|
4777
4920
|
/** Stable definition identifier used by inspection and visualization. */
|
|
4778
4921
|
readonly id?: string;
|
|
4779
4922
|
/** State topology and value schemas, captured by a `Machine.state` descriptor. */
|
|
@@ -4792,37 +4935,30 @@ type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends Readon
|
|
|
4792
4935
|
/** Schema used to decode input before initial-state construction. */
|
|
4793
4936
|
readonly input?: Input;
|
|
4794
4937
|
};
|
|
4795
|
-
type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined
|
|
4938
|
+
type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources, Branches extends Readonly<Record<string, Readonly<Record<string, unknown>>>>> = Definition<{
|
|
4796
4939
|
readonly "": Root;
|
|
4797
4940
|
}, readonly [...InputEvents, ...InternalEvents], Input, InitialE, InitialR, Machine.FinalStateFromDefinition<{
|
|
4798
4941
|
readonly "": Root;
|
|
4799
4942
|
}>, Machine.TerminalOutput<{
|
|
4800
4943
|
readonly "": Root;
|
|
4801
|
-
}>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration
|
|
4802
|
-
|
|
4803
|
-
readonly
|
|
4804
|
-
|
|
4805
|
-
readonly
|
|
4806
|
-
|
|
4807
|
-
readonly
|
|
4808
|
-
|
|
4809
|
-
readonly
|
|
4810
|
-
|
|
4944
|
+
}>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration>, {
|
|
4945
|
+
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
4946
|
+
readonly effects: Effects;
|
|
4947
|
+
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
4948
|
+
readonly streams: Streams;
|
|
4949
|
+
/** Cancellable delays, supplied as durations or functions of one required input. */
|
|
4950
|
+
readonly timers: Timers;
|
|
4951
|
+
/** Logic values or functions of one required input; their Effect channels remain inferred. */
|
|
4952
|
+
readonly logic: Logics;
|
|
4953
|
+
/** Child machine descriptors registered for state-owned invocation. */
|
|
4954
|
+
readonly children: Children;
|
|
4955
|
+
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4956
|
+
readonly branches: Branches;
|
|
4957
|
+
}>;
|
|
4811
4958
|
/** @inline */
|
|
4812
4959
|
interface Make {
|
|
4813
|
-
/** @param config Complete starting configuration, including root and descendant values. */
|
|
4814
|
-
<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>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration> & {
|
|
4815
|
-
/** Mutually exclusive with a complete initial configuration. */
|
|
4816
|
-
readonly initial?: never;
|
|
4817
|
-
/** Constructs the complete initial root configuration, overriding child defaults. */
|
|
4818
|
-
readonly initialConfiguration: Machine.RootConfigurationBuilderInput<NoInfer<Root>, Input["Type"]>;
|
|
4819
|
-
}): MakeResult<Root & {
|
|
4820
|
-
readonly "~effect/Machine/ExplicitInitial": true;
|
|
4821
|
-
}, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
|
|
4822
4960
|
/** @param config Complete schema-first machine definition. */
|
|
4823
|
-
<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>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration> &
|
|
4824
|
-
readonly initialConfiguration: unknown;
|
|
4825
|
-
}>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
|
|
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>;
|
|
4826
4962
|
}
|
|
4827
4963
|
/**
|
|
4828
4964
|
* Creates a schema-first machine definition.
|
|
@@ -4852,33 +4988,40 @@ interface Make {
|
|
|
4852
4988
|
* **Example** (Typed counter machine)
|
|
4853
4989
|
*
|
|
4854
4990
|
* ```ts
|
|
4855
|
-
* import { Schema } from "effect"
|
|
4856
4991
|
* import { Machine } from "@typeonce/effect-machine"
|
|
4857
|
-
*
|
|
4992
|
+
* import { Schema } from "effect"
|
|
4858
4993
|
* class Count extends Schema.TaggedClass<Count>("Count")("Count", {
|
|
4859
4994
|
* value: Schema.Number
|
|
4860
|
-
* }) {
|
|
4861
|
-
*
|
|
4995
|
+
* }) {
|
|
4996
|
+
* }
|
|
4862
4997
|
* class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
|
|
4863
4998
|
* by: Schema.Number
|
|
4864
|
-
* }) {
|
|
4865
|
-
*
|
|
4866
|
-
* const States = Machine.state({
|
|
4999
|
+
* }) {
|
|
5000
|
+
* }
|
|
5001
|
+
* const States = Machine.state({ states: { Count } })
|
|
4867
5002
|
* const Events = Machine.eventsFromSchemas(Increment)
|
|
4868
|
-
*
|
|
5003
|
+
* const targets = Machine.targets(States)
|
|
4869
5004
|
* const counter = Machine.make({
|
|
4870
5005
|
* root: States,
|
|
4871
|
-
* events: Events
|
|
4872
|
-
*
|
|
4873
|
-
*
|
|
4874
|
-
*
|
|
4875
|
-
*
|
|
4876
|
-
*
|
|
4877
|
-
*
|
|
4878
|
-
*
|
|
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
|
+
* }
|
|
5021
|
+
* }
|
|
4879
5022
|
* }
|
|
4880
5023
|
* }
|
|
4881
|
-
* }
|
|
5024
|
+
* })
|
|
4882
5025
|
* ```
|
|
4883
5026
|
*
|
|
4884
5027
|
* @see {@link state} for typed state-tree helpers.
|
|
@@ -5059,17 +5202,22 @@ export declare const emittedEventsFromSchemas: {
|
|
|
5059
5202
|
* **Example**
|
|
5060
5203
|
*
|
|
5061
5204
|
* ```ts
|
|
5062
|
-
* import { Effect, Schema } from "effect"
|
|
5063
5205
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5064
|
-
*
|
|
5065
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5066
|
-
*
|
|
5206
|
+
* import { Effect, Schema } from "effect"
|
|
5207
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5208
|
+
* }
|
|
5209
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5067
5210
|
* const machine = Machine.make({
|
|
5068
5211
|
* root: States,
|
|
5069
|
-
* events: Machine.eventsFromSchemas()
|
|
5070
|
-
*
|
|
5071
|
-
*
|
|
5072
|
-
*
|
|
5212
|
+
* events: Machine.eventsFromSchemas()
|
|
5213
|
+
* }).handle({
|
|
5214
|
+
* initial: {
|
|
5215
|
+
* target: Machine.targets(States).root.Idle
|
|
5216
|
+
* },
|
|
5217
|
+
* states: {
|
|
5218
|
+
* Idle: {}
|
|
5219
|
+
* }
|
|
5220
|
+
* })
|
|
5073
5221
|
* const encoded = Effect.gen(function*() {
|
|
5074
5222
|
* const initial = yield* Machine.planInitial(machine)
|
|
5075
5223
|
* return yield* Machine.encodeSnapshot(machine, initial.state)
|
|
@@ -5103,17 +5251,22 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
5103
5251
|
* **Example**
|
|
5104
5252
|
*
|
|
5105
5253
|
* ```ts
|
|
5106
|
-
* import { Effect, Schema } from "effect"
|
|
5107
5254
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5108
|
-
*
|
|
5109
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5110
|
-
*
|
|
5255
|
+
* import { Effect, Schema } from "effect"
|
|
5256
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5257
|
+
* }
|
|
5258
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5111
5259
|
* const machine = Machine.make({
|
|
5112
5260
|
* root: States,
|
|
5113
|
-
* events: Machine.eventsFromSchemas()
|
|
5114
|
-
*
|
|
5115
|
-
*
|
|
5116
|
-
*
|
|
5261
|
+
* events: Machine.eventsFromSchemas()
|
|
5262
|
+
* }).handle({
|
|
5263
|
+
* initial: {
|
|
5264
|
+
* target: Machine.targets(States).root.Idle
|
|
5265
|
+
* },
|
|
5266
|
+
* states: {
|
|
5267
|
+
* Idle: {}
|
|
5268
|
+
* }
|
|
5269
|
+
* })
|
|
5117
5270
|
* const roundTrip = Effect.gen(function*() {
|
|
5118
5271
|
* const initial = yield* Machine.planInitial(machine)
|
|
5119
5272
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
@@ -5130,17 +5283,16 @@ type TransitionBranchRecordError<Message extends string, Key extends PropertyKey
|
|
|
5130
5283
|
readonly "~effect/Machine/TransitionBranchRecordError": Message;
|
|
5131
5284
|
readonly key: Key;
|
|
5132
5285
|
};
|
|
5133
|
-
type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol>;
|
|
5134
|
-
type
|
|
5135
|
-
readonly [
|
|
5136
|
-
readonly target:
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
} ?
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
] extends [never] ? unknown : TransitionBranchRecordError<"Updating targets require a direct resolver", InvalidUpdatingTransitionBranchKey<Branches>> : TransitionBranchRecordError<"Branch keys must be non-empty, non-index strings", InvalidStaticTransitionBranchKey<Branches>>;
|
|
5286
|
+
type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol | `${number}` | "NaN" | "Infinity" | "-Infinity">;
|
|
5287
|
+
type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never] ? TransitionBranchRecordError<"Branch records must contain at least one branch"> : [InvalidStaticTransitionBranchKey<Branches>] extends [never] ? {
|
|
5288
|
+
readonly [K in keyof Branches]: {
|
|
5289
|
+
readonly [Extra in Exclude<keyof Branches[K], "target" | "update" | "initial" | "history" | "none" | "title">]: never;
|
|
5290
|
+
} & (Branches[K] extends {
|
|
5291
|
+
readonly title: "";
|
|
5292
|
+
} ? {
|
|
5293
|
+
readonly title: never;
|
|
5294
|
+
} : unknown);
|
|
5295
|
+
} : TransitionBranchRecordError<"Branch keys must be non-empty, non-numeric strings", InvalidStaticTransitionBranchKey<Branches>>;
|
|
5144
5296
|
/**
|
|
5145
5297
|
* Plans the initial state for a machine without executing machine commands.
|
|
5146
5298
|
*
|
|
@@ -5162,17 +5314,22 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
5162
5314
|
* **Example**
|
|
5163
5315
|
*
|
|
5164
5316
|
* ```ts
|
|
5165
|
-
* import { Effect, Schema } from "effect"
|
|
5166
5317
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5167
|
-
*
|
|
5168
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5169
|
-
*
|
|
5318
|
+
* import { Effect, Schema } from "effect"
|
|
5319
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5320
|
+
* }
|
|
5321
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5170
5322
|
* const machine = Machine.make({
|
|
5171
5323
|
* root: States,
|
|
5172
|
-
* events: Machine.eventsFromSchemas()
|
|
5173
|
-
*
|
|
5174
|
-
*
|
|
5175
|
-
*
|
|
5324
|
+
* events: Machine.eventsFromSchemas()
|
|
5325
|
+
* }).handle({
|
|
5326
|
+
* initial: {
|
|
5327
|
+
* target: Machine.targets(States).root.Idle
|
|
5328
|
+
* },
|
|
5329
|
+
* states: {
|
|
5330
|
+
* Idle: {}
|
|
5331
|
+
* }
|
|
5332
|
+
* })
|
|
5176
5333
|
* const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
|
|
5177
5334
|
* ```
|
|
5178
5335
|
*
|
|
@@ -5200,9 +5357,11 @@ export declare const planInitial: <const States extends Machine.StateSchemas, co
|
|
|
5200
5357
|
}>;
|
|
5201
5358
|
} & ({
|
|
5202
5359
|
readonly done: true;
|
|
5360
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
5203
5361
|
readonly output: Output;
|
|
5204
5362
|
} | {
|
|
5205
5363
|
readonly done: false;
|
|
5364
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
5206
5365
|
readonly output: undefined;
|
|
5207
5366
|
}), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, never>;
|
|
5208
5367
|
/**
|
|
@@ -5332,12 +5491,15 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5332
5491
|
* import { Effect, Schema } from "effect"
|
|
5333
5492
|
*
|
|
5334
5493
|
* const internalEvents = Machine.internalEventsFromSchemas(Schema.TaggedStruct("Loaded", {}))
|
|
5494
|
+
* const Root = Machine.state({ states: { Idle: {} } })
|
|
5335
5495
|
* const machine = Machine.make({
|
|
5336
|
-
* root:
|
|
5496
|
+
* root: Root,
|
|
5337
5497
|
* events: Machine.eventsFromSchemas(),
|
|
5338
|
-
* internalEvents
|
|
5339
|
-
*
|
|
5340
|
-
*
|
|
5498
|
+
* internalEvents
|
|
5499
|
+
* }).handle({
|
|
5500
|
+
* initial: { target: Machine.targets(Root).root.Idle },
|
|
5501
|
+
* states: { Idle: { on: { Loaded: { none: true } } } }
|
|
5502
|
+
* })
|
|
5341
5503
|
*
|
|
5342
5504
|
* export const canLoad = Effect.gen(function*() {
|
|
5343
5505
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -5372,27 +5534,32 @@ export declare const can: {
|
|
|
5372
5534
|
* **Example**
|
|
5373
5535
|
*
|
|
5374
5536
|
* ```ts
|
|
5375
|
-
* import { Effect, Schema } from "effect"
|
|
5376
5537
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5377
|
-
*
|
|
5378
|
-
* class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {
|
|
5379
|
-
*
|
|
5380
|
-
* class
|
|
5381
|
-
*
|
|
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 } })
|
|
5546
|
+
* const targets = Machine.targets(States)
|
|
5382
5547
|
* const machine = Machine.make({
|
|
5383
5548
|
* root: States,
|
|
5384
|
-
* events: Machine.eventsFromSchemas(Toggle)
|
|
5385
|
-
*
|
|
5386
|
-
*
|
|
5387
|
-
*
|
|
5388
|
-
* on: {
|
|
5389
|
-
* Toggle: (to) =>
|
|
5390
|
-
* to.branch.On().resolve(({ target }) => target.from())
|
|
5391
|
-
* }
|
|
5549
|
+
* events: Machine.eventsFromSchemas(Toggle)
|
|
5550
|
+
* }).handle({
|
|
5551
|
+
* initial: {
|
|
5552
|
+
* target: Machine.targets(States).root.Off
|
|
5392
5553
|
* },
|
|
5393
|
-
*
|
|
5394
|
-
*
|
|
5395
|
-
*
|
|
5554
|
+
* states: {
|
|
5555
|
+
* Off: {
|
|
5556
|
+
* on: {
|
|
5557
|
+
* Toggle: { target: targets.root.On }
|
|
5558
|
+
* }
|
|
5559
|
+
* },
|
|
5560
|
+
* On: {}
|
|
5561
|
+
* }
|
|
5562
|
+
* })
|
|
5396
5563
|
* const nextState = Effect.gen(function*() {
|
|
5397
5564
|
* const initial = yield* Machine.planInitial(machine)
|
|
5398
5565
|
* return (yield* Machine.plan(machine, initial.state, new Toggle({}))).next
|
|
@@ -5422,9 +5589,11 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
5422
5589
|
}>;
|
|
5423
5590
|
} & ({
|
|
5424
5591
|
readonly done: true;
|
|
5592
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
5425
5593
|
readonly output: Output;
|
|
5426
5594
|
} | {
|
|
5427
5595
|
readonly done: false;
|
|
5596
|
+
/** Constructs the decoded output declared by the state schema. */
|
|
5428
5597
|
readonly output: undefined;
|
|
5429
5598
|
}), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
|
|
5430
5599
|
/**
|
|
@@ -5456,6 +5625,7 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
5456
5625
|
* @since 0.4.0
|
|
5457
5626
|
*/
|
|
5458
5627
|
export declare const logic: <State, Event = never, Output = void, Error = never, Requirements = never, InitialError = never, InitialRequirements = never>(options: {
|
|
5628
|
+
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
5459
5629
|
readonly initial: State | ((scope: Logic.Scope<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
|
|
5460
5630
|
readonly run: (context: Logic.Context<State, Event>) => Effect.Effect<Output, Error, Requirements>;
|
|
5461
5631
|
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError>;
|
|
@@ -5503,7 +5673,7 @@ export declare const childAddress: <Event = never>(id: string) => ChildAddress<E
|
|
|
5503
5673
|
* This Effect requires a managed process runtime. A named child id must be
|
|
5504
5674
|
* unique for the current parent until that child stops.
|
|
5505
5675
|
*
|
|
5506
|
-
*
|
|
5676
|
+
* Register logic in `make({ logic })` and use `invoke: { src, id, address, ...outcomes }` for children
|
|
5507
5677
|
* that start and stop with that state.
|
|
5508
5678
|
* @see {@link sendTo} for sending events to named children.
|
|
5509
5679
|
* @category runtime
|
|
@@ -5588,17 +5758,22 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
|
|
|
5588
5758
|
* **Example**
|
|
5589
5759
|
*
|
|
5590
5760
|
* ```ts
|
|
5591
|
-
* import { Effect, Schema } from "effect"
|
|
5592
5761
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5593
|
-
*
|
|
5594
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5595
|
-
*
|
|
5762
|
+
* import { Effect, Schema } from "effect"
|
|
5763
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5764
|
+
* }
|
|
5765
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5596
5766
|
* const machine = Machine.make({
|
|
5597
5767
|
* root: States,
|
|
5598
|
-
* events: Machine.eventsFromSchemas()
|
|
5599
|
-
*
|
|
5600
|
-
*
|
|
5601
|
-
*
|
|
5768
|
+
* events: Machine.eventsFromSchemas()
|
|
5769
|
+
* }).handle({
|
|
5770
|
+
* initial: {
|
|
5771
|
+
* target: Machine.targets(States).root.Idle
|
|
5772
|
+
* },
|
|
5773
|
+
* states: {
|
|
5774
|
+
* Idle: {}
|
|
5775
|
+
* }
|
|
5776
|
+
* })
|
|
5602
5777
|
* const state = Effect.gen(function*() {
|
|
5603
5778
|
* const ref = yield* Machine.start(machine)
|
|
5604
5779
|
* return yield* ref.state
|
|
@@ -5638,17 +5813,22 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
5638
5813
|
* **Example**
|
|
5639
5814
|
*
|
|
5640
5815
|
* ```ts
|
|
5641
|
-
* import { Effect, Schema } from "effect"
|
|
5642
5816
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5643
|
-
*
|
|
5644
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5645
|
-
*
|
|
5817
|
+
* import { Effect, Schema } from "effect"
|
|
5818
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {
|
|
5819
|
+
* }
|
|
5820
|
+
* const States = Machine.state({ states: { Idle } })
|
|
5646
5821
|
* const machine = Machine.make({
|
|
5647
5822
|
* root: States,
|
|
5648
|
-
* events: Machine.eventsFromSchemas()
|
|
5649
|
-
*
|
|
5650
|
-
*
|
|
5651
|
-
*
|
|
5823
|
+
* events: Machine.eventsFromSchemas()
|
|
5824
|
+
* }).handle({
|
|
5825
|
+
* initial: {
|
|
5826
|
+
* target: Machine.targets(States).root.Idle
|
|
5827
|
+
* },
|
|
5828
|
+
* states: {
|
|
5829
|
+
* Idle: {}
|
|
5830
|
+
* }
|
|
5831
|
+
* })
|
|
5652
5832
|
* const resumed = Effect.gen(function*() {
|
|
5653
5833
|
* const initial = yield* Machine.planInitial(machine)
|
|
5654
5834
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|