@typeonce/effect-machine 0.46.0 → 0.47.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/AGENTS.md +1823 -0
- package/CLAUDE.md +1823 -0
- package/README.md +100 -77
- package/ai-docs/README.md +18 -0
- package/ai-docs/src/10_modeling/01_create-a-machine.ts +51 -0
- package/ai-docs/src/10_modeling/02_branch-on-an-event.ts +55 -0
- package/ai-docs/src/10_modeling/03_update-retained-state.ts +58 -0
- package/ai-docs/src/10_modeling/04_verify-after-changing.ts +29 -0
- package/{docs/agent-guide.md → ai-docs/src/10_modeling/index.md} +234 -155
- package/{docs/root-api.md → ai-docs/src/20_root-api/index.md} +29 -57
- package/{docs/effect-atom-react.md → ai-docs/src/30_react/index.md} +42 -49
- package/{docs/machine-review.md → ai-docs/src/40_review/index.md} +42 -40
- package/ai-docs/src/index.md +7 -0
- package/ai-docs/tsconfig.json +22 -0
- package/dist/Machine.d.ts +1195 -1474
- package/dist/Machine.d.ts.map +1 -1
- package/dist/Machine.js +366 -214
- package/dist/Machine.js.map +1 -1
- package/dist/internal/machine/atom.js.map +1 -1
- package/dist/internal/machine/cluster.js.map +1 -1
- package/dist/internal/machine/command.d.ts +8 -0
- package/dist/internal/machine/command.d.ts.map +1 -1
- package/dist/internal/machine/command.js +2 -2
- package/dist/internal/machine/command.js.map +1 -1
- package/dist/internal/machine/configuration.d.ts +21 -5
- package/dist/internal/machine/configuration.d.ts.map +1 -1
- package/dist/internal/machine/configuration.js +1 -0
- package/dist/internal/machine/configuration.js.map +1 -1
- package/dist/internal/machine/construction.js.map +1 -1
- package/dist/internal/machine/declaration.d.ts +2 -1
- package/dist/internal/machine/declaration.d.ts.map +1 -1
- package/dist/internal/machine/declaration.js +28 -46
- package/dist/internal/machine/declaration.js.map +1 -1
- package/dist/internal/machine/executionPlan.d.ts.map +1 -1
- package/dist/internal/machine/executionPlan.js +23 -16
- package/dist/internal/machine/executionPlan.js.map +1 -1
- package/dist/internal/machine/implementation.d.ts +2 -0
- package/dist/internal/machine/implementation.d.ts.map +1 -1
- package/dist/internal/machine/implementation.js.map +1 -1
- package/dist/internal/machine/initialDeclaration.d.ts +2 -0
- package/dist/internal/machine/initialDeclaration.d.ts.map +1 -1
- package/dist/internal/machine/initialDeclaration.js +15 -0
- package/dist/internal/machine/initialDeclaration.js.map +1 -1
- package/dist/internal/machine/invocation.d.ts.map +1 -1
- package/dist/internal/machine/invocation.js +25 -19
- package/dist/internal/machine/invocation.js.map +1 -1
- package/dist/internal/machine/invocationEvent.d.ts +34 -17
- package/dist/internal/machine/invocationEvent.d.ts.map +1 -1
- package/dist/internal/machine/invocationEvent.js +16 -4
- package/dist/internal/machine/invocationEvent.js.map +1 -1
- package/dist/internal/machine/machine.d.ts +5 -22
- package/dist/internal/machine/machine.d.ts.map +1 -1
- package/dist/internal/machine/machine.js +157 -119
- package/dist/internal/machine/machine.js.map +1 -1
- package/dist/internal/machine/planner.d.ts +15 -4
- package/dist/internal/machine/planner.d.ts.map +1 -1
- package/dist/internal/machine/planner.js +18 -21
- package/dist/internal/machine/planner.js.map +1 -1
- package/dist/internal/machine/process.d.ts +2 -0
- package/dist/internal/machine/process.d.ts.map +1 -1
- package/dist/internal/machine/process.js +2 -0
- package/dist/internal/machine/process.js.map +1 -1
- package/dist/internal/machine/protocol.js.map +1 -1
- package/dist/internal/machine/runtime.d.ts.map +1 -1
- package/dist/internal/machine/runtime.js.map +1 -1
- package/dist/internal/machine/runtimeCompiled.js.map +1 -1
- package/dist/internal/machine/runtimeGeneric.d.ts.map +1 -1
- package/dist/internal/machine/runtimeGeneric.js.map +1 -1
- package/dist/internal/machine/runtimeProtocol.d.ts +26 -0
- package/dist/internal/machine/runtimeProtocol.d.ts.map +1 -1
- package/dist/internal/machine/runtimeProtocol.js +71 -0
- package/dist/internal/machine/runtimeProtocol.js.map +1 -1
- package/dist/internal/machine/stateDefinition.d.ts.map +1 -1
- package/dist/internal/machine/stateDefinition.js +0 -14
- package/dist/internal/machine/stateDefinition.js.map +1 -1
- package/dist/internal/machine/symbols.d.ts +9 -0
- package/dist/internal/machine/symbols.d.ts.map +1 -1
- package/dist/internal/machine/symbols.js.map +1 -1
- package/dist/internal/machine/topology.d.ts +18 -9
- package/dist/internal/machine/topology.d.ts.map +1 -1
- package/dist/internal/machine/topology.js +16 -1
- package/dist/internal/machine/topology.js.map +1 -1
- package/dist/internal/testing/machine/arbitrary.d.ts.map +1 -1
- package/dist/internal/testing/machine/arbitrary.js +2 -0
- package/dist/internal/testing/machine/arbitrary.js.map +1 -1
- package/dist/internal/testing/machine/check.d.ts +17 -0
- package/dist/internal/testing/machine/check.d.ts.map +1 -0
- package/dist/internal/testing/machine/check.js +371 -0
- package/dist/internal/testing/machine/check.js.map +1 -0
- package/dist/internal/testing/machine/exploration.d.ts.map +1 -1
- package/dist/internal/testing/machine/exploration.js.map +1 -1
- package/dist/internal/testing/machine/finiteModel.d.ts +14 -13
- package/dist/internal/testing/machine/finiteModel.d.ts.map +1 -1
- package/dist/internal/testing/machine/finiteModel.js +21 -23
- package/dist/internal/testing/machine/finiteModel.js.map +1 -1
- package/dist/internal/testing/machine/runtime.d.ts +19 -88
- package/dist/internal/testing/machine/runtime.d.ts.map +1 -1
- package/dist/internal/testing/machine/runtime.js +0 -19
- package/dist/internal/testing/machine/runtime.js.map +1 -1
- package/dist/internal/testing/machine/runtimeInvariant.js.map +1 -1
- package/dist/internal/testing/machine/verification.d.ts.map +1 -1
- package/dist/internal/testing/machine/verification.js.map +1 -1
- package/dist/testing/MachineTest.d.ts +349 -139
- package/dist/testing/MachineTest.d.ts.map +1 -1
- package/dist/testing/MachineTest.js +201 -136
- package/dist/testing/MachineTest.js.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.d.ts +9 -14
- package/dist/unstable/cluster/ClusterMachine.d.ts.map +1 -1
- package/dist/unstable/cluster/ClusterMachine.js +9 -14
- package/dist/unstable/cluster/ClusterMachine.js.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.d.ts +169 -80
- package/dist/unstable/reactivity/AtomMachine.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomMachine.js +165 -76
- package/dist/unstable/reactivity/AtomMachine.js.map +1 -1
- package/package.json +11 -9
- package/src/Machine.ts +1139 -2130
- package/src/internal/machine/atom.ts +3 -3
- package/src/internal/machine/cluster.ts +2 -2
- package/src/internal/machine/command.ts +10 -4
- package/src/internal/machine/configuration.ts +16 -17
- package/src/internal/machine/construction.ts +1 -1
- package/src/internal/machine/declaration.ts +25 -50
- package/src/internal/machine/executionPlan.ts +90 -56
- package/src/internal/machine/implementation.ts +3 -1
- package/src/internal/machine/initialDeclaration.ts +16 -0
- package/src/internal/machine/invocation.ts +38 -44
- package/src/internal/machine/invocationEvent.ts +46 -20
- package/src/internal/machine/machine.ts +217 -243
- package/src/internal/machine/planner.ts +72 -106
- package/src/internal/machine/process.ts +12 -0
- package/src/internal/machine/protocol.ts +6 -6
- package/src/internal/machine/runtime.ts +1 -5
- package/src/internal/machine/runtimeCompiled.ts +2 -2
- package/src/internal/machine/runtimeGeneric.ts +2 -4
- package/src/internal/machine/runtimeProtocol.ts +80 -4
- package/src/internal/machine/stateDefinition.ts +0 -39
- package/src/internal/machine/symbols.ts +11 -0
- package/src/internal/machine/topology.ts +40 -18
- package/src/internal/testing/machine/arbitrary.ts +2 -0
- package/src/internal/testing/machine/check.ts +460 -0
- package/src/internal/testing/machine/exploration.ts +4 -5
- package/src/internal/testing/machine/finiteModel.ts +40 -42
- package/src/internal/testing/machine/runtime.ts +31 -170
- package/src/internal/testing/machine/runtimeInvariant.ts +3 -3
- package/src/internal/testing/machine/verification.ts +14 -14
- package/src/testing/MachineTest.ts +366 -145
- package/src/unstable/cluster/ClusterMachine.ts +9 -14
- package/src/unstable/reactivity/AtomMachine.ts +167 -78
package/dist/Machine.d.ts
CHANGED
|
@@ -15,11 +15,10 @@ import type * as Stream from "effect/Stream";
|
|
|
15
15
|
import type * as Types from "effect/Types";
|
|
16
16
|
import type * as Activities from "./internal/machine/activities.js";
|
|
17
17
|
import type { ChildAlreadyExistsError, InfiniteTransitionError, MachineSchemaDecodeError, MachineSchemaEncodeError, StartupError, StoppedError } from "./internal/machine/machine.js";
|
|
18
|
-
import * as internal from "./internal/machine/machine.js";
|
|
19
18
|
import { InitialEventTypeId } from "./internal/machine/machine.js";
|
|
20
19
|
import type { EnsureExecutable } from "./internal/machine/readiness.js";
|
|
21
20
|
import type { ExcludeCompatibleRuntime } from "./internal/machine/requirements.js";
|
|
22
|
-
import type
|
|
21
|
+
import type { MachineRuntime } from "./internal/machine/runtimeProtocol.js";
|
|
23
22
|
import type * as StateDefinition from "./internal/machine/stateDefinition.js";
|
|
24
23
|
import type * as Topology from "./internal/machine/topology.js";
|
|
25
24
|
/**
|
|
@@ -37,14 +36,25 @@ export type TypeId = "~effect/Machine";
|
|
|
37
36
|
* @since 0.4.0
|
|
38
37
|
*/
|
|
39
38
|
export declare const TypeId: TypeId;
|
|
40
|
-
declare const MachineOutputStatesTypeId:
|
|
41
|
-
declare const MachineTypeId:
|
|
42
|
-
declare const EventConstructionTypeId:
|
|
43
|
-
declare const EmittedEventConstructionTypeId:
|
|
44
|
-
declare const EventProtocolTypeId:
|
|
45
|
-
declare const ParentModeTypeId:
|
|
39
|
+
declare const MachineOutputStatesTypeId: "~effect/Machine/OutputStates";
|
|
40
|
+
declare const MachineTypeId: "~effect/Machine/TypeCarrier";
|
|
41
|
+
declare const EventConstructionTypeId: "~effect/Machine/EventConstruction";
|
|
42
|
+
declare const EmittedEventConstructionTypeId: "~effect/Machine/EmittedEventConstruction";
|
|
43
|
+
declare const EventProtocolTypeId: "~effect/Machine/EventProtocol";
|
|
44
|
+
declare const ParentModeTypeId: "~effect/Machine/ParentMode";
|
|
45
|
+
declare const ChildMachineLogicTypeId: "~effect/Machine/ChildMachineLogic";
|
|
46
|
+
declare const InvokeTypeId: "~effect/Machine/Invoke";
|
|
47
|
+
declare const StateConstructionTypeId: "~effect/Machine/StateConstruction";
|
|
48
|
+
declare const TargetSnapshotTypeId: "~effect/Machine/TargetSnapshot";
|
|
49
|
+
declare const HistoryTargetTypeId: "~effect/Machine/HistoryTarget";
|
|
50
|
+
declare const InitialTargetTypeId: "~effect/Machine/InitialTarget";
|
|
51
|
+
declare const ChoiceTargetTypeId: "~effect/Machine/ChoiceTarget";
|
|
52
|
+
declare const NoTargetTypeId: "~effect/Machine/NoTarget";
|
|
53
|
+
declare const DeclinedTypeId: "~effect/Machine/Declined";
|
|
54
|
+
declare const StateUpdateTypeId: "~effect/Machine/StateUpdate";
|
|
55
|
+
declare const CombinedTargetTypeId: "~effect/Machine/CombinedTarget";
|
|
56
|
+
declare const SelectedBranchTypeId: "~effect/Machine/SelectedBranch";
|
|
46
57
|
declare const ParentTypeId = "~effect/Machine/Parent";
|
|
47
|
-
declare const ChildMachineLogicTypeId: typeof internal.ChildMachineLogicTypeId;
|
|
48
58
|
/**
|
|
49
59
|
* Type identifier used for the synthetic event passed to startup lifecycle
|
|
50
60
|
* actions.
|
|
@@ -92,29 +102,38 @@ type IsAny<A> = 0 extends (1 & A) ? true : false;
|
|
|
92
102
|
* **Gotchas**
|
|
93
103
|
*
|
|
94
104
|
* Use `guard` to decline a transition before constructing its next state.
|
|
95
|
-
*
|
|
105
|
+
* List `{ decline: true }` in `branches` when `resolve` may return `select.decline()`.
|
|
96
106
|
* Register cancellable state-scoped delays in `make({ timers })`.
|
|
97
107
|
*
|
|
98
|
-
* **Example**
|
|
108
|
+
* **Example** (Declining an event with a guard)
|
|
99
109
|
*
|
|
100
|
-
* ```ts
|
|
110
|
+
* ```ts import.meta.vitest
|
|
101
111
|
* import { Machine } from "@typeonce/effect-machine"
|
|
102
|
-
* import { Schema } from "effect"
|
|
112
|
+
* import { Effect, Schema } from "effect"
|
|
113
|
+
*
|
|
103
114
|
* const events = Machine.events({ Add: { by: Schema.Number } })
|
|
104
115
|
* const Root = Machine.state({ fields: { count: Schema.Number } })
|
|
105
|
-
*
|
|
116
|
+
* const counter = Machine.make({
|
|
106
117
|
* root: Root,
|
|
107
118
|
* events
|
|
108
119
|
* }).handle({
|
|
109
120
|
* root: () => ({ count: 0 }),
|
|
110
121
|
* on: {
|
|
111
122
|
* Add: {
|
|
112
|
-
* update:
|
|
113
|
-
* guard: ({ event }) => event.by > 0
|
|
114
|
-
* data: ({ root, event }) => ({ count: root.count + event.by })
|
|
123
|
+
* update: { root: ({ root, event }) => ({ count: root.count + event.by }) },
|
|
124
|
+
* guard: ({ event }) => event.by > 0
|
|
115
125
|
* }
|
|
116
126
|
* }
|
|
117
127
|
* })
|
|
128
|
+
*
|
|
129
|
+
* const accepts = (by: number) =>
|
|
130
|
+
* Effect.gen(function*() {
|
|
131
|
+
* const initial = yield* Machine.planInitial(counter)
|
|
132
|
+
* return yield* Machine.can(counter, initial.state, events.Add({ by }))
|
|
133
|
+
* })
|
|
134
|
+
*
|
|
135
|
+
* await Effect.runPromise(accepts(1)) // => true
|
|
136
|
+
* await Effect.runPromise(accepts(0)) // => false
|
|
118
137
|
* ```
|
|
119
138
|
*
|
|
120
139
|
* @category models
|
|
@@ -206,19 +225,27 @@ export interface Definition<States extends Machine.StateSchemas, Events extends
|
|
|
206
225
|
* captured by value, so later mutation of the supplied objects cannot alter
|
|
207
226
|
* the resulting machine.
|
|
208
227
|
*
|
|
209
|
-
* **Example**
|
|
210
|
-
*
|
|
211
|
-
* ```ts
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* }
|
|
221
|
-
* }
|
|
228
|
+
* **Example** (Adding handlers to a definition)
|
|
229
|
+
*
|
|
230
|
+
* ```ts import.meta.vitest
|
|
231
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
232
|
+
* import { Effect, Schema } from "effect"
|
|
233
|
+
*
|
|
234
|
+
* const Events = Machine.events({ Increment: { by: Schema.Number } })
|
|
235
|
+
* const definition = Machine.make({ root: Machine.state({ fields: { count: Schema.Number } }), events: Events })
|
|
236
|
+
*
|
|
237
|
+
* const counter = definition.handle({
|
|
238
|
+
* root: { count: 0 },
|
|
239
|
+
* on: { Increment: { update: { root: ({ root, event }) => ({ count: root.count + event.by }) } } }
|
|
240
|
+
* })
|
|
241
|
+
*
|
|
242
|
+
* const count = Effect.gen(function*() {
|
|
243
|
+
* const initial = yield* Machine.planInitial(counter)
|
|
244
|
+
* const planned = yield* Machine.plan(counter, initial.state, Events.Increment({ by: 2 }))
|
|
245
|
+
* return planned.next.value.count
|
|
246
|
+
* })
|
|
247
|
+
*
|
|
248
|
+
* await Effect.runPromise(count) // => 2
|
|
222
249
|
* ```
|
|
223
250
|
*
|
|
224
251
|
* @since 0.4.0
|
|
@@ -299,9 +326,29 @@ StartupError,
|
|
|
299
326
|
* @since 0.4.0
|
|
300
327
|
*/
|
|
301
328
|
StoppedError } from "./internal/machine/machine.js";
|
|
329
|
+
export type {
|
|
330
|
+
/**
|
|
331
|
+
* Service required by operations that act on the machine executing them,
|
|
332
|
+
* such as `sendTo`, `stopChild`, and `spawn`.
|
|
333
|
+
*
|
|
334
|
+
* **When to use**
|
|
335
|
+
*
|
|
336
|
+
* Name this requirement when annotating a reusable helper built from those
|
|
337
|
+
* operations, or when exporting a value whose inferred type includes it.
|
|
338
|
+
*
|
|
339
|
+
* **Details**
|
|
340
|
+
*
|
|
341
|
+
* A running machine provides this service to the effects it executes, so it
|
|
342
|
+
* never appears in the requirements of the machine itself. Only the type is
|
|
343
|
+
* public: the service cannot be constructed or provided outside a running
|
|
344
|
+
* machine.
|
|
345
|
+
*
|
|
346
|
+
* @category services
|
|
347
|
+
* @since 0.47.0
|
|
348
|
+
*/
|
|
349
|
+
MachineRuntime } from "./internal/machine/runtimeProtocol.js";
|
|
302
350
|
declare const RuntimeRequirementTypeId = "~effect/Machine/RuntimeRequirement";
|
|
303
351
|
declare const ActionRequirementTypeId = "~effect/Machine/ActionRequirement";
|
|
304
|
-
type MachineRuntimeRequirement = internalRuntime.MachineRuntime;
|
|
305
352
|
/**
|
|
306
353
|
* Opaque marker used to keep staged action errors and services separate from
|
|
307
354
|
* the Effect that plans a machine step.
|
|
@@ -342,7 +389,7 @@ export type PlanningServices<Requirements> = Exclude<Requirements, ActionRequire
|
|
|
342
389
|
* @category utility types
|
|
343
390
|
* @since 0.4.0
|
|
344
391
|
*/
|
|
345
|
-
export type ExecutionServices<Requirements> = Exclude<PlanningServices<Requirements>,
|
|
392
|
+
export type ExecutionServices<Requirements> = Exclude<PlanningServices<Requirements>, MachineRuntime> | Exclude<ActionServices<Requirements>, MachineRuntime>;
|
|
346
393
|
/**
|
|
347
394
|
* Managed runtime capability used to deliver raised events and publish
|
|
348
395
|
* emitted notifications.
|
|
@@ -472,34 +519,6 @@ export type Command = {
|
|
|
472
519
|
* @since 0.4.0
|
|
473
520
|
*/
|
|
474
521
|
export declare namespace Runtime {
|
|
475
|
-
/**
|
|
476
|
-
* Protocol annotation for managed event delivery.
|
|
477
|
-
*
|
|
478
|
-
* @category models
|
|
479
|
-
* @since 0.4.0
|
|
480
|
-
*/
|
|
481
|
-
interface Protocol {
|
|
482
|
-
readonly events?: unknown;
|
|
483
|
-
readonly emits?: unknown;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Extracts the events required by a runtime protocol annotation.
|
|
487
|
-
*
|
|
488
|
-
* @category utility types
|
|
489
|
-
* @since 0.4.0
|
|
490
|
-
*/
|
|
491
|
-
type Events<Protocol> = Protocol extends {
|
|
492
|
-
readonly events: infer Events;
|
|
493
|
-
} ? Events : never;
|
|
494
|
-
/**
|
|
495
|
-
* Extracts the emitted events required by a runtime protocol annotation.
|
|
496
|
-
*
|
|
497
|
-
* @category utility types
|
|
498
|
-
* @since 0.4.0
|
|
499
|
-
*/
|
|
500
|
-
type Emits<Protocol> = Protocol extends {
|
|
501
|
-
readonly emits: infer Emits;
|
|
502
|
-
} ? Emits : never;
|
|
503
522
|
/**
|
|
504
523
|
* Opaque service requirement for a machine runtime capability.
|
|
505
524
|
*
|
|
@@ -514,7 +533,6 @@ export declare namespace Runtime {
|
|
|
514
533
|
}
|
|
515
534
|
}
|
|
516
535
|
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;
|
|
517
|
-
declare const InvokeTypeId: typeof internal.InvokeTypeId;
|
|
518
536
|
type StateDefinitionError<Message extends string, Path extends PropertyKey = never, Details extends PropertyKey = never> = {
|
|
519
537
|
readonly "~effect/Machine/DefinitionError": Message;
|
|
520
538
|
readonly path: Path;
|
|
@@ -535,7 +553,6 @@ type RootCompatibilityError<Message extends string> = {
|
|
|
535
553
|
};
|
|
536
554
|
type ActiveStateKey<States extends Machine.StateSchemas> = Machine.ActiveStateKey<States>;
|
|
537
555
|
type HistoryStateKey<States extends Machine.StateSchemas> = Machine.HistoryStateKey<States>;
|
|
538
|
-
type ChoiceStateKey<States extends Machine.StateSchemas> = Machine.ChoiceStateKey<States>;
|
|
539
556
|
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>`;
|
|
540
557
|
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;
|
|
541
558
|
type ValidateStateTree<States extends Machine.StateSchemas, AllowHistory extends boolean = false, Prefix extends string = ""> = {
|
|
@@ -568,19 +585,14 @@ type ValidateStateNodeConfig<Node extends Machine.StateNodeConfig, Path extends
|
|
|
568
585
|
type ValidateOutputSchema<Node> = "output" extends keyof Node ? Node extends {
|
|
569
586
|
readonly output: Schema.Top;
|
|
570
587
|
} ? unknown : StateDefinitionError<"State output must be a schema"> : unknown;
|
|
571
|
-
type SelectorChildKey<Children extends Machine.StateSchemas> = ActiveStateKey<Children> | ChoiceStateKey<Children>;
|
|
572
|
-
type ValidateInitialSelectorChild<Children extends Machine.StateSchemas, Path extends PropertyKey> = "initial" extends SelectorChildKey<Children> ? StateDefinitionError<"Active and choice child states cannot use the reserved target selector key \"initial\"", StateDefinitionPath<Extract<Path, string>, "initial">, "initial"> : unknown;
|
|
573
|
-
type ValidateWithSelectorChild<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> = Node extends {
|
|
574
|
-
readonly schema: Machine.TaggedSchema;
|
|
575
|
-
} ? "with" extends SelectorChildKey<Children> ? StateDefinitionError<"Schema-backed compound child states cannot use the reserved local target selector key \"with\"", StateDefinitionPath<Extract<Path, string>, "with">, "with"> : unknown : unknown;
|
|
576
588
|
type ValidateStateNodeWithChildren<Node extends Machine.StateNodeConfig, Children, Path extends PropertyKey> = Children extends Machine.StateSchemas ? Node extends {
|
|
577
589
|
readonly type: "final";
|
|
578
590
|
} ? StateDefinitionError<"Final states cannot declare child states"> : Node extends {
|
|
579
591
|
readonly type: "parallel";
|
|
580
|
-
} ?
|
|
592
|
+
} ? "initial" extends keyof Node ? StateDefinitionError<"Parallel states cannot declare an initial child"> : {
|
|
581
593
|
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
582
|
-
} & ValidateOutputSchema<Node>
|
|
583
|
-
type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> = "initial" extends keyof Node ? StateDefinitionError<"Declare initial edges in handle", Path> :
|
|
594
|
+
} & 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">;
|
|
595
|
+
type ValidateCompoundStateNode<Node extends Machine.StateNodeConfig, Children extends Machine.StateSchemas, Path extends PropertyKey> = "initial" extends keyof Node ? StateDefinitionError<"Declare initial edges in handle", Path> : {
|
|
584
596
|
readonly states: ValidateStateTree<Children, true, Extract<Path, string>>;
|
|
585
597
|
};
|
|
586
598
|
type ValidateStateNodeWithoutChildren<Node extends Machine.StateNodeConfig> = "initial" extends keyof Node ? StateDefinitionError<"Atomic states cannot declare an initial child"> : Node extends {
|
|
@@ -623,12 +635,32 @@ type StateFieldsValidation<Node> = Node extends {
|
|
|
623
635
|
readonly [Key in keyof Children]: StateFieldsValidation<Children[Key]>;
|
|
624
636
|
};
|
|
625
637
|
} : unknown);
|
|
626
|
-
|
|
638
|
+
/**
|
|
639
|
+
* Declaration of one state node accepted by {@link state}: its schema or
|
|
640
|
+
* fields, its kind, and its nested child states.
|
|
641
|
+
*
|
|
642
|
+
* **When to use**
|
|
643
|
+
*
|
|
644
|
+
* Name this type when a declaration you emit includes the signature of
|
|
645
|
+
* `Machine.state`. Build state trees with `Machine.state` itself, which checks
|
|
646
|
+
* the declaration further.
|
|
647
|
+
*
|
|
648
|
+
* **Details**
|
|
649
|
+
*
|
|
650
|
+
* Each entry of `states` is a tagged schema, a nested declaration, or a
|
|
651
|
+
* descriptor returned by `Machine.state`. `Machine.state` validates the whole
|
|
652
|
+
* tree further, so satisfying this type alone does not make a declaration
|
|
653
|
+
* valid.
|
|
654
|
+
*
|
|
655
|
+
* @category models
|
|
656
|
+
* @since 0.47.0
|
|
657
|
+
*/
|
|
658
|
+
export interface StateDeclaration {
|
|
627
659
|
readonly schema?: Machine.TaggedSchema;
|
|
628
660
|
readonly fields?: Schema.Struct.Fields;
|
|
629
661
|
readonly type?: "active" | "parallel" | "final" | "history" | "choice";
|
|
630
662
|
readonly initial?: string;
|
|
631
|
-
readonly states?: Readonly<Record<string, Machine.TaggedSchema |
|
|
663
|
+
readonly states?: Readonly<Record<string, Machine.TaggedSchema | StateDeclaration | {
|
|
632
664
|
readonly [StateTypeId]: typeof StateTypeId;
|
|
633
665
|
readonly node: Machine.StateNodeConfig;
|
|
634
666
|
}>>;
|
|
@@ -636,9 +668,9 @@ interface StateInput {
|
|
|
636
668
|
readonly output?: Schema.Top;
|
|
637
669
|
readonly annotations?: Machine.SchemaLessStateAnnotations;
|
|
638
670
|
}
|
|
639
|
-
|
|
640
|
-
<const Node extends
|
|
641
|
-
}
|
|
671
|
+
type StateConstructor = {
|
|
672
|
+
<const Node extends StateDeclaration>(node: Node & StateFieldsValidation<NoInfer<Node>>, ..._validation: ValidateDefinedState<NormalizeState<NoInfer<Node>>>): State<NormalizedState<Node>>;
|
|
673
|
+
};
|
|
642
674
|
type EventProtocolError<Message extends string, Tag extends PropertyKey = never> = {
|
|
643
675
|
readonly "~effect/Machine/EventProtocolError": Message;
|
|
644
676
|
readonly tag: Tag;
|
|
@@ -650,121 +682,9 @@ type DuplicateEventTag<Events extends ReadonlyArray<Machine.TaggedSchema>, Seen
|
|
|
650
682
|
type ValidateInputEventProtocol<InputEvents extends ReadonlyArray<Machine.TaggedSchema>, DuplicateInput extends PropertyKey = DuplicateEventTag<InputEvents>> = [DuplicateInput] extends [never] ? unknown : EventProtocolError<"Public event tags must be unique", DuplicateInput>;
|
|
651
683
|
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>;
|
|
652
684
|
type ValidateEventProtocolBuilder<Kind extends Machine.EventProtocolKind, Inputs extends ReadonlyArray<Machine.EventProtocolInput<Kind>>, Schemas extends ReadonlyArray<Machine.TaggedSchema> = Machine.EventProtocolInputSchemasOf<Kind, Inputs>, Duplicate extends PropertyKey = DuplicateEventTag<Schemas>> = [Duplicate] extends [never] ? unknown : EventProtocolError<"Event protocol tags must be unique", Duplicate>;
|
|
653
|
-
declare const SnapshotBuilderStateTypeId: typeof internal.SnapshotBuilderStateTypeId;
|
|
654
|
-
declare const SnapshotBuilderConstructionTypeId: unique symbol;
|
|
655
|
-
type SnapshotBuilderComplete<Regions, Constructed extends boolean = false> = {
|
|
656
|
-
readonly [SnapshotBuilderStateTypeId]: Regions;
|
|
657
|
-
readonly [SnapshotBuilderConstructionTypeId]: Constructed;
|
|
658
|
-
};
|
|
659
|
-
type FromCallable<Arguments extends ReadonlyArray<unknown>, Result> = Arguments extends readonly [infer Input, ...infer Rest extends ReadonlyArray<unknown>] ? {} extends Input ? {
|
|
660
|
-
(...args: Rest): Result;
|
|
661
|
-
(...args: Arguments): Result;
|
|
662
|
-
} : (...args: Arguments) => Result : (...args: Arguments) => Result;
|
|
663
|
-
type FromMethod<in out Arguments extends ReadonlyArray<unknown>, out Result> = {
|
|
664
|
-
/**
|
|
665
|
-
* Constructs the selected state from its schema make input while the
|
|
666
|
-
* machine plans the resulting configuration. The input may be omitted when
|
|
667
|
-
* the schema accepts an empty constructor object.
|
|
668
|
-
*
|
|
669
|
-
* @since 0.4.0
|
|
670
|
-
*/
|
|
671
|
-
readonly from: FromCallable<Arguments, Machine.StateConstruction<Result>>;
|
|
672
|
-
};
|
|
673
|
-
type DecodedMethod<Arguments extends ReadonlyArray<unknown>, Result> = {
|
|
674
|
-
/**
|
|
675
|
-
* Constructs the selected state from an already-decoded schema value. The
|
|
676
|
-
* machine validates the value against the schema's type side while planning.
|
|
677
|
-
*
|
|
678
|
-
* @since 0.22.0
|
|
679
|
-
*/
|
|
680
|
-
readonly decoded: (...args: Arguments) => Result;
|
|
681
|
-
};
|
|
682
|
-
type ConstructionResult<Result> = Result | Machine.StateConstruction<Result>;
|
|
683
|
-
type UnwrapConstruction<Result> = Result extends Machine.StateConstruction<infer Value> ? Value : Result;
|
|
684
685
|
type NodeValue<Node> = [Machine.NodeSchema<Node>] extends [never] ? undefined : Machine.NodeSchema<Node>["Type"];
|
|
685
686
|
type NodeMakeInput<Node> = [Machine.NodeSchema<Node>] extends [never] ? never : Machine.NodeSchema<Node>["~type.make.in"];
|
|
686
|
-
type WithNodeValue<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest : readonly [value: NodeValue<Node>, ...Rest];
|
|
687
|
-
type WithNodeInput<Node, Rest extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? Rest : readonly [input: NodeMakeInput<Node>, ...Rest];
|
|
688
|
-
type NodeBuilderMethod<Node, Arguments extends ReadonlyArray<unknown>, Result, FromArguments extends ReadonlyArray<unknown>, FromResult> = Machine.NodeSchema<Node> extends never ? {
|
|
689
|
-
readonly from: FromCallable<FromArguments, FromResult>;
|
|
690
|
-
} : DecodedMethod<Arguments, Result> & {
|
|
691
|
-
readonly from: FromCallable<FromArguments, FromResult>;
|
|
692
|
-
};
|
|
693
|
-
type NodeMethod<Node, Arguments extends ReadonlyArray<unknown>, Result, FromArguments extends ReadonlyArray<unknown>> = Machine.NodeSchema<Node> extends never ? FromMethod<FromArguments, Result> : DecodedMethod<Arguments, Result> & FromMethod<FromArguments, Result>;
|
|
694
|
-
type NodeMethodWithInitial<Node, Arguments extends ReadonlyArray<unknown>, Result, FromArguments extends ReadonlyArray<unknown>, Path extends string> = Machine.NodeSchema<Node> extends never ? {
|
|
695
|
-
readonly from: FromCallable<FromArguments, Machine.StateConstruction<Result>>;
|
|
696
|
-
readonly initial: InitialTargetFactory<Node, Path>;
|
|
697
|
-
} : DecodedMethod<Arguments, Result> & {
|
|
698
|
-
readonly from: FromCallable<FromArguments, Machine.StateConstruction<Result>>;
|
|
699
|
-
readonly initial: InitialTargetFactory<Node, Path>;
|
|
700
|
-
};
|
|
701
|
-
interface InitialTargetMethod<Node, Path extends string> {
|
|
702
|
-
/** Enters this state through its declared initial configuration. */
|
|
703
|
-
readonly initial: InitialTargetFactory<Node, Path>;
|
|
704
|
-
}
|
|
705
|
-
interface InitialTargetFactory<Node, Path extends string> {
|
|
706
|
-
readonly from: FromCallable<WithNodeInput<Node, readonly []>, Machine.StateConstruction<Machine.InitialTarget<Path>>>;
|
|
707
|
-
readonly decoded: (...args: WithNodeValue<Node, readonly []>) => Machine.InitialTarget<Path>;
|
|
708
|
-
}
|
|
709
|
-
type NodeConstructionSelectorFromCallable<Node, Builder, Result> = Machine.NodeSchema<Node> extends never ? {
|
|
710
|
-
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
711
|
-
} : ConstructionSelectorFromCallable<NodeMakeInput<Node>, Builder, Result>;
|
|
712
|
-
type NestedTargetMethod<Node, Builder, Result, Path extends string> = Machine.NodeSchema<Node> extends never ? {
|
|
713
|
-
readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>;
|
|
714
|
-
readonly initial: InitialTargetFactory<Node, Path>;
|
|
715
|
-
} : {
|
|
716
|
-
readonly decoded: <Selected extends ConstructionResult<Result>>(value: NodeValue<Node>, state: (builder: Builder) => Selected) => Selected;
|
|
717
|
-
readonly from: NodeConstructionSelectorFromCallable<Node, Builder, Result>;
|
|
718
|
-
readonly initial: InitialTargetFactory<Node, Path>;
|
|
719
|
-
};
|
|
720
|
-
type ConstructionSelectorFromCallable<Input, Builder, Result> = {} extends Input ? {
|
|
721
|
-
<Selected extends ConstructionResult<Result>>(state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
722
|
-
<Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected): Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
723
|
-
} : <Selected extends ConstructionResult<Result>>(input: Input, state: (builder: Builder) => Selected) => Machine.StateConstruction<UnwrapConstruction<Selected>>;
|
|
724
|
-
type FullSnapshotBuilderWithPrefix<in out States extends Machine.StateSchemas, in out Prefix extends string = ""> = {
|
|
725
|
-
readonly [Key in ActiveStateKey<States> | ChoiceStateKey<States>]: Key extends ActiveStateKey<States> ? FullSnapshotMethod<States, Key, Prefix> : () => Machine.ChoiceTargetInstruction<Machine.JoinPath<Prefix, Key>>;
|
|
726
|
-
};
|
|
727
|
-
type FullSnapshotMethod<in out States extends Machine.StateSchemas, in out StateId extends ActiveStateKey<States>, in out Prefix extends string> = {
|
|
728
|
-
readonly [
|
|
729
|
-
/** Constructs this node using schema make input or an already decoded value. */
|
|
730
|
-
Method in Machine.NodeSchema<States[StateId]> extends never ? "from" : "from" | "decoded"]: Method extends "from" ? FromCallable<FullSnapshotFromArguments<States, StateId, Prefix>, Machine.StateConstruction<FullSnapshotResult<States, StateId, Prefix>>> : (...args: FullSnapshotArguments<States, StateId, Prefix>) => FullSnapshotResult<States, StateId, Prefix>;
|
|
731
|
-
};
|
|
732
|
-
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 {
|
|
733
|
-
readonly type: "parallel";
|
|
734
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
735
|
-
} ? WithNodeValue<Node, [
|
|
736
|
-
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
737
|
-
]> : Node extends {
|
|
738
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
739
|
-
} ? WithNodeValue<Node, [
|
|
740
|
-
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>
|
|
741
|
-
]> : WithNodeValue<Node, []> : never;
|
|
742
|
-
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 {
|
|
743
|
-
readonly type: "parallel";
|
|
744
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
745
|
-
} ? WithNodeInput<Node, [
|
|
746
|
-
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
747
|
-
]> : Node extends {
|
|
748
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
749
|
-
} ? WithNodeInput<Node, [
|
|
750
|
-
state: (builder: FullSnapshotBuilderWithPrefix<Children, Path>) => ConstructionResult<Machine.SnapshotWithPrefix<Children, Path> | Machine.ChoiceTargetInstruction<Machine.ChoiceIdentifierWithPrefix<Children, Path>>>
|
|
751
|
-
]> : WithNodeInput<Node, []> : never;
|
|
752
687
|
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>;
|
|
753
|
-
type InitialEntryStateKey<States extends Machine.StateSchemas> = {
|
|
754
|
-
readonly [Key in ActiveStateKey<States>]: States[Key] extends {
|
|
755
|
-
readonly states: Machine.StateSchemas;
|
|
756
|
-
} ? Key : never;
|
|
757
|
-
}[ActiveStateKey<States>];
|
|
758
|
-
type FullInitialTargetBuilder<States extends Machine.StateSchemas> = {
|
|
759
|
-
readonly [Key in InitialEntryStateKey<States>]: InitialTargetMethod<States[Key], Key>;
|
|
760
|
-
};
|
|
761
|
-
type FullParallelBuilder<States extends Machine.StateSchemas, Prefix extends string, Remaining extends ActiveStateKey<States> = ActiveStateKey<States>, Regions = {}, Constructed extends boolean = false> = SnapshotBuilderComplete<Regions, Constructed> & {
|
|
762
|
-
readonly [Key in Remaining]: NodeBuilderMethod<States[Key], FullSnapshotArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
763
|
-
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
764
|
-
}, Constructed>, FullSnapshotFromArguments<States, Key, Prefix>, FullParallelBuilder<States, Prefix, Exclude<Remaining, Key>, Regions & {
|
|
765
|
-
readonly [Region in Key]: FullSnapshotResult<States, Key, Prefix>;
|
|
766
|
-
}, true>>;
|
|
767
|
-
};
|
|
768
688
|
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 {
|
|
769
689
|
readonly type: "parallel";
|
|
770
690
|
readonly states: infer Children extends Machine.StateSchemas;
|
|
@@ -778,89 +698,6 @@ type HistorySnapshotRegions<States extends Machine.StateSchemas, Prefix extends
|
|
|
778
698
|
readonly [Key in ActiveStateKey<States>]: Owner extends Machine.JoinPath<Prefix, Key> | (Machine.JoinPath<Prefix, Key> extends "" ? string : `${Machine.JoinPath<Prefix, Key>}.${string}`) ? HistorySnapshotResult<States, Key, Prefix, Owner> : FullSnapshotResult<States, Key, Prefix>;
|
|
779
699
|
};
|
|
780
700
|
type ParentPath<Path extends string> = Machine.ImmediateParentStateIdentifier<Path>;
|
|
781
|
-
type IsCompoundNode<Node> = Node extends {
|
|
782
|
-
readonly type: "parallel";
|
|
783
|
-
} ? false : Node extends {
|
|
784
|
-
readonly states: Machine.StateSchemas;
|
|
785
|
-
} ? true : false;
|
|
786
|
-
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;
|
|
787
|
-
type ChildrenOf<States extends Machine.StateSchemas, Path extends Machine.StateIdentifier<States>> = Machine.NodeByIdentifier<States, Path> extends {
|
|
788
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
789
|
-
} ? Children : never;
|
|
790
|
-
type StateIdentifierFromPath<States extends Machine.StateSchemas, Path extends string> = Extract<Path, Machine.StateIdentifier<States>>;
|
|
791
|
-
type LocalTargetResult<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends {
|
|
792
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
793
|
-
} ? States[StateId] extends {
|
|
794
|
-
readonly type: "parallel";
|
|
795
|
-
} ? Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>> : LocalTargetResultWithPrefix<AllStates, Children, Path> : Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>;
|
|
796
|
-
type LocalTargetResultWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
797
|
-
readonly [Key in ActiveStateKey<States>]: LocalTargetResult<AllStates, States, Key, Prefix>;
|
|
798
|
-
}[ActiveStateKey<States>] | Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
799
|
-
type LocalTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>> = {
|
|
800
|
-
readonly [Key in ActiveStateKey<States>]: LocalTargetMethod<AllStates, States, Key, Prefix, Source>;
|
|
801
|
-
} & {
|
|
802
|
-
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
803
|
-
};
|
|
804
|
-
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 {
|
|
805
|
-
readonly type: "parallel";
|
|
806
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
807
|
-
} ? Source extends Path | (Path extends "" ? string : `${Path}.${string}`) ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>, Path> : NodeMethodWithInitial<Node, WithNodeValue<Node, [
|
|
808
|
-
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
809
|
-
]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
|
|
810
|
-
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
811
|
-
]>, Path> : Node extends {
|
|
812
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
813
|
-
} ? NestedTargetMethod<Node, LocalTargetBuilderWithPrefix<AllStates, Children, Path, Source>, LocalTargetResultWithPrefix<AllStates, Children, Path>, Path> : NodeMethod<Node, WithNodeValue<Node, []>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, []>> : never;
|
|
814
|
-
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> & (Scope extends Machine.ValuedStateIdentifier<States> ? {
|
|
815
|
-
/**
|
|
816
|
-
* Updates the value of the state containing the local group and moves to
|
|
817
|
-
* one of the states inside it. Values in other active branches are kept.
|
|
818
|
-
*
|
|
819
|
-
* @since 0.4.0
|
|
820
|
-
*/
|
|
821
|
-
readonly with: {
|
|
822
|
-
readonly decoded: <Result extends ConstructionResult<LocalTargetResultWithPrefix<States, Children, Scope>>>(value: Machine.StateByIdentifier<States, Scope>, state: (builder: LocalTargetBuilderWithPrefix<States, Children, Scope, Source>) => Result) => Result;
|
|
823
|
-
readonly from: ConstructionSelectorFromCallable<Machine.SchemaByIdentifier<States, Scope>["~type.make.in"], LocalTargetBuilderWithPrefix<States, Children, Scope, Source>, LocalTargetResultWithPrefix<States, Children, Scope>>;
|
|
824
|
-
};
|
|
825
|
-
} : {}) : {};
|
|
826
|
-
type BranchTargetResult<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, StateId extends ActiveStateKey<States>, Prefix extends string, Path extends string = Machine.JoinPath<Prefix, StateId>> = States[StateId] extends {
|
|
827
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
828
|
-
} ? States[StateId] extends {
|
|
829
|
-
readonly type: "parallel";
|
|
830
|
-
} ? Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>> : BranchTargetResultWithPrefix<AllStates, Children, Path> : Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>;
|
|
831
|
-
type BranchTargetResultWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
832
|
-
readonly [Key in ActiveStateKey<States>]: BranchTargetResult<AllStates, States, Key, Prefix>;
|
|
833
|
-
}[ActiveStateKey<States>] | Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, ChoiceStateKey<States>>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
834
|
-
type BranchTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string, Source extends Machine.StateNodeIdentifier<AllStates>> = {
|
|
835
|
-
readonly [Key in ActiveStateKey<States>]: BranchTargetMethod<AllStates, States, Key, Prefix, Source>;
|
|
836
|
-
} & {
|
|
837
|
-
readonly [Key in ChoiceStateKey<States>]: () => Machine.ChoiceTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.ChoiceIdentifier<AllStates>>>;
|
|
838
|
-
};
|
|
839
|
-
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 {
|
|
840
|
-
readonly type: "parallel";
|
|
841
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
842
|
-
} ? Source extends Path | (Path extends "" ? string : `${Path}.${string}`) ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>, Path> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethodWithInitial<Node, WithNodeValue<Node, [
|
|
843
|
-
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>>
|
|
844
|
-
]>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, [
|
|
845
|
-
states: (builder: FullParallelBuilder<Children, Path>) => SnapshotBuilderComplete<Machine.SnapshotRegionsWithPrefix<Children, Path>, boolean>
|
|
846
|
-
]>, Path> : Node extends {
|
|
847
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
848
|
-
} ? NestedTargetMethod<Node, BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source>, BranchTargetResultWithPrefix<AllStates, Children, Path>, Path> & BranchTargetBuilderWithPrefix<AllStates, Children, Path, Source> : NodeMethod<Node, WithNodeValue<Node, []>, Machine.Target<AllStates, StateIdentifierFromPath<AllStates, Path>>, WithNodeInput<Node, []>> : never;
|
|
849
|
-
type BranchTargetBuilderForRoot<States extends Machine.StateSchemas, Root extends ActiveStateKey<States>, Source extends Machine.StateNodeIdentifier<States>> = {
|
|
850
|
-
readonly [Key in Root]: BranchTargetMethod<States, States, Key, "", Source>;
|
|
851
|
-
};
|
|
852
|
-
type HistoryContainingKey<States extends Machine.StateSchemas> = {
|
|
853
|
-
readonly [Key in Extract<keyof States, string>]: States[Key] extends Machine.HistoryStateNodeConfig ? Key : States[Key] extends {
|
|
854
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
855
|
-
} ? [
|
|
856
|
-
Machine.HistoryIdentifier<Children>
|
|
857
|
-
] extends [never] ? never : Key : never;
|
|
858
|
-
}[Extract<keyof States, string>];
|
|
859
|
-
type HistoryTargetBuilderWithPrefix<AllStates extends Machine.StateSchemas, States extends Machine.StateSchemas, Prefix extends string> = {
|
|
860
|
-
readonly [Key in HistoryContainingKey<States>]: States[Key] extends Machine.HistoryStateNodeConfig ? () => Machine.HistoryTarget<AllStates, Extract<Machine.JoinPath<Prefix, Key>, Machine.HistoryIdentifier<AllStates>>> : States[Key] extends {
|
|
861
|
-
readonly states: infer Children extends Machine.StateSchemas;
|
|
862
|
-
} ? HistoryTargetBuilderWithPrefix<AllStates, Children, Machine.JoinPath<Prefix, Key>> : never;
|
|
863
|
-
};
|
|
864
701
|
type HasDirectShallowHistory<States extends Machine.StateSchemas> = {
|
|
865
702
|
readonly [Key in HistoryStateKey<States>]: States[Key] extends {
|
|
866
703
|
readonly history: "deep";
|
|
@@ -891,7 +728,7 @@ type SpawnIdError<Options extends SpawnOptions> = "id" extends keyof Options ? O
|
|
|
891
728
|
readonly id?: infer Id;
|
|
892
729
|
} ? [Id] extends [undefined] ? never : ChildAlreadyExistsError : ChildAlreadyExistsError : never;
|
|
893
730
|
type SpawnError<Options extends SpawnOptions> = SpawnIdError<Options>;
|
|
894
|
-
type SpawnResult<State, Event, Error, Requirements, Output, SpawnError, InitialError = never> = Effect.Effect<MachineRef<State, Event, Error, Output>, SpawnError | InitialError,
|
|
731
|
+
type SpawnResult<State, Event, Error, Requirements, Output, SpawnError, InitialError = never> = Effect.Effect<MachineRef<State, Event, Error, Output>, SpawnError | InitialError, MachineRuntime | SpawnRequirements<Requirements>>;
|
|
895
732
|
/**
|
|
896
733
|
* Represents the active or terminal lifecycle state of a running machine.
|
|
897
734
|
*
|
|
@@ -1316,10 +1153,11 @@ type InvokeLifecycleId = string & {
|
|
|
1316
1153
|
*
|
|
1317
1154
|
* **Details**
|
|
1318
1155
|
*
|
|
1319
|
-
* The descriptor carries the child's address and complete machine type.
|
|
1320
|
-
*
|
|
1321
|
-
*
|
|
1322
|
-
* without separate
|
|
1156
|
+
* The descriptor carries the child's address and complete machine type.
|
|
1157
|
+
* Register it in `make({ children })` to invoke it by `src`, and pass a
|
|
1158
|
+
* descriptor for the same id and machine to `sendTo` and child lookup APIs, so
|
|
1159
|
+
* state, event, error, and output types are inferred without separate
|
|
1160
|
+
* annotations.
|
|
1323
1161
|
*
|
|
1324
1162
|
* @category models
|
|
1325
1163
|
* @since 0.4.0
|
|
@@ -1330,8 +1168,8 @@ export interface ChildMachine<Id extends string, M extends Machine.Any> {
|
|
|
1330
1168
|
readonly id: Id;
|
|
1331
1169
|
/** Complete machine definition carried by this descriptor. */
|
|
1332
1170
|
readonly machine: M;
|
|
1333
|
-
/** @internal */
|
|
1334
|
-
readonly [ChildMachineLogicTypeId]:
|
|
1171
|
+
/** @internal Brand of descriptors built by `child` and `childFamily`. */
|
|
1172
|
+
readonly [ChildMachineLogicTypeId]: typeof ChildMachineLogicTypeId;
|
|
1335
1173
|
}
|
|
1336
1174
|
/**
|
|
1337
1175
|
* Namespace containing type-level members associated with `ChildMachine`.
|
|
@@ -1408,7 +1246,7 @@ export declare namespace ChildMachine {
|
|
|
1408
1246
|
* @category utility types
|
|
1409
1247
|
* @since 0.20.0
|
|
1410
1248
|
*/
|
|
1411
|
-
type StartRequirements<Child extends Any> = Child extends ChildMachine<string, infer M> ? Exclude<ExcludeCompatibleRuntime<Exclude<ExecutionServices<Machine.InitialServices<M> | Machine.Services<M>>,
|
|
1249
|
+
type StartRequirements<Child extends Any> = Child extends ChildMachine<string, infer M> ? Exclude<ExcludeCompatibleRuntime<Exclude<ExecutionServices<Machine.InitialServices<M> | Machine.Services<M>>, MachineRuntime>, Machine.Event<M>, Machine.EmittedEvent<M>>, Scope.Scope> : never;
|
|
1412
1250
|
/**
|
|
1413
1251
|
* Running machine reference selected by a child descriptor.
|
|
1414
1252
|
*
|
|
@@ -1506,15 +1344,6 @@ export declare namespace ChildAddress {
|
|
|
1506
1344
|
export interface SpawnOptions {
|
|
1507
1345
|
readonly id?: string;
|
|
1508
1346
|
}
|
|
1509
|
-
/**
|
|
1510
|
-
* Options for spawning child processes with a parent-local id.
|
|
1511
|
-
*
|
|
1512
|
-
* @category models
|
|
1513
|
-
* @since 0.4.0
|
|
1514
|
-
*/
|
|
1515
|
-
export interface SpawnIdOptions extends SpawnOptions {
|
|
1516
|
-
readonly id: string;
|
|
1517
|
-
}
|
|
1518
1347
|
/**
|
|
1519
1348
|
* Namespace containing type-level members associated with `Machine`.
|
|
1520
1349
|
*
|
|
@@ -1527,7 +1356,7 @@ export declare namespace Machine {
|
|
|
1527
1356
|
*
|
|
1528
1357
|
* @internal
|
|
1529
1358
|
*/
|
|
1530
|
-
interface TypeCarrier<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, Emits extends ReadonlyArray<TaggedSchema>, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> {
|
|
1359
|
+
export interface TypeCarrier<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Input extends Schema.Top, UnhandledStates extends StateIdentifier<States>, E, R, InitialE, InitialR, FinalStates extends StateIdentifier<States>, Output, Emits extends ReadonlyArray<TaggedSchema>, OutputStates extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema>, ParentEvents extends ReadonlyArray<TaggedSchema>> {
|
|
1531
1360
|
readonly states: States;
|
|
1532
1361
|
readonly events: Events;
|
|
1533
1362
|
readonly input: Input;
|
|
@@ -1544,17 +1373,17 @@ export declare namespace Machine {
|
|
|
1544
1373
|
readonly parentEvents: ParentEvents;
|
|
1545
1374
|
}
|
|
1546
1375
|
/** @internal Carries parent availability without widening the event tuple. */
|
|
1547
|
-
type ParentEventSchemas<Mode extends ParentMode, Events extends ReadonlyArray<TaggedSchema>> = Events & {
|
|
1376
|
+
export type ParentEventSchemas<Mode extends ParentMode, Events extends ReadonlyArray<TaggedSchema>> = Events & {
|
|
1548
1377
|
readonly [ParentModeTypeId]: Mode;
|
|
1549
1378
|
};
|
|
1550
1379
|
/** Extracts the parent availability encoded in a machine event tuple. */
|
|
1551
|
-
type ParentModeOf<Events extends ReadonlyArray<TaggedSchema>> = Events extends {
|
|
1380
|
+
export type ParentModeOf<Events extends ReadonlyArray<TaggedSchema>> = Events extends {
|
|
1552
1381
|
readonly [ParentModeTypeId]: infer Mode extends ParentMode;
|
|
1553
1382
|
} ? Mode : Events extends readonly [] ? "none" : "optional";
|
|
1554
1383
|
/** Extracts the event schemas declared by an owning-machine protocol. */
|
|
1555
|
-
type ParentEventsOf<Declaration extends Parent.Any | undefined> = Declaration extends Parent<infer Mode, infer Events> ? ParentEventSchemas<Mode, Events> : readonly [];
|
|
1384
|
+
export type ParentEventsOf<Declaration extends Parent.Any | undefined> = Declaration extends Parent<infer Mode, infer Events> ? ParentEventSchemas<Mode, Events> : readonly [];
|
|
1556
1385
|
/** Extracts the owning-machine declaration carried by a machine. */
|
|
1557
|
-
type ParentDeclarationOf<Events extends ReadonlyArray<TaggedSchema>> = ParentModeOf<Events> extends infer Mode ? Mode extends ParentMode ? Parent<Mode, Events> : undefined : never;
|
|
1386
|
+
export type ParentDeclarationOf<Events extends ReadonlyArray<TaggedSchema>> = ParentModeOf<Events> extends infer Mode ? Mode extends ParentMode ? Parent<Mode, Events> : undefined : never;
|
|
1558
1387
|
/**
|
|
1559
1388
|
* Constraint applied to APIs that create an independent root runtime.
|
|
1560
1389
|
*
|
|
@@ -1568,7 +1397,7 @@ export declare namespace Machine {
|
|
|
1568
1397
|
* @category utility types
|
|
1569
1398
|
* @since 0.27.0
|
|
1570
1399
|
*/
|
|
1571
|
-
type RootCompatible<Events extends ReadonlyArray<TaggedSchema>> = ParentModeOf<Events> extends "required" ? RootCompatibilityError<"Machine declares a required parent and cannot run as a root; invoke or spawn it from an owning machine"> : unknown;
|
|
1400
|
+
export type RootCompatible<Events extends ReadonlyArray<TaggedSchema>> = ParentModeOf<Events> extends "required" ? RootCompatibilityError<"Machine declares a required parent and cannot run as a root; invoke or spawn it from an owning machine"> : unknown;
|
|
1572
1401
|
/**
|
|
1573
1402
|
* Any schema-first machine.
|
|
1574
1403
|
*
|
|
@@ -1581,7 +1410,7 @@ export declare namespace Machine {
|
|
|
1581
1410
|
* @category models
|
|
1582
1411
|
* @since 0.4.0
|
|
1583
1412
|
*/
|
|
1584
|
-
interface Any extends Pipeable {
|
|
1413
|
+
export interface Any extends Pipeable {
|
|
1585
1414
|
readonly [TypeId]: TypeId;
|
|
1586
1415
|
/** @internal */
|
|
1587
1416
|
readonly [MachineTypeId]: TypeCarrier<any, any, any, any, any, any, any, any, any, any, any, any, any, any>;
|
|
@@ -1608,21 +1437,21 @@ export declare namespace Machine {
|
|
|
1608
1437
|
* @category utility types
|
|
1609
1438
|
* @since 0.4.0
|
|
1610
1439
|
*/
|
|
1611
|
-
type States<M extends Any> = M[typeof MachineTypeId]["states"];
|
|
1440
|
+
export type States<M extends Any> = M[typeof MachineTypeId]["states"];
|
|
1612
1441
|
/**
|
|
1613
1442
|
* Extracts the complete event schema tuple carried by a machine definition.
|
|
1614
1443
|
*
|
|
1615
1444
|
* @category utility types
|
|
1616
1445
|
* @since 0.4.0
|
|
1617
1446
|
*/
|
|
1618
|
-
type Events<M extends Any> = M[typeof MachineTypeId]["events"];
|
|
1447
|
+
export type Events<M extends Any> = M[typeof MachineTypeId]["events"];
|
|
1619
1448
|
/**
|
|
1620
1449
|
* Extracts the startup input schema carried by a machine definition.
|
|
1621
1450
|
*
|
|
1622
1451
|
* @category utility types
|
|
1623
1452
|
* @since 0.18.0
|
|
1624
1453
|
*/
|
|
1625
|
-
type InputSchema<M extends Any> = M[typeof MachineTypeId]["input"];
|
|
1454
|
+
export type InputSchema<M extends Any> = M[typeof MachineTypeId]["input"];
|
|
1626
1455
|
/**
|
|
1627
1456
|
* Extracts the decoded startup input accepted by a machine definition.
|
|
1628
1457
|
*
|
|
@@ -1632,102 +1461,102 @@ export declare namespace Machine {
|
|
|
1632
1461
|
* @category utility types
|
|
1633
1462
|
* @since 0.18.0
|
|
1634
1463
|
*/
|
|
1635
|
-
type Input<M extends Any> = InputSchema<M> extends infer Input extends Schema.Top ? Input extends typeof Schema.Void ? never : Input["Type"] : never;
|
|
1464
|
+
export type Input<M extends Any> = InputSchema<M> extends infer Input extends Schema.Top ? Input extends typeof Schema.Void ? never : Input["Type"] : never;
|
|
1636
1465
|
/**
|
|
1637
1466
|
* Extracts state paths that do not yet have handlers.
|
|
1638
1467
|
*
|
|
1639
1468
|
* @category utility types
|
|
1640
1469
|
* @since 0.4.0
|
|
1641
1470
|
*/
|
|
1642
|
-
type UnhandledStates<M extends Any> = M[typeof MachineTypeId]["unhandledStates"];
|
|
1471
|
+
export type UnhandledStates<M extends Any> = M[typeof MachineTypeId]["unhandledStates"];
|
|
1643
1472
|
/**
|
|
1644
1473
|
* Extracts the runtime error channel carried by a machine definition.
|
|
1645
1474
|
*
|
|
1646
1475
|
* @category utility types
|
|
1647
1476
|
* @since 0.4.0
|
|
1648
1477
|
*/
|
|
1649
|
-
type Error<M extends Any> = M[typeof MachineTypeId]["error"];
|
|
1478
|
+
export type Error<M extends Any> = M[typeof MachineTypeId]["error"];
|
|
1650
1479
|
/**
|
|
1651
1480
|
* Extracts runtime service requirements carried by a machine definition.
|
|
1652
1481
|
*
|
|
1653
1482
|
* @category utility types
|
|
1654
1483
|
* @since 0.4.0
|
|
1655
1484
|
*/
|
|
1656
|
-
type Services<M extends Any> = M[typeof MachineTypeId]["services"];
|
|
1485
|
+
export type Services<M extends Any> = M[typeof MachineTypeId]["services"];
|
|
1657
1486
|
/**
|
|
1658
1487
|
* Extracts the startup error channel carried by a machine definition.
|
|
1659
1488
|
*
|
|
1660
1489
|
* @category utility types
|
|
1661
1490
|
* @since 0.4.0
|
|
1662
1491
|
*/
|
|
1663
|
-
type InitialError<M extends Any> = M[typeof MachineTypeId]["initialError"];
|
|
1492
|
+
export type InitialError<M extends Any> = M[typeof MachineTypeId]["initialError"];
|
|
1664
1493
|
/**
|
|
1665
1494
|
* Extracts startup service requirements carried by a machine definition.
|
|
1666
1495
|
*
|
|
1667
1496
|
* @category utility types
|
|
1668
1497
|
* @since 0.4.0
|
|
1669
1498
|
*/
|
|
1670
|
-
type InitialServices<M extends Any> = M[typeof MachineTypeId]["initialServices"];
|
|
1499
|
+
export type InitialServices<M extends Any> = M[typeof MachineTypeId]["initialServices"];
|
|
1671
1500
|
/**
|
|
1672
1501
|
* Extracts final state paths carried by a machine definition.
|
|
1673
1502
|
*
|
|
1674
1503
|
* @category utility types
|
|
1675
1504
|
* @since 0.4.0
|
|
1676
1505
|
*/
|
|
1677
|
-
type FinalStates<M extends Any> = M[typeof MachineTypeId]["finalStates"];
|
|
1506
|
+
export type FinalStates<M extends Any> = M[typeof MachineTypeId]["finalStates"];
|
|
1678
1507
|
/**
|
|
1679
1508
|
* Extracts the terminal output channel carried by a machine definition.
|
|
1680
1509
|
*
|
|
1681
1510
|
* @category utility types
|
|
1682
1511
|
* @since 0.4.0
|
|
1683
1512
|
*/
|
|
1684
|
-
type Output<M extends Any> = M[typeof MachineTypeId]["output"];
|
|
1513
|
+
export type Output<M extends Any> = M[typeof MachineTypeId]["output"];
|
|
1685
1514
|
/**
|
|
1686
1515
|
* Extracts the emitted event schema tuple carried by a machine definition.
|
|
1687
1516
|
*
|
|
1688
1517
|
* @category utility types
|
|
1689
1518
|
* @since 0.4.0
|
|
1690
1519
|
*/
|
|
1691
|
-
type EmittedEvents<M extends Any> = M[typeof MachineTypeId]["emittedEvents"];
|
|
1520
|
+
export type EmittedEvents<M extends Any> = M[typeof MachineTypeId]["emittedEvents"];
|
|
1692
1521
|
/**
|
|
1693
1522
|
* Extracts state paths with implemented output handlers.
|
|
1694
1523
|
*
|
|
1695
1524
|
* @category utility types
|
|
1696
1525
|
* @since 0.4.0
|
|
1697
1526
|
*/
|
|
1698
|
-
type OutputStates<M extends Any> = M[typeof MachineTypeId]["outputStates"];
|
|
1527
|
+
export type OutputStates<M extends Any> = M[typeof MachineTypeId]["outputStates"];
|
|
1699
1528
|
/**
|
|
1700
1529
|
* Extracts the public input event schema tuple carried by a machine definition.
|
|
1701
1530
|
*
|
|
1702
1531
|
* @category utility types
|
|
1703
1532
|
* @since 0.4.0
|
|
1704
1533
|
*/
|
|
1705
|
-
type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"];
|
|
1534
|
+
export type InputEvents<M extends Any> = M[typeof MachineTypeId]["inputEvents"];
|
|
1706
1535
|
/** Extracts the public input protocol required from an owning machine. */
|
|
1707
|
-
type ParentEvents<M extends Any> = M[typeof MachineTypeId]["parentEvents"];
|
|
1536
|
+
export type ParentEvents<M extends Any> = M[typeof MachineTypeId]["parentEvents"];
|
|
1708
1537
|
/** Extracts whether a machine requires or optionally accepts an owner. */
|
|
1709
|
-
type ParentAvailability<M extends Any> = ParentModeOf<M[typeof MachineTypeId]["parentEvents"]>;
|
|
1538
|
+
export type ParentAvailability<M extends Any> = ParentModeOf<M[typeof MachineTypeId]["parentEvents"]>;
|
|
1710
1539
|
/** Extracts an internal event schema tuple from the complete and public protocols. */
|
|
1711
|
-
type InternalEventSchemas<Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>> = Events extends readonly [
|
|
1540
|
+
export type InternalEventSchemas<Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>> = Events extends readonly [
|
|
1712
1541
|
...InputEvents,
|
|
1713
1542
|
...infer Internal extends ReadonlyArray<TaggedSchema>
|
|
1714
1543
|
] ? readonly [...Internal] : readonly [];
|
|
1715
1544
|
/** Extracts the internal event schema tuple carried by a machine definition. */
|
|
1716
|
-
type InternalEvents<M extends Any> = InternalEventSchemas<Events<M>, InputEvents<M>>;
|
|
1545
|
+
export type InternalEvents<M extends Any> = InternalEventSchemas<Events<M>, InputEvents<M>>;
|
|
1717
1546
|
/**
|
|
1718
1547
|
* Extracts the complete event protocol handled inside a machine.
|
|
1719
1548
|
*
|
|
1720
1549
|
* @category utility types
|
|
1721
1550
|
* @since 0.4.0
|
|
1722
1551
|
*/
|
|
1723
|
-
type Event<M extends Any> = EventOf<Events<M>>;
|
|
1552
|
+
export type Event<M extends Any> = EventOf<Events<M>>;
|
|
1724
1553
|
/**
|
|
1725
1554
|
* Extracts the event protocol accepted by public machine input boundaries.
|
|
1726
1555
|
*
|
|
1727
1556
|
* @category utility types
|
|
1728
1557
|
* @since 0.4.0
|
|
1729
1558
|
*/
|
|
1730
|
-
type InputEvent<M extends Any> = EventOf<InputEvents<M>>;
|
|
1559
|
+
export type InputEvent<M extends Any> = EventOf<InputEvents<M>>;
|
|
1731
1560
|
/**
|
|
1732
1561
|
* Opaque event construction returned by {@link events} and
|
|
1733
1562
|
* {@link internalEvents}.
|
|
@@ -1735,32 +1564,44 @@ export declare namespace Machine {
|
|
|
1735
1564
|
* The machine resolves the instruction through its event schema when it is
|
|
1736
1565
|
* delivered. Only the discriminator is available before decoding succeeds.
|
|
1737
1566
|
*/
|
|
1738
|
-
interface EventConstruction<out Event extends {
|
|
1567
|
+
export interface EventConstruction<out Event extends {
|
|
1739
1568
|
readonly _tag: PropertyKey;
|
|
1740
1569
|
}> {
|
|
1741
1570
|
readonly [EventConstructionTypeId]: Event;
|
|
1742
1571
|
readonly _tag: Event["_tag"];
|
|
1743
1572
|
}
|
|
1744
1573
|
/** Opaque construction returned by {@link emittedEvents}. */
|
|
1745
|
-
interface EmittedEventConstruction<out Event extends {
|
|
1574
|
+
export interface EmittedEventConstruction<out Event extends {
|
|
1746
1575
|
readonly _tag: PropertyKey;
|
|
1747
1576
|
}> {
|
|
1748
1577
|
readonly [EmittedEventConstructionTypeId]: Event;
|
|
1749
1578
|
readonly _tag: Event["_tag"];
|
|
1750
1579
|
}
|
|
1751
1580
|
/** A decoded event or a deferred machine-bound construction of that event. */
|
|
1752
|
-
type EventInput<Event> = Event | (Event extends {
|
|
1581
|
+
export type EventInput<Event> = Event | (Event extends {
|
|
1753
1582
|
readonly _tag: PropertyKey;
|
|
1754
1583
|
} ? EventConstruction<Event> : never);
|
|
1755
1584
|
/** A decoded emitted event or a deferred emitted-event construction. */
|
|
1756
|
-
type EmittedEventInput<Event> = Event | (Event extends {
|
|
1585
|
+
export type EmittedEventInput<Event> = Event | (Event extends {
|
|
1757
1586
|
readonly _tag: PropertyKey;
|
|
1758
1587
|
} ? EmittedEventConstruction<Event> : never);
|
|
1759
1588
|
/** Event inputs accepted for a schema tuple at machine delivery boundaries. */
|
|
1760
|
-
type EventInputOf<Events extends ReadonlyArray<TaggedSchema>> = EventInput<EventOf<Events>>;
|
|
1589
|
+
export type EventInputOf<Events extends ReadonlyArray<TaggedSchema>> = EventInput<EventOf<Events>>;
|
|
1761
1590
|
/** Identifies whether an event protocol is accepted publicly or only inside a machine. */
|
|
1762
|
-
type EventProtocolKind = "public" | "internal" | "emitted";
|
|
1763
|
-
|
|
1591
|
+
export type EventProtocolKind = "public" | "internal" | "emitted";
|
|
1592
|
+
/**
|
|
1593
|
+
* Fields accepted by the constructor of one event in an event protocol.
|
|
1594
|
+
*
|
|
1595
|
+
* **Details**
|
|
1596
|
+
*
|
|
1597
|
+
* The input is the event schema's constructor input without `_tag`, which
|
|
1598
|
+
* the constructor supplies. When every field is optional, so is the
|
|
1599
|
+
* constructor's argument.
|
|
1600
|
+
*
|
|
1601
|
+
* @category utility types
|
|
1602
|
+
* @since 0.23.0
|
|
1603
|
+
*/
|
|
1604
|
+
export type EventConstructorInput<EventSchema extends TaggedSchema> = Omit<EventSchema["~type.make.in"], "_tag">;
|
|
1764
1605
|
type EventConstructor<EventSchema extends TaggedSchema, Tag extends EventSchema["Type"]["_tag"], Kind extends EventProtocolKind> = {} extends EventConstructorInput<EventSchema> ? (input?: EventConstructorInput<EventSchema>) => Kind extends "emitted" ? EmittedEventConstruction<EventByTag<readonly [EventSchema], Tag>> : EventConstruction<EventByTag<readonly [EventSchema], Tag>> : (input: EventConstructorInput<EventSchema>) => Kind extends "emitted" ? EmittedEventConstruction<EventByTag<readonly [EventSchema], Tag>> : EventConstruction<EventByTag<readonly [EventSchema], Tag>>;
|
|
1765
1606
|
type FiniteEventTag<Tag extends PropertyKey> = string extends Tag ? never : number extends Tag ? never : symbol extends Tag ? never : Tag;
|
|
1766
1607
|
type EventConstructorsForSchema<EventSchema extends TaggedSchema, Kind extends EventProtocolKind> = EventSchema extends {
|
|
@@ -1773,7 +1614,7 @@ export declare namespace Machine {
|
|
|
1773
1614
|
readonly [Tag in FiniteEventTag<EventSchema["Type"]["_tag"]>]: EventConstructor<EventSchema, Tag, Kind>;
|
|
1774
1615
|
};
|
|
1775
1616
|
/** Protocol-bound constructors keyed by each configured event tag. */
|
|
1776
|
-
type EventConstructors<Events extends ReadonlyArray<TaggedSchema>, Kind extends EventProtocolKind = "public"> = {
|
|
1617
|
+
export type EventConstructors<Events extends ReadonlyArray<TaggedSchema>, Kind extends EventProtocolKind = "public"> = {
|
|
1777
1618
|
readonly [Tag in keyof Types.UnionToIntersection<EventConstructorsForSchema<Events[number], Kind>>]: Types.UnionToIntersection<EventConstructorsForSchema<Events[number], Kind>>[Tag];
|
|
1778
1619
|
};
|
|
1779
1620
|
/**
|
|
@@ -1784,13 +1625,13 @@ export declare namespace Machine {
|
|
|
1784
1625
|
*
|
|
1785
1626
|
* @since 0.10.0
|
|
1786
1627
|
*/
|
|
1787
|
-
type EventProtocol<Kind extends EventProtocolKind, Schemas extends ReadonlyArray<TaggedSchema>> = EventConstructors<Schemas, Kind> & {
|
|
1628
|
+
export type EventProtocol<Kind extends EventProtocolKind, Schemas extends ReadonlyArray<TaggedSchema>> = EventConstructors<Schemas, Kind> & {
|
|
1788
1629
|
readonly [EventProtocolTypeId]: {
|
|
1789
1630
|
readonly kind: Kind;
|
|
1790
1631
|
readonly schemas: Schemas;
|
|
1791
1632
|
};
|
|
1792
1633
|
};
|
|
1793
|
-
namespace EventProtocol {
|
|
1634
|
+
export namespace EventProtocol {
|
|
1794
1635
|
/** An erased event protocol descriptor retaining its kind and schema carrier. */
|
|
1795
1636
|
interface Any<Kind extends EventProtocolKind = EventProtocolKind> {
|
|
1796
1637
|
readonly [EventProtocolTypeId]: {
|
|
@@ -1799,23 +1640,23 @@ export declare namespace Machine {
|
|
|
1799
1640
|
};
|
|
1800
1641
|
}
|
|
1801
1642
|
}
|
|
1802
|
-
/** A schema or an existing protocol accepted by
|
|
1803
|
-
type EventProtocolInput<Kind extends EventProtocolKind> = TaggedSchema | EventProtocol.Any<Kind>;
|
|
1643
|
+
/** A schema or an existing protocol accepted by `eventsFromSchemas` and its internal and emitted counterparts. */
|
|
1644
|
+
export type EventProtocolInput<Kind extends EventProtocolKind> = TaggedSchema | EventProtocol.Any<Kind>;
|
|
1804
1645
|
type EventProtocolInputSchemas<Kind extends EventProtocolKind, Input extends EventProtocolInput<Kind>> = Input extends EventProtocol<Kind, infer Schemas> ? Schemas : Input extends TaggedSchema ? readonly [Input] : readonly [];
|
|
1805
1646
|
/** Flattens schema and protocol inputs into one owned schema tuple. */
|
|
1806
|
-
type EventProtocolInputSchemasOf<Kind extends EventProtocolKind, Inputs extends ReadonlyArray<EventProtocolInput<Kind>>> = Inputs extends readonly [
|
|
1647
|
+
export type EventProtocolInputSchemasOf<Kind extends EventProtocolKind, Inputs extends ReadonlyArray<EventProtocolInput<Kind>>> = Inputs extends readonly [
|
|
1807
1648
|
infer Head extends EventProtocolInput<Kind>,
|
|
1808
1649
|
...infer Tail extends ReadonlyArray<EventProtocolInput<Kind>>
|
|
1809
1650
|
] ? readonly [...EventProtocolInputSchemas<Kind, Head>, ...EventProtocolInputSchemasOf<Kind, Tail>] : readonly [];
|
|
1810
1651
|
/** @internal Extracts the schema tuple carried opaquely by an event protocol. */
|
|
1811
|
-
type EventProtocolSchemas<Protocol extends EventProtocol.Any> = Protocol[typeof EventProtocolTypeId]["schemas"];
|
|
1652
|
+
export type EventProtocolSchemas<Protocol extends EventProtocol.Any> = Protocol[typeof EventProtocolTypeId]["schemas"];
|
|
1812
1653
|
/**
|
|
1813
1654
|
* Extracts the event protocol emitted by a machine.
|
|
1814
1655
|
*
|
|
1815
1656
|
* @category utility types
|
|
1816
1657
|
* @since 0.4.0
|
|
1817
1658
|
*/
|
|
1818
|
-
type EmittedEvent<M extends Any> = EmittedEventOf<EmittedEvents<M>>;
|
|
1659
|
+
export type EmittedEvent<M extends Any> = EmittedEventOf<EmittedEvents<M>>;
|
|
1819
1660
|
/**
|
|
1820
1661
|
* A schema whose decoded value contains a `_tag` discriminator.
|
|
1821
1662
|
*
|
|
@@ -1826,7 +1667,7 @@ export declare namespace Machine {
|
|
|
1826
1667
|
* @category models
|
|
1827
1668
|
* @since 0.4.0
|
|
1828
1669
|
*/
|
|
1829
|
-
type TaggedSchema = Schema.Top & {
|
|
1670
|
+
export type TaggedSchema = Schema.Top & {
|
|
1830
1671
|
readonly Type: {
|
|
1831
1672
|
readonly _tag: PropertyKey;
|
|
1832
1673
|
};
|
|
@@ -1842,7 +1683,7 @@ export declare namespace Machine {
|
|
|
1842
1683
|
* @category models
|
|
1843
1684
|
* @since 0.4.0
|
|
1844
1685
|
*/
|
|
1845
|
-
interface StateNodeAnnotations extends Schema.Annotations.Annotations {
|
|
1686
|
+
export interface StateNodeAnnotations extends Schema.Annotations.Annotations {
|
|
1846
1687
|
/** Human-readable label used by visualization and documentation tooling. */
|
|
1847
1688
|
readonly title?: string | undefined;
|
|
1848
1689
|
/** Short explanation of the state node's domain meaning. */
|
|
@@ -1851,7 +1692,7 @@ export declare namespace Machine {
|
|
|
1851
1692
|
readonly documentation?: string | undefined;
|
|
1852
1693
|
}
|
|
1853
1694
|
/** Descriptive annotations accepted by schema-less active and pseudo-states. */
|
|
1854
|
-
type SchemaLessStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
|
|
1695
|
+
export type SchemaLessStateAnnotations = Pick<StateNodeAnnotations, "title" | "description" | "documentation">;
|
|
1855
1696
|
/**
|
|
1856
1697
|
* Configuration accepted for an atomic object state node.
|
|
1857
1698
|
*
|
|
@@ -1861,7 +1702,7 @@ export declare namespace Machine {
|
|
|
1861
1702
|
* @category models
|
|
1862
1703
|
* @since 0.4.0
|
|
1863
1704
|
*/
|
|
1864
|
-
type AtomicStateNodeConfig = {
|
|
1705
|
+
export type AtomicStateNodeConfig = {
|
|
1865
1706
|
/** Tagged schema that owns the state's decoded value. */
|
|
1866
1707
|
readonly schema: TaggedSchema;
|
|
1867
1708
|
/** Declares an ordinary active state. Omitted values default to `"active"`. */
|
|
@@ -1897,7 +1738,7 @@ export declare namespace Machine {
|
|
|
1897
1738
|
* @category models
|
|
1898
1739
|
* @since 0.4.0
|
|
1899
1740
|
*/
|
|
1900
|
-
type CompoundStateNodeConfig = {
|
|
1741
|
+
export type CompoundStateNodeConfig = {
|
|
1901
1742
|
/** Tagged schema that owns the compound state's decoded value. */
|
|
1902
1743
|
readonly schema: TaggedSchema;
|
|
1903
1744
|
/** Compound states are ordinary active states. */
|
|
@@ -1921,7 +1762,7 @@ export declare namespace Machine {
|
|
|
1921
1762
|
* @category models
|
|
1922
1763
|
* @since 0.4.0
|
|
1923
1764
|
*/
|
|
1924
|
-
type ParallelStateNodeConfig = {
|
|
1765
|
+
export type ParallelStateNodeConfig = {
|
|
1925
1766
|
/** Tagged schema that owns the parallel state's decoded value. */
|
|
1926
1767
|
readonly schema: TaggedSchema;
|
|
1927
1768
|
/** Selects parallel-region semantics for the node. */
|
|
@@ -1952,7 +1793,7 @@ export declare namespace Machine {
|
|
|
1952
1793
|
* @category models
|
|
1953
1794
|
* @since 0.4.0
|
|
1954
1795
|
*/
|
|
1955
|
-
interface HistoryStateNodeConfig {
|
|
1796
|
+
export interface HistoryStateNodeConfig {
|
|
1956
1797
|
/** Selects history pseudo-state semantics. */
|
|
1957
1798
|
readonly type: "history";
|
|
1958
1799
|
/**
|
|
@@ -1969,13 +1810,13 @@ export declare namespace Machine {
|
|
|
1969
1810
|
* Transient decision pseudo-state resolved immediately when targeted.
|
|
1970
1811
|
*
|
|
1971
1812
|
* Choice nodes have no value and never belong to an active configuration.
|
|
1972
|
-
* Their required `choice`
|
|
1973
|
-
*
|
|
1813
|
+
* Their required `choice` transition selects a typed destination
|
|
1814
|
+
* synchronously.
|
|
1974
1815
|
*
|
|
1975
1816
|
* @category models
|
|
1976
1817
|
* @since 0.4.0
|
|
1977
1818
|
*/
|
|
1978
|
-
interface ChoiceStateNodeConfig {
|
|
1819
|
+
export interface ChoiceStateNodeConfig {
|
|
1979
1820
|
/** Selects transient choice pseudo-state semantics. */
|
|
1980
1821
|
readonly type: "choice";
|
|
1981
1822
|
/** Descriptive metadata used by visualization and documentation tooling. */
|
|
@@ -1987,7 +1828,7 @@ export declare namespace Machine {
|
|
|
1987
1828
|
* @category models
|
|
1988
1829
|
* @since 0.4.0
|
|
1989
1830
|
*/
|
|
1990
|
-
type StateNodeConfig = AtomicStateNodeConfig | CompoundStateNodeConfig | ParallelStateNodeConfig | HistoryStateNodeConfig | ChoiceStateNodeConfig;
|
|
1831
|
+
export type StateNodeConfig = AtomicStateNodeConfig | CompoundStateNodeConfig | ParallelStateNodeConfig | HistoryStateNodeConfig | ChoiceStateNodeConfig;
|
|
1991
1832
|
/**
|
|
1992
1833
|
* Object state tree keyed by state path.
|
|
1993
1834
|
*
|
|
@@ -1997,30 +1838,15 @@ export declare namespace Machine {
|
|
|
1997
1838
|
* @category models
|
|
1998
1839
|
* @since 0.4.0
|
|
1999
1840
|
*/
|
|
2000
|
-
type StateTree = Readonly<Record<string, TaggedSchema | StateNodeConfig>>;
|
|
1841
|
+
export type StateTree = Readonly<Record<string, TaggedSchema | StateNodeConfig>>;
|
|
2001
1842
|
/**
|
|
2002
|
-
* State
|
|
1843
|
+
* State tree used as the topology parameter of machine types. A machine's
|
|
1844
|
+
* tree holds its root node under the `""` key.
|
|
2003
1845
|
*
|
|
2004
1846
|
* @category models
|
|
2005
1847
|
* @since 0.4.0
|
|
2006
1848
|
*/
|
|
2007
|
-
type StateSchemas = StateTree;
|
|
2008
|
-
/**
|
|
2009
|
-
* Builder for initial state snapshots generated by `states`.
|
|
2010
|
-
*
|
|
2011
|
-
* **When to use**
|
|
2012
|
-
*
|
|
2013
|
-
* Use when you need the type of the `initial` property returned by
|
|
2014
|
-
* `states` or want to expose an initial snapshot builder from a helper.
|
|
2015
|
-
*
|
|
2016
|
-
* **Details**
|
|
2017
|
-
*
|
|
2018
|
-
* Initial builders enforce the declared initial child for compound states and
|
|
2019
|
-
* require every direct region for parallel states.
|
|
2020
|
-
*
|
|
2021
|
-
* @category utility types
|
|
2022
|
-
* @since 0.4.0
|
|
2023
|
-
*/
|
|
1849
|
+
export type StateSchemas = StateTree;
|
|
2024
1850
|
/**
|
|
2025
1851
|
* Typed snapshot access shared by state descriptors.
|
|
2026
1852
|
*
|
|
@@ -2031,7 +1857,7 @@ export declare namespace Machine {
|
|
|
2031
1857
|
* @category models
|
|
2032
1858
|
* @since 0.4.0
|
|
2033
1859
|
*/
|
|
2034
|
-
interface StateAccessors<States extends StateSchemas> {
|
|
1860
|
+
export interface StateAccessors<States extends StateSchemas> {
|
|
2035
1861
|
/**
|
|
2036
1862
|
* Checks and preserves one active state path from this definition.
|
|
2037
1863
|
*
|
|
@@ -2095,9 +1921,9 @@ export declare namespace Machine {
|
|
|
2095
1921
|
* @category utility types
|
|
2096
1922
|
* @since 0.4.0
|
|
2097
1923
|
*/
|
|
2098
|
-
type ValidateStateSchemas<States extends StateSchemas> = ValidateStateTree<States>;
|
|
1924
|
+
export type ValidateStateSchemas<States extends StateSchemas> = ValidateStateTree<States>;
|
|
2099
1925
|
/** Properties shared by every compiled state-node variant. */
|
|
2100
|
-
interface StateNodeBase<Path extends string = string> {
|
|
1926
|
+
export interface StateNodeBase<Path extends string = string> {
|
|
2101
1927
|
readonly path: Path;
|
|
2102
1928
|
readonly key: string;
|
|
2103
1929
|
/** Resolved schema annotations, or descriptive schema-less-state annotations. */
|
|
@@ -2105,7 +1931,7 @@ export declare namespace Machine {
|
|
|
2105
1931
|
readonly order: number;
|
|
2106
1932
|
}
|
|
2107
1933
|
/** Runtime metadata for a compiled atomic state. */
|
|
2108
|
-
interface AtomicStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1934
|
+
export interface AtomicStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
2109
1935
|
readonly type: "atomic";
|
|
2110
1936
|
readonly schema: TaggedSchema | undefined;
|
|
2111
1937
|
readonly output: undefined;
|
|
@@ -2115,7 +1941,7 @@ export declare namespace Machine {
|
|
|
2115
1941
|
readonly initial: undefined;
|
|
2116
1942
|
}
|
|
2117
1943
|
/** Runtime metadata for a compiled compound state. */
|
|
2118
|
-
interface CompoundStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath, ChoicePath extends string = ActivePath> extends StateNodeBase<OwnPath> {
|
|
1944
|
+
export interface CompoundStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath, ChoicePath extends string = ActivePath> extends StateNodeBase<OwnPath> {
|
|
2119
1945
|
readonly type: "compound";
|
|
2120
1946
|
readonly schema: TaggedSchema | undefined;
|
|
2121
1947
|
readonly output: undefined;
|
|
@@ -2126,7 +1952,7 @@ export declare namespace Machine {
|
|
|
2126
1952
|
readonly initial: ActivePath | ChoicePath;
|
|
2127
1953
|
}
|
|
2128
1954
|
/** Runtime metadata for a compiled parallel state. */
|
|
2129
|
-
interface ParallelStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1955
|
+
export interface ParallelStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
2130
1956
|
readonly type: "parallel";
|
|
2131
1957
|
readonly schema: TaggedSchema | undefined;
|
|
2132
1958
|
readonly output: Schema.Top | undefined;
|
|
@@ -2137,7 +1963,7 @@ export declare namespace Machine {
|
|
|
2137
1963
|
readonly initial: undefined;
|
|
2138
1964
|
}
|
|
2139
1965
|
/** Runtime metadata for a compiled final state. */
|
|
2140
|
-
interface FinalStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
1966
|
+
export interface FinalStateNode<OwnPath extends string = string, ActivePath extends string = OwnPath> extends StateNodeBase<OwnPath> {
|
|
2141
1967
|
readonly type: "final";
|
|
2142
1968
|
readonly schema: TaggedSchema | undefined;
|
|
2143
1969
|
readonly output: Schema.Top | undefined;
|
|
@@ -2147,7 +1973,7 @@ export declare namespace Machine {
|
|
|
2147
1973
|
readonly initial: undefined;
|
|
2148
1974
|
}
|
|
2149
1975
|
/** Runtime metadata for a compiled history pseudo-state. */
|
|
2150
|
-
interface HistoryStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
|
|
1976
|
+
export interface HistoryStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
|
|
2151
1977
|
readonly type: "history";
|
|
2152
1978
|
readonly schema: undefined;
|
|
2153
1979
|
readonly output: undefined;
|
|
@@ -2157,7 +1983,7 @@ export declare namespace Machine {
|
|
|
2157
1983
|
readonly initial: undefined;
|
|
2158
1984
|
}
|
|
2159
1985
|
/** Runtime metadata for a compiled choice pseudo-state. */
|
|
2160
|
-
interface ChoiceStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
|
|
1986
|
+
export interface ChoiceStateNode<OwnPath extends string = string, ActivePath extends string = string> extends StateNodeBase<OwnPath> {
|
|
2161
1987
|
readonly type: "choice";
|
|
2162
1988
|
readonly schema: undefined;
|
|
2163
1989
|
readonly output: undefined;
|
|
@@ -2175,15 +2001,15 @@ export declare namespace Machine {
|
|
|
2175
2001
|
* @category models
|
|
2176
2002
|
* @since 0.4.0
|
|
2177
2003
|
*/
|
|
2178
|
-
type ActiveStateNode<ActivePath extends string = string, ChoicePath extends string = ActivePath> = AtomicStateNode<ActivePath, ActivePath> | CompoundStateNode<ActivePath, ActivePath, ChoicePath> | ParallelStateNode<ActivePath, ActivePath> | FinalStateNode<ActivePath, ActivePath>;
|
|
2179
|
-
type StateNode<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> = ActiveStateNode<ActivePath, ChoicePath> | HistoryStateNode<HistoryPath, ActivePath> | ChoiceStateNode<ChoicePath, ActivePath>;
|
|
2004
|
+
export type ActiveStateNode<ActivePath extends string = string, ChoicePath extends string = ActivePath> = AtomicStateNode<ActivePath, ActivePath> | CompoundStateNode<ActivePath, ActivePath, ChoicePath> | ParallelStateNode<ActivePath, ActivePath> | FinalStateNode<ActivePath, ActivePath>;
|
|
2005
|
+
export type StateNode<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> = ActiveStateNode<ActivePath, ChoicePath> | HistoryStateNode<HistoryPath, ActivePath> | ChoiceStateNode<ChoicePath, ActivePath>;
|
|
2180
2006
|
/**
|
|
2181
2007
|
* Runtime lookup table for state nodes.
|
|
2182
2008
|
*
|
|
2183
2009
|
* @category models
|
|
2184
2010
|
* @since 0.4.0
|
|
2185
2011
|
*/
|
|
2186
|
-
interface StateNodes<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> {
|
|
2012
|
+
export interface StateNodes<ActivePath extends string = string, HistoryPath extends string = ActivePath, ChoicePath extends string = ActivePath> {
|
|
2187
2013
|
readonly byPath: ReadonlyMap<ActivePath | HistoryPath | ChoicePath, StateNode<ActivePath, HistoryPath, ChoicePath>>;
|
|
2188
2014
|
readonly roots: ReadonlyArray<ActivePath>;
|
|
2189
2015
|
}
|
|
@@ -2193,7 +2019,7 @@ export declare namespace Machine {
|
|
|
2193
2019
|
* @category models
|
|
2194
2020
|
* @since 0.4.0
|
|
2195
2021
|
*/
|
|
2196
|
-
type TransitionTrigger<EventTag extends PropertyKey = PropertyKey> = {
|
|
2022
|
+
export type TransitionTrigger<EventTag extends PropertyKey = PropertyKey> = {
|
|
2197
2023
|
readonly type: "event";
|
|
2198
2024
|
readonly event: EventTag;
|
|
2199
2025
|
} | {
|
|
@@ -2207,30 +2033,40 @@ export declare namespace Machine {
|
|
|
2207
2033
|
readonly id: string;
|
|
2208
2034
|
readonly outcome: "element" | "done" | "failure" | "snapshot";
|
|
2209
2035
|
};
|
|
2210
|
-
/**
|
|
2211
|
-
|
|
2036
|
+
/**
|
|
2037
|
+
* Static topology selected by a transition branch.
|
|
2038
|
+
*
|
|
2039
|
+
* **Details**
|
|
2040
|
+
*
|
|
2041
|
+
* `kind` is `"state"` or `"choice"` for the path named by `target`,
|
|
2042
|
+
* `"history"` for `history`, `"state"` with the root path `""` for
|
|
2043
|
+
* `initialize`, and `"update"` for an `update` without a destination. A
|
|
2044
|
+
* `{ stay: true }` entry, or a transition with only `reenter: true`, has kind
|
|
2045
|
+
* `"none"` and no path. The machine's initial entry has kind `"initial"`.
|
|
2046
|
+
*/
|
|
2047
|
+
export interface TransitionTargetSelection<Path extends string | undefined = string | undefined, Kind extends Topology.TargetSelectionKind = Topology.TargetSelectionKind, Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> {
|
|
2212
2048
|
readonly path: Path;
|
|
2213
2049
|
readonly kind: Kind;
|
|
2214
2050
|
readonly scope: Scope;
|
|
2215
2051
|
}
|
|
2216
2052
|
/** One statically captured branch of a transition definition. */
|
|
2217
|
-
type TransitionBranch<Path extends string = string> = {
|
|
2053
|
+
export type TransitionBranch<Path extends string = string> = {
|
|
2218
2054
|
readonly type: "direct";
|
|
2219
2055
|
readonly target: Path | undefined;
|
|
2220
2056
|
readonly selection: TransitionTargetSelection<Path | undefined>;
|
|
2221
2057
|
readonly updates: ReadonlyArray<string>;
|
|
2222
2058
|
} | {
|
|
2223
2059
|
readonly type: "branch";
|
|
2060
|
+
/** The entry as written: `target:Paid`, `target:Paid+update:root`, `update:root`, `history:X`, `initialize`, or `stay`. */
|
|
2224
2061
|
readonly key: string;
|
|
2225
|
-
readonly title: string;
|
|
2226
2062
|
readonly target: Path | undefined;
|
|
2227
2063
|
readonly selection: TransitionTargetSelection<Path | undefined>;
|
|
2228
2064
|
readonly updates: ReadonlyArray<string>;
|
|
2229
2065
|
};
|
|
2230
2066
|
/** The statically selected root entry for machine startup. */
|
|
2231
|
-
interface InitialDefinition<Path extends string = string> {
|
|
2067
|
+
export interface InitialDefinition<Path extends string = string> {
|
|
2232
2068
|
readonly target: Path;
|
|
2233
|
-
readonly selection: TransitionTargetSelection<Path, "
|
|
2069
|
+
readonly selection: TransitionTargetSelection<Path, "initial", "initial">;
|
|
2234
2070
|
}
|
|
2235
2071
|
/**
|
|
2236
2072
|
* Inspectable registration for a transition handler.
|
|
@@ -2238,14 +2074,16 @@ export declare namespace Machine {
|
|
|
2238
2074
|
* **Details**
|
|
2239
2075
|
*
|
|
2240
2076
|
* Every branch exposes its static selection without executing its resolver.
|
|
2241
|
-
*
|
|
2242
|
-
*
|
|
2243
|
-
*
|
|
2077
|
+
* Selecting a compound or parallel state also covers the descendants the
|
|
2078
|
+
* transition enters through it. An `update` selection keeps `target`
|
|
2079
|
+
* undefined and records its value owner in `selection.path`. A
|
|
2080
|
+
* `{ stay: true }` entry keeps `target` undefined and has
|
|
2081
|
+
* `selection.kind` `"none"`.
|
|
2244
2082
|
*
|
|
2245
2083
|
* @category models
|
|
2246
2084
|
* @since 0.4.0
|
|
2247
2085
|
*/
|
|
2248
|
-
interface TransitionDefinition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
|
|
2086
|
+
export interface TransitionDefinition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
|
|
2249
2087
|
readonly source: SourcePath;
|
|
2250
2088
|
readonly trigger: TransitionTrigger<EventTag>;
|
|
2251
2089
|
readonly reenter: boolean;
|
|
@@ -2262,7 +2100,7 @@ export declare namespace Machine {
|
|
|
2262
2100
|
* @category models
|
|
2263
2101
|
* @since 0.4.0
|
|
2264
2102
|
*/
|
|
2265
|
-
type ActivityDefinition<SourcePath extends string = string> = Activities.ActivityDefinition<SourcePath>;
|
|
2103
|
+
export type ActivityDefinition<SourcePath extends string = string> = Activities.ActivityDefinition<SourcePath>;
|
|
2266
2104
|
/**
|
|
2267
2105
|
* Transition retained after hierarchy precedence and conflict resolution for
|
|
2268
2106
|
* one planned microstep.
|
|
@@ -2270,13 +2108,13 @@ export declare namespace Machine {
|
|
|
2270
2108
|
* @category models
|
|
2271
2109
|
* @since 0.4.0
|
|
2272
2110
|
*/
|
|
2273
|
-
interface RetainedTransition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
|
|
2111
|
+
export interface RetainedTransition<SourcePath extends string = string, EventTag extends PropertyKey = PropertyKey, TargetPath extends string = SourcePath> {
|
|
2274
2112
|
readonly source: SourcePath;
|
|
2275
2113
|
readonly trigger: TransitionTrigger<EventTag>;
|
|
2276
2114
|
readonly reenter: boolean;
|
|
2277
2115
|
/** Zero-based index of the selected static branch. */
|
|
2278
2116
|
readonly branchIndex: number;
|
|
2279
|
-
/**
|
|
2117
|
+
/** The selected `branches` entry as written, such as `target:Paid`, or `undefined` for a direct transition. */
|
|
2280
2118
|
readonly branchKey: string | undefined;
|
|
2281
2119
|
/** Path returned by the handler, including a choice or history pseudo-state. */
|
|
2282
2120
|
readonly target: TargetPath | undefined;
|
|
@@ -2289,26 +2127,27 @@ export declare namespace Machine {
|
|
|
2289
2127
|
readonly updates: ReadonlyArray<string>;
|
|
2290
2128
|
}
|
|
2291
2129
|
/**
|
|
2292
|
-
*
|
|
2130
|
+
* Startup arguments: the decoded input when the machine declares an input
|
|
2131
|
+
* schema, and none otherwise.
|
|
2293
2132
|
*
|
|
2294
2133
|
* @category utility types
|
|
2295
2134
|
* @since 0.4.0
|
|
2296
2135
|
*/
|
|
2297
|
-
type InputArgs<Input extends Schema.Top> = Input extends typeof Schema.Void ? [] : [input: Input["Type"]];
|
|
2136
|
+
export type InputArgs<Input extends Schema.Top> = Input extends typeof Schema.Void ? [] : [input: Input["Type"]];
|
|
2298
2137
|
/**
|
|
2299
2138
|
* Extracts the discriminator value represented by a tagged schema.
|
|
2300
2139
|
*
|
|
2301
2140
|
* @category utility types
|
|
2302
2141
|
* @since 0.4.0
|
|
2303
2142
|
*/
|
|
2304
|
-
type TagOf<S extends TaggedSchema> = S["Type"]["_tag"];
|
|
2143
|
+
export type TagOf<S extends TaggedSchema> = S["Type"]["_tag"];
|
|
2305
2144
|
/**
|
|
2306
2145
|
* Extracts the schema from a state tree node definition.
|
|
2307
2146
|
*
|
|
2308
2147
|
* @category utility types
|
|
2309
2148
|
* @since 0.4.0
|
|
2310
2149
|
*/
|
|
2311
|
-
type NodeSchema<Node> = Node extends TaggedSchema ? Node : Node extends {
|
|
2150
|
+
export type NodeSchema<Node> = Node extends TaggedSchema ? Node : Node extends {
|
|
2312
2151
|
readonly schema: infer Schema extends TaggedSchema;
|
|
2313
2152
|
} ? Schema : never;
|
|
2314
2153
|
/**
|
|
@@ -2317,18 +2156,18 @@ export declare namespace Machine {
|
|
|
2317
2156
|
* @category utility types
|
|
2318
2157
|
* @since 0.4.0
|
|
2319
2158
|
*/
|
|
2320
|
-
type JoinPath<Parent extends string, Child extends string> = Parent extends "" ? Child : `${Parent}.${Child}`;
|
|
2159
|
+
export type JoinPath<Parent extends string, Child extends string> = Parent extends "" ? Child : `${Parent}.${Child}`;
|
|
2321
2160
|
/**
|
|
2322
2161
|
* Extracts the state path values represented by a state definition.
|
|
2323
2162
|
*
|
|
2324
2163
|
* @category utility types
|
|
2325
2164
|
* @since 0.4.0
|
|
2326
2165
|
*/
|
|
2327
|
-
type StateIdentifier<States extends StateSchemas> = StateIdentifierWithPrefix<States>;
|
|
2166
|
+
export type StateIdentifier<States extends StateSchemas> = StateIdentifierWithPrefix<States>;
|
|
2328
2167
|
/** Extracts active state paths whose definitions declare a state value schema. */
|
|
2329
|
-
type ValuedStateIdentifier<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? NodeSchema<NodeByIdentifier<States, StateId>> extends never ? never : StateId : never : never;
|
|
2168
|
+
export type ValuedStateIdentifier<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? NodeSchema<NodeByIdentifier<States, StateId>> extends never ? never : StateId : never : never;
|
|
2330
2169
|
/** Extracts active state paths whose definitions intentionally omit a state value schema. */
|
|
2331
|
-
type StructuralStateIdentifier<States extends StateSchemas> = Exclude<StateIdentifier<States>, ValuedStateIdentifier<States>>;
|
|
2170
|
+
export type StructuralStateIdentifier<States extends StateSchemas> = Exclude<StateIdentifier<States>, ValuedStateIdentifier<States>>;
|
|
2332
2171
|
/**
|
|
2333
2172
|
* Extracts the state path values represented by a state definition under a
|
|
2334
2173
|
* parent path prefix.
|
|
@@ -2336,7 +2175,7 @@ export declare namespace Machine {
|
|
|
2336
2175
|
* @category utility types
|
|
2337
2176
|
* @since 0.4.0
|
|
2338
2177
|
*/
|
|
2339
|
-
type StateIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
2178
|
+
export type StateIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
2340
2179
|
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig | ChoiceStateNodeConfig ? never : States[Key] extends {
|
|
2341
2180
|
readonly states: infer Children;
|
|
2342
2181
|
} ? Children extends StateSchemas ? JoinPath<Prefix, Key> | StateIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : JoinPath<Prefix, Key> : JoinPath<Prefix, Key>;
|
|
@@ -2347,38 +2186,38 @@ export declare namespace Machine {
|
|
|
2347
2186
|
* @category utility types
|
|
2348
2187
|
* @since 0.4.0
|
|
2349
2188
|
*/
|
|
2350
|
-
type HistoryIdentifier<States extends StateSchemas> = HistoryIdentifierWithPrefix<States>;
|
|
2189
|
+
export type HistoryIdentifier<States extends StateSchemas> = HistoryIdentifierWithPrefix<States>;
|
|
2351
2190
|
/** Extracts the transition-only choice pseudo-state paths. */
|
|
2352
|
-
type ChoiceIdentifier<States extends StateSchemas> = ChoiceIdentifierWithPrefix<States>;
|
|
2191
|
+
export type ChoiceIdentifier<States extends StateSchemas> = ChoiceIdentifierWithPrefix<States>;
|
|
2353
2192
|
/**
|
|
2354
2193
|
* Extracts every compiled state-node path, including history pseudo-states.
|
|
2355
2194
|
*
|
|
2356
2195
|
* @category utility types
|
|
2357
2196
|
* @since 0.4.0
|
|
2358
2197
|
*/
|
|
2359
|
-
type StateNodeIdentifier<States extends StateSchemas> = StateIdentifier<States> | HistoryIdentifier<States> | ChoiceIdentifier<States>;
|
|
2198
|
+
export type StateNodeIdentifier<States extends StateSchemas> = StateIdentifier<States> | HistoryIdentifier<States> | ChoiceIdentifier<States>;
|
|
2360
2199
|
/** @internal */
|
|
2361
|
-
type HistoryIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
2200
|
+
export type HistoryIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
2362
2201
|
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? JoinPath<Prefix, Key> : States[Key] extends {
|
|
2363
2202
|
readonly states: infer Children extends StateSchemas;
|
|
2364
2203
|
} ? HistoryIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : never;
|
|
2365
2204
|
}[Extract<keyof States, string>];
|
|
2366
2205
|
/** @internal */
|
|
2367
|
-
type ChoiceIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
2206
|
+
export type ChoiceIdentifierWithPrefix<States extends StateSchemas, Prefix extends string = ""> = {
|
|
2368
2207
|
readonly [Key in Extract<keyof States, string>]: States[Key] extends ChoiceStateNodeConfig ? JoinPath<Prefix, Key> : States[Key] extends {
|
|
2369
2208
|
readonly states: infer Children extends StateSchemas;
|
|
2370
2209
|
} ? ChoiceIdentifierWithPrefix<Children, JoinPath<Prefix, Key>> : never;
|
|
2371
2210
|
}[Extract<keyof States, string>];
|
|
2372
2211
|
/** Active keys directly declared in a state tree. */
|
|
2373
|
-
type ActiveStateKey<States extends StateSchemas> = {
|
|
2212
|
+
export type ActiveStateKey<States extends StateSchemas> = {
|
|
2374
2213
|
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig | ChoiceStateNodeConfig ? never : Key;
|
|
2375
2214
|
}[Extract<keyof States, string>];
|
|
2376
2215
|
/** History pseudo-state keys directly declared in a state tree. */
|
|
2377
|
-
type HistoryStateKey<States extends StateSchemas> = {
|
|
2216
|
+
export type HistoryStateKey<States extends StateSchemas> = {
|
|
2378
2217
|
readonly [Key in Extract<keyof States, string>]: States[Key] extends HistoryStateNodeConfig ? Key : never;
|
|
2379
2218
|
}[Extract<keyof States, string>];
|
|
2380
2219
|
/** Choice pseudo-state keys directly declared in a state tree. */
|
|
2381
|
-
type ChoiceStateKey<States extends StateSchemas> = {
|
|
2220
|
+
export type ChoiceStateKey<States extends StateSchemas> = {
|
|
2382
2221
|
readonly [Key in Extract<keyof States, string>]: States[Key] extends ChoiceStateNodeConfig ? Key : never;
|
|
2383
2222
|
}[Extract<keyof States, string>];
|
|
2384
2223
|
/**
|
|
@@ -2388,27 +2227,27 @@ export declare namespace Machine {
|
|
|
2388
2227
|
* @category utility types
|
|
2389
2228
|
* @since 0.4.0
|
|
2390
2229
|
*/
|
|
2391
|
-
type RequiredHistoryInitializers<States extends StateSchemas> = [HistoryIdentifier<States>] extends [never] ? never : Extract<RequiredHistoryInitializersWithPrefix<States, States, "">, StateIdentifier<States>>;
|
|
2230
|
+
export type RequiredHistoryInitializers<States extends StateSchemas> = [HistoryIdentifier<States>] extends [never] ? never : Extract<RequiredHistoryInitializersWithPrefix<States, States, "">, StateIdentifier<States>>;
|
|
2392
2231
|
/** Active parent states that own one or more history pseudo-states. */
|
|
2393
|
-
type HistoryParentIdentifier<States extends StateSchemas> = HistoryIdentifier<States> extends infer HistoryId ? HistoryId extends string ? Extract<ImmediateParentStateIdentifier<HistoryId>, StateIdentifier<States>> : never : never;
|
|
2232
|
+
export type HistoryParentIdentifier<States extends StateSchemas> = HistoryIdentifier<States> extends infer HistoryId ? HistoryId extends string ? Extract<ImmediateParentStateIdentifier<HistoryId>, StateIdentifier<States>> : never : never;
|
|
2394
2233
|
/** Active parent states that own one or more choice pseudo-states. */
|
|
2395
|
-
type ChoiceParentIdentifier<States extends StateSchemas> = ChoiceIdentifier<States> extends infer ChoiceId ? ChoiceId extends string ? Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>> : never : never;
|
|
2234
|
+
export type ChoiceParentIdentifier<States extends StateSchemas> = ChoiceIdentifier<States> extends infer ChoiceId ? ChoiceId extends string ? Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>> : never : never;
|
|
2396
2235
|
/** History defaults and implicit initializers that remain unimplemented. */
|
|
2397
|
-
type MissingHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, HistoryParentIdentifier<States> | RequiredHistoryInitializers<States>>;
|
|
2236
|
+
export type MissingHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, HistoryParentIdentifier<States> | RequiredHistoryInitializers<States>>;
|
|
2398
2237
|
/** Choice-owning active parents that remain unimplemented. */
|
|
2399
|
-
type MissingChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, ChoiceParentIdentifier<States>>;
|
|
2238
|
+
export type MissingChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = Extract<UnhandledStates, ChoiceParentIdentifier<States>>;
|
|
2400
2239
|
/** @internal Readiness proof for required choice resolvers. */
|
|
2401
|
-
type EnsureChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = IsAny<States> extends true ? unknown : [ChoiceIdentifier<States>] extends [never] ? unknown : [MissingChoiceImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
2240
|
+
export type EnsureChoiceImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = IsAny<States> extends true ? unknown : [ChoiceIdentifier<States>] extends [never] ? unknown : [MissingChoiceImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
2402
2241
|
readonly "~effect/Machine/MissingChoiceImplementation": MissingChoiceImplementations<States, UnhandledStates>;
|
|
2403
2242
|
};
|
|
2404
2243
|
/** @internal Readiness proof required by planning and managed execution. */
|
|
2405
|
-
type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = IsAny<States> extends true ? unknown : ([HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
2244
|
+
export type EnsureHistoryImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = IsAny<States> extends true ? unknown : ([HistoryIdentifier<States>] extends [never] ? unknown : [MissingHistoryImplementations<States, UnhandledStates>] extends [never] ? unknown : {
|
|
2406
2245
|
readonly "~effect/Machine/MissingHistoryImplementation": MissingHistoryImplementations<States, UnhandledStates>;
|
|
2407
2246
|
}) & EnsureChoiceImplementations<States, UnhandledStates>;
|
|
2408
2247
|
/** Owners that require a handler-owned initial edge or region data. */
|
|
2409
|
-
type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never : "" extends keyof States ? InitializerClosureForNode<States, States[""], ""> : never;
|
|
2248
|
+
export type RequiredInitializers<States extends StateSchemas> = string extends keyof States ? never : "" extends keyof States ? InitializerClosureForNode<States, States[""], ""> : never;
|
|
2410
2249
|
/** Proof that initialization can construct every required default value. */
|
|
2411
|
-
type EnsureInitialImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [UnhandledStates] extends [never] ? unknown : [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown : {
|
|
2250
|
+
export type EnsureInitialImplementations<States extends StateSchemas, UnhandledStates extends StateIdentifier<States>> = [UnhandledStates] extends [never] ? unknown : [Extract<RequiredInitializers<States>, UnhandledStates>] extends [never] ? unknown : {
|
|
2412
2251
|
readonly "~effect/Machine/MissingInitialImplementation": Extract<RequiredInitializers<States>, UnhandledStates>;
|
|
2413
2252
|
};
|
|
2414
2253
|
/**
|
|
@@ -2417,7 +2256,7 @@ export declare namespace Machine {
|
|
|
2417
2256
|
* @category utility types
|
|
2418
2257
|
* @since 0.4.0
|
|
2419
2258
|
*/
|
|
2420
|
-
type NodeByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = string extends keyof States ? NodeByNamedIdentifier<States, StateId> : "" extends keyof States ? StateId extends "" ? States[""] : States[""] extends {
|
|
2259
|
+
export type NodeByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = string extends keyof States ? NodeByNamedIdentifier<States, StateId> : "" extends keyof States ? StateId extends "" ? States[""] : States[""] extends {
|
|
2421
2260
|
readonly states: infer Children extends StateSchemas;
|
|
2422
2261
|
} ? NodeByIdentifier<Children, Extract<StateId, StateIdentifier<Children>>> : never : NodeByNamedIdentifier<States, StateId>;
|
|
2423
2262
|
type NodeByNamedIdentifier<States extends StateSchemas, StateId extends string> = StateId extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
@@ -2429,21 +2268,21 @@ export declare namespace Machine {
|
|
|
2429
2268
|
* @category utility types
|
|
2430
2269
|
* @since 0.4.0
|
|
2431
2270
|
*/
|
|
2432
|
-
type SchemaByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeSchema<NodeByIdentifier<States, StateId>>;
|
|
2271
|
+
export type SchemaByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeSchema<NodeByIdentifier<States, StateId>>;
|
|
2433
2272
|
/**
|
|
2434
2273
|
* Extracts the union of state values represented by a state definition.
|
|
2435
2274
|
*
|
|
2436
2275
|
* @category utility types
|
|
2437
2276
|
* @since 0.4.0
|
|
2438
2277
|
*/
|
|
2439
|
-
type StateOf<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : never : never;
|
|
2278
|
+
export type StateOf<States extends StateSchemas> = StateIdentifier<States> extends infer StateId ? StateId extends StateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : never : never;
|
|
2440
2279
|
/**
|
|
2441
2280
|
* Extracts the union of event values represented by an event schema list.
|
|
2442
2281
|
*
|
|
2443
2282
|
* @category utility types
|
|
2444
2283
|
* @since 0.4.0
|
|
2445
2284
|
*/
|
|
2446
|
-
type EventOf<Events extends ReadonlyArray<TaggedSchema>> = Events[number]["Type"];
|
|
2285
|
+
export type EventOf<Events extends ReadonlyArray<TaggedSchema>> = Events[number]["Type"];
|
|
2447
2286
|
/**
|
|
2448
2287
|
* Extracts the union of emitted event values represented by an emitted event
|
|
2449
2288
|
* schema list.
|
|
@@ -2451,28 +2290,28 @@ export declare namespace Machine {
|
|
|
2451
2290
|
* @category utility types
|
|
2452
2291
|
* @since 0.4.0
|
|
2453
2292
|
*/
|
|
2454
|
-
type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"];
|
|
2293
|
+
export type EmittedEventOf<Emits extends ReadonlyArray<TaggedSchema>> = Emits[number]["Type"];
|
|
2455
2294
|
/**
|
|
2456
2295
|
* Event values received by lifecycle callbacks.
|
|
2457
2296
|
*
|
|
2458
2297
|
* @category utility types
|
|
2459
2298
|
* @since 0.4.0
|
|
2460
2299
|
*/
|
|
2461
|
-
type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> = EventOf<Events> | InitialEvent;
|
|
2300
|
+
export type LifecycleEvent<Events extends ReadonlyArray<TaggedSchema>> = EventOf<Events> | InitialEvent;
|
|
2462
2301
|
/**
|
|
2463
2302
|
* Extracts a state value from a state definition by identifier.
|
|
2464
2303
|
*
|
|
2465
2304
|
* @category utility types
|
|
2466
2305
|
* @since 0.4.0
|
|
2467
2306
|
*/
|
|
2468
|
-
type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends ValuedStateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : undefined;
|
|
2307
|
+
export type StateByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends ValuedStateIdentifier<States> ? SchemaByIdentifier<States, StateId>["Type"] : undefined;
|
|
2469
2308
|
/**
|
|
2470
2309
|
* Extracts every parent state path from a state identifier.
|
|
2471
2310
|
*
|
|
2472
2311
|
* @category utility types
|
|
2473
2312
|
* @since 0.4.0
|
|
2474
2313
|
*/
|
|
2475
|
-
type ParentStateIdentifier<StateId extends string> = StateId extends "" ? never : "" | NamedParentStateIdentifier<StateId>;
|
|
2314
|
+
export type ParentStateIdentifier<StateId extends string> = StateId extends "" ? never : "" | NamedParentStateIdentifier<StateId>;
|
|
2476
2315
|
type NamedParentStateIdentifier<StateId extends string> = StateId extends `${infer Parent}.${infer Child}` ? Parent | (Child extends `${string}.${string}` ? `${Parent}.${NamedParentStateIdentifier<Child>}` : never) : never;
|
|
2477
2316
|
/**
|
|
2478
2317
|
* Extracts the nearest parent state path from a state identifier.
|
|
@@ -2480,14 +2319,14 @@ export declare namespace Machine {
|
|
|
2480
2319
|
* @category utility types
|
|
2481
2320
|
* @since 0.4.0
|
|
2482
2321
|
*/
|
|
2483
|
-
type ImmediateParentStateIdentifier<StateId extends string> = StateId extends `${infer Head}.${infer Tail}` ? Tail extends `${string}.${string}` ? `${Head}.${ImmediateParentStateIdentifier<Tail>}` : Head : StateId extends "" ? never : "";
|
|
2322
|
+
export type ImmediateParentStateIdentifier<StateId extends string> = StateId extends `${infer Head}.${infer Tail}` ? Tail extends `${string}.${string}` ? `${Head}.${ImmediateParentStateIdentifier<Tail>}` : Head : StateId extends "" ? never : "";
|
|
2484
2323
|
/**
|
|
2485
2324
|
* Maps every parent state path of a state identifier to its decoded value.
|
|
2486
2325
|
*
|
|
2487
2326
|
* @category utility types
|
|
2488
2327
|
* @since 0.4.0
|
|
2489
2328
|
*/
|
|
2490
|
-
type ParentStateValues<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
2329
|
+
export type ParentStateValues<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
2491
2330
|
readonly [Parent in Extract<ParentStateIdentifier<StateId>, ValuedStateIdentifier<States>>]: StateByIdentifier<States, Parent>;
|
|
2492
2331
|
} : never;
|
|
2493
2332
|
/**
|
|
@@ -2496,14 +2335,14 @@ export declare namespace Machine {
|
|
|
2496
2335
|
* @category utility types
|
|
2497
2336
|
* @since 0.4.0
|
|
2498
2337
|
*/
|
|
2499
|
-
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 ValuedStateIdentifier<States> ? StateByIdentifier<States, Parent> : undefined : undefined : never;
|
|
2338
|
+
export 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 ValuedStateIdentifier<States> ? StateByIdentifier<States, Parent> : undefined : undefined : never;
|
|
2500
2339
|
/**
|
|
2501
2340
|
* Represents a decoded state value together with all of its parent values.
|
|
2502
2341
|
*
|
|
2503
2342
|
* @category models
|
|
2504
2343
|
* @since 0.4.0
|
|
2505
2344
|
*/
|
|
2506
|
-
type StateWithParents<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
2345
|
+
export type StateWithParents<States extends StateSchemas, StateId extends StateIdentifier<States>> = StateId extends StateIdentifier<States> ? {
|
|
2507
2346
|
readonly value: StateByIdentifier<States, StateId>;
|
|
2508
2347
|
readonly parents: ParentStateValues<States, StateId>;
|
|
2509
2348
|
} : never;
|
|
@@ -2517,7 +2356,7 @@ export declare namespace Machine {
|
|
|
2517
2356
|
* @category utility types
|
|
2518
2357
|
* @since 0.4.0
|
|
2519
2358
|
*/
|
|
2520
|
-
type OutputByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeOutput<NodeByIdentifier<States, StateId>>;
|
|
2359
|
+
export type OutputByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeOutput<NodeByIdentifier<States, StateId>>;
|
|
2521
2360
|
type DirectFinalCompletionOutput<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends {
|
|
2522
2361
|
readonly type: "final";
|
|
2523
2362
|
} ? OutputByIdentifier<States, StateId> : never;
|
|
@@ -2531,7 +2370,7 @@ export declare namespace Machine {
|
|
|
2531
2370
|
* @category utility types
|
|
2532
2371
|
* @since 0.4.0
|
|
2533
2372
|
*/
|
|
2534
|
-
type CompletionOutputByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
2373
|
+
export type CompletionOutputByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
2535
2374
|
readonly type: "parallel";
|
|
2536
2375
|
} ? OutputByIdentifier<States, StateId> : Node extends {
|
|
2537
2376
|
readonly states: infer Children extends StateSchemas;
|
|
@@ -2554,7 +2393,7 @@ export declare namespace Machine {
|
|
|
2554
2393
|
* @category utility types
|
|
2555
2394
|
* @since 0.4.0
|
|
2556
2395
|
*/
|
|
2557
|
-
type TerminalOutput<States extends StateSchemas> = {
|
|
2396
|
+
export type TerminalOutput<States extends StateSchemas> = {
|
|
2558
2397
|
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 {
|
|
2559
2398
|
readonly type: "parallel" | "final";
|
|
2560
2399
|
} ? OutputByIdentifier<States, StateId> : Node extends {
|
|
@@ -2567,7 +2406,7 @@ export declare namespace Machine {
|
|
|
2567
2406
|
* @category utility types
|
|
2568
2407
|
* @since 0.4.0
|
|
2569
2408
|
*/
|
|
2570
|
-
type DeclaredOutputState<States extends StateSchemas> = {
|
|
2409
|
+
export type DeclaredOutputState<States extends StateSchemas> = {
|
|
2571
2410
|
readonly [StateId in StateIdentifier<States>]: NodeByIdentifier<States, StateId> extends {
|
|
2572
2411
|
readonly output: Schema.Top;
|
|
2573
2412
|
} ? StateId : never;
|
|
@@ -2579,7 +2418,7 @@ export declare namespace Machine {
|
|
|
2579
2418
|
* @category utility types
|
|
2580
2419
|
* @since 0.4.0
|
|
2581
2420
|
*/
|
|
2582
|
-
type EnsureOutputImplementations<States extends StateSchemas, OutputStates extends StateIdentifier<States>> = [
|
|
2421
|
+
export type EnsureOutputImplementations<States extends StateSchemas, OutputStates extends StateIdentifier<States>> = [
|
|
2583
2422
|
Exclude<DeclaredOutputState<States>, OutputStates>
|
|
2584
2423
|
] extends [never] ? unknown : {
|
|
2585
2424
|
readonly "~effect/Machine/MissingOutputImplementation": Exclude<DeclaredOutputState<States>, OutputStates>;
|
|
@@ -2596,7 +2435,7 @@ export declare namespace Machine {
|
|
|
2596
2435
|
* @category utility types
|
|
2597
2436
|
* @since 0.4.0
|
|
2598
2437
|
*/
|
|
2599
|
-
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;
|
|
2438
|
+
export 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;
|
|
2600
2439
|
/**
|
|
2601
2440
|
* Services required to encode every state value and completion output in a
|
|
2602
2441
|
* machine snapshot.
|
|
@@ -2604,14 +2443,14 @@ export declare namespace Machine {
|
|
|
2604
2443
|
* @category utility types
|
|
2605
2444
|
* @since 0.4.0
|
|
2606
2445
|
*/
|
|
2607
|
-
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;
|
|
2446
|
+
export 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;
|
|
2608
2447
|
/**
|
|
2609
2448
|
* Encoded value for one active state path in a normalized machine snapshot.
|
|
2610
2449
|
*
|
|
2611
2450
|
* @category models
|
|
2612
2451
|
* @since 0.4.0
|
|
2613
2452
|
*/
|
|
2614
|
-
interface EncodedSnapshotState {
|
|
2453
|
+
export interface EncodedSnapshotState {
|
|
2615
2454
|
readonly path: string;
|
|
2616
2455
|
readonly value?: Schema.Json;
|
|
2617
2456
|
}
|
|
@@ -2624,12 +2463,12 @@ export declare namespace Machine {
|
|
|
2624
2463
|
* @category models
|
|
2625
2464
|
* @since 0.4.0
|
|
2626
2465
|
*/
|
|
2627
|
-
interface EncodedSnapshotCompletion {
|
|
2466
|
+
export interface EncodedSnapshotCompletion {
|
|
2628
2467
|
readonly path: string;
|
|
2629
2468
|
readonly output?: Schema.Json;
|
|
2630
2469
|
}
|
|
2631
2470
|
/** Encoded values and paths retained by one history pseudo-state. */
|
|
2632
|
-
interface EncodedSnapshotHistoryEntry {
|
|
2471
|
+
export interface EncodedSnapshotHistoryEntry {
|
|
2633
2472
|
readonly mode: "shallow" | "deep";
|
|
2634
2473
|
readonly active: ReadonlyArray<string>;
|
|
2635
2474
|
readonly values: Readonly<Record<string, Schema.Json>>;
|
|
@@ -2647,7 +2486,7 @@ export declare namespace Machine {
|
|
|
2647
2486
|
* @category models
|
|
2648
2487
|
* @since 0.4.0
|
|
2649
2488
|
*/
|
|
2650
|
-
interface EncodedSnapshot {
|
|
2489
|
+
export interface EncodedSnapshot {
|
|
2651
2490
|
readonly version: 2;
|
|
2652
2491
|
readonly _tag: "MachineSnapshot";
|
|
2653
2492
|
readonly active: ReadonlyArray<EncodedSnapshotState>;
|
|
@@ -2660,12 +2499,12 @@ export declare namespace Machine {
|
|
|
2660
2499
|
* @category models
|
|
2661
2500
|
* @since 0.4.0
|
|
2662
2501
|
*/
|
|
2663
|
-
interface SnapshotCompletion {
|
|
2502
|
+
export interface SnapshotCompletion {
|
|
2664
2503
|
readonly path: string;
|
|
2665
2504
|
readonly output: unknown;
|
|
2666
2505
|
}
|
|
2667
2506
|
/** Decoded values and paths retained by one history pseudo-state. */
|
|
2668
|
-
interface SnapshotHistoryEntry {
|
|
2507
|
+
export interface SnapshotHistoryEntry {
|
|
2669
2508
|
readonly mode: "shallow" | "deep";
|
|
2670
2509
|
readonly active: ReadonlyArray<string>;
|
|
2671
2510
|
readonly values: Readonly<Record<string, unknown>>;
|
|
@@ -2686,7 +2525,7 @@ export declare namespace Machine {
|
|
|
2686
2525
|
* @category models
|
|
2687
2526
|
* @since 0.4.0
|
|
2688
2527
|
*/
|
|
2689
|
-
interface SnapshotMetadata {
|
|
2528
|
+
export interface SnapshotMetadata {
|
|
2690
2529
|
readonly completed?: ReadonlyArray<SnapshotCompletion>;
|
|
2691
2530
|
readonly history?: Readonly<Record<string, SnapshotHistoryEntry>>;
|
|
2692
2531
|
}
|
|
@@ -2697,7 +2536,7 @@ export declare namespace Machine {
|
|
|
2697
2536
|
* @category models
|
|
2698
2537
|
* @since 0.4.0
|
|
2699
2538
|
*/
|
|
2700
|
-
interface AtomicSnapshot<Path extends string, Value> extends SnapshotMetadata {
|
|
2539
|
+
export interface AtomicSnapshot<Path extends string, Value> extends SnapshotMetadata {
|
|
2701
2540
|
readonly path: Path;
|
|
2702
2541
|
readonly value: Value;
|
|
2703
2542
|
}
|
|
@@ -2708,7 +2547,7 @@ export declare namespace Machine {
|
|
|
2708
2547
|
* @category models
|
|
2709
2548
|
* @since 0.4.0
|
|
2710
2549
|
*/
|
|
2711
|
-
interface CompoundSnapshot<Path extends string, Value, Child> extends SnapshotMetadata {
|
|
2550
|
+
export interface CompoundSnapshot<Path extends string, Value, Child> extends SnapshotMetadata {
|
|
2712
2551
|
readonly path: Path;
|
|
2713
2552
|
readonly value: Value;
|
|
2714
2553
|
readonly state: Child;
|
|
@@ -2720,7 +2559,7 @@ export declare namespace Machine {
|
|
|
2720
2559
|
* @category models
|
|
2721
2560
|
* @since 0.4.0
|
|
2722
2561
|
*/
|
|
2723
|
-
interface ParallelSnapshot<Path extends string, Value, Regions> extends SnapshotMetadata {
|
|
2562
|
+
export interface ParallelSnapshot<Path extends string, Value, Regions> extends SnapshotMetadata {
|
|
2724
2563
|
readonly path: Path;
|
|
2725
2564
|
readonly value: Value;
|
|
2726
2565
|
readonly states: Regions;
|
|
@@ -2732,7 +2571,7 @@ export declare namespace Machine {
|
|
|
2732
2571
|
* @category utility types
|
|
2733
2572
|
* @since 0.4.0
|
|
2734
2573
|
*/
|
|
2735
|
-
type SnapshotByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
2574
|
+
export type SnapshotByIdentifier<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends infer Node ? Node extends {
|
|
2736
2575
|
readonly type: "parallel";
|
|
2737
2576
|
readonly states: infer Children;
|
|
2738
2577
|
} ? Children extends StateSchemas ? ParallelSnapshot<StateId, StateByIdentifier<States, StateId>, SnapshotRegionsWithPrefix<Children, StateId>> : AtomicSnapshot<StateId, StateByIdentifier<States, StateId>> : Node extends {
|
|
@@ -2744,7 +2583,7 @@ export declare namespace Machine {
|
|
|
2744
2583
|
* @category utility types
|
|
2745
2584
|
* @since 0.4.0
|
|
2746
2585
|
*/
|
|
2747
|
-
type SnapshotWithPrefix<States extends StateSchemas, Prefix extends string> = {
|
|
2586
|
+
export type SnapshotWithPrefix<States extends StateSchemas, Prefix extends string> = {
|
|
2748
2587
|
readonly [Key in ActiveStateKey<States>]: SnapshotByIdentifierWithPath<States, Key, JoinPath<Prefix, Key>>;
|
|
2749
2588
|
}[ActiveStateKey<States>];
|
|
2750
2589
|
/**
|
|
@@ -2754,7 +2593,7 @@ export declare namespace Machine {
|
|
|
2754
2593
|
* @category utility types
|
|
2755
2594
|
* @since 0.4.0
|
|
2756
2595
|
*/
|
|
2757
|
-
type SnapshotRegionsWithPrefix<States extends StateSchemas, Prefix extends string> = {
|
|
2596
|
+
export type SnapshotRegionsWithPrefix<States extends StateSchemas, Prefix extends string> = {
|
|
2758
2597
|
readonly [Key in ActiveStateKey<States>]: SnapshotByIdentifierWithPath<States, Key, JoinPath<Prefix, Key>>;
|
|
2759
2598
|
};
|
|
2760
2599
|
/**
|
|
@@ -2763,7 +2602,7 @@ export declare namespace Machine {
|
|
|
2763
2602
|
* @category utility types
|
|
2764
2603
|
* @since 0.4.0
|
|
2765
2604
|
*/
|
|
2766
|
-
type SnapshotByIdentifierWithPath<States extends StateSchemas, StateId extends ActiveStateKey<States>, Path extends string> = States[StateId] extends {
|
|
2605
|
+
export type SnapshotByIdentifierWithPath<States extends StateSchemas, StateId extends ActiveStateKey<States>, Path extends string> = States[StateId] extends {
|
|
2767
2606
|
readonly type: "parallel";
|
|
2768
2607
|
readonly states: infer Children;
|
|
2769
2608
|
} ? Children extends StateSchemas ? ParallelSnapshot<Path, NodeValue<States[StateId]>, SnapshotRegionsWithPrefix<Children, Path>> : AtomicSnapshot<Path, NodeValue<States[StateId]>> : States[StateId] extends {
|
|
@@ -2779,7 +2618,7 @@ export declare namespace Machine {
|
|
|
2779
2618
|
* @category utility types
|
|
2780
2619
|
* @since 0.4.0
|
|
2781
2620
|
*/
|
|
2782
|
-
type CompleteSnapshotContaining<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotWithPrefix<States, Owner, "">;
|
|
2621
|
+
export type CompleteSnapshotContaining<States extends StateSchemas, Owner extends StateIdentifier<States>> = HistorySnapshotWithPrefix<States, Owner, "">;
|
|
2783
2622
|
/**
|
|
2784
2623
|
* Extracts the union of statechart snapshots represented by a state
|
|
2785
2624
|
* definition.
|
|
@@ -2787,7 +2626,7 @@ export declare namespace Machine {
|
|
|
2787
2626
|
* @category models
|
|
2788
2627
|
* @since 0.4.0
|
|
2789
2628
|
*/
|
|
2790
|
-
type Snapshot<States extends StateSchemas> = {
|
|
2629
|
+
export type Snapshot<States extends StateSchemas> = {
|
|
2791
2630
|
readonly [StateId in ActiveStateKey<States>]: SnapshotByIdentifier<States, StateId & StateIdentifier<States>>;
|
|
2792
2631
|
}[ActiveStateKey<States>];
|
|
2793
2632
|
/**
|
|
@@ -2796,21 +2635,21 @@ export declare namespace Machine {
|
|
|
2796
2635
|
* @category utility types
|
|
2797
2636
|
* @since 0.4.0
|
|
2798
2637
|
*/
|
|
2799
|
-
type RootStateIdentifier<StateId extends string> = StateId extends string ? "" : never;
|
|
2638
|
+
export type RootStateIdentifier<StateId extends string> = StateId extends string ? "" : never;
|
|
2800
2639
|
/**
|
|
2801
2640
|
* Extracts the public snapshot shape that contains a final state path.
|
|
2802
2641
|
*
|
|
2803
2642
|
* @category utility types
|
|
2804
2643
|
* @since 0.4.0
|
|
2805
2644
|
*/
|
|
2806
|
-
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;
|
|
2645
|
+
export 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;
|
|
2807
2646
|
/**
|
|
2808
2647
|
* Extracts state identifiers whose state-tree definition marks them final.
|
|
2809
2648
|
*
|
|
2810
2649
|
* @category utility types
|
|
2811
2650
|
* @since 0.4.0
|
|
2812
2651
|
*/
|
|
2813
|
-
type FinalStateFromDefinition<States extends StateSchemas> = {
|
|
2652
|
+
export type FinalStateFromDefinition<States extends StateSchemas> = {
|
|
2814
2653
|
readonly [StateId in StateIdentifier<States>]: NodeByIdentifier<States, StateId> extends {
|
|
2815
2654
|
readonly type: "final";
|
|
2816
2655
|
} ? StateId : never;
|
|
@@ -2821,7 +2660,7 @@ export declare namespace Machine {
|
|
|
2821
2660
|
* @category utility types
|
|
2822
2661
|
* @since 0.4.0
|
|
2823
2662
|
*/
|
|
2824
|
-
type EventByTag<Events extends ReadonlyArray<TaggedSchema>, Tag extends TagOf<Events[number]>> = Extract<EventOf<Events>, {
|
|
2663
|
+
export type EventByTag<Events extends ReadonlyArray<TaggedSchema>, Tag extends TagOf<Events[number]>> = Extract<EventOf<Events>, {
|
|
2825
2664
|
readonly _tag: Tag;
|
|
2826
2665
|
}> | (EventOf<Events> extends infer Event ? Event extends {
|
|
2827
2666
|
readonly _tag: infer EventTag extends PropertyKey;
|
|
@@ -2829,7 +2668,7 @@ export declare namespace Machine {
|
|
|
2829
2668
|
readonly _tag: Tag;
|
|
2830
2669
|
} : never : never : never);
|
|
2831
2670
|
/**
|
|
2832
|
-
* Opaque state construction returned by a
|
|
2671
|
+
* Opaque state construction returned by a history default's `target`.
|
|
2833
2672
|
*
|
|
2834
2673
|
* The machine resolves the instruction through the selected state schema
|
|
2835
2674
|
* while planning. Its decoded value is intentionally unavailable until
|
|
@@ -2838,8 +2677,8 @@ export declare namespace Machine {
|
|
|
2838
2677
|
* @category models
|
|
2839
2678
|
* @since 0.4.0
|
|
2840
2679
|
*/
|
|
2841
|
-
interface StateConstruction<out Result> {
|
|
2842
|
-
readonly [
|
|
2680
|
+
export interface StateConstruction<out Result> {
|
|
2681
|
+
readonly [StateConstructionTypeId]: Result;
|
|
2843
2682
|
}
|
|
2844
2683
|
/**
|
|
2845
2684
|
* Machine-bound target instruction accepted from transition handlers.
|
|
@@ -2847,9 +2686,9 @@ export declare namespace Machine {
|
|
|
2847
2686
|
* @category models
|
|
2848
2687
|
* @since 0.4.0
|
|
2849
2688
|
*/
|
|
2850
|
-
interface Target<States extends StateSchemas, StateId extends StateIdentifier<States>> {
|
|
2689
|
+
export interface Target<States extends StateSchemas, StateId extends StateIdentifier<States>> {
|
|
2851
2690
|
readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId;
|
|
2852
|
-
readonly [
|
|
2691
|
+
readonly [TargetSnapshotTypeId]?: SnapshotByIdentifier<States, StateId>;
|
|
2853
2692
|
readonly path: StateId;
|
|
2854
2693
|
readonly value: StateByIdentifier<States, StateId>;
|
|
2855
2694
|
readonly values?: Partial<{
|
|
@@ -2863,8 +2702,8 @@ export declare namespace Machine {
|
|
|
2863
2702
|
* @category models
|
|
2864
2703
|
* @since 0.21.0
|
|
2865
2704
|
*/
|
|
2866
|
-
interface StateUpdate<States extends StateSchemas, StateId extends ValuedStateIdentifier<States>> {
|
|
2867
|
-
readonly [
|
|
2705
|
+
export interface StateUpdate<States extends StateSchemas, StateId extends ValuedStateIdentifier<States>> {
|
|
2706
|
+
readonly [StateUpdateTypeId]: {
|
|
2868
2707
|
readonly states: Types.Covariant<States>;
|
|
2869
2708
|
readonly owner: Types.Covariant<StateId>;
|
|
2870
2709
|
};
|
|
@@ -2876,18 +2715,13 @@ export declare namespace Machine {
|
|
|
2876
2715
|
* @category models
|
|
2877
2716
|
* @since 0.22.0
|
|
2878
2717
|
*/
|
|
2879
|
-
interface CombinedTarget<Result, States extends StateSchemas, Owner extends ValuedStateIdentifier<States>> {
|
|
2880
|
-
readonly [
|
|
2718
|
+
export interface CombinedTarget<Result, States extends StateSchemas, Owner extends ValuedStateIdentifier<States>> {
|
|
2719
|
+
readonly [CombinedTargetTypeId]: {
|
|
2881
2720
|
readonly result: Types.Covariant<Result>;
|
|
2882
2721
|
readonly states: Types.Covariant<States>;
|
|
2883
2722
|
readonly owner: Types.Covariant<Owner>;
|
|
2884
2723
|
};
|
|
2885
2724
|
}
|
|
2886
|
-
/** @internal */
|
|
2887
|
-
type StateUpdateBuilder<States extends StateSchemas, StateId extends ValuedStateIdentifier<States>> = {
|
|
2888
|
-
readonly decoded: (value: StateByIdentifier<States, StateId>) => StateUpdate<States, StateId>;
|
|
2889
|
-
readonly from: FromCallable<readonly [input: SchemaByIdentifier<States, StateId>["~type.make.in"]], StateUpdate<States, StateId>>;
|
|
2890
|
-
};
|
|
2891
2725
|
/**
|
|
2892
2726
|
* Opaque result returned by an explicitly targetless transition.
|
|
2893
2727
|
*
|
|
@@ -2897,12 +2731,12 @@ export declare namespace Machine {
|
|
|
2897
2731
|
* @category models
|
|
2898
2732
|
* @since 0.10.0
|
|
2899
2733
|
*/
|
|
2900
|
-
interface NoTarget {
|
|
2901
|
-
readonly [
|
|
2734
|
+
export interface NoTarget {
|
|
2735
|
+
readonly [NoTargetTypeId]: typeof NoTargetTypeId;
|
|
2902
2736
|
}
|
|
2903
2737
|
/**
|
|
2904
|
-
* Opaque result
|
|
2905
|
-
* current event
|
|
2738
|
+
* Opaque result of `select.decline()`, when a transition does not accept the
|
|
2739
|
+
* current event.
|
|
2906
2740
|
*
|
|
2907
2741
|
* Declining selects no transition and discards operations enqueued by that
|
|
2908
2742
|
* resolver. Hierarchical event and eventless dispatch continues with the
|
|
@@ -2911,11 +2745,15 @@ export declare namespace Machine {
|
|
|
2911
2745
|
* @category models
|
|
2912
2746
|
* @since 0.17.0
|
|
2913
2747
|
*/
|
|
2914
|
-
interface Declined {
|
|
2915
|
-
readonly [
|
|
2748
|
+
export interface Declined {
|
|
2749
|
+
readonly [DeclinedTypeId]: typeof DeclinedTypeId;
|
|
2916
2750
|
}
|
|
2917
|
-
/**
|
|
2918
|
-
|
|
2751
|
+
/**
|
|
2752
|
+
* Static acceptance contract of one transition definition: `"declinable"`
|
|
2753
|
+
* when it has a `guard` or lists `{ decline: true }` in `branches`, so it may
|
|
2754
|
+
* leave the event to the next candidate, and `"required"` otherwise.
|
|
2755
|
+
*/
|
|
2756
|
+
export type TransitionAcceptance = "required" | "declinable";
|
|
2919
2757
|
/**
|
|
2920
2758
|
* Transition instruction that restores a history pseudo-state's parent.
|
|
2921
2759
|
*
|
|
@@ -2926,8 +2764,8 @@ export declare namespace Machine {
|
|
|
2926
2764
|
* @category models
|
|
2927
2765
|
* @since 0.4.0
|
|
2928
2766
|
*/
|
|
2929
|
-
interface HistoryTarget<States extends StateSchemas, HistoryId extends HistoryIdentifier<States>> {
|
|
2930
|
-
readonly [
|
|
2767
|
+
export interface HistoryTarget<States extends StateSchemas, HistoryId extends HistoryIdentifier<States>> {
|
|
2768
|
+
readonly [HistoryTargetTypeId]: typeof HistoryTargetTypeId;
|
|
2931
2769
|
readonly path: HistoryId;
|
|
2932
2770
|
readonly parent: Extract<ParentPath<HistoryId>, StateIdentifier<States>>;
|
|
2933
2771
|
}
|
|
@@ -2938,159 +2776,41 @@ export declare namespace Machine {
|
|
|
2938
2776
|
* @category models
|
|
2939
2777
|
* @since 0.13.0
|
|
2940
2778
|
*/
|
|
2941
|
-
interface InitialTarget<StateId extends string> {
|
|
2779
|
+
export interface InitialTarget<StateId extends string> {
|
|
2942
2780
|
readonly [Topology.TargetTypeId]: typeof Topology.TargetTypeId;
|
|
2943
|
-
readonly [
|
|
2944
|
-
readonly [
|
|
2781
|
+
readonly [TargetSnapshotTypeId]?: never;
|
|
2782
|
+
readonly [InitialTargetTypeId]: typeof InitialTargetTypeId;
|
|
2945
2783
|
readonly _tag: "InitialTarget";
|
|
2946
2784
|
readonly path: StateId;
|
|
2947
2785
|
readonly value: never;
|
|
2948
2786
|
readonly values?: never;
|
|
2949
2787
|
}
|
|
2950
|
-
/** Branded
|
|
2951
|
-
interface ChoiceTargetInstruction<ChoiceId extends string = string> {
|
|
2952
|
-
readonly [
|
|
2788
|
+
/** Branded instruction that enters a choice pseudo-state, before its parent is checked against a machine. */
|
|
2789
|
+
export interface ChoiceTargetInstruction<ChoiceId extends string = string> {
|
|
2790
|
+
readonly [ChoiceTargetTypeId]: typeof ChoiceTargetTypeId;
|
|
2953
2791
|
readonly path: ChoiceId;
|
|
2954
2792
|
readonly parent: ParentPath<ChoiceId>;
|
|
2955
2793
|
readonly values?: Readonly<Record<string, unknown>>;
|
|
2956
2794
|
}
|
|
2957
2795
|
/** Transition instruction that enters a transient choice pseudo-state. */
|
|
2958
|
-
interface ChoiceTarget<States extends StateSchemas, ChoiceId extends ChoiceIdentifier<States>> extends ChoiceTargetInstruction<ChoiceId> {
|
|
2796
|
+
export interface ChoiceTarget<States extends StateSchemas, ChoiceId extends ChoiceIdentifier<States>> extends ChoiceTargetInstruction<ChoiceId> {
|
|
2959
2797
|
readonly parent: Extract<ParentPath<ChoiceId>, StateIdentifier<States>>;
|
|
2960
2798
|
}
|
|
2961
|
-
/** Builder containing only history pseudo-state paths. */
|
|
2962
|
-
type HistoryTargetBuilder<States extends StateSchemas> = HistoryTargetBuilderWithPrefix<States, States, "">;
|
|
2963
|
-
/**
|
|
2964
|
-
* Builder for complete transition snapshots.
|
|
2965
|
-
*
|
|
2966
|
-
* **When to use**
|
|
2967
|
-
*
|
|
2968
|
-
* Use when a transition enters an inactive root or otherwise needs to provide
|
|
2969
|
-
* every active child below the selected root.
|
|
2970
|
-
*
|
|
2971
|
-
* @category utility types
|
|
2972
|
-
* @since 0.4.0
|
|
2973
|
-
*/
|
|
2974
|
-
type FullTargetBuilder<States extends StateSchemas> = [InitialEntryStateKey<States>] extends [never] ? FullSnapshotBuilderWithPrefix<States> : FullSnapshotBuilderWithPrefix<States> & FullInitialTargetBuilder<States>;
|
|
2975
2799
|
/**
|
|
2976
|
-
*
|
|
2800
|
+
* Function that constructs a complete fallback configuration containing a
|
|
2801
|
+
* history owner, supplied as `target` to a history default.
|
|
2977
2802
|
*
|
|
2978
2803
|
* @category utility types
|
|
2979
2804
|
* @since 0.4.0
|
|
2980
2805
|
*/
|
|
2981
|
-
type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = (construction: HistoryConstruction<States[""], Owner>) => StateConstruction<CompleteSnapshotContaining<States, Owner>>;
|
|
2982
|
-
/**
|
|
2983
|
-
* Builder for source-local transition targets.
|
|
2984
|
-
*
|
|
2985
|
-
* **When to use**
|
|
2986
|
-
*
|
|
2987
|
-
* Use when a transition stays inside the nearest active compound ancestor of
|
|
2988
|
-
* the source state and should preserve active ancestor and sibling values.
|
|
2989
|
-
*
|
|
2990
|
-
* @category utility types
|
|
2991
|
-
* @since 0.4.0
|
|
2992
|
-
*/
|
|
2993
|
-
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> : {} : {};
|
|
2994
|
-
/**
|
|
2995
|
-
* Builder for partial transition targets within the active source root.
|
|
2996
|
-
*
|
|
2997
|
-
* **When to use**
|
|
2998
|
-
*
|
|
2999
|
-
* Use when a transition should replace one descendant of the active source
|
|
3000
|
-
* root while preserving unmentioned active ancestors or parallel regions.
|
|
3001
|
-
*
|
|
3002
|
-
* @category utility types
|
|
3003
|
-
* @since 0.4.0
|
|
3004
|
-
*/
|
|
3005
|
-
type BranchTargetBuilder<States extends StateSchemas, Source extends StateNodeIdentifier<States>> = BranchTargetBuilderForRoot<States, Extract<"" extends keyof States ? "" : RootStateIdentifier<Source>, ActiveStateKey<States>>, Source>;
|
|
3006
|
-
/**
|
|
3007
|
-
* Machine-bound target builders available in transition contexts.
|
|
3008
|
-
*
|
|
3009
|
-
* **Details**
|
|
3010
|
-
*
|
|
3011
|
-
* `none()` handles without selecting a destination, `local` targets the
|
|
3012
|
-
* nearest compound scope for the source state, `branch` targets descendants
|
|
3013
|
-
* of the source root, and `full` builds complete snapshots for any root.
|
|
3014
|
-
*
|
|
3015
|
-
* These builders control how the next active configuration is assembled; they
|
|
3016
|
-
* do not directly control state re-entry. Exit and entry paths are derived
|
|
3017
|
-
* from the previous and next active paths. Shared active ancestors remain
|
|
3018
|
-
* entered even when a `full` target supplies their values again. Use an event
|
|
3019
|
-
* transition with `reenter: true` when the source should explicitly exit and
|
|
3020
|
-
* enter again.
|
|
3021
|
-
*
|
|
3022
|
-
* @category models
|
|
3023
|
-
* @since 0.4.0
|
|
3024
|
-
*/
|
|
3025
|
-
interface TargetBuilder<in out States extends StateSchemas, in out Source extends StateNodeIdentifier<States>> {
|
|
3026
|
-
/**
|
|
3027
|
-
* Selects an explicitly targetless transition.
|
|
3028
|
-
*
|
|
3029
|
-
* The event or lifecycle outcome is handled and queued operations are
|
|
3030
|
-
* retained, while the current state configuration remains the transition
|
|
3031
|
-
* result.
|
|
3032
|
-
*
|
|
3033
|
-
* @since 0.10.0
|
|
3034
|
-
*/
|
|
3035
|
-
readonly none: () => NoTarget;
|
|
3036
|
-
/**
|
|
3037
|
-
* Moves to another state in the same local group. The value of the state
|
|
3038
|
-
* containing that group, and values in other active branches, are kept.
|
|
3039
|
-
*
|
|
3040
|
-
* @since 0.4.0
|
|
3041
|
-
*/
|
|
3042
|
-
readonly local: LocalTargetBuilder<States, Source>;
|
|
3043
|
-
/**
|
|
3044
|
-
* Moves to a state elsewhere under the current top-level state. Parent
|
|
3045
|
-
* values change only when their builder methods are explicitly called;
|
|
3046
|
-
* other active branches are kept.
|
|
3047
|
-
*
|
|
3048
|
-
* @since 0.4.0
|
|
3049
|
-
*/
|
|
3050
|
-
readonly branch: BranchTargetBuilder<States, Source>;
|
|
3051
|
-
/**
|
|
3052
|
-
* Moves to any top-level state by building its complete active state
|
|
3053
|
-
* configuration.
|
|
3054
|
-
*
|
|
3055
|
-
* **Details**
|
|
3056
|
-
*
|
|
3057
|
-
* When the target contains nested states, an active child must be selected.
|
|
3058
|
-
* When it contains parallel states, an active state must be provided for
|
|
3059
|
-
* every region.
|
|
3060
|
-
*
|
|
3061
|
-
* @since 0.4.0
|
|
3062
|
-
*/
|
|
3063
|
-
readonly full: FullTargetBuilder<States>;
|
|
3064
|
-
/** Restores a declared shallow or deep history pseudo-state. */
|
|
3065
|
-
readonly history: HistoryTargetBuilder<States>;
|
|
3066
|
-
}
|
|
3067
|
-
/**
|
|
3068
|
-
* Opaque exact destination selected while a machine definition is captured.
|
|
3069
|
-
* The selection contains topology only; state values are constructed later
|
|
3070
|
-
* by the selected branch's resolver.
|
|
3071
|
-
*
|
|
3072
|
-
* @category models
|
|
3073
|
-
* @since 0.14.0
|
|
3074
|
-
*/
|
|
3075
|
-
interface TargetSelection<out Result, out Path extends string | undefined = string | undefined, out Kind extends Topology.TargetSelectionKind = Topology.TargetSelectionKind, out Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> {
|
|
3076
|
-
readonly [Topology.TargetSelectionTypeId]: typeof Topology.TargetSelectionTypeId;
|
|
3077
|
-
readonly kind: Kind;
|
|
3078
|
-
readonly scope: Scope;
|
|
3079
|
-
readonly path: Path;
|
|
3080
|
-
readonly "~effect/Machine/TargetSelectionResult"?: Types.Covariant<Result>;
|
|
3081
|
-
}
|
|
3082
|
-
type SelectionValue<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state", Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> = TargetSelection<Builder, Path, Kind, Scope>;
|
|
3083
|
-
type SelectionMethod<Builder, Path extends string, Kind extends Topology.TargetSelectionKind = "state", Scope extends Topology.TargetSelectionScope | undefined = Topology.TargetSelectionScope | undefined> = () => SelectionValue<Builder, Path, Kind, Scope>;
|
|
3084
|
-
type RootBuilder<Builder> = Builder extends {
|
|
3085
|
-
readonly "": infer Root;
|
|
3086
|
-
} ? Root : never;
|
|
2806
|
+
export type HistoryDefaultTargetBuilder<States extends StateSchemas, Owner extends StateIdentifier<States>> = (construction: HistoryConstruction<States[""], Owner>) => StateConstruction<CompleteSnapshotContaining<States, Owner>>;
|
|
3087
2807
|
/**
|
|
3088
2808
|
* Context passed to a state/event handler.
|
|
3089
2809
|
*
|
|
3090
2810
|
* @category models
|
|
3091
2811
|
* @since 0.4.0
|
|
3092
2812
|
*/
|
|
3093
|
-
type HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2813
|
+
export type HandlerContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3094
2814
|
/** Value owned by the state whose handler is running. */
|
|
3095
2815
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3096
2816
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
@@ -3110,7 +2830,7 @@ export declare namespace Machine {
|
|
|
3110
2830
|
* @category models
|
|
3111
2831
|
* @since 0.4.0
|
|
3112
2832
|
*/
|
|
3113
|
-
type StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2833
|
+
export type StateActionContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3114
2834
|
/** Value owned by the state entering or exiting. */
|
|
3115
2835
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3116
2836
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
@@ -3126,7 +2846,7 @@ export declare namespace Machine {
|
|
|
3126
2846
|
* @category models
|
|
3127
2847
|
* @since 0.4.0
|
|
3128
2848
|
*/
|
|
3129
|
-
type InvokeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2849
|
+
export type InvokeContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3130
2850
|
/** Process-owned child operations for dynamic child machine lifecycles. */
|
|
3131
2851
|
readonly children: ChildOwner<EventOf<InputEvents>>;
|
|
3132
2852
|
/** Value owned by the state that owns this invocation. */
|
|
@@ -3146,7 +2866,7 @@ export declare namespace Machine {
|
|
|
3146
2866
|
* @category models
|
|
3147
2867
|
* @since 0.4.0
|
|
3148
2868
|
*/
|
|
3149
|
-
type InvokeSnapshotContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, State, Error, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2869
|
+
export type InvokeSnapshotContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, State, Error, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3150
2870
|
/** Parent-local invocation identifier. */
|
|
3151
2871
|
readonly id: string;
|
|
3152
2872
|
/** Current value of the state that owns the invocation. */
|
|
@@ -3168,7 +2888,7 @@ export declare namespace Machine {
|
|
|
3168
2888
|
* @category models
|
|
3169
2889
|
* @since 0.4.0
|
|
3170
2890
|
*/
|
|
3171
|
-
type InvokeDoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2891
|
+
export type InvokeDoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Output, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3172
2892
|
/** Parent-local invocation identifier. */
|
|
3173
2893
|
readonly id: string;
|
|
3174
2894
|
/** Current value of the state that owns the invocation. */
|
|
@@ -3185,7 +2905,7 @@ export declare namespace Machine {
|
|
|
3185
2905
|
readonly output: Output;
|
|
3186
2906
|
};
|
|
3187
2907
|
/** Context passed to a Stream invocation's element transition. */
|
|
3188
|
-
type InvokeElementContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Element, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2908
|
+
export type InvokeElementContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Element, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3189
2909
|
/** Parent-local invocation identifier. */
|
|
3190
2910
|
readonly id: string;
|
|
3191
2911
|
/** Current value of the state that owns the Stream invocation. */
|
|
@@ -3202,7 +2922,7 @@ export declare namespace Machine {
|
|
|
3202
2922
|
readonly element: Element;
|
|
3203
2923
|
};
|
|
3204
2924
|
/** Context passed to an invocation typed-failure transition. */
|
|
3205
|
-
type InvokeFailureContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Error, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2925
|
+
export type InvokeFailureContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Error, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3206
2926
|
/** Parent-local invocation identifier. */
|
|
3207
2927
|
readonly id: string;
|
|
3208
2928
|
/** Current value of the state that owns the invocation. */
|
|
@@ -3224,7 +2944,7 @@ export declare namespace Machine {
|
|
|
3224
2944
|
* @category models
|
|
3225
2945
|
* @since 0.4.0
|
|
3226
2946
|
*/
|
|
3227
|
-
type AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2947
|
+
export type AlwaysContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3228
2948
|
/** Current value of the state evaluating the eventless transition. */
|
|
3229
2949
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3230
2950
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
@@ -3244,7 +2964,7 @@ export declare namespace Machine {
|
|
|
3244
2964
|
* @category models
|
|
3245
2965
|
* @since 0.4.0
|
|
3246
2966
|
*/
|
|
3247
|
-
type DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2967
|
+
export type DoneContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3248
2968
|
/** Current value of the state whose child configuration completed. */
|
|
3249
2969
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3250
2970
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
@@ -3261,7 +2981,7 @@ export declare namespace Machine {
|
|
|
3261
2981
|
readonly root: StateByIdentifier<States, Extract<"", StateIdentifier<States>>>;
|
|
3262
2982
|
};
|
|
3263
2983
|
/** Context passed to a transient choice resolver. There is no `state` value. */
|
|
3264
|
-
type ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
2984
|
+
export type ChoiceContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = MachineReferences<InputEvents, ParentEvents> & {
|
|
3265
2985
|
/** Value owned by the choice node's immediate schema-backed parent. */
|
|
3266
2986
|
readonly containingState: StateByIdentifier<States, Extract<ImmediateParentStateIdentifier<ChoiceId>, StateIdentifier<States>>>;
|
|
3267
2987
|
/** Schema-backed ancestor values keyed by their complete state paths. */
|
|
@@ -3279,7 +2999,7 @@ export declare namespace Machine {
|
|
|
3279
2999
|
* @category models
|
|
3280
3000
|
* @since 0.4.0
|
|
3281
3001
|
*/
|
|
3282
|
-
interface FinalOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
3002
|
+
export interface FinalOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
3283
3003
|
/** Decoded value owned by the final state. */
|
|
3284
3004
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3285
3005
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
@@ -3295,7 +3015,7 @@ export declare namespace Machine {
|
|
|
3295
3015
|
* @category utility types
|
|
3296
3016
|
* @since 0.4.0
|
|
3297
3017
|
*/
|
|
3298
|
-
type ParallelOutputRegions<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends {
|
|
3018
|
+
export type ParallelOutputRegions<States extends StateSchemas, StateId extends StateIdentifier<States>> = NodeByIdentifier<States, StateId> extends {
|
|
3299
3019
|
readonly type: "parallel";
|
|
3300
3020
|
readonly states: infer Children extends StateSchemas;
|
|
3301
3021
|
} ? {
|
|
@@ -3307,7 +3027,7 @@ export declare namespace Machine {
|
|
|
3307
3027
|
* @category models
|
|
3308
3028
|
* @since 0.4.0
|
|
3309
3029
|
*/
|
|
3310
|
-
interface ParallelOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
3030
|
+
export interface ParallelOutputContext<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>> {
|
|
3311
3031
|
/** Decoded value owned by the completed parallel state. */
|
|
3312
3032
|
readonly state: StateByIdentifier<States, StateId>;
|
|
3313
3033
|
/** Value owned by the nearest schema-backed ancestor, when one exists. */
|
|
@@ -3325,68 +3045,37 @@ export declare namespace Machine {
|
|
|
3325
3045
|
* @category utility types
|
|
3326
3046
|
* @since 0.4.0
|
|
3327
3047
|
*/
|
|
3328
|
-
type StateActionResult<E, R> = undefined;
|
|
3048
|
+
export type StateActionResult<E, R> = undefined;
|
|
3329
3049
|
/**
|
|
3330
|
-
*
|
|
3050
|
+
* Initial target that a machine resolves at startup.
|
|
3331
3051
|
*
|
|
3332
3052
|
* @category utility types
|
|
3333
3053
|
* @since 0.4.0
|
|
3334
3054
|
*/
|
|
3335
|
-
type InitialResult<States extends StateSchemas, E, R> = InitialTarget<StateIdentifier<States>>;
|
|
3055
|
+
export type InitialResult<States extends StateSchemas, E, R> = InitialTarget<StateIdentifier<States>>;
|
|
3336
3056
|
/**
|
|
3337
|
-
*
|
|
3057
|
+
* Result that a transition declaration resolves to.
|
|
3338
3058
|
*
|
|
3339
3059
|
* **Details**
|
|
3340
3060
|
*
|
|
3341
|
-
*
|
|
3342
|
-
*
|
|
3343
|
-
*
|
|
3344
|
-
*
|
|
3345
|
-
* not accepted as transition targets.
|
|
3346
|
-
*
|
|
3347
|
-
* @category utility types
|
|
3348
|
-
* @since 0.4.0
|
|
3349
|
-
*/
|
|
3350
|
-
type HandlerResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateUpdate<States, ValuedStateIdentifier<States>> | CombinedTarget<Target<States, StateIdentifier<States>> | Snapshot<States> | ChoiceTarget<States, ChoiceIdentifier<States>>, States, ValuedStateIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateUpdate<States, ValuedStateIdentifier<States>>> | NoTarget;
|
|
3351
|
-
/** A choice resolver must always select a typed target synchronously. */
|
|
3352
|
-
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>>>;
|
|
3353
|
-
/**
|
|
3354
|
-
* Extracts the union of handler return values from a handler map.
|
|
3355
|
-
*
|
|
3356
|
-
* @category utility types
|
|
3357
|
-
* @since 0.4.0
|
|
3358
|
-
*/
|
|
3359
|
-
type HandlerEffect<Handlers> = Handlers[keyof Handlers];
|
|
3360
|
-
/**
|
|
3361
|
-
* Extracts the error type from a handler return value.
|
|
3362
|
-
*
|
|
3363
|
-
* @category utility types
|
|
3364
|
-
* @since 0.4.0
|
|
3365
|
-
*/
|
|
3366
|
-
type HandlerError<Handlers> = Effect.Error<HandlerEffect<Handlers>>;
|
|
3367
|
-
/**
|
|
3368
|
-
* Extracts the service requirements from a handler return value.
|
|
3369
|
-
*
|
|
3370
|
-
* @category utility types
|
|
3371
|
-
* @since 0.4.0
|
|
3372
|
-
*/
|
|
3373
|
-
type HandlerServices<Handlers> = Effect.Services<HandlerEffect<Handlers>>;
|
|
3374
|
-
/**
|
|
3375
|
-
* Extracts the return value from an initial state function.
|
|
3061
|
+
* A transition resolves to a complete snapshot, a target, history, or
|
|
3062
|
+
* choice destination, a state-value update, a target combined with an
|
|
3063
|
+
* owner update, or the targetless result of `{ stay: true }`. Raw decoded
|
|
3064
|
+
* state values are not accepted as transition targets.
|
|
3376
3065
|
*
|
|
3377
3066
|
* @category utility types
|
|
3378
3067
|
* @since 0.4.0
|
|
3379
3068
|
*/
|
|
3380
|
-
type
|
|
3069
|
+
export type HandlerResult<States extends StateSchemas, E, R> = Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateUpdate<States, ValuedStateIdentifier<States>> | CombinedTarget<Target<States, StateIdentifier<States>> | Snapshot<States> | ChoiceTarget<States, ChoiceIdentifier<States>>, States, ValuedStateIdentifier<States>> | StateConstruction<Snapshot<States> | Target<States, StateIdentifier<States>> | HistoryTarget<States, HistoryIdentifier<States>> | ChoiceTarget<States, ChoiceIdentifier<States>> | StateUpdate<States, ValuedStateIdentifier<States>>> | NoTarget;
|
|
3381
3070
|
/**
|
|
3382
3071
|
* Extracts the return value from an entry or exit action.
|
|
3383
3072
|
*
|
|
3384
3073
|
* @category utility types
|
|
3385
3074
|
* @since 0.4.0
|
|
3386
3075
|
*/
|
|
3387
|
-
type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3076
|
+
export type StateActionReturn<Config, Key extends "entry" | "exit"> = Key extends keyof Config ? NonNullable<Config[Key]> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3388
3077
|
/** Extracts the return values from a state's history defaults. */
|
|
3389
|
-
type HistoryDefaultReturn<Config> = Config extends {
|
|
3078
|
+
export type HistoryDefaultReturn<Config> = Config extends {
|
|
3390
3079
|
readonly history?: infer History;
|
|
3391
3080
|
} ? {
|
|
3392
3081
|
readonly [Key in keyof NonNullable<History>]: NonNullable<History>[Key] extends {
|
|
@@ -3394,7 +3083,7 @@ export declare namespace Machine {
|
|
|
3394
3083
|
} ? Ret : never;
|
|
3395
3084
|
}[keyof NonNullable<History>] : never;
|
|
3396
3085
|
/** Extracts the return value from a choice resolver. */
|
|
3397
|
-
type ChoiceReturn<Config> = Config extends {
|
|
3086
|
+
export type ChoiceReturn<Config> = Config extends {
|
|
3398
3087
|
readonly choice: infer Choice;
|
|
3399
3088
|
} ? EventTransitionReturn<Choice> : never;
|
|
3400
3089
|
/**
|
|
@@ -3403,7 +3092,7 @@ export declare namespace Machine {
|
|
|
3403
3092
|
* @category utility types
|
|
3404
3093
|
* @since 0.4.0
|
|
3405
3094
|
*/
|
|
3406
|
-
type EventTransitionReturn<Transition> = Transition extends {
|
|
3095
|
+
export type EventTransitionReturn<Transition> = Transition extends {
|
|
3407
3096
|
readonly resolve?: infer Resolve;
|
|
3408
3097
|
} ? NonNullable<Resolve> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3409
3098
|
/**
|
|
@@ -3412,7 +3101,7 @@ export declare namespace Machine {
|
|
|
3412
3101
|
* @category utility types
|
|
3413
3102
|
* @since 0.4.0
|
|
3414
3103
|
*/
|
|
3415
|
-
type EventHandlerReturn<Config> = Config extends {
|
|
3104
|
+
export type EventHandlerReturn<Config> = Config extends {
|
|
3416
3105
|
readonly on?: infer On;
|
|
3417
3106
|
} ? {
|
|
3418
3107
|
readonly [EventTag in keyof On]: EventTransitionReturn<NonNullable<On[EventTag]>>;
|
|
@@ -3423,7 +3112,7 @@ export declare namespace Machine {
|
|
|
3423
3112
|
* @category utility types
|
|
3424
3113
|
* @since 0.4.0
|
|
3425
3114
|
*/
|
|
3426
|
-
type InvokeReturn<Config> = "invoke" extends keyof Config ? Config extends {
|
|
3115
|
+
export type InvokeReturn<Config> = "invoke" extends keyof Config ? Config extends {
|
|
3427
3116
|
readonly invoke?: infer Invoke;
|
|
3428
3117
|
} ? NonNullable<Invoke> extends (...args: any) => infer Resolved ? NonNullable<Resolved> extends ReadonlyArray<infer One> ? One : NonNullable<Resolved> : NonNullable<Invoke> extends ReadonlyArray<infer One> ? One : NonNullable<Invoke> : never : never;
|
|
3429
3118
|
/**
|
|
@@ -3432,10 +3121,10 @@ export declare namespace Machine {
|
|
|
3432
3121
|
* @category utility types
|
|
3433
3122
|
* @since 0.4.0
|
|
3434
3123
|
*/
|
|
3435
|
-
type InvokeResolvedSource<Source> = Source extends LazyProgramValue ? Source : Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3124
|
+
export type InvokeResolvedSource<Source> = Source extends LazyProgramValue ? Source : Source extends (...args: any) => infer Resolved ? Resolved : Source;
|
|
3436
3125
|
type InvokeFactoryResult<Source> = Source extends (...args: any) => infer Resolved ? Resolved : never;
|
|
3437
|
-
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialServices<M> | Services<M>>,
|
|
3438
|
-
type InvokeLogic<Invoke> = Invoke extends {
|
|
3126
|
+
type ChildMachineLogic<Child> = Child extends ChildMachine<string, infer M> ? Logic<Snapshot<States<M>>, EventInput<InputEvent<M>>, Error<M> | ActionError<Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StoppedError, ExcludeCompatibleRuntime<Exclude<ExecutionServices<InitialServices<M> | Services<M>>, MachineRuntime>, Event<M>, EmittedEvent<M>>, Output<M>, InitialError<M> | Error<M> | ActionError<InitialServices<M> | Services<M>> | InfiniteTransitionError | MachineSchemaDecodeError | StartupError | StoppedError> : never;
|
|
3127
|
+
export type InvokeLogic<Invoke> = Invoke extends {
|
|
3439
3128
|
readonly effect: infer Source;
|
|
3440
3129
|
} ? InvokeFactoryResult<Source> extends infer Fx extends Effect.Effect<any, any, any> ? Logic<void, never, Effect.Error<Fx>, Effect.Services<Fx>, Effect.Success<Fx>> : never : Invoke extends {
|
|
3441
3130
|
readonly stream: infer Source;
|
|
@@ -3452,7 +3141,7 @@ export declare namespace Machine {
|
|
|
3452
3141
|
* @category utility types
|
|
3453
3142
|
* @since 0.4.0
|
|
3454
3143
|
*/
|
|
3455
|
-
type InvokeInitialError<Invoke> = Invoke extends {
|
|
3144
|
+
export type InvokeInitialError<Invoke> = Invoke extends {
|
|
3456
3145
|
readonly [InvokeTypeId]: {
|
|
3457
3146
|
readonly initialError: Types.Covariant<infer InitialError>;
|
|
3458
3147
|
};
|
|
@@ -3463,7 +3152,7 @@ export declare namespace Machine {
|
|
|
3463
3152
|
* @category utility types
|
|
3464
3153
|
* @since 0.4.0
|
|
3465
3154
|
*/
|
|
3466
|
-
type InvokeRuntimeError<Invoke> = Invoke extends {
|
|
3155
|
+
export type InvokeRuntimeError<Invoke> = Invoke extends {
|
|
3467
3156
|
readonly [InvokeTypeId]: {
|
|
3468
3157
|
readonly error: Types.Covariant<infer Error>;
|
|
3469
3158
|
};
|
|
@@ -3474,7 +3163,7 @@ export declare namespace Machine {
|
|
|
3474
3163
|
* @category utility types
|
|
3475
3164
|
* @since 0.4.0
|
|
3476
3165
|
*/
|
|
3477
|
-
type InvokeOutput<Invoke> = Invoke extends {
|
|
3166
|
+
export type InvokeOutput<Invoke> = Invoke extends {
|
|
3478
3167
|
readonly [InvokeTypeId]: {
|
|
3479
3168
|
readonly output: Types.Covariant<infer Output>;
|
|
3480
3169
|
};
|
|
@@ -3485,26 +3174,13 @@ export declare namespace Machine {
|
|
|
3485
3174
|
* @category utility types
|
|
3486
3175
|
* @since 0.4.0
|
|
3487
3176
|
*/
|
|
3488
|
-
type InvokeServices<Invoke> = Invoke extends {
|
|
3177
|
+
export type InvokeServices<Invoke> = Invoke extends {
|
|
3489
3178
|
readonly [InvokeTypeId]: {
|
|
3490
3179
|
readonly requirements: Types.Covariant<infer Requirements>;
|
|
3491
3180
|
};
|
|
3492
3181
|
} ? Requirements : LogicServicesOf<InvokeLogic<Invoke>>;
|
|
3493
|
-
/**
|
|
3494
|
-
* Extracts events emitted directly by an invoked child.
|
|
3495
|
-
*
|
|
3496
|
-
* @category utility types
|
|
3497
|
-
* @since 0.4.0
|
|
3498
|
-
*/
|
|
3499
|
-
type InvokeEmits<Invoke> = Invoke extends {
|
|
3500
|
-
readonly [InvokeTypeId]: {
|
|
3501
|
-
readonly emits: Types.Covariant<infer Emitted>;
|
|
3502
|
-
};
|
|
3503
|
-
} ? Emitted : Invoke extends {
|
|
3504
|
-
readonly child: ChildMachine<string, infer M>;
|
|
3505
|
-
} ? EmittedEvent<M> : never;
|
|
3506
3182
|
/** Public parent inputs required by an invoked child machine. */
|
|
3507
|
-
type InvokeParentEvents<Invoke> = Invoke extends {
|
|
3183
|
+
export type InvokeParentEvents<Invoke> = Invoke extends {
|
|
3508
3184
|
readonly [InvokeTypeId]: {
|
|
3509
3185
|
readonly parentEvents: Types.Covariant<infer ParentEvent>;
|
|
3510
3186
|
};
|
|
@@ -3512,7 +3188,7 @@ export declare namespace Machine {
|
|
|
3512
3188
|
readonly child: ChildMachine<string, infer M>;
|
|
3513
3189
|
} ? EventOf<ParentEvents<M>> : never;
|
|
3514
3190
|
/** Extracts transition results returned by invocation lifecycle handlers. */
|
|
3515
|
-
type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ? (Invoke extends {
|
|
3191
|
+
export type InvokeOutcomeReturn<Invoke> = Invoke extends unknown ? (Invoke extends {
|
|
3516
3192
|
readonly [InvokeTypeId]: {
|
|
3517
3193
|
readonly outcomes: Types.Covariant<infer Outcomes>;
|
|
3518
3194
|
};
|
|
@@ -3547,21 +3223,21 @@ export declare namespace Machine {
|
|
|
3547
3223
|
* @category utility types
|
|
3548
3224
|
* @since 0.4.0
|
|
3549
3225
|
*/
|
|
3550
|
-
type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : InvokeCollisionError<InvokeReturn<Config>> | InvokeInitialError<InvokeReturn<Config>> | InvokeOutcomeError<InvokeReturn<Config>>;
|
|
3226
|
+
export type InvokeError<Config> = [InvokeReturn<Config>] extends [never] ? never : InvokeCollisionError<InvokeReturn<Config>> | InvokeInitialError<InvokeReturn<Config>> | InvokeOutcomeError<InvokeReturn<Config>>;
|
|
3551
3227
|
/**
|
|
3552
3228
|
* Extracts the parent service requirement contribution from invoked children.
|
|
3553
3229
|
*
|
|
3554
3230
|
* @category utility types
|
|
3555
3231
|
* @since 0.4.0
|
|
3556
3232
|
*/
|
|
3557
|
-
type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never :
|
|
3233
|
+
export type InvokeRequirements<Config> = [InvokeReturn<Config>] extends [never] ? never : MachineRuntime | InvokeServices<InvokeReturn<Config>> | InvokeOutcomeServices<InvokeReturn<Config>>;
|
|
3558
3234
|
/**
|
|
3559
3235
|
* Extracts the return value from an eventless transition.
|
|
3560
3236
|
*
|
|
3561
3237
|
* @category utility types
|
|
3562
3238
|
* @since 0.4.0
|
|
3563
3239
|
*/
|
|
3564
|
-
type AlwaysReturn<Config> = Config extends {
|
|
3240
|
+
export type AlwaysReturn<Config> = Config extends {
|
|
3565
3241
|
readonly always?: infer Always;
|
|
3566
3242
|
} ? EventTransitionReturn<NonNullable<Always>> : never;
|
|
3567
3243
|
/**
|
|
@@ -3570,117 +3246,40 @@ export declare namespace Machine {
|
|
|
3570
3246
|
* @category utility types
|
|
3571
3247
|
* @since 0.4.0
|
|
3572
3248
|
*/
|
|
3573
|
-
type DoneReturn<Config> = Config extends {
|
|
3249
|
+
export type DoneReturn<Config> = Config extends {
|
|
3574
3250
|
readonly onDone?: infer OnDone;
|
|
3575
3251
|
} ? EventTransitionReturn<NonNullable<OnDone>> : never;
|
|
3576
|
-
/**
|
|
3577
|
-
* Extracts the return value from a final state output function.
|
|
3578
|
-
*
|
|
3579
|
-
* @category utility types
|
|
3580
|
-
* @since 0.4.0
|
|
3581
|
-
*/
|
|
3582
|
-
type FinalOutputReturn<Config> = Config extends {
|
|
3583
|
-
readonly output?: infer Output;
|
|
3584
|
-
} ? NonNullable<Output> extends (...args: any) => infer Ret ? Ret : never : never;
|
|
3585
3252
|
/**
|
|
3586
3253
|
* Extracts all service requirements contributed by a state handler config.
|
|
3587
3254
|
*
|
|
3588
3255
|
* @category utility types
|
|
3589
3256
|
* @since 0.4.0
|
|
3590
3257
|
*/
|
|
3591
|
-
type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config> : never;
|
|
3258
|
+
export type ConfigServices<Config> = Config extends unknown ? [keyof Config] extends [never] ? never : Effect.Services<EventHandlerReturn<Config>> | Effect.Services<AlwaysReturn<Config>> | Effect.Services<DoneReturn<Config>> | Effect.Services<StateActionReturn<Config, "entry">> | Effect.Services<StateActionReturn<Config, "exit">> | Effect.Services<HistoryDefaultReturn<Config>> | Effect.Services<ChoiceReturn<Config>> | InvokeRequirements<Config> : never;
|
|
3592
3259
|
/** The only transition value accepted by machine handler APIs. */
|
|
3593
3260
|
type TransitionConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = Transition<States, StateId, Context, Events, Emits, {}, Reenter, Acceptance>;
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
type TargetBuilderResult<Builder> = (Builder extends (...args: any) => infer Result ? Result : never) | (Builder extends {
|
|
3598
|
-
readonly decoded: (...args: any) => infer Result;
|
|
3599
|
-
} ? Result : never) | (Builder extends {
|
|
3600
|
-
readonly from: (...args: any) => infer Result;
|
|
3601
|
-
} ? Result : never);
|
|
3602
|
-
type SelectedTargetResult<Selection> = SelectionBuilder<Selection> extends infer Builder ? TargetBuilderResult<Builder> : never;
|
|
3603
|
-
/**
|
|
3604
|
-
* Destination construction returned when a transition declares one retained
|
|
3605
|
-
* valued owner with a `{ target, update }` declaration.
|
|
3606
|
-
*
|
|
3607
|
-
* @category models
|
|
3608
|
-
* @since 0.22.0
|
|
3609
|
-
*/
|
|
3610
|
-
interface UpdatingStateConstruction<Result, States extends StateSchemas, Owner extends ValuedStateIdentifier<States>> {
|
|
3611
|
-
/** Combines the selected topology with the required owner replacement. */
|
|
3612
|
-
readonly update: (update: StateUpdate<States, Owner>) => CombinedTarget<UnwrapConstruction<Result>, States, Owner>;
|
|
3613
|
-
}
|
|
3614
|
-
type UpdatingCallable<Callable, States extends StateSchemas, Owner extends ValuedStateIdentifier<States>> = Callable extends {
|
|
3615
|
-
(...args: infer Arguments1): infer Result1;
|
|
3616
|
-
(...args: infer Arguments2): infer Result2;
|
|
3617
|
-
} ? {
|
|
3618
|
-
(...args: Arguments1): UpdatingStateConstruction<Result1, States, Owner>;
|
|
3619
|
-
(...args: Arguments2): UpdatingStateConstruction<Result2, States, Owner>;
|
|
3620
|
-
} : Callable extends (...args: infer Arguments) => infer Result ? (...args: Arguments) => UpdatingStateConstruction<Result, States, Owner> : never;
|
|
3621
|
-
type UpdatingTargetBuilder<Builder, States extends StateSchemas, Owner extends ValuedStateIdentifier<States>> = {
|
|
3622
|
-
readonly [Key in keyof Builder]: Key extends "from" | "decoded" ? UpdatingCallable<Builder[Key], States, Owner> : Builder[Key];
|
|
3623
|
-
};
|
|
3624
|
-
type SelectionSupportsDefaultConstruction<Selection> = SelectionKind<Selection> extends "none" ? true : SelectionBuilder<Selection> extends {
|
|
3625
|
-
readonly from: (...args: infer Args) => any;
|
|
3626
|
-
} ? [] extends Args ? true : false : false;
|
|
3627
|
-
type TransitionResolveContext<Context, Selection> = Omit<Context, "target"> & (SelectionKind<Selection> extends "none" ? {} : {
|
|
3628
|
-
readonly target: SelectionBuilder<Selection>;
|
|
3629
|
-
});
|
|
3630
|
-
/** Context capability available only to explicitly declinable resolvers. */
|
|
3631
|
-
interface DeclineCapability {
|
|
3632
|
-
/** Declines this candidate and continues hierarchical transition selection. */
|
|
3633
|
-
readonly decline: () => Declined;
|
|
3634
|
-
}
|
|
3635
|
-
/** One named destination declared by a branching transition. */
|
|
3636
|
-
interface TransitionBranchInput<Selection extends TargetSelection<any, any, any> = TargetSelection<any, any, any>> {
|
|
3637
|
-
/** Exact topology destination available to the branching resolver. */
|
|
3638
|
-
readonly target: Selection;
|
|
3639
|
-
/** Optional human-readable branch label used by visualization tooling. */
|
|
3640
|
-
readonly title?: string;
|
|
3641
|
-
}
|
|
3642
|
-
/** Opaque evidence that a branching resolver selected one declared branch. */
|
|
3643
|
-
interface SelectedBranch<out Key extends string, out Result> {
|
|
3644
|
-
readonly [Topology.SelectedBranchTypeId]: {
|
|
3261
|
+
/** Opaque evidence that `resolve` selected one declared branch. */
|
|
3262
|
+
export interface SelectedBranch<out Key extends string, out Result> {
|
|
3263
|
+
readonly [SelectedBranchTypeId]: {
|
|
3645
3264
|
readonly key: Types.Covariant<Key>;
|
|
3646
3265
|
readonly result: Types.Covariant<Result>;
|
|
3647
3266
|
};
|
|
3648
3267
|
}
|
|
3649
|
-
type
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
(...args: Arguments2): SelectedConstruction<Key, Result2>;
|
|
3665
|
-
} : Callable extends (...args: infer Arguments) => infer Result ? (...args: Arguments) => SelectedConstruction<Key, Result> : {};
|
|
3666
|
-
type SelectedBranchBuilderProperties<Builder, Key extends string> = {
|
|
3667
|
-
readonly [Property in keyof Builder]: Builder[Property] extends (...args: any) => any ? SelectedBranchCallable<Builder[Property], Key> : Builder[Property];
|
|
3668
|
-
};
|
|
3669
|
-
/** Target-specific builder that brands every construction with its branch key. */
|
|
3670
|
-
type SelectedBranchBuilder<Builder, Key extends string> = SelectedBranchCallable<Builder, Key> & SelectedBranchBuilderProperties<Builder, Key>;
|
|
3671
|
-
type BranchSelectors<Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
|
|
3672
|
-
readonly [Key in Extract<keyof Branches, string>]: SelectedBranchBuilder<SelectionBuilder<Branches[Key]["target"]>, Key>;
|
|
3673
|
-
};
|
|
3674
|
-
type BranchSelectionResult<Branches extends Readonly<Record<string, TransitionBranchInput>>> = {
|
|
3675
|
-
readonly [Key in Extract<keyof Branches, string>]: SelectedBranch<Key, CompletedBranchResult<SelectedTargetResult<Branches[Key]["target"]>>>;
|
|
3676
|
-
}[Extract<keyof Branches, string>];
|
|
3677
|
-
type TransitionBranchesResolveContext<Context, Branches extends Readonly<Record<string, TransitionBranchInput>>> = Omit<Context, "target"> & {
|
|
3678
|
-
readonly select: BranchSelectors<Branches>;
|
|
3679
|
-
};
|
|
3680
|
-
type InvokeTransition<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateNodeIdentifier<States>, Context> = TransitionConfig<States, Events, Emits, StateId, Context, true, TransitionAcceptance>;
|
|
3681
|
-
type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
3682
|
-
/** Inline state-owned work that runs for the lifetime of its active state. */
|
|
3683
|
-
interface InvokeOwned<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3268
|
+
export type InvokeSource<Value, Context> = Value | ((context: Context) => Value);
|
|
3269
|
+
/**
|
|
3270
|
+
* State-owned work that runs for the lifetime of its active state.
|
|
3271
|
+
*
|
|
3272
|
+
* **Details**
|
|
3273
|
+
*
|
|
3274
|
+
* Every `invoke` entry carries this type-level marker, which records the
|
|
3275
|
+
* state that owns the entry together with the machine's state schemas and
|
|
3276
|
+
* event protocols. The marker property is optional and is never set at
|
|
3277
|
+
* runtime.
|
|
3278
|
+
*
|
|
3279
|
+
* @category models
|
|
3280
|
+
* @since 0.23.0
|
|
3281
|
+
*/
|
|
3282
|
+
export interface InvokeOwned<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3684
3283
|
readonly "~effect/Machine/InvokeOwner"?: Types.Covariant<readonly [States, Events, Emits, StateId, InputEvents, ParentEvents]>;
|
|
3685
3284
|
}
|
|
3686
3285
|
type StoredInvokeConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> = InvokeOwned<States, Events, Emits, StateId, InputEvents, ParentEvents> & ({
|
|
@@ -3752,14 +3351,14 @@ export declare namespace Machine {
|
|
|
3752
3351
|
type LogicRunEffectOf<Value> = Value extends {
|
|
3753
3352
|
readonly run: infer Run;
|
|
3754
3353
|
} ? Run extends (...args: ReadonlyArray<any>) => infer Result ? Result : never : never;
|
|
3755
|
-
type LogicStateOf<Value> = Effect.Success<LogicInitialEffectOf<Value>>;
|
|
3756
|
-
type LogicEventOf<Value> = Value extends {
|
|
3354
|
+
export type LogicStateOf<Value> = Effect.Success<LogicInitialEffectOf<Value>>;
|
|
3355
|
+
export type LogicEventOf<Value> = Value extends {
|
|
3757
3356
|
readonly initial: infer Initial;
|
|
3758
3357
|
} ? Initial extends (scope: infer LogicScope, ...args: ReadonlyArray<any>) => any ? LogicScope extends Logic.Scope<infer Event> ? Event : never : never : never;
|
|
3759
|
-
type LogicErrorOf<Value> = Effect.Error<LogicRunEffectOf<Value>>;
|
|
3760
|
-
type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>;
|
|
3761
|
-
type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>;
|
|
3762
|
-
type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>;
|
|
3358
|
+
export type LogicErrorOf<Value> = Effect.Error<LogicRunEffectOf<Value>>;
|
|
3359
|
+
export type LogicServicesOf<Value> = Effect.Services<LogicInitialEffectOf<Value> | LogicRunEffectOf<Value>>;
|
|
3360
|
+
export type LogicOutputOf<Value> = Effect.Success<LogicRunEffectOf<Value>>;
|
|
3361
|
+
export type LogicInitialErrorOf<Value> = Effect.Error<LogicInitialEffectOf<Value>>;
|
|
3763
3362
|
/** Output construction available to final and output-producing parallel states. */
|
|
3764
3363
|
type OutputHandlerConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, Context> = NodeByIdentifier<States, StateId> extends {
|
|
3765
3364
|
readonly output: Schema.Top;
|
|
@@ -3792,10 +3391,10 @@ export declare namespace Machine {
|
|
|
3792
3391
|
readonly states?: never;
|
|
3793
3392
|
});
|
|
3794
3393
|
/** Context used only when a history node has no previously captured record. */
|
|
3795
|
-
interface HistoryDefaultContext<in out States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, in out ParentId extends StateIdentifier<States>> {
|
|
3394
|
+
export interface HistoryDefaultContext<in out States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, in out ParentId extends StateIdentifier<States>> {
|
|
3796
3395
|
/** Lifecycle event that attempted to restore this history node. */
|
|
3797
3396
|
readonly event: LifecycleEvent<Events>;
|
|
3798
|
-
/**
|
|
3397
|
+
/** Constructs the complete root configuration that contains the history owner. */
|
|
3799
3398
|
readonly target: HistoryDefaultTargetBuilder<States, ParentId>;
|
|
3800
3399
|
/** State path whose child configuration is restored by this history node. */
|
|
3801
3400
|
readonly owner: ParentId;
|
|
@@ -3807,13 +3406,20 @@ export declare namespace Machine {
|
|
|
3807
3406
|
* history owner. This makes the default independent of the transition source
|
|
3808
3407
|
* and provides every inactive ancestor and required parallel region.
|
|
3809
3408
|
*/
|
|
3810
|
-
type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CompleteSnapshotContaining<States, ParentId> | StateConstruction<CompleteSnapshotContaining<States, ParentId>>;
|
|
3409
|
+
export type HistoryDefaultHandler<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> = (context: HistoryDefaultContext<States, Events, Emits, ParentId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => CompleteSnapshotContaining<States, ParentId> | StateConstruction<CompleteSnapshotContaining<States, ParentId>>;
|
|
3811
3410
|
/**
|
|
3812
3411
|
* Fallback implementation for one direct history pseudo-state.
|
|
3813
3412
|
*
|
|
3413
|
+
* **Details**
|
|
3414
|
+
*
|
|
3415
|
+
* `default` runs only when the history state is entered before its owner has
|
|
3416
|
+
* recorded a configuration, and returns the complete configuration to enter.
|
|
3417
|
+
*
|
|
3814
3418
|
* @inline
|
|
3419
|
+
* @category models
|
|
3420
|
+
* @since 0.23.0
|
|
3815
3421
|
*/
|
|
3816
|
-
interface HistoryDefaultEntry<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
3422
|
+
export interface HistoryDefaultEntry<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>> {
|
|
3817
3423
|
/** Builds the complete fallback configuration used before history is first captured. */
|
|
3818
3424
|
readonly default: HistoryDefaultHandler<States, Events, Emits, ParentId>;
|
|
3819
3425
|
}
|
|
@@ -3822,14 +3428,24 @@ export declare namespace Machine {
|
|
|
3822
3428
|
*
|
|
3823
3429
|
* @inlineType HistoryDefaultEntry
|
|
3824
3430
|
*/
|
|
3825
|
-
type HistoryDefaultConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>, Children extends StateSchemas> = {
|
|
3431
|
+
export type HistoryDefaultConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ParentId extends StateIdentifier<States>, Children extends StateSchemas> = {
|
|
3826
3432
|
readonly [Key in HistoryStateKey<Children>]?: HistoryDefaultEntry<States, Events, Emits, ParentId>;
|
|
3827
3433
|
};
|
|
3828
|
-
/**
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3434
|
+
/**
|
|
3435
|
+
* Required implementation for a choice pseudo-state.
|
|
3436
|
+
*
|
|
3437
|
+
* **Details**
|
|
3438
|
+
*
|
|
3439
|
+
* A choice state declares only `choice`, the transition that resolves it to
|
|
3440
|
+
* a concrete destination. Every other handler key is rejected.
|
|
3441
|
+
*
|
|
3442
|
+
* @category models
|
|
3443
|
+
* @since 0.23.0
|
|
3444
|
+
*/
|
|
3445
|
+
export interface ChoiceStateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, ChoiceId extends ChoiceIdentifier<States>, InputEvents extends ReadonlyArray<TaggedSchema> = Events, ParentEvents extends ReadonlyArray<TaggedSchema> = readonly []> {
|
|
3446
|
+
/** Required transition that resolves this transient choice to a concrete destination. */
|
|
3447
|
+
readonly choice: TransitionConfig<States, Events, Emits, ChoiceId, ChoiceContext<States, Events, Emits, ChoiceId, InputEvents, ParentEvents>>;
|
|
3448
|
+
readonly entry?: never;
|
|
3833
3449
|
readonly exit?: never;
|
|
3834
3450
|
readonly invoke?: never;
|
|
3835
3451
|
readonly always?: never;
|
|
@@ -3843,22 +3459,6 @@ export declare namespace Machine {
|
|
|
3843
3459
|
type HandlerConfigPart<Config> = {
|
|
3844
3460
|
readonly [Key in keyof Config as Key extends "states" | "initial" | "root" ? never : Key]: Config[Key];
|
|
3845
3461
|
};
|
|
3846
|
-
type HandlerNodeChildrenConfig<Config> = "states" extends keyof Config ? Config extends {
|
|
3847
|
-
readonly states?: infer Children;
|
|
3848
|
-
} ? NonNullable<Children> : never : never;
|
|
3849
|
-
type HandlerNodeByPath<States extends StateSchemas, Path extends string> = "" extends keyof States ? Path extends "" ? States[""] : States[""] extends {
|
|
3850
|
-
readonly states: infer Children extends StateSchemas;
|
|
3851
|
-
} ? HandlerNodeByPath<Children, Path> : never : Path extends `${infer Head}.${infer Rest}` ? Head extends keyof States ? States[Head] extends {
|
|
3852
|
-
readonly states: infer Children extends StateSchemas;
|
|
3853
|
-
} ? HandlerNodeByPath<Children, Rest> : never : never : Path extends keyof States ? States[Path] : never;
|
|
3854
|
-
type HandlerConfigAtPath<Config, Path extends string> = [Config] extends [never] ? never : "" extends keyof Config ? Path extends "" ? Config[""] : HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[""]>, Path> : Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Config ? HandlerConfigAtPath<HandlerNodeChildrenConfig<Config[Head]>, Rest> : never : Path extends keyof Config ? Config[Path] : never;
|
|
3855
|
-
type HandlerValidationAtPath<Path extends string, Validation> = Path extends `${infer Head}.${infer Rest}` ? {
|
|
3856
|
-
readonly [Key in Head]?: {
|
|
3857
|
-
readonly states: HandlerValidationAtPath<Rest, Validation>;
|
|
3858
|
-
};
|
|
3859
|
-
} : {
|
|
3860
|
-
readonly [Key in Path]?: Validation;
|
|
3861
|
-
};
|
|
3862
3462
|
type HandlerNodeConfigKey = "always" | "choice" | "entry" | "exit" | "history" | "initial" | "root" | "invoke" | "on" | "onDone" | "output" | "states";
|
|
3863
3463
|
type HandlerValidationError<Message extends string, Path extends string, Detail = unknown> = {
|
|
3864
3464
|
readonly "~effect/Machine/HandlerError": readonly [message: Message, path: Path, detail: Detail];
|
|
@@ -3897,19 +3497,6 @@ export declare namespace Machine {
|
|
|
3897
3497
|
readonly [Key in UnknownKeys]: HandlerValidationError<"Handler config contains an event key that does not exist", StateId, Key>;
|
|
3898
3498
|
};
|
|
3899
3499
|
} : unknown;
|
|
3900
|
-
type TransitionResultInitialTargetPath<Result> = IsAny<Result> extends true ? never : Result extends Effect.Effect<infer Success, any, any> ? TransitionResultInitialTargetPath<Success> : Result extends SelectedBranch<any, infer Selected> ? TransitionResultInitialTargetPath<Selected> : Result extends StateConstruction<infer Constructed> ? TransitionResultInitialTargetPath<Constructed> : Result extends {
|
|
3901
|
-
readonly [Topology.InitialTargetTypeId]: typeof Topology.InitialTargetTypeId;
|
|
3902
|
-
readonly _tag: "InitialTarget";
|
|
3903
|
-
} ? Result extends {
|
|
3904
|
-
readonly path: infer Path extends string;
|
|
3905
|
-
} ? Path : never : never;
|
|
3906
|
-
type HandlerConfigInitialTargetPath<Config> = TransitionResultInitialTargetPath<EventHandlerReturn<Config> | AlwaysReturn<Config> | DoneReturn<Config> | ChoiceReturn<Config> | InvokeOutcomeReturn<InvokeReturn<Config>>>;
|
|
3907
|
-
type RequiredInitializersForTargetPath<AllStates extends StateSchemas, Path> = string extends Path ? never : Path extends StateIdentifier<AllStates> ? InitializerClosureForNode<AllStates, NodeByIdentifier<AllStates, Path>, Path> : never;
|
|
3908
|
-
type HandlerTreeInitialTargetPath<Config> = string extends keyof Config ? never : Config extends object ? {
|
|
3909
|
-
readonly [Key in keyof Config]: HandlerConfigInitialTargetPath<HandlerConfigPart<Config[Key]>> | (Config[Key] extends {
|
|
3910
|
-
readonly states: infer Children;
|
|
3911
|
-
} ? HandlerTreeInitialTargetPath<Children> : never);
|
|
3912
|
-
}[keyof Config] : never;
|
|
3913
3500
|
type HandlerChildrenValidation<Node, Prefix extends string, Config> = "states" extends keyof Config ? Config extends {
|
|
3914
3501
|
readonly states?: infer ChildrenConfig;
|
|
3915
3502
|
} ? HandlerChildren<Node> extends infer Children extends StateSchemas ? [Children] extends [never] ? {
|
|
@@ -3941,20 +3528,6 @@ export declare namespace Machine {
|
|
|
3941
3528
|
readonly invoke: HandlerValidationError<"Invoked child expects parent events not accepted by this machine", StateId, Exclude<InvokeParentEvents<InvokeReturn<Config>>, EventOf<Events>>>;
|
|
3942
3529
|
};
|
|
3943
3530
|
type HandlerRuntimeValidation<Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends string, Config, Incompatible = keyof Config extends never ? never : IncompatibleRuntime<ConfigServices<HandlerConfigPart<Config>>, EventOf<Events>, EmittedEventOf<Emits>>> = [Incompatible] extends [never] ? unknown : HandlerValidationError<"Handler config requires an incompatible machine runtime", StateId, Incompatible>;
|
|
3944
|
-
type RootInitialTargetValidation<States extends StateSchemas, Config> = RequiredInitializersForTargetPath<States, HandlerTreeInitialTargetPath<{
|
|
3945
|
-
readonly "": Config;
|
|
3946
|
-
}>> extends infer Required ? Types.UnionToIntersection<Required extends string ? HandlerConfigAtPath<{
|
|
3947
|
-
readonly "": Config;
|
|
3948
|
-
}, Required> extends infer NodeConfig ? [
|
|
3949
|
-
NodeConfig
|
|
3950
|
-
] extends [never] ? RootInitializeError<Required> : "initial" extends keyof NodeConfig ? never : RootInitializeError<Required> : never : unknown> : unknown;
|
|
3951
|
-
type RootInitializeError<Path extends string> = Path extends "" ? {
|
|
3952
|
-
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
3953
|
-
} : {
|
|
3954
|
-
readonly states: HandlerValidationAtPath<Path, {
|
|
3955
|
-
readonly initialize: HandlerValidationError<"State requires initialize because a transition enters its declared initial configuration", Path>;
|
|
3956
|
-
}>;
|
|
3957
|
-
};
|
|
3958
3531
|
type HandlerTreeValidation<States extends StateSchemas, Node, Events extends ReadonlyArray<TaggedSchema>, InputEvents extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, Path extends StateNodeIdentifier<States>, Config, OutputStates extends StateIdentifier<States>> = HandlerNodeValidation<States, Node, Events, InputEvents, Emits, Path, Config, OutputStates> & (Config extends {
|
|
3959
3532
|
readonly states: infer Handlers;
|
|
3960
3533
|
} ? Node extends {
|
|
@@ -3999,29 +3572,25 @@ export declare namespace Machine {
|
|
|
3999
3572
|
readonly states: infer Handlers;
|
|
4000
3573
|
} ? HandlerTreeEvidence<AllStates, Handlers, Children, JoinPath<Prefix, K>> : never : never);
|
|
4001
3574
|
}[Extract<keyof Config & keyof Nodes, string>];
|
|
4002
|
-
type
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
/** Child handlers nested according to the declared root topology. */
|
|
4006
|
-
readonly states: StateSchemas;
|
|
4007
|
-
} ? P : never;
|
|
4008
|
-
}[StateIdentifier<S>];
|
|
3575
|
+
type HandleEvidence<S extends StateSchemas, C, R> = HandlerTreeEvidence<S, {
|
|
3576
|
+
readonly "": NormalizeObjectConfig<C, R>;
|
|
3577
|
+
}>;
|
|
4009
3578
|
type LazyProgramValue = Effect.Effect<unknown, unknown, unknown> | Stream.Stream<unknown, unknown, unknown>;
|
|
4010
3579
|
/** Registered lazy programs and their optional explicit input adapters. */
|
|
4011
|
-
type Program<Value> = Value | ((...args: never[]) => Value);
|
|
4012
|
-
type EffectSources = Readonly<Record<string, Program<Effect.Effect<unknown, unknown, unknown>>>>;
|
|
4013
|
-
type StreamSources = Readonly<Record<string, Program<Stream.Stream<unknown, unknown, unknown>>>>;
|
|
4014
|
-
type TimerSources = Readonly<Record<string, Program<Duration.Input>>>;
|
|
4015
|
-
type LogicSources = Readonly<Record<string, unknown>>;
|
|
4016
|
-
type ValidateLogicSources<Sources> = {
|
|
3580
|
+
export type Program<Value> = Value | ((...args: never[]) => Value);
|
|
3581
|
+
export type EffectSources = Readonly<Record<string, Program<Effect.Effect<unknown, unknown, unknown>>>>;
|
|
3582
|
+
export type StreamSources = Readonly<Record<string, Program<Stream.Stream<unknown, unknown, unknown>>>>;
|
|
3583
|
+
export type TimerSources = Readonly<Record<string, Program<Duration.Input>>>;
|
|
3584
|
+
export type LogicSources = Readonly<Record<string, unknown>>;
|
|
3585
|
+
export type ValidateLogicSources<Sources> = {
|
|
4017
3586
|
readonly [K in keyof Sources]: InvokeResolvedSource<Sources[K]> extends {
|
|
4018
|
-
/**
|
|
3587
|
+
/** Produces the first state of the registered logic. */
|
|
4019
3588
|
readonly initial: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
|
|
4020
3589
|
readonly run: (...args: never[]) => Effect.Effect<unknown, unknown, unknown>;
|
|
4021
3590
|
} ? unknown : never;
|
|
4022
3591
|
};
|
|
4023
|
-
type ChildSources = Readonly<Record<string, ChildMachine.Any>>;
|
|
4024
|
-
type ValidatePrograms<Sources> = {
|
|
3592
|
+
export type ChildSources = Readonly<Record<string, ChildMachine.Any>>;
|
|
3593
|
+
export type ValidatePrograms<Sources> = {
|
|
4025
3594
|
readonly [K in keyof Sources]: Sources[K] extends LazyProgramValue ? unknown : Sources[K] extends (...args: never[]) => unknown ? Parameters<Sources[K]>["length"] extends 1 ? unknown : never : unknown;
|
|
4026
3595
|
};
|
|
4027
3596
|
type PathName<P extends string> = P extends "" ? "root" : P;
|
|
@@ -4029,85 +3598,8 @@ export declare namespace Machine {
|
|
|
4029
3598
|
type ReferenceAt<S extends StateSchemas, P extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = PathName<P>;
|
|
4030
3599
|
type ReferenceUnion<S extends StateSchemas, Paths extends StateNodeIdentifier<S> | HistoryIdentifier<S>> = PathName<Paths>;
|
|
4031
3600
|
type DestinationPath<S extends StateSchemas> = Exclude<StateNodeIdentifier<S>, "">;
|
|
4032
|
-
type RootSchemas<Root extends StateNodeConfig> = {
|
|
4033
|
-
readonly "": Root;
|
|
4034
|
-
};
|
|
4035
|
-
/** A topology declaration; its state values are constructed by a resolver. */
|
|
4036
|
-
type BranchDeclaration<Root extends StateNodeConfig, S extends StateSchemas = RootSchemas<Root>> = {
|
|
4037
|
-
/** Optional presentation label for this named branch. */
|
|
4038
|
-
readonly title?: string;
|
|
4039
|
-
} & ({
|
|
4040
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4041
|
-
readonly target: ReferenceUnion<S, DestinationPath<S>>;
|
|
4042
|
-
/**
|
|
4043
|
-
* Replaces the complete value of a retained ancestor of the source and target without replacing its active
|
|
4044
|
-
* children. A choice target resolves after the update, and every branch it can reach must stay below the owner.
|
|
4045
|
-
*/
|
|
4046
|
-
readonly update?: ReferenceUnion<S, ValuedStateIdentifier<S>>;
|
|
4047
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4048
|
-
readonly initial?: never;
|
|
4049
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4050
|
-
readonly history?: never;
|
|
4051
|
-
/** Accepts the event without selecting a new destination. */
|
|
4052
|
-
readonly none?: never;
|
|
4053
|
-
/** Reconstructs root and its initial children from fresh machine input. */
|
|
4054
|
-
readonly initialize?: never;
|
|
4055
|
-
} | {
|
|
4056
|
-
/** Reconstructs root and its initial children from fresh machine input supplied by the resolver. */
|
|
4057
|
-
readonly initialize: true;
|
|
4058
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4059
|
-
readonly target?: never;
|
|
4060
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4061
|
-
readonly update?: never;
|
|
4062
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4063
|
-
readonly initial?: never;
|
|
4064
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4065
|
-
readonly history?: never;
|
|
4066
|
-
/** Accepts the event without selecting a new destination. */
|
|
4067
|
-
readonly none?: never;
|
|
4068
|
-
} | {
|
|
4069
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4070
|
-
readonly update: ReferenceUnion<S, ValuedStateIdentifier<S>>;
|
|
4071
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4072
|
-
readonly target?: never;
|
|
4073
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4074
|
-
readonly initial?: never;
|
|
4075
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4076
|
-
readonly history?: never;
|
|
4077
|
-
/** Accepts the event without selecting a new destination. */
|
|
4078
|
-
readonly none?: never;
|
|
4079
|
-
/** Reconstructs root and its initial children from fresh machine input. */
|
|
4080
|
-
readonly initialize?: never;
|
|
4081
|
-
} | {
|
|
4082
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4083
|
-
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
4084
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4085
|
-
readonly target?: never;
|
|
4086
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4087
|
-
readonly update?: never;
|
|
4088
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4089
|
-
readonly initial?: never;
|
|
4090
|
-
/** Accepts the event without selecting a new destination. */
|
|
4091
|
-
readonly none?: never;
|
|
4092
|
-
/** Reconstructs root and its initial children from fresh machine input. */
|
|
4093
|
-
readonly initialize?: never;
|
|
4094
|
-
} | {
|
|
4095
|
-
/** Accepts the event without selecting a new destination. */
|
|
4096
|
-
readonly none: true;
|
|
4097
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4098
|
-
readonly target?: never;
|
|
4099
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4100
|
-
readonly update?: never;
|
|
4101
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4102
|
-
readonly initial?: never;
|
|
4103
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4104
|
-
readonly history?: never;
|
|
4105
|
-
/** Reconstructs root and its initial children from fresh machine input. */
|
|
4106
|
-
readonly initialize?: never;
|
|
4107
|
-
});
|
|
4108
|
-
type BranchDefinitions<Root extends StateNodeConfig> = Readonly<Record<string, Readonly<Record<string, BranchDeclaration<Root>>>>>;
|
|
4109
3601
|
/** Source programs and named topology declarations captured by a machine definition. */
|
|
4110
|
-
interface Registrations {
|
|
3602
|
+
export interface Registrations {
|
|
4111
3603
|
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
4112
3604
|
readonly effects?: EffectSources;
|
|
4113
3605
|
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
@@ -4118,14 +3610,11 @@ export declare namespace Machine {
|
|
|
4118
3610
|
readonly logic?: LogicSources;
|
|
4119
3611
|
/** Child machine descriptors registered for state-owned invocation. */
|
|
4120
3612
|
readonly children?: ChildSources;
|
|
4121
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4122
|
-
readonly branches?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
4123
3613
|
}
|
|
4124
3614
|
type RegisteredInput<R> = R extends {
|
|
4125
3615
|
readonly "~input": infer I extends Schema.Top;
|
|
4126
3616
|
} ? I : typeof Schema.Void;
|
|
4127
3617
|
type Registered<R, Kind extends PropertyKey> = Kind extends keyof R ? NonNullable<R[Kind]> : {};
|
|
4128
|
-
type RefPath<R> = PathOf<R>;
|
|
4129
3618
|
type ConstructionData<Node> = [NodeSchema<Node>] extends [never] ? {
|
|
4130
3619
|
readonly data?: never;
|
|
4131
3620
|
readonly decoded?: never;
|
|
@@ -4149,7 +3638,7 @@ export declare namespace Machine {
|
|
|
4149
3638
|
};
|
|
4150
3639
|
}[ActiveStateKey<Children> | ChoiceStateKey<Children>];
|
|
4151
3640
|
/** Values for one state and, optionally, its explicitly selected descendants. */
|
|
4152
|
-
type ConstructionObject<Node, Source extends string = never> = {
|
|
3641
|
+
export type ConstructionObject<Node, Source extends string = never> = {
|
|
4153
3642
|
readonly input?: never;
|
|
4154
3643
|
} & ConstructionData<Node> & (Node extends {
|
|
4155
3644
|
readonly states: infer Children extends StateSchemas;
|
|
@@ -4171,34 +3660,52 @@ export declare namespace Machine {
|
|
|
4171
3660
|
} : {
|
|
4172
3661
|
/** Fresh machine input used by root construction and root initial callbacks. */ readonly input: RegisteredInput<R>["Type"];
|
|
4173
3662
|
});
|
|
4174
|
-
type
|
|
3663
|
+
type UpdateValue<Node> = OrdinaryData<NodeMakeInput<Node>> | {
|
|
3664
|
+
readonly decoded: true;
|
|
3665
|
+
readonly data: NodeValue<Node>;
|
|
3666
|
+
};
|
|
3667
|
+
type TargetConstruction<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends DestinationPath<S>> = P extends StateIdentifier<S> ? ConstructionObject<NodeByIdentifier<S, P>, Src extends `${P}.${infer Rest}` ? Rest : Src extends P ? "" : never> : {};
|
|
3668
|
+
type TargetArguments<A> = {} extends A ? [construction?: A & {
|
|
4175
3669
|
readonly update?: never;
|
|
4176
|
-
}
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
3670
|
+
}] : [construction: A & {
|
|
3671
|
+
readonly update?: never;
|
|
3672
|
+
}];
|
|
3673
|
+
type TargetResult<S extends StateSchemas, P extends string> = P extends ChoiceIdentifier<S> ? ChoiceTarget<S, P> : P extends StateIdentifier<S> ? Target<S, P> : never;
|
|
3674
|
+
type OnePath<P extends string> = Types.IsUnion<P> extends true ? {
|
|
3675
|
+
readonly [K in `select.target takes one path, got: ${JoinUnion<P>}. Call it once per path`]: never;
|
|
3676
|
+
} : unknown;
|
|
3677
|
+
type OneOwner<O extends string> = Types.IsUnion<O> extends true ? `update takes one owner, got: ${JoinUnion<O>}` : unknown;
|
|
3678
|
+
/**
|
|
3679
|
+
* Selects one entry of a transition's `branches` list. The compiler checks that `resolve` selects exactly the
|
|
3680
|
+
* declared entries, so each call here must match one of them.
|
|
3681
|
+
*
|
|
3682
|
+
* @category models
|
|
3683
|
+
* @since 0.47.0
|
|
3684
|
+
*/
|
|
3685
|
+
export interface BranchSelect<S extends StateSchemas, Src extends StateNodeIdentifier<S>, R> {
|
|
3686
|
+
/** Selects `{ target }`, or `{ target, update }` when the construction has an `update` record. */
|
|
3687
|
+
readonly target: {
|
|
3688
|
+
<P extends DestinationPath<S>, O extends ReferenceUnion<S, TargetOwner<S, Src, P>>>(path: P & OnePath<P>, construction: TargetConstruction<S, Src, P> & {
|
|
3689
|
+
/** The new value of the retained owner named by this branch. */
|
|
3690
|
+
readonly update: {
|
|
3691
|
+
readonly [Owner in O]: UpdateValue<NodeByIdentifier<S, Extract<PathOf<Owner>, StateIdentifier<S>>>>;
|
|
3692
|
+
} & OneOwner<O>;
|
|
3693
|
+
}): SelectedBranch<`target:${P}+update:${O}`, CombinedTarget<TargetResult<S, P>, S, Extract<PathOf<O>, ValuedStateIdentifier<S>>>>;
|
|
3694
|
+
<P extends DestinationPath<S>>(path: P & OnePath<P>, ...construction: TargetArguments<TargetConstruction<S, Src, P>>): SelectedBranch<`target:${P}`, TargetResult<S, P>>;
|
|
3695
|
+
};
|
|
3696
|
+
/** Selects `{ update }`, replacing the value of one retained source or ancestor. */
|
|
3697
|
+
readonly update: <O extends ReferenceUnion<S, UpdatableOwner<S, Src>>>(updates: {
|
|
3698
|
+
readonly [Owner in O]: UpdateValue<NodeByIdentifier<S, Extract<PathOf<Owner>, StateIdentifier<S>>>>;
|
|
3699
|
+
} & OneOwner<O>) => SelectedBranch<`update:${O}`, StateUpdate<S, Extract<PathOf<O>, ValuedStateIdentifier<S>>>>;
|
|
3700
|
+
/** Selects `{ history }`. */
|
|
3701
|
+
readonly history: <P extends ReferenceUnion<S, HistoryIdentifier<S>>>(path: P) => SelectedBranch<`history:${P}`, HistoryTarget<S, Extract<PathOf<P>, HistoryIdentifier<S>>>>;
|
|
3702
|
+
/** Selects `{ initialize: true }`. */
|
|
3703
|
+
readonly initialize: ConstructionCall<RootInput<R>, SelectedBranch<"initialize", InitialTarget<"">>>;
|
|
3704
|
+
/** Selects `{ stay: true }`. */
|
|
3705
|
+
readonly stay: () => SelectedBranch<"stay", NoTarget>;
|
|
3706
|
+
/** Selects `{ decline: true }`, passing the event on to the next candidate. */
|
|
3707
|
+
readonly decline: () => SelectedBranch<"decline", Declined>;
|
|
3708
|
+
}
|
|
4202
3709
|
type ObjectPolicy<C, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
|
|
4203
3710
|
/** Set to true to exit and reenter the handler source. */
|
|
4204
3711
|
readonly reenter?: Reenter extends true ? boolean : never;
|
|
@@ -4228,139 +3735,133 @@ export declare namespace Machine {
|
|
|
4228
3735
|
* Machines without an input schema use `true`.
|
|
4229
3736
|
*/
|
|
4230
3737
|
readonly initialize: RegisteredInput<R> extends typeof Schema.Void ? true : DataValue<C, RegisteredInput<R>["Type"]>;
|
|
3738
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
4231
3739
|
readonly target?: never;
|
|
3740
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
4232
3741
|
readonly update?: never;
|
|
3742
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
3743
|
+
readonly history?: never;
|
|
3744
|
+
/** Accepts the event and stays in the current states. */
|
|
3745
|
+
readonly stay?: never;
|
|
3746
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
4233
3747
|
readonly branches?: never;
|
|
3748
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4234
3749
|
readonly resolve?: never;
|
|
4235
|
-
readonly history?: never;
|
|
4236
|
-
readonly none?: never;
|
|
4237
3750
|
};
|
|
3751
|
+
type OwnerUpdates<S extends StateSchemas, Owners extends ValuedStateIdentifier<S>, C> = {
|
|
3752
|
+
readonly [O in Owners as PathName<O>]?: ShortConstruction<C, NodeByIdentifier<S, O>>;
|
|
3753
|
+
};
|
|
3754
|
+
type TargetOwner<S extends StateSchemas, Src extends StateNodeIdentifier<S>, P extends string> = Src extends ChoiceIdentifier<S> ? never : Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>;
|
|
3755
|
+
type UpdatableOwner<S extends StateSchemas, Src extends StateNodeIdentifier<S>> = Src extends ChoiceIdentifier<S> ? never : Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>;
|
|
4238
3756
|
type InlineDestination<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = {
|
|
4239
3757
|
readonly [P in DestinationPath<S>]: {
|
|
4240
|
-
/** Selects a declared descendant
|
|
3758
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
4241
3759
|
readonly target: ReferenceAt<S, P>;
|
|
4242
|
-
/**
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
3760
|
+
/**
|
|
3761
|
+
* Replaces the value of one retained ancestor of the source and target without replacing its active children.
|
|
3762
|
+
* A choice target resolves after the update, and every branch it can reach must stay below the owner.
|
|
3763
|
+
*/
|
|
3764
|
+
readonly update?: OwnerUpdates<S, TargetOwner<S, Src, P>, C>;
|
|
3765
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
3766
|
+
readonly initialize?: never;
|
|
4246
3767
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4247
3768
|
readonly history?: never;
|
|
4248
|
-
/** Accepts the event
|
|
4249
|
-
readonly
|
|
4250
|
-
/**
|
|
3769
|
+
/** Accepts the event and stays in the current states. */
|
|
3770
|
+
readonly stay?: never;
|
|
3771
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
4251
3772
|
readonly branches?: never;
|
|
4252
3773
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4253
3774
|
readonly resolve?: never;
|
|
4254
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
4255
|
-
readonly declinable?: never;
|
|
4256
3775
|
} & InlineDestinationConstruction<S, Src, P, C>;
|
|
4257
3776
|
}[DestinationPath<S>];
|
|
4258
|
-
type
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
readonly
|
|
4264
|
-
|
|
4265
|
-
readonly
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
3777
|
+
type InlineUnknownTarget<S extends StateSchemas> = {
|
|
3778
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
3779
|
+
readonly target: ReferenceUnion<S, DestinationPath<S>> | (string & {});
|
|
3780
|
+
readonly update?: never;
|
|
3781
|
+
readonly initialize?: never;
|
|
3782
|
+
readonly history?: never;
|
|
3783
|
+
readonly stay?: never;
|
|
3784
|
+
readonly branches?: never;
|
|
3785
|
+
readonly resolve?: never;
|
|
3786
|
+
};
|
|
3787
|
+
type InlineUpdate<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = [UpdatableOwner<S, Src>] extends [
|
|
3788
|
+
never
|
|
3789
|
+
] ? never : {
|
|
3790
|
+
/** Replaces the value of one retained source or ancestor without replacing its active children. */
|
|
3791
|
+
readonly update: OwnerUpdates<S, UpdatableOwner<S, Src>, C>;
|
|
3792
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
3793
|
+
readonly target?: never;
|
|
3794
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
3795
|
+
readonly initialize?: never;
|
|
3796
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
3797
|
+
readonly history?: never;
|
|
3798
|
+
/** Accepts the event and stays in the current states. */
|
|
3799
|
+
readonly stay?: never;
|
|
3800
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
3801
|
+
readonly branches?: never;
|
|
3802
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
3803
|
+
readonly resolve?: never;
|
|
3804
|
+
};
|
|
3805
|
+
/**
|
|
3806
|
+
* One destination a `resolve` function can select. Here `update` names the owner as a string, because the value is
|
|
3807
|
+
* passed to the `select` call.
|
|
3808
|
+
*
|
|
3809
|
+
* @category models
|
|
3810
|
+
* @since 0.47.0
|
|
3811
|
+
*/
|
|
3812
|
+
export type BranchEntry<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Acceptance extends TransitionAcceptance> = {
|
|
4274
3813
|
readonly [P in DestinationPath<S>]: {
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4278
|
-
|
|
4279
|
-
* Replaces the complete value of a retained ancestor of the source and target without replacing its active
|
|
4280
|
-
* children. A choice target resolves after the update, and every branch it can reach must stay below the
|
|
4281
|
-
* owner; `data` then constructs only the owner value.
|
|
4282
|
-
*/
|
|
4283
|
-
readonly update: ReferenceAt<S, Owner>;
|
|
4284
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4285
|
-
readonly initial?: never;
|
|
4286
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4287
|
-
readonly history?: never;
|
|
4288
|
-
/** Accepts the event without selecting a new destination. */
|
|
4289
|
-
readonly none?: never;
|
|
4290
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4291
|
-
readonly branches?: never;
|
|
4292
|
-
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4293
|
-
readonly resolve?: never;
|
|
4294
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
4295
|
-
readonly declinable?: never;
|
|
4296
|
-
} & InlinePairConstruction<S, Src, P, Owner, C>;
|
|
4297
|
-
}[Extract<ParentStateIdentifier<Src>, ParentStateIdentifier<P> & ValuedStateIdentifier<S>>];
|
|
4298
|
-
}[DestinationPath<S>];
|
|
4299
|
-
type InlineUpdate<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C> = Src extends ChoiceIdentifier<S> ? never : {
|
|
4300
|
-
readonly [P in Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>]: {
|
|
4301
|
-
/** Set to true to exit and reenter the handler source. */
|
|
4302
|
-
readonly reenter?: P extends Src ? never : boolean;
|
|
4303
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4304
|
-
readonly update: ReferenceAt<S, P>;
|
|
4305
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4306
|
-
readonly target?: never;
|
|
4307
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4308
|
-
readonly initial?: never;
|
|
4309
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4310
|
-
readonly history?: never;
|
|
4311
|
-
/** Accepts the event without selecting a new destination. */
|
|
4312
|
-
readonly none?: never;
|
|
4313
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4314
|
-
readonly branches?: never;
|
|
4315
|
-
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4316
|
-
readonly resolve?: never;
|
|
4317
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
4318
|
-
readonly declinable?: never;
|
|
4319
|
-
} & ObjectConstruction<C, StateUpdateBuilder<S, P>>;
|
|
4320
|
-
}[Extract<Src | ParentStateIdentifier<Src>, ValuedStateIdentifier<S>>];
|
|
4321
|
-
type BranchSelections<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
|
|
4322
|
-
readonly [K in Extract<keyof Group, string>]: {
|
|
4323
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4324
|
-
readonly target: SelectionOf<S, Src, Group[K], R>;
|
|
3814
|
+
/** Selects a declared descendant through `select.target`. */
|
|
3815
|
+
readonly target: ReferenceAt<S, P>;
|
|
3816
|
+
/** The retained ancestor that this branch's `select.target` call updates. */
|
|
3817
|
+
readonly update?: ReferenceUnion<S, TargetOwner<S, Src, P>>;
|
|
4325
3818
|
};
|
|
3819
|
+
}[DestinationPath<S>] | ([UpdatableOwner<S, Src>] extends [never] ? never : {
|
|
3820
|
+
/** The retained state updated through `select.update`. */
|
|
3821
|
+
readonly update: ReferenceUnion<S, UpdatableOwner<S, Src>>;
|
|
3822
|
+
readonly target?: never;
|
|
3823
|
+
}) | {
|
|
3824
|
+
/** Restores this history reference through `select.history`. */
|
|
3825
|
+
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
3826
|
+
} | {
|
|
3827
|
+
/** Reconstructs root from fresh machine input through `select.initialize`. */
|
|
3828
|
+
readonly initialize: true;
|
|
3829
|
+
} | (Src extends ChoiceIdentifier<S> ? never : {
|
|
3830
|
+
/** Accepts the event and stays in the current states through `select.stay`. */
|
|
3831
|
+
readonly stay: true;
|
|
3832
|
+
}) | (Acceptance extends "declinable" ? {
|
|
3833
|
+
/** Passes the event on to the next candidate through `select.decline`. */
|
|
3834
|
+
readonly decline: true;
|
|
3835
|
+
} : never);
|
|
3836
|
+
type ObjectBranches<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean, Acceptance extends TransitionAcceptance> = {
|
|
3837
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
3838
|
+
readonly branches?: ReadonlyArray<BranchEntry<S, Src, Acceptance>>;
|
|
3839
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
3840
|
+
readonly resolve?: (context: C & {
|
|
3841
|
+
/** Selects one of the declared `branches`. */
|
|
3842
|
+
readonly select: BranchSelect<S, Src, R>;
|
|
3843
|
+
}, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => unknown;
|
|
3844
|
+
/** Set to true to exit and reenter the handler source. */
|
|
3845
|
+
readonly reenter?: Reenter extends true ? boolean : never;
|
|
3846
|
+
/** Branch on the condition inside `resolve`, returning `select.decline()`. */
|
|
3847
|
+
readonly guard?: never;
|
|
3848
|
+
/** Enqueue commands inside `resolve`. */
|
|
3849
|
+
readonly commands?: never;
|
|
3850
|
+
/** Constructs values through the `select` calls inside `resolve`. */
|
|
3851
|
+
readonly data?: never;
|
|
3852
|
+
/** Constructs values through the `select` calls inside `resolve`. */
|
|
3853
|
+
readonly decoded?: never;
|
|
3854
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
3855
|
+
readonly target?: never;
|
|
3856
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
3857
|
+
readonly update?: never;
|
|
3858
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
3859
|
+
readonly initialize?: never;
|
|
3860
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
3861
|
+
readonly history?: never;
|
|
3862
|
+
/** Accepts the event and stays in the current states. */
|
|
3863
|
+
readonly stay?: never;
|
|
4326
3864
|
};
|
|
4327
|
-
type ObjectBranchResolver<Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, C, B extends Readonly<Record<string, TransitionBranchInput>>, Declinable extends boolean> = (context: C & {
|
|
4328
|
-
readonly select: BranchSelectors<B>;
|
|
4329
|
-
} & DeclineCapability, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => BranchSelectionResult<B> | (Declinable extends true ? Declined : never);
|
|
4330
|
-
type InvalidBranchSelection<S extends StateSchemas, Src extends StateNodeIdentifier<S>, Group, R> = {
|
|
4331
|
-
readonly [K in keyof Group]: Src extends ChoiceIdentifier<S> ? Group[K] extends {
|
|
4332
|
-
/** Accepts the event without selecting a new destination. */
|
|
4333
|
-
readonly none: true;
|
|
4334
|
-
} | {
|
|
4335
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4336
|
-
readonly update: unknown;
|
|
4337
|
-
} ? K : [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K : never : [SelectionBuilder<SelectionOf<S, Src, Group[K], R>>] extends [never] ? K : never;
|
|
4338
|
-
}[keyof Group];
|
|
4339
|
-
type ObjectBranches<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Acceptance extends TransitionAcceptance> = {
|
|
4340
|
-
readonly [K in Extract<keyof Registered<R, "branches">, string>]: ([InvalidBranchSelection<S, Src, Registered<R, "branches">[K], R>] extends [never] ? unknown : never) & {
|
|
4341
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4342
|
-
readonly branches: K;
|
|
4343
|
-
/** Selects a declared descendant; its transition or bound branch constructor supplies required values. */
|
|
4344
|
-
readonly target?: never;
|
|
4345
|
-
/** Replaces the complete value of a retained source or ancestor without replacing its active children. */
|
|
4346
|
-
readonly update?: never;
|
|
4347
|
-
/** Enters a compound or parallel subtree through its declared initialization. */
|
|
4348
|
-
readonly initial?: never;
|
|
4349
|
-
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4350
|
-
readonly history?: never;
|
|
4351
|
-
/** Accepts the event without selecting a new destination. */
|
|
4352
|
-
readonly none?: never;
|
|
4353
|
-
/** Constructs schema make input from the typed source context. */
|
|
4354
|
-
readonly from?: never;
|
|
4355
|
-
/** Supplies an already decoded schema value from the typed source context. */
|
|
4356
|
-
readonly decoded?: never;
|
|
4357
|
-
} & {
|
|
4358
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
4359
|
-
readonly declinable?: "declinable" extends Acceptance ? boolean : false;
|
|
4360
|
-
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4361
|
-
readonly resolve: ObjectBranchResolver<Ev, Em, C, BranchSelections<S, Src, Registered<R, "branches">[K], R>, true>;
|
|
4362
|
-
};
|
|
4363
|
-
}[Extract<keyof Registered<R, "branches">, string>];
|
|
4364
3865
|
type DataValue<C, A> = A | ((context: C) => A);
|
|
4365
3866
|
type DeclarationData<T> = T extends {
|
|
4366
3867
|
readonly from: (context: infer C) => infer A;
|
|
@@ -4382,49 +3883,57 @@ export declare namespace Machine {
|
|
|
4382
3883
|
* @category models
|
|
4383
3884
|
* @since 0.34.0
|
|
4384
3885
|
*/
|
|
4385
|
-
type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = ObjectPolicy<C, Reenter, Acceptance> &
|
|
3886
|
+
export type Transition<S extends StateSchemas, Src extends StateNodeIdentifier<S>, C, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, R, Reenter extends boolean = false, Acceptance extends TransitionAcceptance = "required"> = (ObjectPolicy<C, Reenter, Acceptance> & {
|
|
3887
|
+
/** Enqueues synchronous commands when this transition is selected. */
|
|
3888
|
+
readonly commands?: (context: C, enqueue: Enqueue<EventOf<Ev>, EmittedEventOf<Em>>) => void;
|
|
3889
|
+
} & DeclarationData<InlineDestination<S, Src, C> | InlineUnknownTarget<S> | InlineUpdate<S, Src, C> | InlineRoot<C, R> | {
|
|
4386
3890
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4387
3891
|
readonly history: ReferenceUnion<S, HistoryIdentifier<S>>;
|
|
4388
|
-
/** Selects a declared descendant
|
|
3892
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
4389
3893
|
readonly target?: never;
|
|
4390
|
-
/** Replaces the
|
|
3894
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
4391
3895
|
readonly update?: never;
|
|
4392
|
-
/**
|
|
4393
|
-
readonly
|
|
4394
|
-
/** Accepts the event
|
|
4395
|
-
readonly
|
|
4396
|
-
/**
|
|
3896
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
3897
|
+
readonly initialize?: never;
|
|
3898
|
+
/** Accepts the event and stays in the current states. */
|
|
3899
|
+
readonly stay?: never;
|
|
3900
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
4397
3901
|
readonly branches?: never;
|
|
4398
3902
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4399
3903
|
readonly resolve?: never;
|
|
4400
|
-
/** Constructs schema make input from the typed source context. */
|
|
4401
|
-
readonly from?: never;
|
|
4402
|
-
/** Supplies an already decoded schema value from the typed source context. */
|
|
4403
|
-
readonly decoded?: never;
|
|
4404
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
4405
|
-
readonly declinable?: never;
|
|
4406
3904
|
} | (Src extends ChoiceIdentifier<S> ? never : {
|
|
4407
|
-
/** Accepts the event
|
|
4408
|
-
readonly
|
|
4409
|
-
/** Selects a declared descendant
|
|
3905
|
+
/** Accepts the event and stays in the current states. */
|
|
3906
|
+
readonly stay: true;
|
|
3907
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
4410
3908
|
readonly target?: never;
|
|
4411
|
-
/** Replaces the
|
|
3909
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
4412
3910
|
readonly update?: never;
|
|
4413
|
-
/**
|
|
4414
|
-
readonly
|
|
3911
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
3912
|
+
readonly initialize?: never;
|
|
4415
3913
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4416
3914
|
readonly history?: never;
|
|
4417
|
-
/**
|
|
3915
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
3916
|
+
readonly branches?: never;
|
|
3917
|
+
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
3918
|
+
readonly resolve?: never;
|
|
3919
|
+
}) | (Src extends ChoiceIdentifier<S> ? never : Reenter extends true ? {
|
|
3920
|
+
/** Exits and reenters the source. */
|
|
3921
|
+
readonly reenter: true;
|
|
3922
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
3923
|
+
readonly target?: never;
|
|
3924
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
3925
|
+
readonly update?: never;
|
|
3926
|
+
/** Reconstructs root and its initial children from fresh machine input. */
|
|
3927
|
+
readonly initialize?: never;
|
|
3928
|
+
/** Restores the declared history reference, using its fallback on first entry. */
|
|
3929
|
+
readonly history?: never;
|
|
3930
|
+
/** Accepts the event and stays in the current states. */
|
|
3931
|
+
readonly stay?: never;
|
|
3932
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
4418
3933
|
readonly branches?: never;
|
|
4419
|
-
/** Constructs schema make input from the typed source context. */
|
|
4420
|
-
readonly from?: never;
|
|
4421
|
-
/** Supplies an already decoded schema value from the typed source context. */
|
|
4422
|
-
readonly decoded?: never;
|
|
4423
|
-
/** Set to true when the resolver can explicitly return decline(). */
|
|
4424
|
-
readonly declinable?: "declinable" extends Acceptance ? boolean : false;
|
|
4425
3934
|
/** Selects one declared branch and may enqueue synchronous commands. */
|
|
4426
|
-
readonly resolve?:
|
|
4427
|
-
}) | ObjectBranches<S, Src, C, Ev, Em, R, Acceptance
|
|
3935
|
+
readonly resolve?: never;
|
|
3936
|
+
} : never)>) | ObjectBranches<S, Src, C, Ev, Em, R, Reenter, Acceptance>;
|
|
4428
3937
|
type SourceValue<R, K extends PropertyKey> = {
|
|
4429
3938
|
readonly [Kind in "effects" | "streams" | "timers" | "logic" | "children"]: K extends keyof Registered<R, Kind> ? Registered<R, Kind>[K] : never;
|
|
4430
3939
|
}["effects" | "streams" | "timers" | "logic" | "children"];
|
|
@@ -4470,16 +3979,16 @@ export declare namespace Machine {
|
|
|
4470
3979
|
} : never : SourceInput<SourceValue<R, K>, C>;
|
|
4471
3980
|
type ObjectOutcome<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R, V, Channel extends "onDone" | "onFailure" | "onElement" | "onSnapshot"> = [V] extends [never] ? {} : Channel extends "onDone" ? {
|
|
4472
3981
|
/** Handles successful invocation or state completion with its exact output type. */
|
|
4473
|
-
readonly onDone: Transition<S, Src, InvokeDoneContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true,
|
|
3982
|
+
readonly onDone: Transition<S, Src, InvokeDoneContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, "required">;
|
|
4474
3983
|
} : Channel extends "onFailure" ? {
|
|
4475
3984
|
/** Handles the typed failure of the invoked source; required exactly when that channel is reachable. */
|
|
4476
|
-
readonly onFailure: Transition<S, Src, InvokeFailureContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true,
|
|
3985
|
+
readonly onFailure: Transition<S, Src, InvokeFailureContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, "required">;
|
|
4477
3986
|
} : Channel extends "onElement" ? {
|
|
4478
3987
|
/** Handles each Stream element; required when the element type is reachable. */
|
|
4479
|
-
readonly onElement: Transition<S, Src, InvokeElementContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true,
|
|
3988
|
+
readonly onElement: Transition<S, Src, InvokeElementContext<S, Ev, Em, Src, V, In, Pa>, Ev, Em, R, true, "required">;
|
|
4480
3989
|
} : {
|
|
4481
3990
|
/** Optionally handles active snapshots of invoked logic or a child machine. */
|
|
4482
|
-
readonly onSnapshot: Transition<S, Src, InvokeSnapshotContext<S, Ev, Em, Src, V, never, never, In, Pa>, Ev, Em, R, true,
|
|
3991
|
+
readonly onSnapshot: Transition<S, Src, InvokeSnapshotContext<S, Ev, Em, Src, V, never, never, In, Pa>, Ev, Em, R, true, "required">;
|
|
4483
3992
|
};
|
|
4484
3993
|
type RegisteredInvokeError<R, K extends PropertyKey> = SourceKind<R, K> extends "children" ? SourceValue<R, K> extends ChildMachine<string, infer M> ? Error<M> | ActionError<Services<M>> : never : InvokeRuntimeError<ResolvedInvoke<R, K>>;
|
|
4485
3994
|
/**
|
|
@@ -4488,7 +3997,7 @@ export declare namespace Machine {
|
|
|
4488
3997
|
* @category models
|
|
4489
3998
|
* @since 0.34.0
|
|
4490
3999
|
*/
|
|
4491
|
-
type Invocation<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = {
|
|
4000
|
+
export type Invocation<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = {
|
|
4492
4001
|
readonly [K in Extract<SourceKeys<R>, string>]: Types.Simplify<{
|
|
4493
4002
|
/** Name of the source registered in make. */
|
|
4494
4003
|
readonly src: K;
|
|
@@ -4619,13 +4128,14 @@ export declare namespace Machine {
|
|
|
4619
4128
|
readonly exit?: never; /** Constructs the decoded output declared by the state schema. */
|
|
4620
4129
|
readonly output?: never;
|
|
4621
4130
|
};
|
|
4131
|
+
type StateFieldError<Kind extends string, Src extends string, Field extends string, Fix extends string> = `${Kind} state "${PathName<Src>}" cannot declare ${Field}. ${Fix}`;
|
|
4622
4132
|
/**
|
|
4623
4133
|
* Handlers for a node of the declared root tree.
|
|
4624
4134
|
*
|
|
4625
4135
|
* @category models
|
|
4626
4136
|
* @since 0.34.0
|
|
4627
4137
|
*/
|
|
4628
|
-
type StateHandler<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa> & InitialHandler<S, Node, Src, StateActionContext<S, Ev, Em, Extract<Src, StateIdentifier<S>>, In, Pa> & {
|
|
4138
|
+
export type StateHandler<S extends StateSchemas, Node, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, Src extends StateNodeIdentifier<S>, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> = ObjectLifecycle<S, Node, Ev, Em, Src, In, Pa> & InitialHandler<S, Node, Src, StateActionContext<S, Ev, Em, Extract<Src, StateIdentifier<S>>, In, Pa> & {
|
|
4629
4139
|
/** Root-owned data constructed before initial descendant values. */
|
|
4630
4140
|
readonly root: StateByIdentifier<S, Extract<"", StateIdentifier<S>>>;
|
|
4631
4141
|
} & (Src extends "" ? {
|
|
@@ -4634,13 +4144,13 @@ export declare namespace Machine {
|
|
|
4634
4144
|
/** Required total transition for a transient choice state. */
|
|
4635
4145
|
readonly choice: Transition<S, Src, ChoiceContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R>;
|
|
4636
4146
|
/** Event handlers keyed by the public or internal event tag. */
|
|
4637
|
-
readonly on?:
|
|
4147
|
+
readonly on?: StateFieldError<"Choice", Src, "on", "Declare one transition in choice">;
|
|
4638
4148
|
/** Eventless transition evaluated during stabilization. */
|
|
4639
|
-
readonly always?:
|
|
4149
|
+
readonly always?: StateFieldError<"Choice", Src, "always", "Declare one transition in choice">;
|
|
4640
4150
|
/** Handles successful invocation or state completion with its exact output type. */
|
|
4641
|
-
readonly onDone?:
|
|
4151
|
+
readonly onDone?: StateFieldError<"Choice", Src, "onDone", "Declare one transition in choice">;
|
|
4642
4152
|
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4643
|
-
readonly invoke?:
|
|
4153
|
+
readonly invoke?: StateFieldError<"Choice", Src, "invoke", "Declare one transition in choice">;
|
|
4644
4154
|
/** Child handlers nested according to the declared root topology. */
|
|
4645
4155
|
readonly states?: never;
|
|
4646
4156
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
@@ -4649,15 +4159,15 @@ export declare namespace Machine {
|
|
|
4649
4159
|
readonly type: "final";
|
|
4650
4160
|
} ? {
|
|
4651
4161
|
/** Event handlers keyed by the public or internal event tag. */
|
|
4652
|
-
readonly on?:
|
|
4162
|
+
readonly on?: StateFieldError<"Final", Src, "on", "A final state has no outgoing work">;
|
|
4653
4163
|
/** Eventless transition evaluated during stabilization. */
|
|
4654
|
-
readonly always?:
|
|
4164
|
+
readonly always?: StateFieldError<"Final", Src, "always", "A final state has no outgoing work">;
|
|
4655
4165
|
/** Handles successful invocation or state completion with its exact output type. */
|
|
4656
|
-
readonly onDone?:
|
|
4166
|
+
readonly onDone?: StateFieldError<"Final", Src, "onDone", "A final state has no outgoing work">;
|
|
4657
4167
|
/** Required total transition for a transient choice state. */
|
|
4658
4168
|
readonly choice?: never;
|
|
4659
4169
|
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
4660
|
-
readonly invoke?:
|
|
4170
|
+
readonly invoke?: StateFieldError<"Final", Src, "invoke", "A final state has no outgoing work">;
|
|
4661
4171
|
/** Child handlers nested according to the declared root topology. */
|
|
4662
4172
|
readonly states?: never;
|
|
4663
4173
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
@@ -4665,12 +4175,12 @@ export declare namespace Machine {
|
|
|
4665
4175
|
} : {
|
|
4666
4176
|
/** Event handlers keyed by the public or internal event tag. */
|
|
4667
4177
|
readonly on?: {
|
|
4668
|
-
readonly [Tag in TagOf<Ev[number]>]?: Transition<S, Src, HandlerContext<S, Ev, Em, Src, Tag, never, never, In, Pa>, Ev, Em, R, true,
|
|
4178
|
+
readonly [Tag in TagOf<Ev[number]>]?: Transition<S, Src, HandlerContext<S, Ev, Em, Src, Tag, never, never, In, Pa>, Ev, Em, R, true, "declinable">;
|
|
4669
4179
|
};
|
|
4670
4180
|
/** Eventless transition evaluated during stabilization. */
|
|
4671
|
-
readonly always?: Transition<S, Src, AlwaysContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false,
|
|
4181
|
+
readonly always?: Transition<S, Src, AlwaysContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, "declinable">;
|
|
4672
4182
|
/** Handles successful invocation or state completion with its exact output type. */
|
|
4673
|
-
readonly onDone?: Transition<S, Src, DoneContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false,
|
|
4183
|
+
readonly onDone?: Transition<S, Src, DoneContext<S, Ev, Em, Src, In, Pa>, Ev, Em, R, false, "required">;
|
|
4674
4184
|
/** Required total transition for a transient choice state. */
|
|
4675
4185
|
readonly choice?: never;
|
|
4676
4186
|
/** One registered invocation or an array with distinct lifecycle identities. */
|
|
@@ -4690,26 +4200,128 @@ export declare namespace Machine {
|
|
|
4690
4200
|
readonly states?: never; /** Restores the declared history reference, using its fallback on first entry. */
|
|
4691
4201
|
readonly history?: never;
|
|
4692
4202
|
}) : never);
|
|
4693
|
-
type
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
readonly
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
readonly
|
|
4700
|
-
} ?
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
readonly
|
|
4706
|
-
} ?
|
|
4707
|
-
|
|
4203
|
+
type LastOfUnion<U> = Types.UnionToIntersection<U extends unknown ? () => U : never> extends () => infer Last ? Last : never;
|
|
4204
|
+
type JoinUnion<U extends string> = [U] extends [never] ? "" : LastOfUnion<U> extends infer Last extends string ? [Exclude<U, Last>] extends [never] ? Last : `${JoinUnion<Exclude<U, Last>>}, ${Last}` : never;
|
|
4205
|
+
type BranchEntryKey<Entry> = Entry extends {
|
|
4206
|
+
readonly target: infer P extends string;
|
|
4207
|
+
readonly update: infer O extends string;
|
|
4208
|
+
} ? `target:${P}+update:${O}` : Entry extends {
|
|
4209
|
+
readonly target: infer P extends string;
|
|
4210
|
+
} ? `target:${P}` : Entry extends {
|
|
4211
|
+
readonly update: infer O extends string;
|
|
4212
|
+
} ? `update:${O}` : Entry extends {
|
|
4213
|
+
readonly history: infer P extends string;
|
|
4214
|
+
} ? `history:${P}` : Entry extends {
|
|
4215
|
+
readonly initialize: true;
|
|
4216
|
+
} ? "initialize" : Entry extends {
|
|
4217
|
+
readonly stay: true;
|
|
4218
|
+
} ? "stay" : Entry extends {
|
|
4219
|
+
readonly decline: true;
|
|
4220
|
+
} ? "decline" : never;
|
|
4221
|
+
type BranchLabel<Key extends string> = Key extends `target:${infer P}+update:${infer O}` ? `{ target: "${P}", update: "${O}" }` : Key extends `target:${infer P}` ? `{ target: "${P}" }` : Key extends `update:${infer O}` ? `{ update: "${O}" }` : Key extends `history:${infer P}` ? `{ history: "${P}" }` : Key extends "initialize" | "stay" | "decline" ? `{ ${Key}: true }` : never;
|
|
4222
|
+
type BranchEntryKeyAt<B extends ReadonlyArray<unknown>, K> = K extends keyof B ? BranchEntryKey<B[K]> : never;
|
|
4223
|
+
type DuplicateBranchKey<B extends ReadonlyArray<unknown>, Indices extends keyof B = Extract<keyof B, `${number}`>> = {
|
|
4224
|
+
readonly [K in Indices]: BranchEntryKeyAt<B, K> extends BranchEntryKeyAt<B, Exclude<Indices, K>> ? BranchEntryKeyAt<B, K> : never;
|
|
4225
|
+
}[Indices];
|
|
4226
|
+
type SelectedBranchKey<Result> = Result extends SelectedBranch<infer Key, any> ? Key : never;
|
|
4227
|
+
type ValidateBranchSelection<B extends ReadonlyArray<unknown>, Result> = number extends B["length"] ? {
|
|
4228
|
+
readonly branches: "branches must list its entries inline";
|
|
4229
|
+
} : B["length"] extends 0 ? {
|
|
4230
|
+
readonly branches: "branches needs at least one entry";
|
|
4231
|
+
} : [DuplicateBranchKey<B>] extends [never] ? 0 extends 1 & Result ? {
|
|
4232
|
+
readonly resolve: "resolve must return a select call, got any";
|
|
4233
|
+
} : unknown extends Result ? {
|
|
4234
|
+
readonly resolve: "resolve must return a select call, got unknown";
|
|
4235
|
+
} : [Exclude<Result, SelectedBranch<any, any>>] extends [never] ? [
|
|
4236
|
+
Exclude<SelectedBranchKey<Result>, BranchEntryKey<B[number]>>
|
|
4237
|
+
] extends [never] ? [
|
|
4238
|
+
Exclude<BranchEntryKey<B[number]>, SelectedBranchKey<Result>>
|
|
4239
|
+
] extends [never] ? unknown : {
|
|
4240
|
+
readonly branches: `Declared branch ${BranchLabel<Exclude<BranchEntryKey<B[number]>, SelectedBranchKey<Result>>> extends infer Label extends string ? JoinUnion<Label> : never} is never selected by resolve`;
|
|
4241
|
+
} : {
|
|
4242
|
+
readonly resolve: `resolve selects undeclared ${BranchLabel<Exclude<SelectedBranchKey<Result>, BranchEntryKey<B[number]>>> extends infer Label extends string ? JoinUnion<Label> : never}. Add it to branches`;
|
|
4243
|
+
} : {
|
|
4244
|
+
readonly resolve: "resolve must return a select call on every path";
|
|
4245
|
+
} : {
|
|
4246
|
+
readonly branches: `Declared branch ${BranchLabel<DuplicateBranchKey<B>> extends infer Label extends string ? JoinUnion<Label> : never} appears more than once`;
|
|
4247
|
+
};
|
|
4248
|
+
type ValidateBranches<T> = T extends {
|
|
4249
|
+
readonly branches: infer B extends ReadonlyArray<unknown>;
|
|
4250
|
+
} ? T extends {
|
|
4708
4251
|
readonly resolve: (...args: any[]) => infer Result;
|
|
4709
|
-
} ?
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4252
|
+
} ? ValidateBranchSelection<B, Result> : {
|
|
4253
|
+
readonly branches: "branches needs a resolve that selects one of them";
|
|
4254
|
+
} : T extends {
|
|
4255
|
+
readonly resolve: unknown;
|
|
4256
|
+
} ? {
|
|
4257
|
+
readonly resolve: "resolve needs a branches list. Add: branches: [...]";
|
|
4258
|
+
} : unknown;
|
|
4259
|
+
type UpdatableNames<S extends StateSchemas, Src extends string, T> = T extends {
|
|
4260
|
+
readonly target: infer Target extends string;
|
|
4261
|
+
} ? PathName<TargetOwner<S, Extract<Src, StateNodeIdentifier<S>>, PathOf<Target>>> : PathName<UpdatableOwner<S, Extract<Src, StateNodeIdentifier<S>>>>;
|
|
4262
|
+
type ValidateOwnerNames<U, Allowed extends string> = [Exclude<keyof U, Allowed>] extends [never] ? unknown : {
|
|
4263
|
+
readonly update: `Cannot update "${JoinUnion<Extract<Exclude<keyof U, Allowed>, string>>}". ${[Allowed] extends [
|
|
4264
|
+
never
|
|
4265
|
+
] ? "No retained state can be updated here" : `Updatable here: ${JoinUnion<Allowed>}`}`;
|
|
4266
|
+
};
|
|
4267
|
+
type ValidateUpdateOwners<T, S extends StateSchemas, Src extends string> = T extends {
|
|
4268
|
+
readonly update: infer U;
|
|
4269
|
+
} ? Types.IsUnion<keyof U> extends true ? {
|
|
4270
|
+
readonly update: `update takes one owner, got: ${JoinUnion<Extract<keyof U, string>>}`;
|
|
4271
|
+
} : [keyof U] extends [never] ? {
|
|
4272
|
+
readonly update: "update takes one owner, got none";
|
|
4273
|
+
} : ValidateOwnerNames<U, UpdatableNames<S, Src, T>> & (T extends {
|
|
4274
|
+
readonly reenter: true;
|
|
4275
|
+
} ? keyof U extends PathName<Src> ? {
|
|
4276
|
+
readonly reenter: `Cannot reenter "${PathName<Src>}" while updating it. Update it or reenter it`;
|
|
4277
|
+
} : unknown : unknown) : unknown;
|
|
4278
|
+
type ValidateCommands<T> = T extends {
|
|
4279
|
+
readonly commands: (...args: any[]) => infer Result;
|
|
4280
|
+
} ? [
|
|
4281
|
+
Result
|
|
4282
|
+
] extends [void | undefined] ? unknown : {
|
|
4283
|
+
readonly commands: "commands must not return a value. Enqueue work with its second argument";
|
|
4284
|
+
} : unknown;
|
|
4285
|
+
type DestinationNames<S extends StateSchemas> = ReferenceUnion<S, Exclude<DestinationPath<S>, HistoryIdentifier<S>>>;
|
|
4286
|
+
type UnknownTargetMessage<P extends string, S extends StateSchemas> = P extends "root" ? `Cannot target "root". Reconstruct it with initialize, or update it with update: { root: ... }` : P extends ReferenceUnion<S, HistoryIdentifier<S>> ? `"${P}" is a history state. Restore it with: { history: "${P}" }` : `Unknown target "${P}". Declared: ${JoinUnion<DestinationNames<S>>}`;
|
|
4287
|
+
type ValidateTarget<T, S extends StateSchemas, Src extends string> = T extends {
|
|
4288
|
+
readonly target: infer P extends string;
|
|
4289
|
+
} ? string extends P ? unknown : P extends DestinationNames<S> ? ValidateTargetAncestors<S, Src, P> & ValidateTargetData<T, S, P> : UnknownTargetMessage<P, S> : unknown;
|
|
4290
|
+
type ValidateTargetData<T, S extends StateSchemas, P extends string> = "data" extends keyof T ? unknown : PathOf<P> extends infer Id extends StateIdentifier<S> ? [
|
|
4291
|
+
NodeSchema<NodeByIdentifier<S, Id>>
|
|
4292
|
+
] extends [never] ? unknown : {} extends NodeMakeInput<NodeByIdentifier<S, Id>> ? unknown : `Target "${P}" requires data` : unknown;
|
|
4293
|
+
type HasParallelAncestor<S extends StateSchemas, Id extends string> = true extends {
|
|
4294
|
+
[A in Extract<ParentStateIdentifier<Id>, StateIdentifier<S>>]: NodeByIdentifier<S, A> extends {
|
|
4295
|
+
readonly type: "parallel";
|
|
4296
|
+
} ? true : false;
|
|
4297
|
+
}[Extract<ParentStateIdentifier<Id>, StateIdentifier<S>>] ? true : false;
|
|
4298
|
+
type InactiveValuedAncestor<S extends StateSchemas, Src extends string, P extends string> = {
|
|
4299
|
+
[A in Exclude<Extract<ParentStateIdentifier<PathOf<P>>, ValuedStateIdentifier<S>>, Src | ParentStateIdentifier<Src> | JoinPath<Src, string>>]: HasParallelAncestor<S, A> extends true ? never : A;
|
|
4300
|
+
}[Exclude<Extract<ParentStateIdentifier<PathOf<P>>, ValuedStateIdentifier<S>>, Src | ParentStateIdentifier<Src> | JoinPath<Src, string>>];
|
|
4301
|
+
type ValidateTargetAncestors<S extends StateSchemas, Src extends string, P extends string> = [
|
|
4302
|
+
InactiveValuedAncestor<S, Src, P>
|
|
4303
|
+
] extends [never] ? unknown : `Target "${P}" enters "${JoinUnion<PathName<InactiveValuedAncestor<S, Src, P>>>}", which needs a value. Target that state and construct "${P}" with states`;
|
|
4304
|
+
type ValidateBranchEntries<T, S extends StateSchemas, Src extends string> = T extends {
|
|
4305
|
+
readonly branches: infer B extends ReadonlyArray<unknown>;
|
|
4306
|
+
} ? {
|
|
4307
|
+
readonly branches: {
|
|
4308
|
+
readonly [K in keyof B]: (B[K] extends {
|
|
4309
|
+
readonly target: infer P extends string;
|
|
4310
|
+
} ? P extends DestinationNames<S> ? ValidateTargetAncestors<S, Src, P> : UnknownTargetMessage<P, S> : unknown) & (B[K] extends {
|
|
4311
|
+
readonly update: infer O extends string;
|
|
4312
|
+
} ? O extends UpdatableNames<S, Src, B[K]> ? unknown : `Cannot update "${O}". ${[UpdatableNames<S, Src, B[K]>] extends [never] ? "No retained state can be updated here" : `Updatable here: ${JoinUnion<UpdatableNames<S, Src, B[K]>>}`}` : unknown);
|
|
4313
|
+
};
|
|
4314
|
+
} : unknown;
|
|
4315
|
+
type ValidateDestination<T> = Extract<keyof T, "target" | "update" | "initialize" | "history" | "stay" | "branches" | "resolve"> extends never ? T extends {
|
|
4316
|
+
readonly reenter: true;
|
|
4317
|
+
} ? unknown : {
|
|
4318
|
+
readonly target: "A transition needs one of: target, update, initialize, history, stay, reenter: true, branches";
|
|
4319
|
+
} : unknown;
|
|
4320
|
+
type ValidateObjectTransition<T, S extends StateSchemas, Src extends string> = ("initialize" extends keyof T ? {
|
|
4321
|
+
readonly [K in Exclude<keyof T, "initialize" | "guard" | "reenter" | "commands">]: never;
|
|
4322
|
+
} : unknown) & {
|
|
4323
|
+
readonly [K in Exclude<keyof T, "target" | "update" | "initialize" | "history" | "stay" | "branches" | "data" | "decoded" | "resolve" | "guard" | "reenter" | "commands">]: never;
|
|
4324
|
+
} & ValidateDestination<T> & ValidateTarget<T, S, Src> & ValidateBranches<T> & ValidateBranchEntries<T, S, Src> & ValidateUpdateOwners<T, S, Src> & ValidateCommands<T>;
|
|
4713
4325
|
type AllowedInvokeChannels<R, K extends PropertyKey> = ([InvokeOutput<ResolvedInvoke<R, K>>] extends [never] ? never : "onDone") | ([RegisteredInvokeError<R, K>] extends [never] ? never : "onFailure") | (SourceKind<R, K> extends "streams" ? [Stream.Success<Extract<InvokeResolvedSource<SourceValue<R, K>>, Stream.Stream<any, any, any>>>] extends [never] ? never : "onElement" : never) | (SourceKind<R, K> extends "logic" | "children" ? "onSnapshot" : never);
|
|
4714
4326
|
type UnreachableInvokeChannelMessage<Channel extends string, Src extends string> = Channel extends "onDone" ? `Invocation '${Src}' never completes, so onDone is unreachable` : Channel extends "onFailure" ? `Invocation '${Src}' cannot fail, so onFailure is unreachable` : Channel extends "onElement" ? `Invocation '${Src}' emits no Stream elements, so onElement is unreachable` : `Invocation '${Src}' has no snapshots; onSnapshot applies only to logic and child invocations`;
|
|
4715
4327
|
type InvokeFieldError<K, Src extends string> = K extends "onDone" | "onFailure" | "onElement" | "onSnapshot" ? InvocationDefinitionError<UnreachableInvokeChannelMessage<K, Src>, Src, K> : K extends string ? InvocationDefinitionError<`Invocation '${Src}' does not accept the field '${K}'`, Src, K> : never;
|
|
@@ -4722,18 +4334,19 @@ export declare namespace Machine {
|
|
|
4722
4334
|
type DuplicateInvokeId<I extends ReadonlyArray<unknown>, K, R> = LiteralInvokeIdAt<I, K, R> extends infer Id ? [
|
|
4723
4335
|
Id
|
|
4724
4336
|
] extends [never] ? never : Id extends LiteralInvokeIdAt<I, Exclude<Extract<keyof I, `${number}`>, K>, R> ? Id : never : never;
|
|
4725
|
-
type ValidateInvokeEntry<I, R, Duplicate extends string, Root> = I extends {
|
|
4337
|
+
type ValidateInvokeEntry<I, R, Duplicate extends string, Root, S extends StateSchemas, Path extends string> = I extends {
|
|
4726
4338
|
/** Name of the source registered in make. */
|
|
4727
4339
|
readonly src: infer Src extends PropertyKey;
|
|
4728
|
-
} ? {
|
|
4729
|
-
readonly [K in keyof I]: [Duplicate] extends [never] ? ValidateInvokeField<I, K, R, Extract<Src, string>, Root> : K extends ("id" extends keyof I ? "id" : "src") ? InvocationDefinitionError<`Invocation id '${Duplicate}' is declared more than once in this state`, Extract<Src, string>, K> : ValidateInvokeField<I, K, R, Extract<Src, string>, Root>;
|
|
4730
|
-
} : never;
|
|
4731
|
-
type ValidateInvokeField<I, K extends keyof I, R, Src extends string, Root> = K extends AllowedInvokeChannels<R, Src> ? ValidateObjectTransition<I[K]> & ValidateChoiceUpdate<I[K],
|
|
4732
|
-
type
|
|
4733
|
-
|
|
4340
|
+
} ? Src extends SourceKeys<R> ? {
|
|
4341
|
+
readonly [K in keyof I]: [Duplicate] extends [never] ? ValidateInvokeField<I, K, R, Extract<Src, string>, Root, S, Path> : K extends ("id" extends keyof I ? "id" : "src") ? InvocationDefinitionError<`Invocation id '${Duplicate}' is declared more than once in this state`, Extract<Src, string>, K> : ValidateInvokeField<I, K, R, Extract<Src, string>, Root, S, Path>;
|
|
4342
|
+
} : UnknownSourceMessage<R> : never;
|
|
4343
|
+
type ValidateInvokeField<I, K extends keyof I, R, Src extends string, Root, S extends StateSchemas, Path extends string> = K extends AllowedInvokeChannels<R, Src> ? ValidateObjectTransition<I[K], S, Path> & ValidateChoiceUpdate<I[K], Root> : K extends "src" | "id" | "address" | "input" ? unknown : InvokeFieldError<K, Src>;
|
|
4344
|
+
type UnknownSourceMessage<R> = [Extract<SourceKeys<R>, string>] extends [never] ? "Unknown source. Register it in make with effects, streams, timers, logic, or children" : `Unknown source. Registered: ${JoinUnion<Extract<SourceKeys<R>, string>>}`;
|
|
4345
|
+
type ValidateObjectInvoke<I, R, Root, S extends StateSchemas, Path extends string> = I extends ReadonlyArray<unknown> ? number extends I["length"] ? {
|
|
4346
|
+
readonly [K in keyof I]: ValidateInvokeEntry<I[K], R, never, Root, S, Path>;
|
|
4734
4347
|
} : {
|
|
4735
|
-
readonly [K in keyof I]: ValidateInvokeEntry<I[K], R, DuplicateInvokeId<I, K, R>, Root>;
|
|
4736
|
-
} : ValidateInvokeEntry<I, R, never, Root>;
|
|
4348
|
+
readonly [K in keyof I]: ValidateInvokeEntry<I[K], R, DuplicateInvokeId<I, K, R>, Root, S, Path>;
|
|
4349
|
+
} : ValidateInvokeEntry<I, R, never, Root, S, Path>;
|
|
4737
4350
|
type HandlerConfigAt<Config, Path extends string> = Config extends {
|
|
4738
4351
|
readonly states: infer Children;
|
|
4739
4352
|
} ? Path extends `${infer Head}.${infer Rest}` ? Head extends keyof Children ? HandlerConfigAt<Children[Head], Rest> : never : Path extends keyof Children ? Children[Path] : never : never;
|
|
@@ -4741,51 +4354,48 @@ export declare namespace Machine {
|
|
|
4741
4354
|
/** Implements this choice pseudo-state with one required synchronous transition. */
|
|
4742
4355
|
readonly choice: infer Choice;
|
|
4743
4356
|
} ? Choice : never;
|
|
4744
|
-
type ChoiceBranchDeclaration<Choice
|
|
4745
|
-
/**
|
|
4746
|
-
readonly branches: infer
|
|
4747
|
-
} ? {
|
|
4748
|
-
readonly
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
};
|
|
4752
|
-
}[Extract<keyof Registered<R, "branches">[G], string>] : {
|
|
4357
|
+
type ChoiceBranchDeclaration<Choice> = Choice extends {
|
|
4358
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
4359
|
+
readonly branches: infer B extends ReadonlyArray<unknown>;
|
|
4360
|
+
} ? B[number] extends infer Entry ? Entry extends unknown ? {
|
|
4361
|
+
readonly label: `branch ${BranchLabel<BranchEntryKey<Entry>>}`;
|
|
4362
|
+
readonly declaration: Entry;
|
|
4363
|
+
} : never : never : {
|
|
4753
4364
|
readonly label: "transition";
|
|
4754
4365
|
readonly declaration: Choice;
|
|
4755
4366
|
};
|
|
4756
4367
|
type IsBelowOwner<Path extends string, Owner extends string> = Owner extends "" ? Path extends "" ? false : true : Path extends `${Owner}.${string}` ? true : false;
|
|
4757
4368
|
type ChoiceBranchEscape<Path extends string, Owner extends string, Choice extends string, Label extends string> = IsBelowOwner<Path, Owner> extends true ? never : TransitionDefinitionError<`Choice '${Choice}' ${Label} targets '${PathName<Path>}' outside the updated owner '${PathName<Owner>}'`, Choice, PathName<Path>>;
|
|
4758
|
-
type ChoiceUpdateEscape<Root,
|
|
4369
|
+
type ChoiceUpdateEscape<Root, Choice extends string, Owner extends string, Visited extends string = never> = Choice extends Visited ? never : ChoiceBranchDeclaration<ChoiceConfigAt<Root, Choice>> extends infer Branch ? Branch extends {
|
|
4759
4370
|
readonly label: infer Label extends string;
|
|
4760
4371
|
readonly declaration: infer D;
|
|
4761
4372
|
} ? D extends {
|
|
4762
|
-
/** Selects a declared descendant
|
|
4373
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
4763
4374
|
readonly target: infer Ref extends string;
|
|
4764
4375
|
} ? [
|
|
4765
4376
|
ChoiceConfigAt<Root, PathOf<Ref>>
|
|
4766
|
-
] extends [never] ? ChoiceBranchEscape<PathOf<Ref>, Owner, Choice, Label> : ChoiceUpdateEscape<Root,
|
|
4377
|
+
] extends [never] ? ChoiceBranchEscape<PathOf<Ref>, Owner, Choice, Label> : ChoiceUpdateEscape<Root, PathOf<Ref>, Owner, Visited | Choice> : D extends {
|
|
4767
4378
|
/** Restores the declared history reference, using its fallback on first entry. */
|
|
4768
4379
|
readonly history: infer Ref extends string;
|
|
4769
4380
|
} ? ChoiceBranchEscape<PathOf<Ref>, Owner, Choice, Label> : D extends {
|
|
4770
4381
|
/** Reconstructs root and its initial children from fresh machine input. */
|
|
4771
4382
|
readonly initialize: unknown;
|
|
4772
4383
|
} ? ChoiceBranchEscape<"", Owner, Choice, Label> : never : never : never;
|
|
4773
|
-
type
|
|
4774
|
-
|
|
4384
|
+
type OwnerNameOf<Update> = Update extends string ? Update : Extract<keyof Update, string>;
|
|
4385
|
+
type ChoiceUpdateEscapeOf<D, Root> = D extends {
|
|
4386
|
+
/** Selects a declared descendant, constructing the values it requires. */
|
|
4775
4387
|
readonly target: infer Ref extends string;
|
|
4776
|
-
/** Replaces the
|
|
4777
|
-
readonly update: infer
|
|
4778
|
-
} ? [ChoiceConfigAt<Root, PathOf<Ref>>] extends [never] ? never : ChoiceUpdateEscape<Root,
|
|
4779
|
-
type ValidateChoiceUpdate<T,
|
|
4780
|
-
/**
|
|
4781
|
-
readonly branches: infer
|
|
4782
|
-
} ? {
|
|
4783
|
-
|
|
4784
|
-
}[keyof Registered<R, "branches">[G]] extends infer Escape ? [Escape] extends [never] ? unknown : {
|
|
4785
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
4388
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
4389
|
+
readonly update: infer Update;
|
|
4390
|
+
} ? [ChoiceConfigAt<Root, PathOf<Ref>>] extends [never] ? never : ChoiceUpdateEscape<Root, PathOf<Ref>, PathOf<OwnerNameOf<Update>>> : never;
|
|
4391
|
+
type ValidateChoiceUpdate<T, Root> = T extends {
|
|
4392
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
4393
|
+
readonly branches: infer B extends ReadonlyArray<unknown>;
|
|
4394
|
+
} ? ChoiceUpdateEscapeOf<B[number], Root> extends infer Escape ? [Escape] extends [never] ? unknown : {
|
|
4395
|
+
/** The destinations this transition can select, each one checked against `resolve`. */
|
|
4786
4396
|
readonly branches: Escape;
|
|
4787
|
-
} : never : ChoiceUpdateEscapeOf<T,
|
|
4788
|
-
/** Replaces the
|
|
4397
|
+
} : never : ChoiceUpdateEscapeOf<T, Root> extends infer Escape ? [Escape] extends [never] ? unknown : {
|
|
4398
|
+
/** Replaces the value of one retained state without replacing its active children. */
|
|
4789
4399
|
readonly update: Escape;
|
|
4790
4400
|
} : never;
|
|
4791
4401
|
type ObjectDeclarations<C> = Extract<keyof C, "on" | "always" | "onDone" | "choice" | "invoke"> | (C extends {
|
|
@@ -4793,12 +4403,14 @@ export declare namespace Machine {
|
|
|
4793
4403
|
} ? {
|
|
4794
4404
|
readonly [K in keyof Children]: ObjectDeclarations<Children[K]>;
|
|
4795
4405
|
}[keyof Children] : never);
|
|
4796
|
-
type ValidateObjectConfig<C, R,
|
|
4406
|
+
type ValidateObjectConfig<C, R, S extends StateSchemas, Path extends string = "", Root = C> = [
|
|
4407
|
+
ObjectDeclarations<C>
|
|
4408
|
+
] extends [never] ? unknown : {
|
|
4797
4409
|
readonly [K in keyof C]: K extends "states" ? {
|
|
4798
|
-
readonly [P in keyof C[K]]: ValidateObjectConfig<C[K][P], R, Root>;
|
|
4410
|
+
readonly [P in keyof C[K]]: ValidateObjectConfig<C[K][P], R, S, JoinPath<Path, Extract<P, string>>, Root>;
|
|
4799
4411
|
} : K extends "on" ? {
|
|
4800
|
-
readonly [P in keyof C[K]]: ValidateObjectTransition<C[K][P]> & ValidateChoiceUpdate<C[K][P],
|
|
4801
|
-
} : K extends "always" | "onDone" ? ValidateObjectTransition<C[K]> & ValidateChoiceUpdate<C[K],
|
|
4412
|
+
readonly [P in keyof C[K]]: ValidateObjectTransition<C[K][P], S, Path> & ValidateChoiceUpdate<C[K][P], Root>;
|
|
4413
|
+
} : K extends "always" | "onDone" ? ValidateObjectTransition<C[K], S, Path> & ValidateChoiceUpdate<C[K], Root> : K extends "choice" ? ValidateObjectTransition<C[K], S, Path> : K extends "invoke" ? ValidateObjectInvoke<C[K], R, Root, S, Path> : unknown;
|
|
4802
4414
|
};
|
|
4803
4415
|
type NormalizeObjectInvoke<I, R> = I extends ReadonlyArray<unknown> ? {
|
|
4804
4416
|
readonly [K in keyof I]: NormalizeObjectInvoke<I[K], R>;
|
|
@@ -4811,10 +4423,17 @@ export declare namespace Machine {
|
|
|
4811
4423
|
readonly [P in keyof C[K]]: NormalizeObjectConfig<C[K][P], R>;
|
|
4812
4424
|
} : K extends "invoke" ? NormalizeObjectInvoke<C[K], R> : C[K];
|
|
4813
4425
|
};
|
|
4814
|
-
type
|
|
4426
|
+
type InvokeShape<I, H, R> = I extends ReadonlyArray<{
|
|
4427
|
+
readonly src: infer Src;
|
|
4428
|
+
}> ? [
|
|
4429
|
+
Exclude<Src, SourceKeys<R>>
|
|
4430
|
+
] extends [never] ? H : UnknownSourceMessage<R> : I extends {
|
|
4431
|
+
readonly src: infer Src;
|
|
4432
|
+
} ? [Src] extends [SourceKeys<R>] ? H : UnknownSourceMessage<R> : H;
|
|
4433
|
+
type HandlerShape<C, H, R> = {
|
|
4815
4434
|
readonly [K in keyof C]: K extends keyof H ? K extends "states" ? {
|
|
4816
|
-
readonly [P in keyof C[K]]: P extends keyof NonNullable<H[K]> ? HandlerShape<C[K][P], NonNullable<NonNullable<H[K]>[P]
|
|
4817
|
-
} : H[K] : never;
|
|
4435
|
+
readonly [P in keyof C[K]]: P extends keyof NonNullable<H[K]> ? HandlerShape<C[K][P], NonNullable<NonNullable<H[K]>[P]>, R> : never;
|
|
4436
|
+
} : K extends "invoke" ? InvokeShape<C[K], H[K], R> : H[K] : never;
|
|
4818
4437
|
} & Omit<H, keyof C>;
|
|
4819
4438
|
/**
|
|
4820
4439
|
* Adds object handlers while checking topology, protocols, invocation outcomes, and readiness.
|
|
@@ -4822,14 +4441,12 @@ export declare namespace Machine {
|
|
|
4822
4441
|
* @category combinators
|
|
4823
4442
|
* @since 0.34.0
|
|
4824
4443
|
*/
|
|
4825
|
-
interface Handler<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, I extends Schema.Top, IE, IR, Final extends StateIdentifier<S>, Out, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> {
|
|
4826
|
-
<const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R & {
|
|
4444
|
+
export interface Handler<S extends StateSchemas, Ev extends ReadonlyArray<TaggedSchema>, Em extends ReadonlyArray<TaggedSchema>, I extends Schema.Top, IE, IR, Final extends StateIdentifier<S>, Out, In extends ReadonlyArray<TaggedSchema>, Pa extends ReadonlyArray<TaggedSchema>, R> {
|
|
4445
|
+
<const C>(config: C & (C extends (...args: never[]) => unknown ? never : unknown) & ValidateObjectConfig<NoInfer<C>, R, S> & HandlerShape<C, StateHandler<S, S[""], Ev, Em, Extract<"", StateNodeIdentifier<S>>, In, Pa, R & {
|
|
4827
4446
|
readonly "~input": I;
|
|
4828
|
-
}> & RootConstruction<S[""], I["Type"]
|
|
4447
|
+
}> & RootConstruction<S[""], I["Type"]>, R> & RootConstruction<S[""], I["Type"]> & RootHandlerValidation<S, Ev, In, Em, NormalizeObjectConfig<NoInfer<C>, R>, Extract<HandlerTreeEvidence<S, {
|
|
4829
4448
|
readonly "": NormalizeObjectConfig<NoInfer<C>, R>;
|
|
4830
|
-
}>["outputState"], StateIdentifier<S>>>):
|
|
4831
|
-
readonly "": NormalizeObjectConfig<C, R>;
|
|
4832
|
-
}>;
|
|
4449
|
+
}>["outputState"], StateIdentifier<S>>>): Machine<S, Ev, I, Exclude<StateIdentifier<S>, HandleEvidence<S, C, R>["stateId"]>, HandleEvidence<S, C, R>["error"], ExcludeCompatibleRuntime<HandleEvidence<S, C, R>["services"], EventOf<Ev>, EmittedEventOf<Em>>, IE, IR, Final, Out, Em, Extract<HandleEvidence<S, C, R>["outputState"], StateIdentifier<S>>, In, Pa>;
|
|
4833
4450
|
}
|
|
4834
4451
|
/**
|
|
4835
4452
|
* Any state config.
|
|
@@ -4837,21 +4454,21 @@ export declare namespace Machine {
|
|
|
4837
4454
|
* @category utility types
|
|
4838
4455
|
* @since 0.4.0
|
|
4839
4456
|
*/
|
|
4840
|
-
type AnyStateConfig = StateConfig<any, any, any, any, any, any, any> | ChoiceStateConfig<any, any, any, any>;
|
|
4457
|
+
export type AnyStateConfig = StateConfig<any, any, any, any, any, any, any> | ChoiceStateConfig<any, any, any, any>;
|
|
4841
4458
|
/**
|
|
4842
4459
|
* Runtime event-handler map stored for a single state tag.
|
|
4843
4460
|
*
|
|
4844
4461
|
* @category models
|
|
4845
4462
|
* @since 0.4.0
|
|
4846
4463
|
*/
|
|
4847
|
-
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, TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, true, TransitionAcceptance>>>;
|
|
4464
|
+
export 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, TransitionConfig<States, Events, Emits, StateId, HandlerContext<States, Events, Emits, StateId, EventTag, E, R>, true, TransitionAcceptance>>>;
|
|
4848
4465
|
/**
|
|
4849
4466
|
* Runtime state config stored for a single state tag.
|
|
4850
4467
|
*
|
|
4851
4468
|
* @category models
|
|
4852
4469
|
* @since 0.4.0
|
|
4853
4470
|
*/
|
|
4854
|
-
interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
4471
|
+
export interface StateConfig<States extends StateSchemas, Events extends ReadonlyArray<TaggedSchema>, Emits extends ReadonlyArray<TaggedSchema>, StateId extends StateIdentifier<States>, EventTag extends TagOf<Events[number]>, E, R> {
|
|
4855
4472
|
/** Runs synchronously on entry and may enqueue commands. */
|
|
4856
4473
|
readonly entry?: (context: StateActionContext<States, Events, Emits, StateId>, enqueue: Enqueue<EventOf<Events>, EmittedEventOf<Emits>>) => StateActionResult<E, R>;
|
|
4857
4474
|
/** Runs synchronously on exit and may enqueue commands. */
|
|
@@ -4867,13 +4484,7 @@ export declare namespace Machine {
|
|
|
4867
4484
|
/** Event handlers keyed by the public or internal event tag. */
|
|
4868
4485
|
readonly on?: EventHandlerMap<States, Events, Emits, StateId, EventTag, E, R>;
|
|
4869
4486
|
}
|
|
4870
|
-
|
|
4871
|
-
* Runtime handler table stored on a machine.
|
|
4872
|
-
*
|
|
4873
|
-
* @category models
|
|
4874
|
-
* @since 0.4.0
|
|
4875
|
-
*/
|
|
4876
|
-
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>>>>;
|
|
4487
|
+
export {};
|
|
4877
4488
|
}
|
|
4878
4489
|
type StateSource = State<any> | Machine.Any;
|
|
4879
4490
|
type StateSchemasOf<Source extends StateSource> = Source extends State<infer Node> ? {
|
|
@@ -4915,8 +4526,8 @@ export declare namespace Snapshot {
|
|
|
4915
4526
|
/**
|
|
4916
4527
|
* Extracts the decoded value owned by a schema-backed state path.
|
|
4917
4528
|
*
|
|
4918
|
-
* The source may be
|
|
4919
|
-
*
|
|
4529
|
+
* The source may be a descriptor returned by {@link state} or a machine.
|
|
4530
|
+
* Control-only state paths are intentionally excluded.
|
|
4920
4531
|
*
|
|
4921
4532
|
* @category utility types
|
|
4922
4533
|
* @since 0.18.0
|
|
@@ -4925,9 +4536,8 @@ export type Value<Source extends StateSource, Path extends Machine.ValuedStateId
|
|
|
4925
4536
|
/**
|
|
4926
4537
|
* Extracts the logical snapshot rooted at a state path.
|
|
4927
4538
|
*
|
|
4928
|
-
* The source may be
|
|
4929
|
-
*
|
|
4930
|
-
* `State.getSnapshot`.
|
|
4539
|
+
* The source may be a descriptor returned by {@link state} or a machine.
|
|
4540
|
+
* This is the type-level counterpart of a descriptor's `getSnapshot`.
|
|
4931
4541
|
*
|
|
4932
4542
|
* @category utility types
|
|
4933
4543
|
* @since 0.18.0
|
|
@@ -4954,16 +4564,13 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
4954
4564
|
* can be declared inline or reused by mounting a descriptor in multiple places.
|
|
4955
4565
|
* Initial edges and value constructors belong in the handler tree.
|
|
4956
4566
|
*
|
|
4957
|
-
* **Example** (
|
|
4567
|
+
* **Example** (Reusing one subtree in two parallel regions)
|
|
4958
4568
|
*
|
|
4959
|
-
* ```ts
|
|
4569
|
+
* ```ts import.meta.vitest
|
|
4960
4570
|
* import { Machine } from "@typeonce/effect-machine"
|
|
4961
|
-
* import { Schema } from "effect"
|
|
4571
|
+
* import { Effect, Schema } from "effect"
|
|
4962
4572
|
*
|
|
4963
|
-
* const TradingState = Schema.TaggedUnion({
|
|
4964
|
-
* InSession: {},
|
|
4965
|
-
* Applying: {}
|
|
4966
|
-
* })
|
|
4573
|
+
* const TradingState = Schema.TaggedUnion({ InSession: {}, Applying: {} })
|
|
4967
4574
|
* const TradingSlot = Machine.state({
|
|
4968
4575
|
* states: {
|
|
4969
4576
|
* Idle: {},
|
|
@@ -4971,13 +4578,21 @@ export declare const isFinal: <const States extends Machine.StateSchemas, const
|
|
|
4971
4578
|
* Applying: TradingState.cases.Applying
|
|
4972
4579
|
* }
|
|
4973
4580
|
* })
|
|
4581
|
+
* const States = Machine.state({ type: "parallel", states: { slot1: TradingSlot, slot2: TradingSlot } })
|
|
4974
4582
|
*
|
|
4975
|
-
* const
|
|
4583
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
4976
4584
|
* states: {
|
|
4977
|
-
* slot1:
|
|
4978
|
-
* slot2:
|
|
4585
|
+
* slot1: { initial: { target: "slot1.Idle" } },
|
|
4586
|
+
* slot2: { initial: { target: "slot2.Idle" } }
|
|
4979
4587
|
* }
|
|
4980
4588
|
* })
|
|
4589
|
+
*
|
|
4590
|
+
* const paths = Effect.map(Machine.planInitial(machine), ({ state }) => [
|
|
4591
|
+
* state.states.slot1.state.path,
|
|
4592
|
+
* state.states.slot2.state.path
|
|
4593
|
+
* ])
|
|
4594
|
+
*
|
|
4595
|
+
* await Effect.runPromise(paths) // => ["slot1.Idle", "slot2.Idle"]
|
|
4981
4596
|
* ```
|
|
4982
4597
|
*
|
|
4983
4598
|
* @category constructors
|
|
@@ -4994,7 +4609,7 @@ type ReservedRootName<Root> = Root extends {
|
|
|
4994
4609
|
} ? "root" extends keyof Children ? {
|
|
4995
4610
|
readonly "~effect/Machine/ReservedRootStateName": never;
|
|
4996
4611
|
} : unknown : unknown;
|
|
4997
|
-
type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources
|
|
4612
|
+
type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources> = {
|
|
4998
4613
|
/** Lazy Effects or functions with one required input, invoked by registered name. */
|
|
4999
4614
|
readonly effects?: Effects & Machine.ValidatePrograms<Effects>;
|
|
5000
4615
|
/** Lazy Streams or functions with one required input, invoked by registered name. */
|
|
@@ -5005,10 +4620,6 @@ type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends Readon
|
|
|
5005
4620
|
readonly logic?: Logics & Machine.ValidatePrograms<Logics> & Machine.ValidateLogicSources<NoInfer<Logics>>;
|
|
5006
4621
|
/** Child machine descriptors registered for state-owned invocation. */
|
|
5007
4622
|
readonly children?: Children;
|
|
5008
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
5009
|
-
readonly branches?: Branches & {
|
|
5010
|
-
readonly [K in keyof Branches]: ValidateTransitionBranchRecord<NoInfer<Branches[K]>>;
|
|
5011
|
-
};
|
|
5012
4623
|
/** Stable definition identifier used by inspection and visualization. */
|
|
5013
4624
|
readonly id?: string;
|
|
5014
4625
|
/** State topology and value schemas, captured by a `Machine.state` descriptor. */
|
|
@@ -5027,7 +4638,7 @@ type MakeConfig<Root extends Machine.StateNodeConfig, InputEvents extends Readon
|
|
|
5027
4638
|
/** Schema used to decode input before initial-state construction. */
|
|
5028
4639
|
readonly input?: Input;
|
|
5029
4640
|
};
|
|
5030
|
-
type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources
|
|
4641
|
+
type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends ReadonlyArray<Machine.TaggedSchema>, Emits extends ReadonlyArray<Machine.TaggedSchema>, Input extends Schema.Top, InitialE, InitialR, InternalEvents extends ReadonlyArray<Machine.TaggedSchema>, ParentDeclaration extends Parent.Any | undefined, Effects extends Machine.EffectSources, Streams extends Machine.StreamSources, Timers extends Machine.TimerSources, Logics extends Machine.LogicSources, Children extends Machine.ChildSources> = Definition<{
|
|
5031
4642
|
readonly "": Root;
|
|
5032
4643
|
}, readonly [...InputEvents, ...InternalEvents], Input, InitialE, InitialR, Machine.FinalStateFromDefinition<{
|
|
5033
4644
|
readonly "": Root;
|
|
@@ -5044,29 +4655,27 @@ type MakeResult<Root extends Machine.StateNodeConfig, InputEvents extends Readon
|
|
|
5044
4655
|
readonly logic: Logics;
|
|
5045
4656
|
/** Child machine descriptors registered for state-owned invocation. */
|
|
5046
4657
|
readonly children: Children;
|
|
5047
|
-
/** Named groups of inspectable destinations used by transition resolvers. */
|
|
5048
|
-
readonly branches: Branches;
|
|
5049
4658
|
}>;
|
|
5050
4659
|
/** @inline */
|
|
5051
|
-
|
|
4660
|
+
type Make = {
|
|
5052
4661
|
/** @param config Complete schema-first machine definition. */
|
|
5053
|
-
<const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}
|
|
5054
|
-
}
|
|
4662
|
+
<const Root extends Machine.StateNodeConfig, const InputEvents extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, InitialE = never, InitialR = never, const InternalEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const ParentDeclaration extends Parent.Any | undefined = undefined, const Effects extends Machine.EffectSources = {}, const Streams extends Machine.StreamSources = {}, const Timers extends Machine.TimerSources = {}, const Logics extends Machine.LogicSources = {}, const Children extends Machine.ChildSources = {}>(config: MakeConfig<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children> & UniqueSourceNames<NoInfer<Effects>, NoInfer<Streams>, NoInfer<Timers>, NoInfer<Logics>, NoInfer<Children>>): MakeResult<Root, InputEvents, Emits, Input, InitialE, InitialR, InternalEvents, ParentDeclaration, Effects, Streams, Timers, Logics, Children>;
|
|
4663
|
+
};
|
|
5055
4664
|
/**
|
|
5056
4665
|
* Creates a schema-first machine definition.
|
|
5057
4666
|
*
|
|
5058
4667
|
* **Details**
|
|
5059
4668
|
*
|
|
5060
|
-
*
|
|
5061
|
-
*
|
|
5062
|
-
*
|
|
5063
|
-
* `
|
|
5064
|
-
*
|
|
4669
|
+
* `root` is the `Machine.state` descriptor of the complete state tree. State
|
|
4670
|
+
* and event schemas provide runtime boundary validation while their decoded
|
|
4671
|
+
* types drive handler, state, event, target, error, and service inference.
|
|
4672
|
+
* Call `handle` on the returned {@link Definition} to declare the initial
|
|
4673
|
+
* target and the behavior of each state.
|
|
5065
4674
|
*
|
|
5066
|
-
*
|
|
5067
|
-
*
|
|
5068
|
-
*
|
|
5069
|
-
*
|
|
4675
|
+
* Register Effects, Streams, timers, logic, and child machines under
|
|
4676
|
+
* `effects`, `streams`, `timers`, `logic`, and `children`. A state invokes a
|
|
4677
|
+
* registered source by name with `invoke: { src }`, and only invoked sources
|
|
4678
|
+
* add to the machine's requirements.
|
|
5070
4679
|
*
|
|
5071
4680
|
* `Machine.events` defines the public input protocol. `Machine.internalEvents`
|
|
5072
4681
|
* adds raised events and other machine-local deliveries.
|
|
@@ -5077,42 +4686,82 @@ interface Make {
|
|
|
5077
4686
|
* schemas opaquely for runtime validation. Public and internal tags must be
|
|
5078
4687
|
* disjoint.
|
|
5079
4688
|
*
|
|
5080
|
-
* **
|
|
4689
|
+
* **Gotchas**
|
|
5081
4690
|
*
|
|
5082
|
-
*
|
|
4691
|
+
* Source names must be unique across all five registries. A top-level state
|
|
4692
|
+
* cannot be named `root`, because `root` names the root state.
|
|
4693
|
+
*
|
|
4694
|
+
* **Example** (Invoking a registered Effect)
|
|
4695
|
+
*
|
|
4696
|
+
* ```ts import.meta.vitest
|
|
5083
4697
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5084
|
-
* import { Schema } from "effect"
|
|
5085
|
-
*
|
|
5086
|
-
*
|
|
5087
|
-
* })
|
|
5088
|
-
* }
|
|
5089
|
-
*
|
|
5090
|
-
*
|
|
5091
|
-
*
|
|
5092
|
-
*
|
|
4698
|
+
* import { Effect, Option, Schema } from "effect"
|
|
4699
|
+
*
|
|
4700
|
+
* const Lookup = Schema.TaggedUnion({ Loading: { id: Schema.String }, Ready: { name: Schema.String } })
|
|
4701
|
+
* const States = Machine.state({ states: { Idle: {}, Loading: Lookup.cases.Loading, Ready: Lookup.cases.Ready } })
|
|
4702
|
+
* const Events = Machine.events({ Load: { id: Schema.String } })
|
|
4703
|
+
*
|
|
4704
|
+
* const machine = Machine.make({
|
|
4705
|
+
* root: States,
|
|
4706
|
+
* events: Events,
|
|
4707
|
+
* effects: { findName: (id: string) => Effect.succeed(`User ${id}`) }
|
|
4708
|
+
* }).handle({
|
|
4709
|
+
* initial: { target: "Idle" },
|
|
4710
|
+
* states: {
|
|
4711
|
+
* Idle: { on: { Load: { target: "Loading", data: ({ event }) => ({ id: event.id }) } } },
|
|
4712
|
+
* Loading: {
|
|
4713
|
+
* invoke: {
|
|
4714
|
+
* src: "findName",
|
|
4715
|
+
* input: ({ state }) => state.id,
|
|
4716
|
+
* onDone: { target: "Ready", data: ({ output }) => ({ name: output }) }
|
|
4717
|
+
* }
|
|
4718
|
+
* }
|
|
4719
|
+
* }
|
|
4720
|
+
* })
|
|
4721
|
+
*
|
|
4722
|
+
* const name = Effect.scoped(Effect.gen(function*() {
|
|
4723
|
+
* const ref = yield* Machine.start(machine)
|
|
4724
|
+
* yield* ref.send(Events.Load({ id: "1" }))
|
|
4725
|
+
* const ready = yield* Machine.waitFor(ref, ({ state }) => state.state.path === "Ready").pipe(Effect.timeout("5 seconds"))
|
|
4726
|
+
* return States.get(ready.state, "Ready").pipe(Option.map((state) => state.name))
|
|
4727
|
+
* }))
|
|
4728
|
+
*
|
|
4729
|
+
* await Effect.runPromise(name) // => Option.some("User 1")
|
|
4730
|
+
* ```
|
|
4731
|
+
*
|
|
4732
|
+
* **Example** (Counting with schema classes)
|
|
4733
|
+
*
|
|
4734
|
+
* ```ts import.meta.vitest
|
|
4735
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
4736
|
+
* import { Effect, Option, Schema } from "effect"
|
|
4737
|
+
*
|
|
4738
|
+
* class Count extends Schema.TaggedClass<Count>("Count")("Count", { value: Schema.Number }) {}
|
|
4739
|
+
* class Increment extends Schema.TaggedClass<Increment>("Increment")("Increment", { by: Schema.Number }) {}
|
|
4740
|
+
*
|
|
5093
4741
|
* const States = Machine.state({ states: { Count } })
|
|
5094
|
-
* const Events = Machine.eventsFromSchemas(Increment)
|
|
5095
4742
|
* const counter = Machine.make({
|
|
5096
4743
|
* root: States,
|
|
5097
|
-
* events:
|
|
4744
|
+
* events: Machine.eventsFromSchemas(Increment)
|
|
5098
4745
|
* }).handle({
|
|
5099
|
-
* initial: {
|
|
5100
|
-
* target: "Count",
|
|
5101
|
-
* decoded: true,
|
|
5102
|
-
* data: new Count({ value: 0 })
|
|
5103
|
-
* },
|
|
4746
|
+
* initial: { target: "Count", decoded: true, data: new Count({ value: 0 }) },
|
|
5104
4747
|
* states: {
|
|
5105
4748
|
* Count: {
|
|
5106
4749
|
* on: {
|
|
5107
4750
|
* Increment: {
|
|
5108
|
-
* update:
|
|
5109
|
-
* decoded: true,
|
|
5110
|
-
* data: ({ event, state }) => new Count({ value: state.value + event.by })
|
|
4751
|
+
* update: { Count: { decoded: true, data: ({ event, state }) => new Count({ value: state.value + event.by }) } }
|
|
5111
4752
|
* }
|
|
5112
4753
|
* }
|
|
5113
4754
|
* }
|
|
5114
4755
|
* }
|
|
5115
4756
|
* })
|
|
4757
|
+
*
|
|
4758
|
+
* const value = Effect.gen(function*() {
|
|
4759
|
+
* const initial = yield* Machine.planInitial(counter)
|
|
4760
|
+
* const planned = yield* Machine.plan(counter, initial.state, new Increment({ by: 2 }))
|
|
4761
|
+
* return States.get(planned.next, "Count").pipe(Option.map((count) => count.value))
|
|
4762
|
+
* })
|
|
4763
|
+
*
|
|
4764
|
+
* await Effect.runPromise(value) // => Option.some(2)
|
|
5116
4765
|
* ```
|
|
5117
4766
|
*
|
|
5118
4767
|
* @see {@link state} for typed state-tree helpers.
|
|
@@ -5128,53 +4777,76 @@ export declare const make: Make;
|
|
|
5128
4777
|
* @since 0.10.0
|
|
5129
4778
|
*/
|
|
5130
4779
|
export type EventOf<Protocol extends Machine.EventProtocol.Any> = Machine.EventOf<Machine.EventProtocolSchemas<Protocol>>;
|
|
4780
|
+
type EventFieldsSchemas<Cases extends Readonly<Record<string, Schema.Struct.Fields>>> = keyof Cases extends never ? readonly [] : readonly [
|
|
4781
|
+
Extract<Schema.TaggedUnion<{
|
|
4782
|
+
readonly [Tag in keyof Cases & string]: Schema.TaggedStruct<Tag, Cases[Tag]>;
|
|
4783
|
+
}>, Machine.TaggedSchema>
|
|
4784
|
+
];
|
|
4785
|
+
type ValidateEventFields<Cases> = {
|
|
4786
|
+
readonly [Tag in keyof Cases]: "_tag" extends keyof Cases[Tag] ? EventProtocolError<"Event fields cannot declare _tag", Extract<Tag, PropertyKey>> : unknown;
|
|
4787
|
+
};
|
|
4788
|
+
/**
|
|
4789
|
+
* Defines a public event protocol from tagged field records.
|
|
4790
|
+
*
|
|
4791
|
+
* Constructors defer schema validation until delivery. Use
|
|
4792
|
+
* {@link eventsFromSchemas} when importing existing tagged schemas or protocol
|
|
4793
|
+
* descriptors.
|
|
4794
|
+
*
|
|
4795
|
+
* **Example** (Defining events from fields)
|
|
4796
|
+
*
|
|
4797
|
+
* ```ts import.meta.vitest
|
|
4798
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
4799
|
+
* import { Schema } from "effect"
|
|
4800
|
+
*
|
|
4801
|
+
* const Events = Machine.events({ Increment: { by: Schema.Number }, Reset: {} })
|
|
4802
|
+
*
|
|
4803
|
+
* Events.Increment({ by: 1 })._tag // => "Increment"
|
|
4804
|
+
* Events.Reset()._tag // => "Reset"
|
|
4805
|
+
* ```
|
|
4806
|
+
*
|
|
4807
|
+
* @category constructors
|
|
4808
|
+
* @since 0.32.0
|
|
4809
|
+
*/
|
|
4810
|
+
export declare const events: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"public", EventFieldsSchemas<Cases>>) => Machine.EventProtocol<"public", EventFieldsSchemas<Cases>>;
|
|
5131
4811
|
/**
|
|
5132
|
-
* Defines a public event protocol
|
|
5133
|
-
*
|
|
4812
|
+
* Defines a public event protocol from existing tagged schemas or protocol
|
|
4813
|
+
* descriptors, without rebuilding their contracts, and returns deferred
|
|
4814
|
+
* constructors for every statically finite configured event tag.
|
|
5134
4815
|
*
|
|
5135
4816
|
* Constructor inputs retain their schema-derived required fields, defaults,
|
|
5136
4817
|
* and transformations. Construction is deferred until delivery so failures
|
|
5137
4818
|
* enter the machine's `MachineSchemaDecodeError` channel rather than throwing
|
|
5138
4819
|
* at the call site.
|
|
5139
4820
|
*
|
|
5140
|
-
* **Example**
|
|
4821
|
+
* **Example** (Reusing a tagged union as the event protocol)
|
|
5141
4822
|
*
|
|
5142
|
-
* ```ts
|
|
5143
|
-
*
|
|
4823
|
+
* ```ts import.meta.vitest
|
|
4824
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
4825
|
+
* import { Effect, Schema } from "effect"
|
|
4826
|
+
*
|
|
4827
|
+
* const Event = Machine.eventsFromSchemas(
|
|
5144
4828
|
* Schema.TaggedUnion({
|
|
5145
4829
|
* Increment: { by: Schema.Number },
|
|
5146
4830
|
* Reset: {}
|
|
5147
4831
|
* })
|
|
5148
4832
|
* )
|
|
5149
|
-
* const machine = Machine.make({ events: Event
|
|
5150
|
-
*
|
|
5151
|
-
*
|
|
4833
|
+
* const machine = Machine.make({ root: Machine.state({ fields: { count: Schema.Number } }), events: Event }).handle({
|
|
4834
|
+
* root: { count: 0 },
|
|
4835
|
+
* on: {
|
|
4836
|
+
* Increment: { update: { root: ({ root, event }) => ({ count: root.count + event.by }) } },
|
|
4837
|
+
* Reset: { update: { root: { count: 0 } } }
|
|
4838
|
+
* }
|
|
4839
|
+
* })
|
|
5152
4840
|
*
|
|
5153
|
-
*
|
|
5154
|
-
*
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
readonly [Tag in keyof Cases & string]: Schema.TaggedStruct<Tag, Cases[Tag]>;
|
|
5159
|
-
}>, Machine.TaggedSchema>
|
|
5160
|
-
];
|
|
5161
|
-
type ValidateEventFields<Cases> = {
|
|
5162
|
-
readonly [Tag in keyof Cases]: "_tag" extends keyof Cases[Tag] ? EventProtocolError<"Event fields cannot declare _tag", Extract<Tag, PropertyKey>> : unknown;
|
|
5163
|
-
};
|
|
5164
|
-
/** Defines a public event protocol from tagged field records.
|
|
4841
|
+
* const count = Effect.scoped(Effect.gen(function*() {
|
|
4842
|
+
* const ref = yield* Machine.start(machine)
|
|
4843
|
+
* yield* ref.send(Event.Increment({ by: 1 }))
|
|
4844
|
+
* return (yield* ref.state).value.count
|
|
4845
|
+
* }))
|
|
5165
4846
|
*
|
|
5166
|
-
*
|
|
5167
|
-
* const Events = Machine.events({ Increment: { by: Schema.Number }, Reset: {} })
|
|
5168
|
-
* const increment = Events.Increment({ by: 1 })
|
|
4847
|
+
* await Effect.runPromise(count) // => 1
|
|
5169
4848
|
* ```
|
|
5170
4849
|
*
|
|
5171
|
-
* Constructors defer schema validation until delivery. Use eventsFromSchemas
|
|
5172
|
-
* when importing existing tagged schemas or protocol descriptors.
|
|
5173
|
-
* @category constructors
|
|
5174
|
-
* @since 0.32.0
|
|
5175
|
-
*/
|
|
5176
|
-
export declare const events: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"public", EventFieldsSchemas<Cases>>) => Machine.EventProtocol<"public", EventFieldsSchemas<Cases>>;
|
|
5177
|
-
/** Imports existing schemas and protocols without rebuilding their contracts.
|
|
5178
4850
|
* @category constructors
|
|
5179
4851
|
* @since 0.32.0
|
|
5180
4852
|
*/
|
|
@@ -5208,28 +4880,48 @@ export declare const optionalParent: <const Events extends ReadonlyArray<Machine
|
|
|
5208
4880
|
*
|
|
5209
4881
|
* Use these constructors for raised events and other machine-local deliveries.
|
|
5210
4882
|
* Construction failures are reported through the
|
|
5211
|
-
* owning machine's `MachineSchemaDecodeError` channel.
|
|
4883
|
+
* owning machine's `MachineSchemaDecodeError` channel. Use
|
|
4884
|
+
* {@link internalEventsFromSchemas} when importing existing tagged schemas or
|
|
4885
|
+
* protocol descriptors.
|
|
5212
4886
|
*
|
|
5213
|
-
* **Example**
|
|
4887
|
+
* **Example** (Raising an internal event)
|
|
5214
4888
|
*
|
|
5215
|
-
* ```ts
|
|
5216
|
-
*
|
|
5217
|
-
*
|
|
5218
|
-
* Loaded: { value: Schema.String },
|
|
5219
|
-
* Failed: { message: Schema.String }
|
|
5220
|
-
* })
|
|
5221
|
-
* )
|
|
5222
|
-
* const machine = Machine.make({ internalEvents: Internal, ... })
|
|
4889
|
+
* ```ts import.meta.vitest
|
|
4890
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
4891
|
+
* import { Effect, Schema } from "effect"
|
|
5223
4892
|
*
|
|
5224
|
-
*
|
|
5225
|
-
*
|
|
4893
|
+
* const Events = Machine.events({ Load: { value: Schema.String } })
|
|
4894
|
+
* const Internal = Machine.internalEvents({ Loaded: { value: Schema.String }, Failed: { message: Schema.String } })
|
|
4895
|
+
* const machine = Machine.make({
|
|
4896
|
+
* root: Machine.state({ fields: { value: Schema.String } }),
|
|
4897
|
+
* events: Events,
|
|
4898
|
+
* internalEvents: Internal
|
|
4899
|
+
* }).handle({
|
|
4900
|
+
* root: { value: "" },
|
|
4901
|
+
* on: {
|
|
4902
|
+
* Load: { stay: true, commands: ({ event }, enqueue) => enqueue.raise(Internal.Loaded({ value: event.value })) },
|
|
4903
|
+
* Loaded: { update: { root: ({ event }) => ({ value: event.value }) } },
|
|
4904
|
+
* Failed: { stay: true }
|
|
4905
|
+
* }
|
|
4906
|
+
* })
|
|
4907
|
+
*
|
|
4908
|
+
* const value = Effect.gen(function*() {
|
|
4909
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
4910
|
+
* const planned = yield* Machine.plan(machine, initial.state, Events.Load({ value: "ready" }))
|
|
4911
|
+
* return planned.next.value.value
|
|
4912
|
+
* })
|
|
4913
|
+
*
|
|
4914
|
+
* await Effect.runPromise(value) // => "ready"
|
|
5226
4915
|
* ```
|
|
5227
4916
|
*
|
|
5228
4917
|
* @category constructors
|
|
5229
4918
|
* @since 0.10.0
|
|
5230
4919
|
*/
|
|
5231
4920
|
export declare const internalEvents: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"internal", EventFieldsSchemas<Cases>>) => Machine.EventProtocol<"internal", EventFieldsSchemas<Cases>>;
|
|
5232
|
-
/**
|
|
4921
|
+
/**
|
|
4922
|
+
* Defines an internal event protocol from existing tagged schemas or protocol
|
|
4923
|
+
* descriptors, without rebuilding their contracts.
|
|
4924
|
+
*
|
|
5233
4925
|
* @category constructors
|
|
5234
4926
|
* @since 0.32.0
|
|
5235
4927
|
*/
|
|
@@ -5240,24 +4932,47 @@ export declare const internalEventsFromSchemas: {
|
|
|
5240
4932
|
* Defines the ephemeral notifications a machine may publish to external
|
|
5241
4933
|
* observers. Emitted events are separate from machine input and are never sent
|
|
5242
4934
|
* implicitly to a parent machine. Observe them through `MachineRef.emissions` or
|
|
5243
|
-
* the AtomMachine emission stream adapters.
|
|
4935
|
+
* the AtomMachine emission stream adapters. Use {@link emittedEventsFromSchemas}
|
|
4936
|
+
* when importing existing tagged schemas or protocol descriptors.
|
|
5244
4937
|
*
|
|
5245
|
-
* **Example**
|
|
4938
|
+
* **Example** (Emitting an event to observers)
|
|
5246
4939
|
*
|
|
5247
|
-
* ```ts
|
|
5248
|
-
*
|
|
5249
|
-
*
|
|
5250
|
-
*
|
|
5251
|
-
*
|
|
5252
|
-
* )
|
|
5253
|
-
* const machine = Machine.make({
|
|
4940
|
+
* ```ts import.meta.vitest
|
|
4941
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
4942
|
+
* import { Effect, Schema } from "effect"
|
|
4943
|
+
*
|
|
4944
|
+
* const Events = Machine.events({ Save: { id: Schema.String } })
|
|
4945
|
+
* const Emitted = Machine.emittedEvents({ Saved: { id: Schema.String } })
|
|
4946
|
+
* const machine = Machine.make({
|
|
4947
|
+
* root: Machine.state({ states: { Idle: {} } }),
|
|
4948
|
+
* events: Events,
|
|
4949
|
+
* emittedEvents: Emitted
|
|
4950
|
+
* }).handle({
|
|
4951
|
+
* initial: { target: "Idle" },
|
|
4952
|
+
* states: {
|
|
4953
|
+
* Idle: {
|
|
4954
|
+
* on: { Save: { stay: true, commands: ({ event }, enqueue) => enqueue.emit(Emitted.Saved({ id: event.id })) } }
|
|
4955
|
+
* }
|
|
4956
|
+
* }
|
|
4957
|
+
* })
|
|
4958
|
+
*
|
|
4959
|
+
* const emitted = Effect.gen(function*() {
|
|
4960
|
+
* const initial = yield* Machine.planInitial(machine)
|
|
4961
|
+
* const planned = yield* Machine.plan(machine, initial.state, Events.Save({ id: "a" }))
|
|
4962
|
+
* return planned.emittedEvents.length
|
|
4963
|
+
* })
|
|
4964
|
+
*
|
|
4965
|
+
* await Effect.runPromise(emitted) // => 1
|
|
5254
4966
|
* ```
|
|
5255
4967
|
*
|
|
5256
4968
|
* @category constructors
|
|
5257
4969
|
* @since 0.10.0
|
|
5258
4970
|
*/
|
|
5259
4971
|
export declare const emittedEvents: <const Cases extends Readonly<Record<string, Schema.Struct.Fields>>>(cases: Cases & ValidateEventFields<NoInfer<Cases>> & ValidateEventProtocolBuilder<"emitted", EventFieldsSchemas<Cases>>) => Machine.EventProtocol<"emitted", EventFieldsSchemas<Cases>>;
|
|
5260
|
-
/**
|
|
4972
|
+
/**
|
|
4973
|
+
* Defines an emitted event protocol from existing tagged schemas or protocol
|
|
4974
|
+
* descriptors, without rebuilding their contracts.
|
|
4975
|
+
*
|
|
5261
4976
|
* @category constructors
|
|
5262
4977
|
* @since 0.32.0
|
|
5263
4978
|
*/
|
|
@@ -5290,29 +5005,24 @@ export declare const emittedEventsFromSchemas: {
|
|
|
5290
5005
|
* Define an explicit JSON codec or keep process-local capabilities outside the
|
|
5291
5006
|
* logical snapshot.
|
|
5292
5007
|
*
|
|
5293
|
-
* **Example**
|
|
5008
|
+
* **Example** (Encoding a snapshot for storage)
|
|
5294
5009
|
*
|
|
5295
|
-
* ```ts
|
|
5010
|
+
* ```ts import.meta.vitest
|
|
5296
5011
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5297
|
-
* import { Effect
|
|
5298
|
-
*
|
|
5299
|
-
* }
|
|
5300
|
-
* const
|
|
5301
|
-
*
|
|
5302
|
-
* root: States,
|
|
5303
|
-
* events: Machine.eventsFromSchemas()
|
|
5304
|
-
* }).handle({
|
|
5305
|
-
* initial: {
|
|
5306
|
-
* target: "Idle"
|
|
5307
|
-
* },
|
|
5308
|
-
* states: {
|
|
5309
|
-
* Idle: {}
|
|
5310
|
-
* }
|
|
5012
|
+
* import { Effect } from "effect"
|
|
5013
|
+
*
|
|
5014
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
5015
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
5016
|
+
* initial: { target: "Idle" }
|
|
5311
5017
|
* })
|
|
5018
|
+
*
|
|
5312
5019
|
* const encoded = Effect.gen(function*() {
|
|
5313
5020
|
* const initial = yield* Machine.planInitial(machine)
|
|
5314
|
-
*
|
|
5021
|
+
* const snapshot = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
5022
|
+
* return typeof snapshot
|
|
5315
5023
|
* })
|
|
5024
|
+
*
|
|
5025
|
+
* await Effect.runPromise(encoded) // => "object"
|
|
5316
5026
|
* ```
|
|
5317
5027
|
*
|
|
5318
5028
|
* @see {@link decodeSnapshot} for restoring an encoded snapshot.
|
|
@@ -5339,30 +5049,25 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
5339
5049
|
* Decoding restores logical statechart data only. It does not restart invoked
|
|
5340
5050
|
* processes, recreate spawned children, or restore a previous `MachineRef`.
|
|
5341
5051
|
*
|
|
5342
|
-
* **Example**
|
|
5052
|
+
* **Example** (Restoring an encoded snapshot)
|
|
5343
5053
|
*
|
|
5344
|
-
* ```ts
|
|
5054
|
+
* ```ts import.meta.vitest
|
|
5345
5055
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5346
|
-
* import { Effect
|
|
5347
|
-
*
|
|
5348
|
-
* }
|
|
5349
|
-
* const
|
|
5350
|
-
*
|
|
5351
|
-
* root: States,
|
|
5352
|
-
* events: Machine.eventsFromSchemas()
|
|
5353
|
-
* }).handle({
|
|
5354
|
-
* initial: {
|
|
5355
|
-
* target: "Idle"
|
|
5356
|
-
* },
|
|
5357
|
-
* states: {
|
|
5358
|
-
* Idle: {}
|
|
5359
|
-
* }
|
|
5056
|
+
* import { Effect } from "effect"
|
|
5057
|
+
*
|
|
5058
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
5059
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
5060
|
+
* initial: { target: "Idle" }
|
|
5360
5061
|
* })
|
|
5361
|
-
*
|
|
5062
|
+
*
|
|
5063
|
+
* const path = Effect.gen(function*() {
|
|
5362
5064
|
* const initial = yield* Machine.planInitial(machine)
|
|
5363
5065
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
5364
|
-
*
|
|
5066
|
+
* const decoded = yield* Machine.decodeSnapshot(machine, encoded)
|
|
5067
|
+
* return decoded.state.path
|
|
5365
5068
|
* })
|
|
5069
|
+
*
|
|
5070
|
+
* await Effect.runPromise(path) // => "Idle"
|
|
5366
5071
|
* ```
|
|
5367
5072
|
*
|
|
5368
5073
|
* @see {@link encodeSnapshot} for creating the normalized representation.
|
|
@@ -5370,20 +5075,6 @@ export declare const encodeSnapshot: <const States extends Machine.StateSchemas,
|
|
|
5370
5075
|
* @since 0.4.0
|
|
5371
5076
|
*/
|
|
5372
5077
|
export declare const decodeSnapshot: <const States extends Machine.StateSchemas, const Events extends ReadonlyArray<Machine.TaggedSchema>, const Emits extends ReadonlyArray<Machine.TaggedSchema> = readonly [], const Input extends Schema.Top = typeof Schema.Void, UnhandledStates extends Machine.StateIdentifier<States> = Machine.StateIdentifier<States>, E = never, R = never, InitialE = never, InitialR = never, FinalStates extends Machine.StateIdentifier<States> = never, Output = never, OutputStates extends Machine.StateIdentifier<States> = never, InputEvents extends ReadonlyArray<Machine.TaggedSchema> = Events, ParentEvents extends ReadonlyArray<Machine.TaggedSchema> = readonly []>(machine: Machine<States, Events, Input, UnhandledStates, E, R, InitialE, InitialR, FinalStates, Output, Emits, OutputStates, InputEvents, ParentEvents>, encoded: unknown) => Effect.Effect<Machine.Snapshot<States>, MachineSchemaDecodeError, Machine.SnapshotDecodingServices<States>>;
|
|
5373
|
-
type TransitionBranchRecordError<Message extends string, Key extends PropertyKey = never> = {
|
|
5374
|
-
readonly "~effect/Machine/TransitionBranchRecordError": Message;
|
|
5375
|
-
readonly key: Key;
|
|
5376
|
-
};
|
|
5377
|
-
type InvalidStaticTransitionBranchKey<Branches> = Extract<keyof Branches, "" | number | symbol | `${number}` | "NaN" | "Infinity" | "-Infinity">;
|
|
5378
|
-
type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never] ? TransitionBranchRecordError<"Branch records must contain at least one branch"> : [InvalidStaticTransitionBranchKey<Branches>] extends [never] ? {
|
|
5379
|
-
readonly [K in keyof Branches]: {
|
|
5380
|
-
readonly [Extra in Exclude<keyof Branches[K], "target" | "update" | "initialize" | "initial" | "history" | "none" | "title">]: never;
|
|
5381
|
-
} & (Branches[K] extends {
|
|
5382
|
-
readonly title: "";
|
|
5383
|
-
} ? {
|
|
5384
|
-
readonly title: never;
|
|
5385
|
-
} : unknown);
|
|
5386
|
-
} : TransitionBranchRecordError<"Branch keys must be non-empty, non-numeric strings", InvalidStaticTransitionBranchKey<Branches>>;
|
|
5387
5078
|
/**
|
|
5388
5079
|
* Plans the initial state for a machine without executing machine commands.
|
|
5389
5080
|
*
|
|
@@ -5402,26 +5093,20 @@ type ValidateTransitionBranchRecord<Branches> = [keyof Branches] extends [never]
|
|
|
5402
5093
|
* protocol. Manual planners may inspect commands but need running machine targets
|
|
5403
5094
|
* to execute child-addressed operations.
|
|
5404
5095
|
*
|
|
5405
|
-
* **Example**
|
|
5096
|
+
* **Example** (Planning startup without running the machine)
|
|
5406
5097
|
*
|
|
5407
|
-
* ```ts
|
|
5098
|
+
* ```ts import.meta.vitest
|
|
5408
5099
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5409
|
-
* import { Effect
|
|
5410
|
-
*
|
|
5411
|
-
* }
|
|
5412
|
-
* const
|
|
5413
|
-
*
|
|
5414
|
-
* root: States,
|
|
5415
|
-
* events: Machine.eventsFromSchemas()
|
|
5416
|
-
* }).handle({
|
|
5417
|
-
* initial: {
|
|
5418
|
-
* target: "Idle"
|
|
5419
|
-
* },
|
|
5420
|
-
* states: {
|
|
5421
|
-
* Idle: {}
|
|
5422
|
-
* }
|
|
5100
|
+
* import { Effect } from "effect"
|
|
5101
|
+
*
|
|
5102
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
5103
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
5104
|
+
* initial: { target: "Idle" }
|
|
5423
5105
|
* })
|
|
5424
|
-
*
|
|
5106
|
+
*
|
|
5107
|
+
* const path = Effect.map(Machine.planInitial(machine), (plan) => plan.state.state.path)
|
|
5108
|
+
*
|
|
5109
|
+
* await Effect.runPromise(path) // => "Idle"
|
|
5425
5110
|
* ```
|
|
5426
5111
|
*
|
|
5427
5112
|
* @see {@link plan} for planning a received event.
|
|
@@ -5473,9 +5158,9 @@ export declare const stateNodes: <M extends Machine.Any>(machine: M) => Readonly
|
|
|
5473
5158
|
/**
|
|
5474
5159
|
* Returns the statically selected root entry used during machine startup.
|
|
5475
5160
|
*
|
|
5476
|
-
* This function does not
|
|
5477
|
-
* input. `kind: "initial"` means that the
|
|
5478
|
-
*
|
|
5161
|
+
* This function does not construct initial state values or require machine
|
|
5162
|
+
* input. `kind: "initial"` means that the root enters its declared initial
|
|
5163
|
+
* configuration.
|
|
5479
5164
|
*
|
|
5480
5165
|
* @category getters
|
|
5481
5166
|
* @since 0.14.0
|
|
@@ -5486,7 +5171,8 @@ export declare const initialDefinition: <M extends Machine.Any>(machine: M) => M
|
|
|
5486
5171
|
*
|
|
5487
5172
|
* **Details**
|
|
5488
5173
|
*
|
|
5489
|
-
* The returned tuple retains the schemas supplied to {@link events}
|
|
5174
|
+
* The returned tuple retains the schemas supplied to {@link events} or
|
|
5175
|
+
* {@link eventsFromSchemas}, including
|
|
5490
5176
|
* grouped tagged unions. Internal and emitted event schemas are excluded. This
|
|
5491
5177
|
* getter is intended for tooling that needs to describe or construct valid
|
|
5492
5178
|
* external inputs without reaching into the opaque event protocol.
|
|
@@ -5496,16 +5182,16 @@ export declare const initialDefinition: <M extends Machine.Any>(machine: M) => M
|
|
|
5496
5182
|
*/
|
|
5497
5183
|
export declare const inputEventSchemas: <M extends Machine.Any>(machine: M) => Machine.InputEvents<M>;
|
|
5498
5184
|
/**
|
|
5499
|
-
* Returns every
|
|
5185
|
+
* Returns every declared transition in state definition order.
|
|
5500
5186
|
*
|
|
5501
5187
|
* **Details**
|
|
5502
5188
|
*
|
|
5503
|
-
* Event
|
|
5504
|
-
*
|
|
5189
|
+
* Event transitions retain their key order within each source state and are
|
|
5190
|
+
* followed by eventless and completion transitions. This function does not
|
|
5505
5191
|
* execute resolvers. Every branch exposes its static selection. State updates
|
|
5506
5192
|
* retain the updated owner in `selection.path` while leaving `target`
|
|
5507
5193
|
* undefined because they do not change topology. `acceptance` reports whether
|
|
5508
|
-
* the
|
|
5194
|
+
* the transition may decline the event.
|
|
5509
5195
|
*
|
|
5510
5196
|
* @category getters
|
|
5511
5197
|
* @since 0.4.0
|
|
@@ -5516,7 +5202,7 @@ export declare const transitionDefinitions: <M extends Machine.Any>(machine: M)
|
|
|
5516
5202
|
*
|
|
5517
5203
|
* **Details**
|
|
5518
5204
|
*
|
|
5519
|
-
* Static
|
|
5205
|
+
* Static invocation definitions expose stable ownership and lifecycle
|
|
5520
5206
|
* metadata without serializing runtime values. Function-valued sources are
|
|
5521
5207
|
* represented as dynamic and are never evaluated during inspection.
|
|
5522
5208
|
*
|
|
@@ -5541,7 +5227,7 @@ export declare const configuration: <M extends Machine.Any>(machine: M, state: M
|
|
|
5541
5227
|
* Returns event tags with at least one structurally eligible handler in the
|
|
5542
5228
|
* current state snapshot.
|
|
5543
5229
|
*
|
|
5544
|
-
* A `
|
|
5230
|
+
* A handler with `guard` or `{ decline: true }` may still reject a concrete event at planning time,
|
|
5545
5231
|
* so this is a static candidate query rather than a guarantee that every value
|
|
5546
5232
|
* with the returned tag will be handled.
|
|
5547
5233
|
*
|
|
@@ -5555,9 +5241,10 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5555
5241
|
*
|
|
5556
5242
|
* **Details**
|
|
5557
5243
|
*
|
|
5558
|
-
* Required
|
|
5559
|
-
* Declinable
|
|
5560
|
-
*
|
|
5244
|
+
* Required transitions are accepted from their structural eligibility.
|
|
5245
|
+
* Declinable transitions, which have a `guard` or a `{ decline: true }` entry,
|
|
5246
|
+
* run their guard or resolver only far enough to decide whether they accept
|
|
5247
|
+
* the event. Any commands, emissions, or raised events collected
|
|
5561
5248
|
* during that check are discarded.
|
|
5562
5249
|
*
|
|
5563
5250
|
* Event input is decoded through the machine's public and internal event protocols.
|
|
@@ -5575,9 +5262,9 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5575
5262
|
* Synchronous transition resolvers cannot execute it. Querying an internal event
|
|
5576
5263
|
* does not make that event available to `MachineRef.send`.
|
|
5577
5264
|
*
|
|
5578
|
-
* **Example**
|
|
5265
|
+
* **Example** (Checking an event against the current state)
|
|
5579
5266
|
*
|
|
5580
|
-
* ```ts
|
|
5267
|
+
* ```ts import.meta.vitest
|
|
5581
5268
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5582
5269
|
* import { Effect, Schema } from "effect"
|
|
5583
5270
|
*
|
|
@@ -5589,13 +5276,15 @@ export declare const enabled: <const States extends Machine.StateSchemas, const
|
|
|
5589
5276
|
* internalEvents
|
|
5590
5277
|
* }).handle({
|
|
5591
5278
|
* initial: { target: "Idle" },
|
|
5592
|
-
* states: { Idle: { on: { Loaded: {
|
|
5279
|
+
* states: { Idle: { on: { Loaded: { stay: true } } } }
|
|
5593
5280
|
* })
|
|
5594
5281
|
*
|
|
5595
|
-
*
|
|
5282
|
+
* const canLoad = Effect.gen(function*() {
|
|
5596
5283
|
* const initial = yield* Machine.planInitial(machine)
|
|
5597
5284
|
* return yield* Machine.can(machine, initial.state, internalEvents.Loaded())
|
|
5598
5285
|
* })
|
|
5286
|
+
*
|
|
5287
|
+
* await Effect.runPromise(canLoad) // => true
|
|
5599
5288
|
* ```
|
|
5600
5289
|
*
|
|
5601
5290
|
* @category getters
|
|
@@ -5622,38 +5311,30 @@ export declare const can: {
|
|
|
5622
5311
|
* `emittedEvents`. Events with no enabled transition are ignored and produce
|
|
5623
5312
|
* an unchanged plan.
|
|
5624
5313
|
*
|
|
5625
|
-
* **Example**
|
|
5314
|
+
* **Example** (Planning one event without running the machine)
|
|
5626
5315
|
*
|
|
5627
|
-
* ```ts
|
|
5316
|
+
* ```ts import.meta.vitest
|
|
5628
5317
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5629
|
-
* import { Effect
|
|
5630
|
-
*
|
|
5631
|
-
* }
|
|
5632
|
-
* class On extends Schema.TaggedClass<On>("On")("On", {}) {
|
|
5633
|
-
* }
|
|
5634
|
-
* class Toggle extends Schema.TaggedClass<Toggle>("Toggle")("Toggle", {}) {
|
|
5635
|
-
* }
|
|
5636
|
-
* const States = Machine.state({ states: { Off, On } })
|
|
5318
|
+
* import { Effect } from "effect"
|
|
5319
|
+
*
|
|
5320
|
+
* const Events = Machine.events({ Toggle: {} })
|
|
5637
5321
|
* const machine = Machine.make({
|
|
5638
|
-
* root:
|
|
5639
|
-
* events:
|
|
5322
|
+
* root: Machine.state({ states: { Off: {}, On: {} } }),
|
|
5323
|
+
* events: Events
|
|
5640
5324
|
* }).handle({
|
|
5641
|
-
* initial: {
|
|
5642
|
-
* target: "Off"
|
|
5643
|
-
* },
|
|
5325
|
+
* initial: { target: "Off" },
|
|
5644
5326
|
* states: {
|
|
5645
|
-
* Off: {
|
|
5646
|
-
* on: {
|
|
5647
|
-
* Toggle: { target: "On" }
|
|
5648
|
-
* }
|
|
5649
|
-
* },
|
|
5650
|
-
* On: {}
|
|
5327
|
+
* Off: { on: { Toggle: { target: "On" } } }
|
|
5651
5328
|
* }
|
|
5652
5329
|
* })
|
|
5653
|
-
*
|
|
5330
|
+
*
|
|
5331
|
+
* const path = Effect.gen(function*() {
|
|
5654
5332
|
* const initial = yield* Machine.planInitial(machine)
|
|
5655
|
-
*
|
|
5333
|
+
* const planned = yield* Machine.plan(machine, initial.state, Events.Toggle())
|
|
5334
|
+
* return planned.next.state.path
|
|
5656
5335
|
* })
|
|
5336
|
+
*
|
|
5337
|
+
* await Effect.runPromise(path) // => "On"
|
|
5657
5338
|
* ```
|
|
5658
5339
|
*
|
|
5659
5340
|
* @see {@link planInitial} for planning machine startup.
|
|
@@ -5709,13 +5390,16 @@ export declare const plan: <const States extends Machine.StateSchemas, const Eve
|
|
|
5709
5390
|
* which machine will eventually own it. Prefer typed output, typed child
|
|
5710
5391
|
* addresses, or invocation lifecycle transitions when possible.
|
|
5711
5392
|
*
|
|
5712
|
-
*
|
|
5713
|
-
*
|
|
5393
|
+
* For one-shot work, register an Effect in `make({ effects })` and invoke it
|
|
5394
|
+
* with `invoke: { src }` instead. Register logic in `make({ logic })` to run it
|
|
5395
|
+
* for the lifetime of one state.
|
|
5396
|
+
*
|
|
5397
|
+
* @see {@link make} for registering sources that states invoke by name.
|
|
5714
5398
|
* @category constructors
|
|
5715
5399
|
* @since 0.4.0
|
|
5716
5400
|
*/
|
|
5717
5401
|
export declare const logic: <State, Event = never, Output = void, Error = never, Requirements = never, InitialError = never, InitialRequirements = never>(options: {
|
|
5718
|
-
/**
|
|
5402
|
+
/** The first state, or an Effect that produces it from the process scope before `run` starts. */
|
|
5719
5403
|
readonly initial: State | ((scope: Logic.Scope<Event>) => Effect.Effect<State, InitialError, InitialRequirements>);
|
|
5720
5404
|
readonly run: (context: Logic.Context<State, Event>) => Effect.Effect<Output, Error, Requirements>;
|
|
5721
5405
|
}) => Logic<State, Event, Error, Requirements | InitialRequirements, Output, InitialError>;
|
|
@@ -5780,8 +5464,8 @@ export declare const spawn: {
|
|
|
5780
5464
|
* @since 0.4.0
|
|
5781
5465
|
*/
|
|
5782
5466
|
export declare const sendTo: {
|
|
5783
|
-
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): Effect.Effect<void, StoppedError,
|
|
5784
|
-
<Address extends ChildAddress<never>>(id: Address, event: ChildAddress.Event<Address>): Effect.Effect<void, StoppedError,
|
|
5467
|
+
<Child extends ChildMachine.Any>(child: Child, event: ChildMachine.Event<Child>): Effect.Effect<void, StoppedError, MachineRuntime>;
|
|
5468
|
+
<Address extends ChildAddress<never>>(id: Address, event: ChildAddress.Event<Address>): Effect.Effect<void, StoppedError, MachineRuntime>;
|
|
5785
5469
|
};
|
|
5786
5470
|
/**
|
|
5787
5471
|
* Stops a named child process of the running machine.
|
|
@@ -5790,8 +5474,8 @@ export declare const sendTo: {
|
|
|
5790
5474
|
* @since 0.4.0
|
|
5791
5475
|
*/
|
|
5792
5476
|
export declare const stopChild: {
|
|
5793
|
-
<Event>(child: ChildAddress<Event>): Effect.Effect<void, never,
|
|
5794
|
-
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never,
|
|
5477
|
+
<Event>(child: ChildAddress<Event>): Effect.Effect<void, never, MachineRuntime>;
|
|
5478
|
+
<Child extends ChildMachine.Any>(child: Child): Effect.Effect<void, never, MachineRuntime>;
|
|
5795
5479
|
};
|
|
5796
5480
|
/**
|
|
5797
5481
|
* Returns a stream of terminal lifecycle outcomes for a running machine.
|
|
@@ -5817,9 +5501,31 @@ export declare const watch: <State, Event, Error = never, Output = never>(ref: M
|
|
|
5817
5501
|
* Type predicates narrow the returned snapshot. Intermediate microsteps and
|
|
5818
5502
|
* historical snapshots are not observed.
|
|
5819
5503
|
*
|
|
5820
|
-
*
|
|
5821
|
-
*
|
|
5822
|
-
*
|
|
5504
|
+
* **Example** (Waiting for a state with a timeout)
|
|
5505
|
+
*
|
|
5506
|
+
* ```ts import.meta.vitest
|
|
5507
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
5508
|
+
* import { Effect } from "effect"
|
|
5509
|
+
*
|
|
5510
|
+
* const Events = Machine.events({ Finish: {} })
|
|
5511
|
+
* const machine = Machine.make({
|
|
5512
|
+
* root: Machine.state({ states: { Working: {}, Ready: {} } }),
|
|
5513
|
+
* events: Events
|
|
5514
|
+
* }).handle({
|
|
5515
|
+
* initial: { target: "Working" },
|
|
5516
|
+
* states: {
|
|
5517
|
+
* Working: { on: { Finish: { target: "Ready" } } }
|
|
5518
|
+
* }
|
|
5519
|
+
* })
|
|
5520
|
+
*
|
|
5521
|
+
* const path = Effect.scoped(Effect.gen(function*() {
|
|
5522
|
+
* const ref = yield* Machine.start(machine)
|
|
5523
|
+
* yield* ref.send(Events.Finish())
|
|
5524
|
+
* const ready = yield* Machine.waitFor(ref, ({ state }) => state.state.path === "Ready").pipe(Effect.timeout("5 seconds"))
|
|
5525
|
+
* return ready.state.state.path
|
|
5526
|
+
* }))
|
|
5527
|
+
*
|
|
5528
|
+
* await Effect.runPromise(path) // => "Ready"
|
|
5823
5529
|
* ```
|
|
5824
5530
|
* @category combinators
|
|
5825
5531
|
* @since 0.37.0
|
|
@@ -5841,15 +5547,41 @@ export declare const waitFor: {
|
|
|
5841
5547
|
* `prepared.start` is one-shot and scoped: the `Scope` that first evaluates it
|
|
5842
5548
|
* owns the machine, and closing that `Scope` is equivalent to `ref.stop`.
|
|
5843
5549
|
*
|
|
5844
|
-
*
|
|
5845
|
-
* const prepared = yield* Machine.prepare(machine)
|
|
5550
|
+
* **Example** (Observing emissions before startup)
|
|
5846
5551
|
*
|
|
5847
|
-
*
|
|
5848
|
-
*
|
|
5849
|
-
*
|
|
5850
|
-
*
|
|
5552
|
+
* ```ts import.meta.vitest
|
|
5553
|
+
* import { Machine } from "@typeonce/effect-machine"
|
|
5554
|
+
* import { Effect, Stream } from "effect"
|
|
5555
|
+
*
|
|
5556
|
+
* const Emitted = Machine.emittedEvents({ Started: {} })
|
|
5557
|
+
* const machine = Machine.make({
|
|
5558
|
+
* root: Machine.state({ states: { Idle: {} } }),
|
|
5559
|
+
* events: Machine.events({}),
|
|
5560
|
+
* emittedEvents: Emitted
|
|
5561
|
+
* }).handle({
|
|
5562
|
+
* initial: { target: "Idle" },
|
|
5563
|
+
* states: {
|
|
5564
|
+
* Idle: {
|
|
5565
|
+
* entry: (_, enqueue) => {
|
|
5566
|
+
* enqueue.emit(Emitted.Started())
|
|
5567
|
+
* }
|
|
5568
|
+
* }
|
|
5569
|
+
* }
|
|
5570
|
+
* })
|
|
5571
|
+
*
|
|
5572
|
+
* const emitted = Effect.scoped(Effect.gen(function*() {
|
|
5573
|
+
* const prepared = yield* Machine.prepare(machine)
|
|
5574
|
+
* const seen: Array<string> = []
|
|
5575
|
+
* yield* prepared.emissions.pipe(
|
|
5576
|
+
* Stream.runForEach((event) => Effect.sync(() => seen.push(event._tag))),
|
|
5577
|
+
* Effect.forkScoped({ startImmediately: true })
|
|
5578
|
+
* )
|
|
5579
|
+
* yield* prepared.start
|
|
5580
|
+
* yield* Effect.yieldNow
|
|
5581
|
+
* return seen
|
|
5582
|
+
* }))
|
|
5851
5583
|
*
|
|
5852
|
-
*
|
|
5584
|
+
* await Effect.runPromise(emitted) // => ["Started"]
|
|
5853
5585
|
* ```
|
|
5854
5586
|
*
|
|
5855
5587
|
* @category constructors
|
|
@@ -5885,29 +5617,23 @@ export declare const prepare: <const States extends Machine.StateSchemas, const
|
|
|
5885
5617
|
* rather than being returned by `send`. Sending after the machine reaches any
|
|
5886
5618
|
* terminal state fails immediately with `StoppedError`.
|
|
5887
5619
|
*
|
|
5888
|
-
* **Example**
|
|
5620
|
+
* **Example** (Starting a machine in a scope)
|
|
5889
5621
|
*
|
|
5890
|
-
* ```ts
|
|
5622
|
+
* ```ts import.meta.vitest
|
|
5891
5623
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5892
|
-
* import { Effect
|
|
5893
|
-
*
|
|
5894
|
-
* }
|
|
5895
|
-
* const
|
|
5896
|
-
*
|
|
5897
|
-
* root: States,
|
|
5898
|
-
* events: Machine.eventsFromSchemas()
|
|
5899
|
-
* }).handle({
|
|
5900
|
-
* initial: {
|
|
5901
|
-
* target: "Idle"
|
|
5902
|
-
* },
|
|
5903
|
-
* states: {
|
|
5904
|
-
* Idle: {}
|
|
5905
|
-
* }
|
|
5624
|
+
* import { Effect } from "effect"
|
|
5625
|
+
*
|
|
5626
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
5627
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
5628
|
+
* initial: { target: "Idle" }
|
|
5906
5629
|
* })
|
|
5907
|
-
*
|
|
5630
|
+
*
|
|
5631
|
+
* const path = Effect.scoped(Effect.gen(function*() {
|
|
5908
5632
|
* const ref = yield* Machine.start(machine)
|
|
5909
|
-
* return yield* ref.state
|
|
5633
|
+
* return (yield* ref.state).state.path
|
|
5910
5634
|
* }))
|
|
5635
|
+
*
|
|
5636
|
+
* await Effect.runPromise(path) // => "Idle"
|
|
5911
5637
|
* ```
|
|
5912
5638
|
*
|
|
5913
5639
|
* @see {@link plan} for inspecting the same transition plan without executing it.
|
|
@@ -5926,7 +5652,7 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
5926
5652
|
* the `Scope` is equivalent to `ref.stop`.
|
|
5927
5653
|
*
|
|
5928
5654
|
* `resume` validates and normalizes the supplied snapshot before publishing it
|
|
5929
|
-
* as the first state. It does not
|
|
5655
|
+
* as the first state. It does not construct the declared initial state, replay
|
|
5930
5656
|
* entry or transition actions, re-deliver raised or emitted events, or
|
|
5931
5657
|
* re-evaluate historical completion and eventless transitions. Active-state
|
|
5932
5658
|
* invokes start once in ancestor and document order with {@link InitialEvent};
|
|
@@ -5944,31 +5670,26 @@ export declare const start: <const States extends Machine.StateSchemas, const Ev
|
|
|
5944
5670
|
* evaluated merely because the runtime was resumed; only ordinary subsequent
|
|
5945
5671
|
* transition planning can enter and stabilize states.
|
|
5946
5672
|
*
|
|
5947
|
-
* **Example**
|
|
5673
|
+
* **Example** (Resuming from a decoded snapshot)
|
|
5948
5674
|
*
|
|
5949
|
-
* ```ts
|
|
5675
|
+
* ```ts import.meta.vitest
|
|
5950
5676
|
* import { Machine } from "@typeonce/effect-machine"
|
|
5951
|
-
* import { Effect
|
|
5952
|
-
*
|
|
5953
|
-
* }
|
|
5954
|
-
* const
|
|
5955
|
-
*
|
|
5956
|
-
* root: States,
|
|
5957
|
-
* events: Machine.eventsFromSchemas()
|
|
5958
|
-
* }).handle({
|
|
5959
|
-
* initial: {
|
|
5960
|
-
* target: "Idle"
|
|
5961
|
-
* },
|
|
5962
|
-
* states: {
|
|
5963
|
-
* Idle: {}
|
|
5964
|
-
* }
|
|
5677
|
+
* import { Effect } from "effect"
|
|
5678
|
+
*
|
|
5679
|
+
* const States = Machine.state({ states: { Idle: {} } })
|
|
5680
|
+
* const machine = Machine.make({ root: States, events: Machine.events({}) }).handle({
|
|
5681
|
+
* initial: { target: "Idle" }
|
|
5965
5682
|
* })
|
|
5966
|
-
*
|
|
5683
|
+
*
|
|
5684
|
+
* const path = Effect.scoped(Effect.gen(function*() {
|
|
5967
5685
|
* const initial = yield* Machine.planInitial(machine)
|
|
5968
5686
|
* const encoded = yield* Machine.encodeSnapshot(machine, initial.state)
|
|
5969
5687
|
* const snapshot = yield* Machine.decodeSnapshot(machine, encoded)
|
|
5970
|
-
*
|
|
5688
|
+
* const ref = yield* Machine.resume(machine, snapshot)
|
|
5689
|
+
* return (yield* ref.state).state.path
|
|
5971
5690
|
* }))
|
|
5691
|
+
*
|
|
5692
|
+
* await Effect.runPromise(path) // => "Idle"
|
|
5972
5693
|
* ```
|
|
5973
5694
|
*
|
|
5974
5695
|
* @see {@link decodeSnapshot} for the schema and transport boundary.
|