@typeonce/effect-machine 0.3.0 → 0.5.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 +410 -17
- package/dist/Machine.d.ts +1191 -510
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +371 -565
- 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} +20 -95
- 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} +12 -61
- package/dist/internal/machine/configuration.d.ts.map +1 -0
- package/dist/internal/{machineModel.js → machine/configuration.js} +250 -545
- package/dist/internal/machine/configuration.js.map +1 -0
- package/dist/internal/{machineErrors.d.ts → machine/errors.d.ts} +8 -8
- package/dist/internal/machine/errors.d.ts.map +1 -0
- package/dist/internal/{machineErrors.js → machine/errors.js} +8 -8
- 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 +676 -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} +11 -5
- package/dist/internal/machine/process.d.ts.map +1 -0
- package/dist/internal/machine/process.js +498 -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/machine/runtime.d.ts +255 -0
- package/dist/internal/machine/runtime.d.ts.map +1 -0
- package/dist/internal/machine/runtime.js +1489 -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/exploration.d.ts +30 -0
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -0
- package/dist/internal/testing/machine/exploration.js +237 -0
- package/dist/internal/testing/machine/exploration.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/invariant.d.ts +31 -0
- package/dist/internal/testing/machine/invariant.d.ts.map +1 -0
- package/dist/internal/testing/machine/invariant.js +214 -0
- package/dist/internal/testing/machine/invariant.js.map +1 -0
- package/dist/internal/testing/machine/probe.d.ts +26 -0
- package/dist/internal/testing/machine/probe.d.ts.map +1 -0
- package/dist/internal/testing/machine/probe.js +45 -0
- package/dist/internal/testing/machine/probe.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 +631 -0
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -0
- package/dist/internal/testing/machine/runtime.js +726 -0
- package/dist/internal/testing/machine/runtime.js.map +1 -0
- package/dist/internal/testing/machine/runtimeInvariant.d.ts +32 -0
- package/dist/internal/testing/machine/runtimeInvariant.d.ts.map +1 -0
- package/dist/internal/testing/machine/runtimeInvariant.js +334 -0
- package/dist/internal/testing/machine/runtimeInvariant.js.map +1 -0
- package/dist/internal/testing/machine/trace.d.ts +17 -0
- package/dist/internal/testing/machine/trace.d.ts.map +1 -0
- package/dist/internal/testing/machine/trace.js +94 -0
- package/dist/internal/testing/machine/trace.js.map +1 -0
- package/dist/internal/testing/machine/verification.d.ts +36 -0
- package/dist/internal/testing/machine/verification.d.ts.map +1 -0
- package/dist/internal/testing/machine/verification.js +1375 -0
- package/dist/internal/testing/machine/verification.js.map +1 -0
- package/dist/testing/MachineTest.d.ts +1588 -0
- package/dist/testing/MachineTest.d.ts.map +1 -0
- package/dist/testing/MachineTest.js +406 -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} +56 -45
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -0
- package/dist/unstable/cluster/ClusterMachine.js +144 -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} +116 -50
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -0
- package/dist/unstable/reactivity/AtomMachine.js +164 -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 +316 -31
- package/package.json +28 -10
- 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.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 -797
- 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 +0 -125
- 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
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Schema-first machine definitions.
|
|
3
3
|
*
|
|
4
|
-
* @since 4.0
|
|
4
|
+
* @since 0.4.0
|
|
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.
|
|
22
26
|
*
|
|
23
27
|
* @category type IDs
|
|
24
|
-
* @since 4.0
|
|
28
|
+
* @since 0.4.0
|
|
25
29
|
*/
|
|
26
30
|
export type TypeId = "~effect/Machine";
|
|
27
31
|
/**
|
|
28
32
|
* Runtime type identifier attached to `Machine` values.
|
|
29
33
|
*
|
|
30
34
|
* @category type IDs
|
|
31
|
-
* @since 4.0
|
|
35
|
+
* @since 0.4.0
|
|
32
36
|
*/
|
|
33
37
|
export declare const TypeId: TypeId;
|
|
34
38
|
declare const MachineOutputStatesTypeId: unique symbol;
|
|
@@ -38,15 +42,15 @@ declare const MachineTypeId: unique symbol;
|
|
|
38
42
|
* actions.
|
|
39
43
|
*
|
|
40
44
|
* @category type IDs
|
|
41
|
-
* @since 4.0
|
|
45
|
+
* @since 0.4.0
|
|
42
46
|
*/
|
|
43
|
-
export
|
|
47
|
+
export { InitialEventTypeId };
|
|
44
48
|
/**
|
|
45
49
|
* Synthetic event passed to entry, exit, always, invoke, and output callbacks
|
|
46
50
|
* that run while the machine is settling its initial state.
|
|
47
51
|
*
|
|
48
52
|
* @category models
|
|
49
|
-
* @since 4.0
|
|
53
|
+
* @since 0.4.0
|
|
50
54
|
*/
|
|
51
55
|
export interface InitialEvent {
|
|
52
56
|
readonly _tag: typeof InitialEventTypeId;
|
|
@@ -55,14 +59,14 @@ export interface InitialEvent {
|
|
|
55
59
|
* Synthetic event value used while the machine settles its initial state.
|
|
56
60
|
*
|
|
57
61
|
* @category constructors
|
|
58
|
-
* @since 4.0
|
|
62
|
+
* @since 0.4.0
|
|
59
63
|
*/
|
|
60
64
|
export declare const InitialEvent: InitialEvent;
|
|
61
65
|
/**
|
|
62
66
|
* Returns `true` if a value is the synthetic machine initial event.
|
|
63
67
|
*
|
|
64
68
|
* @category guards
|
|
65
|
-
* @since 4.0
|
|
69
|
+
* @since 0.4.0
|
|
66
70
|
*/
|
|
67
71
|
export declare const isInitialEvent: (u: unknown) => u is InitialEvent;
|
|
68
72
|
type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
@@ -84,7 +88,7 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
84
88
|
* flow. Use `after` for cancellable state-scoped delayed events.
|
|
85
89
|
*
|
|
86
90
|
* @category models
|
|
87
|
-
* @since 4.0
|
|
91
|
+
* @since 0.4.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,51 +99,54 @@ export interface Machine<States extends Machine.StateSchemas, Events extends Rea
|
|
|
95
99
|
/**
|
|
96
100
|
* State tree that defines the machine topology and state value schemas.
|
|
97
101
|
*
|
|
98
|
-
* @since 4.0
|
|
102
|
+
* @since 0.4.0
|
|
99
103
|
*/
|
|
100
104
|
readonly states: States;
|
|
101
105
|
/**
|
|
102
106
|
* Events accepted through public machine input boundaries.
|
|
103
107
|
*
|
|
104
|
-
* @since 4.0
|
|
108
|
+
* @since 0.4.0
|
|
105
109
|
*/
|
|
106
110
|
readonly events: InputEvents;
|
|
107
111
|
/**
|
|
108
112
|
* Events reserved for invokes, child emissions, and other machine-local work.
|
|
109
113
|
*
|
|
110
|
-
* @since 4.0
|
|
114
|
+
* @since 0.4.0
|
|
111
115
|
*/
|
|
112
116
|
readonly internalEvents: ReadonlyArray<Machine.TaggedSchema>;
|
|
113
117
|
/**
|
|
114
118
|
* Events that the machine may emit to its parent or external adapter.
|
|
115
119
|
*
|
|
116
|
-
* @since 4.0
|
|
120
|
+
* @since 0.4.0
|
|
117
121
|
*/
|
|
118
122
|
readonly emits: Emits;
|
|
119
123
|
/**
|
|
120
124
|
* Optional schema used to decode the machine input before initialization.
|
|
121
125
|
*
|
|
122
|
-
* @since 4.0
|
|
126
|
+
* @since 0.4.0
|
|
123
127
|
*/
|
|
124
128
|
readonly input: Input | undefined;
|
|
125
129
|
/**
|
|
126
130
|
* Optional stable identity used by runtime and persistence integrations.
|
|
127
131
|
*
|
|
128
|
-
* @since 4.0
|
|
132
|
+
* @since 0.4.0
|
|
129
133
|
*/
|
|
130
134
|
readonly id: string | undefined;
|
|
131
135
|
/** @internal */
|
|
132
136
|
readonly stateNodes: Machine.StateNodes;
|
|
133
137
|
/** @internal */
|
|
134
|
-
readonly makeTargetBuilder: <Source extends Machine.
|
|
138
|
+
readonly makeTargetBuilder: <Source extends Machine.StateNodeIdentifier<States>>(source: Source) => Machine.TargetBuilder<States, Source>;
|
|
135
139
|
/** @internal */
|
|
136
140
|
readonly handlers: Machine.StateConfigs<States, Events, Emits, UnhandledStates, Machine.TagOf<Events[number]>, E, R>;
|
|
137
141
|
/**
|
|
138
142
|
* Adds typed state handlers and returns the refined machine definition.
|
|
139
143
|
* Successive calls implement the remaining unhandled states while retaining
|
|
140
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.
|
|
141
148
|
*
|
|
142
|
-
* @since 4.0
|
|
149
|
+
* @since 0.4.0
|
|
143
150
|
*/
|
|
144
151
|
readonly handle: Machine.Handler<States, Events, Emits, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, OutputStates, InputEvents>;
|
|
145
152
|
/** @internal */
|
|
@@ -151,7 +158,7 @@ export {
|
|
|
151
158
|
* exists for the current machine.
|
|
152
159
|
*
|
|
153
160
|
* @category errors
|
|
154
|
-
* @since 4.0
|
|
161
|
+
* @since 0.4.0
|
|
155
162
|
*/
|
|
156
163
|
ChildAlreadyExistsError,
|
|
157
164
|
/**
|
|
@@ -159,7 +166,7 @@ ChildAlreadyExistsError,
|
|
|
159
166
|
* number of macrostep iterations.
|
|
160
167
|
*
|
|
161
168
|
* @category errors
|
|
162
|
-
* @since 4.0
|
|
169
|
+
* @since 0.4.0
|
|
163
170
|
*/
|
|
164
171
|
InfiniteTransitionError,
|
|
165
172
|
/**
|
|
@@ -167,7 +174,7 @@ InfiniteTransitionError,
|
|
|
167
174
|
* structural configuration declared for a machine boundary.
|
|
168
175
|
*
|
|
169
176
|
* @category errors
|
|
170
|
-
* @since 4.0
|
|
177
|
+
* @since 0.4.0
|
|
171
178
|
*/
|
|
172
179
|
MachineSchemaDecodeError,
|
|
173
180
|
/**
|
|
@@ -175,7 +182,7 @@ MachineSchemaDecodeError,
|
|
|
175
182
|
* its declared state or output schemas.
|
|
176
183
|
*
|
|
177
184
|
* @category errors
|
|
178
|
-
* @since 4.0
|
|
185
|
+
* @since 0.4.0
|
|
179
186
|
*/
|
|
180
187
|
MachineSchemaEncodeError,
|
|
181
188
|
/**
|
|
@@ -183,7 +190,7 @@ MachineSchemaEncodeError,
|
|
|
183
190
|
* requires a managed machine process.
|
|
184
191
|
*
|
|
185
192
|
* @category errors
|
|
186
|
-
* @since 4.0
|
|
193
|
+
* @since 0.4.0
|
|
187
194
|
*/
|
|
188
195
|
ProcessLocalError,
|
|
189
196
|
/**
|
|
@@ -191,7 +198,7 @@ ProcessLocalError,
|
|
|
191
198
|
* logic after the initial state has been computed.
|
|
192
199
|
*
|
|
193
200
|
* @category errors
|
|
194
|
-
* @since 4.0
|
|
201
|
+
* @since 0.4.0
|
|
195
202
|
*/
|
|
196
203
|
StartupError,
|
|
197
204
|
/**
|
|
@@ -199,9 +206,9 @@ StartupError,
|
|
|
199
206
|
* producing an output.
|
|
200
207
|
*
|
|
201
208
|
* @category errors
|
|
202
|
-
* @since 4.0
|
|
209
|
+
* @since 0.4.0
|
|
203
210
|
*/
|
|
204
|
-
StoppedError } from "./internal/
|
|
211
|
+
StoppedError } from "./internal/machine/machine.js";
|
|
205
212
|
declare const RuntimeRequirementTypeId = "~effect/Machine/RuntimeRequirement";
|
|
206
213
|
declare const ActionRequirementTypeId = "~effect/Machine/ActionRequirement";
|
|
207
214
|
type MachineRuntimeRequirement = internalRuntime.MachineRuntime;
|
|
@@ -210,7 +217,7 @@ type MachineRuntimeRequirement = internalRuntime.MachineRuntime;
|
|
|
210
217
|
* the Effect that plans a machine step.
|
|
211
218
|
*
|
|
212
219
|
* @category services
|
|
213
|
-
* @since 4.0
|
|
220
|
+
* @since 0.4.0
|
|
214
221
|
*/
|
|
215
222
|
export interface ActionRequirement<Error, Requirements> {
|
|
216
223
|
readonly [ActionRequirementTypeId]: {
|
|
@@ -222,61 +229,100 @@ export interface ActionRequirement<Error, Requirements> {
|
|
|
222
229
|
* Extracts the typed error channel of staged machine actions.
|
|
223
230
|
*
|
|
224
231
|
* @category utility types
|
|
225
|
-
* @since 4.0
|
|
232
|
+
* @since 0.4.0
|
|
226
233
|
*/
|
|
227
234
|
export type ActionError<Requirements> = Requirements extends ActionRequirement<infer Error, any> ? Error : never;
|
|
228
235
|
/**
|
|
229
236
|
* Extracts the service requirements of staged machine actions.
|
|
230
237
|
*
|
|
231
238
|
* @category utility types
|
|
232
|
-
* @since 4.0
|
|
239
|
+
* @since 0.4.0
|
|
233
240
|
*/
|
|
234
241
|
export type ActionServices<Requirements> = Requirements extends ActionRequirement<any, infer Services> ? Services : never;
|
|
235
242
|
/**
|
|
236
243
|
* Removes staged action requirements from machine planning services.
|
|
237
244
|
*
|
|
238
245
|
* @category utility types
|
|
239
|
-
* @since 4.0
|
|
246
|
+
* @since 0.4.0
|
|
240
247
|
*/
|
|
241
248
|
export type PlanningServices<Requirements> = Exclude<Requirements, ActionRequirement<any, any>>;
|
|
242
249
|
/**
|
|
243
250
|
* Resolves all services needed to execute a machine at runtime.
|
|
244
251
|
*
|
|
245
252
|
* @category utility types
|
|
246
|
-
* @since 4.0
|
|
253
|
+
* @since 0.4.0
|
|
247
254
|
*/
|
|
248
255
|
export type ExecutionServices<Requirements> = Exclude<PlanningServices<Requirements>, MachineRuntimeRequirement> | Exclude<ActionServices<Requirements>, MachineRuntimeRequirement>;
|
|
249
256
|
/**
|
|
250
|
-
*
|
|
257
|
+
* Managed runtime capability used to deliver raised and emitted events.
|
|
251
258
|
*
|
|
252
259
|
* @category models
|
|
253
|
-
* @since 4.0
|
|
260
|
+
* @since 0.4.0
|
|
254
261
|
*/
|
|
255
262
|
export interface Runtime<in Events, in Emits> {
|
|
256
263
|
/**
|
|
257
264
|
* Queues an event for the current machine macrostep.
|
|
258
265
|
*
|
|
259
|
-
* @since 4.0
|
|
266
|
+
* @since 0.4.0
|
|
260
267
|
*/
|
|
261
268
|
readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
262
269
|
/**
|
|
263
270
|
* Emits an event through the running machine's parent boundary.
|
|
264
271
|
*
|
|
265
|
-
* @since 4.0
|
|
272
|
+
* @since 0.4.0
|
|
266
273
|
*/
|
|
267
274
|
readonly sendParent: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError>;
|
|
268
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 0.4.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
|
+
/**
|
|
301
|
+
* A closed actor command recorded by a synchronous machine transition.
|
|
302
|
+
*
|
|
303
|
+
* @category models
|
|
304
|
+
* @since 0.4.0
|
|
305
|
+
*/
|
|
306
|
+
export type Command = {
|
|
307
|
+
readonly _tag: "SendTo";
|
|
308
|
+
readonly child: ChildMachine.Any | ChildAddress<never>;
|
|
309
|
+
readonly event: unknown;
|
|
310
|
+
} | {
|
|
311
|
+
readonly _tag: "Stop";
|
|
312
|
+
readonly child: ChildMachine.Any | ChildAddress<never>;
|
|
313
|
+
};
|
|
269
314
|
/**
|
|
270
315
|
* Namespace containing type-level members associated with `Runtime`.
|
|
271
316
|
*
|
|
272
|
-
* @
|
|
317
|
+
* @category models
|
|
318
|
+
* @since 0.4.0
|
|
273
319
|
*/
|
|
274
320
|
export declare namespace Runtime {
|
|
275
321
|
/**
|
|
276
|
-
* Protocol annotation
|
|
322
|
+
* Protocol annotation for managed event delivery.
|
|
277
323
|
*
|
|
278
324
|
* @category models
|
|
279
|
-
* @since 4.0
|
|
325
|
+
* @since 0.4.0
|
|
280
326
|
*/
|
|
281
327
|
interface Protocol {
|
|
282
328
|
readonly events?: unknown;
|
|
@@ -286,7 +332,7 @@ export declare namespace Runtime {
|
|
|
286
332
|
* Extracts the events required by a runtime protocol annotation.
|
|
287
333
|
*
|
|
288
334
|
* @category utility types
|
|
289
|
-
* @since 4.0
|
|
335
|
+
* @since 0.4.0
|
|
290
336
|
*/
|
|
291
337
|
type Events<Protocol> = Protocol extends {
|
|
292
338
|
readonly events: infer Events;
|
|
@@ -295,7 +341,7 @@ export declare namespace Runtime {
|
|
|
295
341
|
* Extracts the emitted events required by a runtime protocol annotation.
|
|
296
342
|
*
|
|
297
343
|
* @category utility types
|
|
298
|
-
* @since 4.0
|
|
344
|
+
* @since 0.4.0
|
|
299
345
|
*/
|
|
300
346
|
type Emits<Protocol> = Protocol extends {
|
|
301
347
|
readonly emits: infer Emits;
|
|
@@ -304,7 +350,7 @@ export declare namespace Runtime {
|
|
|
304
350
|
* Opaque service requirement for a machine runtime capability.
|
|
305
351
|
*
|
|
306
352
|
* @category services
|
|
307
|
-
* @since 4.0
|
|
353
|
+
* @since 0.4.0
|
|
308
354
|
*/
|
|
309
355
|
interface Requirement<Events, Emits> {
|
|
310
356
|
readonly [RuntimeRequirementTypeId]: {
|
|
@@ -315,44 +361,66 @@ export declare namespace Runtime {
|
|
|
315
361
|
}
|
|
316
362
|
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;
|
|
317
363
|
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;
|
|
318
|
-
declare const InvokeTypeId:
|
|
319
|
-
type StateDefinitionError<Message extends string> = {
|
|
364
|
+
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
365
|
+
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
320
366
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
367
|
+
readonly path: Path;
|
|
368
|
+
readonly details: Details;
|
|
321
369
|
};
|
|
322
370
|
type ActiveStateKey<States extends Machine.StateSchemas> = Machine.ActiveStateKey<States>;
|
|
323
371
|
type HistoryStateKey<States extends Machine.StateSchemas> = Machine.HistoryStateKey<States>;
|
|
324
|
-
type
|
|
325
|
-
|
|
372
|
+
type ChoiceStateKey<States extends Machine.StateSchemas> = Machine.ChoiceStateKey<States>;
|
|
373
|
+
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>`;
|
|
374
|
+
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;
|
|
375
|
+
type ValidateStateTree<States extends Machine.StateSchemas, AllowHistory extends boolean = false, Prefix extends string = ""> = {
|
|
376
|
+
readonly [Key in keyof States]: ValidateStateKey<Key, Prefix> & ValidateStateNode<States[Key], AllowHistory, StateDefinitionPath<Prefix, Key>>;
|
|
326
377
|
};
|
|
327
|
-
type
|
|
378
|
+
type UnknownStateNodeProperty<Node, Kind extends StateDefinition.StateNodeKind> = Exclude<keyof Node, StateDefinition.AllowedStateNodeProperty<Kind>>;
|
|
379
|
+
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>>;
|
|
380
|
+
type UnknownPseudoAnnotationProperty<Node> = Node extends {
|
|
381
|
+
readonly annotations: infer Annotations;
|
|
382
|
+
} ? Exclude<keyof Annotations, StateDefinition.AllowedPseudoStateAnnotationProperty> : never;
|
|
383
|
+
type ValidatePseudoStateAnnotations<Node, Path extends PropertyKey> = [UnknownPseudoAnnotationProperty<Node>] extends [
|
|
384
|
+
never
|
|
385
|
+
] ? unknown : StateDefinitionError<"Pseudo-state annotations contain unknown properties", Path, Extract<UnknownPseudoAnnotationProperty<Node>, PropertyKey>>;
|
|
386
|
+
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 {
|
|
328
387
|
readonly schema: Machine.TaggedSchema;
|
|
329
|
-
} ? ValidateStateNodeConfig<Node> : StateDefinitionError<"State nodes must be tagged schemas or state node configs">;
|
|
388
|
+
} ? ValidateStateNodeConfig<Node, Path> : StateDefinitionError<"State nodes must be tagged schemas or state node configs", Path>;
|
|
330
389
|
type ValidateHistoryStateNode<Node extends Machine.HistoryStateNodeConfig> = [
|
|
331
|
-
Extract<keyof Node, "schema" | "states" | "initial" | "output">
|
|
390
|
+
Extract<keyof Node, "schema" | "states" | "initial" | "output" | "choice">
|
|
332
391
|
] extends [never] ? unknown : StateDefinitionError<"History states cannot declare schemas, children, initial states, or output">;
|
|
392
|
+
type ValidateChoiceStateNode<Node extends Machine.ChoiceStateNodeConfig> = [
|
|
393
|
+
Extract<keyof Node, "schema" | "states" | "initial" | "output" | "history">
|
|
394
|
+
] extends [never] ? unknown : StateDefinitionError<"Choice states cannot declare schemas, children, initial states, output, or history">;
|
|
333
395
|
type ValidateStateNodeConfig<Node extends {
|
|
334
396
|
readonly schema: Machine.TaggedSchema;
|
|
335
|
-
}> = Node extends {
|
|
397
|
+
}, Path extends PropertyKey> = Node extends {
|
|
398
|
+
readonly type: "parallel";
|
|
399
|
+
} ? ValidateExactStateNodeProperties<Node, "parallel", Path> & ValidateStateNodeWithChildren<Node, Node extends {
|
|
400
|
+
readonly states: infer Children;
|
|
401
|
+
} ? Children : never, Path> : Node extends {
|
|
402
|
+
readonly type: "final";
|
|
403
|
+
} ? ValidateExactStateNodeProperties<Node, "final", Path> & ValidateStateNodeWithoutChildren<Node> : Node extends {
|
|
336
404
|
readonly states: infer Children;
|
|
337
|
-
} ? ValidateStateNodeWithChildren<Node, Children> : ValidateStateNodeWithoutChildren<Node>;
|
|
405
|
+
} ? ValidateExactStateNodeProperties<Node, "compound", Path> & ValidateStateNodeWithChildren<Node, Children, Path> : ValidateExactStateNodeProperties<Node, "atomic", Path> & ValidateStateNodeWithoutChildren<Node>;
|
|
338
406
|
type ValidateOutputSchema<Node> = "output" extends keyof Node ? Node extends {
|
|
339
407
|
readonly output: Schema.Top;
|
|
340
408
|
} ? unknown : StateDefinitionError<"State output must be a schema"> : unknown;
|
|
341
409
|
type ValidateStateNodeWithChildren<Node extends {
|
|
342
410
|
readonly schema: Machine.TaggedSchema;
|
|
343
|
-
}, Children> = Children extends Machine.StateSchemas ? Node extends {
|
|
411
|
+
}, Children, Path extends PropertyKey> = Children extends Machine.StateSchemas ? Node extends {
|
|
344
412
|
readonly type: "final";
|
|
345
413
|
} ? StateDefinitionError<"Final states cannot declare child states"> : Node extends {
|
|
346
414
|
readonly type: "parallel";
|
|
347
415
|
} ? "initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
|
|
348
|
-
readonly states: ValidateStateTree<Children, true
|
|
349
|
-
} & 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">;
|
|
416
|
+
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
417
|
+
} & 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">;
|
|
350
418
|
type ValidateCompoundStateNode<Node extends {
|
|
351
419
|
readonly schema: Machine.TaggedSchema;
|
|
352
|
-
}, Children extends Machine.StateSchemas> = Node extends {
|
|
420
|
+
}, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
|
|
353
421
|
readonly initial: infer Initial;
|
|
354
|
-
} ? Initial extends ActiveStateKey<Children> ? {
|
|
355
|
-
readonly states: ValidateStateTree<Children, true
|
|
422
|
+
} ? Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children> ? {
|
|
423
|
+
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
356
424
|
} : StateDefinitionError<"Compound initial must be one of its direct child keys"> : StateDefinitionError<"Compound states must declare an initial child">;
|
|
357
425
|
type ValidateStateNodeWithoutChildren<Node extends {
|
|
358
426
|
readonly schema: Machine.TaggedSchema;
|
|
@@ -362,7 +430,7 @@ type ValidateStateNodeWithoutChildren<Node extends {
|
|
|
362
430
|
type DefineStateTreeInput<States extends Machine.StateSchemas> = {
|
|
363
431
|
readonly [Key in keyof States]: DefineStateNodeInput<States[Key]>;
|
|
364
432
|
};
|
|
365
|
-
type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Node extends Machine.HistoryStateNodeConfig ? Machine.HistoryStateNodeConfig : Node extends {
|
|
433
|
+
type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Node extends Machine.HistoryStateNodeConfig ? Machine.HistoryStateNodeConfig : Node extends Machine.ChoiceStateNodeConfig ? Machine.ChoiceStateNodeConfig : Node extends {
|
|
366
434
|
readonly type: "parallel";
|
|
367
435
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
368
436
|
} ? Omit<Node, "states"> & {
|
|
@@ -370,7 +438,7 @@ type DefineStateNodeInput<Node> = Node extends Machine.TaggedSchema ? Node : Nod
|
|
|
370
438
|
} : Node extends {
|
|
371
439
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
372
440
|
} ? Omit<Node, "initial" | "states"> & {
|
|
373
|
-
readonly initial: ActiveStateKey<Children>;
|
|
441
|
+
readonly initial: ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
374
442
|
readonly states: DefineStateTreeInput<Children>;
|
|
375
443
|
} : Node;
|
|
376
444
|
type ValidateDefinedStates<States extends Machine.StateSchemas> = [States] extends [
|
|
@@ -393,7 +461,7 @@ type DuplicateEventTag<Events extends ReadonlyArray<Machine.TaggedSchema>, Seen
|
|
|
393
461
|
] ? Machine.TagOf<Head> extends infer Tag extends PropertyKey ? Tag extends Seen ? Tag | DuplicateEventTag<Tail, Seen> : DuplicateEventTag<Tail, Seen | Tag> : never : never;
|
|
394
462
|
type ValidateInputEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInput extends PropertyKey = DuplicateEventTag<InputEvents>> = [DuplicateInput] extends [never] ? unknown : EventProtocolError<"Public event tags must be unique", DuplicateInput>;
|
|
395
463
|
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>;
|
|
396
|
-
declare const SnapshotBuilderStateTypeId:
|
|
464
|
+
declare const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId;
|
|
397
465
|
declare const SnapshotBuilderConstructionTypeId: unique symbol;
|
|
398
466
|
type SnapshotBuilderComplete<Regions, Constructed extends boolean = false> = {
|
|
399
467
|
readonly [SnapshotBuilderStateTypeId]: Regions;
|
|
@@ -409,7 +477,7 @@ type FromMethod<Arguments extends ReadonlyArray<unknown>, Result> = {
|
|
|
409
477
|
* machine plans the resulting configuration. The input may be omitted when
|
|
410
478
|
* the schema accepts an empty constructor object.
|
|
411
479
|
*
|
|
412
|
-
* @since 4.0
|
|
480
|
+
* @since 0.4.0
|
|
413
481
|
*/
|
|
414
482
|
readonly from: FromCallable<Arguments, Machine.StateConstruction<Result>>;
|
|
415
483
|
};
|
|
@@ -421,6 +489,8 @@ type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input
|
|
|
421
489
|
} : <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected) => Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
422
490
|
type InitialSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
|
|
423
491
|
readonly [Key in ActiveStateKey<States>]: InitialSnapshotMethod<States, Key, Prefix>;
|
|
492
|
+
} & {
|
|
493
|
+
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
424
494
|
};
|
|
425
495
|
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>>;
|
|
426
496
|
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 {
|
|
@@ -432,10 +502,10 @@ type InitialSnapshotArguments<States extends Machine.StateSchemas, StateId exten
|
|
|
432
502
|
] : Node extends {
|
|
433
503
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
434
504
|
} ? Node extends {
|
|
435
|
-
readonly initial: infer Initial extends ActiveStateKey<Children>;
|
|
505
|
+
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
436
506
|
} ? [
|
|
437
507
|
value: Machine.NodeSchema<Node>["Type"],
|
|
438
|
-
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) =>
|
|
508
|
+
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => InitialSelectableResult<Children, Initial, Path>
|
|
439
509
|
] : never : [value: Machine.NodeSchema<Node>["Type"]] : never;
|
|
440
510
|
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 {
|
|
441
511
|
readonly type: "parallel";
|
|
@@ -446,10 +516,10 @@ type InitialSnapshotFromArguments<States extends Machine.StateSchemas, StateId e
|
|
|
446
516
|
] : Node extends {
|
|
447
517
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
448
518
|
} ? Node extends {
|
|
449
|
-
readonly initial: infer Initial extends ActiveStateKey<Children>;
|
|
519
|
+
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
450
520
|
} ? [
|
|
451
521
|
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
452
|
-
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<
|
|
522
|
+
state: (builder: Pick<InitialSnapshotBuilderWithPrefix<Children, Path>, Initial>) => ConstructionResult<InitialSelectableResult<Children, Initial, Path>>
|
|
453
523
|
] : never : [input: Machine.NodeSchema<Node>["~type.make.in"]] : never;
|
|
454
524
|
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 {
|
|
455
525
|
readonly type: "parallel";
|
|
@@ -457,8 +527,9 @@ type InitialSnapshotResult<States extends Machine.StateSchemas, StateId extends
|
|
|
457
527
|
} ? Machine.ParallelSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSnapshotRegionsWithPrefix<Children, Path>> : Node extends {
|
|
458
528
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
459
529
|
} ? Node extends {
|
|
460
|
-
readonly initial: infer Initial extends ActiveStateKey<Children>;
|
|
461
|
-
} ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"],
|
|
530
|
+
readonly initial: infer Initial extends ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
531
|
+
} ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], InitialSelectableResult<Children, Initial, Path>> : never : Machine.AtomicSnapshot<Path, Machine.NodeSchema<Node>["Type"]> : never;
|
|
532
|
+
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;
|
|
462
533
|
type InitialSnapshotRegionsWithPrefix<States extends Machine.StateSchemas, Prefix extends string> = {
|
|
463
534
|
readonly [Key in ActiveStateKey<States>]: InitialSnapshotResult<States, Key, Prefix>;
|
|
464
535
|
};
|
|
@@ -473,6 +544,8 @@ type InitialParallelBuilder<States extends Machine.StateSchemas, Prefix extends
|
|
|
473
544
|
};
|
|
474
545
|
type FullSnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Prefix extends string = ""> = {
|
|
475
546
|
readonly [Key in ActiveStateKey<States>]: FullSnapshotMethod<States, Key, Prefix>;
|
|
547
|
+
} & {
|
|
548
|
+
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
476
549
|
};
|
|
477
550
|
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>>;
|
|
478
551
|
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 {
|
|
@@ -485,7 +558,7 @@ type FullSnapshotArguments<States extends Machine.StateSchemas, StateId extends
|
|
|
485
558
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
486
559
|
} ? [
|
|
487
560
|
value: Machine.NodeSchema<Node>["Type"],
|
|
488
|
-
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path>
|
|
561
|
+
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
|
|
489
562
|
] : [value: Machine.NodeSchema<Node>["Type"]] : never;
|
|
490
563
|
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 {
|
|
491
564
|
readonly type: "parallel";
|
|
@@ -497,7 +570,7 @@ type FullSnapshotFromArguments<States extends Machine.StateSchemas, StateId exte
|
|
|
497
570
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
498
571
|
} ? [
|
|
499
572
|
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
500
|
-
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path
|
|
573
|
+
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>>
|
|
501
574
|
] : [input: Machine.NodeSchema<Node>["~type.make.in"]] : never;
|
|
502
575
|
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>;
|
|
503
576
|
type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
@@ -509,13 +582,68 @@ type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends str
|
|
|
509
582
|
}, true>>;
|
|
510
583
|
};
|
|
511
584
|
};
|
|
585
|
+
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 {
|
|
586
|
+
readonly type: "parallel";
|
|
587
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
588
|
+
} ? [
|
|
589
|
+
value: Machine.NodeSchema<Node>["Type"],
|
|
590
|
+
states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>>
|
|
591
|
+
] : Node extends {
|
|
592
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
593
|
+
} ? [
|
|
594
|
+
value: Machine.NodeSchema<Node>["Type"],
|
|
595
|
+
state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
|
|
596
|
+
] : never : never;
|
|
597
|
+
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 {
|
|
598
|
+
readonly type: "parallel";
|
|
599
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
600
|
+
} ? [
|
|
601
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
602
|
+
states: (builder: HistoryParallelBuilder<Children, Path, Owner>) => SnapshotBuilderComplete<HistorySnapshotRegions<Children, Path, Owner>, boolean>
|
|
603
|
+
] : Node extends {
|
|
604
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
605
|
+
} ? [
|
|
606
|
+
input: Machine.NodeSchema<Node>["~type.make.in"],
|
|
607
|
+
state: (builder: HistorySnapshotBuilderWithPrefix<Children, Owner, Path>) => ConstructionResult<HistorySnapshotWithPrefix<Children, Owner, Path>>
|
|
608
|
+
] : never : never;
|
|
609
|
+
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 {
|
|
610
|
+
readonly type: "parallel";
|
|
611
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
612
|
+
} ? Machine.ParallelSnapshot<Path, Machine.NodeSchema<Node>["Type"], HistorySnapshotRegions<Children, Path, Owner>> : Node extends {
|
|
613
|
+
readonly states: infer Children extends Machine.StateSchemas;
|
|
614
|
+
} ? Machine.CompoundSnapshot<Path, Machine.NodeSchema<Node>["Type"], HistorySnapshotWithPrefix<Children, Owner, Path>> : never : never;
|
|
615
|
+
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>>;
|
|
616
|
+
type HistorySnapshotWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string> = {
|
|
617
|
+
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? HistorySnapshotResult<States, Key, Prefix, Owner> : never;
|
|
618
|
+
}[ActiveStateKey<States>];
|
|
619
|
+
type HistorySnapshotBuilderWithPrefix<States extends Machine.StateSchemas, Owner extends string, Prefix extends string = ""> = {
|
|
620
|
+
readonly [Key in ActiveStateKey<States> as Owner extends Machine.JoinPath<Prefix, Key> | `${Machine.JoinPath<Prefix, Key>}.${string}` ? Key : never]: HistorySnapshotMethod<States, Key, Prefix, Owner>;
|
|
621
|
+
};
|
|
622
|
+
type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends string, Owner extends string> = {
|
|
623
|
+
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>;
|
|
624
|
+
};
|
|
625
|
+
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> & {
|
|
626
|
+
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 & {
|
|
627
|
+
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
628
|
+
}, Constructed>) & {
|
|
629
|
+
readonly from: FromCallable<HistorySnapshotFromArguments<States, Key, Prefix, Owner>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
630
|
+
readonly [Region in Key]: HistorySnapshotResult<States, Key, Prefix, Owner>;
|
|
631
|
+
}, true>>;
|
|
632
|
+
} : ((...args: FullSnapshotArguments<States, Key, Prefix>) => HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
633
|
+
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
634
|
+
}, Constructed>) & {
|
|
635
|
+
readonly from: FromCallable<FullSnapshotFromArguments<States, Key, Prefix>, HistoryParallelBuilder<States, Prefix, Owner, Exclude<Remaining, Key>, Regions & {
|
|
636
|
+
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
637
|
+
}, true>>;
|
|
638
|
+
};
|
|
639
|
+
};
|
|
512
640
|
type ParentPath<Path extends string> = Path extends `${infer Parent}.${infer Child}` ? Child extends `${string}.${string}` ? `${Parent}.${ParentPath<Child>}` : Parent : never;
|
|
513
641
|
type IsCompoundNode<Node> = Node extends {
|
|
514
642
|
readonly type: "parallel";
|
|
515
643
|
} ? false : Node extends {
|
|
516
644
|
readonly states: Machine.StateSchemas;
|
|
517
645
|
} ? true : false;
|
|
518
|
-
type NearestCompoundScope<States extends Machine.StateSchemas, Source extends Machine.
|
|
646
|
+
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;
|
|
519
647
|
type ChildrenOf<States extends Machine.StateSchemas, Path extends Machine.StateIdentifier<States>> = Machine.NodeByIdentifier<States, Path> extends {
|
|
520
648
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
521
649
|
} ? Children : never;
|
|
@@ -527,11 +655,13 @@ type LocalTargetResult<AllStates extends Machine.StateSchemas, States extends Ma
|
|
|
527
655
|
} ? Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>> : LocalTargetResultWithPrefix<AllStates, Children, Path> : Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>;
|
|
528
656
|
type LocalTargetResultWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
529
657
|
readonly [Key in ActiveStateKey<States>]: LocalTargetResult<AllStates, States, Key, Prefix>;
|
|
530
|
-
}[ActiveStateKey<States>]
|
|
531
|
-
type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.
|
|
658
|
+
}[ActiveStateKey<States>] | Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
659
|
+
type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>> = {
|
|
532
660
|
readonly [Key in ActiveStateKey<States>]: LocalTargetMethod<AllStates, States, Key, Prefix, Source>;
|
|
661
|
+
} & {
|
|
662
|
+
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
533
663
|
};
|
|
534
|
-
type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.
|
|
664
|
+
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 {
|
|
535
665
|
readonly type: "parallel";
|
|
536
666
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
537
667
|
} ? 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) & {
|
|
@@ -546,12 +676,12 @@ type LocalTargetMethod<AllStates extends Machine.StateSchemas, States extends Ma
|
|
|
546
676
|
} : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
|
|
547
677
|
input: Machine.NodeSchema<Node>["~type.make.in"]
|
|
548
678
|
], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
|
|
549
|
-
type LocalTargetBuilderForScope<States extends Machine.StateSchemas, Scope extends Machine.StateIdentifier<States>, Source extends Machine.
|
|
679
|
+
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> & {
|
|
550
680
|
/**
|
|
551
681
|
* Updates the value of the state containing the local group and moves to
|
|
552
682
|
* one of the states inside it. Values in other active branches are kept.
|
|
553
683
|
*
|
|
554
|
-
* @since 4.0
|
|
684
|
+
* @since 0.4.0
|
|
555
685
|
*/
|
|
556
686
|
readonly with: (<Result extends ConstructionResult<LocalTargetResultWithPrefix<States, Children, Scope>>>(value: Machine.StateByIdentifier<States, Scope>, state: (builder: LocalTargetBuilderWithPrefix<States, Children, Scope, Source>) => Result) => Result) & {
|
|
557
687
|
readonly from: ConstructionSelectorFromCallable<Machine.SchemaByIdentifier<States, Scope>["~type.make.in"], LocalTargetBuilderWithPrefix<States, Children, Scope, Source>, LocalTargetResultWithPrefix<States, Children, Scope>>;
|
|
@@ -564,11 +694,13 @@ type BranchTargetResult<AllStates extends Machine.StateSchemas, States extends M
|
|
|
564
694
|
} ? Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>> : BranchTargetResultWithPrefix<AllStates, Children, Path> : Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>;
|
|
565
695
|
type BranchTargetResultWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
566
696
|
readonly [Key in ActiveStateKey<States>]: BranchTargetResult<AllStates, States, Key, Prefix>;
|
|
567
|
-
}[ActiveStateKey<States>]
|
|
568
|
-
type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.
|
|
697
|
+
}[ActiveStateKey<States>] | Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
698
|
+
type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>> = {
|
|
569
699
|
readonly [Key in ActiveStateKey<States>]: BranchTargetMethod<AllStates, States, Key, Prefix, Source>;
|
|
700
|
+
} & {
|
|
701
|
+
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
570
702
|
};
|
|
571
|
-
type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Source extends Machine.
|
|
703
|
+
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 {
|
|
572
704
|
readonly type: "parallel";
|
|
573
705
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
574
706
|
} ? 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) & {
|
|
@@ -583,7 +715,7 @@ type BranchTargetMethod<AllStates extends Machine.StateSchemas, States extends M
|
|
|
583
715
|
} & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : ((value: Machine.NodeSchema<Node>["Type"]) => Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>) & FromMethod<[
|
|
584
716
|
input: Machine.NodeSchema<Node>["~type.make.in"]
|
|
585
717
|
], Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>> : never;
|
|
586
|
-
type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.
|
|
718
|
+
type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.StateNodeIdentifier<States>> = {
|
|
587
719
|
readonly [Key in Root]: BranchTargetMethod<States, States, Key, "", Source>;
|
|
588
720
|
};
|
|
589
721
|
type HistoryContainingKey<States extends Machine.StateSchemas> = {
|
|
@@ -634,7 +766,7 @@ type SpawnResult<State, Event, Error, Requirements, Output, SpawnError, InitialE
|
|
|
634
766
|
* with output or fail while processing an event.
|
|
635
767
|
*
|
|
636
768
|
* @category models
|
|
637
|
-
* @since 4.0
|
|
769
|
+
* @since 0.4.0
|
|
638
770
|
*/
|
|
639
771
|
export type RuntimeSnapshot<State, Error = never, Output = never> = {
|
|
640
772
|
readonly status: "active";
|
|
@@ -655,7 +787,7 @@ export type RuntimeSnapshot<State, Error = never, Output = never> = {
|
|
|
655
787
|
* Represents a classified terminal outcome derived from a runtime snapshot.
|
|
656
788
|
*
|
|
657
789
|
* @category models
|
|
658
|
-
* @since 4.0
|
|
790
|
+
* @since 0.4.0
|
|
659
791
|
*/
|
|
660
792
|
export type RuntimeOutcome<State, Error = never, Output = never> = {
|
|
661
793
|
readonly _tag: "Done";
|
|
@@ -707,7 +839,7 @@ export type RuntimeOutcome<State, Error = never, Output = never> = {
|
|
|
707
839
|
* `StoppedError`.
|
|
708
840
|
*
|
|
709
841
|
* @category models
|
|
710
|
-
* @since 4.0
|
|
842
|
+
* @since 0.4.0
|
|
711
843
|
*/
|
|
712
844
|
export interface MachineRef<out State, in Event, out Error = never, out Output = never> {
|
|
713
845
|
/** Stable machine definition id, or a generated fallback when none was declared. */
|
|
@@ -729,13 +861,13 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
729
861
|
/**
|
|
730
862
|
* Returns the current directly owned child for a typed descriptor.
|
|
731
863
|
*
|
|
732
|
-
* @since 4.0
|
|
864
|
+
* @since 0.4.0
|
|
733
865
|
*/
|
|
734
866
|
readonly child: <Child extends ChildMachine.Any>(child: Child) => Effect.Effect<Option.Option<ChildMachine.Ref<Child>>>;
|
|
735
867
|
/**
|
|
736
868
|
* Streams activation, replacement, and removal of a directly owned child.
|
|
737
869
|
*
|
|
738
|
-
* @since 4.0
|
|
870
|
+
* @since 0.4.0
|
|
739
871
|
*/
|
|
740
872
|
readonly childChanges: <Child extends ChildMachine.Any>(child: Child) => Stream.Stream<Option.Option<ChildMachine.Ref<Child>>>;
|
|
741
873
|
}
|
|
@@ -743,7 +875,7 @@ export interface MachineRef<out State, in Event, out Error = never, out Output =
|
|
|
743
875
|
* Machine-specific process logic used by `spawn` and `invoke`.
|
|
744
876
|
*
|
|
745
877
|
* @category models
|
|
746
|
-
* @since 4.0
|
|
878
|
+
* @since 0.4.0
|
|
747
879
|
*/
|
|
748
880
|
export interface Logic<State, Event, out Error = never, out Requirements = never, out Output = never, out InitialError = never> {
|
|
749
881
|
/** Creates the initial process state and may spawn scoped child processes. */
|
|
@@ -754,14 +886,15 @@ export interface Logic<State, Event, out Error = never, out Requirements = never
|
|
|
754
886
|
/**
|
|
755
887
|
* Public types used by advanced machine process logic.
|
|
756
888
|
*
|
|
757
|
-
* @
|
|
889
|
+
* @category models
|
|
890
|
+
* @since 0.4.0
|
|
758
891
|
*/
|
|
759
892
|
export declare namespace Logic {
|
|
760
893
|
/**
|
|
761
894
|
* Machine-local endpoint that can receive events and be stopped.
|
|
762
895
|
*
|
|
763
896
|
* @category models
|
|
764
|
-
* @since 4.0
|
|
897
|
+
* @since 0.4.0
|
|
765
898
|
*/
|
|
766
899
|
interface Address<in Event> {
|
|
767
900
|
/** Parent-local address id. */
|
|
@@ -777,7 +910,7 @@ export declare namespace Logic {
|
|
|
777
910
|
* Starts child process logic owned by the current machine process.
|
|
778
911
|
*
|
|
779
912
|
* @category models
|
|
780
|
-
* @since 4.0
|
|
913
|
+
* @since 0.4.0
|
|
781
914
|
*/
|
|
782
915
|
interface Spawn {
|
|
783
916
|
<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError = never>(logic: Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>): Effect.Effect<MachineRef<ChildState, ChildEvent, ChildError, ChildOutput>, ChildInitialError, Exclude<ChildRequirements, Scope.Scope>>;
|
|
@@ -793,7 +926,7 @@ export declare namespace Logic {
|
|
|
793
926
|
* invoke snapshot mapper when either can represent the communication.
|
|
794
927
|
*
|
|
795
928
|
* @category models
|
|
796
|
-
* @since 4.0
|
|
929
|
+
* @since 0.4.0
|
|
797
930
|
*/
|
|
798
931
|
interface Scope<Event> {
|
|
799
932
|
/** Address of the process being initialized. */
|
|
@@ -813,7 +946,7 @@ export declare namespace Logic {
|
|
|
813
946
|
* Machine-local capabilities available while stateful process logic runs.
|
|
814
947
|
*
|
|
815
948
|
* @category models
|
|
816
|
-
* @since 4.0
|
|
949
|
+
* @since 0.4.0
|
|
817
950
|
*/
|
|
818
951
|
interface Context<State, Event> extends Scope<Event> {
|
|
819
952
|
/** Waits for the next event delivered to this process. */
|
|
@@ -842,7 +975,7 @@ type InvokeLifecycleId = string & {
|
|
|
842
975
|
* event, error, and output types are inferred without separate annotations.
|
|
843
976
|
*
|
|
844
977
|
* @category models
|
|
845
|
-
* @since 4.0
|
|
978
|
+
* @since 0.4.0
|
|
846
979
|
*/
|
|
847
980
|
export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
848
981
|
readonly [ChildMachineTypeId]: typeof ChildMachineTypeId;
|
|
@@ -854,28 +987,29 @@ export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
|
854
987
|
/**
|
|
855
988
|
* Namespace containing type-level members associated with `ChildMachine`.
|
|
856
989
|
*
|
|
857
|
-
* @
|
|
990
|
+
* @category models
|
|
991
|
+
* @since 0.4.0
|
|
858
992
|
*/
|
|
859
993
|
export declare namespace ChildMachine {
|
|
860
994
|
/**
|
|
861
995
|
* Any typed child machine descriptor.
|
|
862
996
|
*
|
|
863
997
|
* @category models
|
|
864
|
-
* @since 4.0
|
|
998
|
+
* @since 0.4.0
|
|
865
999
|
*/
|
|
866
1000
|
type Any = ChildMachine<string, Machine.Any>;
|
|
867
1001
|
/**
|
|
868
1002
|
* Running machine reference selected by a child descriptor.
|
|
869
1003
|
*
|
|
870
1004
|
* @category utility types
|
|
871
|
-
* @since 4.0
|
|
1005
|
+
* @since 0.4.0
|
|
872
1006
|
*/
|
|
873
1007
|
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;
|
|
874
1008
|
/**
|
|
875
1009
|
* Event accepted by the child selected by a descriptor.
|
|
876
1010
|
*
|
|
877
1011
|
* @category utility types
|
|
878
|
-
* @since 4.0
|
|
1012
|
+
* @since 0.4.0
|
|
879
1013
|
*/
|
|
880
1014
|
type Event<Child> = Ref<Child> extends MachineRef<any, infer Event, any, any> ? Event : never;
|
|
881
1015
|
}
|
|
@@ -883,20 +1017,21 @@ export declare namespace ChildMachine {
|
|
|
883
1017
|
* Parent-local address for a child process that can receive events.
|
|
884
1018
|
*
|
|
885
1019
|
* @category models
|
|
886
|
-
* @since 4.0
|
|
1020
|
+
* @since 0.4.0
|
|
887
1021
|
*/
|
|
888
1022
|
export type ChildAddress<Event> = string & ChildAddress.Variance<Event>;
|
|
889
1023
|
/**
|
|
890
1024
|
* Namespace containing type-level members associated with `ChildAddress`.
|
|
891
1025
|
*
|
|
892
|
-
* @
|
|
1026
|
+
* @category models
|
|
1027
|
+
* @since 0.4.0
|
|
893
1028
|
*/
|
|
894
1029
|
export declare namespace ChildAddress {
|
|
895
1030
|
/**
|
|
896
1031
|
* Variance marker carried by a typed child process address.
|
|
897
1032
|
*
|
|
898
1033
|
* @category models
|
|
899
|
-
* @since 4.0
|
|
1034
|
+
* @since 0.4.0
|
|
900
1035
|
*/
|
|
901
1036
|
interface Variance<in Event> {
|
|
902
1037
|
readonly [ChildAddressTypeId]: {
|
|
@@ -907,7 +1042,7 @@ export declare namespace ChildAddress {
|
|
|
907
1042
|
* Extracts the event protocol accepted by a child address.
|
|
908
1043
|
*
|
|
909
1044
|
* @category utility types
|
|
910
|
-
* @since 4.0
|
|
1045
|
+
* @since 0.4.0
|
|
911
1046
|
*/
|
|
912
1047
|
type Event<Address> = Address extends ChildAddress<infer Event> ? Event : unknown;
|
|
913
1048
|
/**
|
|
@@ -915,7 +1050,7 @@ export declare namespace ChildAddress {
|
|
|
915
1050
|
* protocol.
|
|
916
1051
|
*
|
|
917
1052
|
* @category utility types
|
|
918
|
-
* @since 4.0
|
|
1053
|
+
* @since 0.4.0
|
|
919
1054
|
*/
|
|
920
1055
|
type Compatibility<Address, Event> = [Address] extends [ChildAddress<infer AddressEvent>] ? [
|
|
921
1056
|
AddressEvent
|
|
@@ -930,7 +1065,7 @@ export declare namespace ChildAddress {
|
|
|
930
1065
|
* child process event protocol.
|
|
931
1066
|
*
|
|
932
1067
|
* @category utility types
|
|
933
|
-
* @since 4.0
|
|
1068
|
+
* @since 0.4.0
|
|
934
1069
|
*/
|
|
935
1070
|
type OptionsCompatibility<Options, Event> = "id" extends keyof Options ? Options extends {
|
|
936
1071
|
readonly id?: infer Address;
|
|
@@ -940,7 +1075,7 @@ export declare namespace ChildAddress {
|
|
|
940
1075
|
* Options for spawning child processes.
|
|
941
1076
|
*
|
|
942
1077
|
* @category models
|
|
943
|
-
* @since 4.0
|
|
1078
|
+
* @since 0.4.0
|
|
944
1079
|
*/
|
|
945
1080
|
export interface SpawnOptions {
|
|
946
1081
|
readonly id?: string;
|
|
@@ -949,7 +1084,7 @@ export interface SpawnOptions {
|
|
|
949
1084
|
* Options for spawning child processes with a parent-local id.
|
|
950
1085
|
*
|
|
951
1086
|
* @category models
|
|
952
|
-
* @since 4.0
|
|
1087
|
+
* @since 0.4.0
|
|
953
1088
|
*/
|
|
954
1089
|
export interface SpawnIdOptions extends SpawnOptions {
|
|
955
1090
|
readonly id: string;
|
|
@@ -957,7 +1092,8 @@ export interface SpawnIdOptions extends SpawnOptions {
|
|
|
957
1092
|
/**
|
|
958
1093
|
* Namespace containing type-level members associated with `Machine`.
|
|
959
1094
|
*
|
|
960
|
-
* @
|
|
1095
|
+
* @category models
|
|
1096
|
+
* @since 0.4.0
|
|
961
1097
|
*/
|
|
962
1098
|
export declare namespace Machine {
|
|
963
1099
|
/**
|
|
@@ -990,7 +1126,7 @@ export declare namespace Machine {
|
|
|
990
1126
|
* that proof on another concrete `Machine` type.
|
|
991
1127
|
*
|
|
992
1128
|
* @category models
|
|
993
|
-
* @since 4.0
|
|
1129
|
+
* @since 0.4.0
|
|
994
1130
|
*/
|
|
995
1131
|
interface Any extends Pipeable {
|
|
996
1132
|
readonly [TypeId]: TypeId;
|
|
@@ -1002,6 +1138,7 @@ export declare namespace Machine {
|
|
|
1002
1138
|
readonly emits: ReadonlyArray<TaggedSchema>;
|
|
1003
1139
|
readonly input: Schema.Top | undefined;
|
|
1004
1140
|
readonly id: string | undefined;
|
|
1141
|
+
/** @internal */
|
|
1005
1142
|
readonly stateNodes: StateNodes;
|
|
1006
1143
|
/** @internal */
|
|
1007
1144
|
readonly makeTargetBuilder: any;
|
|
@@ -1016,112 +1153,112 @@ export declare namespace Machine {
|
|
|
1016
1153
|
* Extracts the state schema tree carried by a machine definition.
|
|
1017
1154
|
*
|
|
1018
1155
|
* @category utility types
|
|
1019
|
-
* @since 4.0
|
|
1156
|
+
* @since 0.4.0
|
|
1020
1157
|
*/
|
|
1021
1158
|
type States<M extends Any> = M[typeof MachineTypeId]["states"];
|
|
1022
1159
|
/**
|
|
1023
1160
|
* Extracts the complete event schema tuple carried by a machine definition.
|
|
1024
1161
|
*
|
|
1025
1162
|
* @category utility types
|
|
1026
|
-
* @since 4.0
|
|
1163
|
+
* @since 0.4.0
|
|
1027
1164
|
*/
|
|
1028
1165
|
type Events<M extends Any> = M[typeof MachineTypeId]["events"];
|
|
1029
1166
|
/**
|
|
1030
1167
|
* Extracts the input schema carried by a machine definition.
|
|
1031
1168
|
*
|
|
1032
1169
|
* @category utility types
|
|
1033
|
-
* @since 4.0
|
|
1170
|
+
* @since 0.4.0
|
|
1034
1171
|
*/
|
|
1035
1172
|
type Input<M extends Any> = M[typeof MachineTypeId]["input"];
|
|
1036
1173
|
/**
|
|
1037
1174
|
* Extracts state paths that do not yet have handlers.
|
|
1038
1175
|
*
|
|
1039
1176
|
* @category utility types
|
|
1040
|
-
* @since 4.0
|
|
1177
|
+
* @since 0.4.0
|
|
1041
1178
|
*/
|
|
1042
1179
|
type UnhandledStates<M extends Any> = M[typeof MachineTypeId]["unhandledStates"];
|
|
1043
1180
|
/**
|
|
1044
1181
|
* Extracts the runtime error channel carried by a machine definition.
|
|
1045
1182
|
*
|
|
1046
1183
|
* @category utility types
|
|
1047
|
-
* @since 4.0
|
|
1184
|
+
* @since 0.4.0
|
|
1048
1185
|
*/
|
|
1049
1186
|
type Error<M extends Any> = M[typeof MachineTypeId]["error"];
|
|
1050
1187
|
/**
|
|
1051
1188
|
* Extracts runtime service requirements carried by a machine definition.
|
|
1052
1189
|
*
|
|
1053
1190
|
* @category utility types
|
|
1054
|
-
* @since 4.0
|
|
1191
|
+
* @since 0.4.0
|
|
1055
1192
|
*/
|
|
1056
1193
|
type Services<M extends Any> = M[typeof MachineTypeId]["services"];
|
|
1057
1194
|
/**
|
|
1058
1195
|
* Extracts the startup error channel carried by a machine definition.
|
|
1059
1196
|
*
|
|
1060
1197
|
* @category utility types
|
|
1061
|
-
* @since 4.0
|
|
1198
|
+
* @since 0.4.0
|
|
1062
1199
|
*/
|
|
1063
1200
|
type InitialError<M extends Any> = M[typeof MachineTypeId]["initialError"];
|
|
1064
1201
|
/**
|
|
1065
1202
|
* Extracts startup service requirements carried by a machine definition.
|
|
1066
1203
|
*
|
|
1067
1204
|
* @category utility types
|
|
1068
|
-
* @since 4.0
|
|
1205
|
+
* @since 0.4.0
|
|
1069
1206
|
*/
|
|
1070
1207
|
type InitialServices<M extends Any> = M[typeof MachineTypeId]["initialServices"];
|
|
1071
1208
|
/**
|
|
1072
1209
|
* Extracts final state paths carried by a machine definition.
|
|
1073
1210
|
*
|
|
1074
1211
|
* @category utility types
|
|
1075
|
-
* @since 4.0
|
|
1212
|
+
* @since 0.4.0
|
|
1076
1213
|
*/
|
|
1077
1214
|
type FinalStates<M extends Any> = M[typeof MachineTypeId]["finalStates"];
|
|
1078
1215
|
/**
|
|
1079
1216
|
* Extracts the terminal output channel carried by a machine definition.
|
|
1080
1217
|
*
|
|
1081
1218
|
* @category utility types
|
|
1082
|
-
* @since 4.0
|
|
1219
|
+
* @since 0.4.0
|
|
1083
1220
|
*/
|
|
1084
1221
|
type Output<M extends Any> = M[typeof MachineTypeId]["output"];
|
|
1085
1222
|
/**
|
|
1086
1223
|
* Extracts the emitted event schema tuple carried by a machine definition.
|
|
1087
1224
|
*
|
|
1088
1225
|
* @category utility types
|
|
1089
|
-
* @since 4.0
|
|
1226
|
+
* @since 0.4.0
|
|
1090
1227
|
*/
|
|
1091
1228
|
type Emits<M extends Any> = M[typeof MachineTypeId]["emits"];
|
|
1092
1229
|
/**
|
|
1093
1230
|
* Extracts state paths with implemented output handlers.
|
|
1094
1231
|
*
|
|
1095
1232
|
* @category utility types
|
|
1096
|
-
* @since 4.0
|
|
1233
|
+
* @since 0.4.0
|
|
1097
1234
|
*/
|
|
1098
1235
|
type OutputStates<M extends Any> = M[typeof MachineTypeId]["outputStates"];
|
|
1099
1236
|
/**
|
|
1100
1237
|
* Extracts the public input event schema tuple carried by a machine definition.
|
|
1101
1238
|
*
|
|
1102
1239
|
* @category utility types
|
|
1103
|
-
* @since 4.0
|
|
1240
|
+
* @since 0.4.0
|
|
1104
1241
|
*/
|
|
1105
1242
|
type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"];
|
|
1106
1243
|
/**
|
|
1107
1244
|
* Extracts the complete event protocol handled inside a machine.
|
|
1108
1245
|
*
|
|
1109
1246
|
* @category utility types
|
|
1110
|
-
* @since 4.0
|
|
1247
|
+
* @since 0.4.0
|
|
1111
1248
|
*/
|
|
1112
1249
|
type Event<M extends Any> = EventOf<Events<M>>;
|
|
1113
1250
|
/**
|
|
1114
1251
|
* Extracts the event protocol accepted by public machine input boundaries.
|
|
1115
1252
|
*
|
|
1116
1253
|
* @category utility types
|
|
1117
|
-
* @since 4.0
|
|
1254
|
+
* @since 0.4.0
|
|
1118
1255
|
*/
|
|
1119
1256
|
type InputEvent<M extends Any> = EventOf<InputEvents<M>>;
|
|
1120
1257
|
/**
|
|
1121
1258
|
* Extracts the event protocol emitted by a machine.
|
|
1122
1259
|
*
|
|
1123
1260
|
* @category utility types
|
|
1124
|
-
* @since 4.0
|
|
1261
|
+
* @since 0.4.0
|
|
1125
1262
|
*/
|
|
1126
1263
|
type Emit<M extends Any> = EmitOf<Emits<M>>;
|
|
1127
1264
|
/**
|
|
@@ -1132,18 +1269,35 @@ export declare namespace Machine {
|
|
|
1132
1269
|
* This mirrors the tagged-schema constraint used by `Schema.toTaggedUnion`.
|
|
1133
1270
|
*
|
|
1134
1271
|
* @category models
|
|
1135
|
-
* @since 4.0
|
|
1272
|
+
* @since 0.4.0
|
|
1136
1273
|
*/
|
|
1137
1274
|
type TaggedSchema = Schema.Top & {
|
|
1138
1275
|
readonly Type: {
|
|
1139
1276
|
readonly _tag: PropertyKey;
|
|
1140
1277
|
};
|
|
1141
1278
|
};
|
|
1279
|
+
/**
|
|
1280
|
+
* Descriptive annotations exposed for compiled state nodes.
|
|
1281
|
+
*
|
|
1282
|
+
* Schema-backed states resolve their complete Effect Schema annotation map.
|
|
1283
|
+
* Pseudo-states accept only the descriptive fields below. Annotations never
|
|
1284
|
+
* affect state identity, targeting, or runtime behavior.
|
|
1285
|
+
*
|
|
1286
|
+
* @category models
|
|
1287
|
+
* @since 0.4.0
|
|
1288
|
+
*/
|
|
1289
|
+
interface StateNodeAnnotations extends Schema.Annotations.Annotations {
|
|
1290
|
+
readonly title?: string | undefined;
|
|
1291
|
+
readonly description?: string | undefined;
|
|
1292
|
+
readonly documentation?: string | undefined;
|
|
1293
|
+
}
|
|
1294
|
+
/** Descriptive annotations accepted by schema-less pseudo-states. */
|
|
1295
|
+
type PseudoStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
|
|
1142
1296
|
/**
|
|
1143
1297
|
* Configuration accepted for an atomic object state node.
|
|
1144
1298
|
*
|
|
1145
1299
|
* @category models
|
|
1146
|
-
* @since 4.0
|
|
1300
|
+
* @since 0.4.0
|
|
1147
1301
|
*/
|
|
1148
1302
|
type AtomicStateNodeConfig = {
|
|
1149
1303
|
readonly schema: TaggedSchema;
|
|
@@ -1158,7 +1312,7 @@ export declare namespace Machine {
|
|
|
1158
1312
|
* Configuration accepted for a compound object state node.
|
|
1159
1313
|
*
|
|
1160
1314
|
* @category models
|
|
1161
|
-
* @since 4.0
|
|
1315
|
+
* @since 0.4.0
|
|
1162
1316
|
*/
|
|
1163
1317
|
interface CompoundStateNodeConfig {
|
|
1164
1318
|
readonly schema: TaggedSchema;
|
|
@@ -1170,7 +1324,7 @@ export declare namespace Machine {
|
|
|
1170
1324
|
* Configuration accepted for a parallel object state node.
|
|
1171
1325
|
*
|
|
1172
1326
|
* @category models
|
|
1173
|
-
* @since 4.0
|
|
1327
|
+
* @since 0.4.0
|
|
1174
1328
|
*/
|
|
1175
1329
|
interface ParallelStateNodeConfig {
|
|
1176
1330
|
readonly schema: TaggedSchema;
|
|
@@ -1183,34 +1337,55 @@ export declare namespace Machine {
|
|
|
1183
1337
|
*
|
|
1184
1338
|
* History nodes are transition targets only. They never become active and
|
|
1185
1339
|
* therefore do not declare a state value schema or lifecycle handlers.
|
|
1340
|
+
* Both recorded history and a first-use default can rebuild inactive
|
|
1341
|
+
* ancestors. A default is a complete root configuration containing the
|
|
1342
|
+
* history owner, so its validity is independent of the transition source.
|
|
1186
1343
|
*
|
|
1187
1344
|
* @category models
|
|
1188
|
-
* @since 4.0
|
|
1345
|
+
* @since 0.4.0
|
|
1189
1346
|
*/
|
|
1190
1347
|
interface HistoryStateNodeConfig {
|
|
1191
1348
|
readonly type: "history";
|
|
1192
1349
|
/** Defaults to shallow history. */
|
|
1193
1350
|
readonly history?: "shallow" | "deep";
|
|
1351
|
+
readonly annotations?: PseudoStateAnnotations;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Transient decision pseudo-state resolved immediately when targeted.
|
|
1355
|
+
*
|
|
1356
|
+
* Choice nodes have no value and never belong to an active configuration.
|
|
1357
|
+
* Their required `choice` implementation uses ordinary TypeScript or an
|
|
1358
|
+
* Effect to select a typed target.
|
|
1359
|
+
*
|
|
1360
|
+
* @category models
|
|
1361
|
+
* @since 0.4.0
|
|
1362
|
+
*/
|
|
1363
|
+
interface ChoiceStateNodeConfig {
|
|
1364
|
+
readonly type: "choice";
|
|
1365
|
+
readonly annotations?: PseudoStateAnnotations;
|
|
1194
1366
|
}
|
|
1195
1367
|
/**
|
|
1196
1368
|
* Configuration accepted for an object state node.
|
|
1197
1369
|
*
|
|
1198
1370
|
* @category models
|
|
1199
|
-
* @since 4.0
|
|
1371
|
+
* @since 0.4.0
|
|
1200
1372
|
*/
|
|
1201
|
-
type StateNodeConfig = AtomicStateNodeConfig | CompoundStateNodeConfig | ParallelStateNodeConfig | HistoryStateNodeConfig;
|
|
1373
|
+
type StateNodeConfig = AtomicStateNodeConfig | CompoundStateNodeConfig | ParallelStateNodeConfig | HistoryStateNodeConfig | ChoiceStateNodeConfig;
|
|
1202
1374
|
/**
|
|
1203
1375
|
* Object state tree keyed by state path.
|
|
1204
1376
|
*
|
|
1377
|
+
* Keys must be non-empty, non-numeric strings without `.`. The
|
|
1378
|
+
* prototype-mutating key `__proto__` and symbol keys are not accepted.
|
|
1379
|
+
*
|
|
1205
1380
|
* @category models
|
|
1206
|
-
* @since 4.0
|
|
1381
|
+
* @since 0.4.0
|
|
1207
1382
|
*/
|
|
1208
1383
|
type StateTree = Readonly<Record<string, TaggedSchema | StateNodeConfig>>;
|
|
1209
1384
|
/**
|
|
1210
1385
|
* State schema definitions accepted by `make`.
|
|
1211
1386
|
*
|
|
1212
1387
|
* @category models
|
|
1213
|
-
* @since 4.0
|
|
1388
|
+
* @since 0.4.0
|
|
1214
1389
|
*/
|
|
1215
1390
|
type StateSchemas = StateTree;
|
|
1216
1391
|
/**
|
|
@@ -1227,7 +1402,7 @@ export declare namespace Machine {
|
|
|
1227
1402
|
* require every direct region for parallel states.
|
|
1228
1403
|
*
|
|
1229
1404
|
* @category utility types
|
|
1230
|
-
* @since 4.0
|
|
1405
|
+
* @since 0.4.0
|
|
1231
1406
|
*/
|
|
1232
1407
|
type InitialBuilder<States extends StateSchemas> = InitialSnapshotBuilderWithPrefix<States>;
|
|
1233
1408
|
/**
|
|
@@ -1240,7 +1415,7 @@ export declare namespace Machine {
|
|
|
1240
1415
|
* state tree.
|
|
1241
1416
|
*
|
|
1242
1417
|
* @category models
|
|
1243
|
-
* @since 4.0
|
|
1418
|
+
* @since 0.4.0
|
|
1244
1419
|
*/
|
|
1245
1420
|
interface DefinedStates<States extends StateSchemas> {
|
|
1246
1421
|
/** Original state tree supplied to {@link defineStates}. */
|
|
@@ -1250,7 +1425,7 @@ export declare namespace Machine {
|
|
|
1250
1425
|
/**
|
|
1251
1426
|
* Returns the decoded value for an active state path.
|
|
1252
1427
|
*
|
|
1253
|
-
* @since 4.0
|
|
1428
|
+
* @since 0.4.0
|
|
1254
1429
|
*/
|
|
1255
1430
|
readonly get: <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<StateByIdentifier<States, Path>>;
|
|
1256
1431
|
/**
|
|
@@ -1261,19 +1436,19 @@ export declare namespace Machine {
|
|
|
1261
1436
|
*
|
|
1262
1437
|
* Parent values are keyed by their full state paths.
|
|
1263
1438
|
*
|
|
1264
|
-
* @since 4.0
|
|
1439
|
+
* @since 0.4.0
|
|
1265
1440
|
*/
|
|
1266
1441
|
readonly getWithParents: <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<StateWithParents<States, Path>>;
|
|
1267
1442
|
/**
|
|
1268
1443
|
* Returns the snapshot for an active state path.
|
|
1269
1444
|
*
|
|
1270
|
-
* @since 4.0
|
|
1445
|
+
* @since 0.4.0
|
|
1271
1446
|
*/
|
|
1272
1447
|
readonly getSnapshot: <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => Option.Option<SnapshotByIdentifier<States, Path>>;
|
|
1273
1448
|
/**
|
|
1274
1449
|
* Returns whether a state path is active in the snapshot.
|
|
1275
1450
|
*
|
|
1276
|
-
* @since 4.0
|
|
1451
|
+
* @since 0.4.0
|
|
1277
1452
|
*/
|
|
1278
1453
|
readonly matches: <Path extends StateIdentifier<States>>(snapshot: Snapshot<States>, path: Path) => boolean;
|
|
1279
1454
|
}
|
|
@@ -1281,56 +1456,194 @@ export declare namespace Machine {
|
|
|
1281
1456
|
* Validates the nested shape of state schema definitions.
|
|
1282
1457
|
*
|
|
1283
1458
|
* @category utility types
|
|
1284
|
-
* @since 4.0
|
|
1459
|
+
* @since 0.4.0
|
|
1285
1460
|
*/
|
|
1286
1461
|
type ValidateStateSchemas<States extends StateSchemas> = ValidateStateTree<States>;
|
|
1462
|
+
/** Properties shared by every compiled state-node variant. */
|
|
1463
|
+
interface StateNodeBase<Path extends string = string> {
|
|
1464
|
+
readonly path: Path;
|
|
1465
|
+
readonly key: string;
|
|
1466
|
+
/** Resolved Effect Schema annotations, or descriptive pseudo-state annotations. */
|
|
1467
|
+
readonly annotations: Readonly<StateNodeAnnotations> | undefined;
|
|
1468
|
+
readonly order: number;
|
|
1469
|
+
}
|
|
1470
|
+
/** Runtime metadata for a compiled atomic state. */
|
|
1471
|
+
interface AtomicStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1472
|
+
readonly type: "atomic";
|
|
1473
|
+
readonly schema: TaggedSchema;
|
|
1474
|
+
readonly output: undefined;
|
|
1475
|
+
readonly history: undefined;
|
|
1476
|
+
readonly parent: ActivePath | undefined;
|
|
1477
|
+
readonly children: readonly [];
|
|
1478
|
+
readonly initial: undefined;
|
|
1479
|
+
}
|
|
1480
|
+
/** Runtime metadata for a compiled compound state. */
|
|
1481
|
+
interface CompoundStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath, ChoicePath extends string = ActivePath> extends StateNodeBase<OwnPath> {
|
|
1482
|
+
readonly type: "compound";
|
|
1483
|
+
readonly schema: TaggedSchema;
|
|
1484
|
+
readonly output: undefined;
|
|
1485
|
+
readonly history: undefined;
|
|
1486
|
+
readonly parent: ActivePath | undefined;
|
|
1487
|
+
/** Active child paths. Pseudo-states are available through their `parent` relationship. */
|
|
1488
|
+
readonly children: ReadonlyArray<ActivePath>;
|
|
1489
|
+
readonly initial: ActivePath | ChoicePath;
|
|
1490
|
+
}
|
|
1491
|
+
/** Runtime metadata for a compiled parallel state. */
|
|
1492
|
+
interface ParallelStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1493
|
+
readonly type: "parallel";
|
|
1494
|
+
readonly schema: TaggedSchema;
|
|
1495
|
+
readonly output: Schema.Top | undefined;
|
|
1496
|
+
readonly history: undefined;
|
|
1497
|
+
readonly parent: ActivePath | undefined;
|
|
1498
|
+
/** Active child paths. Pseudo-states are available through their `parent` relationship. */
|
|
1499
|
+
readonly children: ReadonlyArray<ActivePath>;
|
|
1500
|
+
readonly initial: undefined;
|
|
1501
|
+
}
|
|
1502
|
+
/** Runtime metadata for a compiled final state. */
|
|
1503
|
+
interface FinalStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1504
|
+
readonly type: "final";
|
|
1505
|
+
readonly schema: TaggedSchema;
|
|
1506
|
+
readonly output: Schema.Top | undefined;
|
|
1507
|
+
readonly history: undefined;
|
|
1508
|
+
readonly parent: ActivePath | undefined;
|
|
1509
|
+
readonly children: readonly [];
|
|
1510
|
+
readonly initial: undefined;
|
|
1511
|
+
}
|
|
1512
|
+
/** Runtime metadata for a compiled history pseudo-state. */
|
|
1513
|
+
interface HistoryStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
|
|
1514
|
+
readonly type: "history";
|
|
1515
|
+
readonly schema: undefined;
|
|
1516
|
+
readonly output: undefined;
|
|
1517
|
+
readonly history: "shallow" | "deep";
|
|
1518
|
+
readonly parent: ActivePath;
|
|
1519
|
+
readonly children: readonly [];
|
|
1520
|
+
readonly initial: undefined;
|
|
1521
|
+
}
|
|
1522
|
+
/** Runtime metadata for a compiled choice pseudo-state. */
|
|
1523
|
+
interface ChoiceStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
|
|
1524
|
+
readonly type: "choice";
|
|
1525
|
+
readonly schema: undefined;
|
|
1526
|
+
readonly output: undefined;
|
|
1527
|
+
readonly history: undefined;
|
|
1528
|
+
readonly parent: ActivePath;
|
|
1529
|
+
readonly children: readonly [];
|
|
1530
|
+
readonly initial: undefined;
|
|
1531
|
+
}
|
|
1287
1532
|
/**
|
|
1288
1533
|
* Runtime metadata for a compiled state node.
|
|
1289
1534
|
*
|
|
1535
|
+
* The `type` discriminator narrows every kind-specific topology and schema
|
|
1536
|
+
* property while preserving a uniform inspection shape.
|
|
1537
|
+
*
|
|
1290
1538
|
* @category models
|
|
1291
|
-
* @since 4.0
|
|
1539
|
+
* @since 0.4.0
|
|
1292
1540
|
*/
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
readonly key: string;
|
|
1296
|
-
readonly schema: TaggedSchema | undefined;
|
|
1297
|
-
readonly output: Schema.Top | undefined;
|
|
1298
|
-
readonly type: "atomic" | "compound" | "parallel" | "final" | "history";
|
|
1299
|
-
readonly history: "shallow" | "deep" | undefined;
|
|
1300
|
-
readonly parent: string | undefined;
|
|
1301
|
-
readonly children: ReadonlyArray<string>;
|
|
1302
|
-
readonly initial: string | undefined;
|
|
1303
|
-
readonly order: number;
|
|
1304
|
-
}
|
|
1541
|
+
type ActiveStateNode<ActivePath extends string = string, ChoicePath extends string = ActivePath> = AtomicStateNode<ActivePath, ActivePath> | CompoundStateNode<ActivePath, ActivePath, ChoicePath> | ParallelStateNode<ActivePath, ActivePath> | FinalStateNode<ActivePath, ActivePath>;
|
|
1542
|
+
type StateNode<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> = ActiveStateNode<ActivePath, ChoicePath> | HistoryStateNode<HistoryPath, ActivePath> | ChoiceStateNode<ChoicePath, ActivePath>;
|
|
1305
1543
|
/**
|
|
1306
1544
|
* Runtime lookup table for state nodes.
|
|
1307
1545
|
*
|
|
1308
1546
|
* @category models
|
|
1309
|
-
* @since 4.0
|
|
1547
|
+
* @since 0.4.0
|
|
1548
|
+
*/
|
|
1549
|
+
interface StateNodes<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> {
|
|
1550
|
+
readonly byPath: ReadonlyMap<ActivePath | HistoryPath | ChoicePath, StateNode<ActivePath, HistoryPath, ChoicePath>>;
|
|
1551
|
+
readonly roots: ReadonlyArray<ActivePath>;
|
|
1552
|
+
}
|
|
1553
|
+
/**
|
|
1554
|
+
* Trigger that selects a registered transition handler.
|
|
1555
|
+
*
|
|
1556
|
+
* @category models
|
|
1557
|
+
* @since 0.4.0
|
|
1558
|
+
*/
|
|
1559
|
+
type TransitionTrigger<EventTag extends PropertyKey = PropertyKey> = {
|
|
1560
|
+
readonly type: "event";
|
|
1561
|
+
readonly event: EventTag;
|
|
1562
|
+
} | {
|
|
1563
|
+
readonly type: "always";
|
|
1564
|
+
} | {
|
|
1565
|
+
readonly type: "done";
|
|
1566
|
+
} | {
|
|
1567
|
+
readonly type: "choice";
|
|
1568
|
+
};
|
|
1569
|
+
/**
|
|
1570
|
+
* Statically inspectable destination paths for a transition handler.
|
|
1571
|
+
* A declared parent path covers every descendant below that state.
|
|
1572
|
+
*
|
|
1573
|
+
* @category models
|
|
1574
|
+
* @since 0.4.0
|
|
1575
|
+
*/
|
|
1576
|
+
type TransitionTargets<Path extends string = string> = {
|
|
1577
|
+
readonly type: "dynamic";
|
|
1578
|
+
} | {
|
|
1579
|
+
readonly type: "declared";
|
|
1580
|
+
readonly paths: ReadonlyArray<Path>;
|
|
1581
|
+
};
|
|
1582
|
+
/**
|
|
1583
|
+
* Inspectable registration for a transition handler.
|
|
1584
|
+
*
|
|
1585
|
+
* **Details**
|
|
1586
|
+
*
|
|
1587
|
+
* Event, eventless, and completion handlers may declare an upper bound of
|
|
1588
|
+
* possible target paths. A handler without that declaration is explicitly
|
|
1589
|
+
* reported as dynamic. The source, trigger, and reentry behavior are
|
|
1590
|
+
* available without executing the handler.
|
|
1591
|
+
*
|
|
1592
|
+
* @category models
|
|
1593
|
+
* @since 0.4.0
|
|
1310
1594
|
*/
|
|
1311
|
-
interface
|
|
1312
|
-
readonly
|
|
1313
|
-
readonly
|
|
1595
|
+
interface TransitionDefinition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
|
|
1596
|
+
readonly source: SourcePath;
|
|
1597
|
+
readonly trigger: TransitionTrigger<EventTag>;
|
|
1598
|
+
readonly reenter: boolean;
|
|
1599
|
+
readonly targets: TransitionTargets<TargetPath>;
|
|
1600
|
+
}
|
|
1601
|
+
/**
|
|
1602
|
+
* Serializable description of state-owned work.
|
|
1603
|
+
*
|
|
1604
|
+
* Static invoke descriptors expose their lifecycle id and kind without
|
|
1605
|
+
* retaining Effects, closures, services, or child runtimes. A function-valued
|
|
1606
|
+
* invoke factory is reported as dynamic and is never evaluated by inspection.
|
|
1607
|
+
*
|
|
1608
|
+
* @category models
|
|
1609
|
+
* @since 0.4.0
|
|
1610
|
+
*/
|
|
1611
|
+
type ActivityDefinition<SourcePath extends string = string> = Activities.ActivityDefinition<SourcePath>;
|
|
1612
|
+
/**
|
|
1613
|
+
* Transition retained after hierarchy precedence and conflict resolution for
|
|
1614
|
+
* one planned microstep.
|
|
1615
|
+
*
|
|
1616
|
+
* @category models
|
|
1617
|
+
* @since 0.4.0
|
|
1618
|
+
*/
|
|
1619
|
+
interface RetainedTransition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
|
|
1620
|
+
readonly source: SourcePath;
|
|
1621
|
+
readonly trigger: TransitionTrigger<EventTag>;
|
|
1622
|
+
readonly reenter: boolean;
|
|
1623
|
+
/** Path returned by the handler, including a history pseudo-state. */
|
|
1624
|
+
readonly target: TargetPath | undefined;
|
|
1625
|
+
/** Concrete path used after resolving history, otherwise equal to `target`. */
|
|
1626
|
+
readonly resolvedTarget: TargetPath | undefined;
|
|
1314
1627
|
}
|
|
1315
1628
|
/**
|
|
1316
1629
|
* Constructor arguments for a machine initial state function.
|
|
1317
1630
|
*
|
|
1318
1631
|
* @category utility types
|
|
1319
|
-
* @since 4.0
|
|
1632
|
+
* @since 0.4.0
|
|
1320
1633
|
*/
|
|
1321
1634
|
type InputArgs<Input extends Schema.Top> = Input extends typeof Schema.Void ? [] : [input: Input["Type"]];
|
|
1322
1635
|
/**
|
|
1323
1636
|
* Extracts the discriminator value represented by a tagged schema.
|
|
1324
1637
|
*
|
|
1325
1638
|
* @category utility types
|
|
1326
|
-
* @since 4.0
|
|
1639
|
+
* @since 0.4.0
|
|
1327
1640
|
*/
|
|
1328
1641
|
type TagOf<S extends TaggedSchema> = S["Type"]["_tag"];
|
|
1329
1642
|
/**
|
|
1330
1643
|
* Extracts the schema from a state tree node definition.
|
|
1331
1644
|
*
|
|
1332
1645
|
* @category utility types
|
|
1333
|
-
* @since 4.0
|
|
1646
|
+
* @since 0.4.0
|
|
1334
1647
|
*/
|
|
1335
1648
|
type NodeSchema<Node> = Node extends TaggedSchema ? Node : Node extends {
|
|
1336
1649
|
readonly schema: infer Schema extends TaggedSchema;
|
|
@@ -1339,14 +1652,14 @@ export declare namespace Machine {
|
|
|
1339
1652
|
* Prefixes a state path with its parent path.
|
|
1340
1653
|
*
|
|
1341
1654
|
* @category utility types
|
|
1342
|
-
* @since 4.0
|
|
1655
|
+
* @since 0.4.0
|
|
1343
1656
|
*/
|
|
1344
1657
|
type JoinPath<Parent extends string, Child extends string> = Parent extends "" ? Child : `${Parent}.${Child}`;
|
|
1345
1658
|
/**
|
|
1346
1659
|
* Extracts the state path values represented by a state definition.
|
|
1347
1660
|
*
|
|
1348
1661
|
* @category utility types
|
|
1349
|
-
* @since 4.0
|
|
1662
|
+
* @since 0.4.0
|
|
1350
1663
|
*/
|
|
1351
1664
|
type StateIdentifier<States extends StateSchemas> = StateIdentifierWithPrefix<States>;
|
|
1352
1665
|
/**
|
|
@@ -1354,10 +1667,10 @@ export declare namespace Machine {
|
|
|
1354
1667
|
* parent path prefix.
|
|
1355
1668
|
*
|
|
1356
1669
|
* @category utility types
|
|
1357
|
-
* @since 4.0
|
|
1670
|
+
* @since 0.4.0
|
|
1358
1671
|
*/
|
|
1359
1672
|
type StateIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
1360
|
-
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? never : States[Key] extends {
|
|
1673
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig | ChoiceStateNodeConfig ? never : States[Key] extends {
|
|
1361
1674
|
readonly states: infer Children;
|
|
1362
1675
|
} ? Children extends StateSchemas ? JoinPath<Prefix, Key> | StateIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : JoinPath<Prefix, Key> : JoinPath<Prefix, Key>;
|
|
1363
1676
|
}[Extract<keyof States, string>];
|
|
@@ -1365,44 +1678,71 @@ export declare namespace Machine {
|
|
|
1365
1678
|
* Extracts the transition-only history pseudo-state paths in a definition.
|
|
1366
1679
|
*
|
|
1367
1680
|
* @category utility types
|
|
1368
|
-
* @since 4.0
|
|
1681
|
+
* @since 0.4.0
|
|
1369
1682
|
*/
|
|
1370
1683
|
type HistoryIdentifier<States extends StateSchemas> = HistoryIdentifierWithPrefix<States>;
|
|
1684
|
+
/** Extracts the transition-only choice pseudo-state paths. */
|
|
1685
|
+
type ChoiceIdentifier<States extends StateSchemas> = ChoiceIdentifierWithPrefix<States>;
|
|
1686
|
+
/**
|
|
1687
|
+
* Extracts every compiled state-node path, including history pseudo-states.
|
|
1688
|
+
*
|
|
1689
|
+
* @category utility types
|
|
1690
|
+
* @since 0.4.0
|
|
1691
|
+
*/
|
|
1692
|
+
type StateNodeIdentifier<States extends StateSchemas> = StateIdentifier<States> | HistoryIdentifier<States> | ChoiceIdentifier<States>;
|
|
1371
1693
|
/** @internal */
|
|
1372
1694
|
type HistoryIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
1373
1695
|
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? JoinPath<Prefix, Key> : States[Key] extends {
|
|
1374
1696
|
readonly states: infer Children extends StateSchemas;
|
|
1375
1697
|
} ? HistoryIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : never;
|
|
1376
1698
|
}[Extract<keyof States, string>];
|
|
1699
|
+
/** @internal */
|
|
1700
|
+
type ChoiceIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
1701
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends ChoiceStateNodeConfig ? JoinPath<Prefix, Key> : States[Key] extends {
|
|
1702
|
+
readonly states: infer Children extends StateSchemas;
|
|
1703
|
+
} ? ChoiceIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : never;
|
|
1704
|
+
}[Extract<keyof States, string>];
|
|
1377
1705
|
/** Active keys directly declared in a state tree. */
|
|
1378
1706
|
type ActiveStateKey<States extends StateSchemas> = {
|
|
1379
|
-
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? never : Key;
|
|
1707
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig | ChoiceStateNodeConfig ? never : Key;
|
|
1380
1708
|
}[Extract<keyof States, string>];
|
|
1381
1709
|
/** History pseudo-state keys directly declared in a state tree. */
|
|
1382
1710
|
type HistoryStateKey<States extends StateSchemas> = {
|
|
1383
1711
|
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? Key : never;
|
|
1384
1712
|
}[Extract<keyof States, string>];
|
|
1713
|
+
/** Choice pseudo-state keys directly declared in a state tree. */
|
|
1714
|
+
type ChoiceStateKey<States extends StateSchemas> = {
|
|
1715
|
+
readonly [Key in Extract<keyof States, string>]: States[Key] extends ChoiceStateNodeConfig ? Key : never;
|
|
1716
|
+
}[Extract<keyof States, string>];
|
|
1385
1717
|
/**
|
|
1386
1718
|
* Active states that must implement implicit initial-value construction for
|
|
1387
1719
|
* shallow history restoration.
|
|
1388
1720
|
*
|
|
1389
1721
|
* @category utility types
|
|
1390
|
-
* @since 4.0
|
|
1722
|
+
* @since 0.4.0
|
|
1391
1723
|
*/
|
|
1392
1724
|
type RequiredHistoryInitializers<States extends StateSchemas> = [HistoryIdentifier<States>] extends [never] ? never : Extract<RequiredHistoryInitializersWithPrefix<States, States, "">, StateIdentifier<States>>;
|
|
1393
1725
|
/** Active parent states that own one or more history pseudo-states. */
|
|
1394
1726
|
type HistoryParentIdentifier<States extends StateSchemas> = HistoryIdentifier<States> extends infer HistoryId ? HistoryId extends string ? Extract<ImmediateParentStateIdentifier<HistoryId>, StateIdentifier<States>> : never : never;
|
|
1727
|
+
/** Active parent states that own one or more choice pseudo-states. */
|
|
1728
|
+
type ChoiceParentIdentifier<States extends StateSchemas> = ChoiceIdentifier<States> extends infer ChoiceId ? ChoiceId extends string ? Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>> : never : never;
|
|
1395
1729
|
/** History defaults and implicit initializers that remain unimplemented. */
|
|
1396
1730
|
type MissingHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, HistoryParentIdentifier<States> | RequiredHistoryInitializers<States>>;
|
|
1731
|
+
/** Choice-owning active parents that remain unimplemented. */
|
|
1732
|
+
type MissingChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, ChoiceParentIdentifier<States>>;
|
|
1733
|
+
/** @internal Readiness proof for required choice resolvers. */
|
|
1734
|
+
type EnsureChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [ChoiceIdentifier<States>] extends [never] ? unknown : [MissingChoiceImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
1735
|
+
readonly "~effect/Machine/MissingChoiceImplementation": MissingChoiceImplementations<States, UnhandledStates>;
|
|
1736
|
+
};
|
|
1397
1737
|
/** @internal Readiness proof required by planning and managed execution. */
|
|
1398
|
-
type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
1738
|
+
type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = ([HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
1399
1739
|
readonly "~effect/Machine/MissingHistoryImplementation": MissingHistoryImplementations<States, UnhandledStates>;
|
|
1400
|
-
}
|
|
1740
|
+
}) & EnsureChoiceImplementations<States, UnhandledStates>;
|
|
1401
1741
|
/**
|
|
1402
1742
|
* Extracts a state-tree node by state path.
|
|
1403
1743
|
*
|
|
1404
1744
|
* @category utility types
|
|
1405
|
-
* @since 4.0
|
|
1745
|
+
* @since 0.4.0
|
|
1406
1746
|
*/
|
|
1407
1747
|
type NodeByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
1408
1748
|
readonly states: infer Children extends StateSchemas;
|
|
@@ -1411,21 +1751,21 @@ export declare namespace Machine {
|
|
|
1411
1751
|
* Extracts a schema from a state definition by state identifier.
|
|
1412
1752
|
*
|
|
1413
1753
|
* @category utility types
|
|
1414
|
-
* @since 4.0
|
|
1754
|
+
* @since 0.4.0
|
|
1415
1755
|
*/
|
|
1416
1756
|
type SchemaByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeSchema<NodeByIdentifier<States, StateId>>;
|
|
1417
1757
|
/**
|
|
1418
1758
|
* Extracts the union of state values represented by a state definition.
|
|
1419
1759
|
*
|
|
1420
1760
|
* @category utility types
|
|
1421
|
-
* @since 4.0
|
|
1761
|
+
* @since 0.4.0
|
|
1422
1762
|
*/
|
|
1423
1763
|
type StateOf<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : never : never;
|
|
1424
1764
|
/**
|
|
1425
1765
|
* Extracts the union of event values represented by an event schema list.
|
|
1426
1766
|
*
|
|
1427
1767
|
* @category utility types
|
|
1428
|
-
* @since 4.0
|
|
1768
|
+
* @since 0.4.0
|
|
1429
1769
|
*/
|
|
1430
1770
|
type EventOf<Events extends ReadonlyArray<TaggedSchema>> = Events[number]["Type"];
|
|
1431
1771
|
/**
|
|
@@ -1433,49 +1773,42 @@ export declare namespace Machine {
|
|
|
1433
1773
|
* schema list.
|
|
1434
1774
|
*
|
|
1435
1775
|
* @category utility types
|
|
1436
|
-
* @since 4.0
|
|
1776
|
+
* @since 0.4.0
|
|
1437
1777
|
*/
|
|
1438
1778
|
type EmitOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"];
|
|
1439
1779
|
/**
|
|
1440
1780
|
* Event values received by lifecycle callbacks.
|
|
1441
1781
|
*
|
|
1442
1782
|
* @category utility types
|
|
1443
|
-
* @since 4.0
|
|
1783
|
+
* @since 0.4.0
|
|
1444
1784
|
*/
|
|
1445
1785
|
type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> = EventOf<Events> | InitialEvent;
|
|
1446
|
-
/**
|
|
1447
|
-
* Runtime capability specialized to a machine's event protocols.
|
|
1448
|
-
*
|
|
1449
|
-
* @category utility types
|
|
1450
|
-
* @since 4.0.0
|
|
1451
|
-
*/
|
|
1452
|
-
type RuntimeEffect<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>> = Effect.Effect<Runtime<EventOf<Events>, EmitOf<Emits>>, never, Runtime.Requirement<EventOf<Events>, EmitOf<Emits>>>;
|
|
1453
1786
|
/**
|
|
1454
1787
|
* Extracts a state value from a state definition by identifier.
|
|
1455
1788
|
*
|
|
1456
1789
|
* @category utility types
|
|
1457
|
-
* @since 4.0
|
|
1790
|
+
* @since 0.4.0
|
|
1458
1791
|
*/
|
|
1459
1792
|
type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = Extract<StateOf<States>, SchemaByIdentifier<States, StateId>["Type"]>;
|
|
1460
1793
|
/**
|
|
1461
1794
|
* Extracts every parent state path from a state identifier.
|
|
1462
1795
|
*
|
|
1463
1796
|
* @category utility types
|
|
1464
|
-
* @since 4.0
|
|
1797
|
+
* @since 0.4.0
|
|
1465
1798
|
*/
|
|
1466
1799
|
type ParentStateIdentifier<StateId extends string> = StateId extends `${infer Parent}.${infer Child}` ? Parent | (Child extends `${string}.${string}` ? `${Parent}.${ParentStateIdentifier<Child>}` : never) : never;
|
|
1467
1800
|
/**
|
|
1468
1801
|
* Extracts the nearest parent state path from a state identifier.
|
|
1469
1802
|
*
|
|
1470
1803
|
* @category utility types
|
|
1471
|
-
* @since 4.0
|
|
1804
|
+
* @since 0.4.0
|
|
1472
1805
|
*/
|
|
1473
1806
|
type ImmediateParentStateIdentifier<StateId extends string> = StateId extends `${infer Head}.${infer Tail}` ? Tail extends `${string}.${string}` ? `${Head}.${ImmediateParentStateIdentifier<Tail>}` : Head : never;
|
|
1474
1807
|
/**
|
|
1475
1808
|
* Maps every parent state path of a state identifier to its decoded value.
|
|
1476
1809
|
*
|
|
1477
1810
|
* @category utility types
|
|
1478
|
-
* @since 4.0
|
|
1811
|
+
* @since 0.4.0
|
|
1479
1812
|
*/
|
|
1480
1813
|
type ParentStateValues<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
1481
1814
|
readonly [Parent in Extract<ParentStateIdentifier<StateId>, StateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
@@ -1484,14 +1817,14 @@ export declare namespace Machine {
|
|
|
1484
1817
|
* Extracts the nearest parent value, or `undefined` for a root state.
|
|
1485
1818
|
*
|
|
1486
1819
|
* @category utility types
|
|
1487
|
-
* @since 4.0
|
|
1820
|
+
* @since 0.4.0
|
|
1488
1821
|
*/
|
|
1489
1822
|
type ParentStateValue<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? Extract<ImmediateParentStateIdentifier<StateId>, StateIdentifier<States>> extends infer Parent ? [Parent] extends [never] ? undefined : Parent extends StateIdentifier<States> ? StateByIdentifier<States, Parent> : undefined : undefined : never;
|
|
1490
1823
|
/**
|
|
1491
1824
|
* Represents a decoded state value together with all of its parent values.
|
|
1492
1825
|
*
|
|
1493
1826
|
* @category models
|
|
1494
|
-
* @since 4.0
|
|
1827
|
+
* @since 0.4.0
|
|
1495
1828
|
*/
|
|
1496
1829
|
type StateWithParents<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
1497
1830
|
readonly value: StateByIdentifier<States, StateId>;
|
|
@@ -1505,7 +1838,7 @@ export declare namespace Machine {
|
|
|
1505
1838
|
* Extracts the declared output type for a state node.
|
|
1506
1839
|
*
|
|
1507
1840
|
* @category utility types
|
|
1508
|
-
* @since 4.0
|
|
1841
|
+
* @since 0.4.0
|
|
1509
1842
|
*/
|
|
1510
1843
|
type OutputByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeOutput<NodeByIdentifier<States, StateId>>;
|
|
1511
1844
|
type DirectFinalCompletionOutput<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends {
|
|
@@ -1519,7 +1852,7 @@ export declare namespace Machine {
|
|
|
1519
1852
|
* Extracts the output passed when a state node completes.
|
|
1520
1853
|
*
|
|
1521
1854
|
* @category utility types
|
|
1522
|
-
* @since 4.0
|
|
1855
|
+
* @since 0.4.0
|
|
1523
1856
|
*/
|
|
1524
1857
|
type CompletionOutputByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
1525
1858
|
readonly type: "parallel";
|
|
@@ -1542,7 +1875,7 @@ export declare namespace Machine {
|
|
|
1542
1875
|
* before that root becomes the machine's terminal result.
|
|
1543
1876
|
*
|
|
1544
1877
|
* @category utility types
|
|
1545
|
-
* @since 4.0
|
|
1878
|
+
* @since 0.4.0
|
|
1546
1879
|
*/
|
|
1547
1880
|
type TerminalOutput<States extends StateSchemas> = {
|
|
1548
1881
|
readonly [Key in Extract<keyof States, string>]: Extract<Key, StateIdentifier<States>> extends infer StateId extends StateIdentifier<States> ? NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
@@ -1555,7 +1888,7 @@ export declare namespace Machine {
|
|
|
1555
1888
|
* Extracts every state path whose definition declares an output schema.
|
|
1556
1889
|
*
|
|
1557
1890
|
* @category utility types
|
|
1558
|
-
* @since 4.0
|
|
1891
|
+
* @since 0.4.0
|
|
1559
1892
|
*/
|
|
1560
1893
|
type DeclaredOutputState<States extends StateSchemas> = {
|
|
1561
1894
|
readonly [StateId in StateIdentifier<States>]: NodeByIdentifier<States, StateId> extends {
|
|
@@ -1567,7 +1900,7 @@ export declare namespace Machine {
|
|
|
1567
1900
|
* implementation before a machine is planned or started.
|
|
1568
1901
|
*
|
|
1569
1902
|
* @category utility types
|
|
1570
|
-
* @since 4.0
|
|
1903
|
+
* @since 0.4.0
|
|
1571
1904
|
*/
|
|
1572
1905
|
type EnsureOutputImplementations<States extends StateSchemas, OutputStates extends StateIdentifier<States>> = [
|
|
1573
1906
|
Exclude<DeclaredOutputState<States>, OutputStates>
|
|
@@ -1584,7 +1917,7 @@ export declare namespace Machine {
|
|
|
1584
1917
|
* machine snapshot.
|
|
1585
1918
|
*
|
|
1586
1919
|
* @category utility types
|
|
1587
|
-
* @since 4.0
|
|
1920
|
+
* @since 0.4.0
|
|
1588
1921
|
*/
|
|
1589
1922
|
type SnapshotDecodingServices<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? DecodingServices<SchemaByIdentifier<States, StateId>> | DecodingServices<OutputSchema<NodeByIdentifier<States, StateId>>> : never : never;
|
|
1590
1923
|
/**
|
|
@@ -1592,14 +1925,14 @@ export declare namespace Machine {
|
|
|
1592
1925
|
* machine snapshot.
|
|
1593
1926
|
*
|
|
1594
1927
|
* @category utility types
|
|
1595
|
-
* @since 4.0
|
|
1928
|
+
* @since 0.4.0
|
|
1596
1929
|
*/
|
|
1597
1930
|
type SnapshotEncodingServices<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? EncodingServices<SchemaByIdentifier<States, StateId>> | EncodingServices<OutputSchema<NodeByIdentifier<States, StateId>>> : never : never;
|
|
1598
1931
|
/**
|
|
1599
1932
|
* Encoded value for one active state path in a normalized machine snapshot.
|
|
1600
1933
|
*
|
|
1601
1934
|
* @category models
|
|
1602
|
-
* @since 4.0
|
|
1935
|
+
* @since 0.4.0
|
|
1603
1936
|
*/
|
|
1604
1937
|
interface EncodedSnapshotState {
|
|
1605
1938
|
readonly path: string;
|
|
@@ -1610,7 +1943,7 @@ export declare namespace Machine {
|
|
|
1610
1943
|
* snapshot. An omitted output represents `undefined`.
|
|
1611
1944
|
*
|
|
1612
1945
|
* @category models
|
|
1613
|
-
* @since 4.0
|
|
1946
|
+
* @since 0.4.0
|
|
1614
1947
|
*/
|
|
1615
1948
|
interface EncodedSnapshotCompletion {
|
|
1616
1949
|
readonly path: string;
|
|
@@ -1632,7 +1965,7 @@ export declare namespace Machine {
|
|
|
1632
1965
|
* scopes, queues, and subscriptions is not included.
|
|
1633
1966
|
*
|
|
1634
1967
|
* @category models
|
|
1635
|
-
* @since 4.0
|
|
1968
|
+
* @since 0.4.0
|
|
1636
1969
|
*/
|
|
1637
1970
|
interface EncodedSnapshot {
|
|
1638
1971
|
readonly _tag: "MachineSnapshot";
|
|
@@ -1644,7 +1977,7 @@ export declare namespace Machine {
|
|
|
1644
1977
|
* Completed state path and its resolved output value.
|
|
1645
1978
|
*
|
|
1646
1979
|
* @category models
|
|
1647
|
-
* @since 4.0
|
|
1980
|
+
* @since 0.4.0
|
|
1648
1981
|
*/
|
|
1649
1982
|
interface SnapshotCompletion {
|
|
1650
1983
|
readonly path: string;
|
|
@@ -1670,7 +2003,7 @@ export declare namespace Machine {
|
|
|
1670
2003
|
* or transport boundary.
|
|
1671
2004
|
*
|
|
1672
2005
|
* @category models
|
|
1673
|
-
* @since 4.0
|
|
2006
|
+
* @since 0.4.0
|
|
1674
2007
|
*/
|
|
1675
2008
|
interface SnapshotMetadata {
|
|
1676
2009
|
readonly completed?: ReadonlyArray<SnapshotCompletion>;
|
|
@@ -1681,7 +2014,7 @@ export declare namespace Machine {
|
|
|
1681
2014
|
* decoded state value.
|
|
1682
2015
|
*
|
|
1683
2016
|
* @category models
|
|
1684
|
-
* @since 4.0
|
|
2017
|
+
* @since 0.4.0
|
|
1685
2018
|
*/
|
|
1686
2019
|
interface AtomicSnapshot<Path extends string, Value> extends SnapshotMetadata {
|
|
1687
2020
|
readonly path: Path;
|
|
@@ -1692,7 +2025,7 @@ export declare namespace Machine {
|
|
|
1692
2025
|
* snapshot.
|
|
1693
2026
|
*
|
|
1694
2027
|
* @category models
|
|
1695
|
-
* @since 4.0
|
|
2028
|
+
* @since 0.4.0
|
|
1696
2029
|
*/
|
|
1697
2030
|
interface CompoundSnapshot<Path extends string, Value, Child> extends SnapshotMetadata {
|
|
1698
2031
|
readonly path: Path;
|
|
@@ -1704,7 +2037,7 @@ export declare namespace Machine {
|
|
|
1704
2037
|
* per child region.
|
|
1705
2038
|
*
|
|
1706
2039
|
* @category models
|
|
1707
|
-
* @since 4.0
|
|
2040
|
+
* @since 0.4.0
|
|
1708
2041
|
*/
|
|
1709
2042
|
interface ParallelSnapshot<Path extends string, Value, Regions> extends SnapshotMetadata {
|
|
1710
2043
|
readonly path: Path;
|
|
@@ -1716,7 +2049,7 @@ export declare namespace Machine {
|
|
|
1716
2049
|
* identifier.
|
|
1717
2050
|
*
|
|
1718
2051
|
* @category utility types
|
|
1719
|
-
* @since 4.0
|
|
2052
|
+
* @since 0.4.0
|
|
1720
2053
|
*/
|
|
1721
2054
|
type SnapshotByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
1722
2055
|
readonly type: "parallel";
|
|
@@ -1728,7 +2061,7 @@ export declare namespace Machine {
|
|
|
1728
2061
|
* Extracts child snapshots under a parent path prefix.
|
|
1729
2062
|
*
|
|
1730
2063
|
* @category utility types
|
|
1731
|
-
* @since 4.0
|
|
2064
|
+
* @since 0.4.0
|
|
1732
2065
|
*/
|
|
1733
2066
|
type SnapshotWithPrefix<States extends StateSchemas, Prefix extends string> = {
|
|
1734
2067
|
readonly [Key in ActiveStateKey<States>]: SnapshotByIdentifierWithPath<States, Key, JoinPath<Prefix, Key>>;
|
|
@@ -1738,7 +2071,7 @@ export declare namespace Machine {
|
|
|
1738
2071
|
* child region.
|
|
1739
2072
|
*
|
|
1740
2073
|
* @category utility types
|
|
1741
|
-
* @since 4.0
|
|
2074
|
+
* @since 0.4.0
|
|
1742
2075
|
*/
|
|
1743
2076
|
type SnapshotRegionsWithPrefix<States extends StateSchemas, Prefix extends string> = {
|
|
1744
2077
|
readonly [Key in ActiveStateKey<States>]: SnapshotByIdentifierWithPath<States, Key, JoinPath<Prefix, Key>>;
|
|
@@ -1747,7 +2080,7 @@ export declare namespace Machine {
|
|
|
1747
2080
|
* Extracts a snapshot for a state node while preserving its full path.
|
|
1748
2081
|
*
|
|
1749
2082
|
* @category utility types
|
|
1750
|
-
* @since 4.0
|
|
2083
|
+
* @since 0.4.0
|
|
1751
2084
|
*/
|
|
1752
2085
|
type SnapshotByIdentifierWithPath<States extends StateSchemas, StateId extends ActiveStateKey<States>, Path extends string> = States[StateId] extends {
|
|
1753
2086
|
readonly type: "parallel";
|
|
@@ -1755,12 +2088,23 @@ export declare namespace Machine {
|
|
|
1755
2088
|
} ? Children extends StateSchemas ? ParallelSnapshot<Path, NodeSchema<States[StateId]>["Type"], SnapshotRegionsWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]> : States[StateId] extends {
|
|
1756
2089
|
readonly states: infer Children;
|
|
1757
2090
|
} ? Children extends StateSchemas ? CompoundSnapshot<Path, NodeSchema<States[StateId]>["Type"], SnapshotWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]> : AtomicSnapshot<Path, NodeSchema<States[StateId]>["Type"]>;
|
|
2091
|
+
/**
|
|
2092
|
+
* Extracts a complete root snapshot whose selected configuration contains a
|
|
2093
|
+
* particular active state.
|
|
2094
|
+
*
|
|
2095
|
+
* Parallel ancestors still require every region, while compound ancestors
|
|
2096
|
+
* are narrowed to the branch leading to `Owner`.
|
|
2097
|
+
*
|
|
2098
|
+
* @category utility types
|
|
2099
|
+
* @since 0.4.0
|
|
2100
|
+
*/
|
|
2101
|
+
type CompleteSnapshotContaining<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotWithPrefix<States, Owner, "">;
|
|
1758
2102
|
/**
|
|
1759
2103
|
* Extracts the union of statechart snapshots represented by a state
|
|
1760
2104
|
* definition.
|
|
1761
2105
|
*
|
|
1762
2106
|
* @category models
|
|
1763
|
-
* @since 4.0
|
|
2107
|
+
* @since 0.4.0
|
|
1764
2108
|
*/
|
|
1765
2109
|
type Snapshot<States extends StateSchemas> = {
|
|
1766
2110
|
readonly [StateId in ActiveStateKey<States>]: SnapshotByIdentifier<States, StateId & StateIdentifier<States>>;
|
|
@@ -1769,21 +2113,21 @@ export declare namespace Machine {
|
|
|
1769
2113
|
* Extracts the root state identifier from a state path.
|
|
1770
2114
|
*
|
|
1771
2115
|
* @category utility types
|
|
1772
|
-
* @since 4.0
|
|
2116
|
+
* @since 0.4.0
|
|
1773
2117
|
*/
|
|
1774
2118
|
type RootStateIdentifier<StateId extends string> = StateId extends `${infer Root}.${string}` ? Root : StateId;
|
|
1775
2119
|
/**
|
|
1776
2120
|
* Extracts the public snapshot shape that contains a final state path.
|
|
1777
2121
|
*
|
|
1778
2122
|
* @category utility types
|
|
1779
|
-
* @since 4.0
|
|
2123
|
+
* @since 0.4.0
|
|
1780
2124
|
*/
|
|
1781
2125
|
type SnapshotContainingFinal<States extends StateSchemas, FinalStates extends StateIdentifier<States>> = FinalStates extends StateIdentifier<States> ? RootStateIdentifier<FinalStates> extends infer Root extends StateIdentifier<States> ? SnapshotByIdentifier<States, Root> : never : never;
|
|
1782
2126
|
/**
|
|
1783
2127
|
* Extracts state identifiers whose state-tree definition marks them final.
|
|
1784
2128
|
*
|
|
1785
2129
|
* @category utility types
|
|
1786
|
-
* @since 4.0
|
|
2130
|
+
* @since 0.4.0
|
|
1787
2131
|
*/
|
|
1788
2132
|
type FinalStateFromDefinition<States extends StateSchemas> = {
|
|
1789
2133
|
readonly [StateId in StateIdentifier<States>]: NodeByIdentifier<States, StateId> extends {
|
|
@@ -1794,11 +2138,15 @@ export declare namespace Machine {
|
|
|
1794
2138
|
* Extracts an event value from an event schema list by tag.
|
|
1795
2139
|
*
|
|
1796
2140
|
* @category utility types
|
|
1797
|
-
* @since 4.0
|
|
2141
|
+
* @since 0.4.0
|
|
1798
2142
|
*/
|
|
1799
2143
|
type EventByTag<Events extends ReadonlyArray<TaggedSchema>, Tag extends TagOf<Events[number]>> = Extract<EventOf<Events>, {
|
|
1800
2144
|
readonly _tag: Tag;
|
|
1801
|
-
}
|
|
2145
|
+
}> | (EventOf<Events> extends infer Event ? Event extends {
|
|
2146
|
+
readonly _tag: infer EventTag extends PropertyKey;
|
|
2147
|
+
} ? [EventTag] extends [Tag] ? never : [Tag] extends [EventTag] ? Omit<Event, "_tag"> & {
|
|
2148
|
+
readonly _tag: Tag;
|
|
2149
|
+
} : never : never : never);
|
|
1802
2150
|
/**
|
|
1803
2151
|
* Opaque state construction returned by a builder's `.from` method.
|
|
1804
2152
|
*
|
|
@@ -1807,20 +2155,20 @@ export declare namespace Machine {
|
|
|
1807
2155
|
* planning succeeds.
|
|
1808
2156
|
*
|
|
1809
2157
|
* @category models
|
|
1810
|
-
* @since 4.0
|
|
2158
|
+
* @since 0.4.0
|
|
1811
2159
|
*/
|
|
1812
2160
|
interface StateConstruction<Result> {
|
|
1813
|
-
readonly [
|
|
2161
|
+
readonly [Topology.StateConstructionTypeId]: Result;
|
|
1814
2162
|
}
|
|
1815
2163
|
/**
|
|
1816
2164
|
* Machine-bound target instruction accepted from transition handlers.
|
|
1817
2165
|
*
|
|
1818
2166
|
* @category models
|
|
1819
|
-
* @since 4.0
|
|
2167
|
+
* @since 0.4.0
|
|
1820
2168
|
*/
|
|
1821
2169
|
interface Target<States extends StateSchemas, StateId extends StateIdentifier<States>> {
|
|
1822
|
-
readonly [
|
|
1823
|
-
readonly [
|
|
2170
|
+
readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId;
|
|
2171
|
+
readonly [Topology.TargetSnapshotTypeId]?: SnapshotByIdentifier<States, StateId>;
|
|
1824
2172
|
readonly path: StateId;
|
|
1825
2173
|
readonly value: StateByIdentifier<States, StateId>;
|
|
1826
2174
|
readonly values?: Partial<{
|
|
@@ -1835,13 +2183,24 @@ export declare namespace Machine {
|
|
|
1835
2183
|
* history node's typed default when no record exists.
|
|
1836
2184
|
*
|
|
1837
2185
|
* @category models
|
|
1838
|
-
* @since 4.0
|
|
2186
|
+
* @since 0.4.0
|
|
1839
2187
|
*/
|
|
1840
2188
|
interface HistoryTarget<States extends StateSchemas, HistoryId extends HistoryIdentifier<States>> {
|
|
1841
|
-
readonly [
|
|
2189
|
+
readonly [Topology.HistoryTargetTypeId]: typeof Topology.HistoryTargetTypeId;
|
|
1842
2190
|
readonly path: HistoryId;
|
|
1843
2191
|
readonly parent: Extract<ParentPath<HistoryId>, StateIdentifier<States>>;
|
|
1844
2192
|
}
|
|
2193
|
+
/** Branded transient target instruction used while constructing initial states. */
|
|
2194
|
+
interface ChoiceTargetInstruction<ChoiceId extends string = string> {
|
|
2195
|
+
readonly [Topology.ChoiceTargetTypeId]: typeof Topology.ChoiceTargetTypeId;
|
|
2196
|
+
readonly path: ChoiceId;
|
|
2197
|
+
readonly parent: ParentPath<ChoiceId>;
|
|
2198
|
+
readonly values?: Readonly<Record<string, unknown>>;
|
|
2199
|
+
}
|
|
2200
|
+
/** Transition instruction that enters a transient choice pseudo-state. */
|
|
2201
|
+
interface ChoiceTarget<States extends StateSchemas, ChoiceId extends ChoiceIdentifier<States>> extends ChoiceTargetInstruction<ChoiceId> {
|
|
2202
|
+
readonly parent: Extract<ParentPath<ChoiceId>, StateIdentifier<States>>;
|
|
2203
|
+
}
|
|
1845
2204
|
/** Builder containing only history pseudo-state paths. */
|
|
1846
2205
|
type HistoryTargetBuilder<States extends StateSchemas> = HistoryTargetBuilderWithPrefix<States, States, "">;
|
|
1847
2206
|
/**
|
|
@@ -1853,9 +2212,16 @@ export declare namespace Machine {
|
|
|
1853
2212
|
* every active child below the selected root.
|
|
1854
2213
|
*
|
|
1855
2214
|
* @category utility types
|
|
1856
|
-
* @since 4.0
|
|
2215
|
+
* @since 0.4.0
|
|
1857
2216
|
*/
|
|
1858
2217
|
type FullTargetBuilder<States extends StateSchemas> = FullSnapshotBuilderWithPrefix<States>;
|
|
2218
|
+
/**
|
|
2219
|
+
* Builder for a complete fallback configuration containing a history owner.
|
|
2220
|
+
*
|
|
2221
|
+
* @category utility types
|
|
2222
|
+
* @since 0.4.0
|
|
2223
|
+
*/
|
|
2224
|
+
type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotBuilderWithPrefix<States, Owner>;
|
|
1859
2225
|
/**
|
|
1860
2226
|
* Builder for source-local transition targets.
|
|
1861
2227
|
*
|
|
@@ -1865,9 +2231,9 @@ export declare namespace Machine {
|
|
|
1865
2231
|
* the source state and should preserve active ancestor and sibling values.
|
|
1866
2232
|
*
|
|
1867
2233
|
* @category utility types
|
|
1868
|
-
* @since 4.0
|
|
2234
|
+
* @since 0.4.0
|
|
1869
2235
|
*/
|
|
1870
|
-
type LocalTargetBuilder<States extends StateSchemas, Source extends
|
|
2236
|
+
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> : {} : {};
|
|
1871
2237
|
/**
|
|
1872
2238
|
* Builder for partial transition targets within the active source root.
|
|
1873
2239
|
*
|
|
@@ -1877,9 +2243,9 @@ export declare namespace Machine {
|
|
|
1877
2243
|
* root while preserving unmentioned active ancestors or parallel regions.
|
|
1878
2244
|
*
|
|
1879
2245
|
* @category utility types
|
|
1880
|
-
* @since 4.0
|
|
2246
|
+
* @since 0.4.0
|
|
1881
2247
|
*/
|
|
1882
|
-
type BranchTargetBuilder<States extends StateSchemas, Source extends
|
|
2248
|
+
type BranchTargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = BranchTargetBuilderForRoot<States, Extract<RootStateIdentifier<Source>, ActiveStateKey<States>>, Source>;
|
|
1883
2249
|
/**
|
|
1884
2250
|
* Machine-bound target builders available in transition contexts.
|
|
1885
2251
|
*
|
|
@@ -1897,14 +2263,14 @@ export declare namespace Machine {
|
|
|
1897
2263
|
* enter again.
|
|
1898
2264
|
*
|
|
1899
2265
|
* @category models
|
|
1900
|
-
* @since 4.0
|
|
2266
|
+
* @since 0.4.0
|
|
1901
2267
|
*/
|
|
1902
|
-
interface TargetBuilder<States extends StateSchemas, Source extends
|
|
2268
|
+
interface TargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> {
|
|
1903
2269
|
/**
|
|
1904
2270
|
* Moves to another state in the same local group. The value of the state
|
|
1905
2271
|
* containing that group, and values in other active branches, are kept.
|
|
1906
2272
|
*
|
|
1907
|
-
* @since 4.0
|
|
2273
|
+
* @since 0.4.0
|
|
1908
2274
|
*/
|
|
1909
2275
|
readonly local: LocalTargetBuilder<States, Source>;
|
|
1910
2276
|
/**
|
|
@@ -1912,7 +2278,7 @@ export declare namespace Machine {
|
|
|
1912
2278
|
* values change only when their builder methods are explicitly called;
|
|
1913
2279
|
* other active branches are kept.
|
|
1914
2280
|
*
|
|
1915
|
-
* @since 4.0
|
|
2281
|
+
* @since 0.4.0
|
|
1916
2282
|
*/
|
|
1917
2283
|
readonly branch: BranchTargetBuilder<States, Source>;
|
|
1918
2284
|
/**
|
|
@@ -1925,53 +2291,30 @@ export declare namespace Machine {
|
|
|
1925
2291
|
* When it contains parallel states, an active state must be provided for
|
|
1926
2292
|
* every region.
|
|
1927
2293
|
*
|
|
1928
|
-
* @since 4.0
|
|
2294
|
+
* @since 0.4.0
|
|
1929
2295
|
*/
|
|
1930
2296
|
readonly full: FullTargetBuilder<States>;
|
|
1931
2297
|
/** Restores a declared shallow or deep history pseudo-state. */
|
|
1932
2298
|
readonly history: HistoryTargetBuilder<States>;
|
|
1933
2299
|
}
|
|
1934
|
-
/**
|
|
1935
|
-
* Stages an Effect to run after the current machine step is planned.
|
|
1936
|
-
*
|
|
1937
|
-
* The two-argument overload returns `next` after staging the Effect, which is
|
|
1938
|
-
* useful when a handler should stage one action and return a target without
|
|
1939
|
-
* introducing an Effect generator.
|
|
1940
|
-
*
|
|
1941
|
-
* @category models
|
|
1942
|
-
* @since 4.0.0
|
|
1943
|
-
*/
|
|
1944
|
-
interface Action {
|
|
1945
|
-
<E, R>(effect: Effect.Effect<void, E, R>): Effect.Effect<void, never, ActionRequirement<E, R>>;
|
|
1946
|
-
<E, R, Next>(effect: Effect.Effect<void, E, R>, next: Next): Effect.Effect<Next, never, ActionRequirement<E, R>>;
|
|
1947
|
-
}
|
|
1948
|
-
/**
|
|
1949
|
-
* Planning capabilities shared by transition and lifecycle callbacks.
|
|
1950
|
-
*
|
|
1951
|
-
* @category models
|
|
1952
|
-
* @since 4.0.0
|
|
1953
|
-
*/
|
|
1954
|
-
interface PlanningCapabilities<Events, Emits> {
|
|
1955
|
-
readonly raise: (event: Events) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError, Runtime.Requirement<Events, Emits>>;
|
|
1956
|
-
readonly emit: (event: Emits) => Effect.Effect<void, MachineSchemaDecodeError | StoppedError, Runtime.Requirement<Events, Emits>>;
|
|
1957
|
-
}
|
|
1958
2300
|
/**
|
|
1959
2301
|
* Context passed to a state/event handler.
|
|
1960
2302
|
*
|
|
1961
2303
|
* @category models
|
|
1962
|
-
* @since 4.0
|
|
2304
|
+
* @since 0.4.0
|
|
1963
2305
|
*/
|
|
1964
|
-
interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R>
|
|
2306
|
+
interface HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
1965
2307
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1966
2308
|
readonly parent: ParentStateValue<States, StateId>;
|
|
1967
2309
|
readonly parents: ParentStateValues<States, StateId>;
|
|
2310
|
+
/** Complete logical configuration captured at the start of this microstep. */
|
|
2311
|
+
readonly snapshot: Snapshot<States>;
|
|
1968
2312
|
readonly event: EventByTag<Events, EventTag>;
|
|
1969
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
1970
2313
|
/**
|
|
1971
2314
|
* Provides typed builders for choosing the next active state from this
|
|
1972
2315
|
* handler. Each builder documents which existing state values it keeps.
|
|
1973
2316
|
*
|
|
1974
|
-
* @since 4.0
|
|
2317
|
+
* @since 0.4.0
|
|
1975
2318
|
*/
|
|
1976
2319
|
readonly target: TargetBuilder<States, StateId>;
|
|
1977
2320
|
}
|
|
@@ -1979,33 +2322,31 @@ export declare namespace Machine {
|
|
|
1979
2322
|
* Context passed to an entry or exit state handler.
|
|
1980
2323
|
*
|
|
1981
2324
|
* @category models
|
|
1982
|
-
* @since 4.0
|
|
2325
|
+
* @since 0.4.0
|
|
1983
2326
|
*/
|
|
1984
|
-
interface StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>>
|
|
2327
|
+
interface StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
1985
2328
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1986
2329
|
readonly parent: ParentStateValue<States, StateId>;
|
|
1987
2330
|
readonly parents: ParentStateValues<States, StateId>;
|
|
1988
2331
|
readonly event: LifecycleEvent<Events>;
|
|
1989
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
1990
2332
|
}
|
|
1991
2333
|
/**
|
|
1992
2334
|
* Context passed to an invoked child process source.
|
|
1993
2335
|
*
|
|
1994
2336
|
* @category models
|
|
1995
|
-
* @since 4.0
|
|
2337
|
+
* @since 0.4.0
|
|
1996
2338
|
*/
|
|
1997
2339
|
interface InvokeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
1998
2340
|
readonly state: StateByIdentifier<States, StateId>;
|
|
1999
2341
|
readonly parent: ParentStateValue<States, StateId>;
|
|
2000
2342
|
readonly parents: ParentStateValues<States, StateId>;
|
|
2001
2343
|
readonly event: LifecycleEvent<Events>;
|
|
2002
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
2003
2344
|
}
|
|
2004
2345
|
/**
|
|
2005
2346
|
* Context passed to an invoked child process active snapshot mapper.
|
|
2006
2347
|
*
|
|
2007
2348
|
* @category models
|
|
2008
|
-
* @since 4.0
|
|
2349
|
+
* @since 0.4.0
|
|
2009
2350
|
*/
|
|
2010
2351
|
interface InvokeSnapshotContext<State, Error, Output> {
|
|
2011
2352
|
readonly id: string;
|
|
@@ -2017,7 +2358,7 @@ export declare namespace Machine {
|
|
|
2017
2358
|
* Context passed to an invoked machine terminal output mapper.
|
|
2018
2359
|
*
|
|
2019
2360
|
* @category models
|
|
2020
|
-
* @since 4.0
|
|
2361
|
+
* @since 0.4.0
|
|
2021
2362
|
*/
|
|
2022
2363
|
interface InvokeDoneContext<Output> {
|
|
2023
2364
|
readonly id: string;
|
|
@@ -2027,20 +2368,21 @@ export declare namespace Machine {
|
|
|
2027
2368
|
* Context passed to an eventless transition handler.
|
|
2028
2369
|
*
|
|
2029
2370
|
* @category models
|
|
2030
|
-
* @since 4.0
|
|
2371
|
+
* @since 0.4.0
|
|
2031
2372
|
*/
|
|
2032
|
-
interface AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>>
|
|
2373
|
+
interface AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2033
2374
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2034
2375
|
readonly parent: ParentStateValue<States, StateId>;
|
|
2035
2376
|
readonly parents: ParentStateValues<States, StateId>;
|
|
2377
|
+
/** Complete logical configuration captured at the start of this microstep. */
|
|
2378
|
+
readonly snapshot: Snapshot<States>;
|
|
2036
2379
|
readonly event: LifecycleEvent<Events>;
|
|
2037
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
2038
2380
|
/**
|
|
2039
2381
|
* Provides typed builders for choosing the next active state from this
|
|
2040
2382
|
* eventless handler. Each builder documents which existing state values it
|
|
2041
2383
|
* keeps.
|
|
2042
2384
|
*
|
|
2043
|
-
* @since 4.0
|
|
2385
|
+
* @since 0.4.0
|
|
2044
2386
|
*/
|
|
2045
2387
|
readonly target: TargetBuilder<States, StateId>;
|
|
2046
2388
|
}
|
|
@@ -2048,29 +2390,39 @@ export declare namespace Machine {
|
|
|
2048
2390
|
* Context passed to a state completion transition handler.
|
|
2049
2391
|
*
|
|
2050
2392
|
* @category models
|
|
2051
|
-
* @since 4.0
|
|
2393
|
+
* @since 0.4.0
|
|
2052
2394
|
*/
|
|
2053
|
-
interface DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>>
|
|
2395
|
+
interface DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2054
2396
|
readonly state: StateByIdentifier<States, StateId>;
|
|
2055
2397
|
readonly parent: ParentStateValue<States, StateId>;
|
|
2056
2398
|
readonly parents: ParentStateValues<States, StateId>;
|
|
2399
|
+
/** Complete logical configuration captured at the start of this microstep. */
|
|
2400
|
+
readonly snapshot: Snapshot<States>;
|
|
2057
2401
|
readonly event: LifecycleEvent<Events>;
|
|
2058
2402
|
readonly output: CompletionOutputByIdentifier<States, StateId>;
|
|
2059
|
-
readonly runtime: RuntimeEffect<Events, Emits>;
|
|
2060
2403
|
/**
|
|
2061
2404
|
* Provides typed builders for choosing the next active state after this
|
|
2062
2405
|
* state completes. Each builder documents which existing state values it
|
|
2063
2406
|
* keeps.
|
|
2064
2407
|
*
|
|
2065
|
-
* @since 4.0
|
|
2408
|
+
* @since 0.4.0
|
|
2066
2409
|
*/
|
|
2067
2410
|
readonly target: TargetBuilder<States, StateId>;
|
|
2068
2411
|
}
|
|
2412
|
+
/** Context passed to a transient choice resolver. There is no `state` value. */
|
|
2413
|
+
interface ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
|
|
2414
|
+
readonly parent: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
|
|
2415
|
+
readonly parents: {
|
|
2416
|
+
readonly [Parent in Extract<ParentStateIdentifier<ChoiceId>, StateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
2417
|
+
};
|
|
2418
|
+
readonly event: LifecycleEvent<Events>;
|
|
2419
|
+
readonly target: TargetBuilder<States, ChoiceId>;
|
|
2420
|
+
}
|
|
2069
2421
|
/**
|
|
2070
2422
|
* Context passed to a final state output function.
|
|
2071
2423
|
*
|
|
2072
2424
|
* @category models
|
|
2073
|
-
* @since 4.0
|
|
2425
|
+
* @since 0.4.0
|
|
2074
2426
|
*/
|
|
2075
2427
|
interface FinalOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2076
2428
|
readonly state: StateByIdentifier<States, StateId>;
|
|
@@ -2082,7 +2434,7 @@ export declare namespace Machine {
|
|
|
2082
2434
|
* Extracts region outputs for a completed parallel state.
|
|
2083
2435
|
*
|
|
2084
2436
|
* @category utility types
|
|
2085
|
-
* @since 4.0
|
|
2437
|
+
* @since 0.4.0
|
|
2086
2438
|
*/
|
|
2087
2439
|
type ParallelOutputRegions<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends {
|
|
2088
2440
|
readonly type: "parallel";
|
|
@@ -2094,7 +2446,7 @@ export declare namespace Machine {
|
|
|
2094
2446
|
* Context passed to a parallel state output function.
|
|
2095
2447
|
*
|
|
2096
2448
|
* @category models
|
|
2097
|
-
* @since 4.0
|
|
2449
|
+
* @since 0.4.0
|
|
2098
2450
|
*/
|
|
2099
2451
|
interface ParallelOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
2100
2452
|
readonly state: StateByIdentifier<States, StateId>;
|
|
@@ -2107,16 +2459,20 @@ export declare namespace Machine {
|
|
|
2107
2459
|
* Return value accepted from entry and exit state actions.
|
|
2108
2460
|
*
|
|
2109
2461
|
* @category utility types
|
|
2110
|
-
* @since 4.0
|
|
2462
|
+
* @since 0.4.0
|
|
2111
2463
|
*/
|
|
2112
|
-
type StateActionResult<E, R> =
|
|
2464
|
+
type StateActionResult<E, R> = undefined;
|
|
2113
2465
|
/**
|
|
2114
2466
|
* Return value accepted from a machine initial state function.
|
|
2115
2467
|
*
|
|
2116
2468
|
* @category utility types
|
|
2117
|
-
* @since 4.0
|
|
2469
|
+
* @since 0.4.0
|
|
2118
2470
|
*/
|
|
2119
|
-
type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> |
|
|
2471
|
+
type InitialResult<States extends StateSchemas, E, R> = Snapshot<States> | InitialSnapshot<States> | StateConstruction<Snapshot<States> | InitialSnapshot<States>>;
|
|
2472
|
+
/** Initial snapshots may transiently terminate in a declared choice node. */
|
|
2473
|
+
type InitialSnapshot<States extends StateSchemas> = {
|
|
2474
|
+
readonly [StateId in ActiveStateKey<States>]: InitialSnapshotResult<States, StateId, "">;
|
|
2475
|
+
}[ActiveStateKey<States>];
|
|
2120
2476
|
/**
|
|
2121
2477
|
* Return value accepted from transition handlers.
|
|
2122
2478
|
*
|
|
@@ -2127,42 +2483,44 @@ export declare namespace Machine {
|
|
|
2127
2483
|
* accepted at transition boundaries.
|
|
2128
2484
|
*
|
|
2129
2485
|
* @category utility types
|
|
2130
|
-
* @since 4.0
|
|
2486
|
+
* @since 0.4.0
|
|
2131
2487
|
*/
|
|
2132
|
-
type HandlerResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> |
|
|
2488
|
+
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;
|
|
2489
|
+
/** A choice resolver must always select a typed target synchronously. */
|
|
2490
|
+
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>>>;
|
|
2133
2491
|
/**
|
|
2134
2492
|
* Extracts the union of handler return values from a handler map.
|
|
2135
2493
|
*
|
|
2136
2494
|
* @category utility types
|
|
2137
|
-
* @since 4.0
|
|
2495
|
+
* @since 0.4.0
|
|
2138
2496
|
*/
|
|
2139
2497
|
type HandlerEffect<Handlers> = Handlers[keyof Handlers];
|
|
2140
2498
|
/**
|
|
2141
2499
|
* Extracts the error type from a handler return value.
|
|
2142
2500
|
*
|
|
2143
2501
|
* @category utility types
|
|
2144
|
-
* @since 4.0
|
|
2502
|
+
* @since 0.4.0
|
|
2145
2503
|
*/
|
|
2146
2504
|
type HandlerError<Handlers> = Effect.Error<HandlerEffect<Handlers>>;
|
|
2147
2505
|
/**
|
|
2148
2506
|
* Extracts the service requirements from a handler return value.
|
|
2149
2507
|
*
|
|
2150
2508
|
* @category utility types
|
|
2151
|
-
* @since 4.0
|
|
2509
|
+
* @since 0.4.0
|
|
2152
2510
|
*/
|
|
2153
2511
|
type HandlerServices<Handlers> = Effect.Services<HandlerEffect<Handlers>>;
|
|
2154
2512
|
/**
|
|
2155
2513
|
* Extracts the return value from an initial state function.
|
|
2156
2514
|
*
|
|
2157
2515
|
* @category utility types
|
|
2158
|
-
* @since 4.0
|
|
2516
|
+
* @since 0.4.0
|
|
2159
2517
|
*/
|
|
2160
2518
|
type InitialReturn<Initial> = Initial extends (...args: any) => infer Ret ? Ret : never;
|
|
2161
2519
|
/**
|
|
2162
2520
|
* Extracts the return value from an entry or exit action.
|
|
2163
2521
|
*
|
|
2164
2522
|
* @category utility types
|
|
2165
|
-
* @since 4.0
|
|
2523
|
+
* @since 0.4.0
|
|
2166
2524
|
*/
|
|
2167
2525
|
type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
2168
2526
|
/** Extracts the return value from an implicit initial child implementation. */
|
|
@@ -2177,11 +2535,17 @@ export declare namespace Machine {
|
|
|
2177
2535
|
readonly default: (...args: any) => infer Ret;
|
|
2178
2536
|
} ? Ret : never;
|
|
2179
2537
|
}[keyof NonNullable<History>] : never;
|
|
2538
|
+
/** Extracts the return value from a choice resolver. */
|
|
2539
|
+
type ChoiceReturn<Config> = Config extends {
|
|
2540
|
+
readonly choice: {
|
|
2541
|
+
readonly transition: (...args: any) => infer Ret;
|
|
2542
|
+
};
|
|
2543
|
+
} ? Ret : never;
|
|
2180
2544
|
/**
|
|
2181
2545
|
* Extracts the return value from an event transition config.
|
|
2182
2546
|
*
|
|
2183
2547
|
* @category utility types
|
|
2184
|
-
* @since 4.0
|
|
2548
|
+
* @since 0.4.0
|
|
2185
2549
|
*/
|
|
2186
2550
|
type EventTransitionReturn<Transition> = Transition extends (...args: any) => infer Ret ? Ret : Transition extends {
|
|
2187
2551
|
readonly transition: (...args: any) => infer Ret;
|
|
@@ -2190,7 +2554,7 @@ export declare namespace Machine {
|
|
|
2190
2554
|
* Extracts the return value from a state's event handlers.
|
|
2191
2555
|
*
|
|
2192
2556
|
* @category utility types
|
|
2193
|
-
* @since 4.0
|
|
2557
|
+
* @since 0.4.0
|
|
2194
2558
|
*/
|
|
2195
2559
|
type EventHandlerReturn<Config> = Config extends {
|
|
2196
2560
|
readonly on?: infer On;
|
|
@@ -2201,7 +2565,7 @@ export declare namespace Machine {
|
|
|
2201
2565
|
* Extracts the invoke config or configs from a state config.
|
|
2202
2566
|
*
|
|
2203
2567
|
* @category utility types
|
|
2204
|
-
* @since 4.0
|
|
2568
|
+
* @since 0.4.0
|
|
2205
2569
|
*/
|
|
2206
2570
|
type InvokeReturn<Config> = "invoke" extends keyof Config ? Config extends {
|
|
2207
2571
|
readonly invoke?: infer Invoke;
|
|
@@ -2210,7 +2574,7 @@ export declare namespace Machine {
|
|
|
2210
2574
|
* Extracts the child process logic returned by an invoke source.
|
|
2211
2575
|
*
|
|
2212
2576
|
* @category utility types
|
|
2213
|
-
* @since 4.0
|
|
2577
|
+
* @since 0.4.0
|
|
2214
2578
|
*/
|
|
2215
2579
|
type InvokeLogic<Invoke> = Invoke extends {
|
|
2216
2580
|
readonly src: (...args: any) => infer Logic;
|
|
@@ -2219,7 +2583,7 @@ export declare namespace Machine {
|
|
|
2219
2583
|
* Extracts the startup error from an invoke source child process logic.
|
|
2220
2584
|
*
|
|
2221
2585
|
* @category utility types
|
|
2222
|
-
* @since 4.0
|
|
2586
|
+
* @since 0.4.0
|
|
2223
2587
|
*/
|
|
2224
2588
|
type InvokeInitialError<Invoke> = Invoke extends {
|
|
2225
2589
|
readonly [InvokeTypeId]: {
|
|
@@ -2230,7 +2594,7 @@ export declare namespace Machine {
|
|
|
2230
2594
|
* Extracts the runtime error from an invoked child process.
|
|
2231
2595
|
*
|
|
2232
2596
|
* @category utility types
|
|
2233
|
-
* @since 4.0
|
|
2597
|
+
* @since 0.4.0
|
|
2234
2598
|
*/
|
|
2235
2599
|
type InvokeRuntimeError<Invoke> = Invoke extends {
|
|
2236
2600
|
readonly [InvokeTypeId]: {
|
|
@@ -2241,7 +2605,7 @@ export declare namespace Machine {
|
|
|
2241
2605
|
* Extracts the output from an invoked child process.
|
|
2242
2606
|
*
|
|
2243
2607
|
* @category utility types
|
|
2244
|
-
* @since 4.0
|
|
2608
|
+
* @since 0.4.0
|
|
2245
2609
|
*/
|
|
2246
2610
|
type InvokeOutput<Invoke> = Invoke extends {
|
|
2247
2611
|
readonly [InvokeTypeId]: {
|
|
@@ -2252,7 +2616,7 @@ export declare namespace Machine {
|
|
|
2252
2616
|
* Extracts the service requirements from an invoke source child process logic.
|
|
2253
2617
|
*
|
|
2254
2618
|
* @category utility types
|
|
2255
|
-
* @since 4.0
|
|
2619
|
+
* @since 0.4.0
|
|
2256
2620
|
*/
|
|
2257
2621
|
type InvokeServices<Invoke> = Invoke extends {
|
|
2258
2622
|
readonly [InvokeTypeId]: {
|
|
@@ -2263,7 +2627,7 @@ export declare namespace Machine {
|
|
|
2263
2627
|
* Extracts events emitted directly by an invoked child.
|
|
2264
2628
|
*
|
|
2265
2629
|
* @category utility types
|
|
2266
|
-
* @since 4.0
|
|
2630
|
+
* @since 0.4.0
|
|
2267
2631
|
*/
|
|
2268
2632
|
type InvokeEmits<Invoke> = Invoke extends {
|
|
2269
2633
|
readonly [InvokeTypeId]: {
|
|
@@ -2274,7 +2638,7 @@ export declare namespace Machine {
|
|
|
2274
2638
|
* Extracts events returned by an invoked child snapshot mapper.
|
|
2275
2639
|
*
|
|
2276
2640
|
* @category utility types
|
|
2277
|
-
* @since 4.0
|
|
2641
|
+
* @since 0.4.0
|
|
2278
2642
|
*/
|
|
2279
2643
|
type InvokeSnapshotEvent<Invoke> = Invoke extends {
|
|
2280
2644
|
readonly [InvokeTypeId]: {
|
|
@@ -2285,39 +2649,39 @@ export declare namespace Machine {
|
|
|
2285
2649
|
* Extracts the parent transition error contribution from invoked children.
|
|
2286
2650
|
*
|
|
2287
2651
|
* @category utility types
|
|
2288
|
-
* @since 4.0
|
|
2652
|
+
* @since 0.4.0
|
|
2289
2653
|
*/
|
|
2290
2654
|
type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : ChildAlreadyExistsError | InvokeInitialError<InvokeReturn<Config>> | InvokeRuntimeError<InvokeReturn<Config>>;
|
|
2291
2655
|
/**
|
|
2292
2656
|
* Extracts the parent service requirement contribution from invoked children.
|
|
2293
2657
|
*
|
|
2294
2658
|
* @category utility types
|
|
2295
|
-
* @since 4.0
|
|
2659
|
+
* @since 0.4.0
|
|
2296
2660
|
*/
|
|
2297
2661
|
type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntimeRequirement | InvokeServices<InvokeReturn<Config>>;
|
|
2298
2662
|
/**
|
|
2299
2663
|
* Extracts the return value from an eventless transition.
|
|
2300
2664
|
*
|
|
2301
2665
|
* @category utility types
|
|
2302
|
-
* @since 4.0
|
|
2666
|
+
* @since 0.4.0
|
|
2303
2667
|
*/
|
|
2304
2668
|
type AlwaysReturn<Config> = Config extends {
|
|
2305
2669
|
readonly always?: infer Always;
|
|
2306
|
-
} ? NonNullable<Always
|
|
2670
|
+
} ? EventTransitionReturn<NonNullable<Always>> : never;
|
|
2307
2671
|
/**
|
|
2308
2672
|
* Extracts the return value from a state completion transition.
|
|
2309
2673
|
*
|
|
2310
2674
|
* @category utility types
|
|
2311
|
-
* @since 4.0
|
|
2675
|
+
* @since 0.4.0
|
|
2312
2676
|
*/
|
|
2313
2677
|
type DoneReturn<Config> = Config extends {
|
|
2314
2678
|
readonly onDone?: infer OnDone;
|
|
2315
|
-
} ? NonNullable<OnDone
|
|
2679
|
+
} ? EventTransitionReturn<NonNullable<OnDone>> : never;
|
|
2316
2680
|
/**
|
|
2317
2681
|
* Extracts the return value from a final state output function.
|
|
2318
2682
|
*
|
|
2319
2683
|
* @category utility types
|
|
2320
|
-
* @since 4.0
|
|
2684
|
+
* @since 0.4.0
|
|
2321
2685
|
*/
|
|
2322
2686
|
type FinalOutputReturn<Config> = Config extends {
|
|
2323
2687
|
readonly output?: infer Output;
|
|
@@ -2326,14 +2690,14 @@ export declare namespace Machine {
|
|
|
2326
2690
|
* Extracts all service requirements contributed by a state handler config.
|
|
2327
2691
|
*
|
|
2328
2692
|
* @category utility types
|
|
2329
|
-
* @since 4.0
|
|
2693
|
+
* @since 0.4.0
|
|
2330
2694
|
*/
|
|
2331
|
-
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>> | InvokeRequirements<Config>;
|
|
2695
|
+
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>;
|
|
2332
2696
|
/**
|
|
2333
2697
|
* Configuration for invoking a child process while a state is active.
|
|
2334
2698
|
*
|
|
2335
2699
|
* @category models
|
|
2336
|
-
* @since 4.0
|
|
2700
|
+
* @since 0.4.0
|
|
2337
2701
|
*/
|
|
2338
2702
|
interface InvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Event, ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError, ChildEmits = never, DeliveredOutput = ChildOutput> {
|
|
2339
2703
|
readonly [InvokeTypeId]: {
|
|
@@ -2344,6 +2708,8 @@ export declare namespace Machine {
|
|
|
2344
2708
|
readonly requirements: Types.Covariant<ChildRequirements>;
|
|
2345
2709
|
readonly initialError: Types.Covariant<ChildInitialError>;
|
|
2346
2710
|
};
|
|
2711
|
+
/** @internal Serializable descriptor metadata used by inspection. */
|
|
2712
|
+
readonly [Activities.ActivityMetadataTypeId]?: Activities.StaticActivityMetadata;
|
|
2347
2713
|
readonly id: string;
|
|
2348
2714
|
/**
|
|
2349
2715
|
* Optional parent-local address for sending events to this invocation.
|
|
@@ -2381,7 +2747,7 @@ export declare namespace Machine {
|
|
|
2381
2747
|
* event before constructing one or more invoke configurations.
|
|
2382
2748
|
*
|
|
2383
2749
|
* @category models
|
|
2384
|
-
* @since 4.0
|
|
2750
|
+
* @since 0.4.0
|
|
2385
2751
|
*/
|
|
2386
2752
|
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>);
|
|
2387
2753
|
type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
@@ -2400,18 +2766,32 @@ export declare namespace Machine {
|
|
|
2400
2766
|
* Configuration accepted for a non-final state.
|
|
2401
2767
|
*
|
|
2402
2768
|
* @category models
|
|
2403
|
-
* @since 4.0
|
|
2769
|
+
* @since 0.4.0
|
|
2404
2770
|
*/
|
|
2405
2771
|
type ActiveStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = {
|
|
2406
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId
|
|
2407
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId
|
|
2772
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2773
|
+
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2408
2774
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
|
|
2409
|
-
readonly always?: (context: AlwaysContext<States, Events, Emits, StateId
|
|
2410
|
-
|
|
2775
|
+
readonly always?: ((context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2776
|
+
/** Statically declared upper bound of possible target paths. */
|
|
2777
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2778
|
+
readonly transition: (context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2779
|
+
};
|
|
2780
|
+
readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>) | {
|
|
2781
|
+
/** Statically declared upper bound of possible target paths. */
|
|
2782
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2783
|
+
readonly transition: (context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2784
|
+
};
|
|
2411
2785
|
readonly on?: {
|
|
2412
|
-
readonly [EventTag in TagOf<Events[number]>]?: ((context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R
|
|
2786
|
+
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>) | {
|
|
2413
2787
|
readonly reenter?: boolean;
|
|
2414
|
-
|
|
2788
|
+
/**
|
|
2789
|
+
* Upper bound of state or history paths this handler may target.
|
|
2790
|
+
* Returning `void` is always permitted. Declaring a parent state also
|
|
2791
|
+
* permits concrete descendant targets below it.
|
|
2792
|
+
*/
|
|
2793
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
2794
|
+
readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, any, any>;
|
|
2415
2795
|
};
|
|
2416
2796
|
};
|
|
2417
2797
|
readonly initial?: StateInitialHandler<States, Events, Emits, StateId>;
|
|
@@ -2429,30 +2809,51 @@ export declare namespace Machine {
|
|
|
2429
2809
|
/** Context passed to an implicit child-state initializer. */
|
|
2430
2810
|
type StateInitialContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = StateActionContext<States, Events, Emits, StateId>;
|
|
2431
2811
|
/** Initial child value implementation for a compound or parallel state. */
|
|
2432
|
-
type StateInitialHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = (context: StateInitialContext<States, Events, Emits, StateId
|
|
2812
|
+
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>;
|
|
2433
2813
|
/** Context used only when a history node has no previously captured record. */
|
|
2434
|
-
interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>>
|
|
2814
|
+
interface HistoryDefaultContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
2435
2815
|
readonly event: LifecycleEvent<Events>;
|
|
2436
|
-
readonly
|
|
2437
|
-
readonly target: FullTargetBuilder<States>;
|
|
2816
|
+
readonly target: HistoryDefaultTargetBuilder<States, ParentId>;
|
|
2438
2817
|
readonly parent: ParentId;
|
|
2439
2818
|
}
|
|
2440
|
-
/**
|
|
2441
|
-
|
|
2819
|
+
/**
|
|
2820
|
+
* Typed fallback evaluated when a history node has no record yet.
|
|
2821
|
+
*
|
|
2822
|
+
* The fallback constructs a complete root configuration containing the
|
|
2823
|
+
* history owner. This makes the default independent of the transition source
|
|
2824
|
+
* and provides every inactive ancestor and required parallel region.
|
|
2825
|
+
*/
|
|
2826
|
+
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>>;
|
|
2442
2827
|
/** Default implementations keyed by direct history child. */
|
|
2443
2828
|
type HistoryDefaultConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>, Children extends StateSchemas> = {
|
|
2444
2829
|
readonly [Key in HistoryStateKey<Children>]?: {
|
|
2445
2830
|
readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>;
|
|
2446
2831
|
};
|
|
2447
2832
|
};
|
|
2833
|
+
/** Required implementation for a choice pseudo-state. */
|
|
2834
|
+
interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>> {
|
|
2835
|
+
readonly choice: {
|
|
2836
|
+
/** Statically inspectable upper bound of every possible target. */
|
|
2837
|
+
readonly targets: readonly [StateNodeIdentifier<States>, ...ReadonlyArray<StateNodeIdentifier<States>>];
|
|
2838
|
+
readonly transition: (context: ChoiceContext<States, Events, Emits, ChoiceId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => ChoiceResult<States, any, any>;
|
|
2839
|
+
};
|
|
2840
|
+
readonly entry?: never;
|
|
2841
|
+
readonly exit?: never;
|
|
2842
|
+
readonly invoke?: never;
|
|
2843
|
+
readonly always?: never;
|
|
2844
|
+
readonly on?: never;
|
|
2845
|
+
readonly onDone?: never;
|
|
2846
|
+
readonly output?: never;
|
|
2847
|
+
readonly initial?: never;
|
|
2848
|
+
}
|
|
2448
2849
|
/**
|
|
2449
2850
|
* Configuration accepted for a final state.
|
|
2450
2851
|
*
|
|
2451
2852
|
* @category models
|
|
2452
|
-
* @since 4.0
|
|
2853
|
+
* @since 0.4.0
|
|
2453
2854
|
*/
|
|
2454
2855
|
type FinalStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> = {
|
|
2455
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId
|
|
2856
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<any, any>;
|
|
2456
2857
|
readonly exit?: never;
|
|
2457
2858
|
readonly always?: never;
|
|
2458
2859
|
readonly onDone?: never;
|
|
@@ -2462,32 +2863,50 @@ export declare namespace Machine {
|
|
|
2462
2863
|
* Configuration accepted by `handle` for a state tag.
|
|
2463
2864
|
*
|
|
2464
2865
|
* @category models
|
|
2465
|
-
* @since 4.0
|
|
2866
|
+
* @since 0.4.0
|
|
2466
2867
|
*/
|
|
2467
2868
|
type HandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, E, R> = NodeByIdentifier<States, StateId> extends {
|
|
2468
2869
|
readonly type: "final";
|
|
2469
2870
|
} ? FinalStateConfig<States, Events, Emits, StateId> : ActiveStateConfig<States, Events, Emits, StateId, E, R>;
|
|
2871
|
+
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;
|
|
2470
2872
|
type HandlerChildren<Node> = Node extends {
|
|
2471
2873
|
readonly states: infer Children extends StateSchemas;
|
|
2472
2874
|
} ? Children : never;
|
|
2473
|
-
type
|
|
2875
|
+
type HandlerNodeId<States extends StateSchemas, Path extends string> = Extract<Path, StateNodeIdentifier<States>>;
|
|
2474
2876
|
type HandlerConfigPart<Config> = {
|
|
2475
2877
|
readonly [Key in keyof Config as Key extends "states" ? never : Key]: Config[Key];
|
|
2476
2878
|
};
|
|
2477
|
-
type
|
|
2879
|
+
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
|
|
2880
|
+
readonly states?: infer Children;
|
|
2881
|
+
} ? NonNullable<Children> : never : never;
|
|
2882
|
+
type HandlerNodeByPath<States extends StateSchemas, Path extends string> = Path extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
2883
|
+
readonly states: infer Children extends StateSchemas;
|
|
2884
|
+
} ? HandlerNodeByPath<Children, Rest> : never : never : Path extends keyof States ? States[Path] : never;
|
|
2885
|
+
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;
|
|
2886
|
+
type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
2887
|
+
readonly [Key in Head]?: {
|
|
2888
|
+
readonly states: HandlerValidationAtPath<Rest, Validation>;
|
|
2889
|
+
};
|
|
2890
|
+
} : {
|
|
2891
|
+
readonly [Key in Path]?: Validation;
|
|
2892
|
+
};
|
|
2893
|
+
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> ? {
|
|
2894
|
+
readonly states?: never;
|
|
2895
|
+
readonly history?: never;
|
|
2896
|
+
} : HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
2478
2897
|
readonly states?: never;
|
|
2479
2898
|
readonly history?: never;
|
|
2480
2899
|
} : {
|
|
2481
|
-
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, StateId
|
|
2482
|
-
readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, StateId, Children>;
|
|
2900
|
+
readonly states?: HandlerTree<AllStates, Children, Events, Emits, E, R, Extract<StateId, StateIdentifier<AllStates>>>;
|
|
2901
|
+
readonly history?: HistoryDefaultConfig<AllStates, Events, Emits, Extract<StateId, StateIdentifier<AllStates>>, Children>;
|
|
2483
2902
|
} : {
|
|
2484
2903
|
readonly states?: never;
|
|
2485
2904
|
readonly history?: never;
|
|
2486
2905
|
});
|
|
2487
2906
|
type HandlerTree<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, E, R, Prefix extends string> = {
|
|
2488
|
-
readonly [Key in ActiveStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R,
|
|
2907
|
+
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]?: HandlerNode<AllStates, States[Key], Events, Emits, E, R, HandlerNodeId<AllStates, JoinPath<Prefix, Key>>>;
|
|
2489
2908
|
};
|
|
2490
|
-
type HandlerNodeConfigKey = "always" | "entry" | "exit" | "history" | "initial" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
2909
|
+
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initial" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
2491
2910
|
type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
|
|
2492
2911
|
readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
|
|
2493
2912
|
};
|
|
@@ -2525,19 +2944,36 @@ export declare namespace Machine {
|
|
|
2525
2944
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Handler config contains an event key that does not exist", StateId, Key>;
|
|
2526
2945
|
};
|
|
2527
2946
|
} : unknown;
|
|
2528
|
-
type
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2947
|
+
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 {
|
|
2948
|
+
readonly path: infer Path extends string;
|
|
2949
|
+
} ? Path : never;
|
|
2950
|
+
type DeclaredTransitionTarget<Transition> = Transition extends {
|
|
2951
|
+
readonly targets: infer Targets extends ReadonlyArray<string>;
|
|
2952
|
+
} ? Targets[number] : never;
|
|
2953
|
+
type ExcludeDeclaredTransitionTarget<Returned, Declared extends string> = Returned extends string ? Returned extends Declared | `${Declared}.${string}` ? never : Returned : never;
|
|
2954
|
+
type UndeclaredTransitionTarget<Transition> = "targets" extends keyof Transition ? ExcludeDeclaredTransitionTarget<TransitionResultTargetPath<EventTransitionReturn<Transition>>, DeclaredTransitionTarget<Transition>> : never;
|
|
2955
|
+
type HandlerOnTargetValidationErrors<StateId extends string, On> = {
|
|
2956
|
+
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]>]>;
|
|
2957
|
+
};
|
|
2958
|
+
type HandlerOnTargetValidation<StateId extends string, Config> = "on" extends keyof Config ? Config extends {
|
|
2959
|
+
readonly on?: infer On;
|
|
2960
|
+
} ? HandlerOnTargetValidationErrors<StateId, NonNullable<On>> extends infer Errors ? keyof Errors extends never ? unknown : {
|
|
2961
|
+
readonly on: Errors;
|
|
2962
|
+
} : never : unknown : unknown;
|
|
2963
|
+
type HandlerDirectTargetValidation<StateId extends string, Config, Trigger extends "always" | "onDone", Transition = Config extends {
|
|
2964
|
+
readonly [Key in Trigger]?: infer Value;
|
|
2965
|
+
} ? NonNullable<Value> : never, Undeclared extends string = UndeclaredTransitionTarget<Transition>> = Trigger extends keyof Config ? [Undeclared] extends [never] ? unknown : {
|
|
2966
|
+
readonly [Key in Trigger]: HandlerValidationError<"Transition returns a target not listed in targets", StateId, readonly [trigger: Trigger, target: Undeclared]>;
|
|
2967
|
+
} : unknown;
|
|
2968
|
+
type HandlerChildrenValidation<Node, Prefix extends string, Config> = "states" extends keyof Config ? Config extends {
|
|
2533
2969
|
readonly states?: infer ChildrenConfig;
|
|
2534
2970
|
} ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
2535
2971
|
readonly states: HandlerValidationError<"Handler config contains child states for a state that has no children", Prefix>;
|
|
2536
|
-
} :
|
|
2972
|
+
} : HandlerUnknownStateKeyValidation<Children, Prefix, NonNullable<ChildrenConfig>> extends infer Validation ? unknown extends Validation ? unknown : {
|
|
2537
2973
|
readonly states: Validation;
|
|
2538
|
-
} : never : {
|
|
2974
|
+
} : never : never : {
|
|
2539
2975
|
readonly states: HandlerValidationError<"Handler config contains child states for a state that has no children", Prefix>;
|
|
2540
|
-
} : unknown
|
|
2976
|
+
} : unknown;
|
|
2541
2977
|
type HandlerOutputRequirementValidation<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, AvailableOutputStates extends StateIdentifier<AllStates>, Config> = ("onDone" extends keyof Config ? [
|
|
2542
2978
|
Exclude<RequiredCompletionOutputStates<AllStates, StateId>, AvailableOutputStates>
|
|
2543
2979
|
] extends [never] ? unknown : {
|
|
@@ -2549,7 +2985,15 @@ export declare namespace Machine {
|
|
|
2549
2985
|
] extends [never] ? unknown : {
|
|
2550
2986
|
readonly output: HandlerValidationError<"Handler config is missing a region output implementation required by parallel output", StateId, Exclude<RequiredParallelOutputStates<AllStates, StateId>, AvailableOutputStates>>;
|
|
2551
2987
|
} : unknown : unknown);
|
|
2552
|
-
type HandlerNodeValidation<AllStates extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends
|
|
2988
|
+
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;
|
|
2989
|
+
type HandlerChoiceUnknownConfigKeyValidation<StateId extends string, Config, UnknownKeys extends string = Exclude<Extract<keyof Config, string>, "choice">> = [UnknownKeys] extends [never] ? unknown : {
|
|
2990
|
+
readonly [Key in UnknownKeys]: HandlerValidationError<"Choice handler config contains an invalid key", StateId, Key>;
|
|
2991
|
+
};
|
|
2992
|
+
type HandlerChoiceTargetValidation<StateId extends string, Config> = Config extends {
|
|
2993
|
+
readonly choice: infer Choice;
|
|
2994
|
+
} ? [UndeclaredTransitionTarget<Choice>] extends [never] ? unknown : {
|
|
2995
|
+
readonly choice: HandlerValidationError<"Choice resolver returns a target not listed in targets", StateId, UndeclaredTransitionTarget<Choice>>;
|
|
2996
|
+
} : unknown;
|
|
2553
2997
|
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 : {
|
|
2554
2998
|
readonly invoke: HandlerValidationError<"Invoked child output must be a machine event or void", StateId, Exclude<InvokeOutput<InvokeReturn<Config>>, EventOf<Events> | void>>;
|
|
2555
2999
|
};
|
|
@@ -2560,20 +3004,9 @@ export declare namespace Machine {
|
|
|
2560
3004
|
readonly invoke: HandlerValidationError<"Invoked child snapshot mapper must return a machine event or undefined", StateId, Exclude<InvokeSnapshotEvent<InvokeReturn<Config>>, EventOf<Events> | undefined>>;
|
|
2561
3005
|
};
|
|
2562
3006
|
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>;
|
|
2563
|
-
type
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
type HandlerTreeNodeValidationErrors<Validations> = {
|
|
2567
|
-
readonly [Key in keyof Validations as unknown extends Validations[Key] ? never : Key]?: Validations[Key];
|
|
2568
|
-
};
|
|
2569
|
-
type HandlerTreeNodeValidations<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Prefix extends string, Config, AvailableOutputStates extends StateIdentifier<AllStates>, Depth extends ReadonlyArray<unknown>> = HandlerTreeNodeValidationMap<AllStates, States, Events, Emits, Prefix, Config, AvailableOutputStates, Depth> extends infer Validations ? HandlerTreeNodeValidationErrors<Validations> extends infer Errors ? keyof Errors extends never ? unknown : Errors : never : never;
|
|
2570
|
-
type HandlerTreeValidation<AllStates extends StateSchemas, States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Prefix extends string, Config, AvailableOutputStates extends StateIdentifier<AllStates>, Depth extends ReadonlyArray<unknown> = HandlerDepth> = HandlerUnknownStateKeyValidation<States, Prefix, Config> & HandlerTreeNodeValidations<AllStates, States, Events, Emits, Prefix, Config, AvailableOutputStates, Depth>;
|
|
2571
|
-
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
|
|
2572
|
-
readonly states?: infer Children;
|
|
2573
|
-
} ? NonNullable<Children> : never : never;
|
|
2574
|
-
type HandlerTreeStateIds<AllStates extends StateSchemas, States extends StateSchemas, Prefix extends string, Config, Depth extends ReadonlyArray<unknown> = HandlerDepth> = {
|
|
2575
|
-
readonly [Key in Extract<Extract<keyof Config, string>, Extract<keyof States, string>>]: HandlerImplementedStateId<AllStates, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key]> | HandlerNodeChildStateIds<AllStates, States[Key], HandlerStateId<AllStates, JoinPath<Prefix, Key>>, Config[Key], Depth>;
|
|
2576
|
-
}[Extract<Extract<keyof Config, string>, Extract<keyof States, string>>];
|
|
3007
|
+
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;
|
|
3008
|
+
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>;
|
|
3009
|
+
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>;
|
|
2577
3010
|
type HandlerHasRequiredInitial<AllStates extends StateSchemas, StateId extends StateIdentifier<AllStates>, Config> = StateId extends RequiredHistoryInitializers<AllStates> ? "initial" extends keyof Config ? true : false : true;
|
|
2578
3011
|
type HandlerHasRequiredHistoryDefaults<Node, Config> = Node extends {
|
|
2579
3012
|
readonly states: infer Children extends StateSchemas;
|
|
@@ -2582,66 +3015,69 @@ export declare namespace Machine {
|
|
|
2582
3015
|
} ? [
|
|
2583
3016
|
Exclude<HistoryStateKey<Children>, Extract<keyof NonNullable<HistoryConfig>, string>>
|
|
2584
3017
|
] extends [never] ? true : false : false : true;
|
|
2585
|
-
type
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
type
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
readonly
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
type
|
|
3018
|
+
type HandlerHasRequiredChoices<Node, Config> = Node extends {
|
|
3019
|
+
readonly states: infer Children extends StateSchemas;
|
|
3020
|
+
} ? [ChoiceStateKey<Children>] extends [never] ? true : Config extends {
|
|
3021
|
+
readonly states?: infer ChildrenConfig;
|
|
3022
|
+
} ? [
|
|
3023
|
+
Exclude<ChoiceStateKey<Children>, Extract<keyof NonNullable<ChildrenConfig>, string>>
|
|
3024
|
+
] extends [never] ? true : false : false : true;
|
|
3025
|
+
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;
|
|
3026
|
+
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>;
|
|
3027
|
+
type HandlerNodeEvidence<AllStates extends StateSchemas, Config, StateId extends StateNodeIdentifier<AllStates>, NodeConfig = HandlerConfigAtPath<Config, StateId>> = [NodeConfig] extends [never] ? never : {
|
|
3028
|
+
readonly stateId: StateId extends StateIdentifier<AllStates> ? HandlerImplementedStateId<AllStates, HandlerNodeByPath<AllStates, StateId>, StateId, NodeConfig> : never;
|
|
3029
|
+
readonly error: HandlerConfigError<HandlerConfigPart<NodeConfig>>;
|
|
3030
|
+
readonly services: ConfigServices<HandlerConfigPart<NodeConfig>>;
|
|
3031
|
+
readonly outputState: StateId extends StateIdentifier<AllStates> ? HandlerOutputStates<AllStates, StateId, HandlerConfigPart<NodeConfig>> : never;
|
|
3032
|
+
};
|
|
3033
|
+
type HandlerTreeEvidence<AllStates extends StateSchemas, Config> = StateNodeIdentifier<AllStates> extends infer StateId extends StateNodeIdentifier<AllStates> ? StateId extends StateNodeIdentifier<AllStates> ? HandlerNodeEvidence<AllStates, Config, StateId> : never : never;
|
|
3034
|
+
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>;
|
|
2601
3035
|
/**
|
|
2602
3036
|
* Adds state handlers from a root state object.
|
|
2603
3037
|
*
|
|
2604
|
-
* **Gotchas**
|
|
2605
|
-
*
|
|
2606
|
-
* Type inference traverses up to eight nested child-state objects. Deeper
|
|
2607
|
-
* handler trees are rejected explicitly instead of silently dropping their
|
|
2608
|
-
* error, service, final-state, or output channels.
|
|
2609
|
-
*
|
|
2610
3038
|
* @category combinators
|
|
2611
|
-
* @since 4.0
|
|
3039
|
+
* @since 0.4.0
|
|
2612
3040
|
*/
|
|
2613
3041
|
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>> {
|
|
2614
|
-
<const Config extends HandlerTree<States, States, Events, Emits, E, R, "">>(config: Config & HandlerTreeValidation<States,
|
|
3042
|
+
<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>;
|
|
2615
3043
|
}
|
|
2616
3044
|
/**
|
|
2617
3045
|
* Any state config.
|
|
2618
3046
|
*
|
|
2619
3047
|
* @category utility types
|
|
2620
|
-
* @since 4.0
|
|
3048
|
+
* @since 0.4.0
|
|
2621
3049
|
*/
|
|
2622
|
-
type AnyStateConfig = StateConfig<any, any, any, any, any, any, any>;
|
|
3050
|
+
type AnyStateConfig = StateConfig<any, any, any, any, any, any, any> | ChoiceStateConfig<any, any, any, any>;
|
|
2623
3051
|
/**
|
|
2624
3052
|
* Runtime event-handler map stored for a single state tag.
|
|
2625
3053
|
*
|
|
2626
3054
|
* @category models
|
|
2627
|
-
* @since 4.0
|
|
3055
|
+
* @since 0.4.0
|
|
2628
3056
|
*/
|
|
2629
|
-
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
|
|
3057
|
+
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>) | {
|
|
2630
3058
|
readonly reenter?: boolean;
|
|
2631
|
-
|
|
3059
|
+
/** Statically declared upper bound of possible target paths. */
|
|
3060
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3061
|
+
readonly transition: (context: HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
2632
3062
|
}>>;
|
|
2633
3063
|
/**
|
|
2634
3064
|
* Runtime state config stored for a single state tag.
|
|
2635
3065
|
*
|
|
2636
3066
|
* @category models
|
|
2637
|
-
* @since 4.0
|
|
3067
|
+
* @since 0.4.0
|
|
2638
3068
|
*/
|
|
2639
3069
|
interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
2640
|
-
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId
|
|
2641
|
-
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId
|
|
3070
|
+
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
|
|
3071
|
+
readonly exit?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => StateActionResult<E, R>;
|
|
2642
3072
|
readonly invoke?: InvokeDefinition<States, Events, Emits, StateId>;
|
|
2643
|
-
readonly always?: (context: AlwaysContext<States, Events, Emits, StateId
|
|
2644
|
-
|
|
3073
|
+
readonly always?: ((context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
|
|
3074
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3075
|
+
readonly transition: (context: AlwaysContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
3076
|
+
};
|
|
3077
|
+
readonly onDone?: ((context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>) | {
|
|
3078
|
+
readonly targets?: ReadonlyArray<StateNodeIdentifier<States>>;
|
|
3079
|
+
readonly transition: (context: DoneContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmitOf<Emits>>) => HandlerResult<States, E, R>;
|
|
3080
|
+
};
|
|
2645
3081
|
readonly output?: ((context: FinalOutputContext<States, Events, StateId>) => unknown) | ((context: ParallelOutputContext<States, Events, StateId>) => unknown);
|
|
2646
3082
|
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
|
|
2647
3083
|
}
|
|
@@ -2649,22 +3085,22 @@ export declare namespace Machine {
|
|
|
2649
3085
|
* Runtime handler table stored on a machine.
|
|
2650
3086
|
*
|
|
2651
3087
|
* @category models
|
|
2652
|
-
* @since 4.0
|
|
3088
|
+
* @since 0.4.0
|
|
2653
3089
|
*/
|
|
2654
|
-
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
|
|
3090
|
+
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>>>>;
|
|
2655
3091
|
}
|
|
2656
3092
|
/**
|
|
2657
3093
|
* Returns `true` if a value is a `Machine`.
|
|
2658
3094
|
*
|
|
2659
3095
|
* @category guards
|
|
2660
|
-
* @since 4.0
|
|
3096
|
+
* @since 0.4.0
|
|
2661
3097
|
*/
|
|
2662
3098
|
export declare const isMachine: (u: unknown) => u is Machine.Any;
|
|
2663
3099
|
/**
|
|
2664
3100
|
* Returns `true` if a state snapshot is final for a machine.
|
|
2665
3101
|
*
|
|
2666
3102
|
* @category guards
|
|
2667
|
-
* @since 4.0
|
|
3103
|
+
* @since 0.4.0
|
|
2668
3104
|
*/
|
|
2669
3105
|
export declare const isFinal: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema>, const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, state: Machine.Snapshot<States>) => state is Machine.SnapshotContainingFinal<States, FinalStates>;
|
|
2670
3106
|
/**
|
|
@@ -2699,7 +3135,7 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
2699
3135
|
* ```
|
|
2700
3136
|
*
|
|
2701
3137
|
* @category constructors
|
|
2702
|
-
* @since 4.0
|
|
3138
|
+
* @since 0.4.0
|
|
2703
3139
|
*/
|
|
2704
3140
|
export declare const defineStates: DefineStates;
|
|
2705
3141
|
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>> = {
|
|
@@ -2766,9 +3202,52 @@ interface Make {
|
|
|
2766
3202
|
*
|
|
2767
3203
|
* @see {@link defineStates} for typed initial snapshot builders.
|
|
2768
3204
|
* @category constructors
|
|
2769
|
-
* @since 4.0
|
|
3205
|
+
* @since 0.4.0
|
|
2770
3206
|
*/
|
|
2771
3207
|
export declare const make: Make;
|
|
3208
|
+
type EventConstructorArgs<EventSchema extends Machine.TaggedSchema> = {} extends EventSchema["~type.make.in"] ? [
|
|
3209
|
+
input?: EventSchema["~type.make.in"]
|
|
3210
|
+
] : [input: EventSchema["~type.make.in"]];
|
|
3211
|
+
/**
|
|
3212
|
+
* Constructs an event from a schema owned by a machine's protocol.
|
|
3213
|
+
*
|
|
3214
|
+
* **Details**
|
|
3215
|
+
*
|
|
3216
|
+
* The schema constructor runs exactly once. The resulting decoded event is
|
|
3217
|
+
* trusted by this machine and definitions derived from it with `handle`, so
|
|
3218
|
+
* repeated delivery does not decode the same already-constructed value again.
|
|
3219
|
+
* Events supplied through ordinary `send` and `plan` calls remain untrusted
|
|
3220
|
+
* and continue through full runtime schema validation.
|
|
3221
|
+
* Treat the returned event as immutable after construction.
|
|
3222
|
+
*
|
|
3223
|
+
* The schema must be one of the machine's configured public or internal event
|
|
3224
|
+
* schemas, or a case schema belonging to a configured `Schema.TaggedUnion`.
|
|
3225
|
+
*
|
|
3226
|
+
* **Example**
|
|
3227
|
+
*
|
|
3228
|
+
* ```ts
|
|
3229
|
+
* import { Schema } from "effect"
|
|
3230
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3231
|
+
*
|
|
3232
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
3233
|
+
* class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", {
|
|
3234
|
+
* by: Schema.Number
|
|
3235
|
+
* }) {}
|
|
3236
|
+
*
|
|
3237
|
+
* const States = Machine.defineStates({ Idle })
|
|
3238
|
+
* const counter = Machine.make({
|
|
3239
|
+
* states: States.states,
|
|
3240
|
+
* events: [Increment],
|
|
3241
|
+
* initial: () => States.initial.Idle.from()
|
|
3242
|
+
* }).handle({ Idle: { on: { Increment: () => States.initial.Idle.from() } } })
|
|
3243
|
+
*
|
|
3244
|
+
* const increment = Machine.event(counter, Increment, { by: 1 })
|
|
3245
|
+
* ```
|
|
3246
|
+
*
|
|
3247
|
+
* @category constructors
|
|
3248
|
+
* @since 0.4.0
|
|
3249
|
+
*/
|
|
3250
|
+
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"];
|
|
2772
3251
|
/**
|
|
2773
3252
|
* Encodes a decoded machine snapshot into a normalized data representation.
|
|
2774
3253
|
*
|
|
@@ -2792,9 +3271,29 @@ export declare const make: Make;
|
|
|
2792
3271
|
* guarantee JSON-compatible values; schemas used with JSON-backed storage must
|
|
2793
3272
|
* have JSON-compatible encoded representations.
|
|
2794
3273
|
*
|
|
3274
|
+
* **Example**
|
|
3275
|
+
*
|
|
3276
|
+
* ```ts
|
|
3277
|
+
* import { Effect, Schema } from "effect"
|
|
3278
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3279
|
+
*
|
|
3280
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
3281
|
+
* const States = Machine.defineStates({ Idle })
|
|
3282
|
+
* const machine = Machine.make({
|
|
3283
|
+
* states: States.states,
|
|
3284
|
+
* events: [],
|
|
3285
|
+
* initial: () => States.initial.Idle.from()
|
|
3286
|
+
* }).handle({ Idle: {} })
|
|
3287
|
+
*
|
|
3288
|
+
* const encoded = Effect.gen(function*() {
|
|
3289
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
3290
|
+
* return yield* Machine.encodeSnapshot(machine, initial.state)
|
|
3291
|
+
* })
|
|
3292
|
+
* ```
|
|
3293
|
+
*
|
|
2795
3294
|
* @see {@link decodeSnapshot} for restoring an encoded snapshot.
|
|
2796
3295
|
* @category encoding
|
|
2797
|
-
* @since 4.0
|
|
3296
|
+
* @since 0.4.0
|
|
2798
3297
|
*/
|
|
2799
3298
|
export declare const encodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, snapshot: Machine.Snapshot<States>) => Effect.Effect<Machine.EncodedSnapshot, MachineSchemaEncodeError, Machine.SnapshotEncodingServices<States>>;
|
|
2800
3299
|
/**
|
|
@@ -2816,9 +3315,30 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
2816
3315
|
* Decoding restores logical statechart data only. It does not restart invoked
|
|
2817
3316
|
* processes, recreate spawned children, or restore a previous `MachineRef`.
|
|
2818
3317
|
*
|
|
3318
|
+
* **Example**
|
|
3319
|
+
*
|
|
3320
|
+
* ```ts
|
|
3321
|
+
* import { Effect, Schema } from "effect"
|
|
3322
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3323
|
+
*
|
|
3324
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
3325
|
+
* const States = Machine.defineStates({ Idle })
|
|
3326
|
+
* const machine = Machine.make({
|
|
3327
|
+
* states: States.states,
|
|
3328
|
+
* events: [],
|
|
3329
|
+
* initial: () => States.initial.Idle.from()
|
|
3330
|
+
* }).handle({ Idle: {} })
|
|
3331
|
+
*
|
|
3332
|
+
* const roundTrip = Effect.gen(function*() {
|
|
3333
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
3334
|
+
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
3335
|
+
* return yield* Machine.decodeSnapshot(machine, encoded)
|
|
3336
|
+
* })
|
|
3337
|
+
* ```
|
|
3338
|
+
*
|
|
2819
3339
|
* @see {@link encodeSnapshot} for creating the normalized representation.
|
|
2820
3340
|
* @category decoding
|
|
2821
|
-
* @since 4.0
|
|
3341
|
+
* @since 0.4.0
|
|
2822
3342
|
*/
|
|
2823
3343
|
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
2824
3344
|
/**
|
|
@@ -2862,7 +3382,7 @@ export declare const decodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
2862
3382
|
* @see {@link effect} for one-shot child effects.
|
|
2863
3383
|
* @see {@link spawn} for children whose lifetime is controlled by actions.
|
|
2864
3384
|
* @category constructors
|
|
2865
|
-
* @since 4.0
|
|
3385
|
+
* @since 0.4.0
|
|
2866
3386
|
*/
|
|
2867
3387
|
export declare const invoke: <ChildState, ChildEvent, ChildError = never, ChildRequirements = never, ChildOutput = never, ChildInitialError = never, Event = never, Address extends ChildAddress<never> | undefined = undefined>(config: {
|
|
2868
3388
|
readonly id: InvokeLifecycleId;
|
|
@@ -2897,10 +3417,27 @@ type InvokeEffectConfig<Fx extends Effect.Effect<any, any, any>, SuccessEvent, F
|
|
|
2897
3417
|
* Declare mapped outcomes in `internalEvents` unless they are also legitimate
|
|
2898
3418
|
* public commands.
|
|
2899
3419
|
*
|
|
3420
|
+
* **Example**
|
|
3421
|
+
*
|
|
3422
|
+
* ```ts
|
|
3423
|
+
* import { Effect, Schema } from "effect"
|
|
3424
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3425
|
+
*
|
|
3426
|
+
* class Loaded extends Schema.TaggedClass<Loaded>("Loaded")("Loaded", {
|
|
3427
|
+
* value: Schema.String
|
|
3428
|
+
* }) {}
|
|
3429
|
+
*
|
|
3430
|
+
* const load = Machine.invokeEffect({
|
|
3431
|
+
* id: "load",
|
|
3432
|
+
* effect: Effect.succeed("ready"),
|
|
3433
|
+
* onSuccess: (value) => new Loaded({ value })
|
|
3434
|
+
* })
|
|
3435
|
+
* ```
|
|
3436
|
+
*
|
|
2900
3437
|
* @see {@link invoke} for arbitrary child process logic.
|
|
2901
3438
|
* @see {@link after} for a state-scoped delayed event.
|
|
2902
3439
|
* @category constructors
|
|
2903
|
-
* @since 4.0
|
|
3440
|
+
* @since 0.4.0
|
|
2904
3441
|
*/
|
|
2905
3442
|
export declare const invokeEffect: <const Fx extends Effect.Effect<any, any, any>, SuccessEvent, FailureEvent = never>(config: InvokeEffectConfig<Fx, SuccessEvent, FailureEvent>) => InvokeEffectResult<Effect.Services<Fx>, SuccessEvent | (InvokeEffectIsInfallible<Fx> extends true ? never : FailureEvent)>;
|
|
2906
3443
|
/**
|
|
@@ -2910,8 +3447,19 @@ export declare const invokeEffect: <const Fx extends Effect.Effect<any, any, any
|
|
|
2910
3447
|
* that state exits. The delayed value should normally be declared in
|
|
2911
3448
|
* `internalEvents`.
|
|
2912
3449
|
*
|
|
3450
|
+
* **Example**
|
|
3451
|
+
*
|
|
3452
|
+
* ```ts
|
|
3453
|
+
* import { Schema } from "effect"
|
|
3454
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3455
|
+
*
|
|
3456
|
+
* class TimedOut extends Schema.TaggedClass<TimedOut>("TimedOut")("TimedOut", {}) {}
|
|
3457
|
+
*
|
|
3458
|
+
* const timeout = Machine.after("5 seconds", new TimedOut({}))
|
|
3459
|
+
* ```
|
|
3460
|
+
*
|
|
2913
3461
|
* @category constructors
|
|
2914
|
-
* @since 4.0
|
|
3462
|
+
* @since 0.4.0
|
|
2915
3463
|
*/
|
|
2916
3464
|
export declare const after: <Event extends {
|
|
2917
3465
|
readonly _tag: PropertyKey;
|
|
@@ -2947,7 +3495,7 @@ type RetagArgs<Target extends Machine.TaggedSchema, Source> = [
|
|
|
2947
3495
|
* remains authoritative at runtime.
|
|
2948
3496
|
*
|
|
2949
3497
|
* @category constructors
|
|
2950
|
-
* @since 4.0
|
|
3498
|
+
* @since 0.4.0
|
|
2951
3499
|
*/
|
|
2952
3500
|
export declare const retag: <const Target extends Machine.TaggedSchema, const Source extends {
|
|
2953
3501
|
readonly _tag: PropertyKey;
|
|
@@ -2980,61 +3528,150 @@ type InvokeMachineInput<Input extends Schema.Top> = Input extends typeof Schema.
|
|
|
2980
3528
|
* @see {@link invoke} for invoking lower-level process logic.
|
|
2981
3529
|
* @see {@link sendTo} for sending events to the invoked machine.
|
|
2982
3530
|
* @category constructors
|
|
2983
|
-
* @since 4.0
|
|
3531
|
+
* @since 0.4.0
|
|
2984
3532
|
*/
|
|
2985
3533
|
export declare const invokeMachine: {
|
|
2986
3534
|
<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: {
|
|
2987
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> &
|
|
3535
|
+
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
|
|
2988
3536
|
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
2989
3537
|
readonly onDone: (context: Machine.InvokeDoneContext<Output>) => DoneEvent | undefined;
|
|
2990
3538
|
} & 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>;
|
|
2991
3539
|
<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: {
|
|
2992
|
-
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> &
|
|
3540
|
+
readonly child: ChildMachine<Id, Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents> & EnsureExecutable<States, UnhandledStates, OutputStates>>;
|
|
2993
3541
|
readonly snapshot?: (context: Machine.InvokeSnapshotContext<Machine.Snapshot<States>, E | ActionError<R> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, Output>) => SnapshotEvent | undefined;
|
|
2994
3542
|
readonly onDone?: never;
|
|
2995
3543
|
} & 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>>;
|
|
2996
3544
|
};
|
|
2997
3545
|
/**
|
|
2998
|
-
* Plans the initial state for a machine without
|
|
3546
|
+
* Plans the initial state for a machine without executing actor commands.
|
|
2999
3547
|
*
|
|
3000
3548
|
* **Details**
|
|
3001
3549
|
*
|
|
3002
|
-
* The returned plan contains the settled initial snapshot,
|
|
3003
|
-
* emitted events,
|
|
3004
|
-
* logic and follow completion, eventless, and
|
|
3005
|
-
*
|
|
3550
|
+
* The returned plan contains the settled initial snapshot, actor commands,
|
|
3551
|
+
* emitted events, optional final output, and every startup microstep. Planning
|
|
3552
|
+
* may evaluate transition logic and follow completion, eventless, and
|
|
3553
|
+
* raised-event steps. Transition callbacks are evaluated synchronously.
|
|
3554
|
+
* `startingState` and `initialEntryPaths` describe the normalized
|
|
3555
|
+
* configuration before entry callbacks and settlement begin.
|
|
3006
3556
|
*
|
|
3007
3557
|
* **Gotchas**
|
|
3008
3558
|
*
|
|
3009
|
-
*
|
|
3010
|
-
*
|
|
3011
|
-
*
|
|
3559
|
+
* `start` executes the closed command list as part of the managed actor commit
|
|
3560
|
+
* protocol. Manual planners may inspect commands but need a running actor scope
|
|
3561
|
+
* to execute child-addressed operations.
|
|
3562
|
+
*
|
|
3563
|
+
* **Example**
|
|
3564
|
+
*
|
|
3565
|
+
* ```ts
|
|
3566
|
+
* import { Effect, Schema } from "effect"
|
|
3567
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3568
|
+
*
|
|
3569
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
3570
|
+
* const States = Machine.defineStates({ Idle })
|
|
3571
|
+
* const machine = Machine.make({
|
|
3572
|
+
* states: States.states,
|
|
3573
|
+
* events: [],
|
|
3574
|
+
* initial: () => States.initial.Idle.from()
|
|
3575
|
+
* }).handle({ Idle: {} })
|
|
3576
|
+
*
|
|
3577
|
+
* const initialState = Effect.map(Machine.planInitial(machine), (plan) => plan.state)
|
|
3578
|
+
* ```
|
|
3012
3579
|
*
|
|
3013
3580
|
* @see {@link plan} for planning a received event.
|
|
3014
3581
|
* @see {@link start} for the managed runtime protocol.
|
|
3015
3582
|
* @category constructors
|
|
3016
|
-
* @since 4.0
|
|
3583
|
+
* @since 0.4.0
|
|
3017
3584
|
*/
|
|
3018
|
-
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> &
|
|
3585
|
+
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<{
|
|
3586
|
+
readonly startingState: Machine.Snapshot<States>;
|
|
3587
|
+
readonly initialEntryPaths: ReadonlyArray<Machine.StateIdentifier<States>>;
|
|
3019
3588
|
readonly state: Machine.Snapshot<States>;
|
|
3020
|
-
readonly
|
|
3589
|
+
readonly commands: ReadonlyArray<Command>;
|
|
3021
3590
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
3591
|
+
readonly microsteps: ReadonlyArray<{
|
|
3592
|
+
readonly next: Machine.Snapshot<States>;
|
|
3593
|
+
readonly event: Machine.EventOf<Events> | InitialEvent;
|
|
3594
|
+
readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<States>, Machine.TagOf<Events[number]>, Machine.StateNodeIdentifier<States>>>;
|
|
3595
|
+
readonly commands: ReadonlyArray<Command>;
|
|
3596
|
+
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>;
|
|
3597
|
+
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
3598
|
+
readonly exitPaths: ReadonlyArray<string>;
|
|
3599
|
+
readonly entryPaths: ReadonlyArray<string>;
|
|
3600
|
+
readonly changed: boolean;
|
|
3601
|
+
}>;
|
|
3022
3602
|
} & ({
|
|
3023
3603
|
readonly done: true;
|
|
3024
3604
|
readonly output: Output;
|
|
3025
3605
|
} | {
|
|
3026
3606
|
readonly done: false;
|
|
3027
3607
|
readonly output: undefined;
|
|
3028
|
-
}), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError,
|
|
3608
|
+
}), InitialE | E | InfiniteTransitionError | MachineSchemaDecodeError | StartupError, never>;
|
|
3609
|
+
/**
|
|
3610
|
+
* Returns every compiled state node in definition order.
|
|
3611
|
+
*
|
|
3612
|
+
* **Details**
|
|
3613
|
+
*
|
|
3614
|
+
* The result includes atomic, compound, parallel, final, history, and choice
|
|
3615
|
+
* nodes together with their resolved descriptive annotations. Use each node's
|
|
3616
|
+
* `parent` property to reconstruct the complete hierarchy. Pseudo-states are
|
|
3617
|
+
* intentionally omitted from `children` because they can never appear in an
|
|
3618
|
+
* active configuration.
|
|
3619
|
+
*
|
|
3620
|
+
* @category getters
|
|
3621
|
+
* @since 0.4.0
|
|
3622
|
+
*/
|
|
3623
|
+
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>>>>;
|
|
3624
|
+
/**
|
|
3625
|
+
* Returns every registered transition handler in state definition order.
|
|
3626
|
+
*
|
|
3627
|
+
* **Details**
|
|
3628
|
+
*
|
|
3629
|
+
* Event handlers retain their handler-key order within each source state and
|
|
3630
|
+
* are followed by eventless and completion handlers. This function does not
|
|
3631
|
+
* execute handlers. Object-form event, eventless, and completion handlers with
|
|
3632
|
+
* a `targets` declaration expose those possible paths; handlers without one
|
|
3633
|
+
* remain dynamic.
|
|
3634
|
+
*
|
|
3635
|
+
* @category getters
|
|
3636
|
+
* @since 0.4.0
|
|
3637
|
+
*/
|
|
3638
|
+
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>>>>;
|
|
3639
|
+
/**
|
|
3640
|
+
* Returns serializable descriptions of every state-owned activity.
|
|
3641
|
+
*
|
|
3642
|
+
* **Details**
|
|
3643
|
+
*
|
|
3644
|
+
* Static `invoke`, `invokeEffect`, `after`, and `invokeMachine` descriptors
|
|
3645
|
+
* expose stable ownership and lifecycle metadata without serializing runtime
|
|
3646
|
+
* values. Function-valued invoke factories are represented as dynamic and are
|
|
3647
|
+
* never evaluated during inspection.
|
|
3648
|
+
*
|
|
3649
|
+
* @category getters
|
|
3650
|
+
* @since 0.4.0
|
|
3651
|
+
*/
|
|
3652
|
+
export declare const activityDefinitions: <M extends Machine.Any>(machine: M) => ReadonlyArray<Machine.ActivityDefinition<Machine.StateIdentifier<Machine.States<M>>>>;
|
|
3653
|
+
/**
|
|
3654
|
+
* Returns every state node active in a decoded snapshot, in definition order.
|
|
3655
|
+
*
|
|
3656
|
+
* **Details**
|
|
3657
|
+
*
|
|
3658
|
+
* Active compound ancestors and parallel regions are included together with
|
|
3659
|
+
* their active descendants. History and choice pseudo-states are never active
|
|
3660
|
+
* and are not returned.
|
|
3661
|
+
*
|
|
3662
|
+
* @category getters
|
|
3663
|
+
* @since 0.4.0
|
|
3664
|
+
*/
|
|
3665
|
+
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>>>>;
|
|
3029
3666
|
/**
|
|
3030
3667
|
* Returns the event tags handled by the current state snapshot.
|
|
3031
3668
|
*
|
|
3032
3669
|
* @category getters
|
|
3033
|
-
* @since 4.0
|
|
3670
|
+
* @since 0.4.0
|
|
3034
3671
|
*/
|
|
3035
3672
|
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]>>;
|
|
3036
3673
|
/**
|
|
3037
|
-
* Plans the next state snapshot
|
|
3674
|
+
* Plans the next state snapshot synchronously.
|
|
3038
3675
|
*
|
|
3039
3676
|
* **Details**
|
|
3040
3677
|
*
|
|
@@ -3045,25 +3682,47 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
3045
3682
|
*
|
|
3046
3683
|
* **Gotchas**
|
|
3047
3684
|
*
|
|
3048
|
-
* `plan` returns data; it does not implement the
|
|
3049
|
-
*
|
|
3050
|
-
*
|
|
3051
|
-
*
|
|
3052
|
-
*
|
|
3685
|
+
* `plan` returns data; it does not implement the actor commit protocol.
|
|
3686
|
+
* `start` executes child commands, publishes `next`, and then delivers
|
|
3687
|
+
* `emittedEvents`. Events with no enabled transition are ignored and produce
|
|
3688
|
+
* an unchanged plan.
|
|
3689
|
+
*
|
|
3690
|
+
* **Example**
|
|
3691
|
+
*
|
|
3692
|
+
* ```ts
|
|
3693
|
+
* import { Effect, Schema } from "effect"
|
|
3694
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3695
|
+
*
|
|
3696
|
+
* class Off extends Schema.TaggedClass<Off>("Off")("Off", {}) {}
|
|
3697
|
+
* class On extends Schema.TaggedClass<On>("On")("On", {}) {}
|
|
3698
|
+
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {}
|
|
3699
|
+
* const States = Machine.defineStates({ Off, On })
|
|
3700
|
+
* const machine = Machine.make({
|
|
3701
|
+
* states: States.states,
|
|
3702
|
+
* events: [Toggle],
|
|
3703
|
+
* initial: () => States.initial.Off.from()
|
|
3704
|
+
* }).handle({ Off: { on: { Toggle: () => States.initial.On.from() } }, On: {} })
|
|
3705
|
+
*
|
|
3706
|
+
* const nextState = Effect.gen(function*() {
|
|
3707
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
3708
|
+
* return (yield* Machine.plan(machine, initial.state, new Toggle({}))).next
|
|
3709
|
+
* })
|
|
3710
|
+
* ```
|
|
3053
3711
|
*
|
|
3054
3712
|
* @see {@link planInitial} for planning machine startup.
|
|
3055
3713
|
* @see {@link start} for managed execution and lifecycle observation.
|
|
3056
3714
|
* @category combinators
|
|
3057
|
-
* @since 4.0
|
|
3715
|
+
* @since 0.4.0
|
|
3058
3716
|
*/
|
|
3059
|
-
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> &
|
|
3717
|
+
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<{
|
|
3060
3718
|
readonly next: Machine.Snapshot<States>;
|
|
3061
|
-
readonly
|
|
3719
|
+
readonly commands: ReadonlyArray<Command>;
|
|
3062
3720
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
3063
3721
|
readonly microsteps: ReadonlyArray<{
|
|
3064
3722
|
readonly next: Machine.Snapshot<States>;
|
|
3065
3723
|
readonly event: Machine.EventOf<Events> | InitialEvent;
|
|
3066
|
-
readonly
|
|
3724
|
+
readonly transitions: ReadonlyArray<Machine.RetainedTransition<Machine.StateNodeIdentifier<States>, Machine.TagOf<Events[number]>, Machine.StateNodeIdentifier<States>>>;
|
|
3725
|
+
readonly commands: ReadonlyArray<Command>;
|
|
3067
3726
|
readonly raisedEvents: ReadonlyArray<Machine.EventOf<Events>>;
|
|
3068
3727
|
readonly emittedEvents: ReadonlyArray<Machine.EmitOf<Emits>>;
|
|
3069
3728
|
readonly exitPaths: ReadonlyArray<string>;
|
|
@@ -3076,67 +3735,7 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
3076
3735
|
} | {
|
|
3077
3736
|
readonly done: false;
|
|
3078
3737
|
readonly output: undefined;
|
|
3079
|
-
}), E | InfiniteTransitionError | MachineSchemaDecodeError,
|
|
3080
|
-
/**
|
|
3081
|
-
* Defers an effectful action until the current machine step is planned.
|
|
3082
|
-
*
|
|
3083
|
-
* **Details**
|
|
3084
|
-
*
|
|
3085
|
-
* The action's error and service requirements are retained in the machine
|
|
3086
|
-
* type without becoming requirements of `plan` or `planInitial`. The managed
|
|
3087
|
-
* runtime executes staged actions sequentially before publishing the planned
|
|
3088
|
-
* state. Pass a second argument when the planning Effect should return that
|
|
3089
|
-
* value after staging.
|
|
3090
|
-
*
|
|
3091
|
-
* **Example** (Typed staged action)
|
|
3092
|
-
*
|
|
3093
|
-
* ```ts
|
|
3094
|
-
* import { Context, Effect } from "effect"
|
|
3095
|
-
* import { Machine } from "@typeonce/effect-machine"
|
|
3096
|
-
*
|
|
3097
|
-
* class Audit extends Context.Service<Audit, {
|
|
3098
|
-
* readonly write: Effect.Effect<void, "AuditError">
|
|
3099
|
-
* }>()("example/Audit") {}
|
|
3100
|
-
*
|
|
3101
|
-
* const writeAudit = Machine.action(
|
|
3102
|
-
* Effect.flatMap(Audit, (audit) => audit.write)
|
|
3103
|
-
* )
|
|
3104
|
-
* ```
|
|
3105
|
-
*
|
|
3106
|
-
* @see {@link plan} for inspecting staged actions without executing them.
|
|
3107
|
-
* @category combinators
|
|
3108
|
-
* @since 4.0.0
|
|
3109
|
-
*/
|
|
3110
|
-
export declare const action: Machine.Action;
|
|
3111
|
-
/**
|
|
3112
|
-
* Runs staged machine actions sequentially with the supplied runtime.
|
|
3113
|
-
*
|
|
3114
|
-
* **When to use**
|
|
3115
|
-
*
|
|
3116
|
-
* Use when you implement a commit protocol around `plan` or `planInitial` and
|
|
3117
|
-
* need to execute their staged actions before publishing the planned snapshot.
|
|
3118
|
-
*
|
|
3119
|
-
* **Gotchas**
|
|
3120
|
-
*
|
|
3121
|
-
* This function only runs actions. The caller remains responsible for
|
|
3122
|
-
* publishing the planned state and delivering planned emitted events after all
|
|
3123
|
-
* actions succeed. Process-local operations such as `spawn`, `sendTo`, and
|
|
3124
|
-
* `stopChild` fail with `ProcessLocalError` because no managed machine process
|
|
3125
|
-
* owns the actions.
|
|
3126
|
-
*
|
|
3127
|
-
* @see {@link plan} for creating a transition plan.
|
|
3128
|
-
* @see {@link planInitial} for creating an initial plan.
|
|
3129
|
-
* @category running
|
|
3130
|
-
* @since 4.0.0
|
|
3131
|
-
*/
|
|
3132
|
-
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>>;
|
|
3133
|
-
/**
|
|
3134
|
-
* Returns the typed runtime capability for the current machine.
|
|
3135
|
-
*
|
|
3136
|
-
* @category combinators
|
|
3137
|
-
* @since 4.0.0
|
|
3138
|
-
*/
|
|
3139
|
-
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>>>;
|
|
3738
|
+
}), E | InfiniteTransitionError | MachineSchemaDecodeError, never>;
|
|
3140
3739
|
/**
|
|
3141
3740
|
* Creates a one-shot child process from an Effect.
|
|
3142
3741
|
*
|
|
@@ -3177,7 +3776,7 @@ export declare const runtime: <const Protocol extends Runtime.Protocol = {}>() =
|
|
|
3177
3776
|
* @see {@link transition} for event-driven state.
|
|
3178
3777
|
* @see {@link logic} for direct control over intermediate snapshots.
|
|
3179
3778
|
* @category constructors
|
|
3180
|
-
* @since 4.0
|
|
3779
|
+
* @since 0.4.0
|
|
3181
3780
|
*/
|
|
3182
3781
|
export declare const effect: <Output, Error = never, Requirements = never>(effect: Effect.Effect<Output, Error, Requirements>) => Logic<void, never, Error, Requirements, Output>;
|
|
3183
3782
|
/**
|
|
@@ -3206,7 +3805,7 @@ export declare const effect: <Output, Error = never, Requirements = never>(effec
|
|
|
3206
3805
|
* @see {@link effect} for one-shot work.
|
|
3207
3806
|
* @see {@link transition} for event-driven state.
|
|
3208
3807
|
* @category constructors
|
|
3209
|
-
* @since 4.0
|
|
3808
|
+
* @since 0.4.0
|
|
3210
3809
|
*/
|
|
3211
3810
|
export declare const logic: <State, Event = never, Output = void, Error = never, Requirements = never, InitialError = never, InitialRequirements = never>(options: {
|
|
3212
3811
|
readonly initial: State | ((scope: Logic.Scope<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
|
|
@@ -3225,10 +3824,22 @@ export declare const logic: <State, Event = never, Output = void, Error = never,
|
|
|
3225
3824
|
* Each received event runs the transition Effect against the latest state. The
|
|
3226
3825
|
* resulting state is published before the next queued event is processed.
|
|
3227
3826
|
*
|
|
3827
|
+
* **Example**
|
|
3828
|
+
*
|
|
3829
|
+
* ```ts
|
|
3830
|
+
* import { Effect } from "effect"
|
|
3831
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3832
|
+
*
|
|
3833
|
+
* const counter = Machine.transition(
|
|
3834
|
+
* 0,
|
|
3835
|
+
* (count, event: { readonly by: number }) => Effect.succeed(count + event.by)
|
|
3836
|
+
* )
|
|
3837
|
+
* ```
|
|
3838
|
+
*
|
|
3228
3839
|
* @see {@link effect} for one-shot work.
|
|
3229
3840
|
* @see {@link logic} for direct process lifecycle control.
|
|
3230
3841
|
* @category constructors
|
|
3231
|
-
* @since 4.0
|
|
3842
|
+
* @since 0.4.0
|
|
3232
3843
|
*/
|
|
3233
3844
|
export declare const transition: <State, Event, Error = never, Requirements = never>(initial: State, transition: (state: State, event: Event) => Effect.Effect<State, Error, Requirements>) => Logic<State, Event, Error, Requirements, never>;
|
|
3234
3845
|
/**
|
|
@@ -3238,7 +3849,7 @@ export declare const transition: <State, Event, Error = never, Requirements = ne
|
|
|
3238
3849
|
* constructed descriptors for the same pair address the same invoked child.
|
|
3239
3850
|
*
|
|
3240
3851
|
* @category constructors
|
|
3241
|
-
* @since 4.0
|
|
3852
|
+
* @since 0.4.0
|
|
3242
3853
|
*/
|
|
3243
3854
|
export declare const child: <const Id extends string, M extends Machine.Any>(id: Id, machine: M) => ChildMachine<Id, M>;
|
|
3244
3855
|
/**
|
|
@@ -3248,7 +3859,7 @@ export declare const child: <const Id extends string, M extends Machine.Any>(id:
|
|
|
3248
3859
|
* the address with `spawn`, `invoke`, or `sendTo`.
|
|
3249
3860
|
*
|
|
3250
3861
|
* @category constructors
|
|
3251
|
-
* @since 4.0
|
|
3862
|
+
* @since 0.4.0
|
|
3252
3863
|
*/
|
|
3253
3864
|
export declare const childAddress: <Event = never>(id: string) => ChildAddress<Event>;
|
|
3254
3865
|
/**
|
|
@@ -3256,20 +3867,19 @@ export declare const childAddress: <Event = never>(id: string) => ChildAddress<E
|
|
|
3256
3867
|
*
|
|
3257
3868
|
* **When to use**
|
|
3258
3869
|
*
|
|
3259
|
-
* Use
|
|
3260
|
-
*
|
|
3261
|
-
*
|
|
3870
|
+
* Use from lower-level process logic to create children that should be
|
|
3871
|
+
* addressed or stopped by the owning process instead of tied to a single
|
|
3872
|
+
* state's `invoke` lifecycle.
|
|
3262
3873
|
*
|
|
3263
3874
|
* **Gotchas**
|
|
3264
3875
|
*
|
|
3265
|
-
* This
|
|
3266
|
-
*
|
|
3267
|
-
* that child stops.
|
|
3876
|
+
* This Effect requires a managed process runtime. A named child id must be
|
|
3877
|
+
* unique for the current parent until that child stops.
|
|
3268
3878
|
*
|
|
3269
3879
|
* @see {@link invoke} for children that start and stop with a state.
|
|
3270
3880
|
* @see {@link sendTo} for sending events to named children.
|
|
3271
3881
|
* @category runtime
|
|
3272
|
-
* @since 4.0
|
|
3882
|
+
* @since 0.4.0
|
|
3273
3883
|
*/
|
|
3274
3884
|
export declare const spawn: {
|
|
3275
3885
|
<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError = never>(logic: Logic<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, ChildInitialError>): SpawnResult<ChildState, ChildEvent, ChildError, ChildRequirements, ChildOutput, never, ChildInitialError>;
|
|
@@ -3279,7 +3889,7 @@ export declare const spawn: {
|
|
|
3279
3889
|
* Sends an event to a named child process of the running machine.
|
|
3280
3890
|
*
|
|
3281
3891
|
* @category runtime
|
|
3282
|
-
* @since 4.0
|
|
3892
|
+
* @since 0.4.0
|
|
3283
3893
|
*/
|
|
3284
3894
|
export declare const sendTo: {
|
|
3285
3895
|
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): Effect.Effect<void, StoppedError, MachineRuntimeRequirement>;
|
|
@@ -3289,7 +3899,7 @@ export declare const sendTo: {
|
|
|
3289
3899
|
* Stops a named child process of the running machine.
|
|
3290
3900
|
*
|
|
3291
3901
|
* @category runtime
|
|
3292
|
-
* @since 4.0
|
|
3902
|
+
* @since 0.4.0
|
|
3293
3903
|
*/
|
|
3294
3904
|
export declare const stopChild: {
|
|
3295
3905
|
<Event>(child: ChildAddress<Event>): Effect.Effect<void, never, MachineRuntimeRequirement>;
|
|
@@ -3299,7 +3909,7 @@ export declare const stopChild: {
|
|
|
3299
3909
|
* Returns a stream of terminal lifecycle outcomes for a running machine.
|
|
3300
3910
|
*
|
|
3301
3911
|
* @category combinators
|
|
3302
|
-
* @since 4.0
|
|
3912
|
+
* @since 0.4.0
|
|
3303
3913
|
*/
|
|
3304
3914
|
export declare const watch: <State, Event, Error = never, Output = never>(ref: MachineRef<State, Event, Error, Output>) => Stream.Stream<RuntimeOutcome<State, Error, Output>>;
|
|
3305
3915
|
/**
|
|
@@ -3312,11 +3922,10 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
3312
3922
|
*
|
|
3313
3923
|
* **Details**
|
|
3314
3924
|
*
|
|
3315
|
-
* For each accepted event the runtime plans the complete
|
|
3316
|
-
*
|
|
3317
|
-
* state, delivers emitted events, and then starts invokes
|
|
3318
|
-
*
|
|
3319
|
-
* from that plan are suppressed.
|
|
3925
|
+
* For each accepted event the runtime plans the complete synchronous
|
|
3926
|
+
* macrostep, executes closed actor commands, stops invokes for exited states,
|
|
3927
|
+
* publishes the new state, delivers emitted events, and then starts invokes
|
|
3928
|
+
* for entered states.
|
|
3320
3929
|
*
|
|
3321
3930
|
* **Gotchas**
|
|
3322
3931
|
*
|
|
@@ -3325,10 +3934,82 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
3325
3934
|
* rather than being returned by `send`. Sending after the machine reaches any
|
|
3326
3935
|
* terminal state fails immediately with `StoppedError`.
|
|
3327
3936
|
*
|
|
3937
|
+
* **Example**
|
|
3938
|
+
*
|
|
3939
|
+
* ```ts
|
|
3940
|
+
* import { Effect, Schema } from "effect"
|
|
3941
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3942
|
+
*
|
|
3943
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
3944
|
+
* const States = Machine.defineStates({ Idle })
|
|
3945
|
+
* const machine = Machine.make({
|
|
3946
|
+
* states: States.states,
|
|
3947
|
+
* events: [],
|
|
3948
|
+
* initial: () => States.initial.Idle.from()
|
|
3949
|
+
* }).handle({ Idle: {} })
|
|
3950
|
+
*
|
|
3951
|
+
* const state = Effect.gen(function*() {
|
|
3952
|
+
* const ref = yield* Machine.start(machine)
|
|
3953
|
+
* return yield* ref.state
|
|
3954
|
+
* })
|
|
3955
|
+
* ```
|
|
3956
|
+
*
|
|
3328
3957
|
* @see {@link plan} for inspecting the same transition plan without executing it.
|
|
3329
3958
|
* @see {@link watch} for classified terminal outcomes.
|
|
3330
3959
|
* @category constructors
|
|
3331
|
-
* @since 4.0
|
|
3960
|
+
* @since 0.4.0
|
|
3961
|
+
*/
|
|
3962
|
+
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>>>;
|
|
3963
|
+
/**
|
|
3964
|
+
* Starts a fresh managed runtime from a decoded logical snapshot.
|
|
3965
|
+
*
|
|
3966
|
+
* **Details**
|
|
3967
|
+
*
|
|
3968
|
+
* `resume` validates and normalizes the supplied snapshot before publishing it
|
|
3969
|
+
* as the first state. It does not call the machine's initial function, replay
|
|
3970
|
+
* entry or transition actions, re-deliver raised or emitted events, or
|
|
3971
|
+
* re-evaluate historical completion and eventless transitions. Active-state
|
|
3972
|
+
* invokes start once in ancestor and document order with {@link InitialEvent};
|
|
3973
|
+
* delayed invokes restart their complete duration and invoked machines start
|
|
3974
|
+
* from their own initial state.
|
|
3975
|
+
*
|
|
3976
|
+
* Only logical state, completion, and history metadata are resumed. Queues,
|
|
3977
|
+
* scopes, subscriptions, fibers, spawned children, invoke progress, and prior
|
|
3978
|
+
* runtime status are process-local and are not restored. A final snapshot
|
|
3979
|
+
* immediately produces a completed ref with its current-machine output.
|
|
3980
|
+
*
|
|
3981
|
+
* Decode encoded data explicitly with {@link decodeSnapshot} before calling
|
|
3982
|
+
* this function. Stable snapshots are hosted as supplied; newly enabled
|
|
3983
|
+
* eventless or completion transitions in a changed machine definition are not
|
|
3984
|
+
* evaluated merely because the runtime was resumed; only ordinary subsequent
|
|
3985
|
+
* transition planning can enter and stabilize states.
|
|
3986
|
+
*
|
|
3987
|
+
* **Example**
|
|
3988
|
+
*
|
|
3989
|
+
* ```ts
|
|
3990
|
+
* import { Effect, Schema } from "effect"
|
|
3991
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
3992
|
+
*
|
|
3993
|
+
* class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
|
|
3994
|
+
* const States = Machine.defineStates({ Idle })
|
|
3995
|
+
* const machine = Machine.make({
|
|
3996
|
+
* states: States.states,
|
|
3997
|
+
* events: [],
|
|
3998
|
+
* initial: () => States.initial.Idle.from()
|
|
3999
|
+
* }).handle({ Idle: {} })
|
|
4000
|
+
*
|
|
4001
|
+
* const resumed = Effect.gen(function*() {
|
|
4002
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
4003
|
+
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
4004
|
+
* const snapshot = yield* Machine.decodeSnapshot(machine, encoded)
|
|
4005
|
+
* return yield* Machine.resume(machine, snapshot)
|
|
4006
|
+
* })
|
|
4007
|
+
* ```
|
|
4008
|
+
*
|
|
4009
|
+
* @see {@link decodeSnapshot} for the schema and transport boundary.
|
|
4010
|
+
* @see {@link start} for ordinary initial startup.
|
|
4011
|
+
* @category constructors
|
|
4012
|
+
* @since 0.4.0
|
|
3332
4013
|
*/
|
|
3333
|
-
export declare const
|
|
4014
|
+
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>>>;
|
|
3334
4015
|
//# sourceMappingURL=Machine.d.ts.map
|