@typeonce/effect-machine 0.31.1 → 0.32.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 +145 -140
- package/dist/Machine.d.ts +428 -254
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +91 -111
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +3 -4
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +0 -2
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/childRegistry.d.ts +52 -0
- package/dist/internal/machine/childRegistry.d.ts.map +1 -0
- package/dist/internal/machine/childRegistry.js +74 -0
- package/dist/internal/machine/childRegistry.js.map +1 -0
- package/dist/internal/machine/cluster.d.ts +2 -3
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +14 -4
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +1 -0
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +97 -53
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +4 -2
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationDefinition.d.ts +35 -0
- package/dist/internal/machine/invocationDefinition.d.ts.map +1 -0
- package/dist/internal/machine/invocationDefinition.js +21 -0
- package/dist/internal/machine/invocationDefinition.js.map +1 -0
- package/dist/internal/machine/invocationEvent.d.ts +0 -2
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +0 -8
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +21 -43
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +98 -374
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +13 -19
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +71 -39
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +6 -8
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +1 -0
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +2 -2
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +4 -18
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/readiness.d.ts +1 -1
- package/dist/internal/machine/readiness.d.ts.map +1 -1
- package/dist/internal/machine/requirements.d.ts +4 -0
- package/dist/internal/machine/requirements.d.ts.map +1 -0
- package/dist/internal/machine/requirements.js +2 -0
- package/dist/internal/machine/requirements.js.map +1 -0
- package/dist/internal/machine/runtime.d.ts +4 -58
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +1 -69
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/serialization.d.ts.map +1 -1
- package/dist/internal/machine/serialization.js +16 -0
- package/dist/internal/machine/serialization.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts +3 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +36 -2
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/targetBuilder.d.ts +16 -0
- package/dist/internal/machine/targetBuilder.d.ts.map +1 -0
- package/dist/internal/machine/targetBuilder.js +333 -0
- package/dist/internal/machine/targetBuilder.js.map +1 -0
- package/dist/internal/machine/topology.js +3 -3
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/machine/transition.d.ts +16 -0
- package/dist/internal/machine/transition.d.ts.map +1 -0
- package/dist/internal/machine/transition.js +2 -0
- package/dist/internal/machine/transition.js.map +1 -0
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +10 -12
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/format.d.ts +7 -0
- package/dist/internal/testing/machine/format.d.ts.map +1 -0
- package/dist/internal/testing/machine/format.js +104 -0
- package/dist/internal/testing/machine/format.js.map +1 -0
- package/dist/internal/testing/machine/probe.d.ts +1 -1
- package/dist/internal/testing/machine/probe.d.ts.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/referenceModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/referenceModel.js +15 -19
- package/dist/internal/testing/machine/referenceModel.js.map +1 -1
- package/dist/internal/testing/machine/trace.d.ts +1 -1
- package/dist/internal/testing/machine/trace.d.ts.map +1 -1
- package/dist/internal/testing/machine/trace.js +3 -3
- package/dist/internal/testing/machine/trace.js.map +1 -1
- package/dist/internal/testing/machine/value.d.ts +8 -0
- package/dist/internal/testing/machine/value.d.ts.map +1 -0
- package/dist/internal/testing/machine/value.js +82 -0
- package/dist/internal/testing/machine/value.js.map +1 -0
- package/dist/internal/testing/machine/verification.d.ts +2 -13
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +21 -113
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +89 -104
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +70 -84
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +10 -13
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +5 -8
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +26 -61
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +17 -26
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +45 -45
- package/docs/effect-atom-react.md +35 -63
- package/docs/machine-review.md +7 -7
- package/docs/root-api.md +214 -0
- package/package.json +1 -1
- package/src/Machine.ts +778 -437
- package/src/internal/machine/atom.ts +3 -13
- package/src/internal/machine/childRegistry.ts +141 -0
- package/src/internal/machine/cluster.ts +5 -14
- package/src/internal/machine/configuration.ts +20 -4
- package/src/internal/machine/executionPlan.ts +109 -52
- package/src/internal/machine/invocation.ts +10 -6
- package/src/internal/machine/invocationDefinition.ts +52 -0
- package/src/internal/machine/invocationEvent.ts +0 -8
- package/src/internal/machine/machine.ts +154 -679
- package/src/internal/machine/planner.ts +82 -66
- package/src/internal/machine/process.ts +14 -21
- package/src/internal/machine/protocol.ts +9 -32
- package/src/internal/machine/readiness.ts +1 -0
- package/src/internal/machine/requirements.ts +11 -0
- package/src/internal/machine/runtime.ts +17 -186
- package/src/internal/machine/serialization.ts +22 -0
- package/src/internal/machine/stateDefinition.ts +36 -3
- package/src/internal/machine/targetBuilder.ts +525 -0
- package/src/internal/machine/topology.ts +3 -3
- package/src/internal/machine/transition.ts +26 -0
- package/src/internal/testing/machine/finiteModel.ts +22 -23
- package/src/internal/testing/machine/format.ts +120 -0
- package/src/internal/testing/machine/probe.ts +4 -4
- package/src/internal/testing/machine/referenceModel.ts +25 -17
- package/src/internal/testing/machine/trace.ts +4 -4
- package/src/internal/testing/machine/value.ts +77 -0
- package/src/internal/testing/machine/verification.ts +904 -1109
- package/src/testing/MachineTest.ts +103 -114
- package/src/unstable/cluster/ClusterMachine.ts +10 -20
- package/src/unstable/reactivity/AtomMachine.ts +42 -79
package/dist/Machine.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type { ChildAlreadyExistsError, InfiniteTransitionError, MachineSchemaDec
|
|
|
18
18
|
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
|
+
import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js";
|
|
21
22
|
import type * as internalRuntime from "./internal/machine/runtime.js";
|
|
22
23
|
import type * as StateDefinition from "./internal/machine/stateDefinition.js";
|
|
23
24
|
import type * as Topology from "./internal/machine/topology.js";
|
|
@@ -109,6 +110,8 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
109
110
|
* @since 0.4.0
|
|
110
111
|
*/
|
|
111
112
|
readonly states: States;
|
|
113
|
+
/** Root descriptor for topology and snapshot access. */
|
|
114
|
+
readonly root: State<Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, Machine.StateNodeConfig>>;
|
|
112
115
|
/**
|
|
113
116
|
* Events accepted through public machine input boundaries.
|
|
114
117
|
*
|
|
@@ -186,15 +189,15 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
|
|
|
186
189
|
* **Example**
|
|
187
190
|
*
|
|
188
191
|
* ```ts
|
|
189
|
-
* const counter = definition.handle({
|
|
192
|
+
* const counter = definition.handle({ states: {
|
|
190
193
|
* Count: {
|
|
191
194
|
* on: {
|
|
192
195
|
* Increment: (to) =>
|
|
193
|
-
* to.
|
|
196
|
+
* to.branch.Count().resolve(({ event, state, target }) =>
|
|
194
197
|
* target.decoded(new Count({ value: state.value + event.by })))
|
|
195
198
|
* }
|
|
196
199
|
* }
|
|
197
|
-
* })
|
|
200
|
+
* } })
|
|
198
201
|
* ```
|
|
199
202
|
*
|
|
200
203
|
* @since 0.4.0
|
|
@@ -485,7 +488,6 @@ export declare namespace Runtime {
|
|
|
485
488
|
};
|
|
486
489
|
}
|
|
487
490
|
}
|
|
488
|
-
type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? Requirements : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : Requirements;
|
|
489
491
|
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;
|
|
490
492
|
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
491
493
|
declare const TransitionTypeId: typeof internal.TransitionTypeId;
|
|
@@ -552,37 +554,58 @@ type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children ex
|
|
|
552
554
|
type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
|
|
553
555
|
readonly type: infer Type;
|
|
554
556
|
} ? 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;
|
|
555
|
-
type DefineStateTreeInput<States extends Machine.StateSchemas> = {
|
|
556
|
-
readonly [Key in keyof States]: DefineStateNodeInput<States[Key]>;
|
|
557
|
-
};
|
|
558
|
-
type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Node extends Machine.HistoryStateNodeConfig ? Machine.HistoryStateNodeConfig : Node extends Machine.ChoiceStateNodeConfig ? Machine.ChoiceStateNodeConfig : Node extends {
|
|
559
|
-
readonly type: "parallel";
|
|
560
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
561
|
-
} ? Omit<Node, "states"> & {
|
|
562
|
-
readonly states: DefineStateTreeInput<Children>;
|
|
563
|
-
} : Node extends {
|
|
564
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
565
|
-
} ? Omit<Node, "initial" | "states"> & {
|
|
566
|
-
readonly initial: ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
567
|
-
readonly states: DefineStateTreeInput<Children>;
|
|
568
|
-
} : Node;
|
|
569
|
-
type ValidateDefinedStates<States extends Machine.StateSchemas> = [States] extends [
|
|
570
|
-
Machine.ValidateStateSchemas<States>
|
|
571
|
-
] ? [] : [validation: Machine.ValidateStateSchemas<States>];
|
|
572
|
-
type InvalidDefinedStateTreeInput<States extends Machine.StateSchemas> = [States] extends [
|
|
573
|
-
Machine.ValidateStateSchemas<States>
|
|
574
|
-
] ? never : States & Machine.ValidateStateSchemas<States>;
|
|
575
557
|
type ReusableStateNodeConfig = Machine.AtomicStateNodeConfig | Machine.CompoundStateNodeConfig | Machine.ParallelStateNodeConfig;
|
|
576
558
|
type ReusableStateValidation<Node> = Node extends ReusableStateNodeConfig ? ValidateStateNode<Node, false, "state"> : StateDefinitionError<"Reusable states must be active state nodes", "state">;
|
|
577
559
|
type ValidateDefinedState<Node> = [Node] extends [ReusableStateValidation<Node>] ? [] : [validation: ReusableStateValidation<Node>];
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
560
|
+
declare const StateTypeId = "~effect/Machine/State";
|
|
561
|
+
/** An immutable state descriptor, usable as a root or a nested state.
|
|
562
|
+
* @category models
|
|
563
|
+
* @since 0.32.0
|
|
564
|
+
*/
|
|
565
|
+
export interface State<Node extends Machine.StateNodeConfig> extends Machine.StateAccessors<{
|
|
566
|
+
readonly "": Node;
|
|
567
|
+
}> {
|
|
568
|
+
readonly [StateTypeId]: typeof StateTypeId;
|
|
569
|
+
readonly node: Node;
|
|
582
570
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
571
|
+
type NormalizeState<Node, Tag extends string = ""> = Node extends {
|
|
572
|
+
readonly [StateTypeId]: typeof StateTypeId;
|
|
573
|
+
readonly node: infer Config;
|
|
574
|
+
} ? Config : Node extends Machine.TaggedSchema ? Node : "fields" extends keyof Node ? NormalizeStateFields<Node, Tag> : Node extends {
|
|
575
|
+
readonly states: infer Children;
|
|
576
|
+
} ? Children extends Readonly<Record<string, Machine.TaggedSchema>> ? Node : NormalizeStateFields<Node, Tag> : Node;
|
|
577
|
+
type NormalizeStateFields<Node, Tag extends string> = {
|
|
578
|
+
readonly [Key in keyof Node as Key extends "fields" ? "schema" : Key]: Key extends "fields" ? Node[Key] extends Schema.Struct.Fields ? Schema.TaggedStruct<Tag, Node[Key]> : never : Key extends "states" ? {
|
|
579
|
+
readonly [Child in keyof Node[Key]]: NormalizeState<Node[Key][Child], Extract<Child, string>>;
|
|
580
|
+
} : Node[Key];
|
|
581
|
+
};
|
|
582
|
+
type NormalizedState<Node> = Extract<NormalizeState<Node>, Machine.StateNodeConfig>;
|
|
583
|
+
type StateFieldsValidation<Node> = Node extends {
|
|
584
|
+
readonly [StateTypeId]: typeof StateTypeId;
|
|
585
|
+
} | Machine.TaggedSchema ? unknown : (Node extends {
|
|
586
|
+
readonly fields: infer Fields;
|
|
587
|
+
} ? "schema" extends keyof Node ? StateDefinitionError<"Declare fields or schema, not both", ""> : Fields extends Schema.Struct.Fields ? "_tag" extends keyof Fields ? StateDefinitionError<"State fields cannot declare _tag", ""> : unknown : StateDefinitionError<"State fields must be schema fields", ""> : unknown) & (Node extends {
|
|
588
|
+
readonly states: infer Children;
|
|
589
|
+
} ? {
|
|
590
|
+
readonly states: {
|
|
591
|
+
readonly [Key in keyof Children]: StateFieldsValidation<Children[Key]>;
|
|
592
|
+
};
|
|
593
|
+
} : unknown);
|
|
594
|
+
interface StateInput {
|
|
595
|
+
readonly schema?: Machine.TaggedSchema;
|
|
596
|
+
readonly fields?: Schema.Struct.Fields;
|
|
597
|
+
readonly type?: "active" | "parallel" | "final" | "history" | "choice";
|
|
598
|
+
readonly initial?: string;
|
|
599
|
+
readonly states?: Readonly<Record<string, Machine.TaggedSchema | StateInput | {
|
|
600
|
+
readonly [StateTypeId]: typeof StateTypeId;
|
|
601
|
+
readonly node: Machine.StateNodeConfig;
|
|
602
|
+
}>>;
|
|
603
|
+
readonly history?: "shallow" | "deep";
|
|
604
|
+
readonly output?: Schema.Top;
|
|
605
|
+
readonly annotations?: Machine.SchemaLessStateAnnotations;
|
|
606
|
+
}
|
|
607
|
+
interface StateConstructor {
|
|
608
|
+
<const Node extends StateInput>(node: Node & StateFieldsValidation<NoInfer<Node>>, ..._validation: ValidateDefinedState<NormalizeState<NoInfer<Node>>>): State<NormalizedState<Node>>;
|
|
586
609
|
}
|
|
587
610
|
type EventProtocolError<Message extends string, Tag extends PropertyKey = never> = {
|
|
588
611
|
readonly "~effect/Machine/EventProtocolError": Message;
|
|
@@ -593,7 +616,6 @@ type DuplicateEventTag<Events extends ReadonlyArray<Machine.TaggedSchema>, Seen
|
|
|
593
616
|
...infer Tail extends ReadonlyArray<Machine.TaggedSchema>
|
|
594
617
|
] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ? Extract<Tag, Seen> | DuplicateEventTag<Tail, Seen | Tag> : never : never;
|
|
595
618
|
type ValidateInputEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInput extends PropertyKey = DuplicateEventTag<InputEvents>> = [DuplicateInput] extends [never] ? unknown : EventProtocolError<"Public event tags must be unique", DuplicateInput>;
|
|
596
|
-
type ValidateEmittedEventProtocol<EmittedEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateEmitted extends PropertyKey = DuplicateEventTag<EmittedEvents>> = [DuplicateEmitted] extends [never] ? unknown : EventProtocolError<"Emitted event tags must be unique", DuplicateEmitted>;
|
|
597
619
|
type ValidateInternalEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInternal extends PropertyKey = DuplicateEventTag<InternalEvents>, Overlap extends PropertyKey = Extract<Machine.TagOf<InputEvents[number]>, Machine.TagOf<InternalEvents[number]>>> = [DuplicateInternal] extends [never] ? [Overlap] extends [never] ? unknown : EventProtocolError<"Public and internal event tags must be disjoint", Overlap> : EventProtocolError<"Internal event tags must be unique", DuplicateInternal>;
|
|
598
620
|
type ValidateEventProtocolBuilder<Kind extends Machine.EventProtocolKind, Inputs extends ReadonlyArray<Machine.EventProtocolInput<Kind>>, Schemas extends ReadonlyArray<Machine.TaggedSchema> = Machine.EventProtocolInputSchemasOf<Kind, Inputs>, Duplicate extends PropertyKey = DuplicateEventTag<Schemas>> = [Duplicate] extends [never] ? unknown : EventProtocolError<"Event protocol tags must be unique", Duplicate>;
|
|
599
621
|
declare const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId;
|
|
@@ -606,7 +628,7 @@ type FromCallable<Arguments extends ReadonlyArray<unknown>, Result> = Arguments
|
|
|
606
628
|
(...args: Rest): Result;
|
|
607
629
|
(...args: Arguments): Result;
|
|
608
630
|
} : (...args: Arguments) => Result : (...args: Arguments) => Result;
|
|
609
|
-
type FromMethod<Arguments extends ReadonlyArray<unknown>, Result> = {
|
|
631
|
+
type FromMethod<in out Arguments extends ReadonlyArray<unknown>, out Result> = {
|
|
610
632
|
/**
|
|
611
633
|
* Constructs the selected state from its schema make input while the
|
|
612
634
|
* machine plans the resulting configuration. The input may be omitted when
|
|
@@ -716,12 +738,14 @@ type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends
|
|
|
716
738
|
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
717
739
|
}, true>>;
|
|
718
740
|
};
|
|
719
|
-
type FullSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
|
|
720
|
-
readonly [Key in ActiveStateKey<States>]: FullSnapshotMethod<States, Key, Prefix
|
|
721
|
-
}
|
|
722
|
-
|
|
741
|
+
type FullSnapshotBuilderWithPrefix<in out States extends Machine.StateSchemas, in out Prefix extends string = ""> = {
|
|
742
|
+
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]: Key extends ActiveStateKey<States> ? FullSnapshotMethod<States, Key, Prefix> : () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
743
|
+
};
|
|
744
|
+
type FullSnapshotMethod<in out States extends Machine.StateSchemas, in out StateId extends ActiveStateKey<States>, in out Prefix extends string> = {
|
|
745
|
+
readonly [
|
|
746
|
+
/** Constructs this node using schema make input or an already decoded value. */
|
|
747
|
+
Method in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"]: Method extends "from" ? FromCallable<FullSnapshotFromArguments<States, StateId, Prefix>, Machine.StateConstruction<FullSnapshotResult<States, StateId, Prefix>>> : (...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>;
|
|
723
748
|
};
|
|
724
|
-
type FullSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = Machine.NodeSchema<States[StateId]> extends never ? FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>> : DecodedMethod<FullSnapshotArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>> & FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>>;
|
|
725
749
|
type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
726
750
|
readonly type: "parallel";
|
|
727
751
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
@@ -784,18 +808,20 @@ type HistorySnapshotResult<States extends Machine.StateSchemas, StateId extends
|
|
|
784
808
|
} ? Machine.ParallelSnapshot<Path, NodeValue<Node>, HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
|
|
785
809
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
786
810
|
} ? Machine.CompoundSnapshot<Path, NodeValue<Node>, HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
|
|
787
|
-
type HistorySnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string> =
|
|
811
|
+
type HistorySnapshotMethod<in out States extends Machine.StateSchemas, in out StateId extends ActiveStateKey<States>, in out Prefix extends string, in out Owner extends string> = {
|
|
812
|
+
readonly [Key in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"]: Key extends "from" ? FromCallable<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, Machine.StateConstruction<HistorySnapshotResult<States, StateId, Prefix, Owner>>> : (...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>;
|
|
813
|
+
};
|
|
788
814
|
type HistorySnapshotWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string> = {
|
|
789
|
-
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
|
|
815
|
+
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
|
|
790
816
|
}[ActiveStateKey<States>];
|
|
791
817
|
type HistorySnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string = ""> = {
|
|
792
|
-
readonly [Key in ActiveStateKey<States> as Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? Key : never]: HistorySnapshotMethod<States, Key, Prefix, Owner>;
|
|
818
|
+
readonly [Key in ActiveStateKey<States> as Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? Key : never]: HistorySnapshotMethod<States, Key, Prefix, Owner>;
|
|
793
819
|
};
|
|
794
820
|
type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends string, Owner extends string> = {
|
|
795
|
-
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
|
|
821
|
+
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
|
|
796
822
|
};
|
|
797
823
|
type HistoryParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Owner extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
798
|
-
readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? NodeBuilderMethod<States[Key], HistorySnapshotArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
824
|
+
readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? NodeBuilderMethod<States[Key], HistorySnapshotArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
799
825
|
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
800
826
|
}, Constructed>, HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
801
827
|
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
@@ -805,7 +831,7 @@ type HistoryParallelBuilder<States extends Machine.StateSchemas, Prefix extends
|
|
|
805
831
|
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
806
832
|
}, true>>;
|
|
807
833
|
};
|
|
808
|
-
type ParentPath<Path extends string> = Path
|
|
834
|
+
type ParentPath<Path extends string> = Machine.ImmediateParentStateIdentifier<Path>;
|
|
809
835
|
type IsCompoundNode<Node> = Node extends {
|
|
810
836
|
readonly type: "parallel";
|
|
811
837
|
} ? false : Node extends {
|
|
@@ -832,7 +858,7 @@ type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States
|
|
|
832
858
|
type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
833
859
|
readonly type: "parallel";
|
|
834
860
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
835
|
-
} ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>, Path> : NodeMethodWithInitial<Node, WithNodeValue<Node, [
|
|
861
|
+
} ? Source extends Path | (Path extends "" ? string : `${Path}.${string}`) ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>, Path> : NodeMethodWithInitial<Node, WithNodeValue<Node, [
|
|
836
862
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
837
863
|
]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
|
|
838
864
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
@@ -867,7 +893,7 @@ type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, State
|
|
|
867
893
|
type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
868
894
|
readonly type: "parallel";
|
|
869
895
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
870
|
-
} ? Source extends Path | `${Path}.${string}` ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>, Path> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethodWithInitial<Node, WithNodeValue<Node, [
|
|
896
|
+
} ? Source extends Path | (Path extends "" ? string : `${Path}.${string}`) ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>, Path> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethodWithInitial<Node, WithNodeValue<Node, [
|
|
871
897
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
872
898
|
]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
|
|
873
899
|
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
@@ -894,16 +920,19 @@ type HasDirectShallowHistory<States extends Machine.StateSchemas> = {
|
|
|
894
920
|
readonly history: "deep";
|
|
895
921
|
} ? never : Key;
|
|
896
922
|
}[HistoryStateKey<States>] extends never ? false : true;
|
|
897
|
-
type
|
|
898
|
-
|
|
923
|
+
type RequiresInitialValue<Node> = Machine.NodeSchema<Node> extends never ? false : {} extends NodeMakeInput<Node> ? false : true;
|
|
924
|
+
type HasRequiredActiveChild<States extends Machine.StateSchemas> = {
|
|
925
|
+
readonly [Key in ActiveStateKey<States>]: RequiresInitialValue<States[Key]> extends true ? Key : never;
|
|
899
926
|
}[ActiveStateKey<States>] extends never ? false : true;
|
|
900
927
|
type InitializerClosureForNode<AllStates extends Machine.StateSchemas, Node, Path extends string> = Node extends {
|
|
928
|
+
readonly states: infer Declared extends Machine.StateSchemas;
|
|
929
|
+
} ? string extends keyof Declared ? never : Node extends {
|
|
901
930
|
readonly type: "parallel";
|
|
902
931
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
903
|
-
} ? (
|
|
932
|
+
} ? (HasRequiredActiveChild<Children> extends true ? Extract<Path, Machine.StateIdentifier<AllStates>> : never) | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
|
|
904
933
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
905
934
|
readonly initial: infer Initial;
|
|
906
|
-
} ? (Initial extends ActiveStateKey<Children> ?
|
|
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;
|
|
907
936
|
type InitializerClosuresForChildren<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
908
937
|
readonly [Key in ActiveStateKey<States>]: InitializerClosureForNode<AllStates, States[Key], Machine.JoinPath<Prefix, Key>>;
|
|
909
938
|
}[ActiveStateKey<States>];
|
|
@@ -1416,7 +1445,7 @@ export declare namespace ChildMachine {
|
|
|
1416
1445
|
* @category utility types
|
|
1417
1446
|
* @since 0.20.0
|
|
1418
1447
|
*/
|
|
1419
|
-
type StartRequirements<Child extends Any> = Child extends ChildMachine<string, infer M> ? Exclude<ExcludeCompatibleRuntime<Exclude<ExecutionServices<Machine.InitialServices<M> | Machine.Services<M>>, MachineRuntimeRequirement>, Machine.Event<M>, Machine.
|
|
1448
|
+
type StartRequirements<Child extends Any> = Child extends ChildMachine<string, infer M> ? Exclude<ExcludeCompatibleRuntime<Exclude<ExecutionServices<Machine.InitialServices<M> | Machine.Services<M>>, MachineRuntimeRequirement>, Machine.Event<M>, Machine.EmittedEvent<M>>, Scope.Scope> : never;
|
|
1420
1449
|
/**
|
|
1421
1450
|
* Running machine reference selected by a child descriptor.
|
|
1422
1451
|
*
|
|
@@ -1582,6 +1611,7 @@ export declare namespace Machine {
|
|
|
1582
1611
|
/** @internal */
|
|
1583
1612
|
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
1584
1613
|
readonly states: StateSchemas;
|
|
1614
|
+
readonly root: Pick<State<Machine.StateNodeConfig>, typeof StateTypeId | "node">;
|
|
1585
1615
|
readonly events: EventProtocol.Any<"public">;
|
|
1586
1616
|
readonly internalEvents: EventProtocol.Any<"internal">;
|
|
1587
1617
|
readonly emittedEvents: EventProtocol.Any<"emitted">;
|
|
@@ -1686,8 +1716,6 @@ export declare namespace Machine {
|
|
|
1686
1716
|
* @since 0.4.0
|
|
1687
1717
|
*/
|
|
1688
1718
|
type EmittedEvents<M extends Any> = M[typeof MachineTypeId]["emittedEvents"];
|
|
1689
|
-
/** @deprecated Use {@link EmittedEvents}. */
|
|
1690
|
-
type Emits<M extends Any> = EmittedEvents<M>;
|
|
1691
1719
|
/**
|
|
1692
1720
|
* Extracts state paths with implemented output handlers.
|
|
1693
1721
|
*
|
|
@@ -1814,9 +1842,7 @@ export declare namespace Machine {
|
|
|
1814
1842
|
* @category utility types
|
|
1815
1843
|
* @since 0.4.0
|
|
1816
1844
|
*/
|
|
1817
|
-
type EmittedEvent<M extends Any> = EmittedEventOf<
|
|
1818
|
-
/** @deprecated Use {@link EmittedEvent}. */
|
|
1819
|
-
type Emit<M extends Any> = EmittedEvent<M>;
|
|
1845
|
+
type EmittedEvent<M extends Any> = EmittedEventOf<EmittedEvents<M>>;
|
|
1820
1846
|
/**
|
|
1821
1847
|
* A schema whose decoded value contains a `_tag` discriminator.
|
|
1822
1848
|
*
|
|
@@ -1853,8 +1879,6 @@ export declare namespace Machine {
|
|
|
1853
1879
|
}
|
|
1854
1880
|
/** Descriptive annotations accepted by schema-less active and pseudo-states. */
|
|
1855
1881
|
type SchemaLessStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
|
|
1856
|
-
/** @deprecated Use {@link SchemaLessStateAnnotations}. */
|
|
1857
|
-
type PseudoStateAnnotations = SchemaLessStateAnnotations;
|
|
1858
1882
|
/**
|
|
1859
1883
|
* Configuration accepted for an atomic object state node.
|
|
1860
1884
|
*
|
|
@@ -2028,20 +2052,16 @@ export declare namespace Machine {
|
|
|
2028
2052
|
*/
|
|
2029
2053
|
type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>;
|
|
2030
2054
|
/**
|
|
2031
|
-
*
|
|
2055
|
+
* Typed snapshot access shared by state descriptors.
|
|
2032
2056
|
*
|
|
2033
2057
|
* **Details**
|
|
2034
2058
|
*
|
|
2035
|
-
* The
|
|
2036
|
-
* to `make`. The remaining helpers match and read snapshots for the same
|
|
2037
|
-
* state tree.
|
|
2059
|
+
* The helpers match and read snapshots for the same captured topology.
|
|
2038
2060
|
*
|
|
2039
2061
|
* @category models
|
|
2040
2062
|
* @since 0.4.0
|
|
2041
2063
|
*/
|
|
2042
|
-
interface
|
|
2043
|
-
/** Captured state tree supplied to {@link states}. */
|
|
2044
|
-
readonly states: States;
|
|
2064
|
+
interface StateAccessors<States extends StateSchemas> {
|
|
2045
2065
|
/**
|
|
2046
2066
|
* Checks and preserves one active state path from this definition.
|
|
2047
2067
|
*
|
|
@@ -2061,7 +2081,7 @@ export declare namespace Machine {
|
|
|
2061
2081
|
*/
|
|
2062
2082
|
readonly get: {
|
|
2063
2083
|
<Path extends ValuedStateIdentifier<States>>(snapshot: Snapshot<States>, path: Path): Option.Option<StateByIdentifier<States, Path>>;
|
|
2064
|
-
<const From extends StateIdentifier<States>, const Path extends ValuedStateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | `${NoInfer<From>}.${string}` ? unknown : never)): Option.Option<StateByIdentifier<States, Path>>;
|
|
2084
|
+
<const From extends StateIdentifier<States>, const Path extends ValuedStateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | (NoInfer<From> extends "" ? string : `${NoInfer<From>}.${string}`) ? unknown : never)): Option.Option<StateByIdentifier<States, Path>>;
|
|
2065
2085
|
};
|
|
2066
2086
|
/**
|
|
2067
2087
|
* Returns the decoded value for an active state path together with all of
|
|
@@ -2084,7 +2104,7 @@ export declare namespace Machine {
|
|
|
2084
2104
|
*/
|
|
2085
2105
|
readonly getSnapshot: {
|
|
2086
2106
|
<Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path): Option.Option<SnapshotByIdentifier<States, Path>>;
|
|
2087
|
-
<const From extends StateIdentifier<States>, const Path extends StateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | `${NoInfer<From>}.${string}` ? unknown : never)): Option.Option<SnapshotByIdentifier<States, Path>>;
|
|
2107
|
+
<const From extends StateIdentifier<States>, const Path extends StateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | (NoInfer<From> extends "" ? string : `${NoInfer<From>}.${string}`) ? unknown : never)): Option.Option<SnapshotByIdentifier<States, Path>>;
|
|
2088
2108
|
};
|
|
2089
2109
|
/**
|
|
2090
2110
|
* Returns whether a state path is active in the snapshot. The supplied
|
|
@@ -2096,7 +2116,7 @@ export declare namespace Machine {
|
|
|
2096
2116
|
*/
|
|
2097
2117
|
readonly matches: {
|
|
2098
2118
|
<Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path): boolean;
|
|
2099
|
-
<const From extends StateIdentifier<States>, const Path extends StateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | `${NoInfer<From>}.${string}` ? unknown : never)): boolean;
|
|
2119
|
+
<const From extends StateIdentifier<States>, const Path extends StateIdentifier<States>>(snapshot: SnapshotByIdentifier<States, From>, path: Path & (Path extends NoInfer<From> | (NoInfer<From> extends "" ? string : `${NoInfer<From>}.${string}`) ? unknown : never)): boolean;
|
|
2100
2120
|
};
|
|
2101
2121
|
}
|
|
2102
2122
|
/**
|
|
@@ -2408,20 +2428,31 @@ export declare namespace Machine {
|
|
|
2408
2428
|
/** Choice-owning active parents that remain unimplemented. */
|
|
2409
2429
|
type MissingChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, ChoiceParentIdentifier<States>>;
|
|
2410
2430
|
/** @internal Readiness proof for required choice resolvers. */
|
|
2411
|
-
type EnsureChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [ChoiceIdentifier<States>] extends [never] ? unknown : [MissingChoiceImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
2431
|
+
type EnsureChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = IsAny<States> extends true ? unknown : [ChoiceIdentifier<States>] extends [never] ? unknown : [MissingChoiceImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
2412
2432
|
readonly "~effect/Machine/MissingChoiceImplementation": MissingChoiceImplementations<States, UnhandledStates>;
|
|
2413
2433
|
};
|
|
2414
2434
|
/** @internal Readiness proof required by planning and managed execution. */
|
|
2415
|
-
type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = ([HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
2435
|
+
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 : {
|
|
2416
2436
|
readonly "~effect/Machine/MissingHistoryImplementation": MissingHistoryImplementations<States, UnhandledStates>;
|
|
2417
2437
|
}) & EnsureChoiceImplementations<States, UnhandledStates>;
|
|
2438
|
+
/** Owners whose declared default descendants require supplied values. */
|
|
2439
|
+
type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never : "" extends keyof States ? States[""] extends {
|
|
2440
|
+
readonly "~effect/Machine/ExplicitInitial": true;
|
|
2441
|
+
} ? never : InitializerClosureForNode<States, States[""], ""> : never;
|
|
2442
|
+
/** 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 : {
|
|
2444
|
+
readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>;
|
|
2445
|
+
};
|
|
2418
2446
|
/**
|
|
2419
2447
|
* Extracts a state-tree node by state path.
|
|
2420
2448
|
*
|
|
2421
2449
|
* @category utility types
|
|
2422
2450
|
* @since 0.4.0
|
|
2423
2451
|
*/
|
|
2424
|
-
type NodeByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> =
|
|
2452
|
+
type NodeByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = string extends keyof States ? NodeByNamedIdentifier<States, StateId> : "" extends keyof States ? StateId extends "" ? States[""] : States[""] extends {
|
|
2453
|
+
readonly states: infer Children extends StateSchemas;
|
|
2454
|
+
} ? NodeByIdentifier<Children, Extract<StateId, StateIdentifier<Children>>> : never : NodeByNamedIdentifier<States, StateId>;
|
|
2455
|
+
type NodeByNamedIdentifier<States extends StateSchemas, StateId extends string> = StateId extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
2425
2456
|
readonly states: infer Children extends StateSchemas;
|
|
2426
2457
|
} ? Rest extends StateIdentifier<Children> ? NodeByIdentifier<Children, Rest> : never : never : never : StateId extends keyof States ? States[StateId] : never;
|
|
2427
2458
|
/**
|
|
@@ -2453,8 +2484,6 @@ export declare namespace Machine {
|
|
|
2453
2484
|
* @since 0.4.0
|
|
2454
2485
|
*/
|
|
2455
2486
|
type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"];
|
|
2456
|
-
/** @deprecated Use {@link EmittedEventOf}. */
|
|
2457
|
-
type EmitOf<Emits extends ReadonlyArray<TaggedSchema>> = EmittedEventOf<Emits>;
|
|
2458
2487
|
/**
|
|
2459
2488
|
* Event values received by lifecycle callbacks.
|
|
2460
2489
|
*
|
|
@@ -2475,14 +2504,15 @@ export declare namespace Machine {
|
|
|
2475
2504
|
* @category utility types
|
|
2476
2505
|
* @since 0.4.0
|
|
2477
2506
|
*/
|
|
2478
|
-
type ParentStateIdentifier<StateId extends string> = StateId extends
|
|
2507
|
+
type ParentStateIdentifier<StateId extends string> = StateId extends "" ? never : "" | NamedParentStateIdentifier<StateId>;
|
|
2508
|
+
type NamedParentStateIdentifier<StateId extends string> = StateId extends `${infer Parent}.${infer Child}` ? Parent | (Child extends `${string}.${string}` ? `${Parent}.${NamedParentStateIdentifier<Child>}` : never) : never;
|
|
2479
2509
|
/**
|
|
2480
2510
|
* Extracts the nearest parent state path from a state identifier.
|
|
2481
2511
|
*
|
|
2482
2512
|
* @category utility types
|
|
2483
2513
|
* @since 0.4.0
|
|
2484
2514
|
*/
|
|
2485
|
-
type ImmediateParentStateIdentifier<StateId extends string> = StateId extends `${infer Head}.${infer Tail}` ? Tail extends `${string}.${string}` ? `${Head}.${ImmediateParentStateIdentifier<Tail>}` : Head : never;
|
|
2515
|
+
type ImmediateParentStateIdentifier<StateId extends string> = StateId extends `${infer Head}.${infer Tail}` ? Tail extends `${string}.${string}` ? `${Head}.${ImmediateParentStateIdentifier<Tail>}` : Head : StateId extends "" ? never : "";
|
|
2486
2516
|
/**
|
|
2487
2517
|
* Maps every parent state path of a state identifier to its decoded value.
|
|
2488
2518
|
*
|
|
@@ -2524,7 +2554,7 @@ export declare namespace Machine {
|
|
|
2524
2554
|
readonly type: "final";
|
|
2525
2555
|
} ? OutputByIdentifier<States, StateId> : never;
|
|
2526
2556
|
type CompoundCompletionOutput<States extends StateSchemas, Children extends StateSchemas, Prefix extends StateIdentifier<States>> = UndefinedIfNever<CompoundCompletionOutputRaw<States, Children, Prefix>>;
|
|
2527
|
-
type CompoundCompletionOutputRaw<States extends StateSchemas, Children extends StateSchemas, Prefix extends StateIdentifier<States>> = {
|
|
2557
|
+
type CompoundCompletionOutputRaw<States extends StateSchemas, Children extends StateSchemas, Prefix extends StateIdentifier<States>> = Prefix extends "" ? TerminalOutput<Children> : {
|
|
2528
2558
|
readonly [Key in ActiveStateKey<Children>]: DirectFinalCompletionOutput<States, Extract<JoinPath<Prefix, Key>, StateIdentifier<States>>>;
|
|
2529
2559
|
}[ActiveStateKey<Children>];
|
|
2530
2560
|
/**
|
|
@@ -2650,6 +2680,7 @@ export declare namespace Machine {
|
|
|
2650
2680
|
* @since 0.4.0
|
|
2651
2681
|
*/
|
|
2652
2682
|
interface EncodedSnapshot {
|
|
2683
|
+
readonly version: 2;
|
|
2653
2684
|
readonly _tag: "MachineSnapshot";
|
|
2654
2685
|
readonly active: ReadonlyArray<EncodedSnapshotState>;
|
|
2655
2686
|
readonly completed?: ReadonlyArray<EncodedSnapshotCompletion>;
|
|
@@ -2797,7 +2828,7 @@ export declare namespace Machine {
|
|
|
2797
2828
|
* @category utility types
|
|
2798
2829
|
* @since 0.4.0
|
|
2799
2830
|
*/
|
|
2800
|
-
type RootStateIdentifier<StateId extends string> = StateId extends
|
|
2831
|
+
type RootStateIdentifier<StateId extends string> = StateId extends string ? "" : never;
|
|
2801
2832
|
/**
|
|
2802
2833
|
* Extracts the public snapshot shape that contains a final state path.
|
|
2803
2834
|
*
|
|
@@ -2839,7 +2870,7 @@ export declare namespace Machine {
|
|
|
2839
2870
|
* @category models
|
|
2840
2871
|
* @since 0.4.0
|
|
2841
2872
|
*/
|
|
2842
|
-
interface StateConstruction<Result> {
|
|
2873
|
+
interface StateConstruction<out Result> {
|
|
2843
2874
|
readonly [Topology.StateConstructionTypeId]: Result;
|
|
2844
2875
|
}
|
|
2845
2876
|
/**
|
|
@@ -2979,7 +3010,11 @@ export declare namespace Machine {
|
|
|
2979
3010
|
* @category utility types
|
|
2980
3011
|
* @since 0.4.0
|
|
2981
3012
|
*/
|
|
2982
|
-
type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> =
|
|
3013
|
+
type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotMethod<{
|
|
3014
|
+
readonly "": Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig>;
|
|
3015
|
+
}, "" & ActiveStateKey<{
|
|
3016
|
+
readonly "": Extract<Omit<States[""], "~effect/Machine/ExplicitInitial">, StateNodeConfig>;
|
|
3017
|
+
}>, "", Owner>;
|
|
2983
3018
|
/**
|
|
2984
3019
|
* Builder for source-local transition targets.
|
|
2985
3020
|
*
|
|
@@ -3003,7 +3038,7 @@ export declare namespace Machine {
|
|
|
3003
3038
|
* @category utility types
|
|
3004
3039
|
* @since 0.4.0
|
|
3005
3040
|
*/
|
|
3006
|
-
type BranchTargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = BranchTargetBuilderForRoot<States, Extract<RootStateIdentifier<Source>, ActiveStateKey<States>>, Source>;
|
|
3041
|
+
type BranchTargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = BranchTargetBuilderForRoot<States, Extract<"" extends keyof States ? "" : RootStateIdentifier<Source>, ActiveStateKey<States>>, Source>;
|
|
3007
3042
|
/**
|
|
3008
3043
|
* Machine-bound target builders available in transition contexts.
|
|
3009
3044
|
*
|
|
@@ -3023,7 +3058,7 @@ export declare namespace Machine {
|
|
|
3023
3058
|
* @category models
|
|
3024
3059
|
* @since 0.4.0
|
|
3025
3060
|
*/
|
|
3026
|
-
interface TargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
|
|
3061
|
+
interface TargetBuilder<in out States extends StateSchemas, in out Source extends StateNodeIdentifier<States>> {
|
|
3027
3062
|
/**
|
|
3028
3063
|
* Selects an explicitly targetless transition.
|
|
3029
3064
|
*
|
|
@@ -3095,10 +3130,10 @@ export declare namespace Machine {
|
|
|
3095
3130
|
} ? SelectionMethod<Builder, Path, "state", Scope> & InitialSelectionMethod<Builder, Path, Scope> & SelectionTreeWithPrefix<AllStates, Children, Path, Scope, Builder> : SelectionMethod<Builder, Path, "state", Scope>;
|
|
3096
3131
|
/** @internal */
|
|
3097
3132
|
type StateUpdateSelectionForNode<AllStates extends StateSchemas, Node, Path extends string, Scope extends "local" | "branch"> = Node extends {
|
|
3098
|
-
readonly
|
|
3099
|
-
} ? NodeSchema<Node> extends never ? {} : {
|
|
3133
|
+
readonly type: "final";
|
|
3134
|
+
} ? {} : NodeSchema<Node> extends never ? {} : {
|
|
3100
3135
|
readonly update: SelectionValue<StateUpdateBuilder<AllStates, Extract<Path, ValuedStateIdentifier<AllStates>>>, Path, "update", Scope>;
|
|
3101
|
-
}
|
|
3136
|
+
};
|
|
3102
3137
|
/** @internal */
|
|
3103
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 {
|
|
3104
3139
|
readonly states: infer Children extends StateSchemas;
|
|
@@ -3110,12 +3145,13 @@ export declare namespace Machine {
|
|
|
3110
3145
|
type FullSelectionNode<AllStates extends StateSchemas, Node, Path extends StateIdentifier<AllStates>, Builder> = Node extends {
|
|
3111
3146
|
readonly states: StateSchemas;
|
|
3112
3147
|
} ? SelectionMethod<Builder, Path, "state", "full"> & InitialSelectionMethod<Builder, Path, "full"> : SelectionMethod<Builder, Path, "state", "full">;
|
|
3113
|
-
type
|
|
3114
|
-
readonly
|
|
3115
|
-
};
|
|
3116
|
-
type
|
|
3117
|
-
|
|
3118
|
-
|
|
3148
|
+
type RootBuilder<Builder> = Builder extends {
|
|
3149
|
+
readonly "": infer Root;
|
|
3150
|
+
} ? 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">) : {};
|
|
3119
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 ? {
|
|
3120
3156
|
readonly with: SelectionValue<Builder["with"], Scope, "state", "local">;
|
|
3121
3157
|
} : {}) & (Source extends ChoiceIdentifier<States> ? {} : Scope extends ValuedStateIdentifier<States> ? {
|
|
@@ -3136,6 +3172,13 @@ export declare namespace Machine {
|
|
|
3136
3172
|
* target-specific resolver APIs retain exact inference.
|
|
3137
3173
|
*/
|
|
3138
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;
|
|
3139
3182
|
/** Handles the trigger without selecting a destination. */
|
|
3140
3183
|
readonly none: SelectionValue<TargetBuilder<States, Source>["none"], never, "none", "local">;
|
|
3141
3184
|
/** Selects a destination or updates the nearest active compound scope. */
|
|
@@ -3145,7 +3188,9 @@ export declare namespace Machine {
|
|
|
3145
3188
|
/** Selects a complete destination under any top-level state. */
|
|
3146
3189
|
readonly full: FullTargetSelector<States>;
|
|
3147
3190
|
/** Restores a shallow or deep history pseudo-state. */
|
|
3148
|
-
readonly history:
|
|
3191
|
+
readonly history: States[""] extends {
|
|
3192
|
+
readonly states: infer Children extends StateSchemas;
|
|
3193
|
+
} ? HistorySelectionTree<States, Children, "", RootBuilder<HistoryTargetBuilder<States>>> : {};
|
|
3149
3194
|
}
|
|
3150
3195
|
/** Definition-time selector that can choose only a valid top-level initial entry. */
|
|
3151
3196
|
type InitialTargetSelector<States extends StateSchemas> = {
|
|
@@ -3430,8 +3475,9 @@ export declare namespace Machine {
|
|
|
3430
3475
|
*
|
|
3431
3476
|
* Handlers return snapshots for complete state replacement, target builder
|
|
3432
3477
|
* results for path-safe partial transitions, state-value updates, or
|
|
3433
|
-
*
|
|
3434
|
-
*
|
|
3478
|
+
* an explicit targetless result. In a machine definition, select `to.none`;
|
|
3479
|
+
* its optional resolver returns `undefined`. Raw decoded state values are
|
|
3480
|
+
* not accepted as transition targets.
|
|
3435
3481
|
*
|
|
3436
3482
|
* @category utility types
|
|
3437
3483
|
* @since 0.4.0
|
|
@@ -3527,7 +3573,7 @@ export declare namespace Machine {
|
|
|
3527
3573
|
*/
|
|
3528
3574
|
type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3529
3575
|
type InvokeFactoryResult<Source> = Source extends (...args: any) => infer Resolved ? Resolved : never;
|
|
3530
|
-
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>,
|
|
3576
|
+
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;
|
|
3531
3577
|
type InvokeLogic<Invoke> = Invoke extends {
|
|
3532
3578
|
readonly effect: infer Source;
|
|
3533
3579
|
} ? InvokeFactoryResult<Source> extends infer Fx extends Effect.Effect<any, any, any> ? Logic<void, never, Effect.Error<Fx>, Effect.Services<Fx>, Effect.Success<Fx>> : never : Invoke extends {
|
|
@@ -3595,7 +3641,7 @@ export declare namespace Machine {
|
|
|
3595
3641
|
};
|
|
3596
3642
|
} ? Emitted : Invoke extends {
|
|
3597
3643
|
readonly child: ChildMachine<string, infer M>;
|
|
3598
|
-
} ?
|
|
3644
|
+
} ? EmittedEvent<M> : never;
|
|
3599
3645
|
/** Public parent inputs required by an invoked child machine. */
|
|
3600
3646
|
type InvokeParentEvents<Invoke> = Invoke extends {
|
|
3601
3647
|
readonly [InvokeTypeId]: {
|
|
@@ -3735,12 +3781,12 @@ export declare namespace Machine {
|
|
|
3735
3781
|
/** Declines this candidate and continues hierarchical transition selection. */
|
|
3736
3782
|
readonly decline: () => Declined;
|
|
3737
3783
|
}
|
|
3738
|
-
type TransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection>, enqueue: Enqueue<EventOf<Events>,
|
|
3739
|
-
type DeclinableTransitionResolver<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context, Selection> = (context: TransitionResolveContext<Context, Selection> & DeclineCapability, enqueue: Enqueue<EventOf<Events>,
|
|
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;
|
|
3740
3786
|
/** @internal */
|
|
3741
|
-
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>,
|
|
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>;
|
|
3742
3788
|
/** @internal */
|
|
3743
|
-
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>,
|
|
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;
|
|
3744
3790
|
/** One named destination declared by a branching transition. */
|
|
3745
3791
|
interface TransitionBranchInput<Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>> {
|
|
3746
3792
|
/** Exact topology destination available to the branching resolver. */
|
|
@@ -3776,8 +3822,8 @@ export declare namespace Machine {
|
|
|
3776
3822
|
type TransitionBranchesResolveContext<Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = Omit<Context, "target"> & {
|
|
3777
3823
|
readonly select: BranchSelectors<Branches>;
|
|
3778
3824
|
};
|
|
3779
|
-
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>,
|
|
3780
|
-
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>,
|
|
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;
|
|
3781
3827
|
/** @internal Type evidence retained by a transition authored through its bound selector. */
|
|
3782
3828
|
interface TransitionBuilderEvidence<out Result, out Acceptance extends TransitionAcceptance> {
|
|
3783
3829
|
readonly [TransitionBuilderTypeId]: {
|
|
@@ -3806,6 +3852,12 @@ export declare namespace Machine {
|
|
|
3806
3852
|
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>> {
|
|
3807
3853
|
(resolve: DeclinableTransitionResolver<Events, Emits, Context, Selection>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, (SelectionKind<Selection> extends "none" ? undefined : SelectedTargetResult<Selection> | undefined) | Declined, "declinable">;
|
|
3808
3854
|
}
|
|
3855
|
+
type ConstructionCallbacks<Context, Builder, Result> = {
|
|
3856
|
+
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;
|
|
3857
|
+
};
|
|
3858
|
+
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"> : {}) & {
|
|
3859
|
+
readonly resolve: (resolve: TransitionResolver<Events, Emits, Context, Selection>, options?: TransitionRequiredOptions<Reenter>) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
|
|
3860
|
+
};
|
|
3809
3861
|
/**
|
|
3810
3862
|
* A selected transition target with target-specific resolver operations.
|
|
3811
3863
|
*
|
|
@@ -3813,7 +3865,7 @@ export declare namespace Machine {
|
|
|
3813
3865
|
*
|
|
3814
3866
|
* ```ts
|
|
3815
3867
|
* Reset: (to) =>
|
|
3816
|
-
* to.
|
|
3868
|
+
* to.branch.Ready().resolve(
|
|
3817
3869
|
* ({ target }) => target.from(),
|
|
3818
3870
|
* { reenter: true }
|
|
3819
3871
|
* )
|
|
@@ -3823,7 +3875,10 @@ export declare namespace Machine {
|
|
|
3823
3875
|
* @inlineType TransitionDeclinableOptions
|
|
3824
3876
|
* @inlineType TransitionReenterOption
|
|
3825
3877
|
*/
|
|
3826
|
-
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 & (
|
|
3878
|
+
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 ? {
|
|
3879
|
+
/** Declines this candidate before construction when the predicate is false. */
|
|
3880
|
+
readonly guard: (predicate: (context: Omit<Context, "target">) => boolean) => GuardedTransition<States, Events, Emits, StateId, Context, Reenter, Selection>;
|
|
3881
|
+
} : {}) & 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"> : {}) & {
|
|
3827
3882
|
/** Evaluates state construction after this transition is selected. */
|
|
3828
3883
|
readonly resolve: TransitionResolveRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? TransitionResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
|
|
3829
3884
|
} & ([Reenter] extends [true] ? SelectionSupportsDefaultConstruction<Selection> extends true ? {
|
|
@@ -3839,7 +3894,7 @@ export declare namespace Machine {
|
|
|
3839
3894
|
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 & {
|
|
3840
3895
|
/** @internal */
|
|
3841
3896
|
readonly "~effect/Machine/UpdatingTransitionTarget": Owner;
|
|
3842
|
-
readonly resolve: ((resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>,
|
|
3897
|
+
readonly resolve: ((resolve: (context: UpdatingTransitionResolveContext<States, Context, Selection, Owner>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner>, options?: TransitionRequiredOptions<Reenter>) => 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<Reenter>) => BuiltTransition<States, Events, Emits, StateId, Context, Reenter, CombinedTarget<UnwrapConstruction<SelectedTargetResult<Selection>>, States, Owner> | Declined, "declinable"> : {});
|
|
3843
3898
|
};
|
|
3844
3899
|
/** @internal */
|
|
3845
3900
|
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">> {
|
|
@@ -3850,13 +3905,20 @@ export declare namespace Machine {
|
|
|
3850
3905
|
(resolve: DeclinableStateUpdateResolver<States, Events, Emits, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection> | Declined, "declinable">;
|
|
3851
3906
|
}
|
|
3852
3907
|
/** @internal */
|
|
3853
|
-
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 &
|
|
3908
|
+
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 & ConstructionCallbacks<Omit<StateUpdateResolveContext<States, Context, Extract<SelectionPath<Selection>, ValuedStateIdentifier<States>>>, "owner">, SelectionBuilder<Selection>, BuiltTransition<States, Events, Emits, StateId, Context, Reenter, SelectedTargetResult<Selection>, "required">> & {
|
|
3909
|
+
readonly resolve: StateUpdateTransitionRequired<States, Events, Emits, StateId, Context, Reenter, Selection> & ("declinable" extends Acceptance ? StateUpdateTransitionDeclinable<States, Events, Emits, StateId, Context, Reenter, Selection> : {});
|
|
3910
|
+
};
|
|
3854
3911
|
/** @internal Type evidence retained by a machine initial-entry declaration. */
|
|
3855
3912
|
interface InitialBuilderEvidence<out Selection> {
|
|
3856
3913
|
readonly [InitialBuilderTypeId]: Types.Covariant<Selection>;
|
|
3857
3914
|
}
|
|
3915
|
+
/** Decoded input shared by initial construction callbacks. */
|
|
3916
|
+
interface InitialContext<Input> {
|
|
3917
|
+
/** Decoded value supplied when the machine is started. */
|
|
3918
|
+
readonly input: Input;
|
|
3919
|
+
}
|
|
3858
3920
|
/** A selected machine initial entry with its exact resolver target. */
|
|
3859
|
-
type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> = Selection & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {}) & {
|
|
3921
|
+
type InitialTransitionTarget<Input, Selection extends TargetSelection<any, any, any>> = Selection & ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<Selection>, InitialBuilderEvidence<Selection>> & (SelectionSupportsDefaultConstruction<Selection> extends true ? InitialBuilderEvidence<Selection> : {}) & {
|
|
3860
3922
|
/** Lazily constructs the selected initial state from decoded machine input. */
|
|
3861
3923
|
readonly resolve: (resolve: (context: {
|
|
3862
3924
|
/** Decoded value supplied when the machine is started. */
|
|
@@ -3874,6 +3936,25 @@ export declare namespace Machine {
|
|
|
3874
3936
|
type InitialSelector<States extends StateSchemas, Input = void> = InitialSelectorNode<Input, InitialTargetSelector<States>>;
|
|
3875
3937
|
/** Target-first initial-entry declaration accepted by {@link make}. */
|
|
3876
3938
|
type InitialBuilderInput<States extends StateSchemas, Input> = (to: InitialSelector<States, Input>) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3939
|
+
/** Initializes the root and its declared default descendants. */
|
|
3940
|
+
type RootInitialBuilderInput<Root extends StateNodeConfig, Input> = (root: InitialTransitionTarget<Input, SelectionValue<InitialTargetFactory<Root, "">, "", "initial", "initial">>) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3941
|
+
interface RootConfigurationSelection<in out Root extends StateNodeConfig> extends TargetSelection<FullSnapshotMethod<{
|
|
3942
|
+
readonly "": Root;
|
|
3943
|
+
}, "" & ActiveStateKey<{
|
|
3944
|
+
readonly "": Root;
|
|
3945
|
+
}>, "">, "", "state", "initial"> {
|
|
3946
|
+
}
|
|
3947
|
+
/** Explicitly constructs a complete starting configuration. */
|
|
3948
|
+
type RootConfigurationBuilderInput<Root extends StateNodeConfig, Input> = (root: ConstructionCallbacks<InitialContext<Input>, SelectionBuilder<RootConfigurationSelection<Root>>, InitialBuilderEvidence<RootConfigurationSelection<Root>>> & {
|
|
3949
|
+
readonly resolve: (resolve: (context: {
|
|
3950
|
+
/** Decoded startup input. */
|
|
3951
|
+
readonly input: Input;
|
|
3952
|
+
/** Builder for the complete root configuration. */
|
|
3953
|
+
readonly target: SelectionBuilder<RootConfigurationSelection<Root>>;
|
|
3954
|
+
}) => ConstructionResult<Snapshot<{
|
|
3955
|
+
readonly "": Root;
|
|
3956
|
+
}>>) => InitialBuilderEvidence<RootConfigurationSelection<Root>>;
|
|
3957
|
+
}) => InitialBuilderEvidence<TargetSelection<any, any, any>>;
|
|
3877
3958
|
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>) & {
|
|
3878
3959
|
readonly [Key in keyof Node]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node[Key]>;
|
|
3879
3960
|
} : never : Node extends TargetSelection<any, any, any> ? TransitionTarget<States, Events, Emits, StateId, Context, Reenter, Acceptance, Node> : {
|
|
@@ -3885,14 +3966,17 @@ export declare namespace Machine {
|
|
|
3885
3966
|
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>>> {
|
|
3886
3967
|
(resolve: DeclinableTransitionBranchesResolver<Events, Emits, Context, Branches>, options: TransitionDeclinableOptions<Reenter>): BuiltTransition<States, Events, Emits, StateId, Context, Reenter, BranchSelectionResult<Branches> | Declined, "declinable">;
|
|
3887
3968
|
}
|
|
3969
|
+
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> = {
|
|
3970
|
+
readonly [Key in keyof TargetSelector<States, StateId>]: TransitionSelectorNode<States, Events, Emits, StateId, Context, Key extends "self" ? false : Reenter, Acceptance, TargetSelector<States, StateId>[Key]>;
|
|
3971
|
+
};
|
|
3888
3972
|
/** Selector supplied to inline transition declarations. */
|
|
3889
|
-
|
|
3973
|
+
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> {
|
|
3890
3974
|
/** Declares a closed set of named destinations for one resolver. */
|
|
3891
3975
|
readonly branches: <const Branches extends Readonly<Record<string, TransitionBranchInput>>>(branches: Branches & ValidateTransitionBranchRecord<NoInfer<Branches>>) => {
|
|
3892
3976
|
/** Resolves exactly one declared branch after this transition is selected. */
|
|
3893
3977
|
readonly resolve: TransitionBranchesResolveRequired<States, Events, Emits, StateId, Context, Reenter, Branches> & ("declinable" extends Acceptance ? TransitionBranchesResolveDeclinable<States, Events, Emits, StateId, Context, Reenter, Branches> : {});
|
|
3894
3978
|
};
|
|
3895
|
-
}
|
|
3979
|
+
}
|
|
3896
3980
|
/** Inline transition declaration accepted by state and invocation handlers. */
|
|
3897
3981
|
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>;
|
|
3898
3982
|
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>;
|
|
@@ -4011,7 +4095,7 @@ export declare namespace Machine {
|
|
|
4011
4095
|
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>;
|
|
4012
4096
|
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>;
|
|
4013
4097
|
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>>>;
|
|
4014
|
-
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>,
|
|
4098
|
+
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>>>;
|
|
4015
4099
|
/**
|
|
4016
4100
|
* Selects state-owned work and begins its lifecycle-handler chain.
|
|
4017
4101
|
*
|
|
@@ -4024,9 +4108,9 @@ export declare namespace Machine {
|
|
|
4024
4108
|
* ```ts
|
|
4025
4109
|
* invoke: (from) =>
|
|
4026
4110
|
* from.effect("load-user", () => loadUser).onDone((to) =>
|
|
4027
|
-
* to.
|
|
4111
|
+
* to.branch.Ready().resolve(({ output, target }) => target.from({ user: output }))
|
|
4028
4112
|
* ).onFailure((to) =>
|
|
4029
|
-
* to.
|
|
4113
|
+
* to.branch.Failed().resolve(({ error, target }) => target.from({ error }))
|
|
4030
4114
|
* )
|
|
4031
4115
|
* ```
|
|
4032
4116
|
*
|
|
@@ -4141,14 +4225,14 @@ export declare namespace Machine {
|
|
|
4141
4225
|
* **Example** (State actions, events, and invocation)
|
|
4142
4226
|
*
|
|
4143
4227
|
* ```ts
|
|
4144
|
-
* machine.handle({
|
|
4228
|
+
* machine.handle({ states: {
|
|
4145
4229
|
* Loading: {
|
|
4146
4230
|
* entry: (_, enqueue) => enqueue.emit({ _tag: "Started" }),
|
|
4147
4231
|
* invoke: (from) =>
|
|
4148
|
-
* from.effect("load", () => load).onDone((to) => to.
|
|
4149
|
-
* on: { Cancel: (to) => to.
|
|
4232
|
+
* from.effect("load", () => load).onDone((to) => to.branch.Ready()),
|
|
4233
|
+
* on: { Cancel: (to) => to.branch.Idle() }
|
|
4150
4234
|
* }
|
|
4151
|
-
* })
|
|
4235
|
+
* } })
|
|
4152
4236
|
* ```
|
|
4153
4237
|
*
|
|
4154
4238
|
* @inlineType ActiveOutputHandlerConfig
|
|
@@ -4159,9 +4243,9 @@ export declare namespace Machine {
|
|
|
4159
4243
|
*/
|
|
4160
4244
|
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 []> = {
|
|
4161
4245
|
/** Runs synchronously when the state is entered and may enqueue commands. */
|
|
4162
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>,
|
|
4246
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4163
4247
|
/** Runs synchronously before the state is exited and may enqueue commands. */
|
|
4164
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>,
|
|
4248
|
+
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4165
4249
|
/** Starts state-owned Effect, Stream, timer, logic, or child lifecycles. */
|
|
4166
4250
|
readonly invoke?: InvokeBuilderInput<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
4167
4251
|
/** Eventless transition evaluated after the state becomes stable. */
|
|
@@ -4235,9 +4319,9 @@ export declare namespace Machine {
|
|
|
4235
4319
|
* @category models
|
|
4236
4320
|
* @since 0.13.0
|
|
4237
4321
|
*/
|
|
4238
|
-
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>,
|
|
4322
|
+
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>;
|
|
4239
4323
|
/** Context used only when a history node has no previously captured record. */
|
|
4240
|
-
interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
4324
|
+
interface HistoryDefaultContext<in out States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, in out ParentId extends StateIdentifier<States>> {
|
|
4241
4325
|
/** Lifecycle event that attempted to restore this history node. */
|
|
4242
4326
|
readonly event: LifecycleEvent<Events>;
|
|
4243
4327
|
/** Complete target builder rooted at the history owner. */
|
|
@@ -4252,7 +4336,7 @@ export declare namespace Machine {
|
|
|
4252
4336
|
* history owner. This makes the default independent of the transition source
|
|
4253
4337
|
* and provides every inactive ancestor and required parallel region.
|
|
4254
4338
|
*/
|
|
4255
|
-
type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Enqueue<EventOf<Events>,
|
|
4339
|
+
type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CompleteSnapshotContaining<States, ParentId> | StateConstruction<CompleteSnapshotContaining<States, ParentId>>;
|
|
4256
4340
|
/**
|
|
4257
4341
|
* Fallback implementation for one direct history pseudo-state.
|
|
4258
4342
|
*
|
|
@@ -4293,7 +4377,7 @@ export declare namespace Machine {
|
|
|
4293
4377
|
*/
|
|
4294
4378
|
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 []> = {
|
|
4295
4379
|
/** Runs synchronously when the final state is entered and may enqueue commands. */
|
|
4296
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>,
|
|
4380
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<any, any>;
|
|
4297
4381
|
readonly exit?: never;
|
|
4298
4382
|
readonly always?: never;
|
|
4299
4383
|
readonly onDone?: never;
|
|
@@ -4319,10 +4403,12 @@ export declare namespace Machine {
|
|
|
4319
4403
|
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
|
|
4320
4404
|
readonly states?: infer Children;
|
|
4321
4405
|
} ? NonNullable<Children> : never : never;
|
|
4322
|
-
type HandlerNodeByPath<States extends StateSchemas, Path extends string> =
|
|
4406
|
+
type HandlerNodeByPath<States extends StateSchemas, Path extends string> = "" extends keyof States ? Path extends "" ? States[""] : States[""] extends {
|
|
4407
|
+
readonly states: infer Children extends StateSchemas;
|
|
4408
|
+
} ? HandlerNodeByPath<Children, Path> : never : Path extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
4323
4409
|
readonly states: infer Children extends StateSchemas;
|
|
4324
4410
|
} ? HandlerNodeByPath<Children, Rest> : never : never : Path extends keyof States ? States[Path] : never;
|
|
4325
|
-
type HandlerConfigAtPath<Config, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Config ? HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[Head]>, Rest> : never : Path extends keyof Config ? Config[Path] : never;
|
|
4411
|
+
type HandlerConfigAtPath<Config, Path extends string> = [Config] extends [never] ? never : "" extends keyof Config ? Path extends "" ? Config[""] : HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[""]>, Path> : Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Config ? HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[Head]>, Rest> : never : Path extends keyof Config ? Config[Path] : never;
|
|
4326
4412
|
type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
4327
4413
|
readonly [Key in Head]?: {
|
|
4328
4414
|
readonly states: HandlerValidationAtPath<Rest, Validation>;
|
|
@@ -4374,7 +4460,7 @@ export declare namespace Machine {
|
|
|
4374
4460
|
readonly [Key in Extract<keyof Children, string>]: RequiredCompletionOutputStates<States, Extract<JoinPath<StateId, Key>, StateIdentifier<States>>>;
|
|
4375
4461
|
}[Extract<keyof Children, string>] : never;
|
|
4376
4462
|
type HandlerOutputStates<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = "output" extends keyof Config ? StateId : never;
|
|
4377
|
-
type HandlerUnknownStateKeyValidation<States extends StateSchemas, Prefix extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>,
|
|
4463
|
+
type HandlerUnknownStateKeyValidation<States extends StateSchemas, Prefix extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, ActiveStateKey<States> | ChoiceStateKey<States>>> = [UnknownKeys] extends [never] ? unknown : {
|
|
4378
4464
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Handler tree contains a state key that does not exist", JoinPath<Prefix, Key>, Key>;
|
|
4379
4465
|
};
|
|
4380
4466
|
type HandlerUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, HandlerNodeConfigKey>> = [UnknownKeys] extends [never] ? unknown : {
|
|
@@ -4427,7 +4513,7 @@ export declare namespace Machine {
|
|
|
4427
4513
|
] extends [never] ? unknown : {
|
|
4428
4514
|
readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
4429
4515
|
} : unknown : unknown);
|
|
4430
|
-
type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> ? "initialize" extends keyof Config ? unknown : {
|
|
4516
|
+
type HandlerRequiredHistoryInitializeValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates>] extends [never] ? unknown : StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "initialize" extends keyof Config ? unknown : {
|
|
4431
4517
|
readonly initialize: HandlerValidationError<"State requires initialize for shallow history restoration", StateId>;
|
|
4432
4518
|
} : unknown;
|
|
4433
4519
|
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;
|
|
@@ -4437,11 +4523,38 @@ export declare namespace Machine {
|
|
|
4437
4523
|
type HandlerInvokeParentEventsValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown : {
|
|
4438
4524
|
readonly invoke: HandlerValidationError<"Invoked child expects parent events not accepted by this machine", StateId, Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
4439
4525
|
};
|
|
4440
|
-
type HandlerRuntimeValidation<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, Incompatible = IncompatibleRuntime<ConfigServices<HandlerConfigPart<Config>>, EventOf<Events>,
|
|
4441
|
-
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 :
|
|
4526
|
+
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>;
|
|
4527
|
+
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 "" ? {
|
|
4528
|
+
readonly ""?: Validation;
|
|
4529
|
+
} : {
|
|
4530
|
+
readonly ""?: {
|
|
4531
|
+
readonly states: HandlerValidationAtPath<StateId, Validation>;
|
|
4532
|
+
};
|
|
4533
|
+
} : HandlerValidationAtPath<StateId, Validation> : never;
|
|
4442
4534
|
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>;
|
|
4443
4535
|
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>;
|
|
4444
|
-
type
|
|
4536
|
+
type RootInitialTargetValidation<States extends StateSchemas, Config> = RequiredInitializersForTargetPath<States, HandlerTreeInitialTargetPath<{
|
|
4537
|
+
readonly "": Config;
|
|
4538
|
+
}>> extends infer Required ? Types.UnionToIntersection<Required extends string ? HandlerConfigAtPath<{
|
|
4539
|
+
readonly "": Config;
|
|
4540
|
+
}, Required> extends infer NodeConfig ? [
|
|
4541
|
+
NodeConfig
|
|
4542
|
+
] extends [never] ? RootInitializeError<Required> : "initialize" extends keyof NodeConfig ? never : RootInitializeError<Required> : never : unknown> : unknown;
|
|
4543
|
+
type RootInitializeError<Path extends string> = Path extends "" ? {
|
|
4544
|
+
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4545
|
+
} : {
|
|
4546
|
+
readonly states: HandlerValidationAtPath<Path, {
|
|
4547
|
+
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
4548
|
+
}>;
|
|
4549
|
+
};
|
|
4550
|
+
type RootHandlerValidation<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, OutputStates extends StateIdentifier<States>> = HandlerNodeValidation<States, States[""], Events, InputEvents, Emits, Extract<"", StateNodeIdentifier<States>>, Config, OutputStates> & RootInitialTargetValidation<States, Config> & Types.UnionToIntersection<Exclude<StateNodeIdentifier<States>, ""> extends infer Path ? Path extends StateNodeIdentifier<States> ? HandlerConfigAtPath<{
|
|
4551
|
+
readonly "": Config;
|
|
4552
|
+
}, Path> extends infer NodeConfig ? [
|
|
4553
|
+
NodeConfig
|
|
4554
|
+
] extends [never] ? never : HandlerNodeValidation<States, HandlerNodeByPath<States, Path>, Events, InputEvents, Emits, Path, NodeConfig, OutputStates> extends infer Validation ? unknown extends Validation ? never : {
|
|
4555
|
+
readonly states: HandlerValidationAtPath<Path, Validation>;
|
|
4556
|
+
} : never : never : never : never>;
|
|
4557
|
+
type HandlerHasRequiredInitial<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = StateId extends RequiredHistoryInitializers<AllStates> | RequiredInitializers<AllStates> ? "initialize" extends keyof Config ? true : false : true;
|
|
4445
4558
|
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
4446
4559
|
readonly states: infer Children extends StateSchemas;
|
|
4447
4560
|
} ? [HistoryStateKey<Children>] extends [never] ? true : Config extends {
|
|
@@ -4456,7 +4569,7 @@ export declare namespace Machine {
|
|
|
4456
4569
|
} ? [
|
|
4457
4570
|
Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
|
|
4458
4571
|
] extends [never] ? true : false : false : true;
|
|
4459
|
-
type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates>] extends [never] ? StateId : HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
|
|
4572
|
+
type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates> | RequiredInitializers<AllStates>] extends [never] ? StateId : HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
|
|
4460
4573
|
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>;
|
|
4461
4574
|
type HandlerNodeEvidence<AllStates extends StateSchemas, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : {
|
|
4462
4575
|
readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, HandlerNodeByPath<AllStates, StateId>, StateId, NodeConfig> : never;
|
|
@@ -4465,7 +4578,7 @@ export declare namespace Machine {
|
|
|
4465
4578
|
readonly outputState: StateId extends StateIdentifier<AllStates> ? HandlerOutputStates<AllStates, StateId, HandlerConfigPart<NodeConfig>> : never;
|
|
4466
4579
|
};
|
|
4467
4580
|
type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId> : never : never;
|
|
4468
|
-
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>,
|
|
4581
|
+
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>;
|
|
4469
4582
|
/**
|
|
4470
4583
|
* Adds state handlers from a root state object.
|
|
4471
4584
|
*
|
|
@@ -4473,7 +4586,11 @@ export declare namespace Machine {
|
|
|
4473
4586
|
* @since 0.4.0
|
|
4474
4587
|
*/
|
|
4475
4588
|
interface Handler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> {
|
|
4476
|
-
<const Config extends
|
|
4589
|
+
<const Config>(config: Config & (Config extends (...args: never[]) => unknown ? never : unknown) & HandlerNode<States, States[""], Events, Emits, E, R, InputEvents, ParentEvents, Extract<"", StateNodeIdentifier<States>>> & RootHandlerValidation<States, Events, InputEvents, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, {
|
|
4590
|
+
readonly "": NoInfer<Config>;
|
|
4591
|
+
}>["outputState"], StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, ParentEvents, {
|
|
4592
|
+
readonly "": Config;
|
|
4593
|
+
}>;
|
|
4477
4594
|
}
|
|
4478
4595
|
/**
|
|
4479
4596
|
* Any state config.
|
|
@@ -4496,8 +4613,8 @@ export declare namespace Machine {
|
|
|
4496
4613
|
* @since 0.4.0
|
|
4497
4614
|
*/
|
|
4498
4615
|
interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
4499
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>,
|
|
4500
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>,
|
|
4616
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4617
|
+
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4501
4618
|
readonly invoke?: StoredInvokeDefinition<States, Events, Emits, StateId>;
|
|
4502
4619
|
readonly always?: TransitionConfig<States, Events, Emits, StateId, AlwaysContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
4503
4620
|
readonly onDone?: TransitionConfig<States, Events, Emits, StateId, DoneContext<States, Events, Emits, StateId>, false, TransitionAcceptance>;
|
|
@@ -4512,8 +4629,10 @@ export declare namespace Machine {
|
|
|
4512
4629
|
*/
|
|
4513
4630
|
type StateConfigs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, StateConfig<States, Events, Emits, StateId, EventTag, E, R> | ChoiceStateConfig<States, Events, Emits, ChoiceIdentifier<States>>>>;
|
|
4514
4631
|
}
|
|
4515
|
-
type StateSource =
|
|
4516
|
-
type StateSchemasOf<Source extends StateSource> = Source extends
|
|
4632
|
+
type StateSource = State<any> | Machine.Any;
|
|
4633
|
+
type StateSchemasOf<Source extends StateSource> = Source extends State<infer Node> ? {
|
|
4634
|
+
readonly "": Node;
|
|
4635
|
+
} : Source extends Machine.Any ? Machine.States<Source> : never;
|
|
4517
4636
|
/**
|
|
4518
4637
|
* Extracts the complete logical snapshot represented by a state definition or
|
|
4519
4638
|
* machine.
|
|
@@ -4522,6 +4641,30 @@ type StateSchemasOf<Source extends StateSource> = Source extends Machine.Defined
|
|
|
4522
4641
|
* @since 0.15.0
|
|
4523
4642
|
*/
|
|
4524
4643
|
export type Snapshot<Source extends StateSource> = Machine.Snapshot<StateSchemasOf<Source>>;
|
|
4644
|
+
/** Type utilities for logical snapshots, including snapshots carried by atom bridges. */
|
|
4645
|
+
/** Typed traversal of root and child logical snapshots.
|
|
4646
|
+
* @category utility types
|
|
4647
|
+
* @since 0.32.0
|
|
4648
|
+
*/
|
|
4649
|
+
export declare namespace Snapshot {
|
|
4650
|
+
/** Every active node represented by a logical snapshot type. */
|
|
4651
|
+
type Node<State> = State extends {
|
|
4652
|
+
readonly path: string;
|
|
4653
|
+
readonly value: unknown;
|
|
4654
|
+
} ? State | (State extends {
|
|
4655
|
+
readonly state: infer Child;
|
|
4656
|
+
} ? Node<Child> : State extends {
|
|
4657
|
+
readonly states: infer Regions;
|
|
4658
|
+
} ? Node<Regions[keyof Regions]> : never) : never;
|
|
4659
|
+
/** Every valid absolute path in a logical snapshot type. */
|
|
4660
|
+
type Path<State> = Node<State> extends infer Current ? Current extends {
|
|
4661
|
+
readonly path: infer Path extends string;
|
|
4662
|
+
} ? Path : never : never;
|
|
4663
|
+
/** The node at one absolute path. Runtime access can still be inactive. */
|
|
4664
|
+
type At<State, Path extends Snapshot.Path<State>> = Node<State> extends infer Current ? Current extends {
|
|
4665
|
+
readonly path: Path;
|
|
4666
|
+
} ? Current : never : never;
|
|
4667
|
+
}
|
|
4525
4668
|
/**
|
|
4526
4669
|
* Extracts the decoded value owned by a schema-backed state path.
|
|
4527
4670
|
*
|
|
@@ -4537,7 +4680,7 @@ export type Value<Source extends StateSource, Path extends Machine.ValuedStateId
|
|
|
4537
4680
|
*
|
|
4538
4681
|
* The source may be the object returned by {@link states} or a machine
|
|
4539
4682
|
* definition. This is the type-level counterpart of
|
|
4540
|
-
* `
|
|
4683
|
+
* `State.getSnapshot`.
|
|
4541
4684
|
*
|
|
4542
4685
|
* @category utility types
|
|
4543
4686
|
* @since 0.18.0
|
|
@@ -4583,59 +4726,24 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
4583
4726
|
* }
|
|
4584
4727
|
* })
|
|
4585
4728
|
*
|
|
4586
|
-
* const States = Machine.
|
|
4729
|
+
* const States = Machine.state({ initial: "slot1", states: {
|
|
4587
4730
|
* slot1: TradingSlot,
|
|
4588
4731
|
* slot2: TradingSlot
|
|
4589
|
-
* })
|
|
4732
|
+
* } })
|
|
4590
4733
|
* ```
|
|
4591
4734
|
*
|
|
4592
4735
|
* @category constructors
|
|
4593
4736
|
* @since 0.15.0
|
|
4594
4737
|
*/
|
|
4595
4738
|
export declare const state: StateConstructor;
|
|
4596
|
-
|
|
4597
|
-
* Defines the complete state tree while preserving literal state paths.
|
|
4598
|
-
*
|
|
4599
|
-
* **When to use**
|
|
4600
|
-
*
|
|
4601
|
-
* Use when you want to pass a state tree to `make` and also get typed
|
|
4602
|
-
* snapshot matching and access helpers.
|
|
4603
|
-
*
|
|
4604
|
-
* **Details**
|
|
4605
|
-
*
|
|
4606
|
-
* The returned `states` property is an immutable structural capture of the
|
|
4607
|
-
* supplied tree.
|
|
4608
|
-
* `Machine.make` derives its initial target selector from that tree and
|
|
4609
|
-
* enforces compound and parallel initial-state rules. Active nodes may omit
|
|
4610
|
-
* `schema` when they own no value and still participate fully in targeting,
|
|
4611
|
-
* matching, and snapshots.
|
|
4612
|
-
*
|
|
4613
|
-
* **Example** (Atomic initial snapshot)
|
|
4614
|
-
*
|
|
4615
|
-
* ```ts
|
|
4616
|
-
* import { Schema } from "effect"
|
|
4617
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
4618
|
-
*
|
|
4619
|
-
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
4620
|
-
*
|
|
4621
|
-
* const States = Machine.states({ idle: Idle })
|
|
4622
|
-
*
|
|
4623
|
-
* Machine.make({
|
|
4624
|
-
* states: States.states,
|
|
4625
|
-
* events: Machine.events(),
|
|
4626
|
-
* initial: (to) => to.idle().resolve(({ target }) => target.from())
|
|
4627
|
-
* })
|
|
4628
|
-
* ```
|
|
4629
|
-
*
|
|
4630
|
-
* @category constructors
|
|
4631
|
-
* @since 0.4.0
|
|
4632
|
-
*/
|
|
4633
|
-
export declare const states: StatesConstructor;
|
|
4634
|
-
type MakeConfig<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined> = {
|
|
4739
|
+
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> = {
|
|
4635
4740
|
/** Stable definition identifier used by inspection and visualization. */
|
|
4636
4741
|
readonly id?: string;
|
|
4637
|
-
/** State topology and value schemas,
|
|
4638
|
-
readonly
|
|
4742
|
+
/** State topology and value schemas, captured by a `Machine.state` descriptor. */
|
|
4743
|
+
readonly root: {
|
|
4744
|
+
readonly [StateTypeId]: typeof StateTypeId;
|
|
4745
|
+
readonly node: Root;
|
|
4746
|
+
};
|
|
4639
4747
|
/** Public events accepted by independently running machine references. */
|
|
4640
4748
|
readonly events: Machine.EventProtocol<"public", InputEvents> & ValidateInputEventProtocol<NoInfer<InputEvents>>;
|
|
4641
4749
|
/** Machine-local events used by raised events and other internal deliveries. */
|
|
@@ -4646,20 +4754,38 @@ type MakeConfig<States extends Machine.StateSchemas, InputEvents extends Readonl
|
|
|
4646
4754
|
readonly parent?: ParentDeclaration;
|
|
4647
4755
|
/** Schema used to decode input before initial-state construction. */
|
|
4648
4756
|
readonly input?: Input;
|
|
4649
|
-
/** Target-first declaration that constructs the initial active configuration. */
|
|
4650
|
-
readonly initial: unknown;
|
|
4651
4757
|
};
|
|
4652
|
-
type MakeResult<
|
|
4758
|
+
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> = Definition<{
|
|
4759
|
+
readonly "": Root;
|
|
4760
|
+
}, readonly [...InputEvents, ...InternalEvents], Input, InitialE, InitialR, Machine.FinalStateFromDefinition<{
|
|
4761
|
+
readonly "": Root;
|
|
4762
|
+
}>, Machine.TerminalOutput<{
|
|
4763
|
+
readonly "": Root;
|
|
4764
|
+
}>, Emits, InputEvents, Machine.ParentEventsOf<ParentDeclaration>>;
|
|
4765
|
+
type RootInitialization<Root extends Machine.StateNodeConfig, Input> = {
|
|
4766
|
+
readonly initialConfiguration?: never;
|
|
4767
|
+
} & (Machine.NodeSchema<Root> extends never ? {
|
|
4768
|
+
readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
|
|
4769
|
+
} : {} extends NodeMakeInput<Root> ? {
|
|
4770
|
+
readonly initial?: Machine.RootInitialBuilderInput<Root, Input>;
|
|
4771
|
+
} : {
|
|
4772
|
+
readonly initial: Machine.RootInitialBuilderInput<Root, Input>;
|
|
4773
|
+
});
|
|
4653
4774
|
/** @inline */
|
|
4654
4775
|
interface Make {
|
|
4776
|
+
/** @param config Complete starting configuration, including root and descendant values. */
|
|
4777
|
+
<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> & {
|
|
4778
|
+
/** Mutually exclusive with a complete initial configuration. */
|
|
4779
|
+
readonly initial?: never;
|
|
4780
|
+
/** Constructs the complete initial root configuration, overriding child defaults. */
|
|
4781
|
+
readonly initialConfiguration: Machine.RootConfigurationBuilderInput<NoInfer<Root>, Input["Type"]>;
|
|
4782
|
+
}): MakeResult<Root & {
|
|
4783
|
+
readonly "~effect/Machine/ExplicitInitial": true;
|
|
4784
|
+
}, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
|
|
4655
4785
|
/** @param config Complete schema-first machine definition. */
|
|
4656
|
-
<const
|
|
4657
|
-
readonly
|
|
4658
|
-
}
|
|
4659
|
-
/** @param config Invalid state tree retained only to report its validation error at the call site. */
|
|
4660
|
-
<const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>, "states"> & {
|
|
4661
|
-
readonly states: InvalidDefinedStateTreeInput<States>;
|
|
4662
|
-
}): never;
|
|
4786
|
+
<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> & Exclude<RootInitialization<NoInfer<Root>, Input["Type"]>, {
|
|
4787
|
+
readonly initialConfiguration: unknown;
|
|
4788
|
+
}>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration>;
|
|
4663
4789
|
}
|
|
4664
4790
|
/**
|
|
4665
4791
|
* Creates a schema-first machine definition.
|
|
@@ -4700,25 +4826,25 @@ interface Make {
|
|
|
4700
4826
|
* by: Schema.Number
|
|
4701
4827
|
* }) {}
|
|
4702
4828
|
*
|
|
4703
|
-
* const States = Machine.
|
|
4704
|
-
* const Events = Machine.
|
|
4829
|
+
* const States = Machine.state({ initial: "Count", states: { Count } })
|
|
4830
|
+
* const Events = Machine.eventsFromSchemas(Increment)
|
|
4705
4831
|
*
|
|
4706
4832
|
* const counter = Machine.make({
|
|
4707
|
-
*
|
|
4833
|
+
* root: States,
|
|
4708
4834
|
* events: Events,
|
|
4709
|
-
*
|
|
4710
|
-
* }).handle({
|
|
4835
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Count.decoded(new Count({ value: 0 }))))
|
|
4836
|
+
* }).handle({ states: {
|
|
4711
4837
|
* Count: {
|
|
4712
4838
|
* on: {
|
|
4713
4839
|
* Increment: (to) =>
|
|
4714
|
-
* to.
|
|
4840
|
+
* to.branch.Count().resolve(({ event, state, target }) =>
|
|
4715
4841
|
* target.decoded(new Count({ value: state.value + event.by })))
|
|
4716
4842
|
* }
|
|
4717
4843
|
* }
|
|
4718
|
-
* })
|
|
4844
|
+
* } })
|
|
4719
4845
|
* ```
|
|
4720
4846
|
*
|
|
4721
|
-
* @see {@link
|
|
4847
|
+
* @see {@link state} for typed state-tree helpers.
|
|
4722
4848
|
* @inlineType MakeConfig
|
|
4723
4849
|
* @category constructors
|
|
4724
4850
|
* @since 0.4.0
|
|
@@ -4743,7 +4869,7 @@ export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventO
|
|
|
4743
4869
|
* **Example**
|
|
4744
4870
|
*
|
|
4745
4871
|
* ```ts
|
|
4746
|
-
* export const Event = Machine.
|
|
4872
|
+
* export const Event = Machine.eventsFromSchemas(
|
|
4747
4873
|
* Schema.TaggedUnion({
|
|
4748
4874
|
* Increment: { by: Schema.Number },
|
|
4749
4875
|
* Reset: {}
|
|
@@ -4756,8 +4882,32 @@ export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventO
|
|
|
4756
4882
|
* @category constructors
|
|
4757
4883
|
* @since 0.10.0
|
|
4758
4884
|
*/
|
|
4759
|
-
|
|
4760
|
-
<
|
|
4885
|
+
type EventFieldsSchemas<Cases extends Readonly<Record<string, Schema.Struct.Fields>>> = keyof Cases extends never ? readonly [] : readonly [
|
|
4886
|
+
Extract<Schema.TaggedUnion<{
|
|
4887
|
+
readonly [Tag in keyof Cases & string]: Schema.TaggedStruct<Tag, Cases[Tag]>;
|
|
4888
|
+
}>, Machine.TaggedSchema>
|
|
4889
|
+
];
|
|
4890
|
+
type ValidateEventFields<Cases> = {
|
|
4891
|
+
readonly [Tag in keyof Cases]: "_tag" extends keyof Cases[Tag] ? EventProtocolError<"Event fields cannot declare _tag", Extract<Tag, PropertyKey>> : unknown;
|
|
4892
|
+
};
|
|
4893
|
+
/** Defines a public event protocol from tagged field records.
|
|
4894
|
+
*
|
|
4895
|
+
* ```ts
|
|
4896
|
+
* const Events = Machine.events({ Increment: { by: Schema.Number }, Reset: {} })
|
|
4897
|
+
* const increment = Events.Increment({ by: 1 })
|
|
4898
|
+
* ```
|
|
4899
|
+
*
|
|
4900
|
+
* Constructors defer schema validation until delivery. Use eventsFromSchemas
|
|
4901
|
+
* when importing existing tagged schemas or protocol descriptors.
|
|
4902
|
+
* @category constructors
|
|
4903
|
+
* @since 0.32.0
|
|
4904
|
+
*/
|
|
4905
|
+
export declare const events: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"public", EventFieldsSchemas<Cases>>) => Machine.EventProtocol<"public", EventFieldsSchemas<Cases>>;
|
|
4906
|
+
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
4907
|
+
* @category constructors
|
|
4908
|
+
* @since 0.32.0
|
|
4909
|
+
*/
|
|
4910
|
+
export declare const eventsFromSchemas: {
|
|
4761
4911
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"public">>>(...inputs: Inputs & ValidateEventProtocolBuilder<"public", Inputs>): Machine.EventProtocol<"public", Machine.EventProtocolInputSchemasOf<"public", Inputs>>;
|
|
4762
4912
|
};
|
|
4763
4913
|
/**
|
|
@@ -4792,7 +4942,7 @@ export declare const optionalParent: <const Events extends ReadonlyArray<Machine
|
|
|
4792
4942
|
* **Example**
|
|
4793
4943
|
*
|
|
4794
4944
|
* ```ts
|
|
4795
|
-
* const Internal = Machine.
|
|
4945
|
+
* const Internal = Machine.internalEventsFromSchemas(
|
|
4796
4946
|
* Schema.TaggedUnion({
|
|
4797
4947
|
* Loaded: { value: Schema.String },
|
|
4798
4948
|
* Failed: { message: Schema.String }
|
|
@@ -4807,8 +4957,12 @@ export declare const optionalParent: <const Events extends ReadonlyArray<Machine
|
|
|
4807
4957
|
* @category constructors
|
|
4808
4958
|
* @since 0.10.0
|
|
4809
4959
|
*/
|
|
4810
|
-
export declare const internalEvents:
|
|
4811
|
-
|
|
4960
|
+
export declare const internalEvents: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"internal", EventFieldsSchemas<Cases>>) => Machine.EventProtocol<"internal", EventFieldsSchemas<Cases>>;
|
|
4961
|
+
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
4962
|
+
* @category constructors
|
|
4963
|
+
* @since 0.32.0
|
|
4964
|
+
*/
|
|
4965
|
+
export declare const internalEventsFromSchemas: {
|
|
4812
4966
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"internal">>>(...inputs: Inputs & ValidateEventProtocolBuilder<"internal", Inputs>): Machine.EventProtocol<"internal", Machine.EventProtocolInputSchemasOf<"internal", Inputs>>;
|
|
4813
4967
|
};
|
|
4814
4968
|
/**
|
|
@@ -4820,7 +4974,7 @@ export declare const internalEvents: {
|
|
|
4820
4974
|
* **Example**
|
|
4821
4975
|
*
|
|
4822
4976
|
* ```ts
|
|
4823
|
-
* const Emitted = Machine.
|
|
4977
|
+
* const Emitted = Machine.emittedEventsFromSchemas(
|
|
4824
4978
|
* Schema.TaggedUnion({
|
|
4825
4979
|
* Saved: { id: Schema.String }
|
|
4826
4980
|
* })
|
|
@@ -4831,8 +4985,12 @@ export declare const internalEvents: {
|
|
|
4831
4985
|
* @category constructors
|
|
4832
4986
|
* @since 0.10.0
|
|
4833
4987
|
*/
|
|
4834
|
-
export declare const emittedEvents:
|
|
4835
|
-
|
|
4988
|
+
export declare const emittedEvents: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"emitted", EventFieldsSchemas<Cases>>) => Machine.EventProtocol<"emitted", EventFieldsSchemas<Cases>>;
|
|
4989
|
+
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
4990
|
+
* @category constructors
|
|
4991
|
+
* @since 0.32.0
|
|
4992
|
+
*/
|
|
4993
|
+
export declare const emittedEventsFromSchemas: {
|
|
4836
4994
|
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"emitted">>>(...inputs: Inputs & ValidateEventProtocolBuilder<"emitted", Inputs>): Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>>;
|
|
4837
4995
|
};
|
|
4838
4996
|
/**
|
|
@@ -4868,12 +5026,12 @@ export declare const emittedEvents: {
|
|
|
4868
5026
|
* import { Machine } from "@typeonce/effect-machine"
|
|
4869
5027
|
*
|
|
4870
5028
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
4871
|
-
* const States = Machine.
|
|
5029
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
4872
5030
|
* const machine = Machine.make({
|
|
4873
|
-
*
|
|
4874
|
-
* events: Machine.
|
|
4875
|
-
*
|
|
4876
|
-
* }).handle({ Idle: {} })
|
|
5031
|
+
* root: States,
|
|
5032
|
+
* events: Machine.eventsFromSchemas(),
|
|
5033
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
5034
|
+
* }).handle({ states: { Idle: {} } })
|
|
4877
5035
|
*
|
|
4878
5036
|
* const encoded = Effect.gen(function*() {
|
|
4879
5037
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -4912,12 +5070,12 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
4912
5070
|
* import { Machine } from "@typeonce/effect-machine"
|
|
4913
5071
|
*
|
|
4914
5072
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
4915
|
-
* const States = Machine.
|
|
5073
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
4916
5074
|
* const machine = Machine.make({
|
|
4917
|
-
*
|
|
4918
|
-
* events: Machine.
|
|
4919
|
-
*
|
|
4920
|
-
* }).handle({ Idle: {} })
|
|
5075
|
+
* root: States,
|
|
5076
|
+
* events: Machine.eventsFromSchemas(),
|
|
5077
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
5078
|
+
* }).handle({ states: { Idle: {} } })
|
|
4921
5079
|
*
|
|
4922
5080
|
* const roundTrip = Effect.gen(function*() {
|
|
4923
5081
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -4971,12 +5129,12 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
4971
5129
|
* import { Machine } from "@typeonce/effect-machine"
|
|
4972
5130
|
*
|
|
4973
5131
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
4974
|
-
* const States = Machine.
|
|
5132
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
4975
5133
|
* const machine = Machine.make({
|
|
4976
|
-
*
|
|
4977
|
-
* events: Machine.
|
|
4978
|
-
*
|
|
4979
|
-
* }).handle({ Idle: {} })
|
|
5134
|
+
* root: States,
|
|
5135
|
+
* events: Machine.eventsFromSchemas(),
|
|
5136
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
5137
|
+
* }).handle({ states: { Idle: {} } })
|
|
4980
5138
|
*
|
|
4981
5139
|
* const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
|
|
4982
5140
|
* ```
|
|
@@ -4991,14 +5149,14 @@ export declare const planInitial: <const States extends Machine.StateSchemas, co
|
|
|
4991
5149
|
readonly initialEntryPaths: ReadonlyArray<Machine.StateIdentifier<States>>;
|
|
4992
5150
|
readonly state: Machine.Snapshot<States>;
|
|
4993
5151
|
readonly commands: ReadonlyArray<Command>;
|
|
4994
|
-
readonly emittedEvents: ReadonlyArray<Machine.
|
|
5152
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>;
|
|
4995
5153
|
readonly microsteps: ReadonlyArray<{
|
|
4996
5154
|
readonly next: Machine.Snapshot<States>;
|
|
4997
5155
|
readonly event: Machine.EventOf<Events> | InitialEvent;
|
|
4998
5156
|
readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<States>, Machine.TagOf<Events[number]>, Machine.StateNodeIdentifier<States>>>;
|
|
4999
5157
|
readonly commands: ReadonlyArray<Command>;
|
|
5000
5158
|
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>;
|
|
5001
|
-
readonly emittedEvents: ReadonlyArray<Machine.
|
|
5159
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>;
|
|
5002
5160
|
readonly exitPaths: ReadonlyArray<string>;
|
|
5003
5161
|
readonly entryPaths: ReadonlyArray<string>;
|
|
5004
5162
|
readonly changed: boolean;
|
|
@@ -5115,23 +5273,38 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5115
5273
|
* they accept the event. Any commands, emissions, or raised events collected
|
|
5116
5274
|
* during that check are discarded.
|
|
5117
5275
|
*
|
|
5118
|
-
* Event input is decoded through the machine's public event
|
|
5119
|
-
* input fails with `MachineSchemaDecodeError`. Final snapshots and valid events
|
|
5276
|
+
* Event input is decoded through the machine's public and internal event protocols.
|
|
5277
|
+
* Invalid input fails with `MachineSchemaDecodeError`. Final snapshots and valid events
|
|
5120
5278
|
* with no accepting handler return `false`.
|
|
5121
5279
|
*
|
|
5122
5280
|
* **Gotchas**
|
|
5123
5281
|
*
|
|
5124
5282
|
* This query does not execute transitions or stabilize the resulting machine.
|
|
5125
5283
|
* It does not run entry, exit, always, completion, child lifecycle, or command
|
|
5126
|
-
* effects. A `true` result therefore describes event acceptance only
|
|
5284
|
+
* effects. A `true` result therefore describes event acceptance only, for this
|
|
5285
|
+
* snapshot. It does not guarantee acceptance after the machine advances.
|
|
5286
|
+
*
|
|
5287
|
+
* This Effect can also be used by machine effects to query internal events.
|
|
5288
|
+
* Synchronous transition resolvers cannot execute it. Querying an internal event
|
|
5289
|
+
* does not make that event available to `MachineRef.send`.
|
|
5127
5290
|
*
|
|
5128
5291
|
* **Example**
|
|
5129
5292
|
*
|
|
5130
5293
|
* ```ts
|
|
5131
|
-
*
|
|
5294
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
5295
|
+
* import { Effect, Schema } from "effect"
|
|
5296
|
+
*
|
|
5297
|
+
* const internalEvents = Machine.internalEventsFromSchemas(Schema.TaggedStruct("Loaded", {}))
|
|
5298
|
+
* const machine = Machine.make({
|
|
5299
|
+
* root: Machine.state({ initial: "Idle", states: { Idle: {} } }),
|
|
5300
|
+
* events: Machine.eventsFromSchemas(),
|
|
5301
|
+
* internalEvents,
|
|
5302
|
+
* initialConfiguration: (root) => root.resolve(({ target }) => target.from((to) => to.Idle.from()))
|
|
5303
|
+
* }).handle({ states: { Idle: { on: { Loaded: (to) => to.none } } } })
|
|
5132
5304
|
*
|
|
5133
|
-
* const
|
|
5134
|
-
*
|
|
5305
|
+
* export const canLoad = Effect.gen(function*() {
|
|
5306
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
5307
|
+
* return yield* Machine.can(machine, initial.state, internalEvents.Loaded())
|
|
5135
5308
|
* })
|
|
5136
5309
|
* ```
|
|
5137
5310
|
*
|
|
@@ -5139,11 +5312,11 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5139
5312
|
* @since 0.30.0
|
|
5140
5313
|
*/
|
|
5141
5314
|
export declare const can: {
|
|
5142
|
-
<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> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>): (state: Machine.Snapshot<States>, event: Machine.EventInputOf<
|
|
5143
|
-
<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> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, state: Machine.Snapshot<States>, event: Machine.EventInputOf<
|
|
5315
|
+
<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> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>): (state: Machine.Snapshot<States>, event: Machine.EventInputOf<Events>) => Effect.Effect<boolean, MachineSchemaDecodeError>;
|
|
5316
|
+
<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> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, state: Machine.Snapshot<States>, event: Machine.EventInputOf<Events>): Effect.Effect<boolean, MachineSchemaDecodeError>;
|
|
5144
5317
|
};
|
|
5145
5318
|
/**
|
|
5146
|
-
*
|
|
5319
|
+
* Returns an Effect that plans the next state snapshot without running command effects.
|
|
5147
5320
|
*
|
|
5148
5321
|
* **Details**
|
|
5149
5322
|
*
|
|
@@ -5168,20 +5341,20 @@ export declare const can: {
|
|
|
5168
5341
|
* class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {}
|
|
5169
5342
|
* class On extends Schema.TaggedClass<On>("On")("On", {}) {}
|
|
5170
5343
|
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
|
|
5171
|
-
* const States = Machine.
|
|
5344
|
+
* const States = Machine.state({ initial: "Off", states: { Off, On } })
|
|
5172
5345
|
* const machine = Machine.make({
|
|
5173
|
-
*
|
|
5174
|
-
* events: Machine.
|
|
5175
|
-
*
|
|
5176
|
-
* }).handle({
|
|
5346
|
+
* root: States,
|
|
5347
|
+
* events: Machine.eventsFromSchemas(Toggle),
|
|
5348
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Off.from()))
|
|
5349
|
+
* }).handle({ states: {
|
|
5177
5350
|
* Off: {
|
|
5178
5351
|
* on: {
|
|
5179
5352
|
* Toggle: (to) =>
|
|
5180
|
-
* to.
|
|
5353
|
+
* to.branch.On().resolve(({ target }) => target.from())
|
|
5181
5354
|
* }
|
|
5182
5355
|
* },
|
|
5183
5356
|
* On: {}
|
|
5184
|
-
* })
|
|
5357
|
+
* } })
|
|
5185
5358
|
*
|
|
5186
5359
|
* const nextState = Effect.gen(function*() {
|
|
5187
5360
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -5195,16 +5368,17 @@ export declare const can: {
|
|
|
5195
5368
|
* @since 0.4.0
|
|
5196
5369
|
*/
|
|
5197
5370
|
export declare const plan: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, state: Machine.Snapshot<States>, event: Machine.EventInputOf<InputEvents>) => Effect.Effect<{
|
|
5371
|
+
readonly event: Machine.EventOf<InputEvents>;
|
|
5198
5372
|
readonly next: Machine.Snapshot<States>;
|
|
5199
5373
|
readonly commands: ReadonlyArray<Command>;
|
|
5200
|
-
readonly emittedEvents: ReadonlyArray<Machine.
|
|
5374
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>;
|
|
5201
5375
|
readonly microsteps: ReadonlyArray<{
|
|
5202
5376
|
readonly next: Machine.Snapshot<States>;
|
|
5203
5377
|
readonly event: Machine.EventOf<Events> | InitialEvent;
|
|
5204
5378
|
readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<States>, Machine.TagOf<Events[number]>, Machine.StateNodeIdentifier<States>>>;
|
|
5205
5379
|
readonly commands: ReadonlyArray<Command>;
|
|
5206
5380
|
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>;
|
|
5207
|
-
readonly emittedEvents: ReadonlyArray<Machine.
|
|
5381
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmittedEventOf<Emits>>;
|
|
5208
5382
|
readonly exitPaths: ReadonlyArray<string>;
|
|
5209
5383
|
readonly entryPaths: ReadonlyArray<string>;
|
|
5210
5384
|
readonly changed: boolean;
|
|
@@ -5351,7 +5525,7 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
5351
5525
|
* @category constructors
|
|
5352
5526
|
* @since 0.11.0
|
|
5353
5527
|
*/
|
|
5354
|
-
export declare const prepare: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<Prepared<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.
|
|
5528
|
+
export declare const prepare: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<Prepared<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmittedEventOf<Emits>>>>;
|
|
5355
5529
|
/**
|
|
5356
5530
|
* Starts a machine.
|
|
5357
5531
|
*
|
|
@@ -5381,12 +5555,12 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
|
|
|
5381
5555
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5382
5556
|
*
|
|
5383
5557
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
5384
|
-
* const States = Machine.
|
|
5558
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
5385
5559
|
* const machine = Machine.make({
|
|
5386
|
-
*
|
|
5387
|
-
* events: Machine.
|
|
5388
|
-
*
|
|
5389
|
-
* }).handle({ Idle: {} })
|
|
5560
|
+
* root: States,
|
|
5561
|
+
* events: Machine.eventsFromSchemas(),
|
|
5562
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
5563
|
+
* }).handle({ states: { Idle: {} } })
|
|
5390
5564
|
*
|
|
5391
5565
|
* const state = Effect.gen(function*() {
|
|
5392
5566
|
* const ref = yield* Machine.start(machine)
|
|
@@ -5399,7 +5573,7 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
|
|
|
5399
5573
|
* @category constructors
|
|
5400
5574
|
* @since 0.4.0
|
|
5401
5575
|
*/
|
|
5402
|
-
export declare const start: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.
|
|
5576
|
+
export declare const start: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmittedEventOf<Emits>>>;
|
|
5403
5577
|
/**
|
|
5404
5578
|
* Starts a fresh managed runtime from a decoded logical snapshot.
|
|
5405
5579
|
*
|
|
@@ -5431,12 +5605,12 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
5431
5605
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5432
5606
|
*
|
|
5433
5607
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
5434
|
-
* const States = Machine.
|
|
5608
|
+
* const States = Machine.state({ initial: "Idle", states: { Idle } })
|
|
5435
5609
|
* const machine = Machine.make({
|
|
5436
|
-
*
|
|
5437
|
-
* events: Machine.
|
|
5438
|
-
*
|
|
5439
|
-
* }).handle({ Idle: {} })
|
|
5610
|
+
* root: States,
|
|
5611
|
+
* events: Machine.eventsFromSchemas(),
|
|
5612
|
+
* initialConfiguration: root => root.resolve(({ target }) => target.from(to => to.Idle.from()))
|
|
5613
|
+
* }).handle({ states: { Idle: {} } })
|
|
5440
5614
|
*
|
|
5441
5615
|
* const resumed = Effect.gen(function*() {
|
|
5442
5616
|
* const initial = yield* Machine.planInitial(machine)
|
|
@@ -5451,5 +5625,5 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
5451
5625
|
* @category constructors
|
|
5452
5626
|
* @since 0.4.0
|
|
5453
5627
|
*/
|
|
5454
|
-
export declare const resume: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, snapshot: Machine.Snapshot<States>) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>>, MachineSchemaDecodeError, ExcludeCompatibleRuntime<ExecutionServices<R>, Machine.EventOf<Events>, Machine.
|
|
5628
|
+
export declare const resume: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents> & EnsureExecutable<States, UnhandledStates, OutputStates> & Machine.RootCompatible<ParentEvents>, snapshot: Machine.Snapshot<States>) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventInputOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output, Machine.EmittedEventOf<Emits>>, MachineSchemaDecodeError, ExcludeCompatibleRuntime<ExecutionServices<R>, Machine.EventOf<Events>, Machine.EmittedEventOf<Emits>>>;
|
|
5455
5629
|
//# sourceMappingURL=Machine.d.ts.map
|