@typeonce/effect-machine 0.8.0 → 0.10.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 +180 -40
- package/dist/Machine.d.ts +659 -481
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +86 -222
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/activities.d.ts +5 -12
- package/dist/internal/machine/activities.d.ts.map +1 -1
- package/dist/internal/machine/activities.js +47 -17
- package/dist/internal/machine/activities.js.map +1 -1
- package/dist/internal/machine/atom.d.ts +6 -2
- package/dist/internal/machine/atom.d.ts.map +1 -1
- package/dist/internal/machine/atom.js +5 -0
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/cluster.d.ts.map +1 -1
- package/dist/internal/machine/cluster.js +2 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/command.js +2 -2
- package/dist/internal/machine/command.js.map +1 -1
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -1
- package/dist/internal/machine/commandRuntime.js +6 -3
- package/dist/internal/machine/commandRuntime.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +8 -1
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +9 -4
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/errors.d.ts +1 -1
- package/dist/internal/machine/errors.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts +3 -3
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +74 -24
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts +10 -2
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +94 -34
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationEvent.d.ts +39 -0
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -0
- package/dist/internal/machine/invocationEvent.js +43 -0
- package/dist/internal/machine/invocationEvent.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +16 -65
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +18 -73
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +4 -2
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +104 -24
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +8 -8
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.d.ts +8 -5
- package/dist/internal/machine/protocol.d.ts.map +1 -1
- package/dist/internal/machine/protocol.js +207 -15
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts +8 -2
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js +86 -8
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/symbols.d.ts +2 -0
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js +2 -0
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +7 -0
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +29 -0
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +1 -1
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +2 -1
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js +5 -3
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +7 -7
- package/dist/testing/MachineTest.js +7 -7
- package/dist/unstable/cluster/ClusterMachine.d.ts +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +25 -8
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +18 -3
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/docs/agent-guide.md +242 -122
- package/package.json +2 -2
- package/src/Machine.ts +1453 -812
- package/src/internal/machine/activities.ts +48 -33
- package/src/internal/machine/atom.ts +38 -13
- package/src/internal/machine/cluster.ts +2 -1
- package/src/internal/machine/command.ts +2 -2
- package/src/internal/machine/commandRuntime.ts +9 -4
- package/src/internal/machine/configuration.ts +23 -5
- package/src/internal/machine/errors.ts +1 -1
- package/src/internal/machine/executionPlan.ts +102 -28
- package/src/internal/machine/invocation.ts +182 -50
- package/src/internal/machine/invocationEvent.ts +72 -0
- package/src/internal/machine/machine.ts +80 -387
- package/src/internal/machine/planner.ts +127 -32
- package/src/internal/machine/process.ts +18 -8
- package/src/internal/machine/protocol.ts +313 -25
- package/src/internal/machine/runtime.ts +135 -9
- package/src/internal/machine/symbols.ts +3 -0
- package/src/internal/machine/topology.ts +38 -0
- package/src/internal/testing/machine/finiteModel.ts +1 -1
- package/src/internal/testing/machine/runtime.ts +2 -1
- package/src/internal/testing/machine/verification.ts +5 -3
- package/src/testing/MachineTest.ts +7 -7
- package/src/unstable/cluster/ClusterMachine.ts +1 -1
- package/src/unstable/reactivity/AtomMachine.ts +45 -13
package/dist/Machine.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export type TypeId = "~effect/Machine";
|
|
|
37
37
|
export declare const TypeId: TypeId;
|
|
38
38
|
declare const MachineOutputStatesTypeId: unique symbol;
|
|
39
39
|
declare const MachineTypeId: unique symbol;
|
|
40
|
+
declare const EventConstructionTypeId: unique symbol;
|
|
41
|
+
declare const EmittedEventConstructionTypeId: unique symbol;
|
|
42
|
+
declare const EventProtocolTypeId: unique symbol;
|
|
43
|
+
declare const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId;
|
|
40
44
|
/**
|
|
41
45
|
* Type identifier used for the synthetic event passed to startup lifecycle
|
|
42
46
|
* actions.
|
|
@@ -90,10 +94,10 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
90
94
|
* @category models
|
|
91
95
|
* @since 0.4.0
|
|
92
96
|
*/
|
|
93
|
-
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 {
|
|
97
|
+
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, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []> extends Pipeable {
|
|
94
98
|
readonly [TypeId]: TypeId;
|
|
95
99
|
/** @internal Stable type-level carrier for machine protocol extraction. */
|
|
96
|
-
readonly [MachineTypeId]: Machine.TypeCarrier<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>;
|
|
100
|
+
readonly [MachineTypeId]: Machine.TypeCarrier<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>;
|
|
97
101
|
/** @internal Prevents output implementation evidence from being widened. */
|
|
98
102
|
readonly [MachineOutputStatesTypeId]: Readonly<Record<OutputStates, true>>;
|
|
99
103
|
/**
|
|
@@ -107,19 +111,31 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
107
111
|
*
|
|
108
112
|
* @since 0.4.0
|
|
109
113
|
*/
|
|
110
|
-
readonly events: InputEvents
|
|
114
|
+
readonly events: Machine.EventProtocol<"public", InputEvents>;
|
|
111
115
|
/**
|
|
112
|
-
* Events reserved for
|
|
116
|
+
* Events reserved for raised events and other machine-local work.
|
|
113
117
|
*
|
|
114
118
|
* @since 0.4.0
|
|
115
119
|
*/
|
|
116
|
-
readonly internalEvents:
|
|
120
|
+
readonly internalEvents: Machine.EventProtocol<"internal", Machine.InternalEventSchemas<Events, InputEvents>>;
|
|
117
121
|
/**
|
|
118
|
-
*
|
|
122
|
+
* Ephemeral outward notifications published to this actor's observers.
|
|
123
|
+
* Emissions are never delivered implicitly to an owning actor.
|
|
119
124
|
*
|
|
120
125
|
* @since 0.4.0
|
|
121
126
|
*/
|
|
122
|
-
readonly
|
|
127
|
+
readonly emittedEvents: Machine.EventProtocol<"emitted", Emits>;
|
|
128
|
+
/**
|
|
129
|
+
* Public input events accepted by an owning actor when this machine is
|
|
130
|
+
* running as a child.
|
|
131
|
+
*
|
|
132
|
+
* The protocol types the optional `parent` actor reference exposed to
|
|
133
|
+
* handlers and is checked against a concrete parent's public events at
|
|
134
|
+
* composition boundaries.
|
|
135
|
+
*
|
|
136
|
+
* @since 0.10.0
|
|
137
|
+
*/
|
|
138
|
+
readonly parentEvents: Machine.EventProtocol<"public", ParentEvents>;
|
|
123
139
|
/**
|
|
124
140
|
* Optional schema used to decode the machine input before initialization.
|
|
125
141
|
*
|
|
@@ -148,7 +164,7 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
148
164
|
*
|
|
149
165
|
* @since 0.4.0
|
|
150
166
|
*/
|
|
151
|
-
readonly handle: Machine.Handler<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents>;
|
|
167
|
+
readonly handle: Machine.Handler<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, ParentEvents>;
|
|
152
168
|
/** @internal */
|
|
153
169
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
|
|
154
170
|
}
|
|
@@ -254,7 +270,8 @@ export type PlanningServices<Requirements> = Exclude<Requirements, ActionRequire
|
|
|
254
270
|
*/
|
|
255
271
|
export type ExecutionServices<Requirements> = Exclude<PlanningServices<Requirements>, MachineRuntimeRequirement> | Exclude<ActionServices<Requirements>, MachineRuntimeRequirement>;
|
|
256
272
|
/**
|
|
257
|
-
* Managed runtime capability used to deliver raised and
|
|
273
|
+
* Managed runtime capability used to deliver raised events and publish
|
|
274
|
+
* emitted notifications.
|
|
258
275
|
*
|
|
259
276
|
* @category models
|
|
260
277
|
* @since 0.4.0
|
|
@@ -265,13 +282,36 @@ export interface Runtime<in Events, in Emits> {
|
|
|
265
282
|
*
|
|
266
283
|
* @since 0.4.0
|
|
267
284
|
*/
|
|
268
|
-
readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
285
|
+
readonly raise: (event: Machine.EventInput<Events>) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
269
286
|
/**
|
|
270
|
-
*
|
|
287
|
+
* Publishes an ephemeral notification to the running actor's observers.
|
|
271
288
|
*
|
|
272
289
|
* @since 0.4.0
|
|
273
290
|
*/
|
|
274
|
-
readonly
|
|
291
|
+
readonly emit: (event: Machine.EmittedEventInput<Emits>) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Minimal typed reference accepted by targeted actor commands.
|
|
295
|
+
*
|
|
296
|
+
* @category models
|
|
297
|
+
* @since 0.10.0
|
|
298
|
+
*/
|
|
299
|
+
export interface ActorRef<in Event> {
|
|
300
|
+
readonly id: string;
|
|
301
|
+
readonly sessionId: string;
|
|
302
|
+
readonly send: (event: Event) => Effect.Effect<void, StoppedError>;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Actor references available while evaluating machine behavior.
|
|
306
|
+
*
|
|
307
|
+
* @category models
|
|
308
|
+
* @since 0.10.0
|
|
309
|
+
*/
|
|
310
|
+
export interface ActorContext<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> {
|
|
311
|
+
/** Reference to the current actor. Sending queues a later mailbox event. */
|
|
312
|
+
readonly self: ActorRef<Machine.EventInputOf<InputEvents>>;
|
|
313
|
+
/** Reference to the owning actor, or `undefined` when running as a root. */
|
|
314
|
+
readonly parent: ActorRef<Machine.EventInputOf<ParentEvents>> | undefined;
|
|
275
315
|
}
|
|
276
316
|
/**
|
|
277
317
|
* Synchronous commands available while a machine transition is being
|
|
@@ -283,11 +323,12 @@ export interface Runtime<in Events, in Emits> {
|
|
|
283
323
|
*/
|
|
284
324
|
export interface Enqueue<in Events, in Emits> {
|
|
285
325
|
/** Raises an event inside the current macrostep. */
|
|
286
|
-
readonly raise: (event: Events) => void;
|
|
287
|
-
/**
|
|
288
|
-
readonly emit: (event: Emits) => void;
|
|
326
|
+
readonly raise: (event: Machine.EventInput<Events>) => void;
|
|
327
|
+
/** Publishes an ephemeral notification to this actor's observers. */
|
|
328
|
+
readonly emit: (event: Machine.EmittedEventInput<Emits>) => void;
|
|
289
329
|
/** Sends an event to an invoked child after the transition is selected. */
|
|
290
330
|
readonly sendTo: {
|
|
331
|
+
<Event>(target: ActorRef<Event>, event: Event): void;
|
|
291
332
|
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): void;
|
|
292
333
|
<Address extends ChildAddress<never>>(child: Address, event: ChildAddress.Event<Address>): void;
|
|
293
334
|
};
|
|
@@ -305,7 +346,7 @@ export interface Enqueue<in Events, in Emits> {
|
|
|
305
346
|
*/
|
|
306
347
|
export type Command = {
|
|
307
348
|
readonly _tag: "SendTo";
|
|
308
|
-
readonly
|
|
349
|
+
readonly target: ActorRef<unknown> | ChildMachine.Any | ChildAddress<never>;
|
|
309
350
|
readonly event: unknown;
|
|
310
351
|
} | {
|
|
311
352
|
readonly _tag: "Stop";
|
|
@@ -448,9 +489,11 @@ type EventProtocolError<Message extends string, Tag extends PropertyKey = never>
|
|
|
448
489
|
type DuplicateEventTag<Events extends ReadonlyArray<Machine.TaggedSchema>, Seen extends PropertyKey = never> = number extends Events["length"] ? never : Events extends readonly [
|
|
449
490
|
infer Head extends Machine.TaggedSchema,
|
|
450
491
|
...infer Tail extends ReadonlyArray<Machine.TaggedSchema>
|
|
451
|
-
] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ? Tag
|
|
492
|
+
] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ? Extract<Tag, Seen> | DuplicateEventTag<Tail, Seen | Tag> : never : never;
|
|
452
493
|
type ValidateInputEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInput extends PropertyKey = DuplicateEventTag<InputEvents>> = [DuplicateInput] extends [never] ? unknown : EventProtocolError<"Public event tags must be unique", DuplicateInput>;
|
|
494
|
+
type ValidateEmittedEventProtocol<EmittedEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateEmitted extends PropertyKey = DuplicateEventTag<EmittedEvents>> = [DuplicateEmitted] extends [never] ? unknown : EventProtocolError<"Emitted event tags must be unique", DuplicateEmitted>;
|
|
453
495
|
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>;
|
|
496
|
+
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>;
|
|
454
497
|
declare const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId;
|
|
455
498
|
declare const SnapshotBuilderConstructionTypeId: unique symbol;
|
|
456
499
|
type SnapshotBuilderComplete<Regions, Constructed extends boolean = false> = {
|
|
@@ -822,7 +865,7 @@ export type RuntimeOutcome<State, Error = never, Output = never> = {
|
|
|
822
865
|
* @category models
|
|
823
866
|
* @since 0.4.0
|
|
824
867
|
*/
|
|
825
|
-
export interface MachineRef<out State, in Event, out Error = never, out Output = never> {
|
|
868
|
+
export interface MachineRef<out State, in Event, out Error = never, out Output = never, out Emitted = never> extends ActorRef<Event> {
|
|
826
869
|
/** Stable machine definition id, or a generated fallback when none was declared. */
|
|
827
870
|
readonly id: string;
|
|
828
871
|
/** Unique identity for this running machine instance. */
|
|
@@ -831,8 +874,13 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
831
874
|
readonly state: Effect.Effect<State>;
|
|
832
875
|
/** Reads the latest lifecycle snapshot. */
|
|
833
876
|
readonly snapshot: Effect.Effect<RuntimeSnapshot<State, Error, Output>>;
|
|
834
|
-
/** Streams lifecycle
|
|
877
|
+
/** Streams the current lifecycle snapshot followed by later changes. */
|
|
835
878
|
readonly changes: Stream.Stream<RuntimeSnapshot<State, Error, Output>>;
|
|
879
|
+
/**
|
|
880
|
+
* Streams ephemeral notifications published after subscription. Emissions
|
|
881
|
+
* are not retained or replayed; the stream completes when the actor stops.
|
|
882
|
+
*/
|
|
883
|
+
readonly emissions: Stream.Stream<Emitted>;
|
|
836
884
|
/** Waits for machine output or fails when execution fails or is stopped. */
|
|
837
885
|
readonly join: Effect.Effect<Output, Error | StoppedError>;
|
|
838
886
|
/** Stops this machine instance and its owned child processes. */
|
|
@@ -900,12 +948,6 @@ export declare namespace Logic {
|
|
|
900
948
|
/**
|
|
901
949
|
* Machine-local capabilities available while process logic initializes.
|
|
902
950
|
*
|
|
903
|
-
* **Gotchas**
|
|
904
|
-
*
|
|
905
|
-
* `sendParent` accepts `unknown` because process logic is independent from
|
|
906
|
-
* the parent that eventually owns it. Prefer typed process output or an
|
|
907
|
-
* invoke snapshot mapper when either can represent the communication.
|
|
908
|
-
*
|
|
909
951
|
* @category models
|
|
910
952
|
* @since 0.4.0
|
|
911
953
|
*/
|
|
@@ -916,10 +958,11 @@ export declare namespace Logic {
|
|
|
916
958
|
readonly parent: Address<unknown> | undefined;
|
|
917
959
|
/** Starts a child process owned by this scope. */
|
|
918
960
|
readonly spawn: Spawn;
|
|
919
|
-
/** Sends an
|
|
920
|
-
readonly
|
|
921
|
-
|
|
922
|
-
|
|
961
|
+
/** Sends an event to an actor reference or typed parent-local child address. */
|
|
962
|
+
readonly sendTo: {
|
|
963
|
+
<TargetEvent>(target: ActorRef<TargetEvent>, event: TargetEvent): Effect.Effect<void, StoppedError>;
|
|
964
|
+
<Address extends ChildAddress<never>>(id: Address, event: ChildAddress.Event<Address>): Effect.Effect<void, StoppedError>;
|
|
965
|
+
};
|
|
923
966
|
/** Stops a child process selected by its parent-local address. */
|
|
924
967
|
readonly stopChild: <Event>(id: ChildAddress<Event>) => Effect.Effect<void>;
|
|
925
968
|
}
|
|
@@ -952,8 +995,9 @@ type InvokeLifecycleId = string & {
|
|
|
952
995
|
* **Details**
|
|
953
996
|
*
|
|
954
997
|
* The descriptor carries the child's address and complete machine type. Pass
|
|
955
|
-
* the same
|
|
956
|
-
* event, error, and output types are inferred
|
|
998
|
+
* a descriptor for the same id and machine to inline `invoke`, `sendTo`, and
|
|
999
|
+
* child lookup APIs so state, event, error, and output types are inferred
|
|
1000
|
+
* without separate annotations.
|
|
957
1001
|
*
|
|
958
1002
|
* @category models
|
|
959
1003
|
* @since 0.4.0
|
|
@@ -964,6 +1008,8 @@ export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
|
964
1008
|
readonly id: Id;
|
|
965
1009
|
/** Complete machine definition carried by this descriptor. */
|
|
966
1010
|
readonly machine: M;
|
|
1011
|
+
/** @internal */
|
|
1012
|
+
readonly [ChildMachineLogicTypeId]: (input?: unknown) => Logic<any, any, any, any, any, any>;
|
|
967
1013
|
}
|
|
968
1014
|
/**
|
|
969
1015
|
* Namespace containing type-level members associated with `ChildMachine`.
|
|
@@ -985,14 +1031,14 @@ export declare namespace ChildMachine {
|
|
|
985
1031
|
* @category utility types
|
|
986
1032
|
* @since 0.4.0
|
|
987
1033
|
*/
|
|
988
|
-
type Ref<Child> = Child extends ChildMachine<string, infer M> ? MachineRef<Machine.Snapshot<Machine.States<M>>, Machine.InputEvent<M
|
|
1034
|
+
type Ref<Child> = Child extends ChildMachine<string, infer M> ? MachineRef<Machine.Snapshot<Machine.States<M>>, Machine.EventInput<Machine.InputEvent<M>>, Machine.Error<M> | ActionError<Machine.Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Machine.Output<M>, Machine.EmittedEvent<M>> : never;
|
|
989
1035
|
/**
|
|
990
1036
|
* Event accepted by the child selected by a descriptor.
|
|
991
1037
|
*
|
|
992
1038
|
* @category utility types
|
|
993
1039
|
* @since 0.4.0
|
|
994
1040
|
*/
|
|
995
|
-
type Event<Child> =
|
|
1041
|
+
type Event<Child> = Child extends ChildMachine<string, infer M> ? Machine.EventInput<Machine.InputEvent<M>> : never;
|
|
996
1042
|
}
|
|
997
1043
|
/**
|
|
998
1044
|
* Parent-local address for a child process that can receive events.
|
|
@@ -1082,7 +1128,7 @@ export declare namespace Machine {
|
|
|
1082
1128
|
*
|
|
1083
1129
|
* @internal
|
|
1084
1130
|
*/
|
|
1085
|
-
interface TypeCarrier<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, Emits extends ReadonlyArray<TaggedSchema>, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>> {
|
|
1131
|
+
interface TypeCarrier<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, Emits extends ReadonlyArray<TaggedSchema>, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> {
|
|
1086
1132
|
readonly states: States;
|
|
1087
1133
|
readonly events: Events;
|
|
1088
1134
|
readonly input: Input;
|
|
@@ -1093,9 +1139,10 @@ export declare namespace Machine {
|
|
|
1093
1139
|
readonly initialServices: InitialR;
|
|
1094
1140
|
readonly finalStates: FinalStates;
|
|
1095
1141
|
readonly output: Output;
|
|
1096
|
-
readonly
|
|
1142
|
+
readonly emittedEvents: Emits;
|
|
1097
1143
|
readonly outputStates: OutputStates;
|
|
1098
1144
|
readonly inputEvents: InputEvents;
|
|
1145
|
+
readonly parentEvents: ParentEvents;
|
|
1099
1146
|
}
|
|
1100
1147
|
/**
|
|
1101
1148
|
* Any schema-first machine.
|
|
@@ -1112,11 +1159,12 @@ export declare namespace Machine {
|
|
|
1112
1159
|
interface Any extends Pipeable {
|
|
1113
1160
|
readonly [TypeId]: TypeId;
|
|
1114
1161
|
/** @internal */
|
|
1115
|
-
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
1162
|
+
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
1116
1163
|
readonly states: StateSchemas;
|
|
1117
|
-
readonly events:
|
|
1118
|
-
readonly internalEvents:
|
|
1119
|
-
readonly
|
|
1164
|
+
readonly events: EventProtocol.Any<"public">;
|
|
1165
|
+
readonly internalEvents: EventProtocol.Any<"internal">;
|
|
1166
|
+
readonly emittedEvents: EventProtocol.Any<"emitted">;
|
|
1167
|
+
readonly parentEvents: EventProtocol.Any<"public">;
|
|
1120
1168
|
readonly input: Schema.Top | undefined;
|
|
1121
1169
|
readonly id: string | undefined;
|
|
1122
1170
|
/** @internal */
|
|
@@ -1206,7 +1254,9 @@ export declare namespace Machine {
|
|
|
1206
1254
|
* @category utility types
|
|
1207
1255
|
* @since 0.4.0
|
|
1208
1256
|
*/
|
|
1209
|
-
type
|
|
1257
|
+
type EmittedEvents<M extends Any> = M[typeof MachineTypeId]["emittedEvents"];
|
|
1258
|
+
/** @deprecated Use {@link EmittedEvents}. */
|
|
1259
|
+
type Emits<M extends Any> = EmittedEvents<M>;
|
|
1210
1260
|
/**
|
|
1211
1261
|
* Extracts state paths with implemented output handlers.
|
|
1212
1262
|
*
|
|
@@ -1221,6 +1271,15 @@ export declare namespace Machine {
|
|
|
1221
1271
|
* @since 0.4.0
|
|
1222
1272
|
*/
|
|
1223
1273
|
type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"];
|
|
1274
|
+
/** Extracts the public input protocol required from an owning actor. */
|
|
1275
|
+
type ParentEvents<M extends Any> = M[typeof MachineTypeId]["parentEvents"];
|
|
1276
|
+
/** Extracts an internal event schema tuple from the complete and public protocols. */
|
|
1277
|
+
type InternalEventSchemas<Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>> = Events extends readonly [
|
|
1278
|
+
...InputEvents,
|
|
1279
|
+
...infer Internal extends ReadonlyArray<TaggedSchema>
|
|
1280
|
+
] ? readonly [...Internal] : readonly [];
|
|
1281
|
+
/** Extracts the internal event schema tuple carried by a machine definition. */
|
|
1282
|
+
type InternalEvents<M extends Any> = InternalEventSchemas<Events<M>, InputEvents<M>>;
|
|
1224
1283
|
/**
|
|
1225
1284
|
* Extracts the complete event protocol handled inside a machine.
|
|
1226
1285
|
*
|
|
@@ -1235,13 +1294,96 @@ export declare namespace Machine {
|
|
|
1235
1294
|
* @since 0.4.0
|
|
1236
1295
|
*/
|
|
1237
1296
|
type InputEvent<M extends Any> = EventOf<InputEvents<M>>;
|
|
1297
|
+
/**
|
|
1298
|
+
* Opaque event construction returned by {@link events} and
|
|
1299
|
+
* {@link internalEvents}.
|
|
1300
|
+
*
|
|
1301
|
+
* The machine resolves the instruction through its event schema when it is
|
|
1302
|
+
* delivered. Only the discriminator is available before decoding succeeds.
|
|
1303
|
+
*/
|
|
1304
|
+
interface EventConstruction<out Event extends {
|
|
1305
|
+
readonly _tag: PropertyKey;
|
|
1306
|
+
}> {
|
|
1307
|
+
readonly [EventConstructionTypeId]: Event;
|
|
1308
|
+
readonly _tag: Event["_tag"];
|
|
1309
|
+
}
|
|
1310
|
+
/** Opaque construction returned by {@link emittedEvents}. */
|
|
1311
|
+
interface EmittedEventConstruction<out Event extends {
|
|
1312
|
+
readonly _tag: PropertyKey;
|
|
1313
|
+
}> {
|
|
1314
|
+
readonly [EmittedEventConstructionTypeId]: Event;
|
|
1315
|
+
readonly _tag: Event["_tag"];
|
|
1316
|
+
}
|
|
1317
|
+
/** A decoded event or a deferred machine-bound construction of that event. */
|
|
1318
|
+
type EventInput<Event> = Event | (Event extends {
|
|
1319
|
+
readonly _tag: PropertyKey;
|
|
1320
|
+
} ? EventConstruction<Event> : never);
|
|
1321
|
+
/** A decoded emitted event or a deferred emitted-event construction. */
|
|
1322
|
+
type EmittedEventInput<Event> = Event | (Event extends {
|
|
1323
|
+
readonly _tag: PropertyKey;
|
|
1324
|
+
} ? EmittedEventConstruction<Event> : never);
|
|
1325
|
+
/** Event inputs accepted for a schema tuple at machine delivery boundaries. */
|
|
1326
|
+
type EventInputOf<Events extends ReadonlyArray<TaggedSchema>> = EventInput<EventOf<Events>>;
|
|
1327
|
+
/** Identifies whether an event protocol is accepted publicly or only inside a machine. */
|
|
1328
|
+
type EventProtocolKind = "public" | "internal" | "emitted";
|
|
1329
|
+
type EventConstructorInput<EventSchema extends TaggedSchema> = Omit<EventSchema["~type.make.in"], "_tag">;
|
|
1330
|
+
type EventConstructor<EventSchema extends TaggedSchema, Tag extends EventSchema["Type"]["_tag"], Kind extends EventProtocolKind> = {} extends EventConstructorInput<EventSchema> ? (input?: EventConstructorInput<EventSchema>) => Kind extends "emitted" ? EmittedEventConstruction<EventByTag<readonly [EventSchema], Tag>> : EventConstruction<EventByTag<readonly [EventSchema], Tag>> : (input: EventConstructorInput<EventSchema>) => Kind extends "emitted" ? EmittedEventConstruction<EventByTag<readonly [EventSchema], Tag>> : EventConstruction<EventByTag<readonly [EventSchema], Tag>>;
|
|
1331
|
+
type FiniteEventTag<Tag extends PropertyKey> = string extends Tag ? never : number extends Tag ? never : symbol extends Tag ? never : Tag;
|
|
1332
|
+
type EventConstructorsForSchema<EventSchema extends TaggedSchema, Kind extends EventProtocolKind> = EventSchema extends {
|
|
1333
|
+
readonly cases: infer Cases extends Readonly<Record<PropertyKey, TaggedSchema>>;
|
|
1334
|
+
} ? {
|
|
1335
|
+
readonly [Tag in keyof Cases]: Tag extends Cases[Tag]["Type"]["_tag"] ? EventConstructor<Cases[Tag], Tag, Kind> : never;
|
|
1336
|
+
} : EventSchema extends {
|
|
1337
|
+
readonly members: infer Members extends ReadonlyArray<TaggedSchema>;
|
|
1338
|
+
} ? Types.UnionToIntersection<EventConstructorsForSchema<Members[number], Kind>> : {
|
|
1339
|
+
readonly [Tag in FiniteEventTag<EventSchema["Type"]["_tag"]>]: EventConstructor<EventSchema, Tag, Kind>;
|
|
1340
|
+
};
|
|
1341
|
+
/** Protocol-bound constructors keyed by each configured event tag. */
|
|
1342
|
+
type EventConstructors<Events extends ReadonlyArray<TaggedSchema>, Kind extends EventProtocolKind = "public"> = {
|
|
1343
|
+
readonly [Tag in keyof Types.UnionToIntersection<EventConstructorsForSchema<Events[number], Kind>>]: Types.UnionToIntersection<EventConstructorsForSchema<Events[number], Kind>>[Tag];
|
|
1344
|
+
};
|
|
1345
|
+
/**
|
|
1346
|
+
* A schema-backed event protocol exposing only deferred event constructors.
|
|
1347
|
+
*
|
|
1348
|
+
* The schema tuple is retained opaquely for machine runtime validation and
|
|
1349
|
+
* type inference. It is not exposed as a runtime property.
|
|
1350
|
+
*
|
|
1351
|
+
* @since 0.10.0
|
|
1352
|
+
*/
|
|
1353
|
+
type EventProtocol<Kind extends EventProtocolKind, Schemas extends ReadonlyArray<TaggedSchema>> = EventConstructors<Schemas, Kind> & {
|
|
1354
|
+
readonly [EventProtocolTypeId]: {
|
|
1355
|
+
readonly kind: Kind;
|
|
1356
|
+
readonly schemas: Schemas;
|
|
1357
|
+
};
|
|
1358
|
+
};
|
|
1359
|
+
namespace EventProtocol {
|
|
1360
|
+
/** An erased event protocol descriptor retaining its kind and schema carrier. */
|
|
1361
|
+
interface Any<Kind extends EventProtocolKind = EventProtocolKind> {
|
|
1362
|
+
readonly [EventProtocolTypeId]: {
|
|
1363
|
+
readonly kind: Kind;
|
|
1364
|
+
readonly schemas: ReadonlyArray<TaggedSchema>;
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
/** A schema or an existing protocol accepted by an event builder. */
|
|
1369
|
+
type EventProtocolInput<Kind extends EventProtocolKind> = TaggedSchema | EventProtocol.Any<Kind>;
|
|
1370
|
+
type EventProtocolInputSchemas<Kind extends EventProtocolKind, Input extends EventProtocolInput<Kind>> = Input extends EventProtocol<Kind, infer Schemas> ? Schemas : Input extends TaggedSchema ? readonly [Input] : readonly [];
|
|
1371
|
+
/** Flattens schema and protocol inputs into one owned schema tuple. */
|
|
1372
|
+
type EventProtocolInputSchemasOf<Kind extends EventProtocolKind, Inputs extends ReadonlyArray<EventProtocolInput<Kind>>> = Inputs extends readonly [
|
|
1373
|
+
infer Head extends EventProtocolInput<Kind>,
|
|
1374
|
+
...infer Tail extends ReadonlyArray<EventProtocolInput<Kind>>
|
|
1375
|
+
] ? readonly [...EventProtocolInputSchemas<Kind, Head>, ...EventProtocolInputSchemasOf<Kind, Tail>] : readonly [];
|
|
1376
|
+
/** @internal Extracts the schema tuple carried opaquely by an event protocol. */
|
|
1377
|
+
type EventProtocolSchemas<Protocol extends EventProtocol.Any> = Protocol[typeof EventProtocolTypeId]["schemas"];
|
|
1238
1378
|
/**
|
|
1239
1379
|
* Extracts the event protocol emitted by a machine.
|
|
1240
1380
|
*
|
|
1241
1381
|
* @category utility types
|
|
1242
1382
|
* @since 0.4.0
|
|
1243
1383
|
*/
|
|
1244
|
-
type
|
|
1384
|
+
type EmittedEvent<M extends Any> = EmittedEventOf<Emits<M>>;
|
|
1385
|
+
/** @deprecated Use {@link EmittedEvent}. */
|
|
1386
|
+
type Emit<M extends Any> = EmittedEvent<M>;
|
|
1245
1387
|
/**
|
|
1246
1388
|
* A schema whose decoded value contains a `_tag` discriminator.
|
|
1247
1389
|
*
|
|
@@ -1596,6 +1738,10 @@ export declare namespace Machine {
|
|
|
1596
1738
|
readonly type: "done";
|
|
1597
1739
|
} | {
|
|
1598
1740
|
readonly type: "choice";
|
|
1741
|
+
} | {
|
|
1742
|
+
readonly type: "invoke";
|
|
1743
|
+
readonly id: string;
|
|
1744
|
+
readonly outcome: "done" | "failure" | "snapshot";
|
|
1599
1745
|
};
|
|
1600
1746
|
/**
|
|
1601
1747
|
* Statically inspectable destination paths for a transition handler.
|
|
@@ -1615,10 +1761,10 @@ export declare namespace Machine {
|
|
|
1615
1761
|
*
|
|
1616
1762
|
* **Details**
|
|
1617
1763
|
*
|
|
1618
|
-
* Event, eventless, and
|
|
1619
|
-
* possible target paths. A handler without that
|
|
1620
|
-
* reported as dynamic. The source, trigger, and
|
|
1621
|
-
* available without executing the handler.
|
|
1764
|
+
* Event, eventless, completion, and invocation lifecycle handlers may
|
|
1765
|
+
* declare an upper bound of possible target paths. A handler without that
|
|
1766
|
+
* declaration is explicitly reported as dynamic. The source, trigger, and
|
|
1767
|
+
* reentry behavior are available without executing the handler.
|
|
1622
1768
|
*
|
|
1623
1769
|
* @category models
|
|
1624
1770
|
* @since 0.4.0
|
|
@@ -1632,9 +1778,9 @@ export declare namespace Machine {
|
|
|
1632
1778
|
/**
|
|
1633
1779
|
* Serializable description of state-owned work.
|
|
1634
1780
|
*
|
|
1635
|
-
* Static invoke
|
|
1636
|
-
* retaining Effects, closures, services, or child runtimes.
|
|
1637
|
-
*
|
|
1781
|
+
* Static invoke definitions expose their lifecycle id and kind without
|
|
1782
|
+
* retaining Effects, closures, services, or child runtimes. Function-valued
|
|
1783
|
+
* sources are reported as dynamic and are never evaluated by inspection.
|
|
1638
1784
|
*
|
|
1639
1785
|
* @category models
|
|
1640
1786
|
* @since 0.4.0
|
|
@@ -1810,7 +1956,9 @@ export declare namespace Machine {
|
|
|
1810
1956
|
* @category utility types
|
|
1811
1957
|
* @since 0.4.0
|
|
1812
1958
|
*/
|
|
1813
|
-
type
|
|
1959
|
+
type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"];
|
|
1960
|
+
/** @deprecated Use {@link EmittedEventOf}. */
|
|
1961
|
+
type EmitOf<Emits extends ReadonlyArray<TaggedSchema>> = EmittedEventOf<Emits>;
|
|
1814
1962
|
/**
|
|
1815
1963
|
* Event values received by lifecycle callbacks.
|
|
1816
1964
|
*
|
|
@@ -2210,6 +2358,20 @@ export declare namespace Machine {
|
|
|
2210
2358
|
readonly [AncestorStateId in ValuedStateIdentifier<States>]: StateByIdentifier<States, AncestorStateId>;
|
|
2211
2359
|
}>;
|
|
2212
2360
|
}
|
|
2361
|
+
/**
|
|
2362
|
+
* Opaque result returned by an explicitly targetless transition.
|
|
2363
|
+
*
|
|
2364
|
+
* The transition remains handled and retains its queued commands, raised
|
|
2365
|
+
* events, and emitted events, but selects no concrete destination. Declared
|
|
2366
|
+
* `targets` constrain only concrete destinations, so this result is always
|
|
2367
|
+
* permitted from ordinary transition handlers.
|
|
2368
|
+
*
|
|
2369
|
+
* @category models
|
|
2370
|
+
* @since 0.10.0
|
|
2371
|
+
*/
|
|
2372
|
+
interface NoTarget {
|
|
2373
|
+
readonly [Topology.NoTargetTypeId]: typeof Topology.NoTargetTypeId;
|
|
2374
|
+
}
|
|
2213
2375
|
/**
|
|
2214
2376
|
* Transition instruction that restores a history pseudo-state's parent.
|
|
2215
2377
|
*
|
|
@@ -2286,9 +2448,9 @@ export declare namespace Machine {
|
|
|
2286
2448
|
*
|
|
2287
2449
|
* **Details**
|
|
2288
2450
|
*
|
|
2289
|
-
* `
|
|
2290
|
-
*
|
|
2291
|
-
* snapshots for any root.
|
|
2451
|
+
* `none()` handles without selecting a destination, `local` targets the
|
|
2452
|
+
* nearest compound scope for the source state, `branch` targets descendants
|
|
2453
|
+
* of the source root, and `full` builds complete snapshots for any root.
|
|
2292
2454
|
*
|
|
2293
2455
|
* These builders control how the next active configuration is assembled; they
|
|
2294
2456
|
* do not directly control state re-entry. Exit and entry paths are derived
|
|
@@ -2301,6 +2463,17 @@ export declare namespace Machine {
|
|
|
2301
2463
|
* @since 0.4.0
|
|
2302
2464
|
*/
|
|
2303
2465
|
interface TargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
|
|
2466
|
+
/**
|
|
2467
|
+
* Selects an explicitly targetless transition.
|
|
2468
|
+
*
|
|
2469
|
+
* The event or lifecycle outcome is handled and queued operations are
|
|
2470
|
+
* retained, while the current state configuration remains the transition
|
|
2471
|
+
* result. This remains valid when the handler declares concrete `targets`,
|
|
2472
|
+
* because those paths are an upper bound rather than an exhaustive result.
|
|
2473
|
+
*
|
|
2474
|
+
* @since 0.10.0
|
|
2475
|
+
*/
|
|
2476
|
+
readonly none: () => NoTarget;
|
|
2304
2477
|
/**
|
|
2305
2478
|
* Moves to another state in the same local group. The value of the state
|
|
2306
2479
|
* containing that group, and values in other active branches, are kept.
|
|
@@ -2338,10 +2511,10 @@ export declare namespace Machine {
|
|
|
2338
2511
|
* @category models
|
|
2339
2512
|
* @since 0.4.0
|
|
2340
2513
|
*/
|
|
2341
|
-
interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
2514
|
+
interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2342
2515
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2343
|
-
readonly
|
|
2344
|
-
readonly
|
|
2516
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2517
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2345
2518
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
2346
2519
|
readonly snapshot: Snapshot<States>;
|
|
2347
2520
|
readonly event: EventByTag<Events, EventTag>;
|
|
@@ -2359,56 +2532,75 @@ export declare namespace Machine {
|
|
|
2359
2532
|
* @category models
|
|
2360
2533
|
* @since 0.4.0
|
|
2361
2534
|
*/
|
|
2362
|
-
interface StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States
|
|
2535
|
+
interface StateActionContext<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 []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2363
2536
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2364
|
-
readonly
|
|
2365
|
-
readonly
|
|
2537
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2538
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2366
2539
|
readonly event: LifecycleEvent<Events>;
|
|
2367
2540
|
}
|
|
2368
2541
|
/**
|
|
2369
|
-
* Context passed to
|
|
2542
|
+
* Context passed to a function-valued invocation source.
|
|
2370
2543
|
*
|
|
2371
2544
|
* @category models
|
|
2372
2545
|
* @since 0.4.0
|
|
2373
2546
|
*/
|
|
2374
|
-
interface InvokeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States
|
|
2547
|
+
interface InvokeContext<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 []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2375
2548
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2376
|
-
readonly
|
|
2377
|
-
readonly
|
|
2549
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2550
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2378
2551
|
readonly event: LifecycleEvent<Events>;
|
|
2379
2552
|
}
|
|
2380
2553
|
/**
|
|
2381
|
-
* Context passed to an
|
|
2554
|
+
* Context passed to an invocation's active-snapshot transition.
|
|
2382
2555
|
*
|
|
2383
2556
|
* @category models
|
|
2384
2557
|
* @since 0.4.0
|
|
2385
2558
|
*/
|
|
2386
|
-
interface InvokeSnapshotContext<State, Error, Output> {
|
|
2559
|
+
interface InvokeSnapshotContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, State, Error, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2387
2560
|
readonly id: string;
|
|
2561
|
+
readonly state: StateByIdentifier<States, StateId>;
|
|
2562
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2563
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2564
|
+
readonly target: TargetBuilder<States, StateId>;
|
|
2388
2565
|
readonly snapshot: Extract<RuntimeSnapshot<State, Error, Output>, {
|
|
2389
2566
|
readonly status: "active";
|
|
2390
2567
|
}>;
|
|
2391
2568
|
}
|
|
2392
2569
|
/**
|
|
2393
|
-
* Context passed to an
|
|
2570
|
+
* Context passed to an invocation's successful completion transition.
|
|
2394
2571
|
*
|
|
2395
2572
|
* @category models
|
|
2396
2573
|
* @since 0.4.0
|
|
2397
2574
|
*/
|
|
2398
|
-
interface InvokeDoneContext<Output> {
|
|
2575
|
+
interface InvokeDoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2399
2576
|
readonly id: string;
|
|
2577
|
+
readonly state: StateByIdentifier<States, StateId>;
|
|
2578
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2579
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2580
|
+
readonly snapshot: Snapshot<States>;
|
|
2581
|
+
readonly target: TargetBuilder<States, StateId>;
|
|
2400
2582
|
readonly output: Output;
|
|
2401
2583
|
}
|
|
2584
|
+
/** Context passed to an invocation typed-failure transition. */
|
|
2585
|
+
interface InvokeFailureContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Error, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2586
|
+
readonly id: string;
|
|
2587
|
+
readonly state: StateByIdentifier<States, StateId>;
|
|
2588
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2589
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2590
|
+
readonly snapshot: Snapshot<States>;
|
|
2591
|
+
readonly target: TargetBuilder<States, StateId>;
|
|
2592
|
+
readonly error: Error;
|
|
2593
|
+
}
|
|
2402
2594
|
/**
|
|
2403
2595
|
* Context passed to an eventless transition handler.
|
|
2404
2596
|
*
|
|
2405
2597
|
* @category models
|
|
2406
2598
|
* @since 0.4.0
|
|
2407
2599
|
*/
|
|
2408
|
-
interface AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States
|
|
2600
|
+
interface AlwaysContext<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 []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2409
2601
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2410
|
-
readonly
|
|
2411
|
-
readonly
|
|
2602
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2603
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2412
2604
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
2413
2605
|
readonly snapshot: Snapshot<States>;
|
|
2414
2606
|
readonly event: LifecycleEvent<Events>;
|
|
@@ -2427,10 +2619,10 @@ export declare namespace Machine {
|
|
|
2427
2619
|
* @category models
|
|
2428
2620
|
* @since 0.4.0
|
|
2429
2621
|
*/
|
|
2430
|
-
interface DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States
|
|
2622
|
+
interface DoneContext<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 []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2431
2623
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2432
|
-
readonly
|
|
2433
|
-
readonly
|
|
2624
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2625
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2434
2626
|
/** Complete logical configuration captured at the start of this microstep. */
|
|
2435
2627
|
readonly snapshot: Snapshot<States>;
|
|
2436
2628
|
readonly event: LifecycleEvent<Events>;
|
|
@@ -2445,9 +2637,9 @@ export declare namespace Machine {
|
|
|
2445
2637
|
readonly target: TargetBuilder<States, StateId>;
|
|
2446
2638
|
}
|
|
2447
2639
|
/** Context passed to a transient choice resolver. There is no `state` value. */
|
|
2448
|
-
interface ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States
|
|
2449
|
-
readonly
|
|
2450
|
-
readonly
|
|
2640
|
+
interface ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> extends ActorContext<InputEvents, ParentEvents> {
|
|
2641
|
+
readonly containingState: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
|
|
2642
|
+
readonly ancestors: {
|
|
2451
2643
|
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
2452
2644
|
};
|
|
2453
2645
|
readonly event: LifecycleEvent<Events>;
|
|
@@ -2461,8 +2653,8 @@ export declare namespace Machine {
|
|
|
2461
2653
|
*/
|
|
2462
2654
|
interface FinalOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2463
2655
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2464
|
-
readonly
|
|
2465
|
-
readonly
|
|
2656
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2657
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2466
2658
|
readonly event: LifecycleEvent<Events>;
|
|
2467
2659
|
}
|
|
2468
2660
|
/**
|
|
@@ -2485,8 +2677,8 @@ export declare namespace Machine {
|
|
|
2485
2677
|
*/
|
|
2486
2678
|
interface ParallelOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2487
2679
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2488
|
-
readonly
|
|
2489
|
-
readonly
|
|
2680
|
+
readonly containingState: ParentStateValue<States, StateId>;
|
|
2681
|
+
readonly ancestors: ParentStateValues<States, StateId>;
|
|
2490
2682
|
readonly event: LifecycleEvent<Events>;
|
|
2491
2683
|
readonly outputs: ParallelOutputRegions<States, StateId>;
|
|
2492
2684
|
}
|
|
@@ -2513,14 +2705,15 @@ export declare namespace Machine {
|
|
|
2513
2705
|
*
|
|
2514
2706
|
* **Details**
|
|
2515
2707
|
*
|
|
2516
|
-
* Handlers return snapshots for complete state replacement
|
|
2517
|
-
* results for path-safe partial transitions
|
|
2518
|
-
*
|
|
2708
|
+
* Handlers return snapshots for complete state replacement, target builder
|
|
2709
|
+
* results for path-safe partial transitions, or `target.none()` for an
|
|
2710
|
+
* explicitly targetless transition. Raw decoded state values and `void` are
|
|
2711
|
+
* not accepted at transition boundaries.
|
|
2519
2712
|
*
|
|
2520
2713
|
* @category utility types
|
|
2521
2714
|
* @since 0.4.0
|
|
2522
2715
|
*/
|
|
2523
|
-
type HandlerResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>>> |
|
|
2716
|
+
type HandlerResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>>> | NoTarget;
|
|
2524
2717
|
/** A choice resolver must always select a typed target synchronously. */
|
|
2525
2718
|
type ChoiceResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>>>;
|
|
2526
2719
|
/**
|
|
@@ -2611,9 +2804,17 @@ export declare namespace Machine {
|
|
|
2611
2804
|
* @category utility types
|
|
2612
2805
|
* @since 0.4.0
|
|
2613
2806
|
*/
|
|
2807
|
+
type InvokeResolvedSource<Source> = Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
2808
|
+
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialServices<M> | Services<M>>, internalRuntime.MachineRuntime>, Event<M>, Emit<M>>, Output<M>, InitialError<M> | Error<M> | ActionError<InitialServices<M> | Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError> : never;
|
|
2614
2809
|
type InvokeLogic<Invoke> = Invoke extends {
|
|
2615
|
-
readonly
|
|
2616
|
-
} ? Logic : never
|
|
2810
|
+
readonly effect: infer Source;
|
|
2811
|
+
} ? InvokeResolvedSource<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 {
|
|
2812
|
+
readonly after: unknown;
|
|
2813
|
+
} ? Logic<void, never, never, never, void> : Invoke extends {
|
|
2814
|
+
readonly logic: infer Source;
|
|
2815
|
+
} ? InvokeResolvedSource<Source> : Invoke extends {
|
|
2816
|
+
readonly child: infer Child;
|
|
2817
|
+
} ? ChildMachineLogic<Child> : never;
|
|
2617
2818
|
/**
|
|
2618
2819
|
* Extracts the startup error from an invoke source child process logic.
|
|
2619
2820
|
*
|
|
@@ -2666,34 +2867,41 @@ export declare namespace Machine {
|
|
|
2666
2867
|
*/
|
|
2667
2868
|
type InvokeEmits<Invoke> = Invoke extends {
|
|
2668
2869
|
readonly [InvokeTypeId]: {
|
|
2669
|
-
readonly emits: Types.Covariant<infer
|
|
2870
|
+
readonly emits: Types.Covariant<infer Emitted>;
|
|
2670
2871
|
};
|
|
2671
|
-
} ?
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
* @since 0.4.0
|
|
2677
|
-
*/
|
|
2678
|
-
type InvokeSnapshotEvent<Invoke> = Invoke extends {
|
|
2872
|
+
} ? Emitted : Invoke extends {
|
|
2873
|
+
readonly child: ChildMachine<string, infer M>;
|
|
2874
|
+
} ? Emit<M> : never;
|
|
2875
|
+
/** Public parent inputs required by an invoked child machine. */
|
|
2876
|
+
type InvokeParentEvents<Invoke> = Invoke extends {
|
|
2679
2877
|
readonly [InvokeTypeId]: {
|
|
2680
|
-
readonly
|
|
2878
|
+
readonly parentEvents: Types.Covariant<infer ParentEvent>;
|
|
2681
2879
|
};
|
|
2682
|
-
} ?
|
|
2880
|
+
} ? ParentEvent : IsAny<Invoke> extends true ? never : Invoke extends {
|
|
2881
|
+
readonly child: ChildMachine<string, infer M>;
|
|
2882
|
+
} ? EventOf<ParentEvents<M>> : never;
|
|
2883
|
+
/** Extracts transition results returned by invocation lifecycle handlers. */
|
|
2884
|
+
type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ? (Invoke extends {
|
|
2885
|
+
readonly onDone?: infer Handler;
|
|
2886
|
+
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
2887
|
+
readonly onFailure?: infer Handler;
|
|
2888
|
+
} ? EventTransitionReturn<NonNullable<Handler>> : never) | (Invoke extends {
|
|
2889
|
+
readonly onSnapshot?: infer Handler;
|
|
2890
|
+
} ? EventTransitionReturn<NonNullable<Handler>> : never) : never;
|
|
2683
2891
|
/**
|
|
2684
2892
|
* Extracts the parent transition error contribution from invoked children.
|
|
2685
2893
|
*
|
|
2686
2894
|
* @category utility types
|
|
2687
2895
|
* @since 0.4.0
|
|
2688
2896
|
*/
|
|
2689
|
-
type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : ChildAlreadyExistsError | InvokeInitialError<InvokeReturn<Config>> |
|
|
2897
|
+
type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : ChildAlreadyExistsError | InvokeInitialError<InvokeReturn<Config>> | Effect.Error<InvokeOutcomeReturn<InvokeReturn<Config>>>;
|
|
2690
2898
|
/**
|
|
2691
2899
|
* Extracts the parent service requirement contribution from invoked children.
|
|
2692
2900
|
*
|
|
2693
2901
|
* @category utility types
|
|
2694
2902
|
* @since 0.4.0
|
|
2695
2903
|
*/
|
|
2696
|
-
type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntimeRequirement | InvokeServices<InvokeReturn<Config
|
|
2904
|
+
type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntimeRequirement | InvokeServices<InvokeReturn<Config>> | Effect.Services<InvokeOutcomeReturn<InvokeReturn<Config>>>;
|
|
2697
2905
|
/**
|
|
2698
2906
|
* Extracts the return value from an eventless transition.
|
|
2699
2907
|
*
|
|
@@ -2728,63 +2936,172 @@ export declare namespace Machine {
|
|
|
2728
2936
|
* @since 0.4.0
|
|
2729
2937
|
*/
|
|
2730
2938
|
type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<StateInitialReturn<Config>> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config>;
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
interface
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
readonly emits: Types.Covariant<ChildEmits>;
|
|
2741
|
-
readonly snapshotEvent: Types.Covariant<Event>;
|
|
2742
|
-
readonly error: Types.Covariant<ChildError>;
|
|
2743
|
-
readonly requirements: Types.Covariant<ChildRequirements>;
|
|
2744
|
-
readonly initialError: Types.Covariant<ChildInitialError>;
|
|
2745
|
-
};
|
|
2746
|
-
/** @internal Serializable descriptor metadata used by inspection. */
|
|
2747
|
-
readonly [Activities.ActivityMetadataTypeId]?: Activities.StaticActivityMetadata;
|
|
2748
|
-
readonly id: string;
|
|
2749
|
-
/**
|
|
2750
|
-
* Optional parent-local address for sending events to this invocation.
|
|
2751
|
-
*
|
|
2752
|
-
* The invocation `id` is only its state-local lifecycle key. Use an
|
|
2753
|
-
* explicit typed address when the parent must communicate with it.
|
|
2754
|
-
*/
|
|
2755
|
-
readonly address?: string;
|
|
2756
|
-
/** @internal */
|
|
2757
|
-
readonly descriptor?: ChildMachine.Any;
|
|
2758
|
-
src(): Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>;
|
|
2759
|
-
snapshot?(context: InvokeSnapshotContext<ChildState, ChildError, ChildOutput>): Event | undefined;
|
|
2760
|
-
onDone?(context: InvokeDoneContext<ChildOutput>): DeliveredOutput | undefined;
|
|
2939
|
+
type InvokeTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Context> = ((context: Context, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2940
|
+
readonly reenter?: boolean;
|
|
2941
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2942
|
+
readonly transition: (context: Context, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2943
|
+
};
|
|
2944
|
+
type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
2945
|
+
interface AnyLogicSource {
|
|
2946
|
+
initial(...args: ReadonlyArray<any>): Effect.Effect<any, any, any>;
|
|
2947
|
+
run(...args: ReadonlyArray<any>): Effect.Effect<any, any, any>;
|
|
2761
2948
|
}
|
|
2762
|
-
/**
|
|
2763
|
-
interface
|
|
2949
|
+
/** Inline state-owned work that runs for the lifetime of its active state. */
|
|
2950
|
+
interface InvokeOwned<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2951
|
+
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId]>;
|
|
2952
|
+
}
|
|
2953
|
+
/** Type evidence retained by {@link invoke} without affecting runtime data. */
|
|
2954
|
+
interface InvokeTyped<Output, Error, Requirements, InitialError, Emits = never, ParentEvent = never> {
|
|
2764
2955
|
readonly [InvokeTypeId]: {
|
|
2765
2956
|
readonly output: Types.Covariant<Output>;
|
|
2766
|
-
readonly emits: Types.Covariant<Emits>;
|
|
2767
|
-
readonly snapshotEvent: Types.Covariant<SnapshotEvent>;
|
|
2768
2957
|
readonly error: Types.Covariant<Error>;
|
|
2769
2958
|
readonly requirements: Types.Covariant<Requirements>;
|
|
2770
2959
|
readonly initialError: Types.Covariant<InitialError>;
|
|
2960
|
+
readonly emits: Types.Covariant<Emits>;
|
|
2961
|
+
readonly parentEvents: Types.Covariant<ParentEvent>;
|
|
2771
2962
|
};
|
|
2772
2963
|
}
|
|
2773
|
-
|
|
2774
|
-
readonly
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2964
|
+
type InvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = InvokeOwned<States, Events, Emits, StateId> & ({
|
|
2965
|
+
readonly id: string;
|
|
2966
|
+
readonly effect: InvokeSource<Effect.Effect<any, any, any>, InvokeContext<States, Events, Emits, StateId>>;
|
|
2967
|
+
readonly after?: never;
|
|
2968
|
+
readonly logic?: never;
|
|
2969
|
+
readonly child?: never;
|
|
2970
|
+
readonly address?: never;
|
|
2971
|
+
readonly onDone?: unknown;
|
|
2972
|
+
readonly onFailure?: unknown;
|
|
2973
|
+
readonly onSnapshot?: never;
|
|
2974
|
+
} | {
|
|
2975
|
+
readonly id: string;
|
|
2976
|
+
readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId>>;
|
|
2977
|
+
readonly effect?: never;
|
|
2978
|
+
readonly logic?: never;
|
|
2979
|
+
readonly child?: never;
|
|
2980
|
+
readonly address?: never;
|
|
2981
|
+
readonly onDone: unknown;
|
|
2982
|
+
readonly onFailure?: never;
|
|
2983
|
+
readonly onSnapshot?: never;
|
|
2984
|
+
} | {
|
|
2985
|
+
readonly id: string;
|
|
2986
|
+
readonly address: string;
|
|
2987
|
+
readonly logic: InvokeSource<AnyLogicSource, InvokeContext<States, Events, Emits, StateId>>;
|
|
2988
|
+
readonly effect?: never;
|
|
2989
|
+
readonly after?: never;
|
|
2990
|
+
readonly child?: never;
|
|
2991
|
+
readonly onDone?: unknown;
|
|
2992
|
+
readonly onFailure?: unknown;
|
|
2993
|
+
readonly onSnapshot?: unknown;
|
|
2994
|
+
} | {
|
|
2995
|
+
readonly child: ChildMachine.Any;
|
|
2996
|
+
readonly input?: {} | null | ((context: InvokeContext<States, Events, Emits, StateId>) => unknown);
|
|
2997
|
+
readonly id?: never;
|
|
2998
|
+
readonly address?: never;
|
|
2999
|
+
readonly effect?: never;
|
|
3000
|
+
readonly after?: never;
|
|
3001
|
+
readonly logic?: never;
|
|
3002
|
+
readonly onDone?: unknown;
|
|
3003
|
+
readonly onFailure?: unknown;
|
|
3004
|
+
readonly onSnapshot?: unknown;
|
|
3005
|
+
});
|
|
3006
|
+
/** State-bound inline invocation configuration. */
|
|
3007
|
+
type InvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = InvokeConfig<States, Events, Emits, StateId> | ReadonlyArray<InvokeConfig<States, Events, Emits, StateId>>;
|
|
3008
|
+
type InvokeHandlerRequirement<Value, Handler> = IsAny<Value> extends true ? {
|
|
3009
|
+
readonly handler: Handler;
|
|
3010
|
+
} : [Value] extends [never] ? {
|
|
3011
|
+
readonly handler?: never;
|
|
3012
|
+
} : {
|
|
3013
|
+
readonly handler: Handler;
|
|
3014
|
+
};
|
|
3015
|
+
type InvokeDoneRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends infer Requirement ? Requirement extends {
|
|
3016
|
+
readonly handler: infer Required;
|
|
3017
|
+
} ? {
|
|
3018
|
+
readonly onDone: Required;
|
|
3019
|
+
} : {
|
|
3020
|
+
readonly onDone?: never;
|
|
3021
|
+
} : never;
|
|
3022
|
+
type InvokeFailureRequirement<Value, Handler> = InvokeHandlerRequirement<Value, Handler> extends infer Requirement ? Requirement extends {
|
|
3023
|
+
readonly handler: infer Required;
|
|
3024
|
+
} ? {
|
|
3025
|
+
readonly onFailure: Required;
|
|
3026
|
+
} : {
|
|
3027
|
+
readonly onFailure?: never;
|
|
3028
|
+
} : never;
|
|
3029
|
+
type EffectInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Fx extends Effect.Effect<any, any, any>, Source = Fx> = {
|
|
3030
|
+
readonly id: InvokeLifecycleId;
|
|
3031
|
+
readonly effect: Source;
|
|
3032
|
+
readonly after?: never;
|
|
3033
|
+
readonly logic?: never;
|
|
3034
|
+
readonly child?: never;
|
|
3035
|
+
readonly address?: never;
|
|
3036
|
+
readonly onSnapshot?: never;
|
|
3037
|
+
} & InvokeDoneRequirement<Effect.Success<NoInfer<Fx>>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<NoInfer<Fx>>>>> & InvokeFailureRequirement<Effect.Error<NoInfer<Fx>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<NoInfer<Fx>>>>>;
|
|
3038
|
+
type TimerInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = {
|
|
3039
|
+
readonly id: InvokeLifecycleId;
|
|
3040
|
+
readonly after: InvokeSource<Duration.Input, InvokeContext<States, Events, Emits, StateId>>;
|
|
3041
|
+
readonly effect?: never;
|
|
3042
|
+
readonly logic?: never;
|
|
3043
|
+
readonly child?: never;
|
|
3044
|
+
readonly address?: never;
|
|
3045
|
+
readonly onFailure?: never;
|
|
3046
|
+
readonly onSnapshot?: never;
|
|
3047
|
+
readonly onDone: InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, void>>;
|
|
3048
|
+
};
|
|
3049
|
+
type LogicInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, Source = Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>> = {
|
|
3050
|
+
readonly id: InvokeLifecycleId;
|
|
3051
|
+
readonly address: Address & ChildAddress.Compatibility<Address, ChildEvent>;
|
|
3052
|
+
readonly logic: Source;
|
|
3053
|
+
readonly effect?: never;
|
|
3054
|
+
readonly after?: never;
|
|
3055
|
+
readonly child?: never;
|
|
3056
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, ChildState, ChildError, ChildOutput>>;
|
|
3057
|
+
} & InvokeDoneRequirement<ChildOutput, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, ChildOutput>>> & InvokeFailureRequirement<ChildError, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, ChildError>>>;
|
|
3058
|
+
type ChildInvokeArgs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, ChildDefinition extends Machine.Any, Child extends ChildMachine<string, ChildDefinition>> = {
|
|
3059
|
+
readonly child: Child & (ChildDefinition extends EnsureExecutable<Machine.States<ChildDefinition>, Machine.UnhandledStates<ChildDefinition>, Machine.OutputStates<ChildDefinition>> ? unknown : never);
|
|
3060
|
+
readonly id?: never;
|
|
3061
|
+
readonly address?: never;
|
|
3062
|
+
readonly effect?: never;
|
|
3063
|
+
readonly after?: never;
|
|
3064
|
+
readonly logic?: never;
|
|
3065
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>>>;
|
|
3066
|
+
} & (Input<ChildDefinition> extends typeof Schema.Void ? {
|
|
3067
|
+
readonly input?: never;
|
|
3068
|
+
} : {
|
|
3069
|
+
readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId>>;
|
|
3070
|
+
}) & InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>>>>;
|
|
3071
|
+
type LogicStateOf<Value> = Value extends Logic<infer State, any, any, any, any, any> ? State : never;
|
|
3072
|
+
type LogicEventOf<Value> = Value extends Logic<any, infer Event, any, any, any, any> ? Event : never;
|
|
3073
|
+
type LogicErrorOf<Value> = Value extends Logic<any, any, infer Error, any, any, any> ? Error : never;
|
|
3074
|
+
type LogicServicesOf<Value> = Value extends Logic<any, any, any, infer Services, any, any> ? Services : never;
|
|
3075
|
+
type LogicOutputOf<Value> = Value extends Logic<any, any, any, any, infer Output, any> ? Output : never;
|
|
3076
|
+
type LogicInitialErrorOf<Value> = Value extends Logic<any, any, any, any, any, infer Error> ? Error : never;
|
|
3077
|
+
type ContextualInvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Raw> = Raw extends InvokeTyped<any, any, any, any, any> ? unknown : Raw extends {
|
|
3078
|
+
readonly effect: infer Source;
|
|
3079
|
+
} ? InvokeResolvedSource<Source> extends infer Fx extends Effect.Effect<any, any, any> ? InvokeDoneRequirement<Effect.Success<Fx>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<Fx>>>> & InvokeFailureRequirement<Effect.Error<Fx>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<Fx>>>> & {
|
|
3080
|
+
readonly onSnapshot?: never;
|
|
3081
|
+
} : never : Raw extends {
|
|
3082
|
+
readonly after: unknown;
|
|
3083
|
+
} ? {
|
|
3084
|
+
readonly onDone: InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, void>>;
|
|
3085
|
+
readonly onFailure?: never;
|
|
3086
|
+
readonly onSnapshot?: never;
|
|
3087
|
+
} : Raw extends {
|
|
3088
|
+
readonly logic: infer Source;
|
|
3089
|
+
readonly address: infer Address;
|
|
3090
|
+
} ? InvokeResolvedSource<Source> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ? InvokeDoneRequirement<InvokeOutput<Raw>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, InvokeOutput<Raw>>>> & InvokeFailureRequirement<InvokeRuntimeError<Raw>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, InvokeRuntimeError<Raw>>>> & {
|
|
3091
|
+
readonly address: ChildAddress<never> & ChildAddress.Compatibility<Address, ChildLogic extends Logic<any, infer ChildEvent, any, any, any, any> ? ChildEvent : never>;
|
|
3092
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, ChildLogic extends Logic<infer ChildState, any, any, any, any, any> ? ChildState : never, InvokeRuntimeError<Raw>, InvokeOutput<Raw>>>;
|
|
3093
|
+
} : never : Raw extends {
|
|
3094
|
+
readonly child: infer Child extends ChildMachine<string, infer ChildDefinition>;
|
|
3095
|
+
} ? ChildMachineLogic<Child> extends infer ChildLogic extends Logic<any, any, any, any, any, any> ? InvokeDoneRequirement<Output<ChildDefinition>, InvokeTransition<States, Events, Emits, InvokeDoneContext<States, Events, Emits, StateId, Output<ChildDefinition>>>> & InvokeFailureRequirement<Error<ChildDefinition> | ActionError<Services<ChildDefinition>>, InvokeTransition<States, Events, Emits, InvokeFailureContext<States, Events, Emits, StateId, Error<ChildDefinition> | ActionError<Services<ChildDefinition>>>>> & (Input<ChildDefinition> extends typeof Schema.Void ? {
|
|
3096
|
+
readonly input?: never;
|
|
3097
|
+
} : {
|
|
3098
|
+
readonly input: InvokeSource<Input<ChildDefinition>["Type"], InvokeContext<States, Events, Emits, StateId>>;
|
|
3099
|
+
}) & {
|
|
3100
|
+
readonly onSnapshot?: InvokeTransition<States, Events, Emits, InvokeSnapshotContext<States, Events, Emits, StateId, Snapshot<Machine.States<ChildDefinition>>, Error<ChildDefinition>, Output<ChildDefinition>>>;
|
|
3101
|
+
} : never : never;
|
|
3102
|
+
type ContextualInvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Raw> = Raw extends ReadonlyArray<any> ? {
|
|
3103
|
+
readonly [Index in keyof Raw]: ContextualInvokeConfig<States, Events, Emits, StateId, Raw[Index]>;
|
|
3104
|
+
} : ContextualInvokeConfig<States, Events, Emits, StateId, Raw>;
|
|
2788
3105
|
type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
2789
3106
|
readonly output: Schema.Top;
|
|
2790
3107
|
} ? {
|
|
@@ -2803,33 +3120,33 @@ export declare namespace Machine {
|
|
|
2803
3120
|
* @category models
|
|
2804
3121
|
* @since 0.4.0
|
|
2805
3122
|
*/
|
|
2806
|
-
type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = {
|
|
2807
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2808
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
3123
|
+
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 []> = {
|
|
3124
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
3125
|
+
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2809
3126
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
|
|
2810
|
-
readonly always?: ((context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
3127
|
+
readonly always?: ((context: AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2811
3128
|
/** Statically declared upper bound of possible target paths. */
|
|
2812
3129
|
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2813
|
-
readonly transition: (context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
3130
|
+
readonly transition: (context: AlwaysContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2814
3131
|
};
|
|
2815
|
-
readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
3132
|
+
readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2816
3133
|
/** Statically declared upper bound of possible target paths. */
|
|
2817
3134
|
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2818
|
-
readonly transition: (context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
3135
|
+
readonly transition: (context: DoneContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2819
3136
|
};
|
|
2820
3137
|
readonly on?: {
|
|
2821
|
-
readonly [EventTag in TagOf<Events[number]>]?: ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
3138
|
+
readonly [EventTag in TagOf<Events[number]>]?: ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2822
3139
|
readonly reenter?: boolean;
|
|
2823
3140
|
/**
|
|
2824
3141
|
* Upper bound of state or history paths this handler may target.
|
|
2825
|
-
* Returning `
|
|
3142
|
+
* Returning `target.none()` is always permitted. Declaring a parent state also
|
|
2826
3143
|
* permits concrete descendant targets below it.
|
|
2827
3144
|
*/
|
|
2828
3145
|
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2829
|
-
readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
3146
|
+
readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2830
3147
|
};
|
|
2831
3148
|
};
|
|
2832
|
-
readonly initial?: StateInitialHandler<States, Events, Emits, StateId>;
|
|
3149
|
+
readonly initial?: StateInitialHandler<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
2833
3150
|
} & ActiveOutputHandlerConfig<States, Events, StateId>;
|
|
2834
3151
|
/** Values supplied when a statechart implicitly enters a state's initial children. */
|
|
2835
3152
|
type StateInitialValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
@@ -2842,14 +3159,14 @@ export declare namespace Machine {
|
|
|
2842
3159
|
readonly initial: infer Initial;
|
|
2843
3160
|
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]> extends never ? never : NodeValue<Children[Initial]> : never : never : never;
|
|
2844
3161
|
/** Context passed to an implicit child-state initializer. */
|
|
2845
|
-
type StateInitialContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States
|
|
3162
|
+
type StateInitialContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>;
|
|
2846
3163
|
/** Initial child value implementation for a compound or parallel state. */
|
|
2847
|
-
type StateInitialHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States
|
|
3164
|
+
type StateInitialHandler<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: StateInitialContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateInitialValue<States, StateId>;
|
|
2848
3165
|
/** Context used only when a history node has no previously captured record. */
|
|
2849
3166
|
interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
2850
3167
|
readonly event: LifecycleEvent<Events>;
|
|
2851
3168
|
readonly target: HistoryDefaultTargetBuilder<States, ParentId>;
|
|
2852
|
-
readonly
|
|
3169
|
+
readonly owner: ParentId;
|
|
2853
3170
|
}
|
|
2854
3171
|
/**
|
|
2855
3172
|
* Typed fallback evaluated when a history node has no record yet.
|
|
@@ -2866,11 +3183,11 @@ export declare namespace Machine {
|
|
|
2866
3183
|
};
|
|
2867
3184
|
};
|
|
2868
3185
|
/** Required implementation for a choice pseudo-state. */
|
|
2869
|
-
interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States
|
|
3186
|
+
interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
2870
3187
|
readonly choice: {
|
|
2871
3188
|
/** Statically inspectable upper bound of every possible target. */
|
|
2872
3189
|
readonly targets: readonly [StateNodeIdentifier<States>, ...ReadonlyArray<StateNodeIdentifier<States>>];
|
|
2873
|
-
readonly transition: (context: ChoiceContext<States, Events, Emits, ChoiceId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => ChoiceResult<States, any, any>;
|
|
3190
|
+
readonly transition: (context: ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => ChoiceResult<States, any, any>;
|
|
2874
3191
|
};
|
|
2875
3192
|
readonly entry?: never;
|
|
2876
3193
|
readonly exit?: never;
|
|
@@ -2887,8 +3204,8 @@ export declare namespace Machine {
|
|
|
2887
3204
|
* @category models
|
|
2888
3205
|
* @since 0.4.0
|
|
2889
3206
|
*/
|
|
2890
|
-
type FinalStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States
|
|
2891
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
3207
|
+
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 []> = {
|
|
3208
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId, InputEvents, ParentEvents>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2892
3209
|
readonly exit?: never;
|
|
2893
3210
|
readonly always?: never;
|
|
2894
3211
|
readonly onDone?: never;
|
|
@@ -2900,10 +3217,10 @@ export declare namespace Machine {
|
|
|
2900
3217
|
* @category models
|
|
2901
3218
|
* @since 0.4.0
|
|
2902
3219
|
*/
|
|
2903
|
-
type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = NodeByIdentifier<States, StateId> extends {
|
|
3220
|
+
type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = NodeByIdentifier<States, StateId> extends {
|
|
2904
3221
|
readonly type: "final";
|
|
2905
|
-
} ? FinalStateConfig<States, Events, Emits, StateId> : ActiveStateConfig<States, Events, Emits, StateId, E, R>;
|
|
2906
|
-
type HandlerNodeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, E, R
|
|
3222
|
+
} ? FinalStateConfig<States, Events, Emits, StateId, InputEvents, ParentEvents> : ActiveStateConfig<States, Events, Emits, StateId, E, R, InputEvents, ParentEvents>;
|
|
3223
|
+
type HandlerNodeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path, InputEvents, ParentEvents> : Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R, InputEvents, ParentEvents> : never;
|
|
2907
3224
|
type HandlerChildren<Node> = Node extends {
|
|
2908
3225
|
readonly states: infer Children extends StateSchemas;
|
|
2909
3226
|
} ? Children : never;
|
|
@@ -2918,6 +3235,12 @@ export declare namespace Machine {
|
|
|
2918
3235
|
readonly states: infer Children extends StateSchemas;
|
|
2919
3236
|
} ? HandlerNodeByPath<Children, Rest> : never : never : Path extends keyof States ? States[Path] : never;
|
|
2920
3237
|
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;
|
|
3238
|
+
type HandlerInvokeContextAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = StateId extends StateIdentifier<AllStates> ? NodeConfig extends {
|
|
3239
|
+
readonly invoke: infer Invoke;
|
|
3240
|
+
} ? HandlerValidationAtPath<StateId, {
|
|
3241
|
+
readonly invoke: ContextualInvokeDefinition<AllStates, Events, Emits, StateId, Invoke>;
|
|
3242
|
+
}> : unknown : unknown;
|
|
3243
|
+
type HandlerInvokeContexts<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config> = Types.UnionToIntersection<StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerInvokeContextAtPath<AllStates, Events, Emits, Config, StateId> : never : never>;
|
|
2921
3244
|
type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
2922
3245
|
readonly [Key in Head]?: {
|
|
2923
3246
|
readonly states: HandlerValidationAtPath<Rest, Validation>;
|
|
@@ -2925,21 +3248,21 @@ export declare namespace Machine {
|
|
|
2925
3248
|
} : {
|
|
2926
3249
|
readonly [Key in Path]?: Validation;
|
|
2927
3250
|
};
|
|
2928
|
-
type HandlerNode<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, StateId extends StateNodeIdentifier<AllStates>> = HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R> & (StateId extends ChoiceIdentifier<AllStates> ? {
|
|
3251
|
+
type HandlerNode<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>> = HandlerNodeConfig<AllStates, Events, Emits, StateId, E, R, InputEvents, ParentEvents> & (StateId extends ChoiceIdentifier<AllStates> ? {
|
|
2929
3252
|
readonly states?: never;
|
|
2930
3253
|
readonly history?: never;
|
|
2931
3254
|
} : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
2932
3255
|
readonly states?: never;
|
|
2933
3256
|
readonly history?: never;
|
|
2934
3257
|
} : {
|
|
2935
|
-
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, Extract<StateId, StateIdentifier<AllStates>>>;
|
|
3258
|
+
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, InputEvents, ParentEvents, Extract<StateId, StateIdentifier<AllStates>>>;
|
|
2936
3259
|
readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
|
|
2937
3260
|
} : {
|
|
2938
3261
|
readonly states?: never;
|
|
2939
3262
|
readonly history?: never;
|
|
2940
3263
|
});
|
|
2941
|
-
type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, Prefix extends string> = {
|
|
2942
|
-
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
|
|
3264
|
+
type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>, Prefix extends string> = {
|
|
3265
|
+
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, InputEvents, ParentEvents, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
|
|
2943
3266
|
};
|
|
2944
3267
|
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initial" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
2945
3268
|
type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
|
|
@@ -3020,7 +3343,7 @@ export declare namespace Machine {
|
|
|
3020
3343
|
] extends [never] ? unknown : {
|
|
3021
3344
|
readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
3022
3345
|
} : unknown : unknown);
|
|
3023
|
-
type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<AllStates>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = StateId extends ChoiceIdentifier<AllStates> ? HandlerChoiceUnknownConfigKeyValidation<StateId, Config> & HandlerChoiceTargetValidation<StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerOnTargetValidation<StateId, Config> & HandlerDirectTargetValidation<StateId, Config, "always"> & HandlerDirectTargetValidation<StateId, Config, "onDone"> &
|
|
3346
|
+
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> & HandlerChoiceTargetValidation<StateId, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : StateId extends StateIdentifier<AllStates> ? HandlerUnknownConfigKeyValidation<StateId, Config> & HandlerOnKeyValidation<Events, StateId, Config> & HandlerOnTargetValidation<StateId, Config> & HandlerDirectTargetValidation<StateId, Config, "always"> & HandlerDirectTargetValidation<StateId, Config, "onDone"> & HandlerInvokeParentEventsValidation<InputEvents, StateId, Config> & HandlerChildrenValidation<Node, StateId, Config> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : unknown;
|
|
3024
3347
|
type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
|
|
3025
3348
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
|
|
3026
3349
|
};
|
|
@@ -3029,19 +3352,13 @@ export declare namespace Machine {
|
|
|
3029
3352
|
} ? [UndeclaredTransitionTarget<Choice>] extends [never] ? unknown : {
|
|
3030
3353
|
readonly choice: HandlerValidationError<"Choice resolver returns a target not listed in targets", StateId, UndeclaredTransitionTarget<Choice>>;
|
|
3031
3354
|
} : unknown;
|
|
3032
|
-
type
|
|
3033
|
-
readonly invoke: HandlerValidationError<"Invoked child
|
|
3034
|
-
};
|
|
3035
|
-
type HandlerInvokeEmitsValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeEmits<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown : {
|
|
3036
|
-
readonly invoke: HandlerValidationError<"Invoked child emits events not accepted by the parent machine", StateId, Exclude<InvokeEmits<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
3037
|
-
};
|
|
3038
|
-
type HandlerInvokeSnapshotValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : IsAny<InvokeSnapshotEvent<InvokeReturn<Config>>> extends true ? unknown : [Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>] extends [never] ? unknown : {
|
|
3039
|
-
readonly invoke: HandlerValidationError<"Invoked child snapshot mapper must return a machine event or undefined", StateId, Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>>;
|
|
3355
|
+
type HandlerInvokeParentEventsValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown : {
|
|
3356
|
+
readonly invoke: HandlerValidationError<"Invoked child expects parent events not accepted by this machine", StateId, Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
3040
3357
|
};
|
|
3041
3358
|
type HandlerRuntimeValidation<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, Incompatible = IncompatibleRuntime<ConfigServices<HandlerConfigPart<Config>>, EventOf<Events>, EmitOf<Emits>>> = [Incompatible] extends [never] ? unknown : HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>;
|
|
3042
|
-
type HandlerNodeValidationAtPath<AllStates extends StateSchemas, Events 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, Emits, StateId, NodeConfig, AvailableOutputStates> extends infer Validation ? unknown extends Validation ? never : HandlerValidationAtPath<StateId, Validation> : never;
|
|
3043
|
-
type HandlerTreeNodeValidations<AllStates extends StateSchemas, Events 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, Emits, Config, AvailableOutputStates, StateId> : never : never>;
|
|
3044
|
-
type HandlerTreeValidation<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>> = HandlerUnknownStateKeyValidation<AllStates, "", Config> & HandlerTreeNodeValidations<AllStates, Events, Emits, Config, AvailableOutputStates>;
|
|
3359
|
+
type HandlerNodeValidationAtPath<AllStates extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Config, AvailableOutputStates extends StateIdentifier<AllStates>, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : HandlerNodeValidation<AllStates, HandlerNodeByPath<AllStates, StateId>, Events, InputEvents, Emits, StateId, NodeConfig, AvailableOutputStates> extends infer Validation ? unknown extends Validation ? never : HandlerValidationAtPath<StateId, Validation> : never;
|
|
3360
|
+
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>;
|
|
3361
|
+
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>;
|
|
3045
3362
|
type HandlerHasRequiredInitial<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = StateId extends RequiredHistoryInitializers<AllStates> ? "initial" extends keyof Config ? true : false : true;
|
|
3046
3363
|
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
3047
3364
|
readonly states: infer Children extends StateSchemas;
|
|
@@ -3066,15 +3383,15 @@ export declare namespace Machine {
|
|
|
3066
3383
|
readonly outputState: StateId extends StateIdentifier<AllStates> ? HandlerOutputStates<AllStates, StateId, HandlerConfigPart<NodeConfig>> : never;
|
|
3067
3384
|
};
|
|
3068
3385
|
type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId> : never : never;
|
|
3069
|
-
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, HandlerTreeEvidence<AllStates, Config>["stateId"]>, E | HandlerTreeEvidence<AllStates, Config>["error"], ExcludeCompatibleRuntime<R | HandlerTreeEvidence<AllStates, Config>["services"], EventOf<Events>, EmitOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>, InputEvents>;
|
|
3386
|
+
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>, EmitOf<Emits>>, InitialE, InitialR, FinalStates, Output, Emits, OutputStates | Extract<HandlerTreeEvidence<AllStates, Config>["outputState"], StateIdentifier<AllStates>>, InputEvents, ParentEvents>;
|
|
3070
3387
|
/**
|
|
3071
3388
|
* Adds state handlers from a root state object.
|
|
3072
3389
|
*
|
|
3073
3390
|
* @category combinators
|
|
3074
3391
|
* @since 0.4.0
|
|
3075
3392
|
*/
|
|
3076
|
-
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>> {
|
|
3077
|
-
<const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerTreeValidation<States, Events, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, NoInfer<Config>>["outputState"], StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, Config>;
|
|
3393
|
+
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>> {
|
|
3394
|
+
<const Config extends HandlerTree<States, States, Events, Emits, E, R, InputEvents, ParentEvents, "">>(config: Config & HandlerInvokeContexts<States, Events, Emits, NoInfer<Config>> & HandlerTreeValidation<States, Events, InputEvents, Emits, NoInfer<Config>, OutputStates | Extract<HandlerTreeEvidence<States, NoInfer<Config>>["outputState"], StateIdentifier<States>>>): HandleTreeResult<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents, ParentEvents, Config>;
|
|
3078
3395
|
}
|
|
3079
3396
|
/**
|
|
3080
3397
|
* Any state config.
|
|
@@ -3137,7 +3454,7 @@ export declare const isMachine: (u: unknown) => u is Machine.Any;
|
|
|
3137
3454
|
* @category guards
|
|
3138
3455
|
* @since 0.4.0
|
|
3139
3456
|
*/
|
|
3140
|
-
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>;
|
|
3457
|
+
export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, state: Machine.Snapshot<States>) => state is Machine.SnapshotContainingFinal<States, FinalStates>;
|
|
3141
3458
|
/**
|
|
3142
3459
|
* Defines a state tree while preserving literal state paths.
|
|
3143
3460
|
*
|
|
@@ -3166,7 +3483,7 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
3166
3483
|
*
|
|
3167
3484
|
* Machine.make({
|
|
3168
3485
|
* states: States.states,
|
|
3169
|
-
* events:
|
|
3486
|
+
* events: Machine.events(),
|
|
3170
3487
|
* initial: () => States.initial.idle.from()
|
|
3171
3488
|
* })
|
|
3172
3489
|
* ```
|
|
@@ -3175,19 +3492,20 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
3175
3492
|
* @since 0.4.0
|
|
3176
3493
|
*/
|
|
3177
3494
|
export declare const defineStates: DefineStates;
|
|
3178
|
-
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>> = {
|
|
3495
|
+
type MakeConfig<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> = {
|
|
3179
3496
|
readonly id?: string;
|
|
3180
3497
|
readonly states: States & DefineStateTreeInput<NoInfer<States>>;
|
|
3181
|
-
readonly events: InputEvents & ValidateInputEventProtocol<NoInfer<InputEvents>>;
|
|
3182
|
-
readonly internalEvents?: InternalEvents & ValidateInternalEventProtocol<NoInfer<InputEvents>, NoInfer<InternalEvents>>;
|
|
3183
|
-
readonly
|
|
3498
|
+
readonly events: Machine.EventProtocol<"public", InputEvents> & ValidateInputEventProtocol<NoInfer<InputEvents>>;
|
|
3499
|
+
readonly internalEvents?: Machine.EventProtocol<"internal", InternalEvents> & ValidateInternalEventProtocol<NoInfer<InputEvents>, NoInfer<InternalEvents>>;
|
|
3500
|
+
readonly emittedEvents?: Machine.EventProtocol<"emitted", Emits>;
|
|
3501
|
+
readonly parentEvents?: Machine.EventProtocol<"public", ParentEvents>;
|
|
3184
3502
|
readonly input?: Input;
|
|
3185
3503
|
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
|
|
3186
3504
|
};
|
|
3187
|
-
type MakeResult<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>> = Machine<States, readonly [...InputEvents, ...InternalEvents], Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, Machine.FinalStateFromDefinition<States>, Machine.TerminalOutput<States>, Emits, never, InputEvents>;
|
|
3505
|
+
type MakeResult<States extends Machine.StateSchemas, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentEvents extends ReadonlyArray<Machine.TaggedSchema>> = Machine<States, readonly [...InputEvents, ...InternalEvents], Input, Machine.StateIdentifier<States>, never, never, InitialE, InitialR, Machine.FinalStateFromDefinition<States>, Machine.TerminalOutput<States>, Emits, never, InputEvents, ParentEvents>;
|
|
3188
3506
|
interface Make {
|
|
3189
|
-
<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: MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>, ..._validation: ValidateDefinedStates<NoInfer<States>>): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>;
|
|
3190
|
-
<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: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents>, "states"> & {
|
|
3507
|
+
<const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>, ..._validation: ValidateDefinedStates<NoInfer<States>>): MakeResult<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>;
|
|
3508
|
+
<const States extends Machine.StateSchemas, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(config: Omit<MakeConfig<States, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentEvents>, "states"> & {
|
|
3191
3509
|
readonly states: InvalidDefinedStateTreeInput<States>;
|
|
3192
3510
|
}): never;
|
|
3193
3511
|
}
|
|
@@ -3202,10 +3520,13 @@ interface Make {
|
|
|
3202
3520
|
* `defineStates` or is passed inline. Call `handle` on the returned definition
|
|
3203
3521
|
* to implement state behavior with ordinary TypeScript control flow.
|
|
3204
3522
|
*
|
|
3205
|
-
*
|
|
3206
|
-
*
|
|
3207
|
-
*
|
|
3208
|
-
*
|
|
3523
|
+
* `Machine.events` defines the public input protocol. `Machine.internalEvents`
|
|
3524
|
+
* adds raised events and other machine-local deliveries.
|
|
3525
|
+
* `Machine.emittedEvents` defines outward ephemeral notifications, while
|
|
3526
|
+
* `parentEvents` declares the inputs a child may explicitly send to its owning
|
|
3527
|
+
* actor. All descriptors expose deferred constructors while retaining their
|
|
3528
|
+
* schemas opaquely for runtime validation. Public and internal tags must be
|
|
3529
|
+
* disjoint.
|
|
3209
3530
|
*
|
|
3210
3531
|
* **Example** (Typed counter machine)
|
|
3211
3532
|
*
|
|
@@ -3222,10 +3543,11 @@ interface Make {
|
|
|
3222
3543
|
* }) {}
|
|
3223
3544
|
*
|
|
3224
3545
|
* const States = Machine.defineStates({ Count })
|
|
3546
|
+
* const Events = Machine.events(Increment)
|
|
3225
3547
|
*
|
|
3226
3548
|
* const counter = Machine.make({
|
|
3227
3549
|
* states: States.states,
|
|
3228
|
-
* events:
|
|
3550
|
+
* events: Events,
|
|
3229
3551
|
* initial: () => States.initial.Count(new Count({ value: 0 }))
|
|
3230
3552
|
* }).handle({
|
|
3231
3553
|
* Count: {
|
|
@@ -3242,49 +3564,75 @@ interface Make {
|
|
|
3242
3564
|
* @since 0.4.0
|
|
3243
3565
|
*/
|
|
3244
3566
|
export declare const make: Make;
|
|
3245
|
-
type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends EventSchema["~type.make.in"] ? [
|
|
3246
|
-
input?: EventSchema["~type.make.in"]
|
|
3247
|
-
] : [input: EventSchema["~type.make.in"]];
|
|
3248
3567
|
/**
|
|
3249
|
-
*
|
|
3568
|
+
* Extracts the decoded event union carried by an event protocol descriptor.
|
|
3250
3569
|
*
|
|
3251
|
-
*
|
|
3252
|
-
*
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
*
|
|
3257
|
-
*
|
|
3258
|
-
* Treat the returned event as immutable after construction.
|
|
3570
|
+
* @category utility types
|
|
3571
|
+
* @since 0.10.0
|
|
3572
|
+
*/
|
|
3573
|
+
export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventOf<Machine.EventProtocolSchemas<Protocol>>;
|
|
3574
|
+
/**
|
|
3575
|
+
* Defines a public event protocol and returns deferred constructors for every
|
|
3576
|
+
* statically finite configured event tag.
|
|
3259
3577
|
*
|
|
3260
|
-
*
|
|
3261
|
-
*
|
|
3578
|
+
* Constructor inputs retain their schema-derived required fields, defaults,
|
|
3579
|
+
* and transformations. Construction is deferred until delivery so failures
|
|
3580
|
+
* enter the machine's `MachineSchemaDecodeError` channel rather than throwing
|
|
3581
|
+
* at the call site.
|
|
3262
3582
|
*
|
|
3263
3583
|
* **Example**
|
|
3264
3584
|
*
|
|
3265
3585
|
* ```ts
|
|
3266
|
-
*
|
|
3267
|
-
*
|
|
3586
|
+
* const Events = Machine.events(Increment, Reset)
|
|
3587
|
+
* const machine = Machine.make({ events: Events, ... })
|
|
3588
|
+
* yield* ref.send(Events.Increment({ by: 1 }))
|
|
3589
|
+
* ```
|
|
3268
3590
|
*
|
|
3269
|
-
*
|
|
3270
|
-
*
|
|
3271
|
-
|
|
3272
|
-
|
|
3591
|
+
* @category constructors
|
|
3592
|
+
* @since 0.10.0
|
|
3593
|
+
*/
|
|
3594
|
+
export declare const events: {
|
|
3595
|
+
<const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(...schemas: Schemas & ValidateInputEventProtocol<NoInfer<Schemas>>): Machine.EventProtocol<"public", readonly [...Schemas]>;
|
|
3596
|
+
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"public">>>(...inputs: Inputs & ValidateEventProtocolBuilder<"public", Inputs>): Machine.EventProtocol<"public", Machine.EventProtocolInputSchemasOf<"public", Inputs>>;
|
|
3597
|
+
};
|
|
3598
|
+
/**
|
|
3599
|
+
* Defines an internal event protocol and returns deferred constructors for
|
|
3600
|
+
* every statically finite configured event tag.
|
|
3273
3601
|
*
|
|
3274
|
-
*
|
|
3275
|
-
*
|
|
3276
|
-
*
|
|
3277
|
-
*
|
|
3278
|
-
*
|
|
3279
|
-
*
|
|
3602
|
+
* Use these constructors for raised events and other machine-local deliveries.
|
|
3603
|
+
* Construction failures are reported through the
|
|
3604
|
+
* owning machine's `MachineSchemaDecodeError` channel.
|
|
3605
|
+
*
|
|
3606
|
+
* **Example**
|
|
3607
|
+
*
|
|
3608
|
+
* ```ts
|
|
3609
|
+
* const InternalEvents = Machine.internalEvents(Loaded, Failed)
|
|
3610
|
+
* const machine = Machine.make({ internalEvents: InternalEvents, ... })
|
|
3280
3611
|
*
|
|
3281
|
-
*
|
|
3612
|
+
* // Inside a transition callback:
|
|
3613
|
+
* enqueue.raise(InternalEvents.Loaded({ value }))
|
|
3282
3614
|
* ```
|
|
3283
3615
|
*
|
|
3284
3616
|
* @category constructors
|
|
3285
|
-
* @since 0.
|
|
3617
|
+
* @since 0.10.0
|
|
3618
|
+
*/
|
|
3619
|
+
export declare const internalEvents: {
|
|
3620
|
+
<const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(...schemas: Schemas & ValidateInternalEventProtocol<readonly [], NoInfer<Schemas>>): Machine.EventProtocol<"internal", readonly [...Schemas]>;
|
|
3621
|
+
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"internal">>>(...inputs: Inputs & ValidateEventProtocolBuilder<"internal", Inputs>): Machine.EventProtocol<"internal", Machine.EventProtocolInputSchemasOf<"internal", Inputs>>;
|
|
3622
|
+
};
|
|
3623
|
+
/**
|
|
3624
|
+
* Defines the ephemeral notifications a machine may publish to external
|
|
3625
|
+
* observers. Emitted events are separate from actor input and are never sent
|
|
3626
|
+
* implicitly to a parent actor. Observe them through `MachineRef.emissions` or
|
|
3627
|
+
* the AtomMachine emission stream adapters.
|
|
3628
|
+
*
|
|
3629
|
+
* @category constructors
|
|
3630
|
+
* @since 0.10.0
|
|
3286
3631
|
*/
|
|
3287
|
-
export declare const
|
|
3632
|
+
export declare const emittedEvents: {
|
|
3633
|
+
<const Schemas extends ReadonlyArray<Machine.TaggedSchema>>(...schemas: Schemas & ValidateEmittedEventProtocol<NoInfer<Schemas>>): Machine.EventProtocol<"emitted", readonly [...Schemas]>;
|
|
3634
|
+
<const Inputs extends ReadonlyArray<Machine.EventProtocolInput<"emitted">>>(...inputs: Inputs & ValidateEventProtocolBuilder<"emitted", Inputs>): Machine.EventProtocol<"emitted", Machine.EventProtocolInputSchemasOf<"emitted", Inputs>>;
|
|
3635
|
+
};
|
|
3288
3636
|
/**
|
|
3289
3637
|
* Encodes a decoded machine snapshot into a normalized data representation.
|
|
3290
3638
|
*
|
|
@@ -3318,7 +3666,7 @@ export declare const event: <const M extends Machine.Any, const EventSchema exte
|
|
|
3318
3666
|
* const States = Machine.defineStates({ Idle })
|
|
3319
3667
|
* const machine = Machine.make({
|
|
3320
3668
|
* states: States.states,
|
|
3321
|
-
* events:
|
|
3669
|
+
* events: Machine.events(),
|
|
3322
3670
|
* initial: () => States.initial.Idle.from()
|
|
3323
3671
|
* }).handle({ Idle: {} })
|
|
3324
3672
|
*
|
|
@@ -3332,7 +3680,7 @@ export declare const event: <const M extends Machine.Any, const EventSchema exte
|
|
|
3332
3680
|
* @category encoding
|
|
3333
3681
|
* @since 0.4.0
|
|
3334
3682
|
*/
|
|
3335
|
-
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>>;
|
|
3683
|
+
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, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, snapshot: Machine.Snapshot<States>) => Effect.Effect<Machine.EncodedSnapshot, MachineSchemaEncodeError, Machine.SnapshotEncodingServices<States>>;
|
|
3336
3684
|
/**
|
|
3337
3685
|
* Decodes a normalized data representation into a validated machine snapshot.
|
|
3338
3686
|
*
|
|
@@ -3362,7 +3710,7 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
3362
3710
|
* const States = Machine.defineStates({ Idle })
|
|
3363
3711
|
* const machine = Machine.make({
|
|
3364
3712
|
* states: States.states,
|
|
3365
|
-
* events:
|
|
3713
|
+
* events: Machine.events(),
|
|
3366
3714
|
* initial: () => States.initial.Idle.from()
|
|
3367
3715
|
* }).handle({ Idle: {} })
|
|
3368
3716
|
*
|
|
@@ -3377,207 +3725,81 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
3377
3725
|
* @category decoding
|
|
3378
3726
|
* @since 0.4.0
|
|
3379
3727
|
*/
|
|
3380
|
-
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>>;
|
|
3381
|
-
|
|
3382
|
-
* Creates an invoked child process configuration for an active state.
|
|
3383
|
-
*
|
|
3384
|
-
* **When to use**
|
|
3385
|
-
*
|
|
3386
|
-
* Use to run a child process while a machine remains in a state. Successful
|
|
3387
|
-
* outputs are sent directly to the parent machine as events; `void` sends
|
|
3388
|
-
* nothing. Unrecovered child failures fail the owning machine. Active
|
|
3389
|
-
* snapshots can optionally be mapped to progress events.
|
|
3390
|
-
*
|
|
3391
|
-
* **Gotchas**
|
|
3392
|
-
*
|
|
3393
|
-
* Invoked child processes run while their owning state is active and are
|
|
3394
|
-
* stopped before the state exits. An unrecovered child failure fails the owning
|
|
3395
|
-
* machine; recover inside the child Effect when failure should become an event.
|
|
3396
|
-
* The `id` is a state-local lifecycle key, not a communication address. To
|
|
3397
|
-
* send events to the invocation, pass a typed `childAddress` as `address`.
|
|
3398
|
-
* The `src` callback is intentionally independent from its parent state. When
|
|
3399
|
-
* construction depends on the typed state, lifecycle event, or runtime, use
|
|
3400
|
-
* the state config factory form `invoke: (context) => Machine.invoke(...)` and
|
|
3401
|
-
* close over that context from `src`.
|
|
3402
|
-
*
|
|
3403
|
-
* **Example** (Effect output as a parent event)
|
|
3404
|
-
*
|
|
3405
|
-
* ```ts
|
|
3406
|
-
* import { Effect, Schema } from "effect"
|
|
3407
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3408
|
-
*
|
|
3409
|
-
* class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
|
|
3410
|
-
* value: Schema.String
|
|
3411
|
-
* }) {}
|
|
3412
|
-
*
|
|
3413
|
-
* const load = Machine.invoke({
|
|
3414
|
-
* id: "load",
|
|
3415
|
-
* src: () => Machine.effect(Effect.succeed(new Loaded({ value: "ready" })))
|
|
3416
|
-
* })
|
|
3417
|
-
* ```
|
|
3418
|
-
*
|
|
3419
|
-
* @see {@link effect} for one-shot child effects.
|
|
3420
|
-
* @see {@link spawn} for children whose lifetime is controlled by actions.
|
|
3421
|
-
* @category constructors
|
|
3422
|
-
* @since 0.4.0
|
|
3423
|
-
*/
|
|
3424
|
-
export declare const invoke: <ChildState, ChildEvent, ChildError = never, ChildRequirements = never, ChildOutput = never, ChildInitialError = never, Event = never, Address extends ChildAddress<never> | undefined = undefined>(config: {
|
|
3728
|
+
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
3729
|
+
type DynamicEffectInvokeSource<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<unknown, unknown, unknown>> = {
|
|
3425
3730
|
readonly id: InvokeLifecycleId;
|
|
3426
|
-
readonly
|
|
3427
|
-
readonly
|
|
3428
|
-
|
|
3731
|
+
readonly effect: Source;
|
|
3732
|
+
readonly after?: never;
|
|
3733
|
+
readonly logic?: never;
|
|
3734
|
+
readonly child?: never;
|
|
3429
3735
|
readonly address?: never;
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
type
|
|
3434
|
-
type
|
|
3435
|
-
type
|
|
3436
|
-
readonly id: InvokeLifecycleId;
|
|
3437
|
-
readonly effect: Fx;
|
|
3438
|
-
readonly onSuccess: (value: NoInfer<Effect.Success<Fx>>) => SuccessEvent | void;
|
|
3439
|
-
} & (InvokeEffectIsInfallible<Fx> extends true ? {
|
|
3440
|
-
readonly onFailure?: never;
|
|
3441
|
-
} : {
|
|
3442
|
-
readonly onFailure: (error: NoInfer<Effect.Error<Fx>>) => FailureEvent | void;
|
|
3443
|
-
});
|
|
3736
|
+
readonly onSnapshot?: never;
|
|
3737
|
+
};
|
|
3738
|
+
type DynamicEffectDoneHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, Machine.InvokeDoneContext<States, Events, Emits, StateId, Effect.Success<ReturnType<NoInfer<Source>>>>>;
|
|
3739
|
+
type DynamicEffectFailureHandler<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeTransition<States, Events, Emits, Machine.InvokeFailureContext<States, Events, Emits, StateId, Effect.Error<ReturnType<NoInfer<Source>>>>>;
|
|
3740
|
+
type DynamicEffectInvokeResult<States extends Machine.StateSchemas, Events extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, Source extends (...args: ReadonlyArray<never>) => Effect.Effect<unknown, unknown, unknown>> = Machine.InvokeConfig<States, Events, Emits, StateId> & Machine.InvokeTyped<Effect.Success<ReturnType<Source>>, Effect.Error<ReturnType<Source>>, Effect.Services<ReturnType<Source>>, never>;
|
|
3741
|
+
type InvokeChannelIsNever<Value> = IsAny<Value> extends true ? false : [Value] extends [never] ? true : false;
|
|
3444
3742
|
/**
|
|
3445
|
-
*
|
|
3743
|
+
* Preserves inference for a state-owned invocation configuration.
|
|
3446
3744
|
*
|
|
3447
|
-
*
|
|
3745
|
+
* Use `effect` for one-shot work, `after` for a cancellable timer, `logic` for
|
|
3746
|
+
* reusable process logic, or `child` for a complete child machine. `onDone` is
|
|
3747
|
+
* required whenever the source can complete with an output, while `onFailure`
|
|
3748
|
+
* is required only when the source has a typed failure channel.
|
|
3448
3749
|
*
|
|
3449
|
-
* This is
|
|
3450
|
-
*
|
|
3451
|
-
*
|
|
3452
|
-
*
|
|
3453
|
-
*
|
|
3454
|
-
*
|
|
3455
|
-
*
|
|
3456
|
-
*
|
|
3457
|
-
* **Example**
|
|
3750
|
+
* This constructor is an identity at runtime, but preserves lifecycle callback
|
|
3751
|
+
* inference through published declarations. Effects and durations may be
|
|
3752
|
+
* supplied directly or derived from the owning state's entry context. Dynamic
|
|
3753
|
+
* Effect sources infer the owner context, output, error, and service channels
|
|
3754
|
+
* together without a return annotation. Logic invocations require both a
|
|
3755
|
+
* lifecycle `id` and a typed communication `address`. Child descriptors already
|
|
3756
|
+
* own their identity, so `id` and `address` must not be repeated.
|
|
3458
3757
|
*
|
|
3459
3758
|
* ```ts
|
|
3460
|
-
*
|
|
3461
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3462
|
-
*
|
|
3463
|
-
* class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
|
|
3464
|
-
* value: Schema.String
|
|
3465
|
-
* }) {}
|
|
3466
|
-
*
|
|
3467
|
-
* const load = Machine.invokeEffect({
|
|
3759
|
+
* invoke: Machine.invoke({
|
|
3468
3760
|
* id: "load",
|
|
3469
|
-
* effect: Effect.
|
|
3470
|
-
*
|
|
3761
|
+
* effect: Effect.tryPromise({
|
|
3762
|
+
* try: () => fetch("/api/data").then((response) => response.json()),
|
|
3763
|
+
* catch: (cause) => new LoadError({ cause })
|
|
3764
|
+
* }),
|
|
3765
|
+
* onDone: ({ output, target }) => target.full.Ready({ data: output }),
|
|
3766
|
+
* onFailure: ({ error, target }) => target.full.Failed({ error })
|
|
3471
3767
|
* })
|
|
3472
3768
|
* ```
|
|
3473
3769
|
*
|
|
3474
|
-
* @see {@link invoke} for arbitrary child process logic.
|
|
3475
|
-
* @see {@link after} for a state-scoped delayed event.
|
|
3476
|
-
* @category constructors
|
|
3477
|
-
* @since 0.4.0
|
|
3478
|
-
*/
|
|
3479
|
-
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)>;
|
|
3480
|
-
/**
|
|
3481
|
-
* Creates a cancellable state-scoped delayed event.
|
|
3482
|
-
*
|
|
3483
|
-
* The timer starts when its owning state is entered and is interrupted when
|
|
3484
|
-
* that state exits. The delayed value should normally be declared in
|
|
3485
|
-
* `internalEvents`.
|
|
3486
|
-
*
|
|
3487
|
-
* **Example**
|
|
3488
|
-
*
|
|
3489
|
-
* ```ts
|
|
3490
|
-
* import { Schema } from "effect"
|
|
3491
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3492
|
-
*
|
|
3493
|
-
* class TimedOut extends Schema.TaggedClass<TimedOut>("TimedOut")("TimedOut", {}) {}
|
|
3494
|
-
*
|
|
3495
|
-
* const timeout = Machine.after("5 seconds", new TimedOut({}))
|
|
3496
|
-
* ```
|
|
3497
|
-
*
|
|
3498
3770
|
* @category constructors
|
|
3499
|
-
* @since 0.
|
|
3500
|
-
*/
|
|
3501
|
-
export declare const after: <Event extends {
|
|
3502
|
-
readonly _tag: PropertyKey;
|
|
3503
|
-
}>(duration: Duration.Input, event: Event, options?: {
|
|
3504
|
-
readonly id?: InvokeLifecycleId;
|
|
3505
|
-
}) => InvokeEffectResult<never, Event>;
|
|
3506
|
-
type RetagFields<Target extends Machine.TaggedSchema> = Omit<Target["~type.make.in"], "_tag">;
|
|
3507
|
-
type RetagTargetCompatibility<Target extends Machine.TaggedSchema> = Target extends {
|
|
3508
|
-
readonly fields: Schema.Struct.Fields;
|
|
3509
|
-
} ? "_tag" extends keyof Target["~type.make.in"] ? {} extends Pick<Target["~type.make.in"], "_tag"> ? unknown : {
|
|
3510
|
-
readonly "~effect/Machine/RetagTargetError": "Target schema must supply its discriminator when make is called";
|
|
3511
|
-
} : unknown : {
|
|
3512
|
-
readonly "~effect/Machine/RetagTargetError": "Target schema must be one tagged struct or tagged class";
|
|
3513
|
-
};
|
|
3514
|
-
type RequiredKeys<A> = {
|
|
3515
|
-
readonly [Key in keyof A]-?: {} extends Pick<A, Key> ? never : Key;
|
|
3516
|
-
}[keyof A];
|
|
3517
|
-
type CompatibleSourceKeys<Fields, Source> = {
|
|
3518
|
-
readonly [Key in Extract<keyof Fields, keyof Source>]: Source[Key] extends Fields[Key] ? Key : never;
|
|
3519
|
-
}[Extract<keyof Fields, keyof Source>];
|
|
3520
|
-
type RetagPatch<Target extends Machine.TaggedSchema, Source> = Partial<RetagFields<Target>> & Pick<RetagFields<Target>, Exclude<RequiredKeys<RetagFields<Target>>, CompatibleSourceKeys<RetagFields<Target>, Source>>>;
|
|
3521
|
-
type RetagArgs<Target extends Machine.TaggedSchema, Source> = [
|
|
3522
|
-
Exclude<RequiredKeys<RetagFields<Target>>, CompatibleSourceKeys<RetagFields<Target>, Source>>
|
|
3523
|
-
] extends [never] ? [patch?: RetagPatch<Target, Source>] : [patch: RetagPatch<Target, Source>];
|
|
3524
|
-
/**
|
|
3525
|
-
* Constructs another tagged case from compatible source fields.
|
|
3526
|
-
*
|
|
3527
|
-
* The target must be one tagged struct or tagged class whose discriminator is
|
|
3528
|
-
* supplied by its constructor. Union wrappers are rejected because their
|
|
3529
|
-
* `make` operation cannot select a member after the source discriminator has
|
|
3530
|
-
* been discarded. Missing or incompatible required target fields must be
|
|
3531
|
-
* supplied by the patch, and the target schema's normal `make` validation
|
|
3532
|
-
* remains authoritative at runtime.
|
|
3533
|
-
*
|
|
3534
|
-
* @category constructors
|
|
3535
|
-
* @since 0.4.0
|
|
3771
|
+
* @since 0.9.0
|
|
3536
3772
|
*/
|
|
3537
|
-
export declare const
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
* **Gotchas**
|
|
3560
|
-
*
|
|
3561
|
-
* Active invoked machines must have unique child addresses. A machine starts
|
|
3562
|
-
* after its owning state's entry actions, so those actions cannot send events
|
|
3563
|
-
* to a newly entered child. Unrecovered child failures fail the parent.
|
|
3564
|
-
*
|
|
3565
|
-
* @see {@link invoke} for invoking lower-level process logic.
|
|
3566
|
-
* @see {@link sendTo} for sending events to the invoked machine.
|
|
3567
|
-
* @category constructors
|
|
3568
|
-
* @since 0.4.0
|
|
3569
|
-
*/
|
|
3570
|
-
export declare const invokeMachine: {
|
|
3571
|
-
<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: {
|
|
3572
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
|
|
3573
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
3574
|
-
readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined;
|
|
3575
|
-
} & 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>;
|
|
3576
|
-
<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: {
|
|
3577
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
|
|
3578
|
-
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
3773
|
+
export declare const invoke: {
|
|
3774
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<unknown, unknown, unknown>>(config: DynamicEffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3775
|
+
readonly onDone: DynamicEffectDoneHandler<States, Events, Emits, StateId, Source>;
|
|
3776
|
+
readonly onFailure: DynamicEffectFailureHandler<States, Events, Emits, StateId, Source>;
|
|
3777
|
+
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
3778
|
+
"onDone must be omitted when the Effect output is never"
|
|
3779
|
+
] : InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
3780
|
+
"onFailure must be omitted when the Effect error is never"
|
|
3781
|
+
] : []): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3782
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<unknown, never, unknown>>(config: DynamicEffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3783
|
+
readonly onDone: DynamicEffectDoneHandler<States, Events, Emits, StateId, Source>;
|
|
3784
|
+
readonly onFailure?: never;
|
|
3785
|
+
}, ..._validation: InvokeChannelIsNever<Effect.Success<ReturnType<Source>>> extends true ? [
|
|
3786
|
+
"onDone must be omitted when the Effect output is never"
|
|
3787
|
+
] : []): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3788
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<never, unknown, unknown>>(config: DynamicEffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3789
|
+
readonly onDone?: never;
|
|
3790
|
+
readonly onFailure: DynamicEffectFailureHandler<States, Events, Emits, StateId, Source>;
|
|
3791
|
+
}, ..._validation: InvokeChannelIsNever<Effect.Error<ReturnType<Source>>> extends true ? [
|
|
3792
|
+
"onFailure must be omitted when the Effect error is never"
|
|
3793
|
+
] : []): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3794
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Source extends (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Effect.Effect<never, never, unknown>>(config: DynamicEffectInvokeSource<States, Events, Emits, StateId, Source> & {
|
|
3579
3795
|
readonly onDone?: never;
|
|
3580
|
-
|
|
3796
|
+
readonly onFailure?: never;
|
|
3797
|
+
}): DynamicEffectInvokeResult<States, Events, Emits, StateId, Source>;
|
|
3798
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Fx extends Effect.Effect<any, any, any>, const Config extends object>(config: Config & Machine.EffectInvokeArgs<States, Events, Emits, StateId, Fx>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Effect.Success<Fx>, Effect.Error<Fx>, Effect.Services<Fx>, never>;
|
|
3799
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Config extends object>(config: Config & Machine.TimerInvokeArgs<States, Events, Emits, StateId>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<void, never, never, never>;
|
|
3800
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>>(config: Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address, (context: Machine.InvokeContext<States, Events, Emits, StateId>) => Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>>): Machine.InvokeConfig<States, Events, Emits, StateId> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
|
|
3801
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address extends ChildAddress<never>, const Config extends object>(config: Config & Machine.LogicInvokeArgs<States, Events, Emits, StateId, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, Address>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<ChildOutput, ChildError, ChildRequirements, ChildInitialError>;
|
|
3802
|
+
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, StateId extends Machine.StateIdentifier<States>, const Child extends ChildMachine.Any, const Config extends object>(config: Config & Machine.ChildInvokeArgs<States, Events, Emits, StateId, Child["machine"], Child>): Config & Machine.InvokeOwned<States, Events, Emits, StateId> & Machine.InvokeTyped<Machine.Output<Child["machine"]>, Machine.Error<Child["machine"]> | ActionError<Machine.Services<Child["machine"]>>, Machine.Services<Child["machine"]>, Machine.InitialError<Child["machine"]>, Machine.Emit<Child["machine"]>, Machine.EventOf<Machine.ParentEvents<Child["machine"]>>>;
|
|
3581
3803
|
};
|
|
3582
3804
|
/**
|
|
3583
3805
|
* Plans the initial state for a machine without executing actor commands.
|
|
@@ -3607,7 +3829,7 @@ export declare const invokeMachine: {
|
|
|
3607
3829
|
* const States = Machine.defineStates({ Idle })
|
|
3608
3830
|
* const machine = Machine.make({
|
|
3609
3831
|
* states: States.states,
|
|
3610
|
-
* events:
|
|
3832
|
+
* events: Machine.events(),
|
|
3611
3833
|
* initial: () => States.initial.Idle.from()
|
|
3612
3834
|
* }).handle({ Idle: {} })
|
|
3613
3835
|
*
|
|
@@ -3619,7 +3841,7 @@ export declare const invokeMachine: {
|
|
|
3619
3841
|
* @category constructors
|
|
3620
3842
|
* @since 0.4.0
|
|
3621
3843
|
*/
|
|
3622
|
-
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> & EnsureExecutable<States, UnhandledStates, OutputStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<{
|
|
3844
|
+
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, 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>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<{
|
|
3623
3845
|
readonly startingState: Machine.Snapshot<States>;
|
|
3624
3846
|
readonly initialEntryPaths: ReadonlyArray<Machine.StateIdentifier<States>>;
|
|
3625
3847
|
readonly state: Machine.Snapshot<States>;
|
|
@@ -3678,10 +3900,9 @@ export declare const transitionDefinitions: <M extends Machine.Any>(machine: M)
|
|
|
3678
3900
|
*
|
|
3679
3901
|
* **Details**
|
|
3680
3902
|
*
|
|
3681
|
-
* Static
|
|
3682
|
-
*
|
|
3683
|
-
*
|
|
3684
|
-
* never evaluated during inspection.
|
|
3903
|
+
* Static inline invocation definitions expose stable ownership and lifecycle
|
|
3904
|
+
* metadata without serializing runtime values. Function-valued sources are
|
|
3905
|
+
* represented as dynamic and are never evaluated during inspection.
|
|
3685
3906
|
*
|
|
3686
3907
|
* @category getters
|
|
3687
3908
|
* @since 0.4.0
|
|
@@ -3706,7 +3927,7 @@ export declare const configuration: <M extends Machine.Any>(machine: M, state: M
|
|
|
3706
3927
|
* @category getters
|
|
3707
3928
|
* @since 0.4.0
|
|
3708
3929
|
*/
|
|
3709
|
-
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]>>;
|
|
3930
|
+
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, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, state: Machine.Snapshot<States>) => ReadonlyArray<Machine.TagOf<Events[number]>>;
|
|
3710
3931
|
/**
|
|
3711
3932
|
* Plans the next state snapshot synchronously.
|
|
3712
3933
|
*
|
|
@@ -3736,7 +3957,7 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
3736
3957
|
* const States = Machine.defineStates({ Off, On })
|
|
3737
3958
|
* const machine = Machine.make({
|
|
3738
3959
|
* states: States.states,
|
|
3739
|
-
* events:
|
|
3960
|
+
* events: Machine.events(Toggle),
|
|
3740
3961
|
* initial: () => States.initial.Off.from()
|
|
3741
3962
|
* }).handle({ Off: { on: { Toggle: () => States.initial.On.from() } }, On: {} })
|
|
3742
3963
|
*
|
|
@@ -3751,7 +3972,7 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
3751
3972
|
* @category combinators
|
|
3752
3973
|
* @since 0.4.0
|
|
3753
3974
|
*/
|
|
3754
|
-
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> & EnsureExecutable<States, UnhandledStates, OutputStates>, state: Machine.Snapshot<States>, event: Machine.
|
|
3975
|
+
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>, state: Machine.Snapshot<States>, event: Machine.EventInputOf<InputEvents>) => Effect.Effect<{
|
|
3755
3976
|
readonly next: Machine.Snapshot<States>;
|
|
3756
3977
|
readonly commands: ReadonlyArray<Command>;
|
|
3757
3978
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
@@ -3773,49 +3994,6 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
3773
3994
|
readonly done: false;
|
|
3774
3995
|
readonly output: undefined;
|
|
3775
3996
|
}), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
|
|
3776
|
-
/**
|
|
3777
|
-
* Creates a one-shot child process from an Effect.
|
|
3778
|
-
*
|
|
3779
|
-
* **When to use**
|
|
3780
|
-
*
|
|
3781
|
-
* Use when you need side effects that produce one typed output or error.
|
|
3782
|
-
*
|
|
3783
|
-
* **Details**
|
|
3784
|
-
*
|
|
3785
|
-
* The Effect may run arbitrary side effects. Its success value is the process
|
|
3786
|
-
* output, its typed error is preserved, and its services are inferred. When
|
|
3787
|
-
* invoked, the output is sent to the owning machine as an event unless it is
|
|
3788
|
-
* `void`.
|
|
3789
|
-
*
|
|
3790
|
-
* **Gotchas**
|
|
3791
|
-
*
|
|
3792
|
-
* This process has no incoming event protocol. Its Effect runs once. Use
|
|
3793
|
-
* `transition` for a process that receives events over time and `logic` for
|
|
3794
|
-
* direct machine-local communication or intermediate snapshots.
|
|
3795
|
-
*
|
|
3796
|
-
* **Example** (Recover a child failure as output)
|
|
3797
|
-
*
|
|
3798
|
-
* ```ts
|
|
3799
|
-
* import { Effect, Schema } from "effect"
|
|
3800
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3801
|
-
*
|
|
3802
|
-
* class LoadFailed extends Schema.TaggedClass<LoadFailed>("LoadFailed")("LoadFailed", {
|
|
3803
|
-
* reason: Schema.String
|
|
3804
|
-
* }) {}
|
|
3805
|
-
*
|
|
3806
|
-
* const load = Machine.effect(
|
|
3807
|
-
* Effect.fail("unavailable").pipe(
|
|
3808
|
-
* Effect.catch((reason) => Effect.succeed(new LoadFailed({ reason })))
|
|
3809
|
-
* )
|
|
3810
|
-
* )
|
|
3811
|
-
* ```
|
|
3812
|
-
*
|
|
3813
|
-
* @see {@link transition} for event-driven state.
|
|
3814
|
-
* @see {@link logic} for direct control over intermediate snapshots.
|
|
3815
|
-
* @category constructors
|
|
3816
|
-
* @since 0.4.0
|
|
3817
|
-
*/
|
|
3818
|
-
export declare const effect: <Output, Error = never, Requirements = never>(effect: Effect.Effect<Output, Error, Requirements>) => Logic<void, never, Error, Requirements, Output>;
|
|
3819
3997
|
/**
|
|
3820
3998
|
* Creates advanced stateful process logic from explicit initialization and
|
|
3821
3999
|
* execution methods.
|
|
@@ -3837,9 +4015,9 @@ export declare const effect: <Output, Error = never, Requirements = never>(effec
|
|
|
3837
4015
|
* This is the low-level process constructor. Parent messages sent directly
|
|
3838
4016
|
* through its scope are intentionally `unknown` because the logic does not know
|
|
3839
4017
|
* which machine will eventually own it. Prefer typed output, typed child
|
|
3840
|
-
* addresses, or
|
|
4018
|
+
* addresses, or invocation lifecycle transitions when possible.
|
|
3841
4019
|
*
|
|
3842
|
-
*
|
|
4020
|
+
* Use an inline `invoke` with an `effect` source for one-shot work.
|
|
3843
4021
|
* @see {@link transition} for event-driven state.
|
|
3844
4022
|
* @category constructors
|
|
3845
4023
|
* @since 0.4.0
|
|
@@ -3873,7 +4051,7 @@ export declare const logic: <State, Event = never, Output = void, Error = never,
|
|
|
3873
4051
|
* )
|
|
3874
4052
|
* ```
|
|
3875
4053
|
*
|
|
3876
|
-
*
|
|
4054
|
+
* Use an inline `invoke` with an `effect` source for one-shot work.
|
|
3877
4055
|
* @see {@link logic} for direct process lifecycle control.
|
|
3878
4056
|
* @category constructors
|
|
3879
4057
|
* @since 0.4.0
|
|
@@ -3981,7 +4159,7 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
3981
4159
|
* const States = Machine.defineStates({ Idle })
|
|
3982
4160
|
* const machine = Machine.make({
|
|
3983
4161
|
* states: States.states,
|
|
3984
|
-
* events:
|
|
4162
|
+
* events: Machine.events(),
|
|
3985
4163
|
* initial: () => States.initial.Idle.from()
|
|
3986
4164
|
* }).handle({ Idle: {} })
|
|
3987
4165
|
*
|
|
@@ -3996,7 +4174,7 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
3996
4174
|
* @category constructors
|
|
3997
4175
|
* @since 0.4.0
|
|
3998
4176
|
*/
|
|
3999
|
-
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> & EnsureExecutable<States, UnhandledStates, OutputStates>, ...args: [...Machine.InputArgs<Input>]) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.
|
|
4177
|
+
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>, ...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.EmitOf<Emits>>>;
|
|
4000
4178
|
/**
|
|
4001
4179
|
* Starts a fresh managed runtime from a decoded logical snapshot.
|
|
4002
4180
|
*
|
|
@@ -4007,8 +4185,8 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
4007
4185
|
* entry or transition actions, re-deliver raised or emitted events, or
|
|
4008
4186
|
* re-evaluate historical completion and eventless transitions. Active-state
|
|
4009
4187
|
* invokes start once in ancestor and document order with {@link InitialEvent};
|
|
4010
|
-
*
|
|
4011
|
-
* from their own initial state.
|
|
4188
|
+
* timer invocations restart their complete duration and child-machine
|
|
4189
|
+
* invocations start from their own initial state.
|
|
4012
4190
|
*
|
|
4013
4191
|
* Only logical state, completion, and history metadata are resumed. Queues,
|
|
4014
4192
|
* scopes, subscriptions, fibers, spawned children, invoke progress, and prior
|
|
@@ -4031,7 +4209,7 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
4031
4209
|
* const States = Machine.defineStates({ Idle })
|
|
4032
4210
|
* const machine = Machine.make({
|
|
4033
4211
|
* states: States.states,
|
|
4034
|
-
* events:
|
|
4212
|
+
* events: Machine.events(),
|
|
4035
4213
|
* initial: () => States.initial.Idle.from()
|
|
4036
4214
|
* }).handle({ Idle: {} })
|
|
4037
4215
|
*
|
|
@@ -4048,5 +4226,5 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
4048
4226
|
* @category constructors
|
|
4049
4227
|
* @since 0.4.0
|
|
4050
4228
|
*/
|
|
4051
|
-
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>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>, snapshot: Machine.Snapshot<States>) => Effect.Effect<MachineRef<Machine.Snapshot<States>, Machine.
|
|
4229
|
+
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>, 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.EmitOf<Emits>>>;
|
|
4052
4230
|
//# sourceMappingURL=Machine.d.ts.map
|