@typeonce/effect-machine 0.2.0 → 0.4.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 +345 -42
- package/dist/Machine.d.ts +1273 -347
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +161 -426
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/activities.d.ts +57 -0
- package/dist/internal/machine/activities.d.ts.map +1 -0
- package/dist/internal/machine/activities.js +49 -0
- package/dist/internal/machine/activities.js.map +1 -0
- package/dist/internal/machine/atom.d.ts +69 -0
- package/dist/internal/machine/atom.d.ts.map +1 -0
- package/dist/{AtomMachine.js → internal/machine/atom.js} +19 -94
- package/dist/internal/machine/atom.js.map +1 -0
- package/dist/internal/machine/cluster.d.ts +63 -0
- package/dist/internal/machine/cluster.d.ts.map +1 -0
- package/dist/{ClusterMachine.js → internal/machine/cluster.js} +15 -119
- package/dist/internal/machine/cluster.js.map +1 -0
- package/dist/internal/machine/command.d.ts +16 -0
- package/dist/internal/machine/command.d.ts.map +1 -0
- package/dist/internal/machine/command.js +45 -0
- package/dist/internal/machine/command.js.map +1 -0
- package/dist/internal/machine/commandRuntime.d.ts +13 -0
- package/dist/internal/machine/commandRuntime.d.ts.map +1 -0
- package/dist/internal/machine/commandRuntime.js +16 -0
- package/dist/internal/machine/commandRuntime.js.map +1 -0
- package/dist/internal/{machineModel.d.ts → machine/configuration.d.ts} +32 -38
- package/dist/internal/machine/configuration.d.ts.map +1 -0
- package/dist/internal/machine/configuration.js +965 -0
- package/dist/internal/machine/configuration.js.map +1 -0
- package/dist/internal/{machineErrors.d.ts → machine/errors.d.ts} +3 -3
- package/dist/internal/machine/errors.d.ts.map +1 -0
- package/dist/internal/{machineErrors.js → machine/errors.js} +1 -1
- package/dist/internal/machine/errors.js.map +1 -0
- package/dist/internal/machine/executionPlan.d.ts +49 -0
- package/dist/internal/machine/executionPlan.d.ts.map +1 -0
- package/dist/internal/machine/executionPlan.js +667 -0
- package/dist/internal/machine/executionPlan.js.map +1 -0
- package/dist/internal/machine/invocation.d.ts +23 -0
- package/dist/internal/machine/invocation.d.ts.map +1 -0
- package/dist/internal/machine/invocation.js +77 -0
- package/dist/internal/machine/invocation.js.map +1 -0
- package/dist/internal/machine/machine.d.ts +183 -0
- package/dist/internal/machine/machine.d.ts.map +1 -0
- package/dist/internal/machine/machine.js +552 -0
- package/dist/internal/machine/machine.js.map +1 -0
- package/dist/internal/machine/planner.d.ts +182 -0
- package/dist/internal/machine/planner.d.ts.map +1 -0
- package/dist/internal/machine/planner.js +1082 -0
- package/dist/internal/machine/planner.js.map +1 -0
- package/dist/internal/{machineProcess.d.ts → machine/process.d.ts} +10 -4
- package/dist/internal/machine/process.d.ts.map +1 -0
- package/dist/internal/machine/process.js +446 -0
- package/dist/internal/machine/process.js.map +1 -0
- package/dist/internal/machine/protocol.d.ts +34 -0
- package/dist/internal/machine/protocol.d.ts.map +1 -0
- package/dist/internal/machine/protocol.js +182 -0
- package/dist/internal/machine/protocol.js.map +1 -0
- package/dist/internal/machine/readiness.d.ts +4 -0
- package/dist/internal/machine/readiness.d.ts.map +1 -0
- package/dist/internal/machine/readiness.js +2 -0
- package/dist/internal/machine/readiness.js.map +1 -0
- package/dist/internal/{machineRuntime.d.ts → machine/runtime.d.ts} +104 -2
- package/dist/internal/machine/runtime.d.ts.map +1 -0
- package/dist/internal/machine/runtime.js +1381 -0
- package/dist/internal/machine/runtime.js.map +1 -0
- package/dist/internal/machine/serialization.d.ts +14 -0
- package/dist/internal/machine/serialization.d.ts.map +1 -0
- package/dist/internal/machine/serialization.js +338 -0
- package/dist/internal/machine/serialization.js.map +1 -0
- package/dist/internal/machine/stateDefinition.d.ts +15 -0
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -0
- package/dist/internal/machine/stateDefinition.js +210 -0
- package/dist/internal/machine/stateDefinition.js.map +1 -0
- package/dist/internal/machine/symbols.d.ts +3 -0
- package/dist/internal/machine/symbols.d.ts.map +1 -0
- package/dist/internal/machine/symbols.js +3 -0
- package/dist/internal/machine/symbols.js.map +1 -0
- package/dist/internal/machine/topology.d.ts +98 -0
- package/dist/internal/machine/topology.d.ts.map +1 -0
- package/dist/internal/machine/topology.js +347 -0
- package/dist/internal/machine/topology.js.map +1 -0
- package/dist/internal/testing/machine/arbitrary.d.ts +36 -0
- package/dist/internal/testing/machine/arbitrary.d.ts.map +1 -0
- package/dist/internal/testing/machine/arbitrary.js +68 -0
- package/dist/internal/testing/machine/arbitrary.js.map +1 -0
- package/dist/internal/testing/machine/finiteModel.d.ts +322 -0
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -0
- package/dist/internal/testing/machine/finiteModel.js +976 -0
- package/dist/internal/testing/machine/finiteModel.js.map +1 -0
- package/dist/internal/testing/machine/referenceModel.d.ts +203 -0
- package/dist/internal/testing/machine/referenceModel.d.ts.map +1 -0
- package/dist/internal/testing/machine/referenceModel.js +1012 -0
- package/dist/internal/testing/machine/referenceModel.js.map +1 -0
- package/dist/internal/testing/machine/runtime.d.ts +328 -0
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -0
- package/dist/internal/testing/machine/runtime.js +437 -0
- package/dist/internal/testing/machine/runtime.js.map +1 -0
- package/dist/internal/testing/machine/verification.d.ts +33 -0
- package/dist/internal/testing/machine/verification.d.ts.map +1 -0
- package/dist/internal/testing/machine/verification.js +1446 -0
- package/dist/internal/testing/machine/verification.js.map +1 -0
- package/dist/testing/MachineTest.d.ts +606 -0
- package/dist/testing/MachineTest.d.ts.map +1 -0
- package/dist/testing/MachineTest.js +102 -0
- package/dist/testing/MachineTest.js.map +1 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +7 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/{ClusterMachine.d.ts → unstable/cluster/ClusterMachine.d.ts} +22 -30
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -0
- package/dist/unstable/cluster/ClusterMachine.js +126 -0
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -0
- package/dist/{cluster.js → unstable/cluster/index.d.ts} +1 -1
- package/dist/unstable/cluster/index.d.ts.map +1 -0
- package/dist/{cluster.d.ts → unstable/cluster/index.js} +1 -1
- package/dist/unstable/cluster/index.js.map +1 -0
- package/dist/{AtomMachine.d.ts → unstable/reactivity/AtomMachine.d.ts} +40 -23
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -0
- package/dist/unstable/reactivity/AtomMachine.js +113 -0
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -0
- package/dist/{reactivity.js → unstable/reactivity/index.d.ts} +1 -1
- package/dist/unstable/reactivity/index.d.ts.map +1 -0
- package/dist/{reactivity.d.ts → unstable/reactivity/index.js} +1 -1
- package/dist/unstable/reactivity/index.js.map +1 -0
- package/docs/agent-guide.md +271 -38
- package/package.json +23 -13
- package/dist/AtomMachine.d.ts.map +0 -1
- package/dist/AtomMachine.js.map +0 -1
- package/dist/ClusterMachine.d.ts.map +0 -1
- package/dist/ClusterMachine.js.map +0 -1
- package/dist/cluster.d.ts.map +0 -1
- package/dist/cluster.js.map +0 -1
- package/dist/internal/machineErrors.d.ts.map +0 -1
- package/dist/internal/machineErrors.js.map +0 -1
- package/dist/internal/machineModel.d.ts.map +0 -1
- package/dist/internal/machineModel.js +0 -766
- package/dist/internal/machineModel.js.map +0 -1
- package/dist/internal/machinePlanner.d.ts +0 -74
- package/dist/internal/machinePlanner.d.ts.map +0 -1
- package/dist/internal/machinePlanner.js +0 -621
- package/dist/internal/machinePlanner.js.map +0 -1
- package/dist/internal/machineProcess.d.ts.map +0 -1
- package/dist/internal/machineProcess.js +0 -181
- package/dist/internal/machineProcess.js.map +0 -1
- package/dist/internal/machineRuntime.d.ts.map +0 -1
- package/dist/internal/machineRuntime.js +0 -365
- package/dist/internal/machineRuntime.js.map +0 -1
- package/dist/reactivity.d.ts.map +0 -1
- package/dist/reactivity.js.map +0 -1
package/dist/Machine.d.ts
CHANGED
|
@@ -5,17 +5,21 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type * as Cause from "effect/Cause";
|
|
7
7
|
import type * as Duration from "effect/Duration";
|
|
8
|
-
import * as Effect from "effect/Effect";
|
|
9
|
-
import * as Option from "effect/Option";
|
|
10
|
-
import {
|
|
8
|
+
import type * as Effect from "effect/Effect";
|
|
9
|
+
import type * as Option from "effect/Option";
|
|
10
|
+
import type { Pipeable } from "effect/Pipeable";
|
|
11
11
|
import type * as Schema from "effect/Schema";
|
|
12
12
|
import type * as Scope from "effect/Scope";
|
|
13
13
|
import type * as Stream from "effect/Stream";
|
|
14
14
|
import type * as Types from "effect/Types";
|
|
15
|
-
import type
|
|
16
|
-
import
|
|
17
|
-
import * as
|
|
18
|
-
import
|
|
15
|
+
import type * as Activities from "./internal/machine/activities.js";
|
|
16
|
+
import type { ChildAlreadyExistsError, InfiniteTransitionError, MachineSchemaDecodeError, MachineSchemaEncodeError, StartupError, StoppedError } from "./internal/machine/machine.js";
|
|
17
|
+
import * as internal from "./internal/machine/machine.js";
|
|
18
|
+
import { InitialEventTypeId } from "./internal/machine/machine.js";
|
|
19
|
+
import type { EnsureExecutable } from "./internal/machine/readiness.js";
|
|
20
|
+
import type * as internalRuntime from "./internal/machine/runtime.js";
|
|
21
|
+
import type * as StateDefinition from "./internal/machine/stateDefinition.js";
|
|
22
|
+
import type * as Topology from "./internal/machine/topology.js";
|
|
19
23
|
/**
|
|
20
24
|
* String literal type used as the runtime type identifier for `Machine`
|
|
21
25
|
* values.
|
|
@@ -32,6 +36,7 @@ export type TypeId = "~effect/Machine";
|
|
|
32
36
|
*/
|
|
33
37
|
export declare const TypeId: TypeId;
|
|
34
38
|
declare const MachineOutputStatesTypeId: unique symbol;
|
|
39
|
+
declare const MachineTypeId: unique symbol;
|
|
35
40
|
/**
|
|
36
41
|
* Type identifier used for the synthetic event passed to startup lifecycle
|
|
37
42
|
* actions.
|
|
@@ -39,7 +44,7 @@ declare const MachineOutputStatesTypeId: unique symbol;
|
|
|
39
44
|
* @category type IDs
|
|
40
45
|
* @since 4.0.0
|
|
41
46
|
*/
|
|
42
|
-
export
|
|
47
|
+
export { InitialEventTypeId };
|
|
43
48
|
/**
|
|
44
49
|
* Synthetic event passed to entry, exit, always, invoke, and output callbacks
|
|
45
50
|
* that run while the machine is settling its initial state.
|
|
@@ -78,16 +83,17 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
78
83
|
*
|
|
79
84
|
* **Gotchas**
|
|
80
85
|
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* delayed events.
|
|
86
|
+
* Declarative first-class guards are not part of the current API. Conditional
|
|
87
|
+
* behavior can be expressed in typed handlers with ordinary TypeScript control
|
|
88
|
+
* flow. Use `after` for cancellable state-scoped delayed events.
|
|
85
89
|
*
|
|
86
90
|
* @category models
|
|
87
91
|
* @since 4.0.0
|
|
88
92
|
*/
|
|
89
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 {
|
|
90
94
|
readonly [TypeId]: TypeId;
|
|
95
|
+
/** @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>;
|
|
91
97
|
/** @internal Prevents output implementation evidence from being widened. */
|
|
92
98
|
readonly [MachineOutputStatesTypeId]: Readonly<Record<OutputStates, true>>;
|
|
93
99
|
/**
|
|
@@ -129,13 +135,16 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
129
135
|
/** @internal */
|
|
130
136
|
readonly stateNodes: Machine.StateNodes;
|
|
131
137
|
/** @internal */
|
|
132
|
-
readonly makeTargetBuilder: <Source extends Machine.
|
|
138
|
+
readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
|
|
133
139
|
/** @internal */
|
|
134
140
|
readonly handlers: Machine.StateConfigs<States, Events, Emits, UnhandledStates, Machine.TagOf<Events[number]>, E, R>;
|
|
135
141
|
/**
|
|
136
142
|
* Adds typed state handlers and returns the refined machine definition.
|
|
137
143
|
* Successive calls implement the remaining unhandled states while retaining
|
|
138
144
|
* accumulated errors, services, final states, and output evidence.
|
|
145
|
+
* Event dispatch maps and transition descriptors are captured by value, so
|
|
146
|
+
* later mutation of the objects supplied to this call cannot alter the
|
|
147
|
+
* resulting machine.
|
|
139
148
|
*
|
|
140
149
|
* @since 4.0.0
|
|
141
150
|
*/
|
|
@@ -199,7 +208,7 @@ StartupError,
|
|
|
199
208
|
* @category errors
|
|
200
209
|
* @since 4.0.0
|
|
201
210
|
*/
|
|
202
|
-
StoppedError } from "./internal/
|
|
211
|
+
StoppedError } from "./internal/machine/machine.js";
|
|
203
212
|
declare const RuntimeRequirementTypeId = "~effect/Machine/RuntimeRequirement";
|
|
204
213
|
declare const ActionRequirementTypeId = "~effect/Machine/ActionRequirement";
|
|
205
214
|
type MachineRuntimeRequirement = internalRuntime.MachineRuntime;
|
|
@@ -245,7 +254,7 @@ export type PlanningServices<Requirements> = Exclude<Requirements, ActionRequire
|
|
|
245
254
|
*/
|
|
246
255
|
export type ExecutionServices<Requirements> = Exclude<PlanningServices<Requirements>, MachineRuntimeRequirement> | Exclude<ActionServices<Requirements>, MachineRuntimeRequirement>;
|
|
247
256
|
/**
|
|
248
|
-
*
|
|
257
|
+
* Managed runtime capability used to deliver raised and emitted events.
|
|
249
258
|
*
|
|
250
259
|
* @category models
|
|
251
260
|
* @since 4.0.0
|
|
@@ -264,6 +273,39 @@ export interface Runtime<in Events, in Emits> {
|
|
|
264
273
|
*/
|
|
265
274
|
readonly sendParent: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
266
275
|
}
|
|
276
|
+
/**
|
|
277
|
+
* Synchronous commands available while a machine transition is being
|
|
278
|
+
* selected. Enqueuing only records statechart and actor operations; it never
|
|
279
|
+
* executes an Effect.
|
|
280
|
+
*
|
|
281
|
+
* @category models
|
|
282
|
+
* @since 4.0.0
|
|
283
|
+
*/
|
|
284
|
+
export interface Enqueue<in Events, in Emits> {
|
|
285
|
+
/** Raises an event inside the current macrostep. */
|
|
286
|
+
readonly raise: (event: Events) => void;
|
|
287
|
+
/** Emits an event through the machine's parent boundary. */
|
|
288
|
+
readonly emit: (event: Emits) => void;
|
|
289
|
+
/** Sends an event to an invoked child after the transition is selected. */
|
|
290
|
+
readonly sendTo: {
|
|
291
|
+
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): void;
|
|
292
|
+
<Address extends ChildAddress<never>>(child: Address, event: ChildAddress.Event<Address>): void;
|
|
293
|
+
};
|
|
294
|
+
/** Stops an invoked child after the transition is selected. */
|
|
295
|
+
readonly stop: {
|
|
296
|
+
<Child extends ChildMachine.Any>(child: Child): void;
|
|
297
|
+
<Event>(child: ChildAddress<Event>): void;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/** A closed actor command recorded by a synchronous machine transition. */
|
|
301
|
+
export type Command = {
|
|
302
|
+
readonly _tag: "SendTo";
|
|
303
|
+
readonly child: ChildMachine.Any | ChildAddress<never>;
|
|
304
|
+
readonly event: unknown;
|
|
305
|
+
} | {
|
|
306
|
+
readonly _tag: "Stop";
|
|
307
|
+
readonly child: ChildMachine.Any | ChildAddress<never>;
|
|
308
|
+
};
|
|
267
309
|
/**
|
|
268
310
|
* Namespace containing type-level members associated with `Runtime`.
|
|
269
311
|
*
|
|
@@ -271,7 +313,7 @@ export interface Runtime<in Events, in Emits> {
|
|
|
271
313
|
*/
|
|
272
314
|
export declare namespace Runtime {
|
|
273
315
|
/**
|
|
274
|
-
* Protocol annotation
|
|
316
|
+
* Protocol annotation for managed event delivery.
|
|
275
317
|
*
|
|
276
318
|
* @category models
|
|
277
319
|
* @since 4.0.0
|
|
@@ -313,45 +355,66 @@ export declare namespace Runtime {
|
|
|
313
355
|
}
|
|
314
356
|
type ExcludeCompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? Requirements : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : Requirements;
|
|
315
357
|
type IncompatibleRuntime<Requirements, Events, Emits> = Requirements extends Runtime.Requirement<infer RequiredEvents, infer RequiredEmits> ? IsAny<Requirements> extends true ? never : [RequiredEvents] extends [Events] ? [RequiredEmits] extends [Emits] ? never : Requirements : Requirements : never;
|
|
316
|
-
declare const
|
|
317
|
-
|
|
318
|
-
type EnsureCompatibleRuntime<Requirements, Events, Emits> = [IncompatibleRuntime<Requirements, Events, Emits>] extends [
|
|
319
|
-
never
|
|
320
|
-
] ? unknown : {
|
|
321
|
-
readonly [RuntimeCompatibilityErrorTypeId]: IncompatibleRuntime<Requirements, Events, Emits>;
|
|
322
|
-
};
|
|
323
|
-
type StateDefinitionError<Message extends string> = {
|
|
358
|
+
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
359
|
+
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
324
360
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
361
|
+
readonly path: Path;
|
|
362
|
+
readonly details: Details;
|
|
325
363
|
};
|
|
326
|
-
type
|
|
327
|
-
|
|
364
|
+
type ActiveStateKey<States extends Machine.StateSchemas> = Machine.ActiveStateKey<States>;
|
|
365
|
+
type HistoryStateKey<States extends Machine.StateSchemas> = Machine.HistoryStateKey<States>;
|
|
366
|
+
type ChoiceStateKey<States extends Machine.StateSchemas> = Machine.ChoiceStateKey<States>;
|
|
367
|
+
type StateDefinitionPath<Prefix extends string, Key extends PropertyKey> = Key extends string ? Key extends "" ? Prefix extends "" ? "<empty>" : `${Prefix}.<empty>` : Prefix extends "" ? Key : `${Prefix}.${Key}` : Key extends number ? Prefix extends "" ? `${Key}` : `${Prefix}.${Key}` : Prefix extends "" ? "<symbol>" : `${Prefix}.<symbol>`;
|
|
368
|
+
type ValidateStateKey<Key extends PropertyKey, Prefix extends string> = Key extends symbol ? StateDefinitionError<"State keys must be strings, not symbols", StateDefinitionPath<Prefix, Key>, Key> : Key extends number ? StateDefinitionError<"State keys cannot use numeric forms", StateDefinitionPath<Prefix, Key>, Key> : Key extends "" ? StateDefinitionError<"State keys cannot be empty", StateDefinitionPath<Prefix, Key>, Key> : Key extends "__proto__" ? StateDefinitionError<"The state key \"__proto__\" is not allowed", StateDefinitionPath<Prefix, Key>, Key> : Key extends `${string}.${string}` ? StateDefinitionError<"State keys cannot contain \".\"", StateDefinitionPath<Prefix, Key>, Key> : Key extends `${number}` ? StateDefinitionError<"State keys cannot use numeric forms", StateDefinitionPath<Prefix, Key>, Key> : unknown;
|
|
369
|
+
type ValidateStateTree<States extends Machine.StateSchemas, AllowHistory extends boolean = false, Prefix extends string = ""> = {
|
|
370
|
+
readonly [Key in keyof States]: ValidateStateKey<Key, Prefix> & ValidateStateNode<States[Key], AllowHistory, StateDefinitionPath<Prefix, Key>>;
|
|
328
371
|
};
|
|
329
|
-
type
|
|
372
|
+
type UnknownStateNodeProperty<Node, Kind extends StateDefinition.StateNodeKind> = Exclude<keyof Node, StateDefinition.AllowedStateNodeProperty<Kind>>;
|
|
373
|
+
type ValidateExactStateNodeProperties<Node, Kind extends StateDefinition.StateNodeKind, Path extends PropertyKey> = [UnknownStateNodeProperty<Node, Kind>] extends [never] ? unknown : StateDefinitionError<"State nodes cannot declare properties outside their state kind", Path, Extract<UnknownStateNodeProperty<Node, Kind>, PropertyKey>>;
|
|
374
|
+
type UnknownPseudoAnnotationProperty<Node> = Node extends {
|
|
375
|
+
readonly annotations: infer Annotations;
|
|
376
|
+
} ? Exclude<keyof Annotations, StateDefinition.AllowedPseudoStateAnnotationProperty> : never;
|
|
377
|
+
type ValidatePseudoStateAnnotations<Node, Path extends PropertyKey> = [UnknownPseudoAnnotationProperty<Node>] extends [
|
|
378
|
+
never
|
|
379
|
+
] ? unknown : StateDefinitionError<"Pseudo-state annotations contain unknown properties", Path, Extract<UnknownPseudoAnnotationProperty<Node>, PropertyKey>>;
|
|
380
|
+
type ValidateStateNode<Node, AllowHistory extends boolean, Path extends PropertyKey> = Node extends Machine.TaggedSchema ? unknown : Node extends Machine.HistoryStateNodeConfig ? ValidateExactStateNodeProperties<Node, "history", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateHistoryStateNode<Node> : StateDefinitionError<"History states must be declared below an active parent state", Path>) : Node extends Machine.ChoiceStateNodeConfig ? ValidateExactStateNodeProperties<Node, "choice", Path> & ValidatePseudoStateAnnotations<Node, Path> & (AllowHistory extends true ? ValidateChoiceStateNode<Node> : StateDefinitionError<"Choice states must be declared below an active parent state", Path>) : Node extends {
|
|
330
381
|
readonly schema: Machine.TaggedSchema;
|
|
331
|
-
} ? ValidateStateNodeConfig<Node> : StateDefinitionError<"State nodes must be tagged schemas or state node configs">;
|
|
382
|
+
} ? ValidateStateNodeConfig<Node, Path> : StateDefinitionError<"State nodes must be tagged schemas or state node configs", Path>;
|
|
383
|
+
type ValidateHistoryStateNode<Node extends Machine.HistoryStateNodeConfig> = [
|
|
384
|
+
Extract<keyof Node, "schema" | "states" | "initial" | "output" | "choice">
|
|
385
|
+
] extends [never] ? unknown : StateDefinitionError<"History states cannot declare schemas, children, initial states, or output">;
|
|
386
|
+
type ValidateChoiceStateNode<Node extends Machine.ChoiceStateNodeConfig> = [
|
|
387
|
+
Extract<keyof Node, "schema" | "states" | "initial" | "output" | "history">
|
|
388
|
+
] extends [never] ? unknown : StateDefinitionError<"Choice states cannot declare schemas, children, initial states, output, or history">;
|
|
332
389
|
type ValidateStateNodeConfig<Node extends {
|
|
333
390
|
readonly schema: Machine.TaggedSchema;
|
|
334
|
-
}> = Node extends {
|
|
391
|
+
}, Path extends PropertyKey> = Node extends {
|
|
392
|
+
readonly type: "parallel";
|
|
393
|
+
} ? ValidateExactStateNodeProperties<Node, "parallel", Path> & ValidateStateNodeWithChildren<Node, Node extends {
|
|
394
|
+
readonly states: infer Children;
|
|
395
|
+
} ? Children : never, Path> : Node extends {
|
|
396
|
+
readonly type: "final";
|
|
397
|
+
} ? ValidateExactStateNodeProperties<Node, "final", Path> & ValidateStateNodeWithoutChildren<Node> : Node extends {
|
|
335
398
|
readonly states: infer Children;
|
|
336
|
-
} ? ValidateStateNodeWithChildren<Node, Children> : ValidateStateNodeWithoutChildren<Node>;
|
|
399
|
+
} ? ValidateExactStateNodeProperties<Node, "compound", Path> & ValidateStateNodeWithChildren<Node, Children, Path> : ValidateExactStateNodeProperties<Node, "atomic", Path> & ValidateStateNodeWithoutChildren<Node>;
|
|
337
400
|
type ValidateOutputSchema<Node> = "output" extends keyof Node ? Node extends {
|
|
338
401
|
readonly output: Schema.Top;
|
|
339
402
|
} ? unknown : StateDefinitionError<"State output must be a schema"> : unknown;
|
|
340
403
|
type ValidateStateNodeWithChildren<Node extends {
|
|
341
404
|
readonly schema: Machine.TaggedSchema;
|
|
342
|
-
}, Children> = Children extends Machine.StateSchemas ? Node extends {
|
|
405
|
+
}, Children, Path extends PropertyKey> = Children extends Machine.StateSchemas ? Node extends {
|
|
343
406
|
readonly type: "final";
|
|
344
407
|
} ? StateDefinitionError<"Final states cannot declare child states"> : Node extends {
|
|
345
408
|
readonly type: "parallel";
|
|
346
409
|
} ? "initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
|
|
347
|
-
readonly states: ValidateStateTree<Children
|
|
348
|
-
} & ValidateOutputSchema<Node> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : ValidateCompoundStateNode<Node, Children> : StateDefinitionError<"Child states must be a state tree">;
|
|
410
|
+
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
411
|
+
} & ValidateOutputSchema<Node> : "output" extends keyof Node ? StateDefinitionError<"Only final and parallel states can declare output"> : ValidateCompoundStateNode<Node, Children, Path> : StateDefinitionError<"Child states must be a state tree">;
|
|
349
412
|
type ValidateCompoundStateNode<Node extends {
|
|
350
413
|
readonly schema: Machine.TaggedSchema;
|
|
351
|
-
}, Children extends Machine.StateSchemas> = Node extends {
|
|
414
|
+
}, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
|
|
352
415
|
readonly initial: infer Initial;
|
|
353
|
-
} ? Initial extends
|
|
354
|
-
readonly states: ValidateStateTree<Children
|
|
416
|
+
} ? Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? {
|
|
417
|
+
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
355
418
|
} : StateDefinitionError<"Compound initial must be one of its direct child keys"> : StateDefinitionError<"Compound states must declare an initial child">;
|
|
356
419
|
type ValidateStateNodeWithoutChildren<Node extends {
|
|
357
420
|
readonly schema: Machine.TaggedSchema;
|
|
@@ -361,7 +424,7 @@ type ValidateStateNodeWithoutChildren<Node extends {
|
|
|
361
424
|
type DefineStateTreeInput<States extends Machine.StateSchemas> = {
|
|
362
425
|
readonly [Key in keyof States]: DefineStateNodeInput<States[Key]>;
|
|
363
426
|
};
|
|
364
|
-
type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Node extends {
|
|
427
|
+
type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Node extends Machine.HistoryStateNodeConfig ? Machine.HistoryStateNodeConfig : Node extends Machine.ChoiceStateNodeConfig ? Machine.ChoiceStateNodeConfig : Node extends {
|
|
365
428
|
readonly type: "parallel";
|
|
366
429
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
367
430
|
} ? Omit<Node, "states"> & {
|
|
@@ -369,12 +432,19 @@ type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Nod
|
|
|
369
432
|
} : Node extends {
|
|
370
433
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
371
434
|
} ? Omit<Node, "initial" | "states"> & {
|
|
372
|
-
readonly initial:
|
|
435
|
+
readonly initial: ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
373
436
|
readonly states: DefineStateTreeInput<Children>;
|
|
374
437
|
} : Node;
|
|
375
438
|
type ValidateDefinedStates<States extends Machine.StateSchemas> = [States] extends [
|
|
376
439
|
Machine.ValidateStateSchemas<States>
|
|
377
440
|
] ? [] : [validation: Machine.ValidateStateSchemas<States>];
|
|
441
|
+
type InvalidDefinedStateTreeInput<States extends Machine.StateSchemas> = [States] extends [
|
|
442
|
+
Machine.ValidateStateSchemas<States>
|
|
443
|
+
] ? never : States & Machine.ValidateStateSchemas<States>;
|
|
444
|
+
interface DefineStates {
|
|
445
|
+
<const States extends Machine.StateSchemas>(states: States & DefineStateTreeInput<NoInfer<States>>, ..._validation: ValidateDefinedStates<NoInfer<States>>): Machine.DefinedStates<States>;
|
|
446
|
+
<const States extends Machine.StateSchemas>(states: InvalidDefinedStateTreeInput<States>): never;
|
|
447
|
+
}
|
|
378
448
|
type EventProtocolError<Message extends string, Tag extends PropertyKey = never> = {
|
|
379
449
|
readonly "~effect/Machine/EventProtocolError": Message;
|
|
380
450
|
readonly tag: Tag;
|
|
@@ -383,16 +453,41 @@ type DuplicateEventTag<Events extends ReadonlyArray<Machine.TaggedSchema>, Seen
|
|
|
383
453
|
infer Head extends Machine.TaggedSchema,
|
|
384
454
|
...infer Tail extends ReadonlyArray<Machine.TaggedSchema>
|
|
385
455
|
] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ? Tag extends Seen ? Tag | DuplicateEventTag<Tail, Seen> : DuplicateEventTag<Tail, Seen | Tag> : never : never;
|
|
386
|
-
type
|
|
387
|
-
|
|
388
|
-
|
|
456
|
+
type ValidateInputEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInput extends PropertyKey = DuplicateEventTag<InputEvents>> = [DuplicateInput] extends [never] ? unknown : EventProtocolError<"Public event tags must be unique", DuplicateInput>;
|
|
457
|
+
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>;
|
|
458
|
+
declare const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId;
|
|
459
|
+
declare const SnapshotBuilderConstructionTypeId: unique symbol;
|
|
460
|
+
type SnapshotBuilderComplete<Regions, Constructed extends boolean = false> = {
|
|
389
461
|
readonly [SnapshotBuilderStateTypeId]: Regions;
|
|
462
|
+
readonly [SnapshotBuilderConstructionTypeId]: Constructed;
|
|
463
|
+
};
|
|
464
|
+
type FromCallable<Arguments extends ReadonlyArray<unknown>, Result> = Arguments extends readonly [infer Input, ...infer Rest extends ReadonlyArray<unknown>] ? {} extends Input ? {
|
|
465
|
+
(...args: Rest): Result;
|
|
466
|
+
(...args: Arguments): Result;
|
|
467
|
+
} : (...args: Arguments) => Result : (...args: Arguments) => Result;
|
|
468
|
+
type FromMethod<Arguments extends ReadonlyArray<unknown>, Result> = {
|
|
469
|
+
/**
|
|
470
|
+
* Constructs the selected state from its schema make input while the
|
|
471
|
+
* machine plans the resulting configuration. The input may be omitted when
|
|
472
|
+
* the schema accepts an empty constructor object.
|
|
473
|
+
*
|
|
474
|
+
* @since 4.0.0
|
|
475
|
+
*/
|
|
476
|
+
readonly from: FromCallable<Arguments, Machine.StateConstruction<Result>>;
|
|
390
477
|
};
|
|
478
|
+
type ConstructionResult<Result> = Result | Machine.StateConstruction<Result>;
|
|
479
|
+
type UnwrapConstruction<Result> = Result extends Machine.StateConstruction<infer Value> ? Value : Result;
|
|
480
|
+
type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input ? {
|
|
481
|
+
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
482
|
+
<Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
483
|
+
} : <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected) => Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
391
484
|
type InitialSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
|
|
392
|
-
readonly [Key in
|
|
485
|
+
readonly [Key in ActiveStateKey<States>]: InitialSnapshotMethod<States, Key, Prefix>;
|
|
486
|
+
} & {
|
|
487
|
+
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
393
488
|
};
|
|
394
|
-
type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends
|
|
395
|
-
type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId extends
|
|
489
|
+
type InitialSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = ((...args: InitialSnapshotArguments<States, StateId, Prefix>) => InitialSnapshotResult<States, StateId, Prefix>) & FromMethod<InitialSnapshotFromArguments<States, StateId, Prefix>, InitialSnapshotResult<States, StateId, Prefix>>;
|
|
490
|
+
type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
396
491
|
readonly type: "parallel";
|
|
397
492
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
398
493
|
} ? [
|
|
@@ -401,32 +496,53 @@ type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId exten
|
|
|
401
496
|
] : Node extends {
|
|
402
497
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
403
498
|
} ? Node extends {
|
|
404
|
-
readonly initial: infer Initial extends
|
|
499
|
+
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
405
500
|
} ? [
|
|
406
501
|
value: Machine.NodeSchema<Node>["Type"],
|
|
407
|
-
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) =>
|
|
502
|
+
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSelectableResult<Children, Initial, Path>
|
|
408
503
|
] : never : [value: Machine.NodeSchema<Node>["Type"]] : never;
|
|
409
|
-
type
|
|
504
|
+
type InitialSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
505
|
+
readonly type: "parallel";
|
|
506
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
507
|
+
} ? [
|
|
508
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
509
|
+
states: (builder: InitialParallelBuilder<Children, Path>) => SnapshotBuilderComplete<InitialSnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
510
|
+
] : Node extends {
|
|
511
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
512
|
+
} ? Node extends {
|
|
513
|
+
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
514
|
+
} ? [
|
|
515
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
516
|
+
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
|
|
517
|
+
] : never : [input: Machine.NodeSchema<Node>["~type.make.in"]] : never;
|
|
518
|
+
type InitialSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
410
519
|
readonly type: "parallel";
|
|
411
520
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
412
521
|
} ? Machine.ParallelSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
|
|
413
522
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
414
523
|
} ? Node extends {
|
|
415
|
-
readonly initial: infer Initial extends
|
|
416
|
-
} ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"],
|
|
524
|
+
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
525
|
+
} ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, Machine.NodeSchema<Node>["Type"]> : never;
|
|
526
|
+
type InitialSelectableResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States> | ChoiceStateKey<States>, Prefix extends string> = StateId extends ChoiceStateKey<States> ? Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, StateId>> : StateId extends ActiveStateKey<States> ? InitialSnapshotResult<States, StateId, Prefix> : never;
|
|
417
527
|
type InitialSnapshotRegionsWithPrefix<States extends Machine.StateSchemas, Prefix extends string> = {
|
|
418
|
-
readonly [Key in
|
|
528
|
+
readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>;
|
|
419
529
|
};
|
|
420
|
-
type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends
|
|
421
|
-
readonly [Key in Remaining]: (...args: InitialSnapshotArguments<States, Key, Prefix>) => InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
530
|
+
type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
531
|
+
readonly [Key in Remaining]: ((...args: InitialSnapshotArguments<States, Key, Prefix>) => InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
422
532
|
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
423
|
-
}
|
|
533
|
+
}, Constructed>) & {
|
|
534
|
+
readonly from: FromCallable<InitialSnapshotFromArguments<States, Key, Prefix>, InitialParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
535
|
+
readonly [Region in Key]: InitialSnapshotResult<States, Key, Prefix>;
|
|
536
|
+
}, true>>;
|
|
537
|
+
};
|
|
424
538
|
};
|
|
425
539
|
type FullSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
|
|
426
|
-
readonly [Key in
|
|
540
|
+
readonly [Key in ActiveStateKey<States>]: FullSnapshotMethod<States, Key, Prefix>;
|
|
541
|
+
} & {
|
|
542
|
+
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
427
543
|
};
|
|
428
|
-
type FullSnapshotMethod<States extends Machine.StateSchemas, StateId extends
|
|
429
|
-
type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends
|
|
544
|
+
type FullSnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string> = ((...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>) & FromMethod<FullSnapshotFromArguments<States, StateId, Prefix>, FullSnapshotResult<States, StateId, Prefix>>;
|
|
545
|
+
type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
430
546
|
readonly type: "parallel";
|
|
431
547
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
432
548
|
} ? [
|
|
@@ -436,13 +552,84 @@ type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends
|
|
|
436
552
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
437
553
|
} ? [
|
|
438
554
|
value: Machine.NodeSchema<Node>["Type"],
|
|
439
|
-
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path>
|
|
555
|
+
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
|
|
440
556
|
] : [value: Machine.NodeSchema<Node>["Type"]] : never;
|
|
441
|
-
type
|
|
442
|
-
type
|
|
443
|
-
readonly
|
|
557
|
+
type FullSnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
558
|
+
readonly type: "parallel";
|
|
559
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
560
|
+
} ? [
|
|
561
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
562
|
+
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
563
|
+
] : Node extends {
|
|
564
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
565
|
+
} ? [
|
|
566
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
567
|
+
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>>
|
|
568
|
+
] : [input: Machine.NodeSchema<Node>["~type.make.in"]] : never;
|
|
569
|
+
type FullSnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Machine.SnapshotByIdentifierWithPath<States, StateId, Path>;
|
|
570
|
+
type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
571
|
+
readonly [Key in Remaining]: ((...args: FullSnapshotArguments<States, Key, Prefix>) => FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
444
572
|
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
445
|
-
}
|
|
573
|
+
}, Constructed>) & {
|
|
574
|
+
readonly from: FromCallable<FullSnapshotFromArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
575
|
+
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
576
|
+
}, true>>;
|
|
577
|
+
};
|
|
578
|
+
};
|
|
579
|
+
type HistorySnapshotArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
|
|
580
|
+
readonly type: "parallel";
|
|
581
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
582
|
+
} ? [
|
|
583
|
+
value: Machine.NodeSchema<Node>["Type"],
|
|
584
|
+
states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
|
|
585
|
+
] : Node extends {
|
|
586
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
587
|
+
} ? [
|
|
588
|
+
value: Machine.NodeSchema<Node>["Type"],
|
|
589
|
+
state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
|
|
590
|
+
] : never : never;
|
|
591
|
+
type HistorySnapshotFromArguments<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotFromArguments<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
|
|
592
|
+
readonly type: "parallel";
|
|
593
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
594
|
+
} ? [
|
|
595
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
596
|
+
states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
|
|
597
|
+
] : Node extends {
|
|
598
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
599
|
+
} ? [
|
|
600
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
601
|
+
state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
|
|
602
|
+
] : never : never;
|
|
603
|
+
type HistorySnapshotResult<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = Path extends Owner ? FullSnapshotResult<States, StateId, Prefix> : States[StateId] extends infer Node ? Node extends {
|
|
604
|
+
readonly type: "parallel";
|
|
605
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
606
|
+
} ? Machine.ParallelSnapshot<Path, Machine.NodeSchema<Node>["Type"], HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
|
|
607
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
608
|
+
} ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
|
|
609
|
+
type HistorySnapshotMethod<States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Owner extends string> = ((...args: HistorySnapshotArguments<States, StateId, Prefix, Owner>) => HistorySnapshotResult<States, StateId, Prefix, Owner>) & FromMethod<HistorySnapshotFromArguments<States, StateId, Prefix, Owner>, HistorySnapshotResult<States, StateId, Prefix, Owner>>;
|
|
610
|
+
type HistorySnapshotWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string> = {
|
|
611
|
+
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
|
|
612
|
+
}[ActiveStateKey<States>];
|
|
613
|
+
type HistorySnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string = ""> = {
|
|
614
|
+
readonly [Key in ActiveStateKey<States> as Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? Key : never]: HistorySnapshotMethod<States, Key, Prefix, Owner>;
|
|
615
|
+
};
|
|
616
|
+
type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends string, Owner extends string> = {
|
|
617
|
+
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
|
|
618
|
+
};
|
|
619
|
+
type HistoryParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Owner extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
620
|
+
readonly [Key in Remaining]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? ((...args: HistorySnapshotArguments<States, Key, Prefix, Owner>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
621
|
+
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
622
|
+
}, Constructed>) & {
|
|
623
|
+
readonly from: FromCallable<HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
624
|
+
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
625
|
+
}, true>>;
|
|
626
|
+
} : ((...args: FullSnapshotArguments<States, Key, Prefix>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
627
|
+
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
628
|
+
}, Constructed>) & {
|
|
629
|
+
readonly from: FromCallable<FullSnapshotFromArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
630
|
+
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
631
|
+
}, true>>;
|
|
632
|
+
};
|
|
446
633
|
};
|
|
447
634
|
type ParentPath<Path extends string> = Path extends `${infer Parent}.${infer Child}` ? Child extends `${string}.${string}` ? `${Parent}.${ParentPath<Child>}` : Parent : never;
|
|
448
635
|
type IsCompoundNode<Node> = Node extends {
|
|
@@ -450,47 +637,113 @@ type IsCompoundNode<Node> = Node extends {
|
|
|
450
637
|
} ? false : Node extends {
|
|
451
638
|
readonly states: Machine.StateSchemas;
|
|
452
639
|
} ? true : false;
|
|
453
|
-
type NearestCompoundScope<States extends Machine.StateSchemas, Source extends Machine.
|
|
640
|
+
type NearestCompoundScope<States extends Machine.StateSchemas, Source extends Machine.StateNodeIdentifier<States>> = Source extends Machine.StateIdentifier<States> ? IsCompoundNode<Machine.NodeByIdentifier<States, Source>> extends true ? Source : ParentPath<Source> extends infer Parent extends Machine.StateIdentifier<States> ? NearestCompoundScope<States, Parent> : never : ParentPath<Source> extends infer Parent extends Machine.StateIdentifier<States> ? NearestCompoundScope<States, Parent> : never;
|
|
454
641
|
type ChildrenOf<States extends Machine.StateSchemas, Path extends Machine.StateIdentifier<States>> = Machine.NodeByIdentifier<States, Path> extends {
|
|
455
642
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
456
643
|
} ? Children : never;
|
|
457
644
|
type StateIdentifierFromPath<States extends Machine.StateSchemas, Path extends string> = Extract<Path, Machine.StateIdentifier<States>>;
|
|
458
|
-
type LocalTargetResult<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends
|
|
645
|
+
type LocalTargetResult<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends {
|
|
459
646
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
460
|
-
} ?
|
|
647
|
+
} ? States[StateId] extends {
|
|
648
|
+
readonly type: "parallel";
|
|
649
|
+
} ? Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>> : LocalTargetResultWithPrefix<AllStates, Children, Path> : Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>;
|
|
461
650
|
type LocalTargetResultWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
462
|
-
readonly [Key in
|
|
463
|
-
}[Extract<
|
|
464
|
-
type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string
|
|
465
|
-
readonly [Key in
|
|
651
|
+
readonly [Key in ActiveStateKey<States>]: LocalTargetResult<AllStates, States, Key, Prefix>;
|
|
652
|
+
}[ActiveStateKey<States>] | Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
653
|
+
type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>> = {
|
|
654
|
+
readonly [Key in ActiveStateKey<States>]: LocalTargetMethod<AllStates, States, Key, Prefix, Source>;
|
|
655
|
+
} & {
|
|
656
|
+
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
466
657
|
};
|
|
467
|
-
type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends
|
|
658
|
+
type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
659
|
+
readonly type: "parallel";
|
|
468
660
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
469
|
-
} ? <Result extends LocalTargetResultWithPrefix<AllStates, Children, Path
|
|
470
|
-
|
|
661
|
+
} ? Source extends Path | `${Path}.${string}` ? (<Result extends ConstructionResult<LocalTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
|
|
662
|
+
readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>>;
|
|
663
|
+
} : ((value: Machine.NodeSchema<Node>["Type"], states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
|
|
664
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
665
|
+
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
666
|
+
], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : Node extends {
|
|
667
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
668
|
+
} ? (<Result extends ConstructionResult<LocalTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
|
|
669
|
+
readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>>;
|
|
670
|
+
} : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
|
|
671
|
+
input: Machine.NodeSchema<Node>["~type.make.in"]
|
|
672
|
+
], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
|
|
673
|
+
type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope extends Machine.StateIdentifier<States>, Source extends Machine.StateNodeIdentifier<States>> = ChildrenOf<States, Scope> extends infer Children extends Machine.StateSchemas ? LocalTargetBuilderWithPrefix<States, Children, Scope, Source> & {
|
|
471
674
|
/**
|
|
472
675
|
* Updates the value of the state containing the local group and moves to
|
|
473
676
|
* one of the states inside it. Values in other active branches are kept.
|
|
474
677
|
*
|
|
475
678
|
* @since 4.0.0
|
|
476
679
|
*/
|
|
477
|
-
readonly with: <Result extends LocalTargetResultWithPrefix<States, Children, Scope
|
|
680
|
+
readonly with: (<Result extends ConstructionResult<LocalTargetResultWithPrefix<States, Children, Scope>>>(value: Machine.StateByIdentifier<States, Scope>, state: (builder: LocalTargetBuilderWithPrefix<States, Children, Scope, Source>) => Result) => Result) & {
|
|
681
|
+
readonly from: ConstructionSelectorFromCallable<Machine.SchemaByIdentifier<States, Scope>["~type.make.in"], LocalTargetBuilderWithPrefix<States, Children, Scope, Source>, LocalTargetResultWithPrefix<States, Children, Scope>>;
|
|
682
|
+
};
|
|
478
683
|
} : {};
|
|
479
|
-
type BranchTargetResult<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends
|
|
684
|
+
type BranchTargetResult<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends {
|
|
480
685
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
481
|
-
} ?
|
|
686
|
+
} ? States[StateId] extends {
|
|
687
|
+
readonly type: "parallel";
|
|
688
|
+
} ? Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>> : BranchTargetResultWithPrefix<AllStates, Children, Path> : Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>;
|
|
482
689
|
type BranchTargetResultWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
483
|
-
readonly [Key in
|
|
484
|
-
}[Extract<
|
|
485
|
-
type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string
|
|
486
|
-
readonly [Key in
|
|
690
|
+
readonly [Key in ActiveStateKey<States>]: BranchTargetResult<AllStates, States, Key, Prefix>;
|
|
691
|
+
}[ActiveStateKey<States>] | Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
692
|
+
type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>> = {
|
|
693
|
+
readonly [Key in ActiveStateKey<States>]: BranchTargetMethod<AllStates, States, Key, Prefix, Source>;
|
|
694
|
+
} & {
|
|
695
|
+
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
487
696
|
};
|
|
488
|
-
type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends
|
|
697
|
+
type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends infer Node ? Node extends {
|
|
698
|
+
readonly type: "parallel";
|
|
699
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
700
|
+
} ? Source extends Path | `${Path}.${string}` ? (<Result extends ConstructionResult<BranchTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
|
|
701
|
+
readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>>;
|
|
702
|
+
} & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : ((value: Machine.NodeSchema<Node>["Type"], states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
|
|
703
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
704
|
+
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
705
|
+
], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : Node extends {
|
|
489
706
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
490
|
-
} ? (<Result extends BranchTargetResultWithPrefix<AllStates, Children, Path
|
|
491
|
-
type
|
|
492
|
-
|
|
707
|
+
} ? (<Result extends ConstructionResult<BranchTargetResultWithPrefix<AllStates, Children, Path>>>(value: Machine.NodeSchema<Node>["Type"], state: (builder: BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>) => Result) => Result) & {
|
|
708
|
+
readonly from: ConstructionSelectorFromCallable<Machine.NodeSchema<Node>["~type.make.in"], BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>>;
|
|
709
|
+
} & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
|
|
710
|
+
input: Machine.NodeSchema<Node>["~type.make.in"]
|
|
711
|
+
], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
|
|
712
|
+
type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.StateNodeIdentifier<States>> = {
|
|
713
|
+
readonly [Key in Root]: BranchTargetMethod<States, States, Key, "", Source>;
|
|
714
|
+
};
|
|
715
|
+
type HistoryContainingKey<States extends Machine.StateSchemas> = {
|
|
716
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends Machine.HistoryStateNodeConfig ? Key : States[Key] extends {
|
|
717
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
718
|
+
} ? [
|
|
719
|
+
Machine.HistoryIdentifier<Children>
|
|
720
|
+
] extends [never] ? never : Key : never;
|
|
721
|
+
}[Extract<keyof States, string>];
|
|
722
|
+
type HistoryTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
723
|
+
readonly [Key in HistoryContainingKey<States>]: States[Key] extends Machine.HistoryStateNodeConfig ? () => Machine.HistoryTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.HistoryIdentifier<AllStates>>> : States[Key] extends {
|
|
724
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
725
|
+
} ? HistoryTargetBuilderWithPrefix<AllStates, Children, Machine.JoinPath<Prefix, Key>> : never;
|
|
493
726
|
};
|
|
727
|
+
type HasDirectShallowHistory<States extends Machine.StateSchemas> = {
|
|
728
|
+
readonly [Key in HistoryStateKey<States>]: States[Key] extends {
|
|
729
|
+
readonly history: "deep";
|
|
730
|
+
} ? never : Key;
|
|
731
|
+
}[HistoryStateKey<States>] extends never ? false : true;
|
|
732
|
+
type InitializerClosureForNode<AllStates extends Machine.StateSchemas, Node, Path extends string> = Node extends {
|
|
733
|
+
readonly type: "parallel";
|
|
734
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
735
|
+
} ? Extract<Path, Machine.StateIdentifier<AllStates>> | InitializerClosuresForChildren<AllStates, Children, Path> : Node extends {
|
|
736
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
737
|
+
readonly initial: infer Initial;
|
|
738
|
+
} ? Extract<Path, Machine.StateIdentifier<AllStates>> | (Initial extends ActiveStateKey<Children> ? InitializerClosureForNode<AllStates, Children[Initial], Machine.JoinPath<Path, Initial>> : never) : never;
|
|
739
|
+
type InitializerClosuresForChildren<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
740
|
+
readonly [Key in ActiveStateKey<States>]: InitializerClosureForNode<AllStates, States[Key], Machine.JoinPath<Prefix, Key>>;
|
|
741
|
+
}[ActiveStateKey<States>];
|
|
742
|
+
type RequiredHistoryInitializersWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
743
|
+
readonly [Key in ActiveStateKey<States>]: States[Key] extends {
|
|
744
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
745
|
+
} ? (HasDirectShallowHistory<Children> extends true ? InitializerClosuresForChildren<AllStates, Children, Machine.JoinPath<Prefix, Key>> : never) | RequiredHistoryInitializersWithPrefix<AllStates, Children, Machine.JoinPath<Prefix, Key>> : never;
|
|
746
|
+
}[ActiveStateKey<States>];
|
|
494
747
|
type SpawnRequirements<Requirements> = Exclude<Requirements, Scope.Scope>;
|
|
495
748
|
type SpawnIdError<Options extends SpawnOptions> = "id" extends keyof Options ? Options extends {
|
|
496
749
|
readonly id?: infer Id;
|
|
@@ -743,7 +996,7 @@ export declare namespace ChildMachine {
|
|
|
743
996
|
* @category utility types
|
|
744
997
|
* @since 4.0.0
|
|
745
998
|
*/
|
|
746
|
-
type Ref<Child> = Child extends ChildMachine<string, infer M> ?
|
|
999
|
+
type Ref<Child> = Child extends ChildMachine<string, infer M> ? MachineRef<Machine.Snapshot<Machine.States<M>>, Machine.InputEvent<M>, Machine.Error<M> | ActionError<Machine.Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Machine.Output<M>> : never;
|
|
747
1000
|
/**
|
|
748
1001
|
* Event accepted by the child selected by a descriptor.
|
|
749
1002
|
*
|
|
@@ -833,6 +1086,26 @@ export interface SpawnIdOptions extends SpawnOptions {
|
|
|
833
1086
|
* @since 4.0.0
|
|
834
1087
|
*/
|
|
835
1088
|
export declare namespace Machine {
|
|
1089
|
+
/**
|
|
1090
|
+
* Stable type-level representation carried by every machine definition.
|
|
1091
|
+
*
|
|
1092
|
+
* @internal
|
|
1093
|
+
*/
|
|
1094
|
+
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>> {
|
|
1095
|
+
readonly states: States;
|
|
1096
|
+
readonly events: Events;
|
|
1097
|
+
readonly input: Input;
|
|
1098
|
+
readonly unhandledStates: UnhandledStates;
|
|
1099
|
+
readonly error: E;
|
|
1100
|
+
readonly services: R;
|
|
1101
|
+
readonly initialError: InitialE;
|
|
1102
|
+
readonly initialServices: InitialR;
|
|
1103
|
+
readonly finalStates: FinalStates;
|
|
1104
|
+
readonly output: Output;
|
|
1105
|
+
readonly emits: Emits;
|
|
1106
|
+
readonly outputStates: OutputStates;
|
|
1107
|
+
readonly inputEvents: InputEvents;
|
|
1108
|
+
}
|
|
836
1109
|
/**
|
|
837
1110
|
* Any schema-first machine.
|
|
838
1111
|
*
|
|
@@ -847,12 +1120,15 @@ export declare namespace Machine {
|
|
|
847
1120
|
*/
|
|
848
1121
|
interface Any extends Pipeable {
|
|
849
1122
|
readonly [TypeId]: TypeId;
|
|
1123
|
+
/** @internal */
|
|
1124
|
+
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
850
1125
|
readonly states: StateSchemas;
|
|
851
1126
|
readonly events: ReadonlyArray<TaggedSchema>;
|
|
852
1127
|
readonly internalEvents: ReadonlyArray<TaggedSchema>;
|
|
853
1128
|
readonly emits: ReadonlyArray<TaggedSchema>;
|
|
854
1129
|
readonly input: Schema.Top | undefined;
|
|
855
1130
|
readonly id: string | undefined;
|
|
1131
|
+
/** @internal */
|
|
856
1132
|
readonly stateNodes: StateNodes;
|
|
857
1133
|
/** @internal */
|
|
858
1134
|
readonly makeTargetBuilder: any;
|
|
@@ -863,20 +1139,118 @@ export declare namespace Machine {
|
|
|
863
1139
|
/** @internal */
|
|
864
1140
|
readonly initial: any;
|
|
865
1141
|
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Extracts the state schema tree carried by a machine definition.
|
|
1144
|
+
*
|
|
1145
|
+
* @category utility types
|
|
1146
|
+
* @since 4.0.0
|
|
1147
|
+
*/
|
|
1148
|
+
type States<M extends Any> = M[typeof MachineTypeId]["states"];
|
|
1149
|
+
/**
|
|
1150
|
+
* Extracts the complete event schema tuple carried by a machine definition.
|
|
1151
|
+
*
|
|
1152
|
+
* @category utility types
|
|
1153
|
+
* @since 4.0.0
|
|
1154
|
+
*/
|
|
1155
|
+
type Events<M extends Any> = M[typeof MachineTypeId]["events"];
|
|
1156
|
+
/**
|
|
1157
|
+
* Extracts the input schema carried by a machine definition.
|
|
1158
|
+
*
|
|
1159
|
+
* @category utility types
|
|
1160
|
+
* @since 4.0.0
|
|
1161
|
+
*/
|
|
1162
|
+
type Input<M extends Any> = M[typeof MachineTypeId]["input"];
|
|
1163
|
+
/**
|
|
1164
|
+
* Extracts state paths that do not yet have handlers.
|
|
1165
|
+
*
|
|
1166
|
+
* @category utility types
|
|
1167
|
+
* @since 4.0.0
|
|
1168
|
+
*/
|
|
1169
|
+
type UnhandledStates<M extends Any> = M[typeof MachineTypeId]["unhandledStates"];
|
|
1170
|
+
/**
|
|
1171
|
+
* Extracts the runtime error channel carried by a machine definition.
|
|
1172
|
+
*
|
|
1173
|
+
* @category utility types
|
|
1174
|
+
* @since 4.0.0
|
|
1175
|
+
*/
|
|
1176
|
+
type Error<M extends Any> = M[typeof MachineTypeId]["error"];
|
|
1177
|
+
/**
|
|
1178
|
+
* Extracts runtime service requirements carried by a machine definition.
|
|
1179
|
+
*
|
|
1180
|
+
* @category utility types
|
|
1181
|
+
* @since 4.0.0
|
|
1182
|
+
*/
|
|
1183
|
+
type Services<M extends Any> = M[typeof MachineTypeId]["services"];
|
|
1184
|
+
/**
|
|
1185
|
+
* Extracts the startup error channel carried by a machine definition.
|
|
1186
|
+
*
|
|
1187
|
+
* @category utility types
|
|
1188
|
+
* @since 4.0.0
|
|
1189
|
+
*/
|
|
1190
|
+
type InitialError<M extends Any> = M[typeof MachineTypeId]["initialError"];
|
|
1191
|
+
/**
|
|
1192
|
+
* Extracts startup service requirements carried by a machine definition.
|
|
1193
|
+
*
|
|
1194
|
+
* @category utility types
|
|
1195
|
+
* @since 4.0.0
|
|
1196
|
+
*/
|
|
1197
|
+
type InitialServices<M extends Any> = M[typeof MachineTypeId]["initialServices"];
|
|
1198
|
+
/**
|
|
1199
|
+
* Extracts final state paths carried by a machine definition.
|
|
1200
|
+
*
|
|
1201
|
+
* @category utility types
|
|
1202
|
+
* @since 4.0.0
|
|
1203
|
+
*/
|
|
1204
|
+
type FinalStates<M extends Any> = M[typeof MachineTypeId]["finalStates"];
|
|
1205
|
+
/**
|
|
1206
|
+
* Extracts the terminal output channel carried by a machine definition.
|
|
1207
|
+
*
|
|
1208
|
+
* @category utility types
|
|
1209
|
+
* @since 4.0.0
|
|
1210
|
+
*/
|
|
1211
|
+
type Output<M extends Any> = M[typeof MachineTypeId]["output"];
|
|
1212
|
+
/**
|
|
1213
|
+
* Extracts the emitted event schema tuple carried by a machine definition.
|
|
1214
|
+
*
|
|
1215
|
+
* @category utility types
|
|
1216
|
+
* @since 4.0.0
|
|
1217
|
+
*/
|
|
1218
|
+
type Emits<M extends Any> = M[typeof MachineTypeId]["emits"];
|
|
1219
|
+
/**
|
|
1220
|
+
* Extracts state paths with implemented output handlers.
|
|
1221
|
+
*
|
|
1222
|
+
* @category utility types
|
|
1223
|
+
* @since 4.0.0
|
|
1224
|
+
*/
|
|
1225
|
+
type OutputStates<M extends Any> = M[typeof MachineTypeId]["outputStates"];
|
|
1226
|
+
/**
|
|
1227
|
+
* Extracts the public input event schema tuple carried by a machine definition.
|
|
1228
|
+
*
|
|
1229
|
+
* @category utility types
|
|
1230
|
+
* @since 4.0.0
|
|
1231
|
+
*/
|
|
1232
|
+
type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"];
|
|
866
1233
|
/**
|
|
867
1234
|
* Extracts the complete event protocol handled inside a machine.
|
|
868
1235
|
*
|
|
869
1236
|
* @category utility types
|
|
870
1237
|
* @since 4.0.0
|
|
871
1238
|
*/
|
|
872
|
-
type Event<M extends Any> =
|
|
1239
|
+
type Event<M extends Any> = EventOf<Events<M>>;
|
|
873
1240
|
/**
|
|
874
1241
|
* Extracts the event protocol accepted by public machine input boundaries.
|
|
875
1242
|
*
|
|
876
1243
|
* @category utility types
|
|
877
1244
|
* @since 4.0.0
|
|
878
1245
|
*/
|
|
879
|
-
type InputEvent<M extends Any> =
|
|
1246
|
+
type InputEvent<M extends Any> = EventOf<InputEvents<M>>;
|
|
1247
|
+
/**
|
|
1248
|
+
* Extracts the event protocol emitted by a machine.
|
|
1249
|
+
*
|
|
1250
|
+
* @category utility types
|
|
1251
|
+
* @since 4.0.0
|
|
1252
|
+
*/
|
|
1253
|
+
type Emit<M extends Any> = EmitOf<Emits<M>>;
|
|
880
1254
|
/**
|
|
881
1255
|
* A schema whose decoded value contains a `_tag` discriminator.
|
|
882
1256
|
*
|
|
@@ -892,6 +1266,23 @@ export declare namespace Machine {
|
|
|
892
1266
|
readonly _tag: PropertyKey;
|
|
893
1267
|
};
|
|
894
1268
|
};
|
|
1269
|
+
/**
|
|
1270
|
+
* Descriptive annotations exposed for compiled state nodes.
|
|
1271
|
+
*
|
|
1272
|
+
* Schema-backed states resolve their complete Effect Schema annotation map.
|
|
1273
|
+
* Pseudo-states accept only the descriptive fields below. Annotations never
|
|
1274
|
+
* affect state identity, targeting, or runtime behavior.
|
|
1275
|
+
*
|
|
1276
|
+
* @category models
|
|
1277
|
+
* @since 4.0.0
|
|
1278
|
+
*/
|
|
1279
|
+
interface StateNodeAnnotations extends Schema.Annotations.Annotations {
|
|
1280
|
+
readonly title?: string | undefined;
|
|
1281
|
+
readonly description?: string | undefined;
|
|
1282
|
+
readonly documentation?: string | undefined;
|
|
1283
|
+
}
|
|
1284
|
+
/** Descriptive annotations accepted by schema-less pseudo-states. */
|
|
1285
|
+
type PseudoStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
|
|
895
1286
|
/**
|
|
896
1287
|
* Configuration accepted for an atomic object state node.
|
|
897
1288
|
*
|
|
@@ -931,16 +1322,51 @@ export declare namespace Machine {
|
|
|
931
1322
|
readonly output?: Schema.Top;
|
|
932
1323
|
readonly states: StateTree;
|
|
933
1324
|
}
|
|
1325
|
+
/**
|
|
1326
|
+
* Pseudo-state that restores the last active configuration of its parent.
|
|
1327
|
+
*
|
|
1328
|
+
* History nodes are transition targets only. They never become active and
|
|
1329
|
+
* therefore do not declare a state value schema or lifecycle handlers.
|
|
1330
|
+
* Both recorded history and a first-use default can rebuild inactive
|
|
1331
|
+
* ancestors. A default is a complete root configuration containing the
|
|
1332
|
+
* history owner, so its validity is independent of the transition source.
|
|
1333
|
+
*
|
|
1334
|
+
* @category models
|
|
1335
|
+
* @since 4.0.0
|
|
1336
|
+
*/
|
|
1337
|
+
interface HistoryStateNodeConfig {
|
|
1338
|
+
readonly type: "history";
|
|
1339
|
+
/** Defaults to shallow history. */
|
|
1340
|
+
readonly history?: "shallow" | "deep";
|
|
1341
|
+
readonly annotations?: PseudoStateAnnotations;
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Transient decision pseudo-state resolved immediately when targeted.
|
|
1345
|
+
*
|
|
1346
|
+
* Choice nodes have no value and never belong to an active configuration.
|
|
1347
|
+
* Their required `choice` implementation uses ordinary TypeScript or an
|
|
1348
|
+
* Effect to select a typed target.
|
|
1349
|
+
*
|
|
1350
|
+
* @category models
|
|
1351
|
+
* @since 4.0.0
|
|
1352
|
+
*/
|
|
1353
|
+
interface ChoiceStateNodeConfig {
|
|
1354
|
+
readonly type: "choice";
|
|
1355
|
+
readonly annotations?: PseudoStateAnnotations;
|
|
1356
|
+
}
|
|
934
1357
|
/**
|
|
935
1358
|
* Configuration accepted for an object state node.
|
|
936
1359
|
*
|
|
937
1360
|
* @category models
|
|
938
1361
|
* @since 4.0.0
|
|
939
1362
|
*/
|
|
940
|
-
type StateNodeConfig = AtomicStateNodeConfig | CompoundStateNodeConfig | ParallelStateNodeConfig;
|
|
1363
|
+
type StateNodeConfig = AtomicStateNodeConfig | CompoundStateNodeConfig | ParallelStateNodeConfig | HistoryStateNodeConfig | ChoiceStateNodeConfig;
|
|
941
1364
|
/**
|
|
942
1365
|
* Object state tree keyed by state path.
|
|
943
1366
|
*
|
|
1367
|
+
* Keys must be non-empty, non-numeric strings without `.`. The
|
|
1368
|
+
* prototype-mutating key `__proto__` and symbol keys are not accepted.
|
|
1369
|
+
*
|
|
944
1370
|
* @category models
|
|
945
1371
|
* @since 4.0.0
|
|
946
1372
|
*/
|
|
@@ -1023,32 +1449,171 @@ export declare namespace Machine {
|
|
|
1023
1449
|
* @since 4.0.0
|
|
1024
1450
|
*/
|
|
1025
1451
|
type ValidateStateSchemas<States extends StateSchemas> = ValidateStateTree<States>;
|
|
1452
|
+
/** Properties shared by every compiled state-node variant. */
|
|
1453
|
+
interface StateNodeBase<Path extends string = string> {
|
|
1454
|
+
readonly path: Path;
|
|
1455
|
+
readonly key: string;
|
|
1456
|
+
/** Resolved Effect Schema annotations, or descriptive pseudo-state annotations. */
|
|
1457
|
+
readonly annotations: Readonly<StateNodeAnnotations> | undefined;
|
|
1458
|
+
readonly order: number;
|
|
1459
|
+
}
|
|
1460
|
+
/** Runtime metadata for a compiled atomic state. */
|
|
1461
|
+
interface AtomicStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1462
|
+
readonly type: "atomic";
|
|
1463
|
+
readonly schema: TaggedSchema;
|
|
1464
|
+
readonly output: undefined;
|
|
1465
|
+
readonly history: undefined;
|
|
1466
|
+
readonly parent: ActivePath | undefined;
|
|
1467
|
+
readonly children: readonly [];
|
|
1468
|
+
readonly initial: undefined;
|
|
1469
|
+
}
|
|
1470
|
+
/** Runtime metadata for a compiled compound state. */
|
|
1471
|
+
interface CompoundStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath, ChoicePath extends string = ActivePath> extends StateNodeBase<OwnPath> {
|
|
1472
|
+
readonly type: "compound";
|
|
1473
|
+
readonly schema: TaggedSchema;
|
|
1474
|
+
readonly output: undefined;
|
|
1475
|
+
readonly history: undefined;
|
|
1476
|
+
readonly parent: ActivePath | undefined;
|
|
1477
|
+
/** Active child paths. Pseudo-states are available through their `parent` relationship. */
|
|
1478
|
+
readonly children: ReadonlyArray<ActivePath>;
|
|
1479
|
+
readonly initial: ActivePath | ChoicePath;
|
|
1480
|
+
}
|
|
1481
|
+
/** Runtime metadata for a compiled parallel state. */
|
|
1482
|
+
interface ParallelStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1483
|
+
readonly type: "parallel";
|
|
1484
|
+
readonly schema: TaggedSchema;
|
|
1485
|
+
readonly output: Schema.Top | undefined;
|
|
1486
|
+
readonly history: undefined;
|
|
1487
|
+
readonly parent: ActivePath | undefined;
|
|
1488
|
+
/** Active child paths. Pseudo-states are available through their `parent` relationship. */
|
|
1489
|
+
readonly children: ReadonlyArray<ActivePath>;
|
|
1490
|
+
readonly initial: undefined;
|
|
1491
|
+
}
|
|
1492
|
+
/** Runtime metadata for a compiled final state. */
|
|
1493
|
+
interface FinalStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1494
|
+
readonly type: "final";
|
|
1495
|
+
readonly schema: TaggedSchema;
|
|
1496
|
+
readonly output: Schema.Top | undefined;
|
|
1497
|
+
readonly history: undefined;
|
|
1498
|
+
readonly parent: ActivePath | undefined;
|
|
1499
|
+
readonly children: readonly [];
|
|
1500
|
+
readonly initial: undefined;
|
|
1501
|
+
}
|
|
1502
|
+
/** Runtime metadata for a compiled history pseudo-state. */
|
|
1503
|
+
interface HistoryStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
|
|
1504
|
+
readonly type: "history";
|
|
1505
|
+
readonly schema: undefined;
|
|
1506
|
+
readonly output: undefined;
|
|
1507
|
+
readonly history: "shallow" | "deep";
|
|
1508
|
+
readonly parent: ActivePath;
|
|
1509
|
+
readonly children: readonly [];
|
|
1510
|
+
readonly initial: undefined;
|
|
1511
|
+
}
|
|
1512
|
+
/** Runtime metadata for a compiled choice pseudo-state. */
|
|
1513
|
+
interface ChoiceStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
|
|
1514
|
+
readonly type: "choice";
|
|
1515
|
+
readonly schema: undefined;
|
|
1516
|
+
readonly output: undefined;
|
|
1517
|
+
readonly history: undefined;
|
|
1518
|
+
readonly parent: ActivePath;
|
|
1519
|
+
readonly children: readonly [];
|
|
1520
|
+
readonly initial: undefined;
|
|
1521
|
+
}
|
|
1026
1522
|
/**
|
|
1027
1523
|
* Runtime metadata for a compiled state node.
|
|
1028
1524
|
*
|
|
1525
|
+
* The `type` discriminator narrows every kind-specific topology and schema
|
|
1526
|
+
* property while preserving a uniform inspection shape.
|
|
1527
|
+
*
|
|
1029
1528
|
* @category models
|
|
1030
1529
|
* @since 4.0.0
|
|
1031
1530
|
*/
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
readonly key: string;
|
|
1035
|
-
readonly schema: TaggedSchema;
|
|
1036
|
-
readonly output: Schema.Top | undefined;
|
|
1037
|
-
readonly type: "atomic" | "compound" | "parallel" | "final";
|
|
1038
|
-
readonly parent: string | undefined;
|
|
1039
|
-
readonly children: ReadonlyArray<string>;
|
|
1040
|
-
readonly initial: string | undefined;
|
|
1041
|
-
readonly order: number;
|
|
1042
|
-
}
|
|
1531
|
+
type ActiveStateNode<ActivePath extends string = string, ChoicePath extends string = ActivePath> = AtomicStateNode<ActivePath, ActivePath> | CompoundStateNode<ActivePath, ActivePath, ChoicePath> | ParallelStateNode<ActivePath, ActivePath> | FinalStateNode<ActivePath, ActivePath>;
|
|
1532
|
+
type StateNode<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> = ActiveStateNode<ActivePath, ChoicePath> | HistoryStateNode<HistoryPath, ActivePath> | ChoiceStateNode<ChoicePath, ActivePath>;
|
|
1043
1533
|
/**
|
|
1044
1534
|
* Runtime lookup table for state nodes.
|
|
1045
1535
|
*
|
|
1046
1536
|
* @category models
|
|
1047
1537
|
* @since 4.0.0
|
|
1048
1538
|
*/
|
|
1049
|
-
interface StateNodes {
|
|
1050
|
-
readonly byPath: ReadonlyMap<
|
|
1051
|
-
readonly roots: ReadonlyArray<
|
|
1539
|
+
interface StateNodes<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> {
|
|
1540
|
+
readonly byPath: ReadonlyMap<ActivePath | HistoryPath | ChoicePath, StateNode<ActivePath, HistoryPath, ChoicePath>>;
|
|
1541
|
+
readonly roots: ReadonlyArray<ActivePath>;
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Trigger that selects a registered transition handler.
|
|
1545
|
+
*
|
|
1546
|
+
* @category models
|
|
1547
|
+
* @since 4.0.0
|
|
1548
|
+
*/
|
|
1549
|
+
type TransitionTrigger<EventTag extends PropertyKey = PropertyKey> = {
|
|
1550
|
+
readonly type: "event";
|
|
1551
|
+
readonly event: EventTag;
|
|
1552
|
+
} | {
|
|
1553
|
+
readonly type: "always";
|
|
1554
|
+
} | {
|
|
1555
|
+
readonly type: "done";
|
|
1556
|
+
} | {
|
|
1557
|
+
readonly type: "choice";
|
|
1558
|
+
};
|
|
1559
|
+
/**
|
|
1560
|
+
* Statically inspectable destination paths for a transition handler.
|
|
1561
|
+
* A declared parent path covers every descendant below that state.
|
|
1562
|
+
*
|
|
1563
|
+
* @category models
|
|
1564
|
+
* @since 4.0.0
|
|
1565
|
+
*/
|
|
1566
|
+
type TransitionTargets<Path extends string = string> = {
|
|
1567
|
+
readonly type: "dynamic";
|
|
1568
|
+
} | {
|
|
1569
|
+
readonly type: "declared";
|
|
1570
|
+
readonly paths: ReadonlyArray<Path>;
|
|
1571
|
+
};
|
|
1572
|
+
/**
|
|
1573
|
+
* Inspectable registration for a transition handler.
|
|
1574
|
+
*
|
|
1575
|
+
* **Details**
|
|
1576
|
+
*
|
|
1577
|
+
* Event, eventless, and completion handlers may declare an upper bound of
|
|
1578
|
+
* possible target paths. A handler without that declaration is explicitly
|
|
1579
|
+
* reported as dynamic. The source, trigger, and reentry behavior are
|
|
1580
|
+
* available without executing the handler.
|
|
1581
|
+
*
|
|
1582
|
+
* @category models
|
|
1583
|
+
* @since 4.0.0
|
|
1584
|
+
*/
|
|
1585
|
+
interface TransitionDefinition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
|
|
1586
|
+
readonly source: SourcePath;
|
|
1587
|
+
readonly trigger: TransitionTrigger<EventTag>;
|
|
1588
|
+
readonly reenter: boolean;
|
|
1589
|
+
readonly targets: TransitionTargets<TargetPath>;
|
|
1590
|
+
}
|
|
1591
|
+
/**
|
|
1592
|
+
* Serializable description of state-owned work.
|
|
1593
|
+
*
|
|
1594
|
+
* Static invoke descriptors expose their lifecycle id and kind without
|
|
1595
|
+
* retaining Effects, closures, services, or child runtimes. A function-valued
|
|
1596
|
+
* invoke factory is reported as dynamic and is never evaluated by inspection.
|
|
1597
|
+
*
|
|
1598
|
+
* @category models
|
|
1599
|
+
* @since 4.0.0
|
|
1600
|
+
*/
|
|
1601
|
+
type ActivityDefinition<SourcePath extends string = string> = Activities.ActivityDefinition<SourcePath>;
|
|
1602
|
+
/**
|
|
1603
|
+
* Transition retained after hierarchy precedence and conflict resolution for
|
|
1604
|
+
* one planned microstep.
|
|
1605
|
+
*
|
|
1606
|
+
* @category models
|
|
1607
|
+
* @since 4.0.0
|
|
1608
|
+
*/
|
|
1609
|
+
interface RetainedTransition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
|
|
1610
|
+
readonly source: SourcePath;
|
|
1611
|
+
readonly trigger: TransitionTrigger<EventTag>;
|
|
1612
|
+
readonly reenter: boolean;
|
|
1613
|
+
/** Path returned by the handler, including a history pseudo-state. */
|
|
1614
|
+
readonly target: TargetPath | undefined;
|
|
1615
|
+
/** Concrete path used after resolving history, otherwise equal to `target`. */
|
|
1616
|
+
readonly resolvedTarget: TargetPath | undefined;
|
|
1052
1617
|
}
|
|
1053
1618
|
/**
|
|
1054
1619
|
* Constructor arguments for a machine initial state function.
|
|
@@ -1095,10 +1660,74 @@ export declare namespace Machine {
|
|
|
1095
1660
|
* @since 4.0.0
|
|
1096
1661
|
*/
|
|
1097
1662
|
type StateIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
1098
|
-
readonly [Key in Extract<keyof States, string>]: States[Key] extends {
|
|
1663
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig | ChoiceStateNodeConfig ? never : States[Key] extends {
|
|
1099
1664
|
readonly states: infer Children;
|
|
1100
1665
|
} ? Children extends StateSchemas ? JoinPath<Prefix, Key> | StateIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : JoinPath<Prefix, Key> : JoinPath<Prefix, Key>;
|
|
1101
1666
|
}[Extract<keyof States, string>];
|
|
1667
|
+
/**
|
|
1668
|
+
* Extracts the transition-only history pseudo-state paths in a definition.
|
|
1669
|
+
*
|
|
1670
|
+
* @category utility types
|
|
1671
|
+
* @since 4.0.0
|
|
1672
|
+
*/
|
|
1673
|
+
type HistoryIdentifier<States extends StateSchemas> = HistoryIdentifierWithPrefix<States>;
|
|
1674
|
+
/** Extracts the transition-only choice pseudo-state paths. */
|
|
1675
|
+
type ChoiceIdentifier<States extends StateSchemas> = ChoiceIdentifierWithPrefix<States>;
|
|
1676
|
+
/**
|
|
1677
|
+
* Extracts every compiled state-node path, including history pseudo-states.
|
|
1678
|
+
*
|
|
1679
|
+
* @category utility types
|
|
1680
|
+
* @since 4.0.0
|
|
1681
|
+
*/
|
|
1682
|
+
type StateNodeIdentifier<States extends StateSchemas> = StateIdentifier<States> | HistoryIdentifier<States> | ChoiceIdentifier<States>;
|
|
1683
|
+
/** @internal */
|
|
1684
|
+
type HistoryIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
1685
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? JoinPath<Prefix, Key> : States[Key] extends {
|
|
1686
|
+
readonly states: infer Children extends StateSchemas;
|
|
1687
|
+
} ? HistoryIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : never;
|
|
1688
|
+
}[Extract<keyof States, string>];
|
|
1689
|
+
/** @internal */
|
|
1690
|
+
type ChoiceIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
1691
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends ChoiceStateNodeConfig ? JoinPath<Prefix, Key> : States[Key] extends {
|
|
1692
|
+
readonly states: infer Children extends StateSchemas;
|
|
1693
|
+
} ? ChoiceIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : never;
|
|
1694
|
+
}[Extract<keyof States, string>];
|
|
1695
|
+
/** Active keys directly declared in a state tree. */
|
|
1696
|
+
type ActiveStateKey<States extends StateSchemas> = {
|
|
1697
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig | ChoiceStateNodeConfig ? never : Key;
|
|
1698
|
+
}[Extract<keyof States, string>];
|
|
1699
|
+
/** History pseudo-state keys directly declared in a state tree. */
|
|
1700
|
+
type HistoryStateKey<States extends StateSchemas> = {
|
|
1701
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? Key : never;
|
|
1702
|
+
}[Extract<keyof States, string>];
|
|
1703
|
+
/** Choice pseudo-state keys directly declared in a state tree. */
|
|
1704
|
+
type ChoiceStateKey<States extends StateSchemas> = {
|
|
1705
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends ChoiceStateNodeConfig ? Key : never;
|
|
1706
|
+
}[Extract<keyof States, string>];
|
|
1707
|
+
/**
|
|
1708
|
+
* Active states that must implement implicit initial-value construction for
|
|
1709
|
+
* shallow history restoration.
|
|
1710
|
+
*
|
|
1711
|
+
* @category utility types
|
|
1712
|
+
* @since 4.0.0
|
|
1713
|
+
*/
|
|
1714
|
+
type RequiredHistoryInitializers<States extends StateSchemas> = [HistoryIdentifier<States>] extends [never] ? never : Extract<RequiredHistoryInitializersWithPrefix<States, States, "">, StateIdentifier<States>>;
|
|
1715
|
+
/** Active parent states that own one or more history pseudo-states. */
|
|
1716
|
+
type HistoryParentIdentifier<States extends StateSchemas> = HistoryIdentifier<States> extends infer HistoryId ? HistoryId extends string ? Extract<ImmediateParentStateIdentifier<HistoryId>, StateIdentifier<States>> : never : never;
|
|
1717
|
+
/** Active parent states that own one or more choice pseudo-states. */
|
|
1718
|
+
type ChoiceParentIdentifier<States extends StateSchemas> = ChoiceIdentifier<States> extends infer ChoiceId ? ChoiceId extends string ? Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>> : never : never;
|
|
1719
|
+
/** History defaults and implicit initializers that remain unimplemented. */
|
|
1720
|
+
type MissingHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, HistoryParentIdentifier<States> | RequiredHistoryInitializers<States>>;
|
|
1721
|
+
/** Choice-owning active parents that remain unimplemented. */
|
|
1722
|
+
type MissingChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, ChoiceParentIdentifier<States>>;
|
|
1723
|
+
/** @internal Readiness proof for required choice resolvers. */
|
|
1724
|
+
type EnsureChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [ChoiceIdentifier<States>] extends [never] ? unknown : [MissingChoiceImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
1725
|
+
readonly "~effect/Machine/MissingChoiceImplementation": MissingChoiceImplementations<States, UnhandledStates>;
|
|
1726
|
+
};
|
|
1727
|
+
/** @internal Readiness proof required by planning and managed execution. */
|
|
1728
|
+
type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = ([HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
1729
|
+
readonly "~effect/Machine/MissingHistoryImplementation": MissingHistoryImplementations<States, UnhandledStates>;
|
|
1730
|
+
}) & EnsureChoiceImplementations<States, UnhandledStates>;
|
|
1102
1731
|
/**
|
|
1103
1732
|
* Extracts a state-tree node by state path.
|
|
1104
1733
|
*
|
|
@@ -1144,13 +1773,6 @@ export declare namespace Machine {
|
|
|
1144
1773
|
* @since 4.0.0
|
|
1145
1774
|
*/
|
|
1146
1775
|
type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> = EventOf<Events> | InitialEvent;
|
|
1147
|
-
/**
|
|
1148
|
-
* Runtime capability specialized to a machine's event protocols.
|
|
1149
|
-
*
|
|
1150
|
-
* @category utility types
|
|
1151
|
-
* @since 4.0.0
|
|
1152
|
-
*/
|
|
1153
|
-
type RuntimeEffect<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>> = Effect.Effect<Runtime<EventOf<Events>, EmitOf<Emits>>, never, Runtime.Requirement<EventOf<Events>, EmitOf<Emits>>>;
|
|
1154
1776
|
/**
|
|
1155
1777
|
* Extracts a state value from a state definition by identifier.
|
|
1156
1778
|
*
|
|
@@ -1214,8 +1836,8 @@ export declare namespace Machine {
|
|
|
1214
1836
|
} ? OutputByIdentifier<States, StateId> : never;
|
|
1215
1837
|
type CompoundCompletionOutput<States extends StateSchemas, Children extends StateSchemas, Prefix extends StateIdentifier<States>> = UndefinedIfNever<CompoundCompletionOutputRaw<States, Children, Prefix>>;
|
|
1216
1838
|
type CompoundCompletionOutputRaw<States extends StateSchemas, Children extends StateSchemas, Prefix extends StateIdentifier<States>> = {
|
|
1217
|
-
readonly [Key in
|
|
1218
|
-
}[
|
|
1839
|
+
readonly [Key in ActiveStateKey<Children>]: DirectFinalCompletionOutput<States, Extract<JoinPath<Prefix, Key>, StateIdentifier<States>>>;
|
|
1840
|
+
}[ActiveStateKey<Children>];
|
|
1219
1841
|
/**
|
|
1220
1842
|
* Extracts the output passed when a state node completes.
|
|
1221
1843
|
*
|
|
@@ -1317,6 +1939,12 @@ export declare namespace Machine {
|
|
|
1317
1939
|
readonly path: string;
|
|
1318
1940
|
readonly output?: unknown;
|
|
1319
1941
|
}
|
|
1942
|
+
/** Encoded values and paths retained by one history pseudo-state. */
|
|
1943
|
+
interface EncodedSnapshotHistoryEntry {
|
|
1944
|
+
readonly mode: "shallow" | "deep";
|
|
1945
|
+
readonly active: ReadonlyArray<string>;
|
|
1946
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
1947
|
+
}
|
|
1320
1948
|
/**
|
|
1321
1949
|
* Normalized data representation of a machine snapshot.
|
|
1322
1950
|
*
|
|
@@ -1333,6 +1961,7 @@ export declare namespace Machine {
|
|
|
1333
1961
|
readonly _tag: "MachineSnapshot";
|
|
1334
1962
|
readonly active: ReadonlyArray<EncodedSnapshotState>;
|
|
1335
1963
|
readonly completed?: ReadonlyArray<EncodedSnapshotCompletion>;
|
|
1964
|
+
readonly history?: Readonly<Record<string, EncodedSnapshotHistoryEntry>>;
|
|
1336
1965
|
}
|
|
1337
1966
|
/**
|
|
1338
1967
|
* Completed state path and its resolved output value.
|
|
@@ -1344,6 +1973,12 @@ export declare namespace Machine {
|
|
|
1344
1973
|
readonly path: string;
|
|
1345
1974
|
readonly output: unknown;
|
|
1346
1975
|
}
|
|
1976
|
+
/** Decoded values and paths retained by one history pseudo-state. */
|
|
1977
|
+
interface SnapshotHistoryEntry {
|
|
1978
|
+
readonly mode: "shallow" | "deep";
|
|
1979
|
+
readonly active: ReadonlyArray<string>;
|
|
1980
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
1981
|
+
}
|
|
1347
1982
|
/**
|
|
1348
1983
|
* Carries lifecycle metadata required to resume planning from a cloned
|
|
1349
1984
|
* snapshot.
|
|
@@ -1362,6 +1997,7 @@ export declare namespace Machine {
|
|
|
1362
1997
|
*/
|
|
1363
1998
|
interface SnapshotMetadata {
|
|
1364
1999
|
readonly completed?: ReadonlyArray<SnapshotCompletion>;
|
|
2000
|
+
readonly history?: Readonly<Record<string, SnapshotHistoryEntry>>;
|
|
1365
2001
|
}
|
|
1366
2002
|
/**
|
|
1367
2003
|
* Atomic statechart snapshot carrying path identity separately from the
|
|
@@ -1418,8 +2054,8 @@ export declare namespace Machine {
|
|
|
1418
2054
|
* @since 4.0.0
|
|
1419
2055
|
*/
|
|
1420
2056
|
type SnapshotWithPrefix<States extends StateSchemas, Prefix extends string> = {
|
|
1421
|
-
readonly [Key in
|
|
1422
|
-
}[
|
|
2057
|
+
readonly [Key in ActiveStateKey<States>]: SnapshotByIdentifierWithPath<States, Key, JoinPath<Prefix, Key>>;
|
|
2058
|
+
}[ActiveStateKey<States>];
|
|
1423
2059
|
/**
|
|
1424
2060
|
* Extracts child snapshots under a parallel parent path prefix, keyed by
|
|
1425
2061
|
* child region.
|
|
@@ -1428,7 +2064,7 @@ export declare namespace Machine {
|
|
|
1428
2064
|
* @since 4.0.0
|
|
1429
2065
|
*/
|
|
1430
2066
|
type SnapshotRegionsWithPrefix<States extends StateSchemas, Prefix extends string> = {
|
|
1431
|
-
readonly [Key in
|
|
2067
|
+
readonly [Key in ActiveStateKey<States>]: SnapshotByIdentifierWithPath<States, Key, JoinPath<Prefix, Key>>;
|
|
1432
2068
|
};
|
|
1433
2069
|
/**
|
|
1434
2070
|
* Extracts a snapshot for a state node while preserving its full path.
|
|
@@ -1436,12 +2072,23 @@ export declare namespace Machine {
|
|
|
1436
2072
|
* @category utility types
|
|
1437
2073
|
* @since 4.0.0
|
|
1438
2074
|
*/
|
|
1439
|
-
type SnapshotByIdentifierWithPath<States extends StateSchemas, StateId extends
|
|
2075
|
+
type SnapshotByIdentifierWithPath<States extends StateSchemas, StateId extends ActiveStateKey<States>, Path extends string> = States[StateId] extends {
|
|
1440
2076
|
readonly type: "parallel";
|
|
1441
2077
|
readonly states: infer Children;
|
|
1442
2078
|
} ? Children extends StateSchemas ? ParallelSnapshot<Path, NodeSchema<States[StateId]>["Type"], SnapshotRegionsWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]> : States[StateId] extends {
|
|
1443
2079
|
readonly states: infer Children;
|
|
1444
2080
|
} ? Children extends StateSchemas ? CompoundSnapshot<Path, NodeSchema<States[StateId]>["Type"], SnapshotWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]>;
|
|
2081
|
+
/**
|
|
2082
|
+
* Extracts a complete root snapshot whose selected configuration contains a
|
|
2083
|
+
* particular active state.
|
|
2084
|
+
*
|
|
2085
|
+
* Parallel ancestors still require every region, while compound ancestors
|
|
2086
|
+
* are narrowed to the branch leading to `Owner`.
|
|
2087
|
+
*
|
|
2088
|
+
* @category utility types
|
|
2089
|
+
* @since 4.0.0
|
|
2090
|
+
*/
|
|
2091
|
+
type CompleteSnapshotContaining<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotWithPrefix<States, Owner, "">;
|
|
1445
2092
|
/**
|
|
1446
2093
|
* Extracts the union of statechart snapshots represented by a state
|
|
1447
2094
|
* definition.
|
|
@@ -1450,8 +2097,8 @@ export declare namespace Machine {
|
|
|
1450
2097
|
* @since 4.0.0
|
|
1451
2098
|
*/
|
|
1452
2099
|
type Snapshot<States extends StateSchemas> = {
|
|
1453
|
-
readonly [StateId in
|
|
1454
|
-
}[
|
|
2100
|
+
readonly [StateId in ActiveStateKey<States>]: SnapshotByIdentifier<States, StateId & StateIdentifier<States>>;
|
|
2101
|
+
}[ActiveStateKey<States>];
|
|
1455
2102
|
/**
|
|
1456
2103
|
* Extracts the root state identifier from a state path.
|
|
1457
2104
|
*
|
|
@@ -1485,7 +2132,24 @@ export declare namespace Machine {
|
|
|
1485
2132
|
*/
|
|
1486
2133
|
type EventByTag<Events extends ReadonlyArray<TaggedSchema>, Tag extends TagOf<Events[number]>> = Extract<EventOf<Events>, {
|
|
1487
2134
|
readonly _tag: Tag;
|
|
1488
|
-
}
|
|
2135
|
+
}> | (EventOf<Events> extends infer Event ? Event extends {
|
|
2136
|
+
readonly _tag: infer EventTag extends PropertyKey;
|
|
2137
|
+
} ? [EventTag] extends [Tag] ? never : [Tag] extends [EventTag] ? Omit<Event, "_tag"> & {
|
|
2138
|
+
readonly _tag: Tag;
|
|
2139
|
+
} : never : never : never);
|
|
2140
|
+
/**
|
|
2141
|
+
* Opaque state construction returned by a builder's `.from` method.
|
|
2142
|
+
*
|
|
2143
|
+
* The machine resolves the instruction through the selected state schema
|
|
2144
|
+
* while planning. Its decoded value is intentionally unavailable until
|
|
2145
|
+
* planning succeeds.
|
|
2146
|
+
*
|
|
2147
|
+
* @category models
|
|
2148
|
+
* @since 4.0.0
|
|
2149
|
+
*/
|
|
2150
|
+
interface StateConstruction<Result> {
|
|
2151
|
+
readonly [Topology.StateConstructionTypeId]: Result;
|
|
2152
|
+
}
|
|
1489
2153
|
/**
|
|
1490
2154
|
* Machine-bound target instruction accepted from transition handlers.
|
|
1491
2155
|
*
|
|
@@ -1493,13 +2157,42 @@ export declare namespace Machine {
|
|
|
1493
2157
|
* @since 4.0.0
|
|
1494
2158
|
*/
|
|
1495
2159
|
interface Target<States extends StateSchemas, StateId extends StateIdentifier<States>> {
|
|
1496
|
-
readonly [
|
|
2160
|
+
readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId;
|
|
2161
|
+
readonly [Topology.TargetSnapshotTypeId]?: SnapshotByIdentifier<States, StateId>;
|
|
1497
2162
|
readonly path: StateId;
|
|
1498
2163
|
readonly value: StateByIdentifier<States, StateId>;
|
|
1499
2164
|
readonly values?: Partial<{
|
|
1500
2165
|
readonly [AncestorStateId in StateIdentifier<States>]: StateByIdentifier<States, AncestorStateId>;
|
|
1501
2166
|
}>;
|
|
1502
2167
|
}
|
|
2168
|
+
/**
|
|
2169
|
+
* Transition instruction that restores a history pseudo-state's parent.
|
|
2170
|
+
*
|
|
2171
|
+
* Unlike ordinary targets, history targets carry no state value. The
|
|
2172
|
+
* planner resolves the remembered concrete configuration, or evaluates the
|
|
2173
|
+
* history node's typed default when no record exists.
|
|
2174
|
+
*
|
|
2175
|
+
* @category models
|
|
2176
|
+
* @since 4.0.0
|
|
2177
|
+
*/
|
|
2178
|
+
interface HistoryTarget<States extends StateSchemas, HistoryId extends HistoryIdentifier<States>> {
|
|
2179
|
+
readonly [Topology.HistoryTargetTypeId]: typeof Topology.HistoryTargetTypeId;
|
|
2180
|
+
readonly path: HistoryId;
|
|
2181
|
+
readonly parent: Extract<ParentPath<HistoryId>, StateIdentifier<States>>;
|
|
2182
|
+
}
|
|
2183
|
+
/** Branded transient target instruction used while constructing initial states. */
|
|
2184
|
+
interface ChoiceTargetInstruction<ChoiceId extends string = string> {
|
|
2185
|
+
readonly [Topology.ChoiceTargetTypeId]: typeof Topology.ChoiceTargetTypeId;
|
|
2186
|
+
readonly path: ChoiceId;
|
|
2187
|
+
readonly parent: ParentPath<ChoiceId>;
|
|
2188
|
+
readonly values?: Readonly<Record<string, unknown>>;
|
|
2189
|
+
}
|
|
2190
|
+
/** Transition instruction that enters a transient choice pseudo-state. */
|
|
2191
|
+
interface ChoiceTarget<States extends StateSchemas, ChoiceId extends ChoiceIdentifier<States>> extends ChoiceTargetInstruction<ChoiceId> {
|
|
2192
|
+
readonly parent: Extract<ParentPath<ChoiceId>, StateIdentifier<States>>;
|
|
2193
|
+
}
|
|
2194
|
+
/** Builder containing only history pseudo-state paths. */
|
|
2195
|
+
type HistoryTargetBuilder<States extends StateSchemas> = HistoryTargetBuilderWithPrefix<States, States, "">;
|
|
1503
2196
|
/**
|
|
1504
2197
|
* Builder for complete transition snapshots.
|
|
1505
2198
|
*
|
|
@@ -1512,6 +2205,13 @@ export declare namespace Machine {
|
|
|
1512
2205
|
* @since 4.0.0
|
|
1513
2206
|
*/
|
|
1514
2207
|
type FullTargetBuilder<States extends StateSchemas> = FullSnapshotBuilderWithPrefix<States>;
|
|
2208
|
+
/**
|
|
2209
|
+
* Builder for a complete fallback configuration containing a history owner.
|
|
2210
|
+
*
|
|
2211
|
+
* @category utility types
|
|
2212
|
+
* @since 4.0.0
|
|
2213
|
+
*/
|
|
2214
|
+
type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotBuilderWithPrefix<States, Owner>;
|
|
1515
2215
|
/**
|
|
1516
2216
|
* Builder for source-local transition targets.
|
|
1517
2217
|
*
|
|
@@ -1523,7 +2223,7 @@ export declare namespace Machine {
|
|
|
1523
2223
|
* @category utility types
|
|
1524
2224
|
* @since 4.0.0
|
|
1525
2225
|
*/
|
|
1526
|
-
type LocalTargetBuilder<States extends StateSchemas, Source extends
|
|
2226
|
+
type LocalTargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = NearestCompoundScope<States, Source> extends infer Scope ? [Scope] extends [never] ? {} : Scope extends StateIdentifier<States> ? LocalTargetBuilderForScope<States, Scope, Source> : {} : {};
|
|
1527
2227
|
/**
|
|
1528
2228
|
* Builder for partial transition targets within the active source root.
|
|
1529
2229
|
*
|
|
@@ -1535,7 +2235,7 @@ export declare namespace Machine {
|
|
|
1535
2235
|
* @category utility types
|
|
1536
2236
|
* @since 4.0.0
|
|
1537
2237
|
*/
|
|
1538
|
-
type BranchTargetBuilder<States extends StateSchemas, Source extends
|
|
2238
|
+
type BranchTargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = BranchTargetBuilderForRoot<States, Extract<RootStateIdentifier<Source>, ActiveStateKey<States>>, Source>;
|
|
1539
2239
|
/**
|
|
1540
2240
|
* Machine-bound target builders available in transition contexts.
|
|
1541
2241
|
*
|
|
@@ -1555,7 +2255,7 @@ export declare namespace Machine {
|
|
|
1555
2255
|
* @category models
|
|
1556
2256
|
* @since 4.0.0
|
|
1557
2257
|
*/
|
|
1558
|
-
interface TargetBuilder<States extends StateSchemas, Source extends
|
|
2258
|
+
interface TargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
|
|
1559
2259
|
/**
|
|
1560
2260
|
* Moves to another state in the same local group. The value of the state
|
|
1561
2261
|
* containing that group, and values in other active branches, are kept.
|
|
@@ -1584,30 +2284,8 @@ export declare namespace Machine {
|
|
|
1584
2284
|
* @since 4.0.0
|
|
1585
2285
|
*/
|
|
1586
2286
|
readonly full: FullTargetBuilder<States>;
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
* Stages an Effect to run after the current machine step is planned.
|
|
1590
|
-
*
|
|
1591
|
-
* The two-argument overload returns `next` after staging the Effect, which is
|
|
1592
|
-
* useful when a handler should stage one action and return a target without
|
|
1593
|
-
* introducing an Effect generator.
|
|
1594
|
-
*
|
|
1595
|
-
* @category models
|
|
1596
|
-
* @since 4.0.0
|
|
1597
|
-
*/
|
|
1598
|
-
interface Action {
|
|
1599
|
-
<E, R>(effect: Effect.Effect<void, E, R>): Effect.Effect<void, never, ActionRequirement<E, R>>;
|
|
1600
|
-
<E, R, Next>(effect: Effect.Effect<void, E, R>, next: Next): Effect.Effect<Next, never, ActionRequirement<E, R>>;
|
|
1601
|
-
}
|
|
1602
|
-
/**
|
|
1603
|
-
* Planning capabilities shared by transition and lifecycle callbacks.
|
|
1604
|
-
*
|
|
1605
|
-
* @category models
|
|
1606
|
-
* @since 4.0.0
|
|
1607
|
-
*/
|
|
1608
|
-
interface PlanningCapabilities<Events, Emits> {
|
|
1609
|
-
readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError, Runtime.Requirement<Events, Emits>>;
|
|
1610
|
-
readonly emit: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError, Runtime.Requirement<Events, Emits>>;
|
|
2287
|
+
/** Restores a declared shallow or deep history pseudo-state. */
|
|
2288
|
+
readonly history: HistoryTargetBuilder<States>;
|
|
1611
2289
|
}
|
|
1612
2290
|
/**
|
|
1613
2291
|
* Context passed to a state/event handler.
|
|
@@ -1615,12 +2293,13 @@ export declare namespace Machine {
|
|
|
1615
2293
|
* @category models
|
|
1616
2294
|
* @since 4.0.0
|
|
1617
2295
|
*/
|
|
1618
|
-
interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R>
|
|
2296
|
+
interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
1619
2297
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1620
2298
|
readonly parent: ParentStateValue<States, StateId>;
|
|
1621
2299
|
readonly parents: ParentStateValues<States, StateId>;
|
|
2300
|
+
/** Complete logical configuration captured at the start of this microstep. */
|
|
2301
|
+
readonly snapshot: Snapshot<States>;
|
|
1622
2302
|
readonly event: EventByTag<Events, EventTag>;
|
|
1623
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
1624
2303
|
/**
|
|
1625
2304
|
* Provides typed builders for choosing the next active state from this
|
|
1626
2305
|
* handler. Each builder documents which existing state values it keeps.
|
|
@@ -1635,12 +2314,11 @@ export declare namespace Machine {
|
|
|
1635
2314
|
* @category models
|
|
1636
2315
|
* @since 4.0.0
|
|
1637
2316
|
*/
|
|
1638
|
-
interface StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>>
|
|
2317
|
+
interface StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
1639
2318
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1640
2319
|
readonly parent: ParentStateValue<States, StateId>;
|
|
1641
2320
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1642
2321
|
readonly event: LifecycleEvent<Events>;
|
|
1643
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
1644
2322
|
}
|
|
1645
2323
|
/**
|
|
1646
2324
|
* Context passed to an invoked child process source.
|
|
@@ -1653,7 +2331,6 @@ export declare namespace Machine {
|
|
|
1653
2331
|
readonly parent: ParentStateValue<States, StateId>;
|
|
1654
2332
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1655
2333
|
readonly event: LifecycleEvent<Events>;
|
|
1656
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
1657
2334
|
}
|
|
1658
2335
|
/**
|
|
1659
2336
|
* Context passed to an invoked child process active snapshot mapper.
|
|
@@ -1683,12 +2360,13 @@ export declare namespace Machine {
|
|
|
1683
2360
|
* @category models
|
|
1684
2361
|
* @since 4.0.0
|
|
1685
2362
|
*/
|
|
1686
|
-
interface AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>>
|
|
2363
|
+
interface AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
1687
2364
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1688
2365
|
readonly parent: ParentStateValue<States, StateId>;
|
|
1689
2366
|
readonly parents: ParentStateValues<States, StateId>;
|
|
2367
|
+
/** Complete logical configuration captured at the start of this microstep. */
|
|
2368
|
+
readonly snapshot: Snapshot<States>;
|
|
1690
2369
|
readonly event: LifecycleEvent<Events>;
|
|
1691
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
1692
2370
|
/**
|
|
1693
2371
|
* Provides typed builders for choosing the next active state from this
|
|
1694
2372
|
* eventless handler. Each builder documents which existing state values it
|
|
@@ -1704,13 +2382,14 @@ export declare namespace Machine {
|
|
|
1704
2382
|
* @category models
|
|
1705
2383
|
* @since 4.0.0
|
|
1706
2384
|
*/
|
|
1707
|
-
interface DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>>
|
|
2385
|
+
interface DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
1708
2386
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1709
2387
|
readonly parent: ParentStateValue<States, StateId>;
|
|
1710
2388
|
readonly parents: ParentStateValues<States, StateId>;
|
|
2389
|
+
/** Complete logical configuration captured at the start of this microstep. */
|
|
2390
|
+
readonly snapshot: Snapshot<States>;
|
|
1711
2391
|
readonly event: LifecycleEvent<Events>;
|
|
1712
2392
|
readonly output: CompletionOutputByIdentifier<States, StateId>;
|
|
1713
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
1714
2393
|
/**
|
|
1715
2394
|
* Provides typed builders for choosing the next active state after this
|
|
1716
2395
|
* state completes. Each builder documents which existing state values it
|
|
@@ -1720,6 +2399,15 @@ export declare namespace Machine {
|
|
|
1720
2399
|
*/
|
|
1721
2400
|
readonly target: TargetBuilder<States, StateId>;
|
|
1722
2401
|
}
|
|
2402
|
+
/** Context passed to a transient choice resolver. There is no `state` value. */
|
|
2403
|
+
interface ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
|
|
2404
|
+
readonly parent: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
|
|
2405
|
+
readonly parents: {
|
|
2406
|
+
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, StateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
2407
|
+
};
|
|
2408
|
+
readonly event: LifecycleEvent<Events>;
|
|
2409
|
+
readonly target: TargetBuilder<States, ChoiceId>;
|
|
2410
|
+
}
|
|
1723
2411
|
/**
|
|
1724
2412
|
* Context passed to a final state output function.
|
|
1725
2413
|
*
|
|
@@ -1742,7 +2430,7 @@ export declare namespace Machine {
|
|
|
1742
2430
|
readonly type: "parallel";
|
|
1743
2431
|
readonly states: infer Children extends StateSchemas;
|
|
1744
2432
|
} ? {
|
|
1745
|
-
readonly [Key in
|
|
2433
|
+
readonly [Key in ActiveStateKey<Children>]: CompletionOutputByIdentifier<States, Extract<JoinPath<StateId, Key>, StateIdentifier<States>>>;
|
|
1746
2434
|
} : never;
|
|
1747
2435
|
/**
|
|
1748
2436
|
* Context passed to a parallel state output function.
|
|
@@ -1763,14 +2451,18 @@ export declare namespace Machine {
|
|
|
1763
2451
|
* @category utility types
|
|
1764
2452
|
* @since 4.0.0
|
|
1765
2453
|
*/
|
|
1766
|
-
type StateActionResult<E, R> =
|
|
2454
|
+
type StateActionResult<E, R> = undefined;
|
|
1767
2455
|
/**
|
|
1768
2456
|
* Return value accepted from a machine initial state function.
|
|
1769
2457
|
*
|
|
1770
2458
|
* @category utility types
|
|
1771
2459
|
* @since 4.0.0
|
|
1772
2460
|
*/
|
|
1773
|
-
type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> |
|
|
2461
|
+
type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> | InitialSnapshot<States> | StateConstruction<Snapshot<States> | InitialSnapshot<States>>;
|
|
2462
|
+
/** Initial snapshots may transiently terminate in a declared choice node. */
|
|
2463
|
+
type InitialSnapshot<States extends StateSchemas> = {
|
|
2464
|
+
readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">;
|
|
2465
|
+
}[ActiveStateKey<States>];
|
|
1774
2466
|
/**
|
|
1775
2467
|
* Return value accepted from transition handlers.
|
|
1776
2468
|
*
|
|
@@ -1783,7 +2475,9 @@ export declare namespace Machine {
|
|
|
1783
2475
|
* @category utility types
|
|
1784
2476
|
* @since 4.0.0
|
|
1785
2477
|
*/
|
|
1786
|
-
type HandlerResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> |
|
|
2478
|
+
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>>> | void;
|
|
2479
|
+
/** A choice resolver must always select a typed target synchronously. */
|
|
2480
|
+
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>>>;
|
|
1787
2481
|
/**
|
|
1788
2482
|
* Extracts the union of handler return values from a handler map.
|
|
1789
2483
|
*
|
|
@@ -1819,6 +2513,24 @@ export declare namespace Machine {
|
|
|
1819
2513
|
* @since 4.0.0
|
|
1820
2514
|
*/
|
|
1821
2515
|
type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
2516
|
+
/** Extracts the return value from an implicit initial child implementation. */
|
|
2517
|
+
type StateInitialReturn<Config> = Config extends {
|
|
2518
|
+
readonly initial?: infer Initial;
|
|
2519
|
+
} ? NonNullable<Initial> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
2520
|
+
/** Extracts the return values from a state's history defaults. */
|
|
2521
|
+
type HistoryDefaultReturn<Config> = Config extends {
|
|
2522
|
+
readonly history?: infer History;
|
|
2523
|
+
} ? {
|
|
2524
|
+
readonly [Key in keyof NonNullable<History>]: NonNullable<History>[Key] extends {
|
|
2525
|
+
readonly default: (...args: any) => infer Ret;
|
|
2526
|
+
} ? Ret : never;
|
|
2527
|
+
}[keyof NonNullable<History>] : never;
|
|
2528
|
+
/** Extracts the return value from a choice resolver. */
|
|
2529
|
+
type ChoiceReturn<Config> = Config extends {
|
|
2530
|
+
readonly choice: {
|
|
2531
|
+
readonly transition: (...args: any) => infer Ret;
|
|
2532
|
+
};
|
|
2533
|
+
} ? Ret : never;
|
|
1822
2534
|
/**
|
|
1823
2535
|
* Extracts the return value from an event transition config.
|
|
1824
2536
|
*
|
|
@@ -1945,7 +2657,7 @@ export declare namespace Machine {
|
|
|
1945
2657
|
*/
|
|
1946
2658
|
type AlwaysReturn<Config> = Config extends {
|
|
1947
2659
|
readonly always?: infer Always;
|
|
1948
|
-
} ? NonNullable<Always
|
|
2660
|
+
} ? EventTransitionReturn<NonNullable<Always>> : never;
|
|
1949
2661
|
/**
|
|
1950
2662
|
* Extracts the return value from a state completion transition.
|
|
1951
2663
|
*
|
|
@@ -1954,7 +2666,7 @@ export declare namespace Machine {
|
|
|
1954
2666
|
*/
|
|
1955
2667
|
type DoneReturn<Config> = Config extends {
|
|
1956
2668
|
readonly onDone?: infer OnDone;
|
|
1957
|
-
} ? NonNullable<OnDone
|
|
2669
|
+
} ? EventTransitionReturn<NonNullable<OnDone>> : never;
|
|
1958
2670
|
/**
|
|
1959
2671
|
* Extracts the return value from a final state output function.
|
|
1960
2672
|
*
|
|
@@ -1970,7 +2682,7 @@ export declare namespace Machine {
|
|
|
1970
2682
|
* @category utility types
|
|
1971
2683
|
* @since 4.0.0
|
|
1972
2684
|
*/
|
|
1973
|
-
type ConfigServices<Config> = Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | InvokeRequirements<Config>;
|
|
2685
|
+
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>;
|
|
1974
2686
|
/**
|
|
1975
2687
|
* Configuration for invoking a child process while a state is active.
|
|
1976
2688
|
*
|
|
@@ -1986,6 +2698,8 @@ export declare namespace Machine {
|
|
|
1986
2698
|
readonly requirements: Types.Covariant<ChildRequirements>;
|
|
1987
2699
|
readonly initialError: Types.Covariant<ChildInitialError>;
|
|
1988
2700
|
};
|
|
2701
|
+
/** @internal Serializable descriptor metadata used by inspection. */
|
|
2702
|
+
readonly [Activities.ActivityMetadataTypeId]?: Activities.StaticActivityMetadata;
|
|
1989
2703
|
readonly id: string;
|
|
1990
2704
|
/**
|
|
1991
2705
|
* Optional parent-local address for sending events to this invocation.
|
|
@@ -2011,6 +2725,9 @@ export declare namespace Machine {
|
|
|
2011
2725
|
readonly initialError: Types.Covariant<InitialError>;
|
|
2012
2726
|
};
|
|
2013
2727
|
}
|
|
2728
|
+
interface InvokeDefinitionValue {
|
|
2729
|
+
readonly [InvokeTypeId]: unknown;
|
|
2730
|
+
}
|
|
2014
2731
|
/**
|
|
2015
2732
|
* State-bound configuration for invoked child processes.
|
|
2016
2733
|
*
|
|
@@ -2022,7 +2739,7 @@ export declare namespace Machine {
|
|
|
2022
2739
|
* @category models
|
|
2023
2740
|
* @since 4.0.0
|
|
2024
2741
|
*/
|
|
2025
|
-
type InvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> =
|
|
2742
|
+
type InvokeDefinition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = InvokeDefinitionValue | ReadonlyArray<InvokeDefinitionValue> | ((context: InvokeContext<States, Events, Emits, StateId>) => InvokeDefinitionValue | ReadonlyArray<InvokeDefinitionValue>);
|
|
2026
2743
|
type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
2027
2744
|
readonly output: Schema.Top;
|
|
2028
2745
|
} ? {
|
|
@@ -2042,18 +2759,83 @@ export declare namespace Machine {
|
|
|
2042
2759
|
* @since 4.0.0
|
|
2043
2760
|
*/
|
|
2044
2761
|
type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = {
|
|
2045
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId
|
|
2046
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId
|
|
2762
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2763
|
+
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2047
2764
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
|
|
2048
|
-
readonly always?: (context: AlwaysContext<States, Events, Emits, StateId
|
|
2049
|
-
|
|
2765
|
+
readonly always?: ((context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2766
|
+
/** Statically declared upper bound of possible target paths. */
|
|
2767
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2768
|
+
readonly transition: (context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2769
|
+
};
|
|
2770
|
+
readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2771
|
+
/** Statically declared upper bound of possible target paths. */
|
|
2772
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2773
|
+
readonly transition: (context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2774
|
+
};
|
|
2050
2775
|
readonly on?: {
|
|
2051
|
-
readonly [EventTag in TagOf<Events[number]>]?: ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R
|
|
2776
|
+
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>) | {
|
|
2052
2777
|
readonly reenter?: boolean;
|
|
2053
|
-
|
|
2778
|
+
/**
|
|
2779
|
+
* Upper bound of state or history paths this handler may target.
|
|
2780
|
+
* Returning `void` is always permitted. Declaring a parent state also
|
|
2781
|
+
* permits concrete descendant targets below it.
|
|
2782
|
+
*/
|
|
2783
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2784
|
+
readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2054
2785
|
};
|
|
2055
2786
|
};
|
|
2787
|
+
readonly initial?: StateInitialHandler<States, Events, Emits, StateId>;
|
|
2056
2788
|
} & ActiveOutputHandlerConfig<States, Events, StateId>;
|
|
2789
|
+
/** Values supplied when a statechart implicitly enters a state's initial children. */
|
|
2790
|
+
type StateInitialValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
2791
|
+
readonly type: "parallel";
|
|
2792
|
+
readonly states: infer Children extends StateSchemas;
|
|
2793
|
+
} ? {
|
|
2794
|
+
readonly [Key in ActiveStateKey<Children>]: NodeSchema<Children[Key]>["Type"];
|
|
2795
|
+
} : Node extends {
|
|
2796
|
+
readonly states: infer Children extends StateSchemas;
|
|
2797
|
+
readonly initial: infer Initial;
|
|
2798
|
+
} ? Initial extends ActiveStateKey<Children> ? NodeSchema<Children[Initial]>["Type"] : never : never : never;
|
|
2799
|
+
/** Context passed to an implicit child-state initializer. */
|
|
2800
|
+
type StateInitialContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = StateActionContext<States, Events, Emits, StateId>;
|
|
2801
|
+
/** Initial child value implementation for a compound or parallel state. */
|
|
2802
|
+
type StateInitialHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = (context: StateInitialContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateInitialValue<States, StateId>;
|
|
2803
|
+
/** Context used only when a history node has no previously captured record. */
|
|
2804
|
+
interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
2805
|
+
readonly event: LifecycleEvent<Events>;
|
|
2806
|
+
readonly target: HistoryDefaultTargetBuilder<States, ParentId>;
|
|
2807
|
+
readonly parent: ParentId;
|
|
2808
|
+
}
|
|
2809
|
+
/**
|
|
2810
|
+
* Typed fallback evaluated when a history node has no record yet.
|
|
2811
|
+
*
|
|
2812
|
+
* The fallback constructs a complete root configuration containing the
|
|
2813
|
+
* history owner. This makes the default independent of the transition source
|
|
2814
|
+
* and provides every inactive ancestor and required parallel region.
|
|
2815
|
+
*/
|
|
2816
|
+
type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => CompleteSnapshotContaining<States, ParentId> | StateConstruction<CompleteSnapshotContaining<States, ParentId>>;
|
|
2817
|
+
/** Default implementations keyed by direct history child. */
|
|
2818
|
+
type HistoryDefaultConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>, Children extends StateSchemas> = {
|
|
2819
|
+
readonly [Key in HistoryStateKey<Children>]?: {
|
|
2820
|
+
readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>;
|
|
2821
|
+
};
|
|
2822
|
+
};
|
|
2823
|
+
/** Required implementation for a choice pseudo-state. */
|
|
2824
|
+
interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
|
|
2825
|
+
readonly choice: {
|
|
2826
|
+
/** Statically inspectable upper bound of every possible target. */
|
|
2827
|
+
readonly targets: readonly [StateNodeIdentifier<States>, ...ReadonlyArray<StateNodeIdentifier<States>>];
|
|
2828
|
+
readonly transition: (context: ChoiceContext<States, Events, Emits, ChoiceId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => ChoiceResult<States, any, any>;
|
|
2829
|
+
};
|
|
2830
|
+
readonly entry?: never;
|
|
2831
|
+
readonly exit?: never;
|
|
2832
|
+
readonly invoke?: never;
|
|
2833
|
+
readonly always?: never;
|
|
2834
|
+
readonly on?: never;
|
|
2835
|
+
readonly onDone?: never;
|
|
2836
|
+
readonly output?: never;
|
|
2837
|
+
readonly initial?: never;
|
|
2838
|
+
}
|
|
2057
2839
|
/**
|
|
2058
2840
|
* Configuration accepted for a final state.
|
|
2059
2841
|
*
|
|
@@ -2061,7 +2843,7 @@ export declare namespace Machine {
|
|
|
2061
2843
|
* @since 4.0.0
|
|
2062
2844
|
*/
|
|
2063
2845
|
type FinalStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = {
|
|
2064
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId
|
|
2846
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2065
2847
|
readonly exit?: never;
|
|
2066
2848
|
readonly always?: never;
|
|
2067
2849
|
readonly onDone?: never;
|
|
@@ -2076,28 +2858,48 @@ export declare namespace Machine {
|
|
|
2076
2858
|
type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = NodeByIdentifier<States, StateId> extends {
|
|
2077
2859
|
readonly type: "final";
|
|
2078
2860
|
} ? FinalStateConfig<States, Events, Emits, StateId> : ActiveStateConfig<States, Events, Emits, StateId, E, R>;
|
|
2861
|
+
type HandlerNodeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, E, R> = Path extends ChoiceIdentifier<States> ? ChoiceStateConfig<States, Events, Emits, Path> : Path extends StateIdentifier<States> ? HandlerConfig<States, Events, Emits, Path, E, R> : never;
|
|
2079
2862
|
type HandlerChildren<Node> = Node extends {
|
|
2080
2863
|
readonly states: infer Children extends StateSchemas;
|
|
2081
2864
|
} ? Children : never;
|
|
2082
|
-
type
|
|
2865
|
+
type HandlerNodeId<States extends StateSchemas, Path extends string> = Extract<Path, StateNodeIdentifier<States>>;
|
|
2083
2866
|
type HandlerConfigPart<Config> = {
|
|
2084
2867
|
readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key];
|
|
2085
2868
|
};
|
|
2086
|
-
type
|
|
2869
|
+
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
|
|
2870
|
+
readonly states?: infer Children;
|
|
2871
|
+
} ? NonNullable<Children> : never : never;
|
|
2872
|
+
type HandlerNodeByPath<States extends StateSchemas, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
2873
|
+
readonly states: infer Children extends StateSchemas;
|
|
2874
|
+
} ? HandlerNodeByPath<Children, Rest> : never : never : Path extends keyof States ? States[Path] : never;
|
|
2875
|
+
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;
|
|
2876
|
+
type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
2877
|
+
readonly [Key in Head]?: {
|
|
2878
|
+
readonly states: HandlerValidationAtPath<Rest, Validation>;
|
|
2879
|
+
};
|
|
2880
|
+
} : {
|
|
2881
|
+
readonly [Key in Path]?: Validation;
|
|
2882
|
+
};
|
|
2883
|
+
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> ? {
|
|
2884
|
+
readonly states?: never;
|
|
2885
|
+
readonly history?: never;
|
|
2886
|
+
} : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
2087
2887
|
readonly states?: never;
|
|
2888
|
+
readonly history?: never;
|
|
2088
2889
|
} : {
|
|
2089
|
-
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, StateId
|
|
2890
|
+
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, Extract<StateId, StateIdentifier<AllStates>>>;
|
|
2891
|
+
readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
|
|
2090
2892
|
} : {
|
|
2091
2893
|
readonly states?: never;
|
|
2894
|
+
readonly history?: never;
|
|
2092
2895
|
});
|
|
2093
2896
|
type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, Prefix extends string> = {
|
|
2094
|
-
readonly [Key in
|
|
2897
|
+
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
|
|
2095
2898
|
};
|
|
2096
|
-
type HandlerNodeConfigKey = "always" | "entry" | "exit" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
2097
|
-
type HandlerValidationError<Message extends string> = {
|
|
2098
|
-
readonly "~effect/Machine/HandlerError": Message;
|
|
2899
|
+
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initial" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
2900
|
+
type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
|
|
2901
|
+
readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
|
|
2099
2902
|
};
|
|
2100
|
-
type HandlerValidationErrors<Validation> = Validation extends HandlerValidationError<any> ? Validation : never;
|
|
2101
2903
|
type NodeHasDeclaredOutput<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends {
|
|
2102
2904
|
readonly output: Schema.Top;
|
|
2103
2905
|
} ? StateId : never;
|
|
@@ -2119,74 +2921,115 @@ export declare namespace Machine {
|
|
|
2119
2921
|
readonly [Key in Extract<keyof Children, string>]: RequiredCompletionOutputStates<States, Extract<JoinPath<StateId, Key>, StateIdentifier<States>>>;
|
|
2120
2922
|
}[Extract<keyof Children, string>] : never;
|
|
2121
2923
|
type HandlerOutputStates<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = "output" extends keyof Config ? StateId : never;
|
|
2122
|
-
type
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2924
|
+
type HandlerUnknownStateKeyValidation<States extends StateSchemas, Prefix extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, Extract<keyof States, string>>> = [UnknownKeys] extends [never] ? unknown : {
|
|
2925
|
+
readonly [Key in UnknownKeys]: HandlerValidationError<"Handler tree contains a state key that does not exist", JoinPath<Prefix, Key>, Key>;
|
|
2926
|
+
};
|
|
2927
|
+
type HandlerUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, HandlerNodeConfigKey>> = [UnknownKeys] extends [never] ? unknown : {
|
|
2928
|
+
readonly [Key in UnknownKeys]: HandlerValidationError<"Handler config contains an unknown key", StateId, Key>;
|
|
2929
|
+
};
|
|
2930
|
+
type HandlerOnKeyValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, On = Config extends {
|
|
2931
|
+
readonly on?: infer Current;
|
|
2932
|
+
} ? NonNullable<Current> : never, UnknownKeys extends string = Exclude<Extract<keyof On, string>, TagOf<Events[number]>>> = "on" extends keyof Config ? [UnknownKeys] extends [never] ? unknown : {
|
|
2933
|
+
readonly on: {
|
|
2934
|
+
readonly [Key in UnknownKeys]: HandlerValidationError<"Handler config contains an event key that does not exist", StateId, Key>;
|
|
2935
|
+
};
|
|
2936
|
+
} : unknown;
|
|
2937
|
+
type TransitionResultTargetPath<Result> = IsAny<Result> extends true ? never : Result extends Effect.Effect<infer Success, any, any> ? TransitionResultTargetPath<Success> : Result extends StateConstruction<infer Constructed> ? TransitionResultTargetPath<Constructed> : Result extends {
|
|
2938
|
+
readonly path: infer Path extends string;
|
|
2939
|
+
} ? Path : never;
|
|
2940
|
+
type DeclaredTransitionTarget<Transition> = Transition extends {
|
|
2941
|
+
readonly targets: infer Targets extends ReadonlyArray<string>;
|
|
2942
|
+
} ? Targets[number] : never;
|
|
2943
|
+
type ExcludeDeclaredTransitionTarget<Returned, Declared extends string> = Returned extends string ? Returned extends Declared | `${Declared}.${string}` ? never : Returned : never;
|
|
2944
|
+
type UndeclaredTransitionTarget<Transition> = "targets" extends keyof Transition ? ExcludeDeclaredTransitionTarget<TransitionResultTargetPath<EventTransitionReturn<Transition>>, DeclaredTransitionTarget<Transition>> : never;
|
|
2945
|
+
type HandlerOnTargetValidationErrors<StateId extends string, On> = {
|
|
2946
|
+
readonly [EventTag in keyof On as [UndeclaredTransitionTarget<On[EventTag]>] extends [never] ? never : EventTag]: HandlerValidationError<"Transition returns a target not listed in targets", StateId, readonly [event: EventTag, target: UndeclaredTransitionTarget<On[EventTag]>]>;
|
|
2947
|
+
};
|
|
2948
|
+
type HandlerOnTargetValidation<StateId extends string, Config> = "on" extends keyof Config ? Config extends {
|
|
2128
2949
|
readonly on?: infer On;
|
|
2129
|
-
} ?
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
type
|
|
2133
|
-
|
|
2134
|
-
|
|
2950
|
+
} ? HandlerOnTargetValidationErrors<StateId, NonNullable<On>> extends infer Errors ? keyof Errors extends never ? unknown : {
|
|
2951
|
+
readonly on: Errors;
|
|
2952
|
+
} : never : unknown : unknown;
|
|
2953
|
+
type HandlerDirectTargetValidation<StateId extends string, Config, Trigger extends "always" | "onDone", Transition = Config extends {
|
|
2954
|
+
readonly [Key in Trigger]?: infer Value;
|
|
2955
|
+
} ? NonNullable<Value> : never, Undeclared extends string = UndeclaredTransitionTarget<Transition>> = Trigger extends keyof Config ? [Undeclared] extends [never] ? unknown : {
|
|
2956
|
+
readonly [Key in Trigger]: HandlerValidationError<"Transition returns a target not listed in targets", StateId, readonly [trigger: Trigger, target: Undeclared]>;
|
|
2957
|
+
} : unknown;
|
|
2958
|
+
type HandlerChildrenValidation<Node, Prefix extends string, Config> = "states" extends keyof Config ? Config extends {
|
|
2135
2959
|
readonly states?: infer ChildrenConfig;
|
|
2136
|
-
} ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [
|
|
2137
|
-
|
|
2138
|
-
|
|
2960
|
+
} ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
2961
|
+
readonly states: HandlerValidationError<"Handler config contains child states for a state that has no children", Prefix>;
|
|
2962
|
+
} : HandlerUnknownStateKeyValidation<Children, Prefix, NonNullable<ChildrenConfig>> extends infer Validation ? unknown extends Validation ? unknown : {
|
|
2963
|
+
readonly states: Validation;
|
|
2964
|
+
} : never : never : {
|
|
2965
|
+
readonly states: HandlerValidationError<"Handler config contains child states for a state that has no children", Prefix>;
|
|
2966
|
+
} : unknown;
|
|
2139
2967
|
type HandlerOutputRequirementValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, AvailableOutputStates extends StateIdentifier<AllStates>, Config> = ("onDone" extends keyof Config ? [
|
|
2140
2968
|
Exclude<RequiredCompletionOutputStates<AllStates, StateId>, AvailableOutputStates>
|
|
2141
|
-
] extends [never] ? unknown :
|
|
2969
|
+
] extends [never] ? unknown : {
|
|
2970
|
+
readonly onDone: HandlerValidationError<"Handler config is missing an output implementation required by onDone", StateId, Exclude<RequiredCompletionOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
2971
|
+
} : unknown) & ("output" extends keyof Config ? NodeByIdentifier<AllStates, StateId> extends {
|
|
2142
2972
|
readonly type: "parallel";
|
|
2143
2973
|
} ? [
|
|
2144
2974
|
Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>
|
|
2145
|
-
] extends [never] ? unknown :
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
type
|
|
2149
|
-
type
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
type
|
|
2164
|
-
readonly
|
|
2165
|
-
}
|
|
2166
|
-
type
|
|
2167
|
-
type
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
type
|
|
2171
|
-
type
|
|
2172
|
-
readonly
|
|
2173
|
-
}[
|
|
2174
|
-
|
|
2175
|
-
|
|
2975
|
+
] extends [never] ? unknown : {
|
|
2976
|
+
readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
2977
|
+
} : unknown : unknown);
|
|
2978
|
+
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"> & HandlerInvokeOutputValidation<Events, StateId, Config> & HandlerInvokeEmitsValidation<Events, StateId, Config> & HandlerInvokeSnapshotValidation<Events, StateId, Config> & HandlerChildrenValidation<Node, StateId, Config> & HandlerOutputRequirementValidation<AllStates, StateId, AvailableOutputStates, Config> & HandlerRuntimeValidation<Events, Emits, StateId, Config> : unknown;
|
|
2979
|
+
type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
|
|
2980
|
+
readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
|
|
2981
|
+
};
|
|
2982
|
+
type HandlerChoiceTargetValidation<StateId extends string, Config> = Config extends {
|
|
2983
|
+
readonly choice: infer Choice;
|
|
2984
|
+
} ? [UndeclaredTransitionTarget<Choice>] extends [never] ? unknown : {
|
|
2985
|
+
readonly choice: HandlerValidationError<"Choice resolver returns a target not listed in targets", StateId, UndeclaredTransitionTarget<Choice>>;
|
|
2986
|
+
} : unknown;
|
|
2987
|
+
type HandlerInvokeOutputValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>] extends [never] ? unknown : {
|
|
2988
|
+
readonly invoke: HandlerValidationError<"Invoked child output must be a machine event or void", StateId, Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>>;
|
|
2989
|
+
};
|
|
2990
|
+
type HandlerInvokeEmitsValidation<Events extends ReadonlyArray<TaggedSchema>, StateId extends string, Config> = [InvokeReturn<Config>] extends [never] ? unknown : [Exclude<InvokeEmits<InvokeReturn<Config>>, EventOf<Events>>] extends [never] ? unknown : {
|
|
2991
|
+
readonly invoke: HandlerValidationError<"Invoked child emits events not accepted by the parent machine", StateId, Exclude<InvokeEmits<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
2992
|
+
};
|
|
2993
|
+
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 : {
|
|
2994
|
+
readonly invoke: HandlerValidationError<"Invoked child snapshot mapper must return a machine event or undefined", StateId, Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>>;
|
|
2995
|
+
};
|
|
2996
|
+
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>;
|
|
2997
|
+
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;
|
|
2998
|
+
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>;
|
|
2999
|
+
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>;
|
|
3000
|
+
type HandlerHasRequiredInitial<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = StateId extends RequiredHistoryInitializers<AllStates> ? "initial" extends keyof Config ? true : false : true;
|
|
3001
|
+
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
3002
|
+
readonly states: infer Children extends StateSchemas;
|
|
3003
|
+
} ? [HistoryStateKey<Children>] extends [never] ? true : Config extends {
|
|
3004
|
+
readonly history?: infer HistoryConfig;
|
|
3005
|
+
} ? [
|
|
3006
|
+
Exclude<HistoryStateKey<Children>, Extract<keyof NonNullable<HistoryConfig>, string>>
|
|
3007
|
+
] extends [never] ? true : false : false : true;
|
|
3008
|
+
type HandlerHasRequiredChoices<Node, Config> = Node extends {
|
|
3009
|
+
readonly states: infer Children extends StateSchemas;
|
|
3010
|
+
} ? [ChoiceStateKey<Children>] extends [never] ? true : Config extends {
|
|
3011
|
+
readonly states?: infer ChildrenConfig;
|
|
3012
|
+
} ? [
|
|
3013
|
+
Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
|
|
3014
|
+
] extends [never] ? true : false : false : true;
|
|
3015
|
+
type HandlerImplementedStateId<AllStates extends StateSchemas, Node, StateId extends StateIdentifier<AllStates>, Config> = [HistoryIdentifier<AllStates> | ChoiceIdentifier<AllStates>] extends [never] ? StateId : HandlerHasRequiredInitial<AllStates, StateId, Config> extends true ? HandlerHasRequiredHistoryDefaults<Node, Config> extends true ? HandlerHasRequiredChoices<Node, Config> extends true ? StateId : never : never : never;
|
|
3016
|
+
type HandlerConfigError<Config> = Effect.Error<EventHandlerReturn<Config>> | Effect.Error<AlwaysReturn<Config>> | Effect.Error<DoneReturn<Config>> | Effect.Error<StateActionReturn<Config, "entry">> | Effect.Error<StateActionReturn<Config, "exit">> | Effect.Error<StateInitialReturn<Config>> | Effect.Error<HistoryDefaultReturn<Config>> | Effect.Error<ChoiceReturn<Config>> | InvokeError<Config>;
|
|
3017
|
+
type HandlerNodeEvidence<AllStates extends StateSchemas, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : {
|
|
3018
|
+
readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, HandlerNodeByPath<AllStates, StateId>, StateId, NodeConfig> : never;
|
|
3019
|
+
readonly error: HandlerConfigError<HandlerConfigPart<NodeConfig>>;
|
|
3020
|
+
readonly services: ConfigServices<HandlerConfigPart<NodeConfig>>;
|
|
3021
|
+
readonly outputState: StateId extends StateIdentifier<AllStates> ? HandlerOutputStates<AllStates, StateId, HandlerConfigPart<NodeConfig>> : never;
|
|
3022
|
+
};
|
|
3023
|
+
type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId> : never : never;
|
|
3024
|
+
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>;
|
|
2176
3025
|
/**
|
|
2177
3026
|
* Adds state handlers from a root state object.
|
|
2178
3027
|
*
|
|
2179
|
-
* **Gotchas**
|
|
2180
|
-
*
|
|
2181
|
-
* Type inference traverses up to eight nested child-state objects. Deeper
|
|
2182
|
-
* handler trees are rejected explicitly instead of silently dropping their
|
|
2183
|
-
* error, service, final-state, or output channels.
|
|
2184
|
-
*
|
|
2185
3028
|
* @category combinators
|
|
2186
3029
|
* @since 4.0.0
|
|
2187
3030
|
*/
|
|
2188
3031
|
interface Handler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>> {
|
|
2189
|
-
<const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerTreeValidation<States,
|
|
3032
|
+
<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>;
|
|
2190
3033
|
}
|
|
2191
3034
|
/**
|
|
2192
3035
|
* Any state config.
|
|
@@ -2194,16 +3037,18 @@ export declare namespace Machine {
|
|
|
2194
3037
|
* @category utility types
|
|
2195
3038
|
* @since 4.0.0
|
|
2196
3039
|
*/
|
|
2197
|
-
type AnyStateConfig = StateConfig<any, any, any, any, any, any, any>;
|
|
3040
|
+
type AnyStateConfig = StateConfig<any, any, any, any, any, any, any> | ChoiceStateConfig<any, any, any, any>;
|
|
2198
3041
|
/**
|
|
2199
3042
|
* Runtime event-handler map stored for a single state tag.
|
|
2200
3043
|
*
|
|
2201
3044
|
* @category models
|
|
2202
3045
|
* @since 4.0.0
|
|
2203
3046
|
*/
|
|
2204
|
-
type EventHandlerMap<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R
|
|
3047
|
+
type EventHandlerMap<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
|
|
2205
3048
|
readonly reenter?: boolean;
|
|
2206
|
-
|
|
3049
|
+
/** Statically declared upper bound of possible target paths. */
|
|
3050
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3051
|
+
readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
2207
3052
|
}>>;
|
|
2208
3053
|
/**
|
|
2209
3054
|
* Runtime state config stored for a single state tag.
|
|
@@ -2212,11 +3057,17 @@ export declare namespace Machine {
|
|
|
2212
3057
|
* @since 4.0.0
|
|
2213
3058
|
*/
|
|
2214
3059
|
interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
2215
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId
|
|
2216
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId
|
|
3060
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
|
|
3061
|
+
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
|
|
2217
3062
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
|
|
2218
|
-
readonly always?: (context: AlwaysContext<States, Events, Emits, StateId
|
|
2219
|
-
|
|
3063
|
+
readonly always?: ((context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
|
|
3064
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3065
|
+
readonly transition: (context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
3066
|
+
};
|
|
3067
|
+
readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
|
|
3068
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3069
|
+
readonly transition: (context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
3070
|
+
};
|
|
2220
3071
|
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
|
|
2221
3072
|
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
|
|
2222
3073
|
}
|
|
@@ -2226,7 +3077,7 @@ export declare namespace Machine {
|
|
|
2226
3077
|
* @category models
|
|
2227
3078
|
* @since 4.0.0
|
|
2228
3079
|
*/
|
|
2229
|
-
type StateConfigs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, StateConfig<States, Events, Emits, StateId, EventTag, E, R
|
|
3080
|
+
type StateConfigs<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> = Readonly<Record<PropertyKey, StateConfig<States, Events, Emits, StateId, EventTag, E, R> | ChoiceStateConfig<States, Events, Emits, ChoiceIdentifier<States>>>>;
|
|
2230
3081
|
}
|
|
2231
3082
|
/**
|
|
2232
3083
|
* Returns `true` if a value is a `Machine`.
|
|
@@ -2269,14 +3120,30 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
2269
3120
|
* Machine.make({
|
|
2270
3121
|
* states: States.states,
|
|
2271
3122
|
* events: [],
|
|
2272
|
-
* initial: () => States.initial.idle(
|
|
3123
|
+
* initial: () => States.initial.idle.from()
|
|
2273
3124
|
* })
|
|
2274
3125
|
* ```
|
|
2275
3126
|
*
|
|
2276
3127
|
* @category constructors
|
|
2277
3128
|
* @since 4.0.0
|
|
2278
3129
|
*/
|
|
2279
|
-
export declare const defineStates:
|
|
3130
|
+
export declare const defineStates: DefineStates;
|
|
3131
|
+
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>> = {
|
|
3132
|
+
readonly id?: string;
|
|
3133
|
+
readonly states: States & DefineStateTreeInput<NoInfer<States>>;
|
|
3134
|
+
readonly events: InputEvents & ValidateInputEventProtocol<NoInfer<InputEvents>>;
|
|
3135
|
+
readonly internalEvents?: InternalEvents & ValidateInternalEventProtocol<NoInfer<InputEvents>, NoInfer<InternalEvents>>;
|
|
3136
|
+
readonly emits?: Emits;
|
|
3137
|
+
readonly input?: Input;
|
|
3138
|
+
readonly initial: (...args: [...Machine.InputArgs<Input>]) => Machine.InitialResult<States, InitialE, InitialR>;
|
|
3139
|
+
};
|
|
3140
|
+
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>;
|
|
3141
|
+
interface Make {
|
|
3142
|
+
<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>;
|
|
3143
|
+
<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"> & {
|
|
3144
|
+
readonly states: InvalidDefinedStateTreeInput<States>;
|
|
3145
|
+
}): never;
|
|
3146
|
+
}
|
|
2280
3147
|
/**
|
|
2281
3148
|
* Creates a schema-first machine definition.
|
|
2282
3149
|
*
|
|
@@ -2327,17 +3194,36 @@ export declare const defineStates: <const States extends Machine.StateSchemas>(s
|
|
|
2327
3194
|
* @category constructors
|
|
2328
3195
|
* @since 4.0.0
|
|
2329
3196
|
*/
|
|
2330
|
-
export declare const make:
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
3197
|
+
export declare const make: Make;
|
|
3198
|
+
type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends EventSchema["~type.make.in"] ? [
|
|
3199
|
+
input?: EventSchema["~type.make.in"]
|
|
3200
|
+
] : [input: EventSchema["~type.make.in"]];
|
|
3201
|
+
/**
|
|
3202
|
+
* Constructs an event from a schema owned by a machine's protocol.
|
|
3203
|
+
*
|
|
3204
|
+
* **Details**
|
|
3205
|
+
*
|
|
3206
|
+
* The schema constructor runs exactly once. The resulting decoded event is
|
|
3207
|
+
* trusted by this machine and definitions derived from it with `handle`, so
|
|
3208
|
+
* repeated delivery does not decode the same already-constructed value again.
|
|
3209
|
+
* Events supplied through ordinary `send` and `plan` calls remain untrusted
|
|
3210
|
+
* and continue through full runtime schema validation.
|
|
3211
|
+
* Treat the returned event as immutable after construction.
|
|
3212
|
+
*
|
|
3213
|
+
* The schema must be one of the machine's configured public or internal event
|
|
3214
|
+
* schemas, or a case schema belonging to a configured `Schema.TaggedUnion`.
|
|
3215
|
+
*
|
|
3216
|
+
* **Example**
|
|
3217
|
+
*
|
|
3218
|
+
* ```ts
|
|
3219
|
+
* const increment = Machine.event(counter, Increment, { by: 1 })
|
|
3220
|
+
* yield* ref.send(increment)
|
|
3221
|
+
* ```
|
|
3222
|
+
*
|
|
3223
|
+
* @category constructors
|
|
3224
|
+
* @since 4.0.0
|
|
3225
|
+
*/
|
|
3226
|
+
export declare const event: <const M extends Machine.Any, const EventSchema extends Machine.TaggedSchema>(machine: M, schema: EventSchema & ([EventSchema["Type"]] extends [Machine.Event<M>] ? unknown : never), ...args: EventConstructorArgs<EventSchema>) => EventSchema["Type"];
|
|
2341
3227
|
/**
|
|
2342
3228
|
* Encodes a decoded machine snapshot into a normalized data representation.
|
|
2343
3229
|
*
|
|
@@ -2553,48 +3439,120 @@ type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.
|
|
|
2553
3439
|
*/
|
|
2554
3440
|
export declare const invokeMachine: {
|
|
2555
3441
|
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, SnapshotEvent = never, DoneEvent = never, Id extends string = string, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(config: {
|
|
2556
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> &
|
|
3442
|
+
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
|
|
2557
3443
|
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
2558
3444
|
readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined;
|
|
2559
3445
|
} & InvokeMachineInput<Input>): Machine.InvokeConfig<any, any, any, any, SnapshotEvent, Machine.Snapshot<States>, Machine.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialR | R>, internalRuntime.MachineRuntime>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>, Output, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, Machine.EmitOf<Emits>, DoneEvent>;
|
|
2560
3446
|
<const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, SnapshotEvent = never, Id extends string = string, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(config: {
|
|
2561
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> &
|
|
3447
|
+
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
|
|
2562
3448
|
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
2563
3449
|
readonly onDone?: never;
|
|
2564
3450
|
} & 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>>;
|
|
2565
3451
|
};
|
|
2566
3452
|
/**
|
|
2567
|
-
* Plans the initial state for a machine without
|
|
3453
|
+
* Plans the initial state for a machine without executing actor commands.
|
|
2568
3454
|
*
|
|
2569
3455
|
* **Details**
|
|
2570
3456
|
*
|
|
2571
|
-
* The returned plan contains the settled initial snapshot,
|
|
2572
|
-
* emitted events,
|
|
2573
|
-
* logic and follow completion, eventless, and
|
|
2574
|
-
*
|
|
3457
|
+
* The returned plan contains the settled initial snapshot, actor commands,
|
|
3458
|
+
* emitted events, optional final output, and every startup microstep. Planning
|
|
3459
|
+
* may evaluate transition logic and follow completion, eventless, and
|
|
3460
|
+
* raised-event steps. Transition callbacks are evaluated synchronously.
|
|
3461
|
+
* `startingState` and `initialEntryPaths` describe the normalized
|
|
3462
|
+
* configuration before entry callbacks and settlement begin.
|
|
2575
3463
|
*
|
|
2576
3464
|
* **Gotchas**
|
|
2577
3465
|
*
|
|
2578
|
-
*
|
|
2579
|
-
*
|
|
2580
|
-
*
|
|
3466
|
+
* `start` executes the closed command list as part of the managed actor commit
|
|
3467
|
+
* protocol. Manual planners may inspect commands but need a running actor scope
|
|
3468
|
+
* to execute child-addressed operations.
|
|
2581
3469
|
*
|
|
2582
3470
|
* @see {@link plan} for planning a received event.
|
|
2583
3471
|
* @see {@link start} for the managed runtime protocol.
|
|
2584
3472
|
* @category constructors
|
|
2585
3473
|
* @since 4.0.0
|
|
2586
3474
|
*/
|
|
2587
|
-
export declare const planInitial: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> &
|
|
3475
|
+
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<{
|
|
3476
|
+
readonly startingState: Machine.Snapshot<States>;
|
|
3477
|
+
readonly initialEntryPaths: ReadonlyArray<Machine.StateIdentifier<States>>;
|
|
2588
3478
|
readonly state: Machine.Snapshot<States>;
|
|
2589
|
-
readonly
|
|
3479
|
+
readonly commands: ReadonlyArray<Command>;
|
|
2590
3480
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
3481
|
+
readonly microsteps: ReadonlyArray<{
|
|
3482
|
+
readonly next: Machine.Snapshot<States>;
|
|
3483
|
+
readonly event: Machine.EventOf<Events> | InitialEvent;
|
|
3484
|
+
readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<States>, Machine.TagOf<Events[number]>, Machine.StateNodeIdentifier<States>>>;
|
|
3485
|
+
readonly commands: ReadonlyArray<Command>;
|
|
3486
|
+
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>;
|
|
3487
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
3488
|
+
readonly exitPaths: ReadonlyArray<string>;
|
|
3489
|
+
readonly entryPaths: ReadonlyArray<string>;
|
|
3490
|
+
readonly changed: boolean;
|
|
3491
|
+
}>;
|
|
2591
3492
|
} & ({
|
|
2592
3493
|
readonly done: true;
|
|
2593
3494
|
readonly output: Output;
|
|
2594
3495
|
} | {
|
|
2595
3496
|
readonly done: false;
|
|
2596
3497
|
readonly output: undefined;
|
|
2597
|
-
}), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError,
|
|
3498
|
+
}), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, never>;
|
|
3499
|
+
/**
|
|
3500
|
+
* Returns every compiled state node in definition order.
|
|
3501
|
+
*
|
|
3502
|
+
* **Details**
|
|
3503
|
+
*
|
|
3504
|
+
* The result includes atomic, compound, parallel, final, history, and choice
|
|
3505
|
+
* nodes together with their resolved descriptive annotations. Use each node's
|
|
3506
|
+
* `parent` property to reconstruct the complete hierarchy. Pseudo-states are
|
|
3507
|
+
* intentionally omitted from `children` because they can never appear in an
|
|
3508
|
+
* active configuration.
|
|
3509
|
+
*
|
|
3510
|
+
* @category getters
|
|
3511
|
+
* @since 4.0.0
|
|
3512
|
+
*/
|
|
3513
|
+
export declare const stateNodes: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.StateNode<Machine.StateIdentifier<Machine.States<M>>, Machine.HistoryIdentifier<Machine.States<M>>, Machine.ChoiceIdentifier<Machine.States<M>>>>;
|
|
3514
|
+
/**
|
|
3515
|
+
* Returns every registered transition handler in state definition order.
|
|
3516
|
+
*
|
|
3517
|
+
* **Details**
|
|
3518
|
+
*
|
|
3519
|
+
* Event handlers retain their handler-key order within each source state and
|
|
3520
|
+
* are followed by eventless and completion handlers. This function does not
|
|
3521
|
+
* execute handlers. Object-form event, eventless, and completion handlers with
|
|
3522
|
+
* a `targets` declaration expose those possible paths; handlers without one
|
|
3523
|
+
* remain dynamic.
|
|
3524
|
+
*
|
|
3525
|
+
* @category getters
|
|
3526
|
+
* @since 4.0.0
|
|
3527
|
+
*/
|
|
3528
|
+
export declare const transitionDefinitions: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.TransitionDefinition<Machine.StateNodeIdentifier<Machine.States<M>>, Machine.TagOf<Machine.Events<M>[number]>, Machine.StateNodeIdentifier<Machine.States<M>>>>;
|
|
3529
|
+
/**
|
|
3530
|
+
* Returns serializable descriptions of every state-owned activity.
|
|
3531
|
+
*
|
|
3532
|
+
* **Details**
|
|
3533
|
+
*
|
|
3534
|
+
* Static `invoke`, `invokeEffect`, `after`, and `invokeMachine` descriptors
|
|
3535
|
+
* expose stable ownership and lifecycle metadata without serializing runtime
|
|
3536
|
+
* values. Function-valued invoke factories are represented as dynamic and are
|
|
3537
|
+
* never evaluated during inspection.
|
|
3538
|
+
*
|
|
3539
|
+
* @category getters
|
|
3540
|
+
* @since 4.0.0
|
|
3541
|
+
*/
|
|
3542
|
+
export declare const activityDefinitions: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.ActivityDefinition<Machine.StateIdentifier<Machine.States<M>>>>;
|
|
3543
|
+
/**
|
|
3544
|
+
* Returns every state node active in a decoded snapshot, in definition order.
|
|
3545
|
+
*
|
|
3546
|
+
* **Details**
|
|
3547
|
+
*
|
|
3548
|
+
* Active compound ancestors and parallel regions are included together with
|
|
3549
|
+
* their active descendants. History and choice pseudo-states are never active
|
|
3550
|
+
* and are not returned.
|
|
3551
|
+
*
|
|
3552
|
+
* @category getters
|
|
3553
|
+
* @since 4.0.0
|
|
3554
|
+
*/
|
|
3555
|
+
export declare const configuration: <M extends Machine.Any>(machine: M, state: Machine.Snapshot<Machine.States<M>>) => ReadonlyArray<Machine.ActiveStateNode<Machine.StateIdentifier<Machine.States<M>>, Machine.ChoiceIdentifier<Machine.States<M>>>>;
|
|
2598
3556
|
/**
|
|
2599
3557
|
* Returns the event tags handled by the current state snapshot.
|
|
2600
3558
|
*
|
|
@@ -2603,7 +3561,7 @@ export declare const planInitial: <const States extends Machine.StateSchemas, co
|
|
|
2603
3561
|
*/
|
|
2604
3562
|
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]>>;
|
|
2605
3563
|
/**
|
|
2606
|
-
* Plans the next state snapshot
|
|
3564
|
+
* Plans the next state snapshot synchronously.
|
|
2607
3565
|
*
|
|
2608
3566
|
* **Details**
|
|
2609
3567
|
*
|
|
@@ -2614,25 +3572,25 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
2614
3572
|
*
|
|
2615
3573
|
* **Gotchas**
|
|
2616
3574
|
*
|
|
2617
|
-
* `plan` returns data; it does not implement the
|
|
2618
|
-
*
|
|
2619
|
-
*
|
|
2620
|
-
*
|
|
2621
|
-
* are ignored and produce an unchanged plan.
|
|
3575
|
+
* `plan` returns data; it does not implement the actor commit protocol.
|
|
3576
|
+
* `start` executes child commands, publishes `next`, and then delivers
|
|
3577
|
+
* `emittedEvents`. Events with no enabled transition are ignored and produce
|
|
3578
|
+
* an unchanged plan.
|
|
2622
3579
|
*
|
|
2623
3580
|
* @see {@link planInitial} for planning machine startup.
|
|
2624
3581
|
* @see {@link start} for managed execution and lifecycle observation.
|
|
2625
3582
|
* @category combinators
|
|
2626
3583
|
* @since 4.0.0
|
|
2627
3584
|
*/
|
|
2628
|
-
export declare const plan: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> &
|
|
3585
|
+
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.EventOf<InputEvents>) => Effect.Effect<{
|
|
2629
3586
|
readonly next: Machine.Snapshot<States>;
|
|
2630
|
-
readonly
|
|
3587
|
+
readonly commands: ReadonlyArray<Command>;
|
|
2631
3588
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
2632
3589
|
readonly microsteps: ReadonlyArray<{
|
|
2633
3590
|
readonly next: Machine.Snapshot<States>;
|
|
2634
3591
|
readonly event: Machine.EventOf<Events> | InitialEvent;
|
|
2635
|
-
readonly
|
|
3592
|
+
readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<States>, Machine.TagOf<Events[number]>, Machine.StateNodeIdentifier<States>>>;
|
|
3593
|
+
readonly commands: ReadonlyArray<Command>;
|
|
2636
3594
|
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>;
|
|
2637
3595
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
2638
3596
|
readonly exitPaths: ReadonlyArray<string>;
|
|
@@ -2645,67 +3603,7 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
2645
3603
|
} | {
|
|
2646
3604
|
readonly done: false;
|
|
2647
3605
|
readonly output: undefined;
|
|
2648
|
-
}), E | InfiniteTransitionError | MachineSchemaDecodeError,
|
|
2649
|
-
/**
|
|
2650
|
-
* Defers an effectful action until the current machine step is planned.
|
|
2651
|
-
*
|
|
2652
|
-
* **Details**
|
|
2653
|
-
*
|
|
2654
|
-
* The action's error and service requirements are retained in the machine
|
|
2655
|
-
* type without becoming requirements of `plan` or `planInitial`. The managed
|
|
2656
|
-
* runtime executes staged actions sequentially before publishing the planned
|
|
2657
|
-
* state. Pass a second argument when the planning Effect should return that
|
|
2658
|
-
* value after staging.
|
|
2659
|
-
*
|
|
2660
|
-
* **Example** (Typed staged action)
|
|
2661
|
-
*
|
|
2662
|
-
* ```ts
|
|
2663
|
-
* import { Context, Effect } from "effect"
|
|
2664
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
2665
|
-
*
|
|
2666
|
-
* class Audit extends Context.Service<Audit, {
|
|
2667
|
-
* readonly write: Effect.Effect<void, "AuditError">
|
|
2668
|
-
* }>()("example/Audit") {}
|
|
2669
|
-
*
|
|
2670
|
-
* const writeAudit = Machine.action(
|
|
2671
|
-
* Effect.flatMap(Audit, (audit) => audit.write)
|
|
2672
|
-
* )
|
|
2673
|
-
* ```
|
|
2674
|
-
*
|
|
2675
|
-
* @see {@link plan} for inspecting staged actions without executing them.
|
|
2676
|
-
* @category combinators
|
|
2677
|
-
* @since 4.0.0
|
|
2678
|
-
*/
|
|
2679
|
-
export declare const action: Machine.Action;
|
|
2680
|
-
/**
|
|
2681
|
-
* Runs staged machine actions sequentially with the supplied runtime.
|
|
2682
|
-
*
|
|
2683
|
-
* **When to use**
|
|
2684
|
-
*
|
|
2685
|
-
* Use when you implement a commit protocol around `plan` or `planInitial` and
|
|
2686
|
-
* need to execute their staged actions before publishing the planned snapshot.
|
|
2687
|
-
*
|
|
2688
|
-
* **Gotchas**
|
|
2689
|
-
*
|
|
2690
|
-
* This function only runs actions. The caller remains responsible for
|
|
2691
|
-
* publishing the planned state and delivering planned emitted events after all
|
|
2692
|
-
* actions succeed. Process-local operations such as `spawn`, `sendTo`, and
|
|
2693
|
-
* `stopChild` fail with `ProcessLocalError` because no managed machine process
|
|
2694
|
-
* owns the actions.
|
|
2695
|
-
*
|
|
2696
|
-
* @see {@link plan} for creating a transition plan.
|
|
2697
|
-
* @see {@link planInitial} for creating an initial plan.
|
|
2698
|
-
* @category running
|
|
2699
|
-
* @since 4.0.0
|
|
2700
|
-
*/
|
|
2701
|
-
export declare const runActions: <E, R, Events, Emits>(actions: Iterable<Effect.Effect<void, E, R>>, runtime: Runtime<Events, Emits>) => Effect.Effect<void, E | ProcessLocalError, Exclude<ExcludeCompatibleRuntime<R, Events, Emits>, MachineRuntimeRequirement>>;
|
|
2702
|
-
/**
|
|
2703
|
-
* Returns the typed runtime capability for the current machine.
|
|
2704
|
-
*
|
|
2705
|
-
* @category combinators
|
|
2706
|
-
* @since 4.0.0
|
|
2707
|
-
*/
|
|
2708
|
-
export declare const runtime: <const Protocol extends Runtime.Protocol = {}>() => Effect.Effect<Runtime<Runtime.Events<Protocol>, Runtime.Emits<Protocol>>, never, Runtime.Requirement<Runtime.Events<Protocol>, Runtime.Emits<Protocol>>>;
|
|
3606
|
+
}), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
|
|
2709
3607
|
/**
|
|
2710
3608
|
* Creates a one-shot child process from an Effect.
|
|
2711
3609
|
*
|
|
@@ -2825,15 +3723,14 @@ export declare const childAddress: <Event = never>(id: string) => ChildAddress<E
|
|
|
2825
3723
|
*
|
|
2826
3724
|
* **When to use**
|
|
2827
3725
|
*
|
|
2828
|
-
* Use
|
|
2829
|
-
*
|
|
2830
|
-
*
|
|
3726
|
+
* Use from lower-level process logic to create children that should be
|
|
3727
|
+
* addressed or stopped by the owning process instead of tied to a single
|
|
3728
|
+
* state's `invoke` lifecycle.
|
|
2831
3729
|
*
|
|
2832
3730
|
* **Gotchas**
|
|
2833
3731
|
*
|
|
2834
|
-
* This
|
|
2835
|
-
*
|
|
2836
|
-
* that child stops.
|
|
3732
|
+
* This Effect requires a managed process runtime. A named child id must be
|
|
3733
|
+
* unique for the current parent until that child stops.
|
|
2837
3734
|
*
|
|
2838
3735
|
* @see {@link invoke} for children that start and stop with a state.
|
|
2839
3736
|
* @see {@link sendTo} for sending events to named children.
|
|
@@ -2881,11 +3778,10 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
2881
3778
|
*
|
|
2882
3779
|
* **Details**
|
|
2883
3780
|
*
|
|
2884
|
-
* For each accepted event the runtime plans the complete
|
|
2885
|
-
*
|
|
2886
|
-
* state, delivers emitted events, and then starts invokes
|
|
2887
|
-
*
|
|
2888
|
-
* from that plan are suppressed.
|
|
3781
|
+
* For each accepted event the runtime plans the complete synchronous
|
|
3782
|
+
* macrostep, executes closed actor commands, stops invokes for exited states,
|
|
3783
|
+
* publishes the new state, delivers emitted events, and then starts invokes
|
|
3784
|
+
* for entered states.
|
|
2889
3785
|
*
|
|
2890
3786
|
* **Gotchas**
|
|
2891
3787
|
*
|
|
@@ -2899,5 +3795,35 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
2899
3795
|
* @category constructors
|
|
2900
3796
|
* @since 4.0.0
|
|
2901
3797
|
*/
|
|
2902
|
-
export declare const start: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> &
|
|
3798
|
+
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.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>, InitialE | E | ActionError<InitialR | R> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError, ExcludeCompatibleRuntime<ExecutionServices<InitialR | R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
|
|
3799
|
+
/**
|
|
3800
|
+
* Starts a fresh managed runtime from a decoded logical snapshot.
|
|
3801
|
+
*
|
|
3802
|
+
* **Details**
|
|
3803
|
+
*
|
|
3804
|
+
* `resume` validates and normalizes the supplied snapshot before publishing it
|
|
3805
|
+
* as the first state. It does not call the machine's initial function, replay
|
|
3806
|
+
* entry or transition actions, re-deliver raised or emitted events, or
|
|
3807
|
+
* re-evaluate historical completion and eventless transitions. Active-state
|
|
3808
|
+
* invokes start once in ancestor and document order with {@link InitialEvent};
|
|
3809
|
+
* delayed invokes restart their complete duration and invoked machines start
|
|
3810
|
+
* from their own initial state.
|
|
3811
|
+
*
|
|
3812
|
+
* Only logical state, completion, and history metadata are resumed. Queues,
|
|
3813
|
+
* scopes, subscriptions, fibers, spawned children, invoke progress, and prior
|
|
3814
|
+
* runtime status are process-local and are not restored. A final snapshot
|
|
3815
|
+
* immediately produces a completed ref with its current-machine output.
|
|
3816
|
+
*
|
|
3817
|
+
* Decode encoded data explicitly with {@link decodeSnapshot} before calling
|
|
3818
|
+
* this function. Stable snapshots are hosted as supplied; newly enabled
|
|
3819
|
+
* eventless or completion transitions in a changed machine definition are not
|
|
3820
|
+
* evaluated merely because the runtime was resumed; only ordinary subsequent
|
|
3821
|
+
* transition planning can enter and stabilize states.
|
|
3822
|
+
*
|
|
3823
|
+
* @see {@link decodeSnapshot} for the schema and transport boundary.
|
|
3824
|
+
* @see {@link start} for ordinary initial startup.
|
|
3825
|
+
* @category constructors
|
|
3826
|
+
* @since 4.0.0
|
|
3827
|
+
*/
|
|
3828
|
+
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.EventOf<InputEvents>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>, MachineSchemaDecodeError, ExcludeCompatibleRuntime<ExecutionServices<R>, Machine.EventOf<Events>, Machine.EmitOf<Emits>>>;
|
|
2903
3829
|
//# sourceMappingURL=Machine.d.ts.map
|