@typeonce/effect-machine 0.1.0 → 0.2.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/NOTICE +0 -2
- package/README.md +347 -52
- package/dist/AtomMachine.d.ts +187 -10
- package/dist/AtomMachine.d.ts.map +1 -1
- package/dist/AtomMachine.js +145 -18
- package/dist/AtomMachine.js.map +1 -1
- package/dist/ClusterMachine.d.ts +15 -5
- package/dist/ClusterMachine.d.ts.map +1 -1
- package/dist/ClusterMachine.js.map +1 -1
- package/dist/Machine.d.ts +410 -94
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +105 -47
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machineModel.d.ts +6 -1
- package/dist/internal/machineModel.d.ts.map +1 -1
- package/dist/internal/machineModel.js +68 -15
- package/dist/internal/machineModel.js.map +1 -1
- package/dist/internal/machinePlanner.d.ts +15 -5
- package/dist/internal/machinePlanner.d.ts.map +1 -1
- package/dist/internal/machinePlanner.js +75 -48
- package/dist/internal/machinePlanner.js.map +1 -1
- package/dist/internal/machineProcess.d.ts +2 -2
- package/dist/internal/machineProcess.d.ts.map +1 -1
- package/dist/internal/machineProcess.js +22 -11
- package/dist/internal/machineProcess.js.map +1 -1
- package/dist/internal/machineRuntime.d.ts +11 -5
- package/dist/internal/machineRuntime.d.ts.map +1 -1
- package/dist/internal/machineRuntime.js +24 -13
- package/dist/internal/machineRuntime.js.map +1 -1
- package/docs/agent-guide.md +585 -0
- package/package.json +18 -21
package/dist/Machine.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @since 4.0.0
|
|
5
5
|
*/
|
|
6
6
|
import type * as Cause from "effect/Cause";
|
|
7
|
+
import type * as Duration from "effect/Duration";
|
|
7
8
|
import * as Effect from "effect/Effect";
|
|
8
9
|
import * as Option from "effect/Option";
|
|
9
10
|
import { type Pipeable } from "effect/Pipeable";
|
|
@@ -30,6 +31,7 @@ export type TypeId = "~effect/Machine";
|
|
|
30
31
|
* @since 4.0.0
|
|
31
32
|
*/
|
|
32
33
|
export declare const TypeId: TypeId;
|
|
34
|
+
declare const MachineOutputStatesTypeId: unique symbol;
|
|
33
35
|
/**
|
|
34
36
|
* Type identifier used for the synthetic event passed to startup lifecycle
|
|
35
37
|
* actions.
|
|
@@ -76,26 +78,68 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
76
78
|
*
|
|
77
79
|
* **Gotchas**
|
|
78
80
|
*
|
|
79
|
-
* History states
|
|
80
|
-
*
|
|
81
|
-
*
|
|
81
|
+
* History states and declarative first-class guards are not part of the
|
|
82
|
+
* current API. Conditional behavior can be expressed in typed handlers with
|
|
83
|
+
* ordinary TypeScript control flow. Use `after` for cancellable state-scoped
|
|
84
|
+
* delayed events.
|
|
82
85
|
*
|
|
83
86
|
* @category models
|
|
84
87
|
* @since 4.0.0
|
|
85
88
|
*/
|
|
86
|
-
export interface Machine<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, 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, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], OutputStates extends Machine.StateIdentifier<States> = never> extends Pipeable {
|
|
89
|
+
export interface Machine<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, 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, Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events> extends Pipeable {
|
|
87
90
|
readonly [TypeId]: TypeId;
|
|
91
|
+
/** @internal Prevents output implementation evidence from being widened. */
|
|
92
|
+
readonly [MachineOutputStatesTypeId]: Readonly<Record<OutputStates, true>>;
|
|
93
|
+
/**
|
|
94
|
+
* State tree that defines the machine topology and state value schemas.
|
|
95
|
+
*
|
|
96
|
+
* @since 4.0.0
|
|
97
|
+
*/
|
|
88
98
|
readonly states: States;
|
|
89
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Events accepted through public machine input boundaries.
|
|
101
|
+
*
|
|
102
|
+
* @since 4.0.0
|
|
103
|
+
*/
|
|
104
|
+
readonly events: InputEvents;
|
|
105
|
+
/**
|
|
106
|
+
* Events reserved for invokes, child emissions, and other machine-local work.
|
|
107
|
+
*
|
|
108
|
+
* @since 4.0.0
|
|
109
|
+
*/
|
|
110
|
+
readonly internalEvents: ReadonlyArray<Machine.TaggedSchema>;
|
|
111
|
+
/**
|
|
112
|
+
* Events that the machine may emit to its parent or external adapter.
|
|
113
|
+
*
|
|
114
|
+
* @since 4.0.0
|
|
115
|
+
*/
|
|
90
116
|
readonly emits: Emits;
|
|
117
|
+
/**
|
|
118
|
+
* Optional schema used to decode the machine input before initialization.
|
|
119
|
+
*
|
|
120
|
+
* @since 4.0.0
|
|
121
|
+
*/
|
|
91
122
|
readonly input: Input | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Optional stable identity used by runtime and persistence integrations.
|
|
125
|
+
*
|
|
126
|
+
* @since 4.0.0
|
|
127
|
+
*/
|
|
92
128
|
readonly id: string | undefined;
|
|
93
129
|
/** @internal */
|
|
94
130
|
readonly stateNodes: Machine.StateNodes;
|
|
95
131
|
/** @internal */
|
|
96
132
|
readonly makeTargetBuilder: <Source extends Machine.StateIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
|
|
133
|
+
/** @internal */
|
|
97
134
|
readonly handlers: Machine.StateConfigs<States, Events, Emits, UnhandledStates, Machine.TagOf<Events[number]>, E, R>;
|
|
98
|
-
|
|
135
|
+
/**
|
|
136
|
+
* Adds typed state handlers and returns the refined machine definition.
|
|
137
|
+
* Successive calls implement the remaining unhandled states while retaining
|
|
138
|
+
* accumulated errors, services, final states, and output evidence.
|
|
139
|
+
*
|
|
140
|
+
* @since 4.0.0
|
|
141
|
+
*/
|
|
142
|
+
readonly handle: Machine.Handler<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents>;
|
|
99
143
|
/** @internal */
|
|
100
144
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
|
|
101
145
|
}
|
|
@@ -207,7 +251,17 @@ export type ExecutionServices<Requirements> = Exclude<PlanningServices<Requireme
|
|
|
207
251
|
* @since 4.0.0
|
|
208
252
|
*/
|
|
209
253
|
export interface Runtime<in Events, in Emits> {
|
|
254
|
+
/**
|
|
255
|
+
* Queues an event for the current machine macrostep.
|
|
256
|
+
*
|
|
257
|
+
* @since 4.0.0
|
|
258
|
+
*/
|
|
210
259
|
readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
260
|
+
/**
|
|
261
|
+
* Emits an event through the running machine's parent boundary.
|
|
262
|
+
*
|
|
263
|
+
* @since 4.0.0
|
|
264
|
+
*/
|
|
211
265
|
readonly sendParent: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
212
266
|
}
|
|
213
267
|
/**
|
|
@@ -321,6 +375,15 @@ type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Nod
|
|
|
321
375
|
type ValidateDefinedStates<States extends Machine.StateSchemas> = [States] extends [
|
|
322
376
|
Machine.ValidateStateSchemas<States>
|
|
323
377
|
] ? [] : [validation: Machine.ValidateStateSchemas<States>];
|
|
378
|
+
type EventProtocolError<Message extends string, Tag extends PropertyKey = never> = {
|
|
379
|
+
readonly "~effect/Machine/EventProtocolError": Message;
|
|
380
|
+
readonly tag: Tag;
|
|
381
|
+
};
|
|
382
|
+
type DuplicateEventTag<Events extends ReadonlyArray<Machine.TaggedSchema>, Seen extends PropertyKey = never> = number extends Events["length"] ? never : Events extends readonly [
|
|
383
|
+
infer Head extends Machine.TaggedSchema,
|
|
384
|
+
...infer Tail extends ReadonlyArray<Machine.TaggedSchema>
|
|
385
|
+
] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ? Tag extends Seen ? Tag | DuplicateEventTag<Tail, Seen> : DuplicateEventTag<Tail, Seen | Tag> : never : never;
|
|
386
|
+
type ValidateEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInput extends PropertyKey = DuplicateEventTag<InputEvents>, DuplicateInternal extends PropertyKey = DuplicateEventTag<InternalEvents>, Overlap extends PropertyKey = Extract<Machine.TagOf<InputEvents[number]>, Machine.TagOf<InternalEvents[number]>>> = [DuplicateInput] extends [never] ? [DuplicateInternal] extends [never] ? [Overlap] extends [never] ? [] : [validation: EventProtocolError<"Public and internal event tags must be disjoint", Overlap>] : [validation: EventProtocolError<"Internal event tags must be unique", DuplicateInternal>] : [validation: EventProtocolError<"Public event tags must be unique", DuplicateInput>];
|
|
324
387
|
declare const SnapshotBuilderStateTypeId: unique symbol;
|
|
325
388
|
type SnapshotBuilderComplete<Regions> = {
|
|
326
389
|
readonly [SnapshotBuilderStateTypeId]: Regions;
|
|
@@ -433,7 +496,7 @@ type SpawnIdError<Options extends SpawnOptions> = "id" extends keyof Options ? O
|
|
|
433
496
|
readonly id?: infer Id;
|
|
434
497
|
} ? [Id] extends [undefined] ? never : ChildAlreadyExistsError : ChildAlreadyExistsError : never;
|
|
435
498
|
type SpawnError<Options extends SpawnOptions> = SpawnIdError<Options>;
|
|
436
|
-
type SpawnResult<State, Event, Error, Requirements, Output, SpawnError, InitialError = never> = Effect.Effect<MachineRef<State, Event, Error
|
|
499
|
+
type SpawnResult<State, Event, Error, Requirements, Output, SpawnError, InitialError = never> = Effect.Effect<MachineRef<State, Event, Error, Output>, SpawnError | InitialError, MachineRuntimeRequirement | SpawnRequirements<Requirements>>;
|
|
437
500
|
/**
|
|
438
501
|
* Represents the active or terminal lifecycle state of a running machine.
|
|
439
502
|
*
|
|
@@ -520,17 +583,33 @@ export type RuntimeOutcome<State, Error = never, Output = never> = {
|
|
|
520
583
|
* @since 4.0.0
|
|
521
584
|
*/
|
|
522
585
|
export interface MachineRef<out State, in Event, out Error = never, out Output = never> {
|
|
586
|
+
/** Stable machine definition id, or a generated fallback when none was declared. */
|
|
523
587
|
readonly id: string;
|
|
588
|
+
/** Unique identity for this running machine instance. */
|
|
524
589
|
readonly sessionId: string;
|
|
590
|
+
/** Reads the latest logical state. */
|
|
525
591
|
readonly state: Effect.Effect<State>;
|
|
592
|
+
/** Reads the latest lifecycle snapshot. */
|
|
526
593
|
readonly snapshot: Effect.Effect<RuntimeSnapshot<State, Error, Output>>;
|
|
594
|
+
/** Streams lifecycle snapshots published after subscription. */
|
|
527
595
|
readonly changes: Stream.Stream<RuntimeSnapshot<State, Error, Output>>;
|
|
596
|
+
/** Waits for machine output or fails when execution fails or is stopped. */
|
|
528
597
|
readonly join: Effect.Effect<Output, Error | StoppedError>;
|
|
598
|
+
/** Stops this machine instance and its owned child processes. */
|
|
529
599
|
readonly stop: Effect.Effect<void>;
|
|
600
|
+
/** Accepts an event for asynchronous processing by the running machine. */
|
|
530
601
|
readonly send: (event: Event) => Effect.Effect<void, StoppedError>;
|
|
531
|
-
/**
|
|
602
|
+
/**
|
|
603
|
+
* Returns the current directly owned child for a typed descriptor.
|
|
604
|
+
*
|
|
605
|
+
* @since 4.0.0
|
|
606
|
+
*/
|
|
532
607
|
readonly child: <Child extends ChildMachine.Any>(child: Child) => Effect.Effect<Option.Option<ChildMachine.Ref<Child>>>;
|
|
533
|
-
/**
|
|
608
|
+
/**
|
|
609
|
+
* Streams activation, replacement, and removal of a directly owned child.
|
|
610
|
+
*
|
|
611
|
+
* @since 4.0.0
|
|
612
|
+
*/
|
|
534
613
|
readonly childChanges: <Child extends ChildMachine.Any>(child: Child) => Stream.Stream<Option.Option<ChildMachine.Ref<Child>>>;
|
|
535
614
|
}
|
|
536
615
|
/**
|
|
@@ -540,7 +619,9 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
540
619
|
* @since 4.0.0
|
|
541
620
|
*/
|
|
542
621
|
export interface Logic<State, Event, out Error = never, out Requirements = never, out Output = never, out InitialError = never> {
|
|
622
|
+
/** Creates the initial process state and may spawn scoped child processes. */
|
|
543
623
|
initial(scope: Logic.Scope<Event>): Effect.Effect<State, InitialError, Requirements>;
|
|
624
|
+
/** Runs the stateful process loop until it produces output or fails. */
|
|
544
625
|
run(context: Logic.Context<State, Event>): Effect.Effect<Output, Error, Requirements>;
|
|
545
626
|
}
|
|
546
627
|
/**
|
|
@@ -556,9 +637,13 @@ export declare namespace Logic {
|
|
|
556
637
|
* @since 4.0.0
|
|
557
638
|
*/
|
|
558
639
|
interface Address<in Event> {
|
|
640
|
+
/** Parent-local address id. */
|
|
559
641
|
readonly id: string;
|
|
642
|
+
/** Unique identity for this running child instance. */
|
|
560
643
|
readonly sessionId: string;
|
|
644
|
+
/** Stops the addressed child process. */
|
|
561
645
|
readonly stop: Effect.Effect<void>;
|
|
646
|
+
/** Sends an event to the addressed child process. */
|
|
562
647
|
readonly send: (event: Event) => Effect.Effect<void, StoppedError>;
|
|
563
648
|
}
|
|
564
649
|
/**
|
|
@@ -568,10 +653,8 @@ export declare namespace Logic {
|
|
|
568
653
|
* @since 4.0.0
|
|
569
654
|
*/
|
|
570
655
|
interface Spawn {
|
|
571
|
-
<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError = never>(logic: Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>): Effect.Effect<MachineRef<ChildState, ChildEvent, ChildError
|
|
572
|
-
<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError = never>(logic: Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, options:
|
|
573
|
-
readonly id: string;
|
|
574
|
-
}): Effect.Effect<MachineRef<ChildState, ChildEvent, ChildError | ChildInitialError, ChildOutput>, ChildAlreadyExistsError | ChildInitialError, Exclude<ChildRequirements, Scope.Scope>>;
|
|
656
|
+
<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError = never>(logic: Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>): Effect.Effect<MachineRef<ChildState, ChildEvent, ChildError, ChildOutput>, ChildInitialError, Exclude<ChildRequirements, Scope.Scope>>;
|
|
657
|
+
<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, Options extends SpawnOptions, ChildInitialError = never>(logic: Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>, options: Options & ChildAddress.OptionsCompatibility<Options, ChildEvent>): Effect.Effect<MachineRef<ChildState, ChildEvent, ChildError, ChildOutput>, SpawnIdError<Options> | ChildInitialError, Exclude<ChildRequirements, Scope.Scope>>;
|
|
575
658
|
}
|
|
576
659
|
/**
|
|
577
660
|
* Machine-local capabilities available while process logic initializes.
|
|
@@ -586,12 +669,18 @@ export declare namespace Logic {
|
|
|
586
669
|
* @since 4.0.0
|
|
587
670
|
*/
|
|
588
671
|
interface Scope<Event> {
|
|
672
|
+
/** Address of the process being initialized. */
|
|
589
673
|
readonly self: Address<Event>;
|
|
674
|
+
/** Address of the owning process, when one exists. */
|
|
590
675
|
readonly parent: Address<unknown> | undefined;
|
|
676
|
+
/** Starts a child process owned by this scope. */
|
|
591
677
|
readonly spawn: Spawn;
|
|
678
|
+
/** Sends an untyped event to the owning process. */
|
|
592
679
|
readonly sendParent: (event: unknown) => Effect.Effect<void, StoppedError>;
|
|
593
|
-
|
|
594
|
-
readonly
|
|
680
|
+
/** Sends an event through a typed parent-local child address. */
|
|
681
|
+
readonly sendTo: <Address extends ChildAddress<never>>(id: Address, event: ChildAddress.Event<Address>) => Effect.Effect<void, StoppedError>;
|
|
682
|
+
/** Stops a child process selected by its parent-local address. */
|
|
683
|
+
readonly stopChild: <Event>(id: ChildAddress<Event>) => Effect.Effect<void>;
|
|
595
684
|
}
|
|
596
685
|
/**
|
|
597
686
|
* Machine-local capabilities available while stateful process logic runs.
|
|
@@ -600,15 +689,22 @@ export declare namespace Logic {
|
|
|
600
689
|
* @since 4.0.0
|
|
601
690
|
*/
|
|
602
691
|
interface Context<State, Event> extends Scope<Event> {
|
|
692
|
+
/** Waits for the next event delivered to this process. */
|
|
603
693
|
readonly receive: Effect.Effect<Event>;
|
|
694
|
+
/** Reads the current process state. */
|
|
604
695
|
readonly state: Effect.Effect<State>;
|
|
696
|
+
/** Replaces the current process state. */
|
|
605
697
|
readonly setState: (state: State) => Effect.Effect<void>;
|
|
698
|
+
/** Updates the current process state effectfully and atomically. */
|
|
606
699
|
readonly updateState: <E, R>(update: (state: State) => Effect.Effect<State, E, R>) => Effect.Effect<void, E, R>;
|
|
607
700
|
}
|
|
608
701
|
}
|
|
609
702
|
declare const ChildAddressTypeId = "~effect/Machine/ChildAddress";
|
|
610
703
|
declare const ChildAddressCompatibilityErrorTypeId = "~effect/Machine/ChildAddressCompatibilityError";
|
|
611
704
|
declare const ChildMachineTypeId = "~effect/Machine/ChildMachine";
|
|
705
|
+
type InvokeLifecycleId = string & {
|
|
706
|
+
readonly [ChildAddressTypeId]?: never;
|
|
707
|
+
};
|
|
612
708
|
/**
|
|
613
709
|
* Typed descriptor for a complete machine invoked as a child.
|
|
614
710
|
*
|
|
@@ -623,7 +719,9 @@ declare const ChildMachineTypeId = "~effect/Machine/ChildMachine";
|
|
|
623
719
|
*/
|
|
624
720
|
export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
625
721
|
readonly [ChildMachineTypeId]: typeof ChildMachineTypeId;
|
|
722
|
+
/** Parent-local id used to address the invoked child. */
|
|
626
723
|
readonly id: Id;
|
|
724
|
+
/** Complete machine definition carried by this descriptor. */
|
|
627
725
|
readonly machine: M;
|
|
628
726
|
}
|
|
629
727
|
/**
|
|
@@ -645,7 +743,7 @@ export declare namespace ChildMachine {
|
|
|
645
743
|
* @category utility types
|
|
646
744
|
* @since 4.0.0
|
|
647
745
|
*/
|
|
648
|
-
type Ref<Child> = Child extends ChildMachine<string, infer M> ? M extends Machine<infer States, infer Events, any, any, infer E, infer R, infer InitialE, infer InitialR, any, infer Output, any, any> ? MachineRef<Machine.Snapshot<States>, Machine.EventOf<
|
|
746
|
+
type Ref<Child> = Child extends ChildMachine<string, infer M> ? M extends Machine<infer States, infer Events, any, any, infer E, infer R, infer InitialE, infer InitialR, any, infer Output, any, any, infer InputEvents> ? MachineRef<Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output> : never : never;
|
|
649
747
|
/**
|
|
650
748
|
* Event accepted by the child selected by a descriptor.
|
|
651
749
|
*
|
|
@@ -738,10 +836,47 @@ export declare namespace Machine {
|
|
|
738
836
|
/**
|
|
739
837
|
* Any schema-first machine.
|
|
740
838
|
*
|
|
839
|
+
* This is an erased structural view for APIs that store machines without
|
|
840
|
+
* knowing their protocols. Generic APIs should capture `M extends Any` to
|
|
841
|
+
* preserve the concrete machine type. The private output-implementation
|
|
842
|
+
* proof is intentionally omitted so erasing a machine cannot manufacture
|
|
843
|
+
* that proof on another concrete `Machine` type.
|
|
844
|
+
*
|
|
741
845
|
* @category models
|
|
742
846
|
* @since 4.0.0
|
|
743
847
|
*/
|
|
744
|
-
|
|
848
|
+
interface Any extends Pipeable {
|
|
849
|
+
readonly [TypeId]: TypeId;
|
|
850
|
+
readonly states: StateSchemas;
|
|
851
|
+
readonly events: ReadonlyArray<TaggedSchema>;
|
|
852
|
+
readonly internalEvents: ReadonlyArray<TaggedSchema>;
|
|
853
|
+
readonly emits: ReadonlyArray<TaggedSchema>;
|
|
854
|
+
readonly input: Schema.Top | undefined;
|
|
855
|
+
readonly id: string | undefined;
|
|
856
|
+
readonly stateNodes: StateNodes;
|
|
857
|
+
/** @internal */
|
|
858
|
+
readonly makeTargetBuilder: any;
|
|
859
|
+
/** @internal */
|
|
860
|
+
readonly handlers: any;
|
|
861
|
+
/** @internal */
|
|
862
|
+
readonly handle: any;
|
|
863
|
+
/** @internal */
|
|
864
|
+
readonly initial: any;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Extracts the complete event protocol handled inside a machine.
|
|
868
|
+
*
|
|
869
|
+
* @category utility types
|
|
870
|
+
* @since 4.0.0
|
|
871
|
+
*/
|
|
872
|
+
type Event<M extends Any> = M extends Machine<any, infer Events, any, any, any, any, any, any, any, any, any, any, any> ? EventOf<Events> : never;
|
|
873
|
+
/**
|
|
874
|
+
* Extracts the event protocol accepted by public machine input boundaries.
|
|
875
|
+
*
|
|
876
|
+
* @category utility types
|
|
877
|
+
* @since 4.0.0
|
|
878
|
+
*/
|
|
879
|
+
type InputEvent<M extends Any> = M extends Machine<any, any, any, any, any, any, any, any, any, any, any, any, infer InputEvents> ? EventOf<InputEvents> : never;
|
|
745
880
|
/**
|
|
746
881
|
* A schema whose decoded value contains a `_tag` discriminator.
|
|
747
882
|
*
|
|
@@ -847,7 +982,9 @@ export declare namespace Machine {
|
|
|
847
982
|
* @since 4.0.0
|
|
848
983
|
*/
|
|
849
984
|
interface DefinedStates<States extends StateSchemas> {
|
|
985
|
+
/** Original state tree supplied to {@link defineStates}. */
|
|
850
986
|
readonly states: States;
|
|
987
|
+
/** Type-safe builders for constructing valid initial snapshots. */
|
|
851
988
|
readonly initial: InitialBuilder<States>;
|
|
852
989
|
/**
|
|
853
990
|
* Returns the decoded value for an active state path.
|
|
@@ -1028,6 +1165,13 @@ export declare namespace Machine {
|
|
|
1028
1165
|
* @since 4.0.0
|
|
1029
1166
|
*/
|
|
1030
1167
|
type ParentStateIdentifier<StateId extends string> = StateId extends `${infer Parent}.${infer Child}` ? Parent | (Child extends `${string}.${string}` ? `${Parent}.${ParentStateIdentifier<Child>}` : never) : never;
|
|
1168
|
+
/**
|
|
1169
|
+
* Extracts the nearest parent state path from a state identifier.
|
|
1170
|
+
*
|
|
1171
|
+
* @category utility types
|
|
1172
|
+
* @since 4.0.0
|
|
1173
|
+
*/
|
|
1174
|
+
type ImmediateParentStateIdentifier<StateId extends string> = StateId extends `${infer Head}.${infer Tail}` ? Tail extends `${string}.${string}` ? `${Head}.${ImmediateParentStateIdentifier<Tail>}` : Head : never;
|
|
1031
1175
|
/**
|
|
1032
1176
|
* Maps every parent state path of a state identifier to its decoded value.
|
|
1033
1177
|
*
|
|
@@ -1037,6 +1181,13 @@ export declare namespace Machine {
|
|
|
1037
1181
|
type ParentStateValues<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
1038
1182
|
readonly [Parent in Extract<ParentStateIdentifier<StateId>, StateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
1039
1183
|
} : never;
|
|
1184
|
+
/**
|
|
1185
|
+
* Extracts the nearest parent value, or `undefined` for a root state.
|
|
1186
|
+
*
|
|
1187
|
+
* @category utility types
|
|
1188
|
+
* @since 4.0.0
|
|
1189
|
+
*/
|
|
1190
|
+
type ParentStateValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? Extract<ImmediateParentStateIdentifier<StateId>, StateIdentifier<States>> extends infer Parent ? [Parent] extends [never] ? undefined : Parent extends StateIdentifier<States> ? StateByIdentifier<States, Parent> : undefined : undefined : never;
|
|
1040
1191
|
/**
|
|
1041
1192
|
* Represents a decoded state value together with all of its parent values.
|
|
1042
1193
|
*
|
|
@@ -1061,9 +1212,10 @@ export declare namespace Machine {
|
|
|
1061
1212
|
type DirectFinalCompletionOutput<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends {
|
|
1062
1213
|
readonly type: "final";
|
|
1063
1214
|
} ? OutputByIdentifier<States, StateId> : never;
|
|
1064
|
-
type CompoundCompletionOutput<States extends StateSchemas, Children extends StateSchemas, Prefix extends StateIdentifier<States>> = UndefinedIfNever<
|
|
1215
|
+
type CompoundCompletionOutput<States extends StateSchemas, Children extends StateSchemas, Prefix extends StateIdentifier<States>> = UndefinedIfNever<CompoundCompletionOutputRaw<States, Children, Prefix>>;
|
|
1216
|
+
type CompoundCompletionOutputRaw<States extends StateSchemas, Children extends StateSchemas, Prefix extends StateIdentifier<States>> = {
|
|
1065
1217
|
readonly [Key in Extract<keyof Children, string>]: DirectFinalCompletionOutput<States, Extract<JoinPath<Prefix, Key>, StateIdentifier<States>>>;
|
|
1066
|
-
}[Extract<keyof Children, string>]
|
|
1218
|
+
}[Extract<keyof Children, string>];
|
|
1067
1219
|
/**
|
|
1068
1220
|
* Extracts the output passed when a state node completes.
|
|
1069
1221
|
*
|
|
@@ -1077,6 +1229,52 @@ export declare namespace Machine {
|
|
|
1077
1229
|
} ? CompoundCompletionOutput<States, Children, StateId> : Node extends {
|
|
1078
1230
|
readonly type: "final";
|
|
1079
1231
|
} ? OutputByIdentifier<States, StateId> : undefined : undefined;
|
|
1232
|
+
/**
|
|
1233
|
+
* Extracts the schema-derived union produced by structurally terminal root
|
|
1234
|
+
* states.
|
|
1235
|
+
*
|
|
1236
|
+
* **Details**
|
|
1237
|
+
*
|
|
1238
|
+
* Unlike a planned step's optional `output`, active atomic roots do not add
|
|
1239
|
+
* `undefined` to the union. Output-less final and parallel roots
|
|
1240
|
+
* intentionally contribute `undefined`, because that is their completed
|
|
1241
|
+
* value. Handler-driven reachability can make this structural union
|
|
1242
|
+
* conservative; for example, a root `onDone` handler can transition away
|
|
1243
|
+
* before that root becomes the machine's terminal result.
|
|
1244
|
+
*
|
|
1245
|
+
* @category utility types
|
|
1246
|
+
* @since 4.0.0
|
|
1247
|
+
*/
|
|
1248
|
+
type TerminalOutput<States extends StateSchemas> = {
|
|
1249
|
+
readonly [Key in Extract<keyof States, string>]: Extract<Key, StateIdentifier<States>> extends infer StateId extends StateIdentifier<States> ? NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
1250
|
+
readonly type: "parallel" | "final";
|
|
1251
|
+
} ? OutputByIdentifier<States, StateId> : Node extends {
|
|
1252
|
+
readonly states: infer Children extends StateSchemas;
|
|
1253
|
+
} ? CompoundCompletionOutputRaw<States, Children, StateId> : never : never : never;
|
|
1254
|
+
}[Extract<keyof States, string>];
|
|
1255
|
+
/**
|
|
1256
|
+
* Extracts every state path whose definition declares an output schema.
|
|
1257
|
+
*
|
|
1258
|
+
* @category utility types
|
|
1259
|
+
* @since 4.0.0
|
|
1260
|
+
*/
|
|
1261
|
+
type DeclaredOutputState<States extends StateSchemas> = {
|
|
1262
|
+
readonly [StateId in StateIdentifier<States>]: NodeByIdentifier<States, StateId> extends {
|
|
1263
|
+
readonly output: Schema.Top;
|
|
1264
|
+
} ? StateId : never;
|
|
1265
|
+
}[StateIdentifier<States>] & StateIdentifier<States>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Validates that every declared output schema has a matching handler
|
|
1268
|
+
* implementation before a machine is planned or started.
|
|
1269
|
+
*
|
|
1270
|
+
* @category utility types
|
|
1271
|
+
* @since 4.0.0
|
|
1272
|
+
*/
|
|
1273
|
+
type EnsureOutputImplementations<States extends StateSchemas, OutputStates extends StateIdentifier<States>> = [
|
|
1274
|
+
Exclude<DeclaredOutputState<States>, OutputStates>
|
|
1275
|
+
] extends [never] ? unknown : {
|
|
1276
|
+
readonly "~effect/Machine/MissingOutputImplementation": Exclude<DeclaredOutputState<States>, OutputStates>;
|
|
1277
|
+
};
|
|
1080
1278
|
type OutputSchema<Node> = Node extends {
|
|
1081
1279
|
readonly output: infer Output extends Schema.Top;
|
|
1082
1280
|
} ? Output : never;
|
|
@@ -1347,6 +1545,13 @@ export declare namespace Machine {
|
|
|
1347
1545
|
* targets descendants of the source root, and `full` builds complete
|
|
1348
1546
|
* snapshots for any root.
|
|
1349
1547
|
*
|
|
1548
|
+
* These builders control how the next active configuration is assembled; they
|
|
1549
|
+
* do not directly control state re-entry. Exit and entry paths are derived
|
|
1550
|
+
* from the previous and next active paths. Shared active ancestors remain
|
|
1551
|
+
* entered even when a `full` target supplies their values again. Use an event
|
|
1552
|
+
* transition with `reenter: true` when the source should explicitly exit and
|
|
1553
|
+
* enter again.
|
|
1554
|
+
*
|
|
1350
1555
|
* @category models
|
|
1351
1556
|
* @since 4.0.0
|
|
1352
1557
|
*/
|
|
@@ -1383,11 +1588,16 @@ export declare namespace Machine {
|
|
|
1383
1588
|
/**
|
|
1384
1589
|
* Stages an Effect to run after the current machine step is planned.
|
|
1385
1590
|
*
|
|
1591
|
+
* The two-argument overload returns `next` after staging the Effect, which is
|
|
1592
|
+
* useful when a handler should stage one action and return a target without
|
|
1593
|
+
* introducing an Effect generator.
|
|
1594
|
+
*
|
|
1386
1595
|
* @category models
|
|
1387
1596
|
* @since 4.0.0
|
|
1388
1597
|
*/
|
|
1389
1598
|
interface Action {
|
|
1390
1599
|
<E, R>(effect: Effect.Effect<void, E, R>): Effect.Effect<void, never, ActionRequirement<E, R>>;
|
|
1600
|
+
<E, R, Next>(effect: Effect.Effect<void, E, R>, next: Next): Effect.Effect<Next, never, ActionRequirement<E, R>>;
|
|
1391
1601
|
}
|
|
1392
1602
|
/**
|
|
1393
1603
|
* Planning capabilities shared by transition and lifecycle callbacks.
|
|
@@ -1396,7 +1606,6 @@ export declare namespace Machine {
|
|
|
1396
1606
|
* @since 4.0.0
|
|
1397
1607
|
*/
|
|
1398
1608
|
interface PlanningCapabilities<Events, Emits> {
|
|
1399
|
-
readonly action: Action;
|
|
1400
1609
|
readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError, Runtime.Requirement<Events, Emits>>;
|
|
1401
1610
|
readonly emit: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError, Runtime.Requirement<Events, Emits>>;
|
|
1402
1611
|
}
|
|
@@ -1408,6 +1617,7 @@ export declare namespace Machine {
|
|
|
1408
1617
|
*/
|
|
1409
1618
|
interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
|
|
1410
1619
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1620
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
1411
1621
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1412
1622
|
readonly event: EventByTag<Events, EventTag>;
|
|
1413
1623
|
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
@@ -1427,6 +1637,7 @@ export declare namespace Machine {
|
|
|
1427
1637
|
*/
|
|
1428
1638
|
interface StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
|
|
1429
1639
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1640
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
1430
1641
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1431
1642
|
readonly event: LifecycleEvent<Events>;
|
|
1432
1643
|
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
@@ -1439,6 +1650,7 @@ export declare namespace Machine {
|
|
|
1439
1650
|
*/
|
|
1440
1651
|
interface InvokeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
1441
1652
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1653
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
1442
1654
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1443
1655
|
readonly event: LifecycleEvent<Events>;
|
|
1444
1656
|
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
@@ -1473,6 +1685,7 @@ export declare namespace Machine {
|
|
|
1473
1685
|
*/
|
|
1474
1686
|
interface AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
|
|
1475
1687
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1688
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
1476
1689
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1477
1690
|
readonly event: LifecycleEvent<Events>;
|
|
1478
1691
|
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
@@ -1493,6 +1706,7 @@ export declare namespace Machine {
|
|
|
1493
1706
|
*/
|
|
1494
1707
|
interface DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> extends PlanningCapabilities<EventOf<Events>, EmitOf<Emits>> {
|
|
1495
1708
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1709
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
1496
1710
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1497
1711
|
readonly event: LifecycleEvent<Events>;
|
|
1498
1712
|
readonly output: CompletionOutputByIdentifier<States, StateId>;
|
|
@@ -1514,6 +1728,7 @@ export declare namespace Machine {
|
|
|
1514
1728
|
*/
|
|
1515
1729
|
interface FinalOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
1516
1730
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1731
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
1517
1732
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1518
1733
|
readonly event: LifecycleEvent<Events>;
|
|
1519
1734
|
}
|
|
@@ -1537,6 +1752,7 @@ export declare namespace Machine {
|
|
|
1537
1752
|
*/
|
|
1538
1753
|
interface ParallelOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
1539
1754
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1755
|
+
readonly parent: ParentStateValue<States, StateId>;
|
|
1540
1756
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1541
1757
|
readonly event: LifecycleEvent<Events>;
|
|
1542
1758
|
readonly outputs: ParallelOutputRegions<States, StateId>;
|
|
@@ -1755,15 +1971,6 @@ export declare namespace Machine {
|
|
|
1755
1971
|
* @since 4.0.0
|
|
1756
1972
|
*/
|
|
1757
1973
|
type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | InvokeRequirements<Config>;
|
|
1758
|
-
/**
|
|
1759
|
-
* Resolves the tag of a state config when it is final.
|
|
1760
|
-
*
|
|
1761
|
-
* @category utility types
|
|
1762
|
-
* @since 4.0.0
|
|
1763
|
-
*/
|
|
1764
|
-
type FinalStateFromConfig<Config, StateTag extends PropertyKey> = Config extends {
|
|
1765
|
-
readonly type: "final";
|
|
1766
|
-
} ? StateTag : never;
|
|
1767
1974
|
/**
|
|
1768
1975
|
* Configuration for invoking a child process while a state is active.
|
|
1769
1976
|
*
|
|
@@ -1780,10 +1987,17 @@ export declare namespace Machine {
|
|
|
1780
1987
|
readonly initialError: Types.Covariant<ChildInitialError>;
|
|
1781
1988
|
};
|
|
1782
1989
|
readonly id: string;
|
|
1990
|
+
/**
|
|
1991
|
+
* Optional parent-local address for sending events to this invocation.
|
|
1992
|
+
*
|
|
1993
|
+
* The invocation `id` is only its state-local lifecycle key. Use an
|
|
1994
|
+
* explicit typed address when the parent must communicate with it.
|
|
1995
|
+
*/
|
|
1996
|
+
readonly address?: string;
|
|
1783
1997
|
/** @internal */
|
|
1784
|
-
readonly
|
|
1998
|
+
readonly descriptor?: ChildMachine.Any;
|
|
1785
1999
|
src(): Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>;
|
|
1786
|
-
snapshot?(context: InvokeSnapshotContext<ChildState, ChildError
|
|
2000
|
+
snapshot?(context: InvokeSnapshotContext<ChildState, ChildError, ChildOutput>): Event | undefined;
|
|
1787
2001
|
onDone?(context: InvokeDoneContext<ChildOutput>): DeliveredOutput | undefined;
|
|
1788
2002
|
}
|
|
1789
2003
|
/** @internal */
|
|
@@ -1828,7 +2042,6 @@ export declare namespace Machine {
|
|
|
1828
2042
|
* @since 4.0.0
|
|
1829
2043
|
*/
|
|
1830
2044
|
type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = {
|
|
1831
|
-
readonly type?: "active";
|
|
1832
2045
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<any, any>;
|
|
1833
2046
|
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<any, any>;
|
|
1834
2047
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
|
|
@@ -1848,7 +2061,6 @@ export declare namespace Machine {
|
|
|
1848
2061
|
* @since 4.0.0
|
|
1849
2062
|
*/
|
|
1850
2063
|
type FinalStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = {
|
|
1851
|
-
readonly type: "final";
|
|
1852
2064
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<any, any>;
|
|
1853
2065
|
readonly exit?: never;
|
|
1854
2066
|
readonly always?: never;
|
|
@@ -1861,7 +2073,9 @@ export declare namespace Machine {
|
|
|
1861
2073
|
* @category models
|
|
1862
2074
|
* @since 4.0.0
|
|
1863
2075
|
*/
|
|
1864
|
-
type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> =
|
|
2076
|
+
type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = NodeByIdentifier<States, StateId> extends {
|
|
2077
|
+
readonly type: "final";
|
|
2078
|
+
} ? FinalStateConfig<States, Events, Emits, StateId> : ActiveStateConfig<States, Events, Emits, StateId, E, R>;
|
|
1865
2079
|
type HandlerChildren<Node> = Node extends {
|
|
1866
2080
|
readonly states: infer Children extends StateSchemas;
|
|
1867
2081
|
} ? Children : never;
|
|
@@ -1879,7 +2093,7 @@ export declare namespace Machine {
|
|
|
1879
2093
|
type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, Prefix extends string> = {
|
|
1880
2094
|
readonly [Key in Extract<keyof States, string>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, HandlerStateId<AllStates, JoinPath<Prefix, Key>>>;
|
|
1881
2095
|
};
|
|
1882
|
-
type HandlerNodeConfigKey = "always" | "entry" | "exit" | "invoke" | "on" | "onDone" | "output" | "states"
|
|
2096
|
+
type HandlerNodeConfigKey = "always" | "entry" | "exit" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
1883
2097
|
type HandlerValidationError<Message extends string> = {
|
|
1884
2098
|
readonly "~effect/Machine/HandlerError": Message;
|
|
1885
2099
|
};
|
|
@@ -1954,19 +2168,11 @@ export declare namespace Machine {
|
|
|
1954
2168
|
readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: ConfigServices<HandlerConfigPart<Config[Key]>> | HandlerNodeChildServices<AllStates, Events, Emits, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
|
|
1955
2169
|
}[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
|
|
1956
2170
|
type HandlerNodeChildServices<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Node, Prefix extends string, Config, Depth extends ReadonlyArray<unknown>> = Depth extends readonly [] ? never : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? never : HandlerTreeServices<AllStates, Events, Emits, Children, Prefix, HandlerNodeChildrenConfig<Config>, HandlerNextDepth<Depth>> : never;
|
|
1957
|
-
type HandlerTreeFinalStates<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Config, Depth extends ReadonlyArray<unknown> = HandlerDepth> = {
|
|
1958
|
-
readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: Extract<FinalStateFromConfig<HandlerConfigPart<Config[Key]>, HandlerStateId<AllStates, JoinPath<Prefix, Key>>>, StateIdentifier<AllStates>> | HandlerNodeChildFinalStates<AllStates, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
|
|
1959
|
-
}[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
|
|
1960
|
-
type HandlerNodeChildFinalStates<AllStates extends StateSchemas, Node, Prefix extends string, Config, Depth extends ReadonlyArray<unknown>> = Depth extends readonly [] ? never : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? never : HandlerTreeFinalStates<AllStates, Children, Prefix, HandlerNodeChildrenConfig<Config>, HandlerNextDepth<Depth>> : never;
|
|
1961
|
-
type HandlerTreeOutput<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Config, Depth extends ReadonlyArray<unknown> = HandlerDepth> = {
|
|
1962
|
-
readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: ("output" extends keyof HandlerConfigPart<Config[Key]> ? OutputByIdentifier<AllStates, HandlerStateId<AllStates, JoinPath<Prefix, Key>>> : never) | HandlerNodeChildOutput<AllStates, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
|
|
1963
|
-
}[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
|
|
1964
|
-
type HandlerNodeChildOutput<AllStates extends StateSchemas, Node, Prefix extends string, Config, Depth extends ReadonlyArray<unknown>> = Depth extends readonly [] ? never : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? never : HandlerTreeOutput<AllStates, Children, Prefix, HandlerNodeChildrenConfig<Config>, HandlerNextDepth<Depth>> : never;
|
|
1965
2171
|
type HandlerTreeOutputStates<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Config, Depth extends ReadonlyArray<unknown> = HandlerDepth> = {
|
|
1966
2172
|
readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: HandlerOutputStates<AllStates, HandlerStateId<AllStates, JoinPath<Prefix, Key>>, HandlerConfigPart<Config[Key]>> | HandlerNodeChildOutputStates<AllStates, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
|
|
1967
2173
|
}[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
|
|
1968
2174
|
type HandlerNodeChildOutputStates<AllStates extends StateSchemas, Node, Prefix extends string, Config, Depth extends ReadonlyArray<unknown>> = Depth extends readonly [] ? never : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? never : HandlerTreeOutputStates<AllStates, Children, Prefix, HandlerNodeChildrenConfig<Config>, HandlerNextDepth<Depth>> : never;
|
|
1969
|
-
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>, Config> = Machine<AllStates, Events, Input, Exclude<UnhandledStates, HandlerTreeStateIds<AllStates, AllStates, "", Config>>, E | HandlerTreeError<AllStates, Events, Emits, AllStates, "", Config>, ExcludeCompatibleRuntime<R | HandlerTreeServices<AllStates, Events, Emits, AllStates, "", Config>, EventOf<Events>, EmitOf<Emits>>, InitialE, InitialR, FinalStates
|
|
2175
|
+
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>, Config> = Machine<AllStates, Events, Input, Exclude<UnhandledStates, HandlerTreeStateIds<AllStates, AllStates, "", Config>>, E | HandlerTreeError<AllStates, Events, Emits, AllStates, "", Config>, ExcludeCompatibleRuntime<R | HandlerTreeServices<AllStates, Events, Emits, AllStates, "", Config>, EventOf<Events>, EmitOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeOutputStates<AllStates, AllStates, "", Config>, StateIdentifier<AllStates>>, InputEvents>;
|
|
1970
2176
|
/**
|
|
1971
2177
|
* Adds state handlers from a root state object.
|
|
1972
2178
|
*
|
|
@@ -1979,8 +2185,8 @@ export declare namespace Machine {
|
|
|
1979
2185
|
* @category combinators
|
|
1980
2186
|
* @since 4.0.0
|
|
1981
2187
|
*/
|
|
1982
|
-
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>> {
|
|
1983
|
-
<const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerTreeValidation<States, States, Events, "", Config, OutputStates | Extract<HandlerTreeOutputStates<States, States, "", Config>, StateIdentifier<States>>> & EnsureCompatibleRuntime<HandlerTreeServices<States, Events, Emits, States, "", Config>, EventOf<Events>, EmitOf<Emits>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, Config>;
|
|
2188
|
+
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>> {
|
|
2189
|
+
<const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerTreeValidation<States, States, Events, "", Config, OutputStates | Extract<HandlerTreeOutputStates<States, States, "", Config>, StateIdentifier<States>>> & EnsureCompatibleRuntime<HandlerTreeServices<States, Events, Emits, States, "", Config>, EventOf<Events>, EmitOf<Emits>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, Config>;
|
|
1984
2190
|
}
|
|
1985
2191
|
/**
|
|
1986
2192
|
* Any state config.
|
|
@@ -2006,13 +2212,12 @@ export declare namespace Machine {
|
|
|
2006
2212
|
* @since 4.0.0
|
|
2007
2213
|
*/
|
|
2008
2214
|
interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
2009
|
-
readonly type?: "final" | "active";
|
|
2010
2215
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<E, R>;
|
|
2011
2216
|
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>) => StateActionResult<E, R>;
|
|
2012
2217
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
|
|
2013
2218
|
readonly always?: (context: AlwaysContext<States, Events, Emits, StateId>) => HandlerResult<States, E, R>;
|
|
2014
2219
|
readonly onDone?: (context: DoneContext<States, Events, Emits, StateId>) => HandlerResult<States, E, R>;
|
|
2015
|
-
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) =>
|
|
2220
|
+
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
|
|
2016
2221
|
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
|
|
2017
2222
|
}
|
|
2018
2223
|
/**
|
|
@@ -2036,7 +2241,7 @@ export declare const isMachine: (u: unknown) => u is Machine.Any;
|
|
|
2036
2241
|
* @category guards
|
|
2037
2242
|
* @since 4.0.0
|
|
2038
2243
|
*/
|
|
2039
|
-
export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates>, state: Machine.Snapshot<States>) => state is Machine.SnapshotContainingFinal<States, FinalStates>;
|
|
2244
|
+
export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, state: Machine.Snapshot<States>) => state is Machine.SnapshotContainingFinal<States, FinalStates>;
|
|
2040
2245
|
/**
|
|
2041
2246
|
* Defines a state tree while preserving literal state paths.
|
|
2042
2247
|
*
|
|
@@ -2055,7 +2260,7 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
2055
2260
|
*
|
|
2056
2261
|
* ```ts
|
|
2057
2262
|
* import { Schema } from "effect"
|
|
2058
|
-
* import { Machine } from "effect
|
|
2263
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
2059
2264
|
*
|
|
2060
2265
|
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
2061
2266
|
*
|
|
@@ -2083,11 +2288,16 @@ export declare const defineStates: <const States extends Machine.StateSchemas>(s
|
|
|
2083
2288
|
* `defineStates` or is passed inline. Call `handle` on the returned definition
|
|
2084
2289
|
* to implement state behavior with ordinary TypeScript control flow.
|
|
2085
2290
|
*
|
|
2291
|
+
* Schemas in `events` define the public input protocol. Schemas in
|
|
2292
|
+
* `internalEvents` are added to the complete handler protocol for invoke
|
|
2293
|
+
* results, child emissions, and other machine-local deliveries. Their tags
|
|
2294
|
+
* must be disjoint.
|
|
2295
|
+
*
|
|
2086
2296
|
* **Example** (Typed counter machine)
|
|
2087
2297
|
*
|
|
2088
2298
|
* ```ts
|
|
2089
2299
|
* import { Schema } from "effect"
|
|
2090
|
-
* import { Machine } from "effect
|
|
2300
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
2091
2301
|
*
|
|
2092
2302
|
* class Count extends Schema.TaggedClass<Count>("Count")("Count", {
|
|
2093
2303
|
* value: Schema.Number
|
|
@@ -2117,14 +2327,17 @@ export declare const defineStates: <const States extends Machine.StateSchemas>(s
|
|
|
2117
2327
|
* @category constructors
|
|
2118
2328
|
* @since 4.0.0
|
|
2119
2329
|
*/
|
|
2120
|
-
export declare const make: <const States extends Machine.StateSchemas, const
|
|
2330
|
+
export declare const make: <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 []>(config: {
|
|
2121
2331
|
readonly id?: string;
|
|
2122
2332
|
readonly states: States & DefineStateTreeInput<NoInfer<States>>;
|
|
2123
|
-
|
|
2333
|
+
/** Events accepted through public machine input boundaries. */
|
|
2334
|
+
readonly events: InputEvents;
|
|
2335
|
+
/** Events delivered only by machine-local logic. */
|
|
2336
|
+
readonly internalEvents?: InternalEvents;
|
|
2124
2337
|
readonly emits?: Emits;
|
|
2125
2338
|
readonly input?: Input;
|
|
2126
2339
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
|
|
2127
|
-
}, ..._validation: ValidateDefinedStates<NoInfer<States>>) => Machine<States,
|
|
2340
|
+
}, ..._validation: [...ValidateDefinedStates<NoInfer<States>>, ...ValidateEventProtocol<NoInfer<InputEvents>, NoInfer<InternalEvents>>]) => Machine<States, readonly [...InputEvents, ...InternalEvents], Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, Machine.FinalStateFromDefinition<States>, Machine.TerminalOutput<States>, Emits, never, InputEvents>;
|
|
2128
2341
|
/**
|
|
2129
2342
|
* Encodes a decoded machine snapshot into a normalized data representation.
|
|
2130
2343
|
*
|
|
@@ -2152,7 +2365,7 @@ export declare const make: <const States extends Machine.StateSchemas, const Eve
|
|
|
2152
2365
|
* @category encoding
|
|
2153
2366
|
* @since 4.0.0
|
|
2154
2367
|
*/
|
|
2155
|
-
export declare const encodeSnapshot: <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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits>, snapshot: Machine.Snapshot<States>) => Effect.Effect<Machine.EncodedSnapshot, MachineSchemaEncodeError, Machine.SnapshotEncodingServices<States>>;
|
|
2368
|
+
export declare const encodeSnapshot: <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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, snapshot: Machine.Snapshot<States>) => Effect.Effect<Machine.EncodedSnapshot, MachineSchemaEncodeError, Machine.SnapshotEncodingServices<States>>;
|
|
2156
2369
|
/**
|
|
2157
2370
|
* Decodes a normalized data representation into a validated machine snapshot.
|
|
2158
2371
|
*
|
|
@@ -2176,7 +2389,7 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
2176
2389
|
* @category decoding
|
|
2177
2390
|
* @since 4.0.0
|
|
2178
2391
|
*/
|
|
2179
|
-
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
2392
|
+
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
2180
2393
|
/**
|
|
2181
2394
|
* Creates an invoked child process configuration for an active state.
|
|
2182
2395
|
*
|
|
@@ -2192,6 +2405,8 @@ export declare const decodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
2192
2405
|
* Invoked child processes run while their owning state is active and are
|
|
2193
2406
|
* stopped before the state exits. An unrecovered child failure fails the owning
|
|
2194
2407
|
* machine; recover inside the child Effect when failure should become an event.
|
|
2408
|
+
* The `id` is a state-local lifecycle key, not a communication address. To
|
|
2409
|
+
* send events to the invocation, pass a typed `childAddress` as `address`.
|
|
2195
2410
|
* The `src` callback is intentionally independent from its parent state. When
|
|
2196
2411
|
* construction depends on the typed state, lifecycle event, or runtime, use
|
|
2197
2412
|
* the state config factory form `invoke: (context) => Machine.invoke(...)` and
|
|
@@ -2201,7 +2416,7 @@ export declare const decodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
2201
2416
|
*
|
|
2202
2417
|
* ```ts
|
|
2203
2418
|
* import { Effect, Schema } from "effect"
|
|
2204
|
-
* import { Machine } from "effect
|
|
2419
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
2205
2420
|
*
|
|
2206
2421
|
* class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
|
|
2207
2422
|
* value: Schema.String
|
|
@@ -2218,11 +2433,94 @@ export declare const decodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
2218
2433
|
* @category constructors
|
|
2219
2434
|
* @since 4.0.0
|
|
2220
2435
|
*/
|
|
2221
|
-
export declare const invoke: <ChildState, ChildEvent, ChildError = never, ChildRequirements = never, ChildOutput = never, ChildInitialError = never, Event = never,
|
|
2222
|
-
readonly id:
|
|
2436
|
+
export declare const invoke: <ChildState, ChildEvent, ChildError = never, ChildRequirements = never, ChildOutput = never, ChildInitialError = never, Event = never, Address extends ChildAddress<never> | undefined = undefined>(config: {
|
|
2437
|
+
readonly id: InvokeLifecycleId;
|
|
2223
2438
|
readonly src: () => Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>;
|
|
2224
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<ChildState, ChildError
|
|
2225
|
-
} &
|
|
2439
|
+
readonly snapshot?: (context: Machine.InvokeSnapshotContext<ChildState, ChildError, ChildOutput>) => Event | undefined;
|
|
2440
|
+
} & ([Address] extends [undefined] ? {
|
|
2441
|
+
readonly address?: never;
|
|
2442
|
+
} : {
|
|
2443
|
+
readonly address: Exclude<Address, undefined>;
|
|
2444
|
+
} & ChildAddress.Compatibility<Exclude<Address, undefined>, NoInfer<ChildEvent>>)) => Machine.InvokeConfig<any, any, any, any, Event, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>;
|
|
2445
|
+
type InvokeEffectResult<Requirements, Event> = Machine.InvokeConfig<any, any, any, any, never, void, never, never, Requirements, Event | void, never>;
|
|
2446
|
+
type InvokeEffectIsInfallible<Fx extends Effect.Effect<any, any, any>> = IsAny<Effect.Error<Fx>> extends true ? false : [Effect.Error<Fx>] extends [never] ? true : false;
|
|
2447
|
+
type InvokeEffectConfig<Fx extends Effect.Effect<any, any, any>, SuccessEvent, FailureEvent> = {
|
|
2448
|
+
readonly id: InvokeLifecycleId;
|
|
2449
|
+
readonly effect: Fx;
|
|
2450
|
+
readonly onSuccess: (value: NoInfer<Effect.Success<Fx>>) => SuccessEvent | void;
|
|
2451
|
+
} & (InvokeEffectIsInfallible<Fx> extends true ? {
|
|
2452
|
+
readonly onFailure?: never;
|
|
2453
|
+
} : {
|
|
2454
|
+
readonly onFailure: (error: NoInfer<Effect.Error<Fx>>) => FailureEvent | void;
|
|
2455
|
+
});
|
|
2456
|
+
/**
|
|
2457
|
+
* Invokes one Effect and maps its typed outcome into machine-local events.
|
|
2458
|
+
*
|
|
2459
|
+
* **Details**
|
|
2460
|
+
*
|
|
2461
|
+
* This is the high-level one-shot counterpart to `invoke`. Success and typed
|
|
2462
|
+
* failure values are mapped independently, so callers do not need to recover
|
|
2463
|
+
* an Effect into a common event union by hand. Defects and interruption remain
|
|
2464
|
+
* failures of the owning machine.
|
|
2465
|
+
*
|
|
2466
|
+
* Declare mapped outcomes in `internalEvents` unless they are also legitimate
|
|
2467
|
+
* public commands.
|
|
2468
|
+
*
|
|
2469
|
+
* @see {@link invoke} for arbitrary child process logic.
|
|
2470
|
+
* @see {@link after} for a state-scoped delayed event.
|
|
2471
|
+
* @category constructors
|
|
2472
|
+
* @since 4.0.0
|
|
2473
|
+
*/
|
|
2474
|
+
export declare const invokeEffect: <const Fx extends Effect.Effect<any, any, any>, SuccessEvent, FailureEvent = never>(config: InvokeEffectConfig<Fx, SuccessEvent, FailureEvent>) => InvokeEffectResult<Effect.Services<Fx>, SuccessEvent | (InvokeEffectIsInfallible<Fx> extends true ? never : FailureEvent)>;
|
|
2475
|
+
/**
|
|
2476
|
+
* Creates a cancellable state-scoped delayed event.
|
|
2477
|
+
*
|
|
2478
|
+
* The timer starts when its owning state is entered and is interrupted when
|
|
2479
|
+
* that state exits. The delayed value should normally be declared in
|
|
2480
|
+
* `internalEvents`.
|
|
2481
|
+
*
|
|
2482
|
+
* @category constructors
|
|
2483
|
+
* @since 4.0.0
|
|
2484
|
+
*/
|
|
2485
|
+
export declare const after: <Event extends {
|
|
2486
|
+
readonly _tag: PropertyKey;
|
|
2487
|
+
}>(duration: Duration.Input, event: Event, options?: {
|
|
2488
|
+
readonly id?: InvokeLifecycleId;
|
|
2489
|
+
}) => InvokeEffectResult<never, Event>;
|
|
2490
|
+
type RetagFields<Target extends Machine.TaggedSchema> = Omit<Target["~type.make.in"], "_tag">;
|
|
2491
|
+
type RetagTargetCompatibility<Target extends Machine.TaggedSchema> = Target extends {
|
|
2492
|
+
readonly fields: Schema.Struct.Fields;
|
|
2493
|
+
} ? "_tag" extends keyof Target["~type.make.in"] ? {} extends Pick<Target["~type.make.in"], "_tag"> ? unknown : {
|
|
2494
|
+
readonly "~effect/Machine/RetagTargetError": "Target schema must supply its discriminator when make is called";
|
|
2495
|
+
} : unknown : {
|
|
2496
|
+
readonly "~effect/Machine/RetagTargetError": "Target schema must be one tagged struct or tagged class";
|
|
2497
|
+
};
|
|
2498
|
+
type RequiredKeys<A> = {
|
|
2499
|
+
readonly [Key in keyof A]-?: {} extends Pick<A, Key> ? never : Key;
|
|
2500
|
+
}[keyof A];
|
|
2501
|
+
type CompatibleSourceKeys<Fields, Source> = {
|
|
2502
|
+
readonly [Key in Extract<keyof Fields, keyof Source>]: Source[Key] extends Fields[Key] ? Key : never;
|
|
2503
|
+
}[Extract<keyof Fields, keyof Source>];
|
|
2504
|
+
type RetagPatch<Target extends Machine.TaggedSchema, Source> = Partial<RetagFields<Target>> & Pick<RetagFields<Target>, Exclude<RequiredKeys<RetagFields<Target>>, CompatibleSourceKeys<RetagFields<Target>, Source>>>;
|
|
2505
|
+
type RetagArgs<Target extends Machine.TaggedSchema, Source> = [
|
|
2506
|
+
Exclude<RequiredKeys<RetagFields<Target>>, CompatibleSourceKeys<RetagFields<Target>, Source>>
|
|
2507
|
+
] extends [never] ? [patch?: RetagPatch<Target, Source>] : [patch: RetagPatch<Target, Source>];
|
|
2508
|
+
/**
|
|
2509
|
+
* Constructs another tagged case from compatible source fields.
|
|
2510
|
+
*
|
|
2511
|
+
* The target must be one tagged struct or tagged class whose discriminator is
|
|
2512
|
+
* supplied by its constructor. Union wrappers are rejected because their
|
|
2513
|
+
* `make` operation cannot select a member after the source discriminator has
|
|
2514
|
+
* been discarded. Missing or incompatible required target fields must be
|
|
2515
|
+
* supplied by the patch, and the target schema's normal `make` validation
|
|
2516
|
+
* remains authoritative at runtime.
|
|
2517
|
+
*
|
|
2518
|
+
* @category constructors
|
|
2519
|
+
* @since 4.0.0
|
|
2520
|
+
*/
|
|
2521
|
+
export declare const retag: <const Target extends Machine.TaggedSchema, const Source extends {
|
|
2522
|
+
readonly _tag: PropertyKey;
|
|
2523
|
+
}>(target: Target & RetagTargetCompatibility<Target>, source: Source, ...args: RetagArgs<Target, Source>) => Target["Type"];
|
|
2226
2524
|
type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.Void ? {
|
|
2227
2525
|
readonly input?: never;
|
|
2228
2526
|
} : {
|
|
@@ -2254,16 +2552,16 @@ type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.
|
|
|
2254
2552
|
* @since 4.0.0
|
|
2255
2553
|
*/
|
|
2256
2554
|
export declare const invokeMachine: {
|
|
2257
|
-
<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, SnapshotEvent = never, DoneEvent = never, Id extends string = string>(config: {
|
|
2258
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits>>;
|
|
2259
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E |
|
|
2260
|
-
readonly onDone: (context: Machine.InvokeDoneContext<Output
|
|
2261
|
-
} & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<
|
|
2262
|
-
<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, SnapshotEvent = never, Id extends string = string>(config: {
|
|
2263
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits>>;
|
|
2264
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E |
|
|
2555
|
+
<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, SnapshotEvent = never, DoneEvent = never, Id extends string = string, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(config: {
|
|
2556
|
+
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates>>;
|
|
2557
|
+
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
2558
|
+
readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined;
|
|
2559
|
+
} & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>, Output, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Machine.EmitOf<Emits>, DoneEvent>;
|
|
2560
|
+
<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, SnapshotEvent = never, Id extends string = string, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(config: {
|
|
2561
|
+
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates>>;
|
|
2562
|
+
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
2265
2563
|
readonly onDone?: never;
|
|
2266
|
-
} & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<
|
|
2564
|
+
} & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>, Output, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Machine.EmitOf<Emits>>;
|
|
2267
2565
|
};
|
|
2268
2566
|
/**
|
|
2269
2567
|
* Plans the initial state for a machine without running deferred actions.
|
|
@@ -2286,19 +2584,24 @@ export declare const invokeMachine: {
|
|
|
2286
2584
|
* @category constructors
|
|
2287
2585
|
* @since 4.0.0
|
|
2288
2586
|
*/
|
|
2289
|
-
export declare const planInitial: <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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<{
|
|
2587
|
+
export declare const planInitial: <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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<{
|
|
2290
2588
|
readonly state: Machine.Snapshot<States>;
|
|
2291
2589
|
readonly actions: ReadonlyArray<Effect.Effect<void, ActionError<InitialR | R>, ActionServices<InitialR | R>>>;
|
|
2292
2590
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
2293
|
-
|
|
2294
|
-
|
|
2591
|
+
} & ({
|
|
2592
|
+
readonly done: true;
|
|
2593
|
+
readonly output: Output;
|
|
2594
|
+
} | {
|
|
2595
|
+
readonly done: false;
|
|
2596
|
+
readonly output: undefined;
|
|
2597
|
+
}), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, ExcludeCompatibleRuntime<PlanningServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
|
|
2295
2598
|
/**
|
|
2296
2599
|
* Returns the event tags handled by the current state snapshot.
|
|
2297
2600
|
*
|
|
2298
2601
|
* @category getters
|
|
2299
2602
|
* @since 4.0.0
|
|
2300
2603
|
*/
|
|
2301
|
-
export declare const enabled: <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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates>, state: Machine.Snapshot<States>) => ReadonlyArray<Machine.TagOf<Events[number]>>;
|
|
2604
|
+
export declare const enabled: <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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, state: Machine.Snapshot<States>) => ReadonlyArray<Machine.TagOf<Events[number]>>;
|
|
2302
2605
|
/**
|
|
2303
2606
|
* Plans the next state snapshot without running deferred actions.
|
|
2304
2607
|
*
|
|
@@ -2322,7 +2625,7 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
2322
2625
|
* @category combinators
|
|
2323
2626
|
* @since 4.0.0
|
|
2324
2627
|
*/
|
|
2325
|
-
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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits>, state: Machine.Snapshot<States>, event: Machine.EventOf<
|
|
2628
|
+
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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates>, state: Machine.Snapshot<States>, event: Machine.EventOf<InputEvents>) => Effect.Effect<{
|
|
2326
2629
|
readonly next: Machine.Snapshot<States>;
|
|
2327
2630
|
readonly actions: ReadonlyArray<Effect.Effect<void, ActionError<R>, ActionServices<R>>>;
|
|
2328
2631
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
@@ -2336,8 +2639,13 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
2336
2639
|
readonly entryPaths: ReadonlyArray<string>;
|
|
2337
2640
|
readonly changed: boolean;
|
|
2338
2641
|
}>;
|
|
2339
|
-
|
|
2340
|
-
|
|
2642
|
+
} & ({
|
|
2643
|
+
readonly done: true;
|
|
2644
|
+
readonly output: Output;
|
|
2645
|
+
} | {
|
|
2646
|
+
readonly done: false;
|
|
2647
|
+
readonly output: undefined;
|
|
2648
|
+
}), E | InfiniteTransitionError | MachineSchemaDecodeError, ExcludeCompatibleRuntime<PlanningServices<R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
|
|
2341
2649
|
/**
|
|
2342
2650
|
* Defers an effectful action until the current machine step is planned.
|
|
2343
2651
|
*
|
|
@@ -2346,13 +2654,14 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
2346
2654
|
* The action's error and service requirements are retained in the machine
|
|
2347
2655
|
* type without becoming requirements of `plan` or `planInitial`. The managed
|
|
2348
2656
|
* runtime executes staged actions sequentially before publishing the planned
|
|
2349
|
-
* state.
|
|
2657
|
+
* state. Pass a second argument when the planning Effect should return that
|
|
2658
|
+
* value after staging.
|
|
2350
2659
|
*
|
|
2351
2660
|
* **Example** (Typed staged action)
|
|
2352
2661
|
*
|
|
2353
2662
|
* ```ts
|
|
2354
2663
|
* import { Context, Effect } from "effect"
|
|
2355
|
-
* import { Machine } from "effect
|
|
2664
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
2356
2665
|
*
|
|
2357
2666
|
* class Audit extends Context.Service<Audit, {
|
|
2358
2667
|
* readonly write: Effect.Effect<void, "AuditError">
|
|
@@ -2367,7 +2676,7 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
2367
2676
|
* @category combinators
|
|
2368
2677
|
* @since 4.0.0
|
|
2369
2678
|
*/
|
|
2370
|
-
export declare const action:
|
|
2679
|
+
export declare const action: Machine.Action;
|
|
2371
2680
|
/**
|
|
2372
2681
|
* Runs staged machine actions sequentially with the supplied runtime.
|
|
2373
2682
|
*
|
|
@@ -2421,7 +2730,7 @@ export declare const runtime: <const Protocol extends Runtime.Protocol = {}>() =
|
|
|
2421
2730
|
*
|
|
2422
2731
|
* ```ts
|
|
2423
2732
|
* import { Effect, Schema } from "effect"
|
|
2424
|
-
* import { Machine } from "effect
|
|
2733
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
2425
2734
|
*
|
|
2426
2735
|
* class LoadFailed extends Schema.TaggedClass<LoadFailed>("LoadFailed")("LoadFailed", {
|
|
2427
2736
|
* reason: Schema.String
|
|
@@ -2468,7 +2777,7 @@ export declare const effect: <Output, Error = never, Requirements = never>(effec
|
|
|
2468
2777
|
* @category constructors
|
|
2469
2778
|
* @since 4.0.0
|
|
2470
2779
|
*/
|
|
2471
|
-
export declare const logic: <State, Event =
|
|
2780
|
+
export declare const logic: <State, Event = never, Output = void, Error = never, Requirements = never, InitialError = never, InitialRequirements = never>(options: {
|
|
2472
2781
|
readonly initial: State | ((scope: Logic.Scope<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
|
|
2473
2782
|
readonly run: (context: Logic.Context<State, Event>) => Effect.Effect<Output, Error, Requirements>;
|
|
2474
2783
|
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError>;
|
|
@@ -2492,21 +2801,25 @@ export declare const logic: <State, Event = any, Output = void, Error = never, R
|
|
|
2492
2801
|
*/
|
|
2493
2802
|
export declare const transition: <State, Event, Error = never, Requirements = never>(initial: State, transition: (state: State, event: Event) => Effect.Effect<State, Error, Requirements>) => Logic<State, Event, Error, Requirements, never>;
|
|
2494
2803
|
/**
|
|
2495
|
-
* Creates a typed
|
|
2804
|
+
* Creates a typed descriptor for a complete child machine.
|
|
2496
2805
|
*
|
|
2497
|
-
*
|
|
2806
|
+
* Descriptors identify a child by id and machine identity, so independently
|
|
2807
|
+
* constructed descriptors for the same pair address the same invoked child.
|
|
2498
2808
|
*
|
|
2499
|
-
*
|
|
2500
|
-
*
|
|
2501
|
-
|
|
2809
|
+
* @category constructors
|
|
2810
|
+
* @since 4.0.0
|
|
2811
|
+
*/
|
|
2812
|
+
export declare const child: <const Id extends string, M extends Machine.Any>(id: Id, machine: M) => ChildMachine<Id, M>;
|
|
2813
|
+
/**
|
|
2814
|
+
* Creates a typed parent-local address for lower-level child process logic.
|
|
2815
|
+
*
|
|
2816
|
+
* The default event protocol is `never`; provide an event type before using
|
|
2817
|
+
* the address with `spawn`, `invoke`, or `sendTo`.
|
|
2502
2818
|
*
|
|
2503
2819
|
* @category constructors
|
|
2504
2820
|
* @since 4.0.0
|
|
2505
2821
|
*/
|
|
2506
|
-
export declare const
|
|
2507
|
-
<const Id extends string, M extends Machine.Any>(id: Id, machine: M): ChildMachine<Id, M>;
|
|
2508
|
-
<Event>(id: string): ChildAddress<Event>;
|
|
2509
|
-
};
|
|
2822
|
+
export declare const childAddress: <Event = never>(id: string) => ChildAddress<Event>;
|
|
2510
2823
|
/**
|
|
2511
2824
|
* Spawns a child process owned by the currently running machine.
|
|
2512
2825
|
*
|
|
@@ -2539,7 +2852,7 @@ export declare const spawn: {
|
|
|
2539
2852
|
*/
|
|
2540
2853
|
export declare const sendTo: {
|
|
2541
2854
|
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): Effect.Effect<void, StoppedError, MachineRuntimeRequirement>;
|
|
2542
|
-
<Address extends
|
|
2855
|
+
<Address extends ChildAddress<never>>(id: Address, event: ChildAddress.Event<Address>): Effect.Effect<void, StoppedError, MachineRuntimeRequirement>;
|
|
2543
2856
|
};
|
|
2544
2857
|
/**
|
|
2545
2858
|
* Stops a named child process of the running machine.
|
|
@@ -2547,7 +2860,10 @@ export declare const sendTo: {
|
|
|
2547
2860
|
* @category runtime
|
|
2548
2861
|
* @since 4.0.0
|
|
2549
2862
|
*/
|
|
2550
|
-
export declare const stopChild:
|
|
2863
|
+
export declare const stopChild: {
|
|
2864
|
+
<Event>(child: ChildAddress<Event>): Effect.Effect<void, never, MachineRuntimeRequirement>;
|
|
2865
|
+
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never, MachineRuntimeRequirement>;
|
|
2866
|
+
};
|
|
2551
2867
|
/**
|
|
2552
2868
|
* Returns a stream of terminal lifecycle outcomes for a running machine.
|
|
2553
2869
|
*
|
|
@@ -2583,5 +2899,5 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
2583
2899
|
* @category constructors
|
|
2584
2900
|
* @since 4.0.0
|
|
2585
2901
|
*/
|
|
2586
|
-
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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventOf<
|
|
2902
|
+
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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & Machine.EnsureOutputImplementations<States, OutputStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
|
|
2587
2903
|
//# sourceMappingURL=Machine.d.ts.map
|